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.gsfpath.platform;
043:
044: import java.io.File;
045: import java.net.MalformedURLException;
046: import java.net.URL;
047: import java.security.CodeSource;
048: import java.util.ArrayList;
049: import java.util.Collection;
050: import java.util.Collections;
051: import java.util.List;
052: import java.util.Map;
053: import java.util.StringTokenizer;
054: import org.netbeans.modules.gsfpath.api.classpath.ClassPath;
055: import org.netbeans.modules.gsfpath.api.platform.JavaPlatform;
056: import org.netbeans.modules.gsfpath.api.platform.Specification;
057: import org.netbeans.modules.gsfpath.spi.classpath.support.ClassPathSupport;
058: import org.openide.filesystems.FileObject;
059: import org.openide.filesystems.FileUtil;
060: import org.openide.modules.Dependency;
061: import org.openide.util.NbCollections;
062:
063: /**
064: * Basic impl in case no other providers can be found.
065: * @author Jesse Glick
066: */
067: public class FallbackDefaultJavaPlatform extends JavaPlatform {
068:
069: public FallbackDefaultJavaPlatform() {
070: setSystemProperties(NbCollections.checkedMapByFilter(System
071: .getProperties(), String.class, String.class, false));
072: }
073:
074: public String getDisplayName() {
075: return System.getProperty("java.vm.vendor") + " "
076: + System.getProperty("java.vm.version"); // NOI18N
077: }
078:
079: public Map<String, String> getProperties() {
080: return Collections.singletonMap("platform.ant.name",
081: "default_platform");
082: }
083:
084: private static ClassPath sysProp2CP(String propname) {
085: String sbcp = System.getProperty(propname);
086: if (sbcp == null) {
087: return null;
088: }
089: List<URL> roots = new ArrayList<URL>();
090: StringTokenizer tok = new StringTokenizer(sbcp,
091: File.pathSeparator);
092: while (tok.hasMoreTokens()) {
093: File f = new File(tok.nextToken());
094: if (!f.exists()) {
095: continue;
096: }
097: URL u;
098: try {
099: u = f.toURI().toURL();
100: } catch (MalformedURLException x) {
101: throw new AssertionError(x);
102: }
103: if (FileUtil.isArchiveFile(u)) {
104: u = FileUtil.getArchiveRoot(u);
105: }
106: roots.add(u);
107: }
108: return ClassPathSupport.createClassPath(roots
109: .toArray(new URL[roots.size()]));
110: }
111:
112: private static ClassPath sampleClass2CP(Class prototype) {
113: CodeSource cs = prototype.getProtectionDomain().getCodeSource();
114: return ClassPathSupport
115: .createClassPath(cs != null ? new URL[] { cs
116: .getLocation() } : new URL[0]);
117: }
118:
119: public ClassPath getBootstrapLibraries() {
120: // XXX ignore standard extensions etc.
121: ClassPath cp = sysProp2CP("sun.boot.class.path"); // NOI18N
122: return cp != null ? cp : sampleClass2CP(Object.class);
123: }
124:
125: public ClassPath getStandardLibraries() {
126: ClassPath cp = sysProp2CP("java.class.path"); // NOI18N
127: return cp != null ? cp
128: : sampleClass2CP(/* likely in startup CP */Dependency.class);
129: }
130:
131: public String getVendor() {
132: return System.getProperty("java.vm.vendor");
133: }
134:
135: public Specification getSpecification() {
136: return new Specification("J2SE", Dependency.JAVA_SPEC); // NOI18N
137: }
138:
139: public Collection<FileObject> getInstallFolders() {
140: return Collections.singleton(FileUtil.toFileObject(new File(
141: System.getProperty("java.home")))); // NOI18N
142: }
143:
144: public FileObject findTool(String toolName) {
145: return null; // XXX too complicated, probably unnecessary for this purpose
146: }
147:
148: public ClassPath getSourceFolders() {
149: return ClassPathSupport.createClassPath(new URL[0]);
150: }
151:
152: public List<URL> getJavadocFolders() {
153: return Collections.emptyList();
154: }
155:
156: }
|