本文整理匯總了Java中org.openide.filesystems.FileUtil.getRelativePath方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUtil.getRelativePath方法的具體用法?Java FileUtil.getRelativePath怎麽用?Java FileUtil.getRelativePath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openide.filesystems.FileUtil
的用法示例。
在下文中一共展示了FileUtil.getRelativePath方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createNewFileForType
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private void createNewFileForType(CompilationUnitTree cut, Tree clazz, CompilationUnitTree node) throws MissingResourceException {
try {
FileObject targetRoot = RefactoringUtils.getClassPathRoot(targetURL);
FileObject target = getOrCreateFolder(targetURL);
String relativePath = FileUtil.getRelativePath(targetRoot, target);
if (isThisFileReferencingOldPackage) {
ExpressionTree newPackageName = cut.getPackageName();
if (newPackageName != null && !moveToDefaulPackageProblem) {
problem = JavaPluginUtils.chainProblems(problem, new Problem(false, NbBundle.getMessage(MoveTransformer.class, "ERR_MovingClassToDefaultPackage")));
moveToDefaulPackageProblem = true;
}
}
GeneratorUtilities.get(workingCopy).importComments(clazz, node);
String cuPath = relativePath + "/" + ((ClassTree) clazz).getSimpleName() + ".java";
CompilationUnitTree compilationUnit = JavaPluginUtils.createCompilationUnit(targetRoot, cuPath, clazz, workingCopy, make);
compilationUnit = GeneratorUtilities.get(workingCopy).importFQNs(compilationUnit);
rewrite(null, compilationUnit);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
示例2: rememberLibraryLocation
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private void rememberLibraryLocation() {
libraryWithinProject = false;
absolutesRelPath = null;
libraryPath = helper.getAntProjectHelper().getLibrariesLocation();
if (libraryPath != null) {
File prjRoot = FileUtil.toFile(project.getProjectDirectory());
libraryFile = PropertyUtils.resolveFile(prjRoot, libraryPath);
if (FileOwnerQuery.getOwner(Utilities.toURI(libraryFile)) == project &&
libraryFile.getAbsolutePath().startsWith(prjRoot.getAbsolutePath())) {
//do not update the relative path if within the project..
libraryWithinProject = true;
FileObject fo = FileUtil.toFileObject(libraryFile);
if (new File(libraryPath).isAbsolute() && fo != null) {
// if absolte path within project, it will get moved/copied..
absolutesRelPath = FileUtil.getRelativePath(project.getProjectDirectory(), fo);
}
}
}
}
示例3: getRelativePath
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
public static String getRelativePath(Lookup.Provider project, String sourceFileAbsolutePath) {
if (project == null) {
return sourceFileAbsolutePath; // no project context for file
}
final FileObject projectDirectory = ProjectUtilities.getProjectDirectory(project);
String projectDirectoryAbsolutePath = FileUtil.toFile(projectDirectory).getAbsolutePath();
if (!sourceFileAbsolutePath.startsWith(projectDirectoryAbsolutePath)) {
return sourceFileAbsolutePath; // file not placed in project directory
}
File file = FileUtil.normalizeFile(new File(sourceFileAbsolutePath));
return PROJECT_DIRECTORY_MARK + "/" // NOI18N
+ FileUtil.getRelativePath(projectDirectory, FileUtil.toFileObject(file)); // file placed in project directory => relative path used
}
示例4: showJavadoc
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
public void showJavadoc() {
String relativeName = FileUtil.getRelativePath(cpRoot, resource);
URL[] urls = JavadocForBinaryQuery.findJavadoc(cpRoot.toURL()).getRoots();
URL pageURL;
if (relativeName.length() == 0) {
pageURL = ShowJavadocAction.findJavadoc("overview-summary.html",urls); //NOI18N
if (pageURL == null) {
pageURL = ShowJavadocAction.findJavadoc("index.html",urls); //NOI18N
}
} else if (resource.isFolder()) {
//XXX Are the names the same also in the localized javadoc?
pageURL = ShowJavadocAction.findJavadoc(relativeName + "/package-summary.html", urls); //NOI18N
} else {
String javadocFileName = relativeName.substring(0, relativeName.lastIndexOf('.')) + ".html"; //NOI18Ns
pageURL = ShowJavadocAction.findJavadoc(javadocFileName, urls);
}
ShowJavadocAction.showJavaDoc(pageURL,relativeName.replace('/','.')); //NOI18N
}
示例5: convert
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
@Override public String convert(String action, Lookup lookup) {
if (SingleMethod.COMMAND_DEBUG_SINGLE_METHOD.equals(action)) {
return ActionProvider.COMMAND_DEBUG_TEST_SINGLE;
}
if (SingleMethod.COMMAND_RUN_SINGLE_METHOD.equals(action)) {
return ActionProvider.COMMAND_TEST_SINGLE;
}
if (ActionProvider.COMMAND_RUN_SINGLE.equals(action) ||
ActionProvider.COMMAND_DEBUG_SINGLE.equals(action) ||
ActionProvider.COMMAND_PROFILE_SINGLE.equals(action)) {
FileObject[] fos = extractFileObjectsfromLookup(lookup);
if (fos.length > 0) {
FileObject fo = fos[0];
if ("text/x-java".equals(fo.getMIMEType())) {//NOI18N
Sources srcs = ProjectUtils.getSources(project);
SourceGroup[] grp = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
for (int i = 0; i < grp.length; i++) {
String relPath = FileUtil.getRelativePath(grp[i].getRootFolder(), fo);
if (relPath != null) {
if (SourceUtils.isMainClass(relPath.replaceFirst("[.]java$", "").replace('/', '.'), ClasspathInfo.create(fo), true)) {
return action + ".main";//NOI18N
}
}
}
}
}
}
return null;
}
示例6: prepare
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
@Override
public Problem prepare(RefactoringElementsBag refactoringElementsBag) {
if (isPackage()){
FileObject pkg = renameRefactoring.getRefactoringSource().lookup(NonRecursiveFolder.class).getFolder();
String oldPackageName = JavaIdentifiers.getQualifiedName(pkg);
return doPrepare(refactoringElementsBag, pkg, oldPackageName, renameRefactoring.getNewName());
} else if (isFolder()){
FileObject folder = renameRefactoring.getRefactoringSource().lookup(FileObject.class);
ClassPath classPath = ClassPath.getClassPath(folder, ClassPath.SOURCE);
if(classPath == null){
return null;//it may happens for folders in php and similar projects, see #181611
}
FileObject root = classPath.findOwnerRoot(folder);
// issue 62320. By JavaDoc, ClassPath.fineOwnerRoot can return null
if(root == null ) {
return null;
}
String prefix = FileUtil.getRelativePath(root, folder.getParent());
// #249491
if (prefix == null) {
return null;
}
prefix = prefix.replace('/','.'); // NOI18N
String oldName = buildName(prefix, folder.getName());
// the new package name
String newName = buildName(prefix, renameRefactoring.getNewName());
return doPrepare(refactoringElementsBag, folder, oldName, newName);
}
return null;
}
示例7: findPathPlain
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
private Node findPathPlain(FileObject fo, FileObject groupRoot, Node rootNode) {
FileObject folder = fo.isFolder() ? fo : fo.getParent();
String relPath = FileUtil.getRelativePath(groupRoot, folder);
List<String> path = new ArrayList<String>();
StringTokenizer strtok = new StringTokenizer(relPath, "/"); // NOI18N
while (strtok.hasMoreTokens()) {
String token = strtok.nextToken();
path.add(token);
}
try {
Node folderNode = folder.equals(groupRoot) ? rootNode : NodeOp.findPath(rootNode, Collections.enumeration(path));
if (fo.isFolder()) {
return folderNode;
} else {
Node[] childs = folderNode.getChildren().getNodes(true);
for (int i = 0; i < childs.length; i++) {
DataObject dobj = childs[i].getLookup().lookup(DataObject.class);
if (dobj != null && dobj.getPrimaryFile().getNameExt().equals(fo.getNameExt())) {
return childs[i];
}
}
}
} catch (NodeNotFoundException e) {
e.printStackTrace();
}
return null;
}
示例8: getName
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
@Override public String getName() {
if (parent != null) {
DataObject d = getLookup().lookup(DataObject.class);
if (d != null) {
final String relName = FileUtil.getRelativePath(parent.getPrimaryFile(), d.getPrimaryFile());
//Null after DO move.
if (relName != null) {
return relName.replace('/', '.'); //NOI18N
}
}
}
return super.getName();
}
示例9: getShortDescription
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
@Override
public String getShortDescription() {
if (g != null) {
final DataObject doj = getLookup().lookup(DataObject.class);
if (doj != null) {
final FileObject f = doj.getPrimaryFile();
String rel = FileUtil.getRelativePath(g.getRootFolder(), f);
if (rel != null) {
return PackageDisplayUtils.getToolTip(f, rel.replace('/', '.')); //NOI18N
}
}
}
return super.getShortDescription();
}
示例10: getPackageForFolder
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
/**
* Converts the path of the given <code>folder</code> to a package name.
*
* @param sourceGroup the source group for the folder; must not be null.
* @param folder the folder to convert; must not be null.
* @return the package name of the given <code>folder</code>.
* @throws IllegalStateException if the given <code>folder</code> was not
* in the same tree as the root folder of the given <code>sourceGroup</code>.
*/
public static String getPackageForFolder(SourceGroup sourceGroup, FileObject folder) {
Parameters.notNull("sourceGroup", sourceGroup); //NOI18N
Parameters.notNull("folder", folder); //NOI18N
String relative = FileUtil.getRelativePath(sourceGroup.getRootFolder(), folder);
if (relative == null){
throw new IllegalStateException("The given folder [ " + folder.getPath() + "] is not in the " +
"same tree with [" + sourceGroup.getRootFolder().getPath() + "]"); //NOI18N
}
return relative.replace('/', '.'); // NOI18N
}
示例11: isPubliclyAccessible
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
/**
*
* @param pkg
* @return
*/
@SuppressWarnings("NP_BOOLEAN_RETURN_NULL")
@Override public Boolean isPubliclyAccessible(FileObject pkg) {
FileObject srcdir = org.netbeans.modules.maven.api.FileUtilities.convertStringToFileObject(project.getLookup().lookup(NbMavenProject.class).getMavenProject().getBuild().getSourceDirectory());
if (srcdir != null) {
String path = FileUtil.getRelativePath(srcdir, pkg);
if (path != null) {
String name = path.replace('/', '.');
//TODO cache somehow..
List<Pattern> pp = getPublicPackagesPatterns();
return check(pp, name);
}
}
return null;
}
示例12: getShortDescription
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
@Override
public String getShortDescription() {
FileObject folder = dataFolder.getPrimaryFile();
String path = FileUtil.getRelativePath(root, folder);
if (path == null) {
// ???
return "";
}
return PackageDisplayUtils.getToolTip(folder, path.replace('/', '.'));
}
示例13: isPubliclyAccessible
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
/**
*
* @param pkg
* @return
*/
@Override
public Boolean isPubliclyAccessible(FileObject pkg) {
FileObject srcdir = org.netbeans.modules.maven.api.FileUtilities.convertStringToFileObject(prj.getLookup().lookup(NbMavenProject.class).getMavenProject().getBuild().getSourceDirectory());
if (srcdir != null) {
String path = FileUtil.getRelativePath(srcdir, pkg);
if (path != null) {
String name = path.replace('/', '.');
return check(name);
}
}
return null;
}
示例14: antIncludesList
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
/**
* Create an "includes" string such as is accepted by many Ant commands
* as well as filesets.
* <samp>/</samp> is always used as the separator in the relative paths.
* @param files a list of files or folders to include, in the case of folder
* the generated include contains recursively all files under the folder.
* @param dir a directory in which all the files reside
* @param recursive if true the include list for directory is recursive
* @return a comma-separated list of relative file paths suitable for use by Ant
* (the empty string in case there are no files)
* @throws IllegalArgumentException in case some file is not in the directory
* @since org.apache.tools.ant.module/3 3.16
*/
public static String antIncludesList(FileObject[] files, FileObject dir, boolean recursive) throws IllegalArgumentException {
Parameters.notNull("files", files);
Parameters.notNull("dir", dir);
if (!dir.isFolder()) {
throw new IllegalArgumentException("Not a folder: " + dir); // NOI18N
}
StringBuilder b = new StringBuilder();
for (int i = 0; i < files.length; i++) {
String path = FileUtil.getRelativePath(dir, files[i]);
if (path == null) {
throw new IllegalArgumentException("The file " + files[i] + " is not in " + dir); // NOI18N
}
if (i > 0) {
b.append(',');
}
b.append(path);
if (files[i].isFolder()) {
// files[i] == dir, cannot use "/".
if (path.length() > 0) {
b.append('/'); //NOI18N
}
b.append('*'); //NOI18N
if (recursive) {
b.append('*'); //NOI18N
}
}
}
return b.toString();
}
示例15: isPubliclyAccessible
import org.openide.filesystems.FileUtil; //導入方法依賴的package包/類
@SuppressWarnings("NP_BOOLEAN_RETURN_NULL")
@Override public @CheckForNull Boolean isPubliclyAccessible(@NonNull FileObject pkg) {
FileObject srcdir = project.getSourceDirectory();
if (srcdir != null) {
String path = FileUtil.getRelativePath(srcdir, pkg);
if (path != null) {
String name = path.replace('/', '.');
Element config = project.getPrimaryConfigurationData();
Element pubPkgs = XMLUtil.findElement(config, "public-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N
if (pubPkgs == null) {
// Try <friend-packages> too.
pubPkgs = XMLUtil.findElement(config, "friend-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N
}
if (pubPkgs != null) {
for (Element pubPkg : XMLUtil.findSubElements(pubPkgs)) {
boolean sub = "subpackages".equals(pubPkg.getLocalName()); // NOI18N
String pubPkgS = XMLUtil.findText(pubPkg);
if (name.equals(pubPkgS) || (sub && name.startsWith(pubPkgS + '.'))) {
return true;
}
}
// Everything else assumed to *not* be public.
return false;
} else {
Util.err.log(ErrorManager.WARNING, "Invalid project.xml for " + project);
}
}
}
return null;
}