本文整理汇总了Java中org.netbeans.api.project.ProjectManager类的典型用法代码示例。如果您正苦于以下问题:Java ProjectManager类的具体用法?Java ProjectManager怎么用?Java ProjectManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProjectManager类属于org.netbeans.api.project包,在下文中一共展示了ProjectManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAddRemovePomLib
import org.netbeans.api.project.ProjectManager; //导入依赖的package包/类
@RandomlyFails // frequently fails in NB-Core-Build; [CPExtender] checkLibraryForPoms on Library[Stuff] -> true and [Utilities] WORKDIR/o.n.m.m.c.C/testAddRemovePomLib/[email protected]:2: CHILD_REMOVED:[email protected] yet [Utilities] no changes in [email protected][WORKDIR/o.n.m.m.c.C/testAddRemovePomLib/[email protected]:2] where modified=true
public void testAddRemovePomLib() throws Exception {
Library lib = LibraryManager.getDefault().createLibrary("j2se", "Stuff", Collections.singletonMap("maven-pom", Collections.singletonList(new URL("http://repo1.maven.org/maven2/grp/stuff/1.0/stuff-1.0.pom"))));
Library lib2 = LibraryManager.getDefault().createLibrary("j2se", "Stuff2", Collections.singletonMap("maven-pom", Collections.singletonList(new URL("http://repo1.maven.org/maven2/grp/stuff/2.0/stuff-2.0.pom"))));
FileObject d = FileUtil.toFileObject(getWorkDir());
TestFileUtils.writeFile(d, "pom.xml", "<project><modelVersion>4.0.0</modelVersion>"
+ "<groupId>test</groupId><artifactId>prj</artifactId>"
+ "<packaging>jar</packaging><version>1.0</version></project>");
FileObject java = TestFileUtils.writeFile(d, "src/main/java/p/C.java", "package p; class C {}");
Project p = ProjectManager.getDefault().findProject(d);
NbMavenProject mp = p.getLookup().lookup(NbMavenProject.class);
assertEquals("[]", mp.getMavenProject().getDependencies().toString());
assertTrue(ProjectClassPathModifier.addLibraries(new Library[] {lib}, java, ClassPath.COMPILE));
assertFalse(ProjectClassPathModifier.addLibraries(new Library[] {lib}, java, ClassPath.COMPILE));
NbMavenProject.fireMavenProjectReload(p); // XXX why is this necessary?
assertEquals("[Dependency {groupId=grp, artifactId=stuff, version=1.0, type=jar}]", mp.getMavenProject().getDependencies().toString());
assertFalse(ProjectClassPathModifier.removeLibraries(new Library[] {lib2}, java, ClassPath.COMPILE));
assertTrue(ProjectClassPathModifier.removeLibraries(new Library[] {lib}, java, ClassPath.COMPILE));
assertFalse(ProjectClassPathModifier.removeLibraries(new Library[] {lib}, java, ClassPath.COMPILE));
NbMavenProject.fireMavenProjectReload(p);
assertEquals("[]", mp.getMavenProject().getDependencies().toString());
}
示例2: setUp
import org.netbeans.api.project.ProjectManager; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
TestUtilities.setCacheFolder(getWorkDir());
System.setProperty("netbeans.user", new File(getWorkDir(), "ud").
getAbsolutePath()); // NOI18N
FileObject projectPath = FileUtil.toFileObject(FileUtil.normalizeFile(
new File(getDataDir(), "JavaApp")));
p = ProjectManager.getDefault().findProject(projectPath);
OpenProjects.getDefault().open(new Project[]{p}, false);
IndexingManager.getDefault().refreshIndexAndWait(
projectPath.getFileObject("src").getURL(), null);
IndexingManager.getDefault().refreshAllIndices("java");
while(IndexingManager.getDefault().isIndexing());
}
示例3: testRunInAtomicAction
import org.netbeans.api.project.ProjectManager; //导入依赖的package包/类
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);
}
示例4: testGetActivePlatform
import org.netbeans.api.project.ProjectManager; //导入依赖的package包/类
public void testGetActivePlatform() throws Exception {
ProjectManager.mutex().writeAccess(new ExceptionAction<Void>() {
// saving of platform.properties of the project must be done under
// PM.mutex() lock (read would in fact suffice too), otherwise
// there is a race condition between storing properties file
// and updating project evaluator
public Void run() throws Exception {
SuiteProject suite = generateSuite("suite");
NbModuleProject module = generateSuiteComponent(suite, "module");
File plaf = new File(getWorkDir(), "plaf");
makePlatform(plaf, "1.13"); // 6.7 harness
NbPlatform.addPlatform("plaf", plaf, "Test Platform");
FileObject platformPropertiesFO = suite.getProjectDirectory().getFileObject("nbproject/platform.properties");
EditableProperties platformProperties = Util.loadProperties(platformPropertiesFO);
platformProperties.put("suite.dir", "${basedir}");
platformProperties.put("nbplatform.active", "plaf");
Util.storeProperties(platformPropertiesFO, platformProperties);
SingleModuleProperties props = loadProperties(module);
NbPlatform platform = props.getActivePlatform();
assertEquals(plaf, platform.getDestDir());
return null;
}
});
}
示例5: testAttributes
import org.netbeans.api.project.ProjectManager; //导入依赖的package包/类
public void testAttributes() throws Exception {
System.setProperty("test.load.sync", "true");
FileObject d = FileUtil.toFileObject(getWorkDir());
TestFileUtils.writeFile(d, "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/xsd/maven-4.0.0.xsd'>\n" +
" <modelVersion>4.0.0</modelVersion>\n" +
" <groupId>testgrp</groupId>\n" +
" <artifactId>testart</artifactId>\n" +
" <version>1.0</version>\n" +
" <name>Test</name>\n" +
" <licenses>\n" +
" <license>\n" +
" <name>Apache 2.0</name>\n" +
" <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>\n" +
" </license>\n" +
" </licenses>\n" +
" <organization>\n" +
" <name>Yoyodyne Corp.</name>\n" +
" </organization>\n" +
"</project>\n" +
"");
String attrs = ProjectManager.getDefault().findProject(d).getLookup().lookup(CreateFromTemplateAttributesProvider.class).attributesFor(null, DataFolder.findFolder(d), null).toString();
assertTrue("Expected {displayName=Test, license=apache20, name=testart, organization=Yoyodyne Corp.} but was " + attrs,
attrs.contains("displayName=Test") && attrs.contains("license=apache20") && attrs.contains("name=testart") && attrs.contains("organization=Yoyodyne Corp."));
}
示例6: getProjectName
import org.netbeans.api.project.ProjectManager; //导入依赖的package包/类
public static String getProjectName( final File root ) {
if(root == null || !root.isDirectory()) return null;
final ProjectManager projectManager = ProjectManager.getDefault();
FileObject rootFileObj = FileUtil.toFileObject(FileUtil.normalizeFile(root));
// This can happen if the root is "ssh://<something>"
if (rootFileObj == null || projectManager == null) {
return null;
}
String res = null;
if (projectManager.isProject(rootFileObj)){
try {
Project prj = projectManager.findProject(rootFileObj);
res = getProjectName(prj);
} catch (Exception ex) {
Mercurial.LOG.log(Level.FINE, "getProjectName() file: {0} {1}", new Object[] {rootFileObj.getPath(), ex.toString()}); // NOI18N
}finally{
return res;
}
}else{
return res;
}
}
示例7: setUp
import org.netbeans.api.project.ProjectManager; //导入依赖的package包/类
protected @Override void setUp() throws Exception {
super.setUp();
MockLookup.setLayersAndInstances(
new org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation()
);
scratch = TestUtil.makeScratchDir(this);
projdir = scratch.createFolder("proj");
J2SEProjectGenerator.setDefaultSourceLevel(new SpecificationVersion ("1.6")); //NOI18N
helper = J2SEProjectGenerator.createProject(FileUtil.toFile(projdir),"proj",null,null,null, false); //NOI18N
J2SEProjectGenerator.setDefaultSourceLevel(null);
sources = getFileObject(projdir, "src");
build = getFileObject (scratch, "build");
classes = getFileObject(build,"classes");
File f = FileUtil.normalizeFile (FileUtil.toFile(build));
String path = f.getAbsolutePath ();
//#47657: SourcesHelper.remarkExternalRoots () does not work on deleted folders
// To reproduce it uncomment following line
// build.delete();
EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
props.setProperty(ProjectProperties.BUILD_DIR, path);
helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
pm = ProjectManager.getDefault();
project = pm.findProject(projdir);
assertTrue("Invalid project type", project instanceof J2SEProject);
}
示例8: setUp
import org.netbeans.api.project.ProjectManager; //导入依赖的package包/类
protected @Override void setUp() throws Exception {
FileObject fo = FileUtil.getConfigFile("Services");
if (fo != null) {
fo.delete();
}
MockLookup.setInstances(AntBasedTestUtil.testAntBasedProjectType(), TestUtil.testProjectFactory());
scratch = TestUtil.makeScratchDir(this);
projdir = scratch.createFolder("proj");
ProjectGenerator.createProject(projdir, "test");
pm = ProjectManager.getDefault();
sisterprojdir = FileUtil.createFolder(scratch, "proj2");
AntProjectHelper sisterh = ProjectGenerator.createProject(sisterprojdir, "test");
EditableProperties props = sisterh.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
props.setProperty("build.jar", "dist/proj2.jar");
props.setProperty("build.javadoc", "build/javadoc");
sisterh.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
dummyprojdir = scratch.createFolder("dummy");
dummyprojdir.createFolder("testproject");
}
示例9: updateBuildProperties
import org.netbeans.api.project.ProjectManager; //导入依赖的package包/类
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);
}
}
});
}
示例10: createLibrary
import org.netbeans.api.project.ProjectManager; //导入依赖的package包/类
@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();
}
});
}
示例11: openProjects
import org.netbeans.api.project.ProjectManager; //导入依赖的package包/类
/**
* Open projects with given names located in given folder.
*
* @param projectNames project names to open
* @param dir project's enclosing directory
* @throws java.io.IOException when project cannot be opened
*/
public static void openProjects(File dir, String... projectNames) throws IOException {
List<Project> projects = new ArrayList<>(projectNames.length);
for (String projectName : projectNames) {
File projectsDir = FileUtil.normalizeFile(dir);
FileObject projectsDirFO = FileUtil.toFileObject(projectsDir);
FileObject projdir = projectsDirFO.getFileObject(projectName);
FileObject nbproject = projdir.getFileObject("nbproject");
if (nbproject.getFileObject("private") != null) {
for (FileObject ch : nbproject.getFileObject("private").getChildren()) {
ch.delete();
}
}
Project p = ProjectManager.getDefault().findProject(projdir);
if (p == null) {
throw new IOException("Project is not found " + projectName);
}
projects.add(p);
}
OpenProjects.getDefault().open(projects.toArray(new Project[0]), false);
}
示例12: setUp
import org.netbeans.api.project.ProjectManager; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
MockLookup.setLayersAndInstances(
new org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation()
);
scratch = TestUtil.makeScratchDir(this);
projdir = scratch.createFolder("proj");
J2SEProjectGenerator.setDefaultSourceLevel(new SpecificationVersion ("1.6")); //NOI18N
helper = J2SEProjectGenerator.createProject(FileUtil.toFile(projdir),"proj",null,null,null, false); //NOI18N
J2SEProjectGenerator.setDefaultSourceLevel(null); //NOI18N
sources = projdir.getFileObject("src");
tests = projdir.getFileObject("test");
pm = ProjectManager.getDefault();
Project p = pm.findProject(projdir);
assertTrue("Invalid project type",p instanceof J2SEProject);
pp = (J2SEProject) p;
}
示例13: createModel
import org.netbeans.api.project.ProjectManager; //导入依赖的package包/类
/** 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;
}
});
}
示例14: getConfigurationFragment
import org.netbeans.api.project.ProjectManager; //导入依赖的package包/类
/**
* Get a piece of the configuration subtree by name.
* @param elementName the simple XML element name expected
* @param namespace the XML namespace expected
* @param shared to use project.xml vs. private.xml
* @return (a clone of) the named configuration fragment, or null if it does not exist
*/
Element getConfigurationFragment(final String elementName, final String namespace, final boolean shared) {
return ProjectManager.mutex().readAccess(new Mutex.Action<Element>() {
public Element run() {
synchronized (modifiedMetadataPaths) {
Element root = getConfigurationDataRoot(shared);
Element data = XMLUtil.findElement(root, elementName, namespace);
if (data != null) {
return cloneSafely(data);
} else {
return null;
}
}
}
});
}
示例15: testSpecVersionBaseSourceEntries
import org.netbeans.api.project.ProjectManager; //导入依赖的package包/类
public void testSpecVersionBaseSourceEntries() throws Exception { // #72463
SuiteProject suite = generateSuite("suite");
NbModuleProject p = TestBase.generateSuiteComponent(suite, "module");
ModuleList ml = ModuleList.getModuleList(p.getProjectDirectoryFile());
ModuleEntry e = ml.getEntry("org.example.module");
assertNotNull("have entry", e);
ModuleDependency dep = new ModuleDependency(e);
assertEquals("right initial spec vers from manifest", "1.0", dep.getSpecificationVersion());
EditableProperties ep = p.getHelper().getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
ep.setProperty(SingleModuleProperties.SPEC_VERSION_BASE, "1.1.0");
p.getHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
EditableManifest em = Util.loadManifest(p.getManifestFile());
em.removeAttribute(ManifestManager.OPENIDE_MODULE_SPECIFICATION_VERSION, null);
Util.storeManifest(p.getManifestFile(), em);
ProjectManager.getDefault().saveProject(p);
dep = new ModuleDependency(e);
assertEquals("right spec.version.base", "1.1", dep.getSpecificationVersion());
ep.setProperty(SingleModuleProperties.SPEC_VERSION_BASE, "1.2.0");
p.getHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
ProjectManager.getDefault().saveProject(p);
dep = new ModuleDependency(e);
assertEquals("right modified spec.version.base", "1.2", dep.getSpecificationVersion());
dep = new ModuleDependency(e, null, "1.0", true, false);
assertEquals("right explicit spec vers", "1.0", dep.getSpecificationVersion());
}