本文整理匯總了Java中org.netbeans.api.project.Project類的典型用法代碼示例。如果您正苦於以下問題:Java Project類的具體用法?Java Project怎麽用?Java Project使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Project類屬於org.netbeans.api.project包,在下文中一共展示了Project類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createExecuteClasspath
import org.netbeans.api.project.Project; //導入依賴的package包/類
private List<URL> createExecuteClasspath(List<String> packageRoots, Element compilationUnitEl) {
for (Element e : XMLUtil.findSubElements(compilationUnitEl)) {
if (e.getLocalName().equals("classpath") && e.getAttribute("mode").equals("execute")) { // NOI18N
return createClasspath(e, new RemoveSources(helper, sfbqImpl));
}
}
// None specified; assume it is same as compile classpath plus (cf. #49113) <built-to> dirs/JARs
// if there are any (else include the source dir(s) as a fallback for the I18N wizard to work).
Set<URL> urls = new LinkedHashSet<>();
urls.addAll(createCompileClasspath(compilationUnitEl));
final Project prj = FileOwnerQuery.getOwner(helper.getProjectDirectory());
if (prj != null) {
for (URL src : createSourcePath(packageRoots)) {
urls.addAll(sfbqImpl.findBinaryRoots(src));
}
}
return new ArrayList<>(urls);
}
示例2: findSourceGroup
import org.netbeans.api.project.Project; //導入依賴的package包/類
/**
* Finds a Java source group the given file belongs to.
*
* @param file {@code FileObject} to find a {@code SourceGroup} for
* @return the found {@code SourceGroup}, or {@code null} if the given
* file does not belong to any Java source group
*/
private static SourceGroup findSourceGroup(FileObject file) {
final Project project = FileOwnerQuery.getOwner(file);
if (project == null) {
return null;
}
Sources src = ProjectUtils.getSources(project);
SourceGroup[] srcGrps = src.getSourceGroups(SOURCES_TYPE_JAVA);
for (SourceGroup srcGrp : srcGrps) {
FileObject rootFolder = srcGrp.getRootFolder();
if (((file == rootFolder) || FileUtil.isParentOf(rootFolder, file))
&& srcGrp.contains(file)) {
return srcGrp;
}
}
return null;
}
示例3: createKeys
import org.netbeans.api.project.Project; //導入依賴的package包/類
@Messages({"LBL_this_layer=<this layer>", "LBL_this_layer_in_context=<this layer in context>"})
@Override protected boolean createKeys(List<DataObject> keys) {
handle.setAutosave(true);
FileObject layer = handle.getLayerFile();
if (layer == null) { // #180872, #212541
return true;
}
Project p = FileOwnerQuery.getOwner(layer);
if (p == null) { // #175861: inside JAR etc.
return true;
}
FileSystem layerfs = handle.layer(false);
try {
if (layerfs != null) {
keys.add(DataObject.find(badge(layerfs, handle.getLayerFile(), LBL_this_layer(), null).getRoot()));
}
LayerHandle h = LayerHandle.forProject(p);
if (layer.equals(h.getLayerFile())) {
h.setAutosave(true); // #135376
keys.add(DataObject.find(badge(LayerUtils.getEffectiveSystemFilesystem(p), handle.getLayerFile(), LBL_this_layer_in_context(), handle.layer(false)).getRoot()));
}
} catch (IOException e) {
Util.err.notify(ErrorManager.INFORMATIONAL, e);
}
return true;
}
示例4: FileChooser
import org.netbeans.api.project.Project; //導入依賴的package包/類
/**
* Create chooser for given AntProjectHelper. Standard file chooser is shown
* if project is not sharable.
*
* @param helper ant project helper; cannot be null
* @param copyAllowed is file copying allowed
*/
public FileChooser(AntProjectHelper helper, boolean copyAllowed) {
super();
FileObject projectFolder = helper.getProjectDirectory();
Project p = projectFolder != null ? FileOwnerQuery.getOwner(projectFolder): null;
LibraryManager lm = p != null ? ReferenceHelper.getProjectLibraryManager(p) : null;
if (lm != null) {
URL u = lm.getLocation();
if (u != null) {
File libBase = Utilities.toFile(URI.create(u.toExternalForm())).getParentFile();
accessory = new FileChooserAccessory(this, FileUtil.toFile(helper.getProjectDirectory()),
libBase, copyAllowed);
setAccessory(accessory);
}
}
}
示例5: markExternalOwnerTransient
import org.netbeans.api.project.Project; //導入依賴的package包/類
/** @see FileOwnerQuery#markExternalOwner */
public static void markExternalOwnerTransient(URI root, Project owner) {
externalRootsIncludeNonFolders |= !root.getPath().endsWith("/");
if (owner != null) {
FileObject fo = owner.getProjectDirectory();
URI foUri = owner == FileOwnerQuery.UNOWNED ? UNOWNED_URI : fo.toURI();
synchronized (cacheLock) {
cacheInvalid = true;
externalOwners.put(root, foUri);
deserializedExternalOwners.remove(root);
}
} else {
synchronized (cacheLock) {
cacheInvalid = true;
externalOwners.remove(root);
}
}
}
示例6: createPersistenceUnitUsingWizard
import org.netbeans.api.project.Project; //導入依賴的package包/類
/**
* Creates a persistence unit using the PU wizard and adds the created
* persistence unit to the given project's <code>PUDataObject</code> and saves it.
*
* @param project the project to which the created persistence unit is to be created.
* @param preselectedDB the name of the db connection that should be preselected, or null if none needs
* to be preselected.
* @param tableGeneration the table generation strategy for the persistence unit.
*
* @return true if the creation of the persistence unit was successful, false otherwise.
*
* @throws InvalidPersistenceXmlException if the persistence.xml file in the given
* project is not valid.
*
*/
public static boolean createPersistenceUnitUsingWizard(Project project,
String preselectedDB, TableGeneration tableGeneration) throws InvalidPersistenceXmlException {
PersistenceUnit punit = buildPersistenceUnitUsingWizard(project, preselectedDB, tableGeneration);
if (punit == null) {
return false;
}
String version = Persistence.VERSION_1_0;
if(punit instanceof org.netbeans.modules.j2ee.persistence.dd.persistence.model_2_1.PersistenceUnit) {
version = Persistence.VERSION_2_1;
} else if(punit instanceof org.netbeans.modules.j2ee.persistence.dd.persistence.model_2_0.PersistenceUnit) {
version = Persistence.VERSION_2_0;
}
PUDataObject pud = ProviderUtil.getPUDataObject(project, version);
if (pud == null) {
return false;
}
pud.addPersistenceUnit(punit);
pud.save();
return true;
}
示例7: checkDependenciesOrder
import org.netbeans.api.project.Project; //導入依賴的package包/類
private static void checkDependenciesOrder(final Project proj) throws Exception {
FileObject projectXML = proj.getProjectDirectory().getFileObject("nbproject/project.xml");
BufferedReader r = new BufferedReader(new InputStreamReader(projectXML.getInputStream()));
try {
String previousCNB = null;
String line;
while ((line = r.readLine()) != null) {
line = line.trim();
if (line.matches("<code-name-base>.+</code-name-base>")) {
String currentCNB = line.substring(16, line.length() - 17);
assertTrue("dependencies order, previous = \"" + previousCNB + "\", current = \"" + currentCNB + "\"",
previousCNB == null || previousCNB.compareTo(currentCNB) < 0);
previousCNB = currentCNB;
}
}
} finally {
r.close();
}
}
示例8: updateProjectProperties
import org.netbeans.api.project.Project; //導入依賴的package包/類
private void updateProjectProperties(Project project) throws IOException {
final FileObject projectDir = project.getProjectDirectory();
ProjectManager.mutex().postWriteRequest(new Runnable() {
@Override
public void run() {
try {
FileObject projectProperties = FileUtil.createData(projectDir, AntProjectHelper.PROJECT_PROPERTIES_PATH);
Properties props = getProjectProperties(projectDir);
if (isJUnit3specific) {
String testClasspath = props.getProperty(PROP_JAVAC_TEST_CLASSPATH);
props.put(PROP_JAVAC_TEST_CLASSPATH, testClasspath.replace("${libs.junit.classpath}", ""));
}
props.put(PROP_JUNIT_SELECTED_VERSION, isJUnit3specific ? "3" : "4");
OutputStream propertiesOS = projectProperties.getOutputStream();
props.store(propertiesOS, null);
propertiesOS.close();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
});
}
示例9: checkForExistingProject
import org.netbeans.api.project.Project; //導入依賴的package包/類
private void checkForExistingProject() {
//if project already exists, enable the check box
if ("".equalsIgnoreCase(view.projectNameField.getText().trim())) {
view.overwriteCheckBox.setEnabled(false);
} else {
File projFolder = FileUtil.normalizeFile( new File( readLocationStringFromField(view.projectDirectoryField) ) );
FileObject dirFO = FileUtil.toFileObject(projFolder);
Project proj = null;
if (dirFO != null) {
try {
proj = ProjectManager.getDefault().findProject(dirFO);
} catch (IOException | IllegalArgumentException ex) {
view.overwriteCheckBox.setEnabled(false);
}
}
if (proj == null) {
view.overwriteCheckBox.setEnabled(false);
} else {
view.overwriteCheckBox.setEnabled(true);
}
}
}
示例10: createCategory
import org.netbeans.api.project.Project; //導入依賴的package包/類
@Override
public Category createCategory(Lookup context) {
Project project = context.lookup(Project.class);
NbMavenProject watcher = project.getLookup().lookup(NbMavenProject.class);
String effPackaging = watcher.getPackagingType();
String[] types = PluginPropertyUtils.getPluginPropertyList(project, OSGiConstants.GROUPID_FELIX, OSGiConstants.ARTIFACTID_BUNDLE_PLUGIN, "supportedProjectTypes", "supportedProjectType", /*"bundle" would not work for GlassFish parent POM*/null);
if (types != null) {
for (String type : types) {
if (effPackaging.equals(type)) {
effPackaging = NbMavenProject.TYPE_OSGI;
}
}
}
if (NbMavenProject.TYPE_OSGI.equalsIgnoreCase(effPackaging)) {
return ProjectCustomizer.Category.create(
ModelHandle2.PANEL_COMPILE,
org.openide.util.NbBundle.getMessage(PackagesPanelProvider.class, "TIT_Packages"),
null);
}
return null;
}
示例11: getSubProjects
import org.netbeans.api.project.Project; //導入依賴的package包/類
private void getSubProjects() {
try {
if(activatedNodes != null) {
for( int i = 0; i < activatedNodes.length; i++ ) {
Project p = activatedNodes[i].getLookup().lookup(Project.class);
if ( p != null ) {
ProjectContainerProvider pcp = p.getLookup().lookup(ProjectContainerProvider.class);
if (pcp != null) {
subProjects = pcp.getContainedProjects().getProjects();
} else {
SubprojectProvider spp = p.getLookup().lookup(SubprojectProvider.class);
if(spp != null) {
subProjects = spp.getSubprojects();
}
}
}
}
}
} finally {
initialized = true;
}
}
示例12: processFile
import org.netbeans.api.project.Project; //導入依賴的package包/類
private void processFile(Project project, FileObject fileObject, String originalName, String originalExtension) {
assert fileObject.isData() : "File expected: " + fileObject;
if (!isSupportedFile(fileObject)) {
// unsupported file
return;
}
if (!processedFiles.add(fileObject)) {
// already processed
return;
}
if (fileObject.isValid()) {
fileChanged(project, fileObject);
if (originalName != null) {
// file renamed
fileRenamed(project, fileObject, originalName, originalExtension);
}
} else {
// deleted file
fileDeleted(project, fileObject);
}
}
示例13: isOnSourceClasspath
import org.netbeans.api.project.Project; //導入依賴的package包/類
public static boolean isOnSourceClasspath(FileObject fo) {
Project p = FileOwnerQuery.getOwner(fo);
if (p==null) return false;
Project[] opened = OpenProjects.getDefault().getOpenProjects();
for (int i = 0; i<opened.length; i++) {
if (p.equals(opened[i]) || opened[i].equals(p)) {
SourceGroup[] gr = ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
for (int j = 0; j < gr.length; j++) {
if (fo==gr[j].getRootFolder()) return true;
if (FileUtil.isParentOf(gr[j].getRootFolder(), fo))
return true;
}
return false;
}
}
return false;
}
示例14: isTestClass
import org.netbeans.api.project.Project; //導入依賴的package包/類
public static boolean isTestClass(Node activatedNode) {
FileObject fileObject = org.netbeans.modules.gsf.testrunner.ui.api.UICommonUtils.getFileObjectFromNode(activatedNode);
if (fileObject != null && CommonTestUtil.isJavaFile(fileObject)) {
Project project = FileOwnerQuery.getOwner(fileObject);
if (project != null) {
SourceGroup[] javaSGs = new JavaUtils(project).getJavaSourceGroups();
for (int i = 0; i < javaSGs.length; i++) {
SourceGroup javaSG = javaSGs[i];
FileObject rootFolder = javaSG.getRootFolder();
URL[] testRoots = UnitTestForSourceQuery.findUnitTests(rootFolder);
URL[] sourceRoots = UnitTestForSourceQuery.findSources(rootFolder);
if (((fileObject == rootFolder) || FileUtil.isParentOf(rootFolder, fileObject)) && javaSG.contains(fileObject)) {
// activated FO is contained in the javaSG source group
if (testRoots.length == 0 && sourceRoots.length > 0) {
// javaSG has corresponding source root but no corresponding test root,
// thus the activated FO is a test class, so activate action
return true;
}
}
}
}
}
return false;
}
示例15: testListenerOpenClose
import org.netbeans.api.project.Project; //導入依賴的package包/類
public void testListenerOpenClose () throws Exception {
assertTrue ("No project is open.", OpenProjectList.getDefault ().getOpenProjects ().length == 0);
ChangeListener list = new ChangeListener();
OpenProjectList.getDefault().addPropertyChangeListener(list);
CharSequence log = Log.enable("org.netbeans.ui", Level.FINE);
OpenProjectList.getDefault ().open (project1, true);
Pattern p = Pattern.compile("Opening.*1.*TestProject", Pattern.MULTILINE | Pattern.DOTALL);
Matcher m = p.matcher(log);
if (!m.find()) {
fail("There should be TestProject\n" + log.toString());
}
assertEquals(0, list.oldCount);
assertEquals(1, list.newCount);
OpenProjectList.getDefault ().open (project2, true);
assertEquals(1, list.oldCount);
assertEquals(2, list.newCount);
OpenProjectList.getDefault().close(new Project[] {project1}, false);
assertEquals(2, list.oldCount);
assertEquals(1, list.newCount);
OpenProjectList.getDefault().close(new Project[] {project2}, false);
assertEquals(1, list.oldCount);
assertEquals(0, list.newCount);
}