private void setExplicitJavaPlatform(final AntProjectHelper helper, final ProjectImportModel model) { Element pcd = helper.getPrimaryConfigurationData(true); NodeList sourceRootNodes = pcd.getElementsByTagNameNS(J2SEProject.PROJECT_CONFIGURATION_NAMESPACE, "source-roots"); //NOI18N assert sourceRootNodes.getLength() == 1 : "Broken project.xml file"; // NOI18N Element el = pcd.getOwnerDocument().createElementNS(J2SEProject.PROJECT_CONFIGURATION_NAMESPACE, "explicit-platform"); // NOI18N el.setAttribute("explicit-source-supported", "true"); // NOI18N pcd.insertBefore(el, sourceRootNodes.item(0)); helper.putPrimaryConfigurationData(pcd, true); EditableProperties prop = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); String ver = model.getJavaPlatform().getSpecification().getVersion().toString(); String normalizedName = model.getJavaPlatform().getProperties().get("platform.ant.name"); // NOI18N prop.setProperty(ProjectProperties.PLATFORM_ACTIVE, normalizedName); helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, prop); }
public ClassPathProviderImpl(AntProjectHelper helper, PropertyEvaluator evaluator, SourceRoots sourceRoots, SourceRoots testSourceRoots) { this.helper = helper; this.projectDirectory = FileUtil.toFile(helper.getProjectDirectory()); assert this.projectDirectory != null; this.evaluator = evaluator; this.sourceRoots = sourceRoots; this.testSourceRoots = testSourceRoots; this.bootClassPathImpl = new BootClassPathImplementation(evaluator); evaluator.addPropertyChangeListener(WeakListeners.propertyChange(this, evaluator)); }
private FileObject getSharedLibraryFolderLocation() { String libLoc = helper.getLibrariesLocation(); if (libLoc != null) { String libLocEval = evaluator.evaluate(libLoc); File file = null; if (libLocEval != null) { file = helper.resolveFile(libLocEval); } FileObject libLocFO = FileUtil.toFileObject(file); if (libLocFO != null) { //#126366 this can happen when people checkout the project but not the libraries description //that is located outside the project FileObject libLocParent = libLocFO.getParent(); return libLocParent; } } return null; }
private FileObject getFileObject(String propname) { String prop = helper.getStandardPropertyEvaluator().getProperty(propname); if (prop != null) { return helper.resolveFileObject(prop); } else { return null; } }
/** * Updates property file at given location of ant based project * @param h helper of the project * @param path a relative URI in the project directory * @param ep new or updated properties */ public static void updateProperties(AntProjectHelper h, String path, EditableProperties ep) { EditableProperties properties = h.getProperties(path); properties.putAll(ep); h.putProperties(path, properties); }
private File getFile(String propname) { String prop = helper.getStandardPropertyEvaluator().getProperty(propname); if (prop != null) { return helper.resolveFile(prop); } return null; }
public void run() { Element data = helper.getPrimaryConfigurationData(true); // XXX replace by XMLUtil when that has findElement, findText, etc. NodeList nl = data.getElementsByTagNameNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); //NOI18N Element nameEl; if (nl.getLength() == 1) { nameEl = (Element) nl.item(0); NodeList deadKids = nameEl.getChildNodes(); while (deadKids.getLength() > 0) { nameEl.removeChild(deadKids.item(0)); } } else { nameEl = data.getOwnerDocument().createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); //NOI18N data.insertBefore(nameEl, /* OK if null */data.getChildNodes().item(0)); } nameEl.appendChild(data.getOwnerDocument().createTextNode(name)); helper.putPrimaryConfigurationData(data, true); } });
/** * Updates the project helper with the list of classpath items which are to be * included in deployment. */ private static void putIncludedLibraries( List<Item> classpath, AntProjectHelper antProjectHelper, String webModuleLibraries ) { assert antProjectHelper != null; assert webModuleLibraries != null; Element data = antProjectHelper.getPrimaryConfigurationData( true ); Document doc = data.getOwnerDocument(); Element webModuleLibs = (Element) data.getElementsByTagNameNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, webModuleLibraries).item(0); if (webModuleLibs == null) { webModuleLibs = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, webModuleLibraries); //NOI18N data.appendChild(webModuleLibs); } while (webModuleLibs.hasChildNodes()) { webModuleLibs.removeChild(webModuleLibs.getChildNodes().item(0)); } for (Item item : classpath) { webModuleLibs.appendChild(createLibraryElement(antProjectHelper, doc, CommonProjectUtils.getAntPropertyName( item.getReference() ), item)); } antProjectHelper.putPrimaryConfigurationData( data, true ); }
final EjbJarProject prj = (EjbJarProject) ProjectManager.getDefault().findProject(h.getProjectDirectory()); final ReferenceHelper referenceHelper = prj.getReferenceHelper(); Element data = h.getPrimaryConfigurationData(true); Document doc = data.getOwnerDocument(); Element nameEl = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); // NOI18N nameEl.appendChild(doc.createTextNode(name)); data.appendChild(nameEl); EditableProperties ep = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); EditableProperties epPriv = h.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); Element sourceRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N if (srcRoot != null) { h.putPrimaryConfigurationData(data, true); h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); String ref = createFileReference(referenceHelper, dirFO, FileUtil.toFileObject(configFiles)); EditableProperties props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); props.setProperty(EjbJarProjectProperties.META_INF, ref); h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); String ref = createFileReference(referenceHelper, dirFO, FileUtil.toFileObject(libraries)); EditableProperties props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); props.setProperty(EjbJarProjectProperties.LIBRARIES_DIR, ref); h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); h.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, epPriv); Project p = ProjectManager.getDefault().findProject(dirFO);
Element data = uh.createAuxiliaryConfiguration().getConfigurationFragment("data",ns,true); if(data != null) { Element webModuleLibs = (Element) data.getElementsByTagNameNS(ns, webModuleLibraries).item(0); if (webModuleLibs != null) { NodeList ch = webModuleLibs.getChildNodes(); for (int i = 0; i < ch.getLength(); i++) { if (ch.item(i).getNodeType() == Node.ELEMENT_NODE) { Element library = (Element) ch.item(i); String dirs = library.getAttribute(ATTR_DIRS); if (!AntProjectConstants.DESTINATION_DIRECTORY_ROOT.equals(dirs) && !AntProjectConstants.DESTINATION_DIRECTORY_LIB.equals(dirs) && NodeList pathInWarElements = library.getElementsByTagNameNS(ns, TAG_PATH_IN_WAR); String webFileText = XMLUtil.findText(webFile); webFileText = webFileText.substring(2, webFileText.length() - 1); String pathInWar = PATH_IN_WAR_NONE; if (pathInWarElements.getLength() > 0) { pathInWar = XMLUtil.findText((Element) pathInWarElements.item(0)); if (pathInWar == null) pathInWar = ""; warIncludesMap.put(webFileText, pathInWarElements.getLength() > 0 ? XMLUtil.findText((Element) pathInWarElements.item(0)) : PATH_IN_WAR_NONE);
private void updateProjectXML () throws IOException { Element element = aux.getConfigurationFragment("data","http://www.netbeans.org/ns/EjbJar-project/1",true); //NOI18N if (element != null) { Document doc = element.getOwnerDocument(); Element newRoot = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N XMLUtil.copyDocument (element, newRoot, EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE); Element srcRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "source-roots"); //NOI18N Element root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N root.setAttribute ("id","src.dir"); //NOI18N srcRoots.appendChild(root); newRoot.appendChild (srcRoots); Element tstRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); //NOI18N root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N root.setAttribute ("id","test.src.dir"); //NOI18N tstRoots.appendChild (root); newRoot.appendChild (tstRoots); helper.putPrimaryConfigurationData (newRoot, true); ProjectManager.getDefault().saveProject(this); } }
/** * Returns a list with the classpath items which are to be included * in deployment. */ private static List<String> getIncludedLibraries( AntProjectHelper antProjectHelper, String includedLibrariesElement, Map<String, String> destination) { assert antProjectHelper != null; assert includedLibrariesElement != null; Element data = antProjectHelper.getPrimaryConfigurationData( true ); NodeList libs = data.getElementsByTagNameNS( EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, includedLibrariesElement ); List<String> libraries = new ArrayList<String>(libs.getLength()); for ( int i = 0; i < libs.getLength(); i++ ) { Element item = (Element)libs.item( i ); // ejbjar is different from other j2ee projects - it stores reference without ${ and } String ref = "${"+XMLUtil.findText( item )+"}"; libraries.add(ref); // NOI18N String dirs = item.getAttribute(ATTR_DIRS); if (AntProjectConstants.DESTINATION_DIRECTORY_ROOT.equals(dirs) || AntProjectConstants.DESTINATION_DIRECTORY_LIB.equals(dirs) || AntProjectConstants.DESTINATION_DIRECTORY_DO_NOT_COPY.equals(dirs)) { destination.put(ref, dirs); } } return libraries; }
public String getWsdlSource(String serviceName) { Element data = helper.getPrimaryConfigurationData(true); String wsdlSource = null; Element clientElement = getWebServiceClientNode(data, serviceName); if(clientElement != null) { NodeList fromWsdlList = clientElement.getElementsByTagNameNS( EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesConstants.CLIENT_SOURCE_URL); if(fromWsdlList.getLength() == 1) { Element fromWsdlElement = (Element) fromWsdlList.item(0); NodeList nl = fromWsdlElement.getChildNodes(); if(nl.getLength() == 1) { org.w3c.dom.Node n = nl.item(0); if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) { wsdlSource = n.getNodeValue(); } } } } return wsdlSource; }
/** * Updates the project helper with the list of classpath items which are to be * included in deployment. */ private static void putIncludedLibraries(List<Item> classpath, AntProjectHelper antProjectHelper, String includedLibrariesElement) { assert antProjectHelper != null; assert includedLibrariesElement != null; Element data = antProjectHelper.getPrimaryConfigurationData( true ); NodeList libs = data.getElementsByTagNameNS( AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, includedLibrariesElement ); while ( libs.getLength() > 0 ) { Node n = libs.item( 0 ); n.getParentNode().removeChild( n ); } Document doc = data.getOwnerDocument(); //find a correcponding classpath item for the library for (ClassPathSupport.Item item : classpath) { if("true".equals(item.getAdditionalProperty(INCLUDE_IN_DEPLOYMENT))) { // NOI18N data.appendChild(createLibraryElement(antProjectHelper, doc, item, includedLibrariesElement)); } } antProjectHelper.putPrimaryConfigurationData( data, true ); }
/** * Updates the project helper with the list of classpath items which are to be * included in deployment. */ private static void putIncludedLibraries(List<ClassPathSupport.Item> classpath, AntProjectHelper antProjectHelper, String includedLibrariesElement ) { assert antProjectHelper != null; assert includedLibrariesElement != null; Element data = antProjectHelper.getPrimaryConfigurationData( true ); NodeList libs = data.getElementsByTagNameNS( EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, includedLibrariesElement ); while ( libs.getLength() > 0 ) { Node n = libs.item( 0 ); n.getParentNode().removeChild( n ); } Document doc = data.getOwnerDocument(); for (ClassPathSupport.Item item : classpath) { if("true".equals(item.getAdditionalProperty(INCLUDE_IN_DEPLOYMENT))) { // NOI18N XMLUtil.appendChildElement(data, createLibraryElement(antProjectHelper, doc, item, includedLibrariesElement), ejbjarElemOrder); } } antProjectHelper.putPrimaryConfigurationData( data, true ); }
public void saveLicenseFile() throws IOException { if (licenseContent != null) { assert licensePath != null; //path needs to exist once we have content? String evaluated = evaluator.evaluate(licensePath); assert evaluated != null; File file = antHelper.resolveFile(evaluated); FileObject fo; if (!file.exists()) { fo = FileUtil.createData(file); } else { fo = FileUtil.toFileObject(file); } OutputStream out = fo.getOutputStream(); try { FileUtil.copy(new ByteArrayInputStream(licenseContent.getBytes()), out); } finally { out.close(); } } }
@Messages("TXT_AlreadyExists=<html>The file {0} already exists in the library folder.<br>Using the existing file.") private void updateReference(File oldFile, String key, boolean main, FileObject dir) { final FileObject src = FileUtil.toFileObject(oldFile); if (src == null) { assert !oldFile.exists() : "The file: " + oldFile.getAbsolutePath() + " exists but FileObject cannot be found."; //NOI18N newFile = FileUtil.copyFile(src, dir, src.getName()); newFile = src; File absFile = FileUtil.toFile(newFile); String newVal = PropertyUtils.relativizeFile(FileUtil.toFile(ahelper.getProjectDirectory()), absFile); if (newVal == null) {
@Messages("ERR_LibraryExists=The library {0} already exists, reusing the old definition.") public void actionPerformed(ActionEvent e) { String loc = helper.getLibrariesLocation(); assert loc != null; File mainPropertiesFile = helper.resolveFile(loc); try { LibraryManager man = LibraryManager.forLocation(Utilities.toURI(mainPropertiesFile).toURL()); if ("jar".equals(url.getProtocol())) { // NOI18N jarFolder = getJarFolder(URI.create(url.toExternalForm())); url = FileUtil.getArchiveFile(url); if (fo != null) { if (keepRelativeLocations) { File path = FileUtil.toFile(fo); String str = PropertyUtils.relativizeFile(mainPropertiesFile.getParentFile(), path); if (str == null) { File path = FileUtil.toFile(fo); uri = Utilities.toURI(path);
public void updateFileChangeListener() { File resolvedFile; FileObject fo = null; String propertyValue = helper.getStandardPropertyEvaluator().getProperty(propertyName); if (propertyValue != null) { String resolvedPath = helper.resolvePath(propertyValue); resolvedFile = new File(resolvedPath).getAbsoluteFile(); File f = resolvedFile; while (f != null && (fo = FileUtil.toFileObject(f)) == null) { f = f.getParentFile(); } watchRename = f == resolvedFile; } else { resolvedFile = null; watchRename = false; } setFileObject(fo); }
public void invalidateClassFile(FileObject jsp) { String dir = getAntProjectHelper().getStandardPropertyEvaluator().getProperty(WebProjectProperties.BUILD_GENERATED_DIR); if (dir == null) { return; } dir = dir + "/src"; //NOI18N WebModule wm = WebModule.getWebModule(jsp); if (wm == null) { return; } String name = Utils.getServletName(wm.getDocumentBase(), jsp); String filePath = name.substring(0, name.lastIndexOf('.')).replace('.', '/'); String fileClass = dir + '/' + filePath + ".class"; //NOI18N String fileJava = dir + '/' + filePath + ".java"; //NOI18N FileObject fC = FileUtil.toFileObject(getAntProjectHelper().resolveFile(fileClass)); FileObject fJ = FileUtil.toFileObject(getAntProjectHelper().resolveFile(fileJava)); try { if ((fJ != null) && (fJ.isValid())) { fJ.delete(); } if ((fC != null) && (fC.isValid())) { fC.delete(); } } catch (IOException e) { Exceptions.printStackTrace(e); } }