use of org.openide.filesystems.FileObject in project enclojure by EricThorsen.
the class ClojureActionProvider method invokeAction.
public void invokeAction(final String command, final Lookup context) throws IllegalArgumentException {
// Runnable action = new Runnable() { public void run () {} };
// *
final Runnable action = new Runnable() {
public void run() {
try {
FileObject fo = project.getProjectDirectory().getFileObject(getBuildXmlFileName(project));
ActionUtils.runTarget(fo, commands.get(command), null);
} catch (IOException e) {
LOG.log(Level.FINEST, e.getMessage());
}
}
};
// */
action.run();
}
use of org.openide.filesystems.FileObject in project enclojure by EricThorsen.
the class SourcePathProviderImpl method getRelativePath.
/**
* Returns relative path for given url.
*
* @param url a url of resource file
* @param directorySeparator a directory separator character
* @param includeExtension whether the file extension should be included
* in the result
*
* @return relative path
*/
public String getRelativePath(String url, char directorySeparator, boolean includeExtension) {
// 1) url -> FileObject
FileObject fo = null;
URL theUrl = null;
if (verbose) {
System.out.println("SPPI: getRelativePath " + url);
}
try {
LOG.log(Level.ALL, " SourcePathProviderImpl::getRelativePath - " + url);
fo = URLMapper.findFileObject(theUrl = new URL(url));
if (verbose) {
System.out.println("SPPI: fo " + fo);
}
} catch (MalformedURLException e) {
// e.printStackTrace ();
return null;
}
String relativePath = smartSteppingSourcePath.getResourceName(fo, directorySeparator, includeExtension);
if (relativePath == null) {
// fallback to FileObject's class path
ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE);
if (cp == null) {
cp = ClassPath.getClassPath(fo, ClassPath.COMPILE);
}
if (cp == null) {
// ET - If the url of the full path exists, return that...
if (fo != null && theUrl != null) {
File f = new File(theUrl.getPath());
if (f.exists())
return f.getAbsolutePath();
}
return null;
}
relativePath = cp.getResourceName(fo, directorySeparator, includeExtension);
}
if (relativePath == null) {
LOG.log(Level.ALL, " SourcePathProviderImpl::getRelativePath - NO GO! " + url);
}
return relativePath;
}
use of org.openide.filesystems.FileObject in project enclojure by EricThorsen.
the class SourcePathProviderImpl method getAllURLs.
/**
* Translates a relative path to all possible URLs.
* Uses GlobalPathRegistry if global == true.
*
* @param relativePath a relative path (java/lang/Thread.java)
* @param global true if global path should be used
* @return url
*/
public String[] getAllURLs(String relativePath, boolean global) {
if (verbose) {
System.out.println("SPPI: getURL " + relativePath + " global " + global);
}
List<FileObject> fos;
relativePath = normalize(relativePath);
if (originalSourcePath == null) {
fos = new ArrayList<FileObject>();
for (ClassPath cp : GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE)) {
fos.addAll(cp.findAllResources(relativePath));
}
} else {
synchronized (this) {
if (!global) {
fos = smartSteppingSourcePath.findAllResources(relativePath);
if (verbose) {
System.out.println("SPPI: fos " + fos);
}
} else {
fos = originalSourcePath.findAllResources(relativePath);
if (verbose) {
System.out.println("SPPI: fos " + fos);
}
}
}
}
List<String> urls = new ArrayList<String>(fos.size());
for (FileObject fo : fos) {
try {
urls.add(fo.getURL().toString());
} catch (FileStateInvalidException e) {
if (verbose) {
System.out.println("SPPI: FileStateInvalidException for " + fo);
// skip it
}
}
}
return urls.toArray(new String[0]);
}
use of org.openide.filesystems.FileObject in project enclojure by EricThorsen.
the class SourcePathProviderImpl method getFileObject.
/**
* Returns FileObject for given String.
*/
private FileObject getFileObject(String file) {
File f = new File(file);
FileObject fo = FileUtil.toFileObject(f);
String path = null;
if (fo == null && file.contains("!/")) {
int index = file.indexOf("!/");
f = new File(file.substring(0, index));
fo = FileUtil.toFileObject(f);
path = file.substring(index + "!/".length());
}
if (fo != null && FileUtil.isArchiveFile(fo)) {
fo = FileUtil.getArchiveRoot(fo);
if (path != null) {
fo = fo.getFileObject(path);
}
}
return fo;
}
use of org.openide.filesystems.FileObject in project enclojure by EricThorsen.
the class SourcePathProviderImpl method getSourceRoots.
private String[] getSourceRoots(ClassPath classPath) {
FileObject[] sourceRoots = classPath.getRoots();
List<String> roots = new ArrayList<String>(sourceRoots.length);
for (FileObject fo : sourceRoots) {
String root = getRoot(fo);
if (root != null) {
roots.add(root);
}
}
return roots.toArray(new String[0]);
}
Aggregations