Search in sources :

Example 81 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project bndtools by bndtools.

the class BndtoolsBuilder method calculateDependsOn.

private IProject[] calculateDependsOn(Project model) throws Exception {
    Collection<Project> dependsOn = model.getDependson();
    IWorkspaceRoot wsroot = getProject().getWorkspace().getRoot();
    List<IProject> result = new ArrayList<IProject>(dependsOn.size() + 1);
    IProject cnfProject = WorkspaceUtils.findCnfProject(wsroot, model.getWorkspace());
    if (cnfProject != null) {
        result.add(cnfProject);
    }
    for (Project project : dependsOn) {
        IProject targetProj = WorkspaceUtils.findOpenProject(wsroot, project);
        if (targetProj == null)
            logger.logWarning("No open project in workspace for Bnd '-dependson' dependency: " + project.getName(), null);
        else
            result.add(targetProj);
    }
    buildLog.full("Calculated dependsOn list: %s", result);
    return result.toArray(new IProject[0]);
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(aQute.bnd.build.Project) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject)

Example 82 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project bndtools by bndtools.

the class ResolutionView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    this.display = parent.getDisplay();
    SashForm splitPanel = new SashForm(parent, SWT.HORIZONTAL);
    splitPanel.setLayout(new FillLayout());
    Composite reqsPanel = new Composite(splitPanel, SWT.NONE);
    reqsPanel.setBackground(parent.getBackground());
    GridLayout reqsLayout = new GridLayout(1, false);
    reqsLayout.marginWidth = 0;
    reqsLayout.marginHeight = 0;
    reqsLayout.verticalSpacing = 2;
    reqsPanel.setLayout(reqsLayout);
    new Label(reqsPanel, SWT.NONE).setText("Requirements:");
    reqsTree = new Tree(reqsPanel, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    reqsTree.setHeaderVisible(false);
    reqsTree.setLinesVisible(false);
    reqsTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    reqsViewer = new TreeViewer(reqsTree);
    ColumnViewerToolTipSupport.enableFor(reqsViewer);
    reqsViewer.setLabelProvider(new RequirementWrapperLabelProvider(true));
    reqsViewer.setContentProvider(new CapReqMapContentProvider());
    Composite capsPanel = new Composite(splitPanel, SWT.NONE);
    capsPanel.setBackground(parent.getBackground());
    GridLayout capsLayout = new GridLayout(1, false);
    capsLayout.marginWidth = 0;
    capsLayout.marginHeight = 0;
    capsLayout.verticalSpacing = 2;
    capsPanel.setLayout(capsLayout);
    new Label(capsPanel, SWT.NONE).setText("Capabilities:");
    capsTable = new Table(capsPanel, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    capsTable.setHeaderVisible(false);
    capsTable.setLinesVisible(false);
    capsTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    capsViewer = new TableViewer(capsTable);
    ColumnViewerToolTipSupport.enableFor(capsViewer);
    capsViewer.setLabelProvider(new CapabilityLabelProvider(true));
    capsViewer.setContentProvider(new CapReqMapContentProvider());
    capsViewer.setFilters(new ViewerFilter[] { new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parent, Object element) {
            return !filteredCapabilityNamespaces.contains(((Capability) element).getNamespace());
        }
    } });
    hideSelfImportsFilter = new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof RequirementWrapper) {
                RequirementWrapper rw = (RequirementWrapper) element;
                return !rw.resolved;
            }
            return true;
        }
    };
    reqsViewer.setFilters(new ViewerFilter[] { hideSelfImportsFilter });
    reqsViewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new LocalTransferDragListener(reqsViewer));
    capsViewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new LocalTransferDragListener(capsViewer));
    reqsViewer.addOpenListener(new IOpenListener() {

        @Override
        public void open(OpenEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            for (Iterator<?> iter = selection.iterator(); iter.hasNext(); ) {
                Object item = iter.next();
                if (item instanceof Clazz) {
                    Clazz clazz = (Clazz) item;
                    String className = clazz.getFQN();
                    IType type = null;
                    if (!loaders.isEmpty()) {
                        IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
                        for (CapReqLoader loader : loaders) {
                            if (loader instanceof BndBuilderCapReqLoader) {
                                File loaderFile = ((BndBuilderCapReqLoader) loader).getFile();
                                IFile[] wsfiles = wsroot.findFilesForLocationURI(loaderFile.toURI());
                                for (IFile wsfile : wsfiles) {
                                    IJavaProject javaProject = JavaCore.create(wsfile.getProject());
                                    try {
                                        type = javaProject.findType(className);
                                        if (type != null)
                                            break;
                                    } catch (JavaModelException e) {
                                        ErrorDialog.openError(getSite().getShell(), "Error", "", new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error opening Java class '{0}'.", className), e));
                                    }
                                }
                            }
                        }
                    }
                    try {
                        if (type != null)
                            JavaUI.openInEditor(type, true, true);
                    } catch (PartInitException e) {
                        ErrorDialog.openError(getSite().getShell(), "Error", "", new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error opening Java editor for class '{0}'.", className), e));
                    } catch (JavaModelException e) {
                        ErrorDialog.openError(getSite().getShell(), "Error", "", new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error opening Java class '{0}'.", className), e));
                    }
                }
            }
        }
    });
    fillActionBars();
    getSite().getPage().addPostSelectionListener(this);
    getSite().getPage().addPartListener(partAdapter);
    ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
    // Current selection & part
    IWorkbenchPart activePart = getSite().getPage().getActivePart();
    ISelection activeSelection = getSite().getWorkbenchWindow().getSelectionService().getSelection();
    selectionChanged(activePart, activeSelection);
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IFile(org.eclipse.core.resources.IFile) CapReqMapContentProvider(bndtools.model.resolution.CapReqMapContentProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IType(org.eclipse.jdt.core.IType) GridLayout(org.eclipse.swt.layout.GridLayout) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) Iterator(java.util.Iterator) ISelection(org.eclipse.jface.viewers.ISelection) Tree(org.eclipse.swt.widgets.Tree) Clazz(aQute.bnd.osgi.Clazz) BndFileCapReqLoader(bndtools.tasks.BndFileCapReqLoader) BndBuilderCapReqLoader(bndtools.tasks.BndBuilderCapReqLoader) JarFileCapReqLoader(bndtools.tasks.JarFileCapReqLoader) ResourceCapReqLoader(bndtools.tasks.ResourceCapReqLoader) CapReqLoader(bndtools.tasks.CapReqLoader) PartInitException(org.eclipse.ui.PartInitException) RequirementWrapper(bndtools.model.resolution.RequirementWrapper) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) CapabilityLabelProvider(bndtools.model.resolution.CapabilityLabelProvider) FillLayout(org.eclipse.swt.layout.FillLayout) BndBuilderCapReqLoader(bndtools.tasks.BndBuilderCapReqLoader) SashForm(org.eclipse.swt.custom.SashForm) RequirementWrapperLabelProvider(bndtools.model.resolution.RequirementWrapperLabelProvider) IOpenListener(org.eclipse.jface.viewers.IOpenListener) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) IFile(org.eclipse.core.resources.IFile) File(java.io.File) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Example 83 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project bndtools by bndtools.

the class ResolutionView method resourceChanged.

@Override
public void resourceChanged(IResourceChangeEvent event) {
    if (!loaders.isEmpty()) {
        IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
        for (CapReqLoader loader : loaders) {
            if (loader instanceof BndBuilderCapReqLoader) {
                File file = ((BndBuilderCapReqLoader) loader).getFile();
                IFile[] wsfiles = wsroot.findFilesForLocationURI(file.toURI());
                for (IFile wsfile : wsfiles) {
                    if (event.getDelta().findMember(wsfile.getFullPath()) != null) {
                        executeAnalysis();
                        break;
                    }
                }
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) BndFileCapReqLoader(bndtools.tasks.BndFileCapReqLoader) BndBuilderCapReqLoader(bndtools.tasks.BndBuilderCapReqLoader) JarFileCapReqLoader(bndtools.tasks.JarFileCapReqLoader) ResourceCapReqLoader(bndtools.tasks.ResourceCapReqLoader) CapReqLoader(bndtools.tasks.CapReqLoader) IFile(org.eclipse.core.resources.IFile) File(java.io.File) BndBuilderCapReqLoader(bndtools.tasks.BndBuilderCapReqLoader)

Example 84 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project bndtools by bndtools.

the class ImportBndWorkspaceWizard method importBndProject.

private void importBndProject(final Project bndProject, final Workspace bndWorkspace, final ImportSettings importSettings, IProgressMonitor monitor) throws IOException, CoreException, Exception {
    monitor.subTask("Import Bnd project '" + bndProject.getName() + "'.");
    final IWorkspace eclipseWorkspace = ResourcesPlugin.getWorkspace();
    final IWorkspaceRoot eclipseWorkspaceRoot = eclipseWorkspace.getRoot();
    if (importSettings.deleteSettings) {
        deleteOldProjectFiles(Paths.get(bndWorkspace.getBaseURI()).resolve(bndProject.getName()));
    }
    // create generic project
    final IProjectDescription projectDescription = eclipseWorkspace.newProjectDescription(bndProject.getName());
    final IProject project = eclipseWorkspaceRoot.getProject(bndProject.getName());
    IPath path = URIUtil.toPath(bndProject.getBaseURI());
    if (Platform.getLocation().isPrefixOf(path)) {
        projectDescription.setLocation(null);
    } else {
        projectDescription.setLocation(path);
    }
    if (!project.exists()) {
        project.create(projectDescription, monitor);
    }
    project.open(monitor);
    setNatures(project, monitor, JavaCore.NATURE_ID, Plugin.BNDTOOLS_NATURE);
    IJavaProject javaProject = JavaCore.create(project);
    if (!javaProject.isOpen()) {
        javaProject.open(monitor);
    }
    updateJavaProjectSettings(bndProject, javaProject, importSettings, monitor);
    importSourceAndOutputFolders(bndProject, project, javaProject, monitor);
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject)

Example 85 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project bndtools by bndtools.

the class FileUtils method toWorkspaceResource.

public static IResource toWorkspaceResource(File file) {
    IPath path = new Path(file.toString());
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IWorkspaceRoot workspaceRoot = workspace.getRoot();
    IPath workspacePath = workspaceRoot.getLocation();
    if (workspacePath.isPrefixOf(path)) {
        final IPath relativePath = path.removeFirstSegments(workspacePath.segmentCount());
        IResource resource;
        if (file.isDirectory()) {
            resource = workspaceRoot.getFolder(relativePath);
        } else {
            resource = workspaceRoot.getFile(relativePath);
        }
        return resource;
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) IResource(org.eclipse.core.resources.IResource)

Aggregations

IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)92 IPath (org.eclipse.core.runtime.IPath)41 IProject (org.eclipse.core.resources.IProject)31 IFile (org.eclipse.core.resources.IFile)30 IResource (org.eclipse.core.resources.IResource)29 CoreException (org.eclipse.core.runtime.CoreException)25 File (java.io.File)19 IWorkspace (org.eclipse.core.resources.IWorkspace)15 Path (org.eclipse.core.runtime.Path)14 IFolder (org.eclipse.core.resources.IFolder)12 IJavaProject (org.eclipse.jdt.core.IJavaProject)11 ArrayList (java.util.ArrayList)10 IContainer (org.eclipse.core.resources.IContainer)10 IOException (java.io.IOException)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 URI (java.net.URI)5 IProjectDescription (org.eclipse.core.resources.IProjectDescription)5 IStatus (org.eclipse.core.runtime.IStatus)5 Project (aQute.bnd.build.Project)4 Workspace (aQute.bnd.build.Workspace)4