Source Code Cross Referenced for IdeTestUtils.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » apt » pluggable » tests » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » jdt » org.eclipse.jdt.apt.pluggable.tests 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2007 BEA Systems, Inc.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *    wharley@bea.com - initial API and implementation
010:         *
011:         *******************************************************************************/package org.eclipse.jdt.apt.pluggable.tests;
012:
013:        import java.io.File;
014:        import java.io.FileOutputStream;
015:        import java.io.IOException;
016:        import java.net.URL;
017:
018:        import org.eclipse.core.resources.IProject;
019:        import org.eclipse.core.resources.IResource;
020:        import org.eclipse.core.runtime.FileLocator;
021:        import org.eclipse.core.runtime.Platform;
022:
023:        /**
024:         * Helper class to support compilation and results checking for tests running in batch mode.
025:         * @since 3.3.1
026:         */
027:        public class IdeTestUtils {
028:            /**
029:             * Name of the subdirectory within the test bundle where target resources are stored.
030:             */
031:            public static final String RESOURCES_DIR = "resources";
032:
033:            /**
034:             * Copy files from a bundle into a project in the target workspace. Newlines will be
035:             * converted according to {@link #shouldConvertToIndependentLineDelimiter(File)}.
036:             * Directories named "CVS" will be ignored.
037:             * 
038:             * @param proj 
039:             *            the project within which the files will be created.
040:             * @param resourceFolderName
041:             *            the name of the folder within the plug-in that the files will be copied
042:             *            from, relative to <code>[plugin-root]/resources</code>
043:             * @param destFolderName
044:             *            the name of the folder within the target workspace that the files will
045:             *            be copied to, relative to the project
046:             * @throws Exception
047:             *            might be an IOException or a CoreException
048:             */
049:            public static void copyResources(IProject proj,
050:                    String resourceFolderName, String destFolderName)
051:                    throws Exception {
052:                String destFolderOSName = proj.getFolder(destFolderName)
053:                        .getLocation().toOSString(); //$NON-NLS-1$
054:                File destFolder = new File(destFolderOSName);
055:                File resourceFolder = TestUtils.concatPath(
056:                        getPluginDirectoryPath(), RESOURCES_DIR,
057:                        resourceFolderName);
058:                copyResources(resourceFolder, destFolder);
059:                proj.refreshLocal(IResource.DEPTH_INFINITE, null);
060:            }
061:
062:            /**
063:             * @return the absolute filesystem-based path of the root of the bundle filesystem.
064:             * This will cause the bundle to be extracted to a temporary directory on the filesystem
065:             * if necessary; see {@link FileLocator#toFileURL(URL)}.
066:             */
067:            public static String getPluginDirectoryPath() {
068:                try {
069:                    URL platformURL = Platform.getBundle(
070:                            "org.eclipse.jdt.apt.pluggable.tests")
071:                            .getEntry("/");
072:                    return new File(FileLocator.toFileURL(platformURL)
073:                            .getFile()).getAbsolutePath();
074:                } catch (IOException e) {
075:                    e.printStackTrace();
076:                }
077:                return null;
078:            }
079:
080:            /**
081:             * Copy a file from one location to another, unless the destination file already exists and has
082:             * the same timestamp and file size. Create the destination location if necessary. Convert line
083:             * delimiters according to {@link #shouldConvertToIndependentLineDelimiter(File)}.
084:             * 
085:             * @param src
086:             *            the full path to the resource location.
087:             * @param destFolder
088:             *            the full path to the destination location.
089:             * @throws IOException
090:             */
091:            private static void copyResource(File src, File dest)
092:                    throws IOException {
093:                if (dest.exists() && src.lastModified() < dest.lastModified()
094:                        && src.length() == dest.length()) {
095:                    return;
096:                }
097:
098:                // read source bytes
099:                byte[] srcBytes = null;
100:                srcBytes = read(src);
101:
102:                if (shouldConvertToIndependentLineDelimiter(src)) {
103:                    String contents = new String(srcBytes);
104:                    contents = TestUtils
105:                            .convertToIndependentLineDelimiter(contents);
106:                    srcBytes = contents.getBytes();
107:                }
108:
109:                File destFolder = dest.getParentFile();
110:                if (!destFolder.exists()) {
111:                    if (!destFolder.mkdirs()) {
112:                        throw new IOException("Unable to create directory "
113:                                + destFolder);
114:                    }
115:                }
116:                // write bytes to dest
117:                FileOutputStream out = null;
118:                try {
119:                    out = new FileOutputStream(dest);
120:                    out.write(srcBytes);
121:                    out.flush();
122:                } finally {
123:                    if (out != null) {
124:                        out.close();
125:                    }
126:                }
127:            }
128:
129:            private static void copyResources(File resourceFolder,
130:                    File destFolder) throws IOException {
131:                if (resourceFolder == null) {
132:                    return;
133:                }
134:                // Copy all resources in this folder
135:                String[] children = resourceFolder.list();
136:                if (null == children) {
137:                    return;
138:                }
139:                // if there are any children, (recursively) copy them
140:                for (String child : children) {
141:                    if ("CVS".equals(child)) {
142:                        continue;
143:                    }
144:                    File childRes = new File(resourceFolder, child);
145:                    File childDest = new File(destFolder, child);
146:                    if (childRes.isDirectory()) {
147:                        copyResources(childRes, childDest);
148:                    } else {
149:                        copyResource(childRes, childDest);
150:                    }
151:                }
152:            }
153:
154:            private static byte[] read(java.io.File file)
155:                    throws java.io.IOException {
156:                int fileLength;
157:                byte[] fileBytes = new byte[fileLength = (int) file.length()];
158:                java.io.FileInputStream stream = null;
159:                try {
160:                    stream = new java.io.FileInputStream(file);
161:                    int bytesRead = 0;
162:                    int lastReadSize = 0;
163:                    while ((lastReadSize != -1) && (bytesRead != fileLength)) {
164:                        lastReadSize = stream.read(fileBytes, bytesRead,
165:                                fileLength - bytesRead);
166:                        bytesRead += lastReadSize;
167:                    }
168:                } finally {
169:                    if (stream != null) {
170:                        stream.close();
171:                    }
172:                }
173:                return fileBytes;
174:            }
175:
176:            /**
177:             * @return true if this file's end-of-line delimiters should be replaced with
178:             * a platform-independent value, e.g. for compilation.
179:             */
180:            private static boolean shouldConvertToIndependentLineDelimiter(
181:                    File file) {
182:                return file.getName().endsWith(".java");
183:            }
184:
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.