Java Code Examples for org.netbeans.spi.project.support.ant.PropertyUtils#tokenizePath()
The following examples show how to use
org.netbeans.spi.project.support.ant.PropertyUtils#tokenizePath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Util.java From netbeans with Apache License 2.0 | 6 votes |
public static String removeNBArtifacts( @NonNull final String key, @NullAllowed String value) { if (value != null && "java.class.path".equals(key)) { //NOI18N String nbHome = System.getProperty("netbeans.home"); //NOI18N if (nbHome != null) { if (!nbHome.endsWith(File.separator)) { nbHome = nbHome + File.separatorChar; } final String[] elements = PropertyUtils.tokenizePath(value); final List<String> newElements = new ArrayList<>(elements.length); for (String element : elements) { if (!element.startsWith(nbHome)) { newElements.add(element); } } if (elements.length != newElements.size()) { value = newElements.stream() .collect(Collectors.joining(File.pathSeparator)); } } } return value; }
Example 2
Source File: Util.java From netbeans with Apache License 2.0 | 6 votes |
private static String filterProbe (String v, final String probePath) { if (v != null) { final String[] pes = PropertyUtils.tokenizePath(v); final StringBuilder sb = new StringBuilder (); for (String pe : pes) { if (probePath != null ? probePath.equals(pe) : (pe != null && pe.endsWith("org-netbeans-modules-java-j2seplatform-probe.jar"))) { //NOI18N //Skeep } else { if (sb.length() > 0) { sb.append(File.pathSeparatorChar); } sb.append(pe); } } v = sb.toString(); } return v; }
Example 3
Source File: Classpaths.java From netbeans with Apache License 2.0 | 6 votes |
/** * Create a classpath from a <classpath> element. */ private List<URL> createClasspath( final Element classpathEl, final Function<URL,Collection<URL>> translate) { String cp = XMLUtil.findText(classpathEl); if (cp == null) { cp = ""; } String cpEval = evaluator.evaluate(cp); if (cpEval == null) { return Collections.emptyList(); } final String[] path = PropertyUtils.tokenizePath(cpEval); final List<URL> res = new ArrayList<>(); for (String pathElement : path) { res.addAll(translate.apply(createClasspathEntry(pathElement))); } return res; }
Example 4
Source File: ModuleDependency.java From netbeans with Apache License 2.0 | 6 votes |
/** * Return a set of tokens that can be used to search for this dependency. * Per UI spec, includes lower-case versions of: * <ol> * <li>the code name base * <li>the localized display name * <li> the full path to the module JAR or any Class-Path extension * <li> the fully-qualified class name (use . for inner classes) of any class * contained in the module JAR or any Class-Path extension which is in an package * which would be made available to the depending module when using a specification version dependency * </ol> * Note that the last item means that this can behave differently according to the depending * module (according to whether or not it would be listed as a friend). * @param dependingModuleCNB the CNB of the module depending on this one */ public Set<String> getFilterTokens(String dependingModuleCNB) { boolean friend = me.isDeclaredAsFriend(dependingModuleCNB); Set<String> filterTokens = friend ? filterTokensFriend : filterTokensNotFriend; if (filterTokens == null) { filterTokens = new HashSet<String>(); filterTokens.add(me.getCodeNameBase()); filterTokens.add(me.getLocalizedName()); filterTokens.add(me.getJarLocation().getAbsolutePath()); String[] cpext = PropertyUtils.tokenizePath(me.getClassPathExtensions()); filterTokens.addAll(Arrays.asList(cpext)); if (friend) { for (String clazz : me.getPublicClassNames()) { filterTokens.add(clazz.replace('$', '.')); } } if (friend) { filterTokensFriend = filterTokens; } else { filterTokensNotFriend = filterTokens; } } return filterTokens; }
Example 5
Source File: TranslateClassPath.java From netbeans with Apache License 2.0 | 6 votes |
private String translate(String classpath) { StringBuilder cp = new StringBuilder(); boolean first = true; boolean disableSources = Boolean.valueOf(getProject().getProperty("maven.disableSources")); for (String path : PropertyUtils.tokenizePath(classpath)) { File[] files = translateEntry(path, disableSources); if (files.length == 0) { //TODO: log // LOG.log(Level.FINE, "cannot translate {0} to file", e.getURL().toExternalForm()); continue; } for (File f : files) { if (!first) { cp.append(File.pathSeparatorChar); } cp.append(f.getAbsolutePath()); first = false; } } return cp.toString(); }
Example 6
Source File: J2SEProjectClassPathModifierTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testAddRemoveRoot () throws Exception { final FileObject rootFolder = this.scratch.createFolder("Root"); final FileObject jarFile = TestFileUtils.writeZipFile(scratch, "archive.jar", "Test.properties:"); final FileObject jarRoot = FileUtil.getArchiveRoot(jarFile); ProjectClassPathModifier.addRoots (new URL[] {rootFolder.toURL()}, this.src, ClassPath.COMPILE); String cp = this.eval.getProperty("javac.classpath"); assertNotNull (cp); String[] cpRoots = PropertyUtils.tokenizePath (cp); assertNotNull (cpRoots); assertEquals(1,cpRoots.length); assertEquals(rootFolder,this.helper.resolveFileObject(cpRoots[0])); ProjectClassPathModifier.removeRoots (new URL[] {rootFolder.toURL()},this.src, ClassPath.COMPILE); cp = this.eval.getProperty("javac.classpath"); assertNotNull (cp); cpRoots = PropertyUtils.tokenizePath (cp); assertNotNull (cpRoots); assertEquals(0,cpRoots.length); ProjectClassPathModifier.addRoots(new URL[] {jarRoot.toURL()},this.test,ClassPath.EXECUTE); cp = this.eval.getProperty("run.test.classpath"); assertNotNull (cp); cpRoots = PropertyUtils.tokenizePath (cp); assertNotNull (cpRoots); assertEquals(5,cpRoots.length); assertEquals(this.helper.resolveFileObject(cpRoots[4]),jarFile); }
Example 7
Source File: ProjectClassPathImplementation.java From netbeans with Apache License 2.0 | 6 votes |
private List<PathResourceImplementation> getPath() { List<PathResourceImplementation> result = new ArrayList<>(); for (String p : propertyNames) { String prop = evaluator.getProperty(p); if (prop != null) { for (String piece : PropertyUtils.tokenizePath(prop)) { File f = PropertyUtils.resolveFile(projectFolder, piece); URL entry = FileUtil.urlForArchiveOrDir(f); if (entry != null) { result.add(ClassPathSupport.createResource(entry)); } else { Logger.getLogger(ProjectClassPathImplementation.class.getName()).log(Level.WARNING, "{0} does not look like a valid archive file", f); } } } } return Collections.unmodifiableList(result); }
Example 8
Source File: J2SEProjectClassPathModifierTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testAddRemoveLibrary () throws Exception { LibraryProvider lp = Lookup.getDefault().lookup(LibraryProvider.class); assertNotNull (lp); LibraryImplementation[] impls = lp.getLibraries(); assertNotNull (impls); assertEquals(1,impls.length); FileObject libRoot = this.scratch.createFolder("libRoot"); impls[0].setContent("classpath",Collections.singletonList(libRoot.toURL())); Library[] libs =LibraryManager.getDefault().getLibraries(); assertNotNull (libs); assertEquals(1,libs.length); ProjectClassPathModifier.addLibraries(libs, this.src, ClassPath.COMPILE); String cp = this.eval.getProperty("javac.classpath"); assertNotNull (cp); String[] cpRoots = PropertyUtils.tokenizePath (cp); assertNotNull (cpRoots); assertEquals(1,cpRoots.length); assertEquals("${libs.Test.classpath}",cpRoots[0]); //There is no build.properties filled, the libraries are not resolved ProjectClassPathModifier.removeLibraries(libs,this.src, ClassPath.COMPILE); cp = this.eval.getProperty("javac.classpath"); assertNotNull (cp); cpRoots = PropertyUtils.tokenizePath (cp); assertNotNull (cpRoots); assertEquals(0,cpRoots.length); }
Example 9
Source File: TestBase2.java From netbeans with Apache License 2.0 | 6 votes |
public final ClassPath createClassPath(String property) throws MalformedURLException, IOException { String path = System.getProperty("web.project.jars"); if ( path == null ){ path = ""; } String[] st = PropertyUtils.tokenizePath(path); List<FileObject> fos = new ArrayList<FileObject>(); for (int i=0; i<st.length; i++) { String token = st[i]; File f = new File(token); if (!f.exists()) { fail("cannot find file "+token); } FileObject fo = FileUtil.toFileObject(f); fos.add(FileUtil.getArchiveRoot(fo)); } return ClassPathSupport.createClassPath(fos.toArray(new FileObject[fos.size()])); }
Example 10
Source File: ProjectFactorySupport.java From netbeans with Apache License 2.0 | 6 votes |
/** * Add given value to given classpath-like Ant property. */ private static void addToBuildProperties(AntProjectHelper helper, String property, String valueToAppend) { EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); String cp = ep.getProperty(property); if (cp == null) { cp = ""; //NOI18N } else { cp += ":"; //NOI18N } cp += valueToAppend; String[] arr = PropertyUtils.tokenizePath(cp); for (int i = 0; i < arr.length - 1; i++) { arr[i] += ":"; //NOI18N } ep.setProperty(property, arr); helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); }
Example 11
Source File: TestBase2.java From netbeans with Apache License 2.0 | 5 votes |
public final void initParserJARs() throws MalformedURLException { String path = System.getProperty("jsp.parser.jars"); String[] paths = PropertyUtils.tokenizePath(path); List<URL> list = new ArrayList(); for (int i = 0; i< paths.length; i++) { String token = paths[i]; File f = new File(token); if (!f.exists()) { fail("cannot find file "+token); } list.add(f.toURI().toURL()); } JspParserImpl.setParserJARs(list.toArray(new URL[list.size()])); }
Example 12
Source File: ClassPathProviderImpl.java From netbeans with Apache License 2.0 | 5 votes |
private void addPathFromProjectEvaluated(List<PathResourceImplementation> entries, String path) { if (path != null) { for (String piece : PropertyUtils.tokenizePath(path)) { URL url = FileUtil.urlForArchiveOrDir(project.getHelper().resolveFile(piece)); if (url != null) { // #135292 entries.add(ClassPathSupport.createResource(url)); } } } }
Example 13
Source File: ApisupportAntUtils.java From netbeans with Apache License 2.0 | 5 votes |
public static URL[] findURLs(final String path) { if (path == null) { return new URL[0]; } String[] pieces = PropertyUtils.tokenizePath(path); URL[] urls = new URL[pieces.length]; for (int i = 0; i < pieces.length; i++) { // XXX perhaps also support http: URLs somehow? urls[i] = FileUtil.urlForArchiveOrDir(FileUtil.normalizeFile(new File(pieces[i]))); } return urls; }
Example 14
Source File: JWSProjectProperties.java From netbeans with Apache License 2.0 | 5 votes |
/** * Tokenize classpath read from project.properties * * @param ep EditableProperties to access raw property contents * @param eval PropertyEvaluator to access dereferenced property contents * @param classPathProp name of classpath property to read from * @return collection of path pairs, key is the raw item, value is the dereferenced item */ private static Map<String,String> getClassPathItems(final EditableProperties ep, final PropertyEvaluator eval, String classPathProp) { String cpEdit = ep.getProperty(classPathProp); String cpEval = eval.getProperty(classPathProp); String pEdit[] = PropertyUtils.tokenizePath( cpEdit == null ? "" : cpEdit ); // NOI18N String pEval[] = PropertyUtils.tokenizePath( cpEval == null ? "" : cpEval ); // NOI18N if(pEdit.length != pEval.length) { LOG.log(Level.WARNING, NbBundle.getMessage(JWSProjectProperties.class, "ERR_ClassPathProblem", classPathProp)); //NOI18N } Map<String,String> map = new LinkedHashMap<String,String>(); for(int i = 0; i < pEdit.length && i < pEval.length; i++) { map.put(pEdit[i], pEval[i]); } return map; }
Example 15
Source File: Utils.java From netbeans with Apache License 2.0 | 5 votes |
/** * Correct given classpath, that means remove obsolete properties, add missing ones etc. * If the given parameter is <code>null</code> or empty, the default debug classpath is returned. * @return corrected classpath, never <code>null</code>. * @see #getDefaultClassPath() */ public static String correctDebugClassPath(String debugClassPath) { if (debugClassPath == null || debugClassPath.length() == 0) { // should not happen return Utils.getDefaultDebugClassPath(); } // "invalid" strings final String buildEarWebDir = "${build.ear.web.dir}"; // NOI18N final String buildEarClassesDir = "${build.ear.classes.dir}"; // NOI18N final String buildEarPrefix = "${build.ear."; // NOI18N if (!debugClassPath.contains(buildEarPrefix)) { return debugClassPath; } StringBuilder buffer = new StringBuilder(debugClassPath.length()); for (String token : PropertyUtils.tokenizePath(debugClassPath)) { // check NB 5.5.x obsolete properties if (!buildEarWebDir.equals(token) && !buildEarClassesDir.equals(token)) { if (buffer.length() > 0) { buffer.append(":"); // NOI18N } buffer.append(token); } } return buffer.toString(); }
Example 16
Source File: ModuleRoots.java From netbeans with Apache License 2.0 | 5 votes |
public String getRootPath(String rootPathProperty) { String prop = evaluator.getProperty(rootPathProperty); if (prop != null) { StringBuilder sb = new StringBuilder(); for (String propElement : PropertyUtils.tokenizePath(prop)) { if (sb.length() > 0) { sb.append(':'); } sb.append(propElement); } return sb.toString(); } return ""; //NOI18N }
Example 17
Source File: ModuleList.java From netbeans with Apache License 2.0 | 5 votes |
private static File[] findModulesInSuite(File root, PropertyEvaluator eval) throws IOException { String modulesS = eval.getProperty("modules"); // NOI18N if (modulesS == null) { modulesS = ""; // NOI18N } String[] modulesA = PropertyUtils.tokenizePath(modulesS); File[] modules = new File[modulesA.length]; for (int i = 0; i < modulesA.length; i++) { modules[i] = PropertyUtils.resolveFile(root, modulesA[i]); } return modules; }
Example 18
Source File: WebProjectWebServicesSupport.java From netbeans with Apache License 2.0 | 4 votes |
private boolean updateWsCompileProperties(String serviceName) { /** Ensure wscompile.classpath and wscompile.tools.classpath are * properly defined. * * wscompile.classpath goes in project properties and includes * jaxrpc and qname right now. * * wscompile.tools.classpath is for tools.jar which is needed when * running under the Sun JDK to invoke javac. It is placed in * user.properties so that if we compute it incorrectly (say on a mac) * the user can change it and we will not blow away the change. * Hopefully we can do this better for release. */ boolean globalPropertiesChanged = false; EditableProperties globalProperties = PropertyUtils.getGlobalProperties(); if(globalProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) { globalProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); // NOI18N try { PropertyUtils.putGlobalProperties(globalProperties); } catch(IOException ex) { NotifyDescriptor desc = new NotifyDescriptor.Message( NbBundle.getMessage(WebProjectWebServicesSupport.class,"MSG_ErrorSavingGlobalProperties", serviceName, ex.getMessage()), // NOI18N NotifyDescriptor.ERROR_MESSAGE); DialogDisplayer.getDefault().notify(desc); } globalPropertiesChanged = true; } boolean projectPropertiesChanged = false; EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); { // Block that adjusts wscompile.client.classpath as necessary. HashSet<String> wscJars = new HashSet<String>(); boolean newWscJars = false; String wscClientClasspath = projectProperties.getProperty(WSCOMPILE_CLASSPATH); if(wscClientClasspath != null) { String [] libs = PropertyUtils.tokenizePath(wscClientClasspath); for(int i = 0; i < libs.length; i++) { wscJars.add(libs[i]); } } for(int i = 0; i < WSCOMPILE_JARS.length; i++) { if(!wscJars.contains(WSCOMPILE_JARS[i])) { wscJars.add(WSCOMPILE_JARS[i]); newWscJars = true; } } if(newWscJars) { StringBuffer newClasspathBuf = new StringBuffer(256); for(Iterator iter = wscJars.iterator(); iter.hasNext(); ) { newClasspathBuf.append(iter.next()); if(iter.hasNext()) { newClasspathBuf.append(':'); } } projectProperties.put(WSCOMPILE_CLASSPATH, newClasspathBuf.toString()); projectPropertiesChanged = true; } } // set tools.jar property if not set if(projectProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) { projectProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); // NOI18N projectPropertiesChanged = true; } if(projectPropertiesChanged) { helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties); } return globalPropertiesChanged || projectPropertiesChanged; }
Example 19
Source File: AppClientProjectWebServicesClientSupport.java From netbeans with Apache License 2.0 | 4 votes |
private boolean updateWsCompileProperties(String serviceName) { /** Ensure wscompile.classpath and wscompile.tools.classpath are * properly defined. * * wscompile.classpath goes in project properties and includes * jaxrpc and qname right now. * * wscompile.tools.classpath is for tools.jar which is needed when * running under the Sun JDK to invoke javac. It is placed in * user.properties so that if we compute it incorrectly (say on a mac) * the user can change it and we will not blow away the change. * Hopefully we can do this better for release. */ boolean globalPropertiesChanged = false; EditableProperties globalProperties = PropertyUtils.getGlobalProperties(); if(globalProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) { globalProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); // NOI18N try { PropertyUtils.putGlobalProperties(globalProperties); } catch(IOException ex) { NotifyDescriptor desc = new NotifyDescriptor.Message( NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"MSG_ErrorSavingGlobalProperties", serviceName, ex.getMessage()), // NOI18N NotifyDescriptor.ERROR_MESSAGE); DialogDisplayer.getDefault().notify(desc); } globalPropertiesChanged = true; } boolean projectPropertiesChanged = false; EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); { // Block that adjusts wscompile.client.classpath as necessary. Set<String> wscJars = new HashSet<String>(); boolean newWscJars = false; String wscClientClasspath = projectProperties.getProperty(WSCOMPILE_CLASSPATH); if(wscClientClasspath != null) { String [] libs = PropertyUtils.tokenizePath(wscClientClasspath); for(int i = 0; i < libs.length; i++) { wscJars.add(libs[i]); } } for(int i = 0; i < WSCOMPILE_JARS.length; i++) { if(!wscJars.contains(WSCOMPILE_JARS[i])) { wscJars.add(WSCOMPILE_JARS[i]); newWscJars = true; } } if(newWscJars) { StringBuffer newClasspathBuf = new StringBuffer(256); for(Iterator iter = wscJars.iterator(); iter.hasNext(); ) { newClasspathBuf.append(iter.next().toString()); if(iter.hasNext()) { newClasspathBuf.append(':'); } } projectProperties.put(WSCOMPILE_CLASSPATH, newClasspathBuf.toString()); projectPropertiesChanged = true; } } // set tools.jar property if not set if(projectProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) { projectProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); // NOI18N projectPropertiesChanged = true; } if(projectPropertiesChanged) { helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties); } return globalPropertiesChanged || projectPropertiesChanged; }
Example 20
Source File: EjbJarWebServicesClientSupport.java From netbeans with Apache License 2.0 | 4 votes |
private boolean updateWsCompileProperties(String serviceName) { /** Ensure wscompile.classpath and wscompile.tools.classpath are * properly defined. * * wscompile.classpath goes in project properties and includes * jaxrpc and qname right now. * * wscompile.tools.classpath is for tools.jar which is needed when * running under the Sun JDK to invoke javac. It is placed in * user.properties so that if we compute it incorrectly (say on a mac) * the user can change it and we will not blow away the change. * Hopefully we can do this better for release. */ boolean globalPropertiesChanged = false; EditableProperties globalProperties = PropertyUtils.getGlobalProperties(); if(globalProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) { globalProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); // NOI18N try { PropertyUtils.putGlobalProperties(globalProperties); } catch(java.io.IOException ex) { String mes = "Error saving global properties when adding wscompile.tools.classpath for service '" + serviceName + "'\r\n" + ex.getMessage(); // NOI18N NotifyDescriptor desc = new NotifyDescriptor.Message(mes, NotifyDescriptor.Message.ERROR_MESSAGE); DialogDisplayer.getDefault().notify(desc); } globalPropertiesChanged = true; } boolean projectPropertiesChanged = false; EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); { // Block that adjusts wscompile.client.classpath as necessary. HashSet<String> wscJars = new HashSet<String>(); boolean newWscJars = false; String wscClientClasspath = projectProperties.getProperty(WSCOMPILE_CLASSPATH); if(wscClientClasspath != null) { String[] libs = PropertyUtils.tokenizePath(wscClientClasspath); for(int i = 0; i < libs.length; i++) { wscJars.add(libs[i]); } } for(int i = 0; i < WSCOMPILE_JARS.length; i++) { if(!wscJars.contains(WSCOMPILE_JARS[i])) { wscJars.add(WSCOMPILE_JARS[i]); newWscJars = true; } } if(newWscJars) { StringBuffer newClasspathBuf = new StringBuffer(256); for(Iterator iter = wscJars.iterator(); iter.hasNext(); ) { newClasspathBuf.append(iter.next().toString()); if(iter.hasNext()) { newClasspathBuf.append(":"); // NOI18N } } projectProperties.put(WSCOMPILE_CLASSPATH, newClasspathBuf.toString()); projectPropertiesChanged = true; } } // set tools.jar property if not set if(projectProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) { projectProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); // NOI18N projectPropertiesChanged = true; } if(projectPropertiesChanged) { helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties); } return globalPropertiesChanged || projectPropertiesChanged; }