org.netbeans.api.project.ProjectManager Java Examples

The following examples show how to use org.netbeans.api.project.ProjectManager. 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: SingleModulePropertiesTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testGetPublicPackages() throws Exception {
    final NbModuleProject p = generateStandaloneModule("module1");
    FileUtil.createData(p.getSourceDirectory(), "org/example/module1/One.java");
    FileUtil.createData(p.getSourceDirectory(), "org/example/module1/resources/Two.java");
    
    // apply and save project
    boolean result = ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Boolean>() {
        public Boolean run() throws IOException {
            ProjectXMLManager pxm = new ProjectXMLManager(p);
            pxm.replacePublicPackages(Collections.singleton("org.example.module1"));
            return true;
        }
    });
    assertTrue("replace public packages", result);
    ProjectManager.getDefault().saveProject(p);
    
    SingleModuleProperties props = loadProperties(p);
    PublicPackagesTableModel pptm = props.getPublicPackagesModel();
    assertEquals("number of available public packages", 2, pptm.getRowCount());
    assertEquals("number of selected public packages", 1, pptm.getSelectedPackages().size());
}
 
Example #2
Source File: UpdateTask.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void updateBuildProperties() {
    ProjectManager.mutex().postWriteRequest(
        new Runnable () {
            public void run () {
                try {
                    final EditableProperties ep = PropertyUtils.getGlobalProperties();
                    boolean save = updateSourceLevel(ep);
                    save |= updateBuildProperties (ep);
                    if (save) {
                        PropertyUtils.putGlobalProperties (ep);
                    }
                } catch (IOException ioe) {
                    Exceptions.printStackTrace(ioe);
                }
            }
        });
}
 
Example #3
Source File: MavenSourcesImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testManuallyDeletedSourceGroup() throws Exception { // #204545
    TestFileUtils.writeFile(d, "pom.xml", "<project><modelVersion>4.0.0</modelVersion><groupId>g</groupId><artifactId>a</artifactId><version>0</version></project>");
    FileObject main = FileUtil.createFolder(d, "src/main/java");
    FileObject test = FileUtil.createFolder(d, "src/test/java");
    Project p = ProjectManager.getDefault().findProject(d);
    Sources s = ProjectUtils.getSources(p);
    SourceGroup[] grps = s.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    assertEquals(2, grps.length);
    assertEquals(main, grps[0].getRootFolder());
    assertEquals(test, grps[1].getRootFolder());
    MockChangeListener l = new MockChangeListener();
    s.addChangeListener(l);
    test.getParent().delete();
    l.assertEvent();
    grps = s.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    assertEquals(1, grps.length);
    assertEquals(main, grps[0].getRootFolder());
}
 
Example #4
Source File: NbModuleProjectTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testGetPlatformVersionedLocation() throws Exception {
    File plafdir = new File(getWorkDir(), "plaf");
    TestFileUtils.writeZipFile(new File(plafdir, "platform/core/core.jar"), "j:unk");
    File harnessdir = new File(getWorkDir(), "harness");
    TestFileUtils.writeZipFile(new File(harnessdir, "modules/org-netbeans-modules-apisupport-harness.jar"), "META-INF/MANIFEST.MF:OpenIDE-Module-Specification-Version: 1.23\n");
    File suitedir = new File(getWorkDir(), "suite");
    SuiteProjectGenerator.createSuiteProject(suitedir, "_", false);
    FileObject suitedirFO = FileUtil.toFileObject(suitedir);
    FileObject plafProps = suitedirFO.getFileObject("nbproject/platform.properties");
    EditableProperties ep = Util.loadProperties(plafProps);
    ep.setProperty("suite.dir", "${basedir}");
    ep.remove("nbplatform.active");
    ep.setProperty("nbplatform.active.dir", "${suite.dir}/../plaf");
    ep.setProperty("harness.dir", "${suite.dir}/../harness");
    ep.setProperty("cluster.path", new String[] {"${nbplatform.active.dir}/platform:", "${harness.dir}"});
    Util.storeProperties(plafProps, ep);
    File moduledir = new File(getWorkDir(), "suite/m");
    NbModuleProjectGenerator.createSuiteComponentModule(moduledir, "m", "m", "m/Bundle.properties", null, suitedir, false, false);
    NbModuleProject p = (NbModuleProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(moduledir));
    NbPlatform plaf = p.getPlatform(true);
    assertEquals(plafdir, plaf.getDestDir());
    assertEquals(harnessdir, plaf.getHarnessLocation());
    assertEquals(HarnessVersion.V70, plaf.getHarnessVersion());
}
 
Example #5
Source File: ProjectModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Create project model of existing project. Useful for project customization. */
public static ProjectModel createModel(final File baseFolder, final File nbProjectFolder, final PropertyEvaluator evaluator, final AntProjectHelper helper) {
    return ProjectManager.mutex().readAccess(new Mutex.Action<ProjectModel>() {
        public ProjectModel run() {
            ProjectModel pm = new ProjectModel(
                    baseFolder, 
                    nbProjectFolder, 
                    evaluator,
                    // reads only "java" type because other types are not editable in UI
                    JavaProjectGenerator.getSourceFolders(helper, TYPE_JAVA),
                    JavaProjectGenerator.getJavaCompilationUnits(helper,
                        Util.getAuxiliaryConfiguration(helper))
                );
            // only "java" type of sources was read so fix style to "pacakges" on all
            updateStyle(pm.sourceFolders);
            return pm;
        }
    });
}
 
Example #6
Source File: MavenSourcesImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testFragmentaryResourceDecl() throws Exception { // #195928
    TestFileUtils.writeFile(d,
            "pom.xml",
            "<project xmlns='http://maven.apache.org/POM/4.0.0'>" +
            "<modelVersion>4.0.0</modelVersion>" +
            "<groupId>grp</groupId>" +
            "<artifactId>art</artifactId>" +
            "<packaging>jar</packaging>" +
            "<version>1.0-SNAPSHOT</version>" +
            "<build>" +
            "<resources>" +
            "<resource>" +
            "<directory>.</directory>" +
            "<targetPath>META-INF</targetPath>" +
            "<includes>" +
            "<include>changelog.txt</include>" +
            "</includes>" +
            "</resource>" +
            "</resources>" +
            "</build>" +
            "</project>");
    SourceGroup[] grps = ProjectUtils.getSources(ProjectManager.getDefault().findProject(d)).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_RESOURCES);
    assertEquals(0, grps.length);
}
 
Example #7
Source File: ParentVersionErrorTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testSpecialRelativePath() throws Exception { // #194281
    TestFileUtils.writeFile(work, "common.xml", "<project xmlns='http://maven.apache.org/POM/4.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd'>\n" +
            "    <modelVersion>4.0.0</modelVersion>\n" +
            "    <groupId>grp</groupId>\n" +
            "    <artifactId>common</artifactId>\n" +
            "    <version>1.0</version>\n" +
            "</project>\n");
    FileObject pom = TestFileUtils.writeFile(work, "prj/pom.xml", "<project xmlns='http://maven.apache.org/POM/4.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd'>\n" +
            "    <modelVersion>4.0.0</modelVersion>\n" +
            "    <parent>\n" +
            "        <groupId>grp</groupId>\n" +
            "        <artifactId>common</artifactId>\n" +
            "        <relativePath>../common.xml</relativePath>\n" +
            "    </parent>\n" +
            "    <artifactId>prj</artifactId>\n" +
            "</project>\n");
    POMModel model = POMModelFactory.getDefault().getModel(Utilities.createModelSource(pom));
    Project prj = ProjectManager.getDefault().findProject(pom.getParent());
    assertEquals(Collections.<ErrorDescription>emptyList(), new ParentVersionError().getErrorsForDocument(model, prj));
}
 
Example #8
Source File: ProblemReporterImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testMissingParent() throws Exception {
    TestFileUtils.writeFile(new File(getWorkDir(), "pom.xml"), "<project xmlns='http://maven.apache.org/POM/4.0.0'><modelVersion>4.0.0</modelVersion>" +
        "<parent><groupId>g</groupId><artifactId>par</artifactId><version>0</version></parent>" +
        "<artifactId>m</artifactId>" +
        "</project>");
    Project p = ProjectManager.getDefault().findProject(FileUtil.toFileObject(getWorkDir()));
    assertEquals("g:m:jar:0", p.getLookup().lookup(NbMavenProject.class).getMavenProject().getId());
    ProblemReporterImpl pr = getReporter(p);
    MavenModelProblemsProvider mpp = new MavenModelProblemsProvider(p);
    Collection<? extends ProjectProblemsProvider.ProjectProblem> problems = mpp.getProblems();
    
    waitForReports();
    assertFalse(problems.isEmpty());
    
    assertEquals(Collections.singleton(a2f(new DefaultArtifact("g", "par", "0", null, "pom", null, new DefaultArtifactHandler("pom")))), pr.getMissingArtifactFiles());
}
 
Example #9
Source File: AuxiliaryConfigBasedPreferencesProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void put(final String key, final String value) {
    ProjectManager.mutex(false, project).writeAccess(new Action<Void>() {
        public Void run() {
            //#151856
            String oldValue = getSpi(key);
            if (value.equals(oldValue)) {
                return null;
            }
            try {
                AuxiliaryConfigBasedPreferences.super.put(key, value);
            } catch (IllegalArgumentException iae) {
                if (iae.getMessage().contains("too long")) {
                    // Not for us!
                    putSpi(key, value);
                } else {
                    throw iae;
                }
            }
            return null;
        }
    });
}
 
Example #10
Source File: ProjectHooks.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void saveProject() {
    try {
        ProjectManager.getDefault().saveProject(project);
    } catch (IOException e) {
        //#91398 provide a better error message in case of read-only location of project.
        if (!project.getProjectDirectory().canWrite()) {
            final NotifyDescriptor nd = new NotifyDescriptor.Message(
                 NbBundle.getMessage(
                     ProjectHooks.class,
                     "ERR_ProjectReadOnly",
                     project.getProjectDirectory().getName()));
            DialogDisplayer.getDefault().notify(nd);
        } else {
            Exceptions.printStackTrace(e);
        }
    }
}
 
Example #11
Source File: UpdateProjectImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if the project is of current version.
 * @return true if the project is of current version, otherwise false.
 */
public boolean isCurrent () {
    return ProjectManager.mutex().readAccess(new Mutex.Action<Boolean>() {
        public Boolean run() {
            synchronized (UpdateProjectImpl.this) {
                if (isCurrent == null) {
                    if ((cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/1",true) != null) ||
                    (cfg.getConfigurationFragment("data","http://www.netbeans.org/ns/j2se-project/2",true) != null)) {
                        isCurrent = Boolean.FALSE;
                    } else {
                        isCurrent = Boolean.TRUE;
                    }
                }
                return isCurrent;
            }
        }
    }).booleanValue();
}
 
Example #12
Source File: ActionFilterNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void store (
        final @NonNull String property,
        final @NullAllowed String oldValue,
        final @NullAllowed String newValue) {
    Parameters.notNull("property", property);       //NOI18N
    if (oldValue == null ? newValue != null : !oldValue.equals(newValue)) {                
        if (newValue != null) {
            refHelper.createExtraForeignFileReferenceAsIs(newValue, property);
        } else {
            final EditableProperties ep = updateHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
            ep.remove(property);
            updateHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
        }
        try {
            final Project prj = FileOwnerQuery.getOwner(updateHelper.getAntProjectHelper().getProjectDirectory());
            ProjectManager.getDefault().saveProject(prj);
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
}
 
Example #13
Source File: JWSProjectPropertiesUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static <C extends ProjectConfiguration> void setActiveConfig(final ProjectConfigurationProvider<C> provider, String displayName) throws IOException {
    Collection<C> configs = provider.getConfigurations();
    for (final C c : configs) {
        if (displayName.equals(c.getDisplayName())) {
            try {
                ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
                    @Override
                    public Void run() throws Exception {
                        provider.setActiveConfiguration(c);
                        return null;
                    }
                });
            } catch (MutexException mex) {
                throw (IOException) mex.getException();
            }
        }
    }
}
 
Example #14
Source File: UnitTestLibrariesNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Messages({"# {0} - module display name", "CTL_EditModuleDependencyTitle=Edit \"{0}\" Dependency"})
public @Override void actionPerformed(ActionEvent ev) {
    final EditTestDependencyPanel editTestPanel = new EditTestDependencyPanel(testDep);
    DialogDescriptor descriptor = new DialogDescriptor(editTestPanel,
            CTL_EditModuleDependencyTitle(testDep.getModule().getLocalizedName()));
    descriptor.setHelpCtx(new HelpCtx("org.netbeans.modules.apisupport.project.ui.customizer.EditTestDependencyPanel"));
    Dialog d = DialogDisplayer.getDefault().createDialog(descriptor);
    d.setVisible(true);
    if (descriptor.getValue().equals(DialogDescriptor.OK_OPTION)) {
        TestModuleDependency editedDep = editTestPanel.getEditedDependency();
        try {
            ProjectXMLManager pxm = new ProjectXMLManager(project);
            pxm.removeTestDependency(testType, testDep.getModule().getCodeNameBase());
            pxm.addTestDependency(testType, editedDep);
            ProjectManager.getDefault().saveProject(project);
            
            
        } catch (IOException e) {
            Exceptions.attachMessage(e, "Cannot store dependency: " + editedDep); // NOI18N
            Exceptions.printStackTrace(e);
        }
        
        
    }
    d.dispose();
}
 
Example #15
Source File: NbModuleProjectGeneratorTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testCreateOSGiBundle() throws Exception { // #179752
    File targetPrjDir = new File(getWorkDir(), "testModule");
    NbModuleProjectGenerator.createStandAloneModule(
            targetPrjDir,
            "org.example.testModule", // cnb
            "Testing Module", // display name
            "org/example/testModule/resources/Bundle.properties",
            "org/example/testModule/resources/layer.xml",
            NbPlatform.PLATFORM_ID_DEFAULT, true, true);
    FileObject fo = FileUtil.toFileObject(targetPrjDir);
    NbModuleProject p = (NbModuleProject) ProjectManager.getDefault().findProject(fo);
    assertNotNull(p);
    assertEquals("Testing Module", ProjectUtils.getInformation(p).getDisplayName());
    EditableManifest mf = Util.loadManifest(p.getProjectDirectory().getFileObject("manifest.mf"));
    assertNull(mf.getAttribute("OpenIDE-Module-Localizing-Bundle", null));
    assertEquals("org/example/testModule/resources/Bundle", mf.getAttribute("Bundle-Localization", null));
    assertEquals("%OpenIDE-Module-Name", mf.getAttribute("Bundle-Name", null));
    EditableProperties props = Util.loadProperties(p.getProjectDirectory().getFileObject("src/org/example/testModule/resources/Bundle.properties"));
    assertEquals("Testing Module", props.get("OpenIDE-Module-Name"));
}
 
Example #16
Source File: TestNGExecutionManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void rerun() {
    if ((properties.getProperty("test.includes") != null && properties.getProperty("test.includes").endsWith(".xml")) ||    //NOI18N
            (properties.getProperty("test.class") != null && properties.getProperty("test.class").endsWith(".xml"))) {   //NOI18N
        if (properties.getProperty("continue.after.failing.tests") == null) {   //NOI18N
            properties.setProperty("continue.after.failing.tests", "true");  //NOI18N
        }
        try {
            runAnt(FileUtil.toFileObject(scriptFile), targets, properties);
        } catch (IOException ex) {
            LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
        }
    } else {
        Project project = testSession.getProject();
        if(ProjectManager.getDefault().isValid(project)) {
            ActionProvider actionProvider = project.getLookup().lookup(ActionProvider.class);
            String[] actionNames = getActionNames(targets);
            if (actionProvider != null) {
                if (Arrays.asList(actionProvider.getSupportedActions()).contains(actionNames[0])
                        && actionProvider.isActionEnabled(actionNames[0], lookup)) {
                    actionProvider.invokeAction(actionNames[0], lookup);
                }
            }
        }
    }
}
 
Example #17
Source File: AndroidConfigProvider.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
private void load() {
    ProjectManager.mutex().readAccess(new Mutex.Action<Void>() {
        @Override
        public Void run() {
            configs.clear();
            String propNames = auxProps.get(AndroidProjectProperties.PROP_CONFIG_NAMES, false);
            if (propNames != null) {
                for (String key : Splitter.on('|').split(propNames)) {
                    Config cfg = configForKey(key);
                    if (cfg != null) {
                        configs.put(cfg.getDisplayName(), cfg);
                    }
                }
            }
            String active = auxProps.get(AndroidProjectProperties.PROP_ACTIVE_CONFIG, false);
            fixConfigurations(active);
            return null;
        }
    });
}
 
Example #18
Source File: EarProjectGeneratorTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testProjectNameIsSet() throws Exception { // #73930
    File prjDirF = new File(getWorkDir(), "EARProject");
    EarProjectGenerator.createProject(prjDirF, "test-project",
            Profile.JAVA_EE_5, TestUtil.SERVER_URL, "1.5", null);
    // test also build
    final File buildXML = new File(prjDirF, "build.xml");
    String projectName = ProjectManager.mutex().readAccess(new Mutex.ExceptionAction<String>() {
        public String run() throws Exception {
            Document doc = XMLUtil.parse(new InputSource(buildXML.toURI().toString()),
                    false, true, null, null);
            Element project = doc.getDocumentElement();
            return project.getAttribute("name");
        }
    });
    assertEquals("project name is set in the build.xml", "test-project", projectName);
}
 
Example #19
Source File: EjbJarProjectOperations.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void fixOtherReferences(final File originalPath) {
    final String property = EjbJarProjectProperties.META_INF;
    final File projectDir = FileUtil.toFile(project.getProjectDirectory());
            
    ProjectManager.mutex().writeAccess(new Runnable() {
        public void run() {
            EditableProperties props = project.getAntProjectHelper().getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
            String path = props.getProperty(property);
            if (path == null) {
                return;
            }

            if (path.startsWith(originalPath.getAbsolutePath())) {
                String relative = PropertyUtils.relativizeFile(originalPath, new File(path));
                if (relative != null) {
                    String fixedPath = new File(projectDir, relative).getAbsolutePath();
                    props.setProperty(property, fixedPath);
                    project.getAntProjectHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
                }
            }
        }
    });
}
 
Example #20
Source File: SuiteUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Returns suite for the given suite component. May return
 * <code>null</code>.
 * <p>Acquires read access.</p>
 */
public static SuiteProject findSuite(final Project suiteComponent) throws IOException {
    try {
        return ProjectManager.mutex().readAccess(new Mutex.ExceptionAction<SuiteProject>(){
            public SuiteProject run() throws Exception {
                Project suite = null;
                File suiteDir = SuiteUtils.getSuiteDirectory(suiteComponent);
                if (suiteDir != null) {
                    FileObject fo = FileUtil.toFileObject(suiteDir);
                    if (fo == null) {
                        Util.err.log(ErrorManager.WARNING, "Module in the \"" + // NOI18N
                                FileUtil.toFile(suiteComponent.getProjectDirectory()).getAbsolutePath() +
                                "\" directory claims to be a subcomponent of a suite in the \"" + // NOI18N
                                suiteDir.getAbsolutePath() + "\" which does not exist however."); // NOI18N
                    } else {
                        suite = ProjectManager.getDefault().findProject(fo);
                    }
                }
                return suite instanceof SuiteProject ? (SuiteProject) suite : /* #80786 */null;
            }
        });
    } catch (MutexException e) {
        throw (IOException) e.getException();
    }
}
 
Example #21
Source File: ProjectHelper.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static void migrateProjectFromPreDot5Version(Project prj){
    // String oldJaxbLibName = "jaxb21" ; //NOI18N
    // Remove Old library. Can't for now, need an API for removing non existent lib
    //Add new library
    addJAXBLibrary(prj);
    
    //Update JAXB Wiz properties.
    saveProjectProperty(prj, PROP_XJC_DEF_CLASSPATH, 
            PROP_VAL_JAXB_LIB_CLASSPATH);
    saveProjectProperty(prj, PROP_XJC_RUN_CLASSPATH, 
            PROP_VAL_JAXB_LIB_CLASSPATH);
    saveProjectProperty(prj, PROP_JAXB_GEN_SRC_CLASSPATH, 
            PROP_VAL_JAXB_LIB_CLASSPATH);        
    
    try {
        ProjectManager.getDefault().saveProject(prj);
        Schemas scs = ProjectHelper.getXMLBindingSchemas(prj);
        ProjectHelper.refreshBuildScript(prj);
        scs.setVersion(JAXBWizModuleConstants.LATEST_CFG_VERSION);
        ProjectHelper.saveXMLBindingSchemas(prj, scs);
        disableCoS(prj, scs.sizeSchema() != 0);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example #22
Source File: ProjectFactorySupportTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testUpdateProjectClassPathForNonExistingRequiredProject() throws IOException {
    EclipseProject eclipse = getTestableProject(1, getWorkDir());
    File prj = new File(getWorkDirPath(), "nb");
    ProjectImportModel model = new ProjectImportModel(eclipse, new File(prj, "test"),
            JavaPlatform.getDefault(), Arrays.<Project>asList(new Project[0]));
    final AntProjectHelper helper = J2SEProjectGenerator.createProject(
            new File(prj, "test"), "test", model.getEclipseSourceRootsAsFileArray(), 
            model.getEclipseTestSourceRootsAsFileArray(), null, null, null);
    J2SEProject p = (J2SEProject)ProjectManager.getDefault().findProject(helper.getProjectDirectory());
    List<String> importProblems = new ArrayList<String>();
    ProjectFactorySupport.updateProjectClassPath(helper, p.getReferenceHelper(), model, importProblems);
    EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
    // required project "JavaLibrary1" is not available and therefore should not be
    // on classpath nor in key
    assertEquals(
        "${file.reference.commons-cli-1.0.jar}:" +
        "${file.reference.ejb3-persistence.jar}",
        ep.getProperty("javac.classpath").replace(';', ':'));
    String oldKey = ProjectFactorySupport.calculateKey(model);
    assertEquals(
        "src=src;" +
        "src=test;" +
        "var=MAVEN_REPOPO/commons-cli/commons-cli/1.0/commons-cli-1.0.jar;" +
        "file=/home/dev/hibernate-annotations-3.3.1.GA/lib/ejb3-persistence.jar;" +
        "jre="+JavaPlatform.getDefault().getDisplayName()+";", oldKey);
}
 
Example #23
Source File: LibrariesStorageDeadlock167218Test.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
        public LibraryImplementation createLibrary() {
            assertFalse("No Hold lock", Thread.holdsLock(LibraryManager.getDefault()));
//            assertFalse("No mutex", ProjectManager.mutex().isReadAccess());   Libraries refreshed synchronously by caller - makes no sence
//            assertFalse("No mutex write", ProjectManager.mutex().isWriteAccess());  Libraries refreshed synchronously by caller - makes no sence
            try {
                LibrariesTestUtil.registerLibraryTypeProvider(TestLibraryTypeProvider.class);
                Thread.sleep(500);
            } catch (Exception ex) {
                Exceptions.printStackTrace(ex);
            }
            return ProjectManager.mutex().writeAccess(new Action<LibraryImplementation>() {
                public LibraryImplementation run() {
                    return TestMutexLibraryTypeProvider.super.createLibrary();
                }
            });
        }
 
Example #24
Source File: TemplateOperation.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public final Set<FileObject> execute() {
    if (GradleProjects.testForProject(dir)) {
        try {
            FileObject projectDir = FileUtil.toFileObject(dir);
            Project project = ProjectManager.getDefault().findProject(projectDir);
            NbGradleProjectImpl impl = project != null ? project.getLookup().lookup(NbGradleProjectImpl.class): null;
            if (impl != null) {
                impl.fireProjectReload(true);
                configurator.configure(project);
            }

        } catch (IOException ex) {
        }
    }
    return Collections.<FileObject>emptySet();
}
 
Example #25
Source File: AuxiliaryPropertiesImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override public void put(final String key, final String value, final boolean shared) {
    ProjectManager.mutex().writeAccess(new Mutex.Action<Void>() {
        @Override public Void run() {
            String location = shared ? AntProjectHelper.PROJECT_PROPERTIES_PATH : AntProjectHelper.PRIVATE_PROPERTIES_PATH;
            EditableProperties props = helper.getProperties(location);

            if (value != null) {
                props.put(propertyPrefix + key, value);
            } else {
                props.remove(propertyPrefix + key);
            }

            helper.putProperties(location, props);
            
            return null;
        }
    });
}
 
Example #26
Source File: J2SEModularProjectProperties.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void saveLibrariesLocation() throws IOException, IllegalArgumentException {
    try {
        String str = SHARED_LIBRARIES_MODEL.getText(0, SHARED_LIBRARIES_MODEL.getLength()).trim();
        if (str.length() == 0) {
            str = null;
        }
        String old = project.getAntProjectHelper().getLibrariesLocation();
        if ((old == null && str == null) || (old != null && old.equals(str))) {
            //ignore, nothing changed..
        } else {
            project.getAntProjectHelper().setLibrariesLocation(str);
            ProjectManager.getDefault().saveProject(project);
        }
    } catch (BadLocationException x) {
        ErrorManager.getDefault().notify(x);
    }
}
 
Example #27
Source File: CreateJobPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void browseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseActionPerformed
    JFileChooser chooser = ProjectChooser.projectChooser();
    chooser.showOpenDialog(this);
    File dir = chooser.getSelectedFile();
    if (dir != null) {
        FileObject d = FileUtil.toFileObject(dir);
        if (d != null) {
            try {
                Project p = ProjectManager.getDefault().findProject(d);
                if (p != null) {
                    manuallyAddedProjects.add(p);
                    updateProjectModel();
                    project.setSelectedItem(p);
                }
            } catch (IOException x) {
                Exceptions.printStackTrace(x);
            }
        }
    }
}
 
Example #28
Source File: NbModuleProjectTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testRunInAtomicAction() throws Exception {
    FileObject suite1 = resolveEEP("suite1");
    FileObject action = suite1.getFileObject("action-project");
    NbModuleProject project = (NbModuleProject) ProjectManager.getDefault().findProject(action);
    assertFalse(project.isRunInAtomicAction());
    project.setRunInAtomicAction(true);
    assertTrue(project.isRunInAtomicAction());
    // reentrancy check
    project.setRunInAtomicAction(true);
    assertTrue(project.isRunInAtomicAction());
    project.setRunInAtomicAction(false);
    assertTrue(project.isRunInAtomicAction());
    project.setRunInAtomicAction(false);
    assertFalse(project.isRunInAtomicAction());
    // check mismatched leave from AA
    boolean thrown = false;
    try {
        project.setRunInAtomicAction(false);
    } catch (IllegalArgumentException ex) {
        thrown = true;
    }
    assertTrue("Leaving atomic action when outside atomic action throws IAE", thrown);
}
 
Example #29
Source File: BasicProjectWizardIterator.java    From nb-springboot with Apache License 2.0 5 votes vote down vote up
@Override
public Set<FileObject> instantiate(ProgressHandle handle) throws IOException {
    handle.start(4);
    Set<FileObject> resultSet = new LinkedHashSet<>();
    File fDir = FileUtil.normalizeFile((File) wiz.getProperty("projdir"));
    fDir.mkdirs();
    handle.progress(1);
    FileObject foDir = FileUtil.toFileObject(fDir);
    FileObject template = URLMapper.findFileObject(getClass().getResource("BasicSpringbootProject.zip"));
    unZipFile(template.getInputStream(), foDir);
    handle.progress(2);
    // create nbactions.xml file
    createNbActions(foDir);
    // clear non project cache
    ProjectManager.getDefault().clearNonProjectCache();
    // Always open top dir as a project:
    resultSet.add(foDir);
    // open pom.xml file
    final FileObject foPom = foDir.getFileObject("pom.xml");
    if (foPom != null) {
        resultSet.add(foPom);
    }
    handle.progress(3);
    // trigger download of dependencies
    Project prj = ProjectManager.getDefault().findProject(foDir);
    if (prj != null) {
        final NbMavenProject mvn = prj.getLookup().lookup(NbMavenProject.class);
        if (mvn != null) {
            mvn.downloadDependencyAndJavadocSource(false);
        }
    }
    // remember folder for creation of new projects
    File parent = fDir.getParentFile();
    if (parent != null && parent.exists()) {
        ProjectChooser.setProjectsFolder(parent);
    }
    handle.finish();
    return resultSet;
}
 
Example #30
Source File: FreeformProjectGenerator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static AntProjectHelper createProject(File location, File dir, String name, File antScript) throws IOException {
    FileObject dirFO = createProjectDir(dir);
    FileObject locationFO = FileUtil.toFileObject(location);
    AntProjectHelper h = createProject(locationFO, dirFO, name, antScript);
    Project p = ProjectManager.getDefault().findProject(dirFO);
    ProjectManager.getDefault().saveProject(p);
    return h;
}