|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun * Microsystems, Inc. All Rights Reserved. */ package org.openide.execution; import java.io.File; import java.util.*; import org.openide.filesystems.*; import org.openide.util.Lookup; /** Property that can hold informations about class path and * that can be used to create string representation of the * class path. */ public final class NbClassPath extends Object implements java.io.Serializable { /** A JDK 1.1 serial version UID */ static final long serialVersionUID = -8458093409814321744L; /** Fuj: This is the most overloaded variable in this class. * It can hold Object[] with elements of String or Exception * or later Exception[] array. * * Also the array can hold File[] array. */ private Object[] items; /** the prepared classpath */ private String classpath; /** Create a new descriptor for the specified process, classpath switch, and classpath. * @param classpathItems the classpath to be passed to the process */ public NbClassPath (String[] classpathItems) { this.items = classpathItems; } /** Create a new descriptor for the specified process, classpath switch, and classpath. * @param classpathItems the classpath to be passed to the process */ public NbClassPath (File[] classpathItems) { this.items = classpathItems; } /** Private constructor * @param arr array of String and Exceptions */ private NbClassPath (Object[] arr) { this.items = arr; } /** Create a class path from the usual string representation. * @param path a class path separated by {@link File#pathSeparatorChar}s */ public NbClassPath (String path) { this.items = new Exception[0]; this.classpath = path; // [PENDING] what is this here for? *Users* of the classpath should quote it as needed to // pass thru shells, according to the type of shell. Right? if (path.indexOf(' ') >= 0) { if (path.startsWith("\"")) { // NOI18N return; } else { StringBuffer buff = new StringBuffer(path); buff.insert(0, '"'); buff.append('"'); classpath = buff.toString(); } } } /** Method to obtain class path for the current state of the repository. * The classpath should be scanned for all occured exception caused * by file systems that cannot be converted to class path by a call to * method getExceptions(). * * * @return class path for all reachable systems in the repository * @deprecated Please use the ClassPath API instead. */ public static NbClassPath createRepositoryPath () { Thread.dumpStack(); return createRepositoryPath (FileSystemCapability.ALL); } /** Method to obtain class path for the current state of the repository. * The classpath should be scanned for all occured exception caused * by file systems that cannot be converted to class path by a call to * method getExceptions(). * * * @param cap the capability that must be satisfied by the file system * added to the class path * @return class path for all reachable systems in the repository * @deprecated Please use the ClassPath API instead. */ public static NbClassPath createRepositoryPath (FileSystemCapability cap) { Thread.dumpStack(); final LinkedList res = new LinkedList (); final class Env extends FileSystem.Environment { /* method of interface Environment */ public void addClassPath(String element) { res.add (element); } } Env env = new Env (); Enumeration en = cap.fileSystems (); while (en.hasMoreElements ()) { try { FileSystem fs = (FileSystem)en.nextElement (); fs.prepareEnvironment(env); } catch (EnvironmentNotSupportedException ex) { // store the exception res.add (ex); } } // return it return new NbClassPath (res.toArray ()); } /** Creates class path describing additional libraries needed by the system. * Never use this class path as part of a user project! * For more information consult the Module Class Path document. * @deprecated There are generally no excuses to be using this method as part of a normal module; * its exact meaning is vague, and probably not what you want. */ public static NbClassPath createLibraryPath () { Thread.dumpStack(); // modules & libs ExecutionEngine ee = (ExecutionEngine)Lookup.getDefault().lookup(ExecutionEngine.class); if (ee != null) { return ee.createLibraryPath(); } else { return new NbClassPath(new File[0]); } } /** Creates class path of the system. * Never use this class path as part of a user project! * For more information consult the Module Class Path document. * @deprecated There are generally no excuses to be using this method as part of a normal module; * its exact meaning is vague, and probably not what you want. */ public static NbClassPath createClassPath () { Thread.dumpStack(); // ${java.class.path} minus openide-compat.jar String cp = System.getProperty ("java.class.path"); // NOI18N if (cp == null || cp.length () == 0) return new NbClassPath (""); // NOI18N StringBuffer buf = new StringBuffer (cp.length ()); StringTokenizer tok = new StringTokenizer (cp, File.pathSeparator); boolean appended = false; while (tok.hasMoreTokens ()) { String piece = tok.nextToken (); if (piece.endsWith ("openide-compat.jar")) continue; // NOI18N if (appended) { buf.append (File.pathSeparatorChar); } else { appended = true; } buf.append (piece); } return new NbClassPath (buf.toString ()); } /** Creates path describing boot class path of the system. * Never use this class path as part of a user project! * There are generally no excuses to be using this method as part of a normal module. * For more information consult the Module Class Path document. * @return class path of system class including extensions * @deprecated Use the Java Platform API instead. */ public static NbClassPath createBootClassPath () { Thread.dumpStack(); // boot String boot = System.getProperty("sun.boot.class.path"); // NOI18N StringBuffer sb = (boot != null ? new StringBuffer(boot) : new StringBuffer()); // std extensions String extensions = System.getProperty("java.ext.dirs"); // NOI18N if (extensions != null) { for (StringTokenizer st = new StringTokenizer(extensions, File.pathSeparator); st.hasMoreTokens();) { File dir = new File(st.nextToken()); File[] entries = dir.listFiles(); if (entries != null) { for (int i = 0; i < entries.length; i++) { String name = entries[i].getName().toLowerCase(Locale.US); if (name.endsWith(".zip") || name.endsWith(".jar")) { // NOI18N if (sb.length() > 0) { sb.append(File.pathSeparatorChar); } sb.append(entries[i].getPath()); } } } } } return new NbClassPath (sb.toString()); } /** Take one file object and try to convert it into a local file. * @param fo file object to convert * @return disk file for that file object, or |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.