use of org.eclipse.core.runtime.IPath in project che by eclipse.
the class JREContainer method computeClasspathEntries.
/**
* Computes the classpath entries associated with a VM - one entry per library
* in the context of the given path and project.
*
* @param vm the VM
* @param project the project the resolution is for
* @param environmentId execution environment the resolution is for, or <code>null</code>
* @return classpath entries
*/
private static IClasspathEntry[] computeClasspathEntries(IVMInstallType vm, IJavaProject project, String environmentId) {
//vm.getLibraryLocations();
LibraryLocation[] libs = null;
boolean overrideJavaDoc = false;
if (libs == null) {
libs = getLibraryLocations(vm);
overrideJavaDoc = true;
}
IAccessRule[][] rules = null;
// if (environmentId != null) {
// compute access rules for execution environment
IExecutionEnvironment environment = JavaRuntime.getEnvironment(environmentId);
if (environment != null) {
rules = environment.getAccessRules(vm, libs, project);
}
// }
RuleKey key = null;
if (vm != null && rules != null && environmentId != null) {
key = new RuleKey(vm, environmentId);
RuleEntry entry = fgClasspathEntriesWithRules.get(key);
if (entry != null && entry.equals(rules)) {
return entry.getClasspathEntries();
}
}
List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(libs.length);
for (int i = 0; i < libs.length; i++) {
if (!libs[i].getSystemLibraryPath().isEmpty()) {
IPath sourcePath = libs[i].getSystemLibrarySourcePath();
if (sourcePath.isEmpty()) {
sourcePath = null;
}
IPath rootPath = libs[i].getPackageRootPath();
if (rootPath.isEmpty()) {
rootPath = null;
}
// construct the classpath attributes for this library location
IClasspathAttribute[] attributes = JREContainer.buildClasspathAttributes(vm, libs[i], overrideJavaDoc);
IAccessRule[] libRules = null;
if (rules != null) {
libRules = rules[i];
} else {
libRules = EMPTY_RULES;
}
entries.add(JavaCore.newLibraryEntry(libs[i].getSystemLibraryPath(), sourcePath, rootPath, libRules, attributes, false));
}
}
IClasspathEntry[] cpEntries = entries.toArray(new IClasspathEntry[entries.size()]);
if (key != null && rules != null) {
fgClasspathEntriesWithRules.put(key, new RuleEntry(rules, cpEntries));
}
return cpEntries;
}
use of org.eclipse.core.runtime.IPath in project che by eclipse.
the class Launching method writeInstallInfo.
/**
* Writes out the mappings of SDK install time stamps to disk. See
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=266651 for more information.
*/
private static void writeInstallInfo() {
if (fgInstallTimeMap != null) {
OutputStream stream = null;
try {
Document doc = newDocument();
//$NON-NLS-1$
Element root = doc.createElement("dirs");
doc.appendChild(root);
Map.Entry<String, Long> entry = null;
Element e = null;
String key = null;
for (Iterator<Map.Entry<String, Long>> i = fgInstallTimeMap.entrySet().iterator(); i.hasNext(); ) {
entry = i.next();
key = entry.getKey();
if (fgLibraryInfoMap == null || fgLibraryInfoMap.containsKey(key)) {
//only persist the info if the library map also has info OR is null - prevent persisting deleted JRE information
//$NON-NLS-1$
e = doc.createElement("entry");
root.appendChild(e);
//$NON-NLS-1$
e.setAttribute("loc", key);
//$NON-NLS-1$
e.setAttribute("stamp", entry.getValue().toString());
}
}
String xml = serializeDocument(doc);
IPath libPath = getDefault().getStateLocation();
//$NON-NLS-1$
libPath = libPath.append(".install.xml");
File file = libPath.toFile();
if (!file.exists()) {
file.createNewFile();
}
stream = new BufferedOutputStream(new FileOutputStream(file));
//$NON-NLS-1$
stream.write(xml.getBytes("UTF8"));
} catch (IOException e) {
log(e);
} catch (CoreException e) {
log(e);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e1) {
}
}
}
}
}
use of org.eclipse.core.runtime.IPath in project che by eclipse.
the class Launching method restoreLibraryInfo.
/**
* Restores library information for VMs
*/
private static void restoreLibraryInfo() {
fgLibraryInfoMap = new HashMap<String, LibraryInfo>(10);
IPath libPath = getDefault().getStateLocation();
//$NON-NLS-1$
libPath = libPath.append("libraryInfos.xml");
File file = libPath.toFile();
if (file.exists()) {
try {
InputStream stream = new BufferedInputStream(new FileInputStream(file));
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
parser.setErrorHandler(new DefaultHandler());
Element root = parser.parse(new InputSource(stream)).getDocumentElement();
if (!root.getNodeName().equals("libraryInfos")) {
//$NON-NLS-1$
return;
}
NodeList list = root.getChildNodes();
int length = list.getLength();
for (int i = 0; i < length; ++i) {
Node node = list.item(i);
short type = node.getNodeType();
if (type == Node.ELEMENT_NODE) {
Element element = (Element) node;
String nodeName = element.getNodeName();
if (nodeName.equalsIgnoreCase("libraryInfo")) {
//$NON-NLS-1$
//$NON-NLS-1$
String version = element.getAttribute("version");
//$NON-NLS-1$
String location = element.getAttribute("home");
//$NON-NLS-1$
String[] bootpath = getPathsFromXML(element, "bootpath");
//$NON-NLS-1$
String[] extDirs = getPathsFromXML(element, "extensionDirs");
//$NON-NLS-1$
String[] endDirs = getPathsFromXML(element, "endorsedDirs");
if (location != null) {
LibraryInfo info = new LibraryInfo(version, bootpath, extDirs, endDirs);
fgLibraryInfoMap.put(location, info);
}
}
}
}
} catch (IOException | SAXException | ParserConfigurationException e) {
log(e);
}
}
}
use of org.eclipse.core.runtime.IPath in project che by eclipse.
the class Workspace method createResource.
public void createResource(IResource resource, int updateFlags) throws CoreException {
try {
IPath path = resource.getFullPath();
switch(resource.getType()) {
case IResource.FILE:
String newName = path.lastSegment();
VirtualFileEntry child = getProjectsRoot().getChild(path.removeLastSegments(1).toOSString());
if (child == null) {
throw new NotFoundException("Can't find parent folder: " + path.removeLastSegments(1).toOSString());
}
FolderEntry entry = (FolderEntry) child;
entry.createFile(newName, new byte[0]);
break;
case IResource.FOLDER:
getProjectsRoot().createFolder(path.toOSString());
break;
case IResource.PROJECT:
ProjectConfigImpl projectConfig = new ProjectConfigImpl();
projectConfig.setPath(resource.getName());
projectConfig.setName(resource.getName());
projectConfig.setType(BaseProjectType.ID);
projectManager.get().createProject(projectConfig, new HashMap<>());
break;
default:
throw new UnsupportedOperationException();
}
} catch (ForbiddenException | ConflictException | ServerException | NotFoundException e) {
throw new CoreException(new Status(0, ResourcesPlugin.getPluginId(), e.getMessage(), e));
}
}
use of org.eclipse.core.runtime.IPath in project che by eclipse.
the class WorkspaceRoot method getProject.
@Override
public IProject getProject(String name) {
//first check our project cache
Project result = projectTable.get(name);
if (result == null) {
IPath projectPath = new Path(null, name).makeAbsolute();
//try to get the project using a canonical name
//.lastSegment();
String canonicalName = projectPath.toOSString();
result = projectTable.get(canonicalName);
if (result != null)
return result;
result = new Project(projectPath, workspace);
projectTable.putIfAbsent(canonicalName, result);
}
return result;
}
Aggregations