本文整理匯總了Java中org.netbeans.api.project.Project.getProjectDirectory方法的典型用法代碼示例。如果您正苦於以下問題:Java Project.getProjectDirectory方法的具體用法?Java Project.getProjectDirectory怎麽用?Java Project.getProjectDirectory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.netbeans.api.project.Project
的用法示例。
在下文中一共展示了Project.getProjectDirectory方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
}
});
}
示例2: getIndex
import org.netbeans.api.project.Project; //導入方法依賴的package包/類
private int getIndex( Project p ) {
if (p == null || p.getProjectDirectory() == null) {
return -1;
}
URL pURL = p.getProjectDirectory().toURL();
int i = 0;
for (ProjectReference pRef : recentProjects) {
URL p2URL = pRef.getURL();
if ( pURL.equals( p2URL ) ) {
return i;
} else {
i++;
}
}
return -1;
}
示例3: findProjectCacheRelative
import org.netbeans.api.project.Project; //導入方法依賴的package包/類
private static String findProjectCacheRelative(Project p) throws IOException {
FileObject projectDirFO = p.getProjectDirectory();
CacheDirectoryProvider cdp = p.getLookup().lookup(CacheDirectoryProvider.class);
FileObject cacheFO = null;
if (cdp == null || (cacheFO = cdp.getCacheDirectory()) == null) {
return null;
}
if (FileUtil.isParentOf(projectDirFO, cacheFO)) {
return FileUtil.getRelativePath(projectDirFO, cacheFO);
} else {
String s = cacheFO.toURI().toString();
// strip the trailing / marking a directory
return s.substring(0, s.length() - 1);
}
}
示例4: testFirstGenSrcAddedDynamically
import org.netbeans.api.project.Project; //導入方法依賴的package包/類
public void testFirstGenSrcAddedDynamically() throws Exception {
Project p = createTestProject(false);
FileObject d = p.getProjectDirectory();
FileObject src = d.getFileObject("src");
URL classes = new URL(d.toURL(), "build/classes/");
URL distJar = FileUtil.getArchiveRoot(BaseUtilities.toURI(FileUtil.normalizeFile(
new File(FileUtil.toFile(d), "dist/x.jar".replace('/', File.separatorChar)))).toURL()); //NOI18N
ClassPath sourcePath = ClassPath.getClassPath(src, ClassPath.SOURCE);
assertEquals(Arrays.asList(src), Arrays.asList(sourcePath.getRoots()));
assertEquals(Arrays.asList(src), Arrays.asList(SourceForBinaryQuery.findSourceRoots(classes).getRoots()));
// now add the first gensrc root:
FileObject stuff = FileUtil.createFolder(d, "build/generated-sources/stuff");
FileObject xgen = FileUtil.createData(stuff, "net/nowhere/XGen.java");
assertEquals(Arrays.asList(src, stuff), Arrays.asList(sourcePath.getRoots()));
assertEquals(ClassPath.getClassPath(src, ClassPath.COMPILE), ClassPath.getClassPath(stuff, ClassPath.COMPILE));
assertEquals(Arrays.asList(src, stuff), Arrays.asList(SourceForBinaryQuery.findSourceRoots(classes).getRoots()));
assertEquals(Arrays.asList(classes, distJar), Arrays.asList(BinaryForSourceQuery.findBinaryRoots(stuff.toURL()).getRoots()));
FileBuiltQuery.Status status = FileBuiltQuery.getStatus(xgen);
assertNotNull(status);
assertFalse(status.isBuilt());
FileUtil.createData(d, "build/classes/net/nowhere/XGen.class");
assertTrue(status.isBuilt());
}
示例5: testSourceRoots
import org.netbeans.api.project.Project; //導入方法依賴的package包/類
public void testSourceRoots() throws Exception {
Project p = createTestProject(true);
FileObject d = p.getProjectDirectory();
FileObject src = d.getFileObject("src");
FileObject stuff = d.getFileObject("build/generated-sources/stuff");
SourceGroup[] groups = ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
assertEquals(2, groups.length);
assertEquals(src, groups[0].getRootFolder());
assertEquals(d.getFileObject("test"), groups[1].getRootFolder());
ClassPath sourcePath = ClassPath.getClassPath(src, ClassPath.SOURCE);
assertEquals(Arrays.asList(src, stuff), Arrays.asList(sourcePath.getRoots()));
FileObject moreStuff = FileUtil.createFolder(d, "build/generated-sources/morestuff");
final Set<FileObject> expected = new TreeSet<FileObject>(new FOComparator());
expected.addAll(Arrays.asList(src, stuff, moreStuff));
final Set<FileObject> result = new TreeSet<FileObject>(new FOComparator());
result.addAll(Arrays.asList(sourcePath.getRoots()));
assertEquals(expected, result);
ClassPath compile = ClassPath.getClassPath(src, ClassPath.COMPILE);
assertEquals(compile, ClassPath.getClassPath(stuff, ClassPath.COMPILE));
assertEquals(compile, ClassPath.getClassPath(moreStuff, ClassPath.COMPILE));
assertEquals(ClassPath.getClassPath(src, ClassPath.EXECUTE), ClassPath.getClassPath(stuff, ClassPath.EXECUTE));
assertEquals(ClassPath.getClassPath(src, ClassPath.BOOT), ClassPath.getClassPath(stuff, ClassPath.BOOT));
d.getFileObject("build").delete();
assertEquals(Arrays.asList(src), Arrays.asList(sourcePath.getRoots()));
}
示例6: testProjectPropertiesSetUp
import org.netbeans.api.project.Project; //導入方法依賴的package包/類
public void testProjectPropertiesSetUp() throws Exception {
assertNotNull(project);
jfxprops = JFXProjectProperties.getInstance(project.getLookup());
assertNotNull(jfxprops);
Project verify = jfxprops.getProject();
assertNotNull(verify);
FileObject projectDir = verify.getProjectDirectory();
assertNotNull(projectDir);
CONFIGS = jfxprops.getConfigs();
assertNotNull(CONFIGS);
}
示例7: getOpenProjectsDirectories
import org.netbeans.api.project.Project; //導入方法依賴的package包/類
@Override
public FileObject[] getOpenProjectsDirectories() {
Project[] openProjects = OpenProjects.getDefault().getOpenProjects();
if (openProjects.length == 0) {
return null;
}
FileObject[] directories = new FileObject[openProjects.length];
for (int i = 0; i < openProjects.length; i++) {
Project project = openProjects[i];
directories[i] = project.getProjectDirectory();
}
return directories;
}
示例8: getProjectDirectory
import org.netbeans.api.project.Project; //導入方法依賴的package包/類
/**
* Get the project directory of the given project.
*
* @param project
* @return
*/
private String getProjectDirectory(final Project project) {
try {
FileObject projectDirectory = project.getProjectDirectory();
return getNativePath(projectDirectory);
} catch (Exception e) {
Logger.getLogger(CopyPathToClipboardAction.class.getName()).log(
Level.FINE, null, e);
return null;
}
}
示例9: getProjectFile
import org.netbeans.api.project.Project; //導入方法依賴的package包/類
/**
* Returns the {@link Project} {@link File} for the given {@link Project}
*
* @param project
* @return
*/
public static File getProjectFile(Project project){
if (project == null) return null;
FileObject fo = project.getProjectDirectory();
return FileUtil.toFile(fo);
}
示例10: copyBuildScript
import org.netbeans.api.project.Project; //導入方法依賴的package包/類
@NonNull
static FileObject copyBuildScript (@NonNull final Project project) throws IOException {
final FileObject projDir = project.getProjectDirectory();
FileObject rpBuildScript = projDir.getFileObject(BUILD_SCRIPT_PATH);
if (rpBuildScript != null && !isBuildScriptUpToDate(project)) {
// try to close the file just in case the file is already opened in editor
DataObject dobj = DataObject.find(rpBuildScript);
CloseCookie closeCookie = dobj.getLookup().lookup(CloseCookie.class);
if (closeCookie != null) {
closeCookie.close();
}
final FileObject nbproject = projDir.getFileObject("nbproject"); //NOI18N
final FileObject backupFile = nbproject.getFileObject(BUILD_SCRIPT_BACK_UP, "xml"); //NOI18N
if (backupFile != null) {
backupFile.delete();
}
FileUtil.moveFile(rpBuildScript, nbproject, BUILD_SCRIPT_BACK_UP);
rpBuildScript = null;
}
if (rpBuildScript == null) {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(
Level.FINE,
"Updating remote build script in project {0} ({1})", //NOI18N
new Object[]{
ProjectUtils.getInformation(project).getDisplayName(),
FileUtil.getFileDisplayName(projDir)
});
}
rpBuildScript = FileUtil.createData(project.getProjectDirectory(), BUILD_SCRIPT_PATH);
try(
final InputStream in = new BufferedInputStream(RemotePlatformProjectSaver.class.getResourceAsStream(BUILD_SCRIPT_PROTOTYPE));
final OutputStream out = new BufferedOutputStream(rpBuildScript.getOutputStream())) {
FileUtil.copy(in, out);
}
}
return rpBuildScript;
}
示例11: createDefaultProjectSearchInfo
import org.netbeans.api.project.Project; //導入方法依賴的package包/類
/**
* Create default search info for a project.
*/
static SearchInfo createDefaultProjectSearchInfo(Project project) {
Sources sources = ProjectUtils.getSources(project);
SourceGroup[] sourceGroups = sources.getSourceGroups(
Sources.TYPE_GENERIC);
FileObject base = project.getProjectDirectory();
List<FileObject> roots = new ArrayList<FileObject>();
if (base != null) {
roots.add(base);
}
for (SourceGroup sg : sourceGroups) {
FileObject dir = sg.getRootFolder();
if (dir != null && (base == null || !isUnderBase(base, dir))) {
roots.add(dir);
}
}
FileObject[] rootArray = new FileObject[roots.size()];
for (int i = 0; i < roots.size(); i++) {
rootArray[i] = roots.get(i);
}
SubTreeSearchOptions stso =
project.getLookup().lookup(SubTreeSearchOptions.class);
if (stso == null) {
return SearchInfoUtils.createSearchInfoForRoots(rootArray);
} else {
return SearchInfoUtils.createSearchInfoForRoots(rootArray, false,
SearchInfoHelper.subTreeFilters(stso));
}
}
示例12: createConfigurationFiles
import org.netbeans.api.project.Project; //導入方法依賴的package包/類
/**
* Creates property files for run configuration and writes passed properties.
* Shared properties are written to nbproject/configs folder and private properties
* are written to nbproject/private/configs folder. The property file is not created
* if null is passed for either shared or private properties.
*
* @param prj project under which property files will be created
* @param configName name of the config file, '.properties' is apended
* @param sharedProps properties to be written to shared file; is allowed to
* contain special purpose properties starting with $ (e.g. $label)
* @param privateProps properties to be written to private file
* @since 1.29
*/
public static void createConfigurationFiles(Project prj, String configName,
final EditableProperties sharedProps, final EditableProperties privateProps) throws IOException, IllegalArgumentException {
if (prj == null || configName == null || "".equals(configName)) {
throw new IllegalArgumentException();
}
final String configFileName = configName + ".properties"; // NOI18N
final FileObject prjDir = prj.getProjectDirectory();
try {
ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
public Void run() throws IOException {
prjDir.getFileSystem().runAtomicAction(new FileSystem.AtomicAction() {
public void run() throws IOException {
generateConfig(prjDir, "nbproject/configs/" + configFileName, sharedProps); // NOI18N
generateConfig(prjDir, "nbproject/private/configs/" + configFileName, privateProps); // NOI18N
}
});
return null;
}
});
} catch (MutexException ex) {
throw (IOException) ex.getException();
}
}
示例13: getPathNameSeparator
import org.netbeans.api.project.Project; //導入方法依賴的package包/類
private static char getPathNameSeparator(@NullAllowed Project project, @NonNull SourceGroup[] folders) {
FileObject fo = null;
if (folders != null && folders.length > 0) {
fo = folders[0].getRootFolder();
} else if (project != null) {
fo = project.getProjectDirectory();
}
String separator = null;
if (fo != null) {
separator = (String) fo.getAttribute(FileObject.DEFAULT_PATHNAME_SEPARATOR_ATTR);
}
return (separator == null || separator.isEmpty()) ? File.separatorChar : separator.charAt(0);
}
示例14: contains
import org.netbeans.api.project.Project; //導入方法依賴的package包/類
@Override public boolean contains(FileObject file) {
if (file == loc) {
return true;
}
String path = FileUtil.getRelativePath(loc, file);
if (path == null) {
return false;
}
if (file.isFolder()) {
path += "/"; // NOI18N
}
if (!computeIncludeExcludePatterns().matches(path, true)) {
return false;
}
Project p = getProject();
if (file.isFolder() &&
file != p.getProjectDirectory() &&
ProjectManager.getDefault().isProject(file) &&
!ProjectConvertors.isConvertorProject(FileOwnerQuery.getOwner(file))) {
// #67450: avoid actually loading the nested project.
return false;
}
if (!(SourceRoot.this instanceof TypedSourceRoot)) {
// XXX disabled for typed source roots; difficult to make fast (#97215)
Project owner = FileOwnerQuery.getOwner(file);
if (owner != null &&
owner != p &&
!ProjectConvertors.isConvertorProject(owner)) {
return false;
}
if (SharabilityQuery.getSharability(file) == SharabilityQuery.Sharability.NOT_SHARABLE) {
return false;
} // else MIXED, UNKNOWN, or SHARABLE
}
return true;
}
示例15: copyJnlpImplTemplate
import org.netbeans.api.project.Project; //導入方法依賴的package包/類
public static boolean copyJnlpImplTemplate(Project proj) throws IOException {
boolean res = false;
final FileObject projDir = proj.getProjectDirectory();
FileObject jnlpBuildFile = projDir.getFileObject(JNLP_BUILD_IMPL_PATH);
if (jnlpBuildFile != null && !isJnlpImplUpToDate(proj)) {
// try to close the file just in case the file is already opened in editor
DataObject dobj = DataObject.find(jnlpBuildFile);
CloseCookie closeCookie = dobj.getLookup().lookup(CloseCookie.class);
if (closeCookie != null) {
closeCookie.close();
}
final FileObject nbproject = projDir.getFileObject("nbproject"); //NOI18N
final FileObject backupFile = nbproject.getFileObject("jnlp-impl_backup", "xml"); //NOI18N
if (backupFile != null) {
backupFile.delete();
}
FileUtil.moveFile(jnlpBuildFile, nbproject, "jnlp-impl_backup"); //NOI18N
jnlpBuildFile = null;
}
if (jnlpBuildFile == null) {
FileObject templateFO = FileUtil.getConfigFile(BUILD_TEMPLATE);
if (templateFO != null) {
FileUtil.copyFile(templateFO, projDir.getFileObject("nbproject"), "jnlp-impl"); // NOI18N
}
res = true;
}
return res;
}