Java Code Examples for org.netbeans.api.project.ProjectUtils#getAuxiliaryConfiguration()

The following examples show how to use org.netbeans.api.project.ProjectUtils#getAuxiliaryConfiguration() . 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: LibraryPersistence.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Loads library information for the given project.
 *
 * @param project project whose library information should be loaded.
 * @return library information for the given project.
 */
public Library.Version[] loadLibraries(Project project) {
    Library.Version[] libraries;
    AuxiliaryConfiguration config = ProjectUtils.getAuxiliaryConfiguration(project);
    Element element = config.getConfigurationFragment(ELEMENT_LIBRARIES, NAMESPACE_URI, true);
    if (element == null) {
        libraries = new Library.Version[0];
    } else{
        NodeList libraryList = element.getElementsByTagNameNS(NAMESPACE_URI, ELEMENT_LIBRARY);
        libraries = new Library.Version[libraryList.getLength()];
        for (int i=0; i<libraryList.getLength(); i++) {
            Element libraryElement = (Element)libraryList.item(i);
            libraries[i] = loadLibrary(libraryElement);
        }
    }
    return libraries;
}
 
Example 2
Source File: AbstractLogicalViewProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean isVisualWebLegacyProject() {
    boolean isLegacyProject = false;

    // Check if Web module is a visualweb 5.5.x or Creator project
    AuxiliaryConfiguration ac = ProjectUtils.getAuxiliaryConfiguration(project);
    Element auxElement = ac.getConfigurationFragment("creator-data", "http://www.sun.com/creator/ns", true); //NOI18N

    // if project is a visualweb or creator project then find out whether it is a legacy project
    if (auxElement != null) {
        String version = auxElement.getAttribute("jsf.project.version"); //NOI18N
        if (version != null) {
            if (!version.equals("4.0")) { //NOI18N
                isLegacyProject = true;
            }
        }
    }

    return isLegacyProject;
}
 
Example 3
Source File: ReferenceHelper.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a library manager of the given project.
 * There is no guarantee that the manager is the same object from call to call
 * even if the project is the same; in particular, it is <em>not</em> guaranteed that
 * the manager match that returned from {@link Library#getManager} for libraries added
 * from {@link #createLibraryReference}.
 * @return a library manager associated with project's libraries or null if project is 
 *  not shared (will not include {@link LibraryManager#getDefault})
 *  {@link LibraryManager#getDefault})
 * @since org.netbeans.modules.project.ant/1 1.19
 */
public static LibraryManager getProjectLibraryManager(Project p) {
    AuxiliaryConfiguration aux = ProjectUtils.getAuxiliaryConfiguration(p);
    File libFile = ProjectLibraryProvider.getLibrariesLocation(aux, 
            FileUtil.toFile(p.getProjectDirectory()));
    if (libFile != null) {
        try {
            return LibraryManager.forLocation(BaseUtilities.toURI(libFile).toURL());
        } catch (MalformedURLException e) {
            // ok, no project manager
            Logger.getLogger(ReferenceHelper.class.getName()).info(
                "library manager cannot be found for "+libFile+". "+e.toString()); //NOI18N
        }
    }
    return null;
}
 
Example 4
Source File: AuxiliaryConfigImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testFallbackAuxiliaryConfigurationExists() throws Exception {
    Project prj = new PrjNoAC();
    AuxiliaryConfiguration ac = ProjectUtils.getAuxiliaryConfiguration(prj);
    assertNotNull(ac);
    String namespace = "http://nowhere.net/test";
    assertNull(ac.getConfigurationFragment("x", namespace, true));
    ac.putConfigurationFragment(makeElement("x", namespace), true);
    Element e = ac.getConfigurationFragment("x", namespace, true);
    assertNotNull(e);
    assertEquals("x", e.getLocalName());
    assertEquals(namespace, e.getNamespaceURI());
    assertNull(ac.getConfigurationFragment("x", namespace, false));
    ac.removeConfigurationFragment("x", namespace, true);
    assertNull(ac.getConfigurationFragment("x", namespace, true));
    ac.putConfigurationFragment(makeElement("y", namespace), false);
    prj = new PrjNoAC();
    ac = ProjectUtils.getAuxiliaryConfiguration(prj);
    e = ac.getConfigurationFragment("y", namespace, false);
    assertNotNull(e);
    assertEquals("y", e.getLocalName());
    assertEquals(namespace, e.getNamespaceURI());
}
 
Example 5
Source File: LibraryPersistence.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Stores the information about libraries used by the given project.
 *
 * @param project project whose library information should be stored.
 * @param libraries libraries used by the project.
 */
void storeLibraries(Project project, Library.Version[] libraries) throws IOException {
    Arrays.sort(libraries, new LibraryVersionComparator());
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.newDocument();
        Element librariesElement = document.createElementNS(NAMESPACE_URI, ELEMENT_LIBRARIES);
        for (Library.Version library : libraries) {
            Element libraryElement = document.createElementNS(NAMESPACE_URI, ELEMENT_LIBRARY);
            String libraryName = library.getLibrary().getName();
            libraryElement.setAttribute(ATTR_LIBRARY_NAME, libraryName);
            String versionName = library.getName();
            libraryElement.setAttribute(ATTR_VERSION_NAME, versionName);
            String[] files = library.getFiles();
            String[] localFiles = library.getLocalFiles();
            for (int i=0; i<files.length; i++) {
                Element fileElement = document.createElementNS(NAMESPACE_URI, ELEMENT_FILE);
                String path = files[i];
                String localPath = localFiles[i];
                fileElement.setAttribute(ATTR_FILE_PATH, path);
                fileElement.setAttribute(ATTR_FILE_LOCAL_PATH, localPath);
                libraryElement.appendChild(fileElement);
            }
            librariesElement.appendChild(libraryElement);
        }
        AuxiliaryConfiguration config = ProjectUtils.getAuxiliaryConfiguration(project);
        config.putConfigurationFragment(librariesElement, true);
        ProjectManager.getDefault().saveProject(project);

        logLibraryUsage(libraries);

        // fire event
        libraryListenerSupport.fireLibrariesChanged(project);
    } catch (ParserConfigurationException pcex) {
        Logger.getLogger(LibraryPersistence.class.getName()).log(Level.SEVERE,
                "Unable to store library information!", pcex); // NOI18N
    }
}
 
Example 6
Source File: Wadl2JavaHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static String getProjectType(Project project) {
    RestSupport restSupport = project.getLookup().lookup(RestSupport.class);

    if (restSupport != null) {
        int projectType = restSupport.getProjectType();
        if (projectType == RestSupport.PROJECT_TYPE_WEB) {
            return PROJEC_TYPE_WEB;
        } else if (projectType == RestSupport.PROJECT_TYPE_NB_MODULE) {
            return PROJEC_TYPE_NB_MODULE;
        }
    } else {
        AuxiliaryConfiguration aux = ProjectUtils.getAuxiliaryConfiguration(project);
        for (int i=1;i<10;i++) {
            // be prepared for namespace upgrade
            if (aux.getConfigurationFragment("data", //NOI18N
                    "http://www.netbeans.org/ns/nb-module-project/"+String.valueOf(i), //NOI18N
                    true) != null) {
                return PROJEC_TYPE_NB_MODULE;
            } else if (aux.getConfigurationFragment("data", //NOI18N
                    "http://www.netbeans.org/ns/web-project/"+String.valueOf(i), //NOI18N
                    true) != null) {
                return PROJEC_TYPE_WEB;
            }
        }
    }
    return PROJEC_TYPE_DESKTOP;
}
 
Example 7
Source File: ComponentPeer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static synchronized DictionaryImpl getProjectDictionary(Project p, Locale locale) {
    Reference<DictionaryImpl> r = project2Reference.get(p);
    DictionaryImpl d = r != null ? r.get() : null;
    
    if (d == null) {
        AuxiliaryConfiguration ac = ProjectUtils.getAuxiliaryConfiguration(p);
        project2Reference.put(p, new WeakReference<DictionaryImpl>(d = new DictionaryImpl(p, ac, locale)));
    }
    
    return d;
}
 
Example 8
Source File: ProjectUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Set<String> getOpenFilesUrls(Project p, String groupName) {
    AuxiliaryConfiguration aux = ProjectUtils.getAuxiliaryConfiguration(p);
    
    Element openFiles = aux.getConfigurationFragment (OPEN_FILES_ELEMENT, OPEN_FILES_NS2, false);
    if (openFiles == null) {
        return Collections.emptySet();
    }

    Element groupEl = null;
    
    NodeList groups = openFiles.getElementsByTagNameNS(OPEN_FILES_NS2, GROUP_ELEMENT);
    for (int i = 0; i < groups.getLength(); i++) {
        Element g = (Element) groups.item(i);
        String attr = g.getAttribute(NAME_ATTR);
        if (attr.equals(groupName) || (attr.equals("") && groupName == null)) {
            groupEl = g;
            break;
        }
    }
    
    if (groupEl == null) {
        return Collections.emptySet();
    }
    
    NodeList list = groupEl.getElementsByTagNameNS(OPEN_FILES_NS2, FILE_ELEMENT);
    Set<String> toRet = new HashSet<String>();
    for (int i = 0; i < list.getLength (); i++) {
        String url = list.item (i).getChildNodes ().item (0).getNodeValue ();
        toRet.add(url);
    }    
    return toRet;
}
 
Example 9
Source File: AuxiliaryConfigImplTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testSharedStorage() throws Exception {
    Project prj = new PrjNoAC();
    AuxiliaryConfiguration ac = ProjectUtils.getAuxiliaryConfiguration(prj);
    ac.putConfigurationFragment(makeElement("x", "one"), true);
    ac.putConfigurationFragment(makeElement("x", "two"), true);
    ac.putConfigurationFragment(makeElement("y", "two"), true);
    ac.putConfigurationFragment(makeElement("y", "one"), true);
    FileObject netbeansXml = prjdir.getFileObject(AuxiliaryConfigImpl.AUX_CONFIG_FILENAME);
    assertNotNull(netbeansXml);
    assertEquals("<auxiliary-configuration xmlns=\"http://www.netbeans.org/ns/auxiliary-configuration/1\">" +
            "<x xmlns=\"one\"/>" +
            "<x xmlns=\"two\"/>" +
            "<y xmlns=\"one\"/>" +
            "<y xmlns=\"two\"/>" +
            "</auxiliary-configuration>",
            loadXML(netbeansXml));
    Element x = makeElement("x", "two");
    x.appendChild(x.getOwnerDocument().createElementNS("two", "xx"));
    ac.putConfigurationFragment(x, true);
    ac.removeConfigurationFragment("y", "one", true);
    assertEquals("<auxiliary-configuration xmlns=\"http://www.netbeans.org/ns/auxiliary-configuration/1\">" +
            "<x xmlns=\"one\"/>" +
            "<x xmlns=\"two\"><xx/></x>" +
            "<y xmlns=\"two\"/>" +
            "</auxiliary-configuration>",
            loadXML(netbeansXml));
}
 
Example 10
Source File: AuxiliaryConfigImplTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testPrivateStorage() throws Exception {
    Project prj = new PrjNoAC();
    AuxiliaryConfiguration ac = ProjectUtils.getAuxiliaryConfiguration(prj);
    ac.putConfigurationFragment(makeElement("x", "ns"), false);
    String attr = AuxiliaryConfigImpl.AUX_CONFIG_ATTR_BASE + ".ns#x";
    assertEquals("<x xmlns=\"ns\"/>", prjdir.getAttribute(attr));
    Element x = makeElement("x", "ns");
    x.appendChild(x.getOwnerDocument().createElementNS("ns", "xx"));
    ac.putConfigurationFragment(x, false);
    assertEquals("<x xmlns=\"ns\"><xx/></x>", prjdir.getAttribute(attr));
    ac.removeConfigurationFragment("x", "ns", false);
    assertEquals(null, prjdir.getAttribute(attr));
}
 
Example 11
Source File: CoverageProviderHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static boolean isEnabled(Project project) {
    AuxiliaryConfiguration config = ProjectUtils.getAuxiliaryConfiguration(project);
    Element configurationFragment = config.getConfigurationFragment("coverage", COVERAGE_NAMESPACE_URI, false); // NOI18N
    if (configurationFragment == null) {
        return false;
    }
    return configurationFragment.getAttribute("enabled").equals("true"); // NOI18N
}
 
Example 12
Source File: CoverageProviderHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static boolean isAggregating(Project project) {
    AuxiliaryConfiguration config = ProjectUtils.getAuxiliaryConfiguration(project);
    Element configurationFragment = config.getConfigurationFragment("coverage", COVERAGE_NAMESPACE_URI, false); // NOI18N
    if (configurationFragment == null) {
        return false;
    }
    return configurationFragment.getAttribute("aggregating").equals("true"); // NOI18N
}
 
Example 13
Source File: ProjectConfigFileManagerImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public ProjectConfigFileManagerImpl(Project project) {
    this.project = project;
    auxConfig = ProjectUtils.getAuxiliaryConfiguration(project);
}
 
Example 14
Source File: UsageLogger.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static Object[] data(Project p) throws Exception {
    ProjectAccessor accessor = p.getLookup().lookup(ProjectAccessor.class);
    if (accessor == null) {
        throw new IllegalArgumentException("no ProjectAccessor");
    }
    AntProjectHelper helper = accessor.getHelper();
    PropertyEvaluator eval = accessor.getEvaluator();
    AuxiliaryConfiguration aux = ProjectUtils.getAuxiliaryConfiguration(p);
    int compilationUnits = 0;
    int compilationUnitsMissingBuiltTo = 0;
    int compilationUnitsMultipleRoots = 0;
    Set<String> classpathEntries = new HashSet<String>();
    Element java = JavaProjectGenerator.getJavaCompilationUnits(aux);
    if (java != null) {
        for (Element compilationUnitEl : XMLUtil.findSubElements(java)) {
            compilationUnits++;
            int builtTos = 0;
            int roots = 0;
            for (Element other : XMLUtil.findSubElements(compilationUnitEl)) {
                String name = other.getLocalName();
                if (name.equals("package-root")) { // NOI18N
                    roots++;
                } else if (name.equals("built-to")) { // NOI18N
                    builtTos++;
                } else if (name.equals("classpath")) { // NOI18N
                    String text = XMLUtil.findText(other);
                    if (text != null) {
                        String textEval = eval.evaluate(text);
                        if (textEval != null) {
                            for (String entry : textEval.split("[:;]")) {
                                if (entry.length() > 0) {
                                    classpathEntries.add(entry);
                                }
                            }
                        }
                    }
                }
            }
            if (builtTos == 0) {
                compilationUnitsMissingBuiltTo++;
            }
            if (roots > 1) {
                compilationUnitsMultipleRoots++;
            }
        }
    }
    int targets = 0;
    {
        String antScriptS = eval.getProperty(ProjectConstants.PROP_ANT_SCRIPT);
        if (antScriptS == null) {
            antScriptS = "build.xml"; // NOI18N
        }
        FileObject antScript = FileUtil.toFileObject(helper.resolveFile(antScriptS));
        if (antScript != null) {
            AntProjectCookie apc = DataObject.find(antScript).getLookup().lookup(AntProjectCookie.class);
            if (apc != null) {
                try {
                    targets = TargetLister.getTargets(apc).size();
                } catch (IOException ioe) {
                    //pass - Broken build.xml which may happen for freeform, targets = 0 and log usage
                }
            }
        }
    }
    boolean webData = aux.getConfigurationFragment("web-data", "http://www.netbeans.org/ns/freeform-project-web/2", true) != null || // NOI18N
            aux.getConfigurationFragment("web-data", "http://www.netbeans.org/ns/freeform-project-web/1", true) != null; // NOI18N
    /* XXX takes about 1msec per source file to count them, even with a warm disk cache:
    int sourceFiles = 0;
    for (SourceGroup g : ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
        for (FileObject kid : NbCollections.iterable(g.getRootFolder().getChildren(true))) {
            if (kid.hasExt("java")) { // NOI18N
                sourceFiles++;
            }
        }
    }
     */
    // XXX other things which could be reported:
    // number of <properties>s (other than the original project location sometimes inserted by the New Project wizard) or <property-file>s defined
    // number of <view-item>s (other than those inserted by the GUI) defined
    // whether a custom Java platform is configured for the project
    // number of subprojects (i.e. classpath entries corresponding to project-owned sources)
    // number of context-sensitive actions defined
    // number of targets bound to non-context-sensitive actions
    return new Object[] { // Bundle.properties#USG_FREEFORM_PROJECT must match these fields
        someOrMany(compilationUnits),
        someOrMany(compilationUnitsMissingBuiltTo),
        someOrMany(compilationUnitsMultipleRoots),
        someOrMany(classpathEntries.size()),
        someOrMany(targets),
        webData,
    };
}
 
Example 15
Source File: J2SEProjectJaxRpcClientSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public List getServiceClients() {
    
    List<WsCompileClientEditorSupport.ServiceSettings> serviceNames = new ArrayList<WsCompileClientEditorSupport.ServiceSettings>();
    AuxiliaryConfiguration aux = ProjectUtils.getAuxiliaryConfiguration(project);
    Element clientElements = aux.getConfigurationFragment(WebServicesClientConstants.WEB_SERVICE_CLIENTS,
                                JAX_RPC_NAMESPACE, true);
    if (clientElements!=null) {
        NodeList clientNameList = clientElements.getElementsByTagNameNS(
                JAX_RPC_NAMESPACE, WebServicesClientConstants.WEB_SERVICE_CLIENT_NAME);

        for(int i = 0; i < clientNameList.getLength(); i++ ) {
            Element clientNameElement = (Element) clientNameList.item(i);
            NodeList nl = clientNameElement.getChildNodes();
            if(nl.getLength() == 1) {
                org.w3c.dom.Node n = nl.item(0);
                if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) {
                    EditableProperties projectProperties = null;
                    try {
                        projectProperties = WSUtils.getEditableProperties(project, AntProjectHelper.PROJECT_PROPERTIES_PATH);
                    } catch (IOException ex) {
                        
                    }
                    // this may happen when deleting client
                    if (projectProperties == null) continue;
                    
                    String serviceName = n.getNodeValue();
                    String currentFeatures = projectProperties.getProperty("wscompile.client." + serviceName + ".features"); //NOI18N
                    if(currentFeatures == null) {
                        // !PW should probably retrieve default features for stub type.
                        // For now, this will work because this is the same value we'd get doing that.
                        //
                        // Defaults if we can't find any feature property for this client
                        // Mostly for upgrading EA1, EA2 projects which did not have
                        // this property, but also useful if the user deletes it from
                        // project.properties.
                        currentFeatures = "wsi, strict";
                    }
                    ClientStubDescriptor stubType = getClientStubDescriptor(clientNameElement.getParentNode());
                    boolean propVerbose = "true".equalsIgnoreCase( //NOI18N
                            projectProperties.getProperty("wscompile.client." + serviceName + ".verbose")); //NOI18N
                    boolean propDebug = "true".equalsIgnoreCase( //NOI18N
                            projectProperties.getProperty("wscompile.client." + serviceName + ".debug")); //NOI18N                
                    boolean propPrintStackTrace = "true".equalsIgnoreCase( //NOI18N
                            projectProperties.getProperty("wscompile.client." + serviceName + ".xPrintStackTrace")); //NOI18N
                    boolean propExtensible = "true".equalsIgnoreCase( //NOI18N
                            projectProperties.getProperty("wscompile.client." + serviceName + ".xSerializable")); //NOI18N
                    boolean propOptimize = "true".equalsIgnoreCase( //NOI18N
                            projectProperties.getProperty("wscompile.client." + serviceName + ".optimize")); //NOI18N
                    boolean[] options = new boolean[] { //NOI18N
                        propVerbose,propDebug,propPrintStackTrace,propExtensible,propOptimize
                    };
                    WsCompileClientEditorSupport.ServiceSettings settings = new WsCompileClientEditorSupport.ServiceSettings(
                    serviceName, stubType, options, currentFeatures, allClientFeatures, importantClientFeatures);
                    serviceNames.add(settings);
                    
                    
                } else {
                    // !PW FIXME node is wrong type?! - log message or trace?
                }
            } else {
                // !PW FIXME no name for this service entry - notify user
            }
        }      
    }
    
    return serviceNames;
}