use of org.eclipse.core.runtime.IPath in project che by eclipse.
the class HandleFactory method getJarPkgFragmentRoot.
/**
* Returns the package fragment root that corresponds to the given jar path.
* See createOpenable(...) for the format of the jar path string.
* If not null, uses the given scope as a hint for getting Java project handles.
*/
private PackageFragmentRoot getJarPkgFragmentRoot(String resourcePathString, int jarSeparatorIndex, String jarPathString, IJavaSearchScope scope) {
IPath jarPath = new Path(jarPathString);
Object target = JavaModel.getTarget(jarPath, false);
if (target instanceof IFile) {
// internal jar: is it on the classpath of its project?
// e.g. org.eclipse.swt.win32/ws/win32/swt.jar
// is NOT on the classpath of org.eclipse.swt.win32
IFile jarFile = (IFile) target;
JavaProject javaProject = (JavaProject) this.javaModel.getJavaProject(jarFile);
try {
IClasspathEntry entry = javaProject.getClasspathEntryFor(jarPath);
if (entry != null) {
return (PackageFragmentRoot) javaProject.getPackageFragmentRoot(jarFile);
}
} catch (JavaModelException e) {
// ignore and try to find another project
}
}
// walk projects in the scope and find the first one that has the given jar path in its classpath
IJavaProject[] projects;
if (scope != null) {
if (scope instanceof AbstractJavaSearchScope) {
PackageFragmentRoot root = (PackageFragmentRoot) ((AbstractJavaSearchScope) scope).packageFragmentRoot(resourcePathString, jarSeparatorIndex, jarPathString);
if (root != null)
return root;
} else {
IPath[] enclosingProjectsAndJars = scope.enclosingProjectsAndJars();
int length = enclosingProjectsAndJars.length;
projects = new IJavaProject[length];
int index = 0;
for (int i = 0; i < length; i++) {
IPath path = enclosingProjectsAndJars[i];
if (path.segmentCount() == 1) {
projects[index++] = this.javaModel.getJavaProject(path.segment(0));
}
}
if (index < length) {
System.arraycopy(projects, 0, projects = new IJavaProject[index], 0, index);
}
PackageFragmentRoot root = getJarPkgFragmentRoot(jarPath, target, projects);
if (root != null) {
return root;
}
}
}
// not found in the scope, walk all projects
try {
projects = this.javaModel.getJavaProjects();
} catch (JavaModelException e) {
// java model is not accessible
return null;
}
return getJarPkgFragmentRoot(jarPath, target, projects);
}
use of org.eclipse.core.runtime.IPath in project che by eclipse.
the class Util method getJdkLevel.
/**
* Get the jdk level of this root.
* The value can be:
* <ul>
* <li>major<<16 + minor : see predefined constants on ClassFileConstants </li>
* <li><code>0</null> if the root is a source package fragment root or if a Java model exception occured</li>
* </ul>
* Returns the jdk level
*/
public static long getJdkLevel(Object targetLibrary) {
try {
ClassFileReader reader = null;
if (targetLibrary instanceof IFolder) {
// only internal classfolders are allowed
IFile classFile = findFirstClassFile((IFolder) targetLibrary);
if (classFile != null)
reader = Util.newClassFileReader(classFile);
} else {
// root is a jar file or a zip file
ZipFile jar = null;
try {
IPath path = null;
if (targetLibrary instanceof IResource) {
path = ((IResource) targetLibrary).getFullPath();
} else if (targetLibrary instanceof File) {
File f = (File) targetLibrary;
if (!f.isDirectory()) {
path = new Path(((File) targetLibrary).getPath());
}
}
if (path != null) {
jar = JavaModelManager.getJavaModelManager().getZipFile(path);
for (Enumeration e = jar.entries(); e.hasMoreElements(); ) {
ZipEntry member = (ZipEntry) e.nextElement();
String entryName = member.getName();
if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(entryName)) {
reader = ClassFileReader.read(jar, entryName);
break;
}
}
}
} catch (CoreException e) {
// ignore
} finally {
JavaModelManager.getJavaModelManager().closeZipFile(jar);
}
}
if (reader != null) {
return reader.getVersion();
}
} catch (CoreException e) {
// ignore
} catch (ClassFormatException e) {
// ignore
} catch (IOException e) {
// ignore
}
return 0;
}
use of org.eclipse.core.runtime.IPath in project che by eclipse.
the class Util method isExcluded.
/*
* Returns whether the given resource matches one of the exclusion patterns.
* NOTE: should not be asked directly using pkg root pathes
* @see IClasspathEntry#getExclusionPatterns
*/
public static final boolean isExcluded(File resource, char[][] inclusionPatterns, char[][] exclusionPatterns) {
IPath path = new Path(resource.getAbsolutePath());
// ensure that folders are only excluded if all of their children are excluded
int resourceType = resource.isFile() ? IResource.FILE : IResource.FOLDER;
return isExcluded(path, inclusionPatterns, exclusionPatterns, resourceType == IResource.FOLDER || resourceType == IResource.PROJECT);
}
use of org.eclipse.core.runtime.IPath in project che by eclipse.
the class Util method isExcluded.
/*
* Returns whether the given resource matches one of the exclusion patterns.
* NOTE: should not be asked directly using pkg root pathes
* @see IClasspathEntry#getExclusionPatterns
*/
public static final boolean isExcluded(IResource resource, char[][] inclusionPatterns, char[][] exclusionPatterns) {
IPath path = resource.getFullPath();
// ensure that folders are only excluded if all of their children are excluded
int resourceType = resource.getType();
return isExcluded(path, inclusionPatterns, exclusionPatterns, resourceType == IResource.FOLDER || resourceType == IResource.PROJECT);
}
use of org.eclipse.core.runtime.IPath in project che by eclipse.
the class IndexManager method writeIndexMapFile.
private void writeIndexMapFile() {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(this.indexNamesMapFile));
writer.write(DiskIndex.SIGNATURE);
writer.write('\n');
Object[] keys = this.indexStates.keyTable;
Object[] states = this.indexStates.valueTable;
for (int i = 0, l = states.length; i < l; i++) {
IndexLocation location = (IndexLocation) keys[i];
if (location != null && states[i] == REUSE_STATE) {
IPath container = (IPath) this.indexLocations.keyForValue(location);
if (container != null) {
writer.write(location.toString());
writer.write('\n');
writer.write(container.toOSString());
writer.write('\n');
}
}
}
} catch (IOException ignored) {
if (JobManager.VERBOSE)
//$NON-NLS-1$
Util.verbose("Failed to write saved index file names", System.err);
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
// ignore
}
}
}
}
Aggregations