Source Code Cross Referenced for J2eePlatform.java in  » 6.0-JDK-Core » j2eeserver » org » netbeans » modules » j2ee » deployment » devmodules » api » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
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
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » j2eeserver » org.netbeans.modules.j2ee.deployment.devmodules.api 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003         *
004         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005         *
006         * The contents of this file are subject to the terms of either the GNU
007         * General Public License Version 2 only ("GPL") or the Common
008         * Development and Distribution License("CDDL") (collectively, the
009         * "License"). You may not use this file except in compliance with the
010         * License. You can obtain a copy of the License at
011         * http://www.netbeans.org/cddl-gplv2.html
012         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013         * specific language governing permissions and limitations under the
014         * License.  When distributing the software, include this License Header
015         * Notice in each file and include the License file at
016         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017         * particular file as subject to the "Classpath" exception as provided
018         * by Sun in the GPL Version 2 section of the License file that
019         * accompanied this code. If applicable, add the following below the
020         * License Header, with the fields enclosed by brackets [] replaced by
021         * your own identifying information:
022         * "Portions Copyrighted [year] [name of copyright owner]"
023         *
024         * Contributor(s):
025         *
026         * The Original Software is NetBeans. The Initial Developer of the Original
027         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028         * Microsystems, Inc. All Rights Reserved.
029         *
030         * If you wish your version of this file to be governed by only the CDDL
031         * or only the GPL Version 2, indicate your decision by adding
032         * "[Contributor] elects to include this software in this distribution
033         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034         * single choice of license, a recipient has the option to distribute
035         * your version of this file under either the CDDL, the GPL Version 2 or
036         * to extend the choice of license to its licensees as provided above.
037         * However, if you add GPL Version 2 code and therefore, elected the GPL
038         * Version 2 license, then the option applies only if the new code is
039         * made subject to such option by the copyright holder.
040         */
041
042        package org.netbeans.modules.j2ee.deployment.devmodules.api;
043
044        import java.awt.Image;
045        import java.beans.PropertyChangeEvent;
046        import java.beans.PropertyChangeListener;
047        import java.io.File;
048        import java.io.IOException;
049        import java.net.URL;
050        import java.util.ArrayList;
051        import java.util.HashMap;
052        import java.util.Iterator;
053        import java.util.List;
054        import java.util.Map;
055        import java.util.Set;
056        import java.util.logging.Level;
057        import java.util.logging.Logger;
058        import org.netbeans.api.java.platform.JavaPlatform;
059        import org.netbeans.api.project.libraries.Library;
060        import org.netbeans.api.project.libraries.LibraryManager;
061        import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
062        import org.netbeans.modules.j2ee.deployment.plugins.spi.J2eePlatformImpl;
063        import org.netbeans.modules.j2ee.deployment.common.api.J2eeLibraryTypeProvider;
064        import org.netbeans.modules.j2ee.deployment.impl.sharability.ServerLibraryTypeProvider;
065        import org.netbeans.spi.project.libraries.LibraryImplementation;
066        import org.netbeans.spi.project.libraries.support.LibrariesSupport;
067        import org.openide.filesystems.FileObject;
068        import org.openide.filesystems.FileUtil;
069        import org.openide.filesystems.URLMapper;
070        import org.openide.util.Parameters;
071        import org.openide.util.Utilities;
072
073        /**
074         * J2eePlatform describes the target environment J2EE applications are build against
075         * and subsequently deployed to. Each server instance defines its own J2EE platform.
076         *
077         * @author Stepan Herold
078         * @since 1.5
079         */
080        public final class J2eePlatform {
081
082            /**
083             * Type of the library created by {@link #createLibrary(File, String)}.
084             * 
085             * @since 1.40
086             */
087            public static final String LIBRARY_TYPE = ServerLibraryTypeProvider.LIBRARY_TYPE;
088
089            /** Display name property */
090            public static final String PROP_DISPLAY_NAME = "displayName"; //NOI18N
091            /** Libraries property */
092            public static final String PROP_LIBRARIES = "libraries"; //NOI18N
093            /** Classpath property */
094            public static final String PROP_CLASSPATH = "classpath"; //NOI18N
095            /** Platform roots property */
096            public static final String PROP_PLATFORM_ROOTS = "platformRoots"; //NOI18N
097
098            /**
099             * Constant for the application runtime tool. The standard properties defined
100             * for this tool are as follows {@link #TOOL_PROP_MAIN_CLASS},
101             * {@link #TOOL_PROP_MAIN_CLASS_ARGS}, {@link #TOOL_PROP_JVM_OPTS}
102             * @since 1.16
103             */
104            public static final String TOOL_APP_CLIENT_RUNTIME = "appClientRuntime"; // NOI18N
105
106            /**
107             * Constant for the JSR109 tool.
108             * @since 1.16
109             */
110            public static final String TOOL_JSR109 = "jsr109"; // NOI18N
111
112            /**
113             * Constant for the WSCOMPILE tool.
114             * @since 1.16
115             */
116            public static final String TOOL_WSCOMPILE = "wscompile"; // NOI18N
117
118            /**
119             * Constant for the WSIMPORT tool.
120             * @since 1.16
121             */
122            public static final String TOOL_WSIMPORT = "wsimport"; // NOI18N
123
124            /**
125             * Constant for the WSGEN tool.
126             * @since 1.16
127             */
128            public static final String TOOL_WSGEN = "wsgen"; // NOI18N
129
130            /**
131             * Constant for the WSIT tool.
132             * @since 1.16
133             */
134            public static final String TOOL_WSIT = "wsit"; // NOI18N
135
136            /**
137             * Constant for the JWSDP tool.
138             * @since 1.16
139             */
140            public static final String TOOL_JWSDP = "jwsdp"; // NOI18N
141
142            /**
143             * Constant for the KEYSTORE tool.
144             * @since 1.16
145             */
146            public static final String TOOL_KEYSTORE = "keystore"; // NOI18N
147
148            /**
149             * Constant for the KEYSTORE_CLIENT tool.
150             * @since 1.16
151             */
152            public static final String TOOL_KEYSTORE_CLIENT = "keystoreClient"; // NOI18N
153
154            /**
155             * Constant for the TRUSTSTORE tool.
156             * @since 1.16
157             */
158            public static final String TOOL_TRUSTSTORE = "truststore"; // NOI18N
159
160            /**
161             * Constant for the TRUSTSTORE_CLIENT tool.
162             * @since 1.16
163             */
164            public static final String TOOL_TRUSTSTORE_CLIENT = "truststoreClient"; // NOI18N
165
166            /**
167             * Constant for the main class tool property.
168             * @since 1.16
169             */
170            public static final String TOOL_PROP_MAIN_CLASS = "main.class"; // NOI18N
171
172            /**
173             * Constant for the main class arguments tool property.
174             * @since 1.16
175             */
176            public static final String TOOL_PROP_MAIN_CLASS_ARGS = "main.class.args"; // NOI18N
177
178            /**
179             * Constant for the JVM options tool property.
180             * @since 1.16
181             */
182            public static final String TOOL_PROP_JVM_OPTS = "jvm.opts"; // NOI18N
183
184            /**
185             * Tool property constant for application client jar location.
186             * @since 1.40
187             */
188            public static final String TOOL_PROP_CLIENT_JAR_LOCATION = "client.jar.location"; // NOI18N
189
190            /**
191             * Constant for the distribution archive client property. Some of the tool
192             * property values may refer to this property.
193             * @since 1.16
194             */
195            public static final String CLIENT_PROP_DIST_ARCHIVE = "client.dist.archive"; // NOI18N
196
197            private static final String DEFAULT_ICON = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/Servers.png"; // NOI18N
198
199            private static final Logger LOGGER = Logger
200                    .getLogger(J2eePlatform.class.getName());
201
202            private J2eePlatformImpl impl;
203            private File[] classpathCache;
204            private String currentClasspath;
205            private ServerInstance serverInstance;
206
207            // listens to libraries content changes
208            private PropertyChangeListener librariesChangeListener = new PropertyChangeListener() {
209                public void propertyChange(PropertyChangeEvent evt) {
210                    if (evt.getPropertyName().equals(
211                            LibraryImplementation.PROP_CONTENT)) {
212                        classpathCache = null;
213                        String newClassPath = getClasspathAsString();
214                        if (currentClasspath == null
215                                || !currentClasspath.equals(newClassPath)) {
216                            currentClasspath = newClassPath;
217                            impl.firePropertyChange(PROP_CLASSPATH, null, null);
218                        }
219                    }
220                }
221            };
222
223            /**
224             * Creates a new instance of J2eePlatform.
225             *
226             * @param aImpl instance of <code>J2eePlatformImpl</code>.
227             */
228            private J2eePlatform(ServerInstance aServerInstance,
229                    J2eePlatformImpl aImpl) {
230                impl = aImpl;
231                serverInstance = aServerInstance;
232                // listens to libraries changes
233                addPropertyChangeListener(new PropertyChangeListener() {
234                    public void propertyChange(PropertyChangeEvent evt) {
235                        if (evt.getPropertyName().equals(PROP_LIBRARIES)) {
236                            LibraryImplementation[] libs = getLibraries();
237                            for (int i = 0; i < libs.length; i++) {
238                                libs[i]
239                                        .removePropertyChangeListener(librariesChangeListener);
240                                libs[i]
241                                        .addPropertyChangeListener(librariesChangeListener);
242                            }
243
244                            classpathCache = null;
245                            String newClassPath = getClasspathAsString();
246                            if (currentClasspath == null
247                                    || !currentClasspath.equals(newClassPath)) {
248                                currentClasspath = newClassPath;
249                                impl.firePropertyChange(PROP_CLASSPATH, null,
250                                        null);
251                            }
252                        }
253                    }
254                });
255                LibraryImplementation[] libs = getLibraries();
256                for (int i = 0; i < libs.length; i++) {
257                    libs[i].addPropertyChangeListener(librariesChangeListener);
258                }
259                currentClasspath = getClasspathAsString();
260            }
261
262            static J2eePlatform create(ServerInstance serInst) {
263                J2eePlatform result = serInst.getJ2eePlatform();
264                if (result == null) {
265                    J2eePlatformImpl platformImpl = serInst
266                            .getJ2eePlatformImpl();
267                    if (platformImpl != null) {
268                        result = new J2eePlatform(serInst, platformImpl);
269                        serInst.setJ2eePlatform(result);
270                    }
271                }
272                return result;
273            }
274
275            /**
276             * Return classpath entries.
277             *
278             * @return classpath entries.
279             */
280            public File[] getClasspathEntries() {
281                if (classpathCache == null) {
282                    LibraryImplementation[] libraries = impl.getLibraries();
283                    List/*<String>*/classpath = new ArrayList();
284                    for (int i = 0; i < libraries.length; i++) {
285                        List classpathList = libraries[i]
286                                .getContent(J2eeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH);
287                        for (Iterator iter = classpathList.iterator(); iter
288                                .hasNext();) {
289                            URL url = (URL) iter.next();
290                            if ("jar".equals(url.getProtocol())) { //NOI18N
291                                url = FileUtil.getArchiveFile(url);
292                            }
293                            FileObject fo = URLMapper.findFileObject(url);
294                            if (fo != null) {
295                                File f = FileUtil.toFile(fo);
296                                if (f != null) {
297                                    classpath.add(f);
298                                }
299                            }
300                        }
301                    }
302                    classpathCache = (File[]) classpath
303                            .toArray(new File[classpath.size()]);
304                }
305                return classpathCache;
306            }
307
308            /**
309             * Return classpath for the specified tool. Use the tool constants declared
310             * in this class.
311             *
312             * @param  toolName tool name, for example {@link #TOOL_APP_CLIENT_RUNTIME}.
313             * @return classpath for the specified tool.
314             */
315            public File[] getToolClasspathEntries(String toolName) {
316                return impl.getToolClasspathEntries(toolName);
317            }
318
319            /**
320             * Returns the property value for the specified tool.
321             * <p>
322             * The property value uses Ant property format and therefore may contain
323             * references to another properties defined either by the client of this API
324             * or by the tool itself.
325             * <p>
326             * The properties the client may be requited to define are as follows
327             * {@link #CLIENT_PROP_DIST_ARCHIVE}
328             *
329             * @param toolName tool name, for example {@link #TOOL_APP_CLIENT_RUNTIME}.
330             * @param propertyName tool property name, for example {@link #TOOL_PROP_MAIN_CLASS}.
331             *
332             * @return property value or null, if the property is not defined for the
333             *         specified tool.
334             *
335             * @since 1.16
336             */
337            public String getToolProperty(String toolName, String propertyName) {
338                return impl.getToolProperty(toolName, propertyName);
339            }
340
341            /**
342             * Specifies whether a tool of the given name is supported by this platform.
343             * Use the tool constants declared in this class.
344             *
345             * @param  toolName tool name, for example {@link #TOOL_APP_CLIENT_RUNTIME}.
346             * @return <code>true</code> if platform supports tool of the given name,
347             *         <code>false</code> otherwise.
348             */
349            public boolean isToolSupported(String toolName) {
350                return impl.isToolSupported(toolName);
351            }
352
353            // this will be made public and will return Library
354            LibraryImplementation[] getLibraries() {
355                return impl.getLibraries();
356            }
357
358            /**
359             * Return platform's display name.
360             *
361             * @return platform's display name.
362             */
363            public String getDisplayName() {
364                // return impl.getDisplayName();
365                // AB: for now return server instance's display name
366                return serverInstance.getDisplayName();
367            }
368
369            /**
370             * Return platform's icon.
371             *
372             * @return platform's icon.
373             * @since 1.6
374             */
375            public Image getIcon() {
376                Image result = impl.getIcon();
377                if (result == null)
378                    result = Utilities.loadImage(DEFAULT_ICON);
379
380                return result;
381            }
382
383            /**
384             * Return platform's root directories. This will be mostly server's installation
385             * directory.
386             *
387             * @return platform's root directories.
388             */
389            public File[] getPlatformRoots() {
390                return impl.getPlatformRoots();
391            }
392
393            /**
394             * Return a list of supported J2EE specification versions. Use J2EE specification
395             * versions defined in the {@link org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule}
396             * class.
397             *
398             * @return list of supported J2EE specification versions.
399             */
400            public Set/*<String>*/getSupportedSpecVersions() {
401                return impl.getSupportedSpecVersions();
402            }
403
404            /**
405             * Return a list of supported J2EE specification versions for
406             * a given module type.
407             *
408             * @param moduleType one of the constants defined in
409             *   {@link org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule}
410             * @return list of supported J2EE specification versions.
411             */
412            public Set<String> getSupportedSpecVersions(Object moduleType) {
413                return impl.getSupportedSpecVersions(moduleType);
414            }
415
416            /**
417             * Return a list of supported J2EE module types. Use module types defined in the
418             * {@link org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule}
419             * class.
420             *
421             * @return list of supported J2EE module types.
422             */
423            public Set/*<Object>*/getSupportedModuleTypes() {
424                return impl.getSupportedModuleTypes();
425            }
426
427            /**
428             * Return a set of J2SE platform versions this J2EE platform can run with.
429             * Versions should be specified as strings i.g. ("1.3", "1.4", etc.)
430             *
431             * @return set of J2SE platform versions this J2EE platform can run with.
432             *
433             * @since 1.9
434             */
435            public Set getSupportedJavaPlatformVersions() {
436                return impl.getSupportedJavaPlatformVersions();
437            }
438
439            /**
440             * Is profiling supported by this J2EE platform?
441             *
442             * @return true, if profiling is supported, false otherwise.
443             *
444             * @since 1.9
445             */
446            public boolean supportsProfiling() {
447                return true;
448            }
449
450            /**
451             * Return server J2SE platform or null if the platform is unknown, not
452             * registered in the IDE.
453             *
454             * @return server J2SE platform or null if the platform is unknown, not
455             *         registered in the IDE.
456             *
457             * @since 1.9
458             */
459            public JavaPlatform getJavaPlatform() {
460                return impl.getJavaPlatform();
461            }
462
463            /**
464             * Register a listener which will be notified when some of the platform's properties
465             * change.
466             *
467             * @param l listener which should be added.
468             */
469            public void addPropertyChangeListener(PropertyChangeListener l) {
470                impl.addPropertyChangeListener(l);
471            }
472
473            /**
474             * Remove a listener registered previously.
475             *
476             * @param l listener which should be removed.
477             */
478            public void removePropertyChangeListener(PropertyChangeListener l) {
479                impl.removePropertyChangeListener(l);
480            }
481
482            public String toString() {
483                return impl.getDisplayName() + " [" + getClasspathAsString()
484                        + "]"; // NOI18N
485            }
486
487            /**
488             * Creates sharable Java library containing all libraries and sources
489             * provided by this platform. All files are copied to shared location and
490             * library is created.
491             *
492             * @param location sharable libraries location
493             * @param libraryName name of the library
494             * @return created library
495             * @throws java.io.IOException if the library can't be created for some reason
496             * @since 1.40
497             */
498            public Library createLibrary(File location, String libraryName)
499                    throws IOException {
500                Parameters.notNull("location", location); // NOI18N
501
502                FileObject libraries = FileUtil.toFileObject(FileUtil
503                        .normalizeFile(location));
504                if (libraries == null) {
505                    throw new IOException("Library folder does not exist"); // NOI18N
506                }
507
508                URL url = URLMapper.findURL(libraries, URLMapper.EXTERNAL);
509
510                LibraryManager manager = LibraryManager.forLocation(url);
511                Map<String, List<URL>> content = new HashMap<String, List<URL>>();
512
513                FileObject baseFolder = libraries.getParent();
514                String folderName = getFolderName(baseFolder, libraryName);
515                FileObject jarFolder = FileUtil.createFolder(baseFolder,
516                        folderName);
517
518                Map<String, Integer> usedNames = new HashMap<String, Integer>();
519                Map<FileObject, String> copied = new HashMap<FileObject, String>();
520
521                List<URL> contentItem = new ArrayList<URL>();
522                content.put(ServerLibraryTypeProvider.VOLUME_CLASSPATH,
523                        contentItem);
524                copyFiles(copied, usedNames, jarFolder, folderName,
525                        getVolumeContent(this ,
526                                J2eeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH),
527                        contentItem);
528
529                contentItem = new ArrayList<URL>();
530                content.put(
531                        ServerLibraryTypeProvider.VOLUME_WS_COMPILE_CLASSPATH,
532                        contentItem);
533                copyFiles(copied, usedNames, jarFolder, folderName,
534                        getToolClasspathEntries(TOOL_WSCOMPILE), contentItem);
535
536                contentItem = new ArrayList<URL>();
537                content.put(
538                        ServerLibraryTypeProvider.VOLUME_WS_GENERATE_CLASSPATH,
539                        contentItem);
540                copyFiles(copied, usedNames, jarFolder, folderName,
541                        getToolClasspathEntries(TOOL_WSGEN), contentItem);
542
543                contentItem = new ArrayList<URL>();
544                content.put(
545                        ServerLibraryTypeProvider.VOLUME_WS_IMPORT_CLASSPATH,
546                        contentItem);
547                copyFiles(copied, usedNames, jarFolder, folderName,
548                        getToolClasspathEntries(TOOL_WSIMPORT), contentItem);
549
550                contentItem = new ArrayList<URL>();
551                content.put(
552                        ServerLibraryTypeProvider.VOLUME_WS_INTEROP_CLASSPATH,
553                        contentItem);
554                copyFiles(copied, usedNames, jarFolder, folderName,
555                        getToolClasspathEntries(TOOL_WSIT), contentItem);
556
557                contentItem = new ArrayList<URL>();
558                content.put(
559                        ServerLibraryTypeProvider.VOLUME_WS_JWSDP_CLASSPATH,
560                        contentItem);
561                copyFiles(copied, usedNames, jarFolder, folderName,
562                        getToolClasspathEntries(TOOL_JWSDP), contentItem);
563
564                contentItem = new ArrayList<URL>();
565                content.put(ServerLibraryTypeProvider.VOLUME_JAVADOC,
566                        contentItem);
567                copyFiles(copied, usedNames, jarFolder, folderName,
568                        getVolumeContent(this ,
569                                J2eeLibraryTypeProvider.VOLUME_TYPE_JAVADOC),
570                        contentItem);
571
572                contentItem = new ArrayList<URL>();
573                content.put(ServerLibraryTypeProvider.VOLUME_SOURCE,
574                        contentItem);
575                copyFiles(copied, usedNames, jarFolder, folderName,
576                        getVolumeContent(this ,
577                                J2eeLibraryTypeProvider.VOLUME_TYPE_SRC),
578                        contentItem);
579
580                return manager.createLibrary(
581                        ServerLibraryTypeProvider.LIBRARY_TYPE, libraryName,
582                        content); // NOI18N
583            }
584
585            private FileObject[] getVolumeContent(J2eePlatform platform,
586                    String volumeType) {
587                LibraryImplementation[] libraries = platform.getLibraries();
588                List<FileObject> ret = new ArrayList<FileObject>();
589                for (int i = 0; i < libraries.length; i++) {
590                    for (URL url : libraries[i].getContent(volumeType)) {
591                        if ("jar".equals(url.getProtocol())) { // NOI18N
592                            url = FileUtil.getArchiveFile(url);
593                        }
594                        FileObject fo = URLMapper.findFileObject(url);
595                        if (fo != null) {
596                            ret.add(fo);
597                        }
598                    }
599                }
600                return ret.toArray(new FileObject[ret.size()]);
601            }
602
603            private void copyFiles(Map<FileObject, String> copied,
604                    Map<String, Integer> usedNames, FileObject jarFolder,
605                    String folderName, File[] files, List<URL> content)
606                    throws IOException {
607
608                if (files == null) {
609                    return;
610                }
611
612                List<FileObject> fileObjects = new ArrayList<FileObject>();
613                for (File jarFile : files) {
614                    File normalized = FileUtil.normalizeFile(jarFile);
615                    FileObject jarObject = FileUtil.toFileObject(normalized);
616                    if (jarObject != null) {
617                        fileObjects.add(jarObject);
618                    } else {
619                        LOGGER.log(Level.INFO, "Could not find " + jarFile); // NOI18N
620                    }
621                }
622                copyFiles(copied, usedNames, jarFolder, folderName, fileObjects
623                        .toArray(new FileObject[fileObjects.size()]), content);
624            }
625
626            private void copyFiles(Map<FileObject, String> copied,
627                    Map<String, Integer> usedNames, FileObject jarFolder,
628                    String folderName, FileObject[] files, List<URL> content)
629                    throws IOException {
630
631                if (files == null) {
632                    return;
633                }
634
635                for (FileObject jarObject : files) {
636                    if (!copied.containsKey(jarObject)) {
637                        String name = jarObject.getName()
638                                + getEntrySuffix(jarObject.getNameExt(),
639                                        usedNames);
640                        if (jarObject.isFolder()) {
641                            FileObject folder = FileUtil.createFolder(
642                                    jarFolder, name);
643                            copyFolder(jarObject, folder);
644                        } else {
645                            FileUtil.copyFile(jarObject, jarFolder, name,
646                                    jarObject.getExt());
647                        }
648                        copied.put(jarObject, jarObject.getNameExt().replace(
649                                jarObject.getName(), name));
650                    }
651                    URL u = LibrariesSupport.convertFilePathToURL(folderName
652                            + File.separator + copied.get(jarObject));
653                    if (!content.contains(u)) {
654                        content.add(u);
655                    }
656                }
657            }
658
659            private void copyFolder(FileObject source, FileObject dest)
660                    throws IOException {
661                assert source.isFolder() : "Source is not a folder"; // NOI18N
662                assert dest.isFolder() : "Source is not a folder"; // NOI18N
663
664                for (FileObject child : source.getChildren()) {
665                    if (child.isFolder()) {
666                        FileObject created = FileUtil.createFolder(dest, child
667                                .getNameExt());
668                        copyFolder(child, created);
669                    } else {
670                        FileUtil.copyFile(child, dest, child.getName(), child
671                                .getExt());
672                    }
673                }
674            }
675
676            private String getEntrySuffix(String realName,
677                    Map<String, Integer> usages) {
678                Integer value = usages.get(realName);
679                if (value == null) {
680                    value = Integer.valueOf(0);
681                } else {
682                    value = Integer.valueOf(value.intValue() + 1);
683                }
684
685                usages.put(realName, value);
686                if (value.intValue() == 0) {
687                    return ""; // NOI18N
688                }
689                return "-" + value.toString();
690            }
691
692            private String getFolderName(FileObject baseFolder,
693                    String libraryName) {
694                int suffix = 2;
695                String baseName = libraryName; //NOI18N
696
697                String name = baseName;
698                while (baseFolder.getFileObject(name) != null) {
699                    name = baseName + "-" + suffix; // NOI18N
700                    suffix++;
701                }
702                return name;
703            }
704
705            private String getClasspathAsString() {
706                File[] classpathEntr = getClasspathEntries();
707                StringBuffer classpath = new StringBuffer();
708                final String PATH_SEPARATOR = System
709                        .getProperty("path.separator"); // NOI18N
710                for (int i = 0; i < classpathEntr.length; i++) {
711                    classpath.append(classpathEntr[i].getAbsolutePath());
712                    if (i + 1 < classpathEntr.length) {
713                        classpath.append(PATH_SEPARATOR);
714                    }
715                }
716                return classpath.toString();
717            }
718        }
w__w___w__._j_a_va___2_s__.___c__o_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.