Source Code Cross Referenced for Utils.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » build » internal » 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 » Eclipse plug in development » org.eclipse.pde.build.internal.tests 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2007 IBM Corporation and others. All rights reserved. This
003:         * program and the accompanying materials are made available under the terms of
004:         * the Eclipse Public License v1.0 which accompanies this distribution, and is
005:         * available at http://www.eclipse.org/legal/epl-v10.html
006:         * 
007:         * Contributors: IBM Corporation - initial API and implementation
008:         ******************************************************************************/package org.eclipse.pde.build.internal.tests;
009:
010:        import java.io.*;
011:        import java.net.URL;
012:        import java.util.*;
013:        import java.util.jar.*;
014:        import java.util.jar.Attributes.Name;
015:
016:        import org.apache.tools.ant.filters.ReplaceTokens;
017:        import org.apache.tools.ant.util.ReaderInputStream;
018:        import org.eclipse.core.resources.*;
019:        import org.eclipse.core.runtime.*;
020:        import org.eclipse.pde.build.tests.Activator;
021:        import org.eclipse.pde.internal.build.FeatureGenerator;
022:        import org.eclipse.pde.internal.build.site.BuildTimeSiteFactory;
023:
024:        public class Utils {
025:
026:            /**
027:             * Transfer the contents of resource into the destination IFile.  During the transfer, replace all 
028:             * instances of "@replaceTag@" with "replaceString"
029:             * 
030:             * @param resource		- input URL
031:             * @param destination	- IFile destination
032:             * @param replacements	- map of tokens and values to replaces, file should contain "@replaceTag@"
033:             * @throws IOException 
034:             * @throws CoreException 
035:             */
036:            static public void transferAndReplace(URL resource,
037:                    IFile destination, Map replacements) throws IOException,
038:                    CoreException {
039:                Reader reader = new InputStreamReader(new BufferedInputStream(
040:                        resource.openStream()));
041:                final ReplaceTokens replaces = new ReplaceTokens(reader);
042:
043:                for (Iterator iterator = replacements.keySet().iterator(); iterator
044:                        .hasNext();) {
045:                    String replaceTag = (String) iterator.next();
046:                    String replaceString = (String) replacements
047:                            .get(replaceTag);
048:                    ReplaceTokens.Token token = new ReplaceTokens.Token();
049:                    token.setKey(replaceTag);
050:                    token.setValue(replaceString);
051:                    replaces.addConfiguredToken(token);
052:                }
053:
054:                ReaderInputStream inputStream = new ReaderInputStream(replaces);
055:                destination.create(inputStream, true, null);
056:                inputStream.close();
057:            }
058:
059:            static public void generateAllElements(IFolder buildFolder,
060:                    String element) throws CoreException, IOException {
061:                if (element != null) {
062:                    // get the productBuild/allElements.xml and replace @ELEMENT@ with element
063:                    URL allElements = FileLocator.find(Platform
064:                            .getBundle(Activator.PLUGIN_ID), new Path(
065:                            "/resources/allElements.xml"), null);
066:                    Map replacements = new HashMap(1);
067:                    replacements.put("ELEMENT", element);
068:                    transferAndReplace(allElements, buildFolder
069:                            .getFile("allElements.xml"), replacements);
070:                    buildFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
071:                }
072:            }
073:
074:            static public void generatePluginBuildProperties(IFolder folder,
075:                    Properties properties) throws FileNotFoundException,
076:                    IOException {
077:                Properties buildProperties = properties != null ? properties
078:                        : new Properties();
079:
080:                //default contents:
081:                if (!buildProperties.containsKey("source.."))
082:                    buildProperties.put("source..", "src/");
083:                if (!buildProperties.containsKey("output.."))
084:                    buildProperties.put("output..", "bin/");
085:                if (!buildProperties.containsKey("bin.includes"))
086:                    buildProperties.put("bin.includes", "META-INF/, .");
087:
088:                storeBuildProperties(folder, buildProperties);
089:            }
090:
091:            static public void generateBundleManifest(IFolder folder,
092:                    String bundleId, String bundleVersion,
093:                    Attributes additionalAttributes) throws CoreException,
094:                    IOException {
095:                Manifest manifest = new Manifest();
096:                Attributes mainAttributes = manifest.getMainAttributes();
097:                mainAttributes.put(Name.MANIFEST_VERSION, "1.0");
098:                mainAttributes.put(new Name("Bundle-ManifestVersion"), "2");
099:                mainAttributes.put(new Name("Bundle-Name"), "Test Bundle "
100:                        + bundleId);
101:                mainAttributes.put(new Name("Bundle-SymbolicName"), bundleId);
102:                mainAttributes.put(new Name("Bundle-Version"), bundleVersion);
103:                if (additionalAttributes != null)
104:                    mainAttributes.putAll(additionalAttributes);
105:
106:                IFile manifestFile = folder.getFile(JarFile.MANIFEST_NAME);
107:                IFolder metaInf = (IFolder) manifestFile.getParent();
108:                if (!metaInf.exists())
109:                    metaInf.create(true, true, null);
110:                OutputStream outputStream = new BufferedOutputStream(
111:                        new FileOutputStream(manifestFile.getLocation()
112:                                .toFile()));
113:                manifest.write(outputStream);
114:                outputStream.close();
115:            }
116:
117:            static public void generateBundle(IFolder folder, String bundleId)
118:                    throws CoreException, IOException {
119:                generateBundleManifest(folder, bundleId, "1.0.0", null);
120:                generatePluginBuildProperties(folder, null);
121:            }
122:
123:            static public void storeBuildProperties(IFolder buildFolder,
124:                    Properties buildProperties) throws FileNotFoundException,
125:                    IOException {
126:                File buildPropertiesFile = new File(buildFolder.getLocation()
127:                        .toFile(), "build.properties");
128:                OutputStream outputStream = new BufferedOutputStream(
129:                        new FileOutputStream(buildPropertiesFile));
130:                buildProperties.store(outputStream, "");
131:                outputStream.close();
132:            }
133:
134:            static public void generateFeature(IFolder workingDirectory,
135:                    String id, String[] featureList, String[] pluginList)
136:                    throws CoreException {
137:                generateFeature(workingDirectory, id, featureList, pluginList,
138:                        null, false, false);
139:            }
140:
141:            static public void generateFeature(IFolder workingDirectory,
142:                    String id, String[] featureList, String[] pluginList,
143:                    String product, boolean includeLaunchers, boolean verify)
144:                    throws CoreException {
145:                FeatureGenerator generator = new FeatureGenerator();
146:                if (verify) {
147:                    FeatureGenerator.setConfigInfo("*,*,*");
148:                    String baseLocation = Platform.getInstallLocation()
149:                            .getURL().getPath();
150:                    BuildTimeSiteFactory.setInstalledBaseSite(baseLocation);
151:                    File delta = findDeltaPack();
152:                    if (delta != null && !delta.equals(new File(baseLocation)))
153:                        generator.setPluginPath(new String[] { delta
154:                                .getAbsolutePath() });
155:                }
156:                generator.setIncludeLaunchers(includeLaunchers);
157:                generator.setVerify(verify);
158:                generator.setFeatureId(id);
159:                generator.setProductFile(product);
160:                generator.setFeatureList(featureList);
161:                generator.setPluginList(pluginList);
162:                generator.setWorkingDirectory(workingDirectory.getLocation()
163:                        .toOSString());
164:                generator.generate();
165:            }
166:
167:            /**
168:             * Creates a IFolder resources.  Will create any folders necessary under parent
169:             */
170:            static public IFolder createFolder(IFolder parent, String path)
171:                    throws CoreException {
172:                parent.refreshLocal(IResource.DEPTH_INFINITE, null);
173:                IFolder folder = parent.getFolder(path);
174:                if (folder.exists())
175:                    return folder;
176:                IFolder container = (IFolder) folder.getParent();
177:                if (!container.exists()) {
178:                    LinkedList stack = new LinkedList();
179:                    while (!container.equals(parent) && !container.exists()) {
180:                        stack.add(0, container);
181:                        container = (IFolder) container.getParent();
182:                    }
183:
184:                    for (Iterator iterator = stack.iterator(); iterator
185:                            .hasNext();) {
186:                        container = (IFolder) iterator.next();
187:                        container.create(true, true, null);
188:                    }
189:                }
190:                folder.create(true, true, null);
191:                return folder;
192:            }
193:
194:            public static File findDeltaPack() {
195:                File baseLocation = new File(Platform.getInstallLocation()
196:                        .getURL().getPath());
197:
198:                File plugins = new File(baseLocation, "features");
199:                FilenameFilter filter = new FilenameFilter() {
200:                    public boolean accept(File dir, String name) {
201:                        return name
202:                                .startsWith("org.eclipse.equinox.executable");
203:                    }
204:                };
205:                String[] files = plugins.list(filter);
206:
207:                if (files.length > 0)
208:                    return baseLocation;
209:
210:                File delta = new File(baseLocation.getParent(),
211:                        "deltapack/eclipse");
212:                if (delta.exists()) {
213:                    files = new File(delta, "features").list(filter);
214:                    if (files.length > 0)
215:                        return delta;
216:                }
217:                return null;
218:            }
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.