KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > platform > FallbackDefaultJavaPlatform


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.platform;
21
22 import java.io.File JavaDoc;
23 import java.net.MalformedURLException JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.security.CodeSource JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.Collections JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Map JavaDoc;
31 import java.util.StringTokenizer JavaDoc;
32 import org.netbeans.api.java.classpath.ClassPath;
33 import org.netbeans.api.java.platform.JavaPlatform;
34 import org.netbeans.api.java.platform.Specification;
35 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
36 import org.openide.filesystems.FileObject;
37 import org.openide.filesystems.FileUtil;
38 import org.openide.modules.Dependency;
39
40 /**
41  * Basic impl in case no other providers can be found.
42  * @author Jesse Glick
43  */

44 public class FallbackDefaultJavaPlatform extends JavaPlatform {
45
46     public FallbackDefaultJavaPlatform() {
47         setSystemProperties(System.getProperties());
48     }
49
50     public String JavaDoc getDisplayName() {
51         return System.getProperty("java.vm.vendor") + " " + System.getProperty("java.vm.version"); // NOI18N
52
}
53
54     public Map JavaDoc getProperties() {
55         return Collections.singletonMap("platform.ant.name", "default_platform");
56     }
57
58     private static ClassPath sysProp2CP(String JavaDoc propname) {
59         String JavaDoc sbcp = System.getProperty(propname);
60         if (sbcp == null) {
61             return null;
62         }
63         List JavaDoc/*<URL>*/ roots = new ArrayList JavaDoc();
64         StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(sbcp, File.pathSeparator);
65         while (tok.hasMoreTokens()) {
66             File JavaDoc f = new File JavaDoc(tok.nextToken());
67             if (!f.exists()) {
68                 continue;
69             }
70             URL JavaDoc u;
71             try {
72                 u = f.toURI().toURL();
73             } catch (MalformedURLException JavaDoc x) {
74                 throw new AssertionError JavaDoc(x);
75             }
76             if (FileUtil.isArchiveFile(u)) {
77                 u = FileUtil.getArchiveRoot(u);
78             }
79             roots.add(u);
80         }
81         return ClassPathSupport.createClassPath((URL JavaDoc[]) roots.toArray(new URL JavaDoc[roots.size()]));
82     }
83
84     private static ClassPath sampleClass2CP(Class JavaDoc prototype) {
85         CodeSource JavaDoc cs = prototype.getProtectionDomain().getCodeSource();
86         return ClassPathSupport.createClassPath(cs != null ? new URL JavaDoc[] {cs.getLocation()} : new URL JavaDoc[0]);
87     }
88
89     public ClassPath getBootstrapLibraries() {
90         // XXX ignore standard extensions etc.
91
ClassPath cp = sysProp2CP("sun.boot.class.path"); // NOI18N
92
return cp != null ? cp : sampleClass2CP(Object JavaDoc.class);
93     }
94
95     public ClassPath getStandardLibraries() {
96         ClassPath cp = sysProp2CP("java.class.path"); // NOI18N
97
return cp != null ? cp : sampleClass2CP(/* likely in startup CP */ Dependency.class);
98     }
99
100     public String JavaDoc getVendor() {
101         return System.getProperty("java.vm.vendor");
102     }
103
104     public Specification getSpecification() {
105         return new Specification("J2SE", Dependency.JAVA_SPEC); // NOI18N
106
}
107
108     public Collection JavaDoc getInstallFolders() {
109         return Collections.singleton(FileUtil.toFileObject(new File JavaDoc(System.getProperty("java.home")))); // NOI18N
110
}
111
112     public FileObject findTool(String JavaDoc toolName) {
113         return null; // XXX too complicated, probably unnecessary for this purpose
114
}
115
116     public ClassPath getSourceFolders() {
117         return ClassPathSupport.createClassPath(new URL JavaDoc[0]);
118     }
119
120     public List JavaDoc getJavadocFolders() {
121         return Collections.emptyList();
122     }
123
124 }
125
Popular Tags