Search in sources :

Example 1 with JavaProjectSourceContainer

use of org.eclipse.jdt.launching.sourcelookup.containers.JavaProjectSourceContainer in project bndtools by bndtools.

the class BndDependencySourceContainer method createSourceContainers.

@Override
protected ISourceContainer[] createSourceContainers() throws CoreException {
    List<ISourceContainer> result = new LinkedList<ISourceContainer>();
    ILaunchConfiguration config = getLaunchConfiguration();
    Set<String> projectsAdded = new HashSet<>();
    try {
        if (lastRun != null) {
            LaunchUtils.endRun(lastRun);
        }
        Run run = LaunchUtils.createRun(config);
        if (run != null) {
            Collection<Container> runbundles = run.getRunbundles();
            for (Container runbundle : runbundles) {
                if (runbundle.getType() == TYPE.PROJECT) {
                    String targetProjName = runbundle.getProject().getName();
                    if (projectsAdded.add(targetProjName)) {
                        IProject targetProj = ResourcesPlugin.getWorkspace().getRoot().getProject(targetProjName);
                        if (targetProj != null) {
                            IJavaProject targetJavaProj = JavaCore.create(targetProj);
                            result.add(new JavaProjectSourceContainer(targetJavaProj));
                        }
                    }
                } else if (runbundle.getType() == TYPE.REPO) {
                    IPath bundlePath = Central.toPath(runbundle.getFile());
                    IFile bundleFile = null;
                    if (bundlePath != null) {
                        bundleFile = ResourcesPlugin.getWorkspace().getRoot().getFile(bundlePath);
                    }
                    if (bundleFile != null) {
                        ISourceContainer sourceContainer = null;
                        // check to see if this archive came from a repo that encodes the source project name
                        final String sourceProjectName = runbundle.getAttributes().get("sourceProjectName");
                        if (sourceProjectName != null) {
                            try {
                                IProject sourceProject = ResourcesPlugin.getWorkspace().getRoot().getProject(sourceProjectName);
                                if (sourceProject.exists()) {
                                    IJavaProject javaSourceProject = JavaCore.create(sourceProject);
                                    sourceContainer = new JavaProjectSourceContainer(javaSourceProject);
                                }
                            } catch (Exception e) {
                                logger.logError("Error getting source java project", e);
                            }
                        }
                        if (sourceContainer == null) {
                            // default to archive source container
                            sourceContainer = new ArchiveSourceContainer(bundleFile, false);
                        }
                        result.add(sourceContainer);
                    } else {
                        ExternalArchiveSourceContainer container = new ExternalArchiveSourceContainer(runbundle.getFile().toString(), false);
                        result.add(container);
                    }
                }
            }
            lastRun = run;
        }
    } catch (Exception e) {
        logger.logError("Error querying Bnd dependency source containers.", e);
    }
    return result.toArray(new ISourceContainer[0]);
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) Run(aQute.bnd.build.Run) JavaProjectSourceContainer(org.eclipse.jdt.launching.sourcelookup.containers.JavaProjectSourceContainer) LinkedList(java.util.LinkedList) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) ArchiveSourceContainer(org.eclipse.debug.core.sourcelookup.containers.ArchiveSourceContainer) Container(aQute.bnd.build.Container) JavaProjectSourceContainer(org.eclipse.jdt.launching.sourcelookup.containers.JavaProjectSourceContainer) CompositeSourceContainer(org.eclipse.debug.core.sourcelookup.containers.CompositeSourceContainer) ExternalArchiveSourceContainer(org.eclipse.debug.core.sourcelookup.containers.ExternalArchiveSourceContainer) ISourceContainer(org.eclipse.debug.core.sourcelookup.ISourceContainer) IJavaProject(org.eclipse.jdt.core.IJavaProject) ArchiveSourceContainer(org.eclipse.debug.core.sourcelookup.containers.ArchiveSourceContainer) ExternalArchiveSourceContainer(org.eclipse.debug.core.sourcelookup.containers.ExternalArchiveSourceContainer) ISourceContainer(org.eclipse.debug.core.sourcelookup.ISourceContainer) ExternalArchiveSourceContainer(org.eclipse.debug.core.sourcelookup.containers.ExternalArchiveSourceContainer) HashSet(java.util.HashSet)

Aggregations

Container (aQute.bnd.build.Container)1 Run (aQute.bnd.build.Run)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)1 ISourceContainer (org.eclipse.debug.core.sourcelookup.ISourceContainer)1 ArchiveSourceContainer (org.eclipse.debug.core.sourcelookup.containers.ArchiveSourceContainer)1 CompositeSourceContainer (org.eclipse.debug.core.sourcelookup.containers.CompositeSourceContainer)1 ExternalArchiveSourceContainer (org.eclipse.debug.core.sourcelookup.containers.ExternalArchiveSourceContainer)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 JavaProjectSourceContainer (org.eclipse.jdt.launching.sourcelookup.containers.JavaProjectSourceContainer)1