use of org.eclipse.core.resources.IWorkspaceRoot in project bndtools by bndtools.
the class Central method getWorkspaceDirectory.
private static File getWorkspaceDirectory() throws CoreException {
IWorkspaceRoot eclipseWorkspace = ResourcesPlugin.getWorkspace().getRoot();
IProject cnfProject = eclipseWorkspace.getProject(Workspace.BNDDIR);
if (!cnfProject.exists())
cnfProject = eclipseWorkspace.getProject(Workspace.CNFDIR);
if (cnfProject.exists()) {
if (!cnfProject.isOpen())
cnfProject.open(null);
return cnfProject.getLocation().toFile().getParentFile();
}
return null;
}
use of org.eclipse.core.resources.IWorkspaceRoot in project bndtools by bndtools.
the class Central method toResource.
/**
* Return the IResource associated with a file
*
* @param file
* @return
*/
public static IResource toResource(File file) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile[] ifiles = root.findFilesForLocationURI(file.toURI());
if (ifiles == null || ifiles.length == 0)
return null;
return ifiles[0];
}
use of org.eclipse.core.resources.IWorkspaceRoot in project bndtools by bndtools.
the class CreateFileChange method perform.
@Override
public Change perform(IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, encoding != null ? 2 : 1);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile file = root.getFile(path);
file.create(source, updateFlags, progress.newChild(1, SubMonitor.SUPPRESS_NONE));
if (encoding != null)
file.setCharset(encoding, progress.newChild(1, SubMonitor.SUPPRESS_NONE));
return new DeleteResourceChange(path, true);
}
use of org.eclipse.core.resources.IWorkspaceRoot in project bndtools by bndtools.
the class BndContainerSourceManager method getSourceBundle.
private static File getSourceBundle(IPath path, Map<String, String> props) {
Workspace bndWorkspace;
try {
bndWorkspace = Central.getWorkspace();
if (bndWorkspace == null) {
return null;
}
} catch (final Exception e) {
return null;
}
IPath bundlePath = path;
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IResource resource = root.findMember(path);
if (resource != null) {
bundlePath = resource.getLocation();
}
try (JarInputStream jarStream = new JarInputStream(IO.stream(bundlePath.toFile()), false)) {
Manifest manifest = jarStream.getManifest();
if (manifest == null) {
return null;
}
Domain domain = Domain.domain(manifest);
Entry<String, Attrs> bsnAttrs = domain.getBundleSymbolicName();
if (bsnAttrs == null) {
return null;
}
String bsn = bsnAttrs.getKey();
String version = domain.getBundleVersion();
if (version == null) {
version = props.get("version");
}
for (RepositoryPlugin repo : RepositoryUtils.listRepositories(true)) {
if (repo == null) {
continue;
}
if (repo instanceof WorkspaceRepository) {
continue;
}
File sourceBundle = repo.get(bsn + ".source", new Version(version), props);
if (sourceBundle != null) {
return sourceBundle;
}
}
} catch (final Exception e) {
// Ignore, something went wrong, or we could not find the source bundle
}
return null;
}
use of org.eclipse.core.resources.IWorkspaceRoot in project bndtools by bndtools.
the class RepositoryEntry method getAdapter.
@Override
public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
// Avoid getting the file if the requested adapter type is not supported.
boolean adaptable = IFile.class.equals(adapter) || File.class.equals(adapter) || URI.class.equals(adapter);
if (!adaptable)
return null;
if (IFile.class.equals(adapter)) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
File file = getFile(false);
return file != null ? root.getFileForLocation(new Path(file.getAbsolutePath())) : null;
}
if (File.class.equals(adapter))
return getFile(false);
if (URI.class.equals(adapter)) {
File file = getFile(false);
return file != null ? file.toURI() : null;
}
return null;
}
Aggregations