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 setSourceRoots.
/**
* Sets array of source roots.
*
* @param sourceRoots a new array of sourceRoots
*/
public void setSourceRoots(String[] sourceRoots) {
LOG.log(Level.FINE, "SourcePathProviderImpl.setSourceRoots(" + java.util.Arrays.asList(sourceRoots) + ")");
Set<String> newRoots = new HashSet<String>(Arrays.asList(sourceRoots));
ClassPath oldCP = null;
ClassPath newCP = null;
synchronized (this) {
List<FileObject> sourcePath = new ArrayList<FileObject>(Arrays.asList(smartSteppingSourcePath.getRoots()));
List<FileObject> sourcePathOriginal = new ArrayList<FileObject>(Arrays.asList(originalSourcePath.getRoots()));
// First check whether there are some new source roots
Set<String> newOriginalRoots = new HashSet<String>(newRoots);
for (FileObject fo : sourcePathOriginal) {
newOriginalRoots.remove(getRoot(fo));
}
if (!newOriginalRoots.isEmpty()) {
for (String root : newOriginalRoots) {
FileObject fo = getFileObject(root);
if (fo != null) {
sourcePathOriginal.add(fo);
}
}
originalSourcePath = ClassPathSupport.createClassPath(sourcePathOriginal.toArray(new FileObject[0]));
if (additionalSourceRoots == null) {
additionalSourceRoots = new HashSet<String>();
}
additionalSourceRoots.addAll(newOriginalRoots);
}
// Then correct the smart-stepping path
Set<String> newSteppingRoots = new HashSet<String>(newRoots);
for (FileObject fo : sourcePath) {
newSteppingRoots.remove(getRoot(fo));
}
Set<FileObject> removedSteppingRoots = new HashSet<FileObject>();
Set<FileObject> removedOriginalRoots = new HashSet<FileObject>();
for (FileObject fo : sourcePath) {
String spr = getRoot(fo);
if (!newRoots.contains(spr)) {
removedSteppingRoots.add(fo);
if (additionalSourceRoots != null && additionalSourceRoots.contains(spr)) {
removedOriginalRoots.add(fo);
additionalSourceRoots.remove(spr);
if (additionalSourceRoots.size() == 0) {
additionalSourceRoots = null;
}
}
}
}
if (removedOriginalRoots.size() > 0) {
sourcePathOriginal.removeAll(removedOriginalRoots);
originalSourcePath = ClassPathSupport.createClassPath(sourcePathOriginal.toArray(new FileObject[0]));
}
if (newSteppingRoots.size() > 0 || removedSteppingRoots.size() > 0) {
for (String root : newSteppingRoots) {
FileObject fo = getFileObject(root);
if (fo != null) {
sourcePath.add(fo);
}
}
sourcePath.removeAll(removedSteppingRoots);
oldCP = smartSteppingSourcePath;
smartSteppingSourcePath = ClassPathSupport.createClassPath(sourcePath.toArray(new FileObject[0]));
newCP = smartSteppingSourcePath;
}
}
if (oldCP != null) {
pcs.firePropertyChange(PROP_SOURCE_ROOTS, oldCP, newCP);
}
}
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 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;
}
Aggregations