Search in sources :

Example 36 with IWorkspaceRoot

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;
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProject(org.eclipse.core.resources.IProject)

Example 37 with IWorkspaceRoot

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];
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot)

Example 38 with IWorkspaceRoot

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);
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) SubMonitor(org.eclipse.core.runtime.SubMonitor) DeleteResourceChange(org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange)

Example 39 with IWorkspaceRoot

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) JarInputStream(java.util.jar.JarInputStream) Attrs(aQute.bnd.header.Attrs) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Manifest(java.util.jar.Manifest) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) Version(aQute.bnd.version.Version) WorkspaceRepository(aQute.bnd.build.WorkspaceRepository) IWorkspace(org.eclipse.core.resources.IWorkspace) Domain(aQute.bnd.osgi.Domain) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IWorkspace(org.eclipse.core.resources.IWorkspace) Workspace(aQute.bnd.build.Workspace)

Example 40 with IWorkspaceRoot

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;
}
Also used : Path(org.eclipse.core.runtime.Path) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) URI(java.net.URI) File(java.io.File) IFile(org.eclipse.core.resources.IFile)

Aggregations

IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)172 IProject (org.eclipse.core.resources.IProject)69 IPath (org.eclipse.core.runtime.IPath)60 IResource (org.eclipse.core.resources.IResource)57 IFile (org.eclipse.core.resources.IFile)53 CoreException (org.eclipse.core.runtime.CoreException)50 IWorkspace (org.eclipse.core.resources.IWorkspace)34 File (java.io.File)30 Path (org.eclipse.core.runtime.Path)29 IContainer (org.eclipse.core.resources.IContainer)26 URI (java.net.URI)18 IFolder (org.eclipse.core.resources.IFolder)17 IOException (java.io.IOException)15 IProjectDescription (org.eclipse.core.resources.IProjectDescription)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 IStatus (org.eclipse.core.runtime.IStatus)11 IJavaProject (org.eclipse.jdt.core.IJavaProject)11 Location (ch.acanda.eclipse.pmd.domain.Location)10