Search in sources :

Example 76 with Project

use of aQute.bnd.build.Project in project bndtools by bndtools.

the class BndFileCapReqLoader method getBuilder.

@Override
protected synchronized Builder getBuilder() throws Exception {
    if (builder == null) {
        Builder b;
        IFile[] wsfiles = FileUtils.getWorkspaceFiles(file);
        if (wsfiles == null || wsfiles.length == 0)
            throw new Exception("Unable to determine project owner for Bnd file: " + file.getAbsolutePath());
        IProject project = wsfiles[0].getProject();
        // Calculate the manifest
        Project bndProject = Central.getInstance().getModel(JavaCore.create(project));
        if (bndProject == null)
            return null;
        if (file.getName().equals(Project.BNDFILE)) {
            b = bndProject.getSubBuilders().iterator().next();
        } else {
            b = bndProject.getSubBuilder(file);
        }
        if (b == null) {
            b = new Builder();
            b.setProperties(file);
        }
        b.build();
        builder = b;
    }
    return builder;
}
Also used : Project(aQute.bnd.build.Project) IProject(org.eclipse.core.resources.IProject) IFile(org.eclipse.core.resources.IFile) Builder(aQute.bnd.osgi.Builder) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject)

Example 77 with Project

use of aQute.bnd.build.Project in project bndtools by bndtools.

the class NativeBndLaunchDelegate method launch.

/*
     * The Eclipse launch interface.
     */
@Override
public void launch(ILaunchConfiguration configuration, String mode, final ILaunch launch, IProgressMonitor m) throws CoreException {
    final IProgressMonitor monitor = m == null ? new NullProgressMonitor() : m;
    Callable<Boolean> isCancelled = new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return canceled || monitor.isCanceled();
        }
    };
    Processor p = new Processor();
    try {
        monitor.setTaskName("Detecting if configuration is already launched");
        if (isAlreadyRunning(configuration)) {
            return;
        }
        String target = configuration.getAttribute(LaunchConstants.ATTR_LAUNCH_TARGET, (String) null);
        if (target == null || target.length() == 0) {
            p.error("No target specified in the launch configuration");
            return;
        }
        IResource targetResource = ResourcesPlugin.getWorkspace().getRoot().findMember(target);
        if (targetResource == null) {
            p.error("No actual resource found for " + target);
            return;
        }
        IProject parent = targetResource.getProject();
        if (parent == null) {
            p.error("Not part of a project " + targetResource);
            return;
        }
        Project parentModel = Central.getProject(parent);
        if (parentModel == null) {
            p.error("Cannot locate Bnd project for " + targetResource);
            return;
        }
        Project model;
        if (targetResource.getName().equals(Project.BNDFILE)) {
            model = parentModel;
        } else {
            File file = targetResource.getLocation().toFile();
            if (file == null || !file.isFile()) {
                p.error("No file associated with the entry " + targetResource);
                return;
            }
            model = new Run(parentModel.getWorkspace(), parentModel.getBase(), file);
        }
        monitor.setTaskName("Target is " + model);
        boolean debug = "debug".equals(mode);
        try {
            List<LaunchThread> lts = new ArrayList<LaunchThread>();
            ProjectLauncher projectLauncher = model.getProjectLauncher();
            try {
                List<? extends RunSession> sessions = projectLauncher.getRunSessions();
                if (sessions == null) {
                    projectLauncher.error("This launcher for %s cannot handle the new style", target);
                    return;
                }
                for (RunSession session : sessions) try {
                    monitor.setTaskName("validating session " + session.getLabel());
                    if (!session.validate(isCancelled)) {
                        continue;
                    }
                    LaunchThread lt = new LaunchThread(projectLauncher, session, launch);
                    if (debug) {
                        lt.doDebug(monitor);
                    }
                    if (monitor.isCanceled())
                        return;
                    launch.addProcess(lt);
                    lts.add(lt);
                } catch (Exception e) {
                    projectLauncher.exception(e, "Starting session %s in project %s", session.getName(), model);
                }
            } catch (Exception e) {
                projectLauncher.exception(e, "starting processes");
            } finally {
                p.getInfo(projectLauncher);
            }
            if (!p.isOk()) {
                IStatus status = Central.toStatus(projectLauncher, "Errors detected during the launch");
                IStatusHandler prompter = DebugPlugin.getDefault().getStatusHandler(status);
                Boolean cont = (Boolean) prompter.handleStatus(status, null);
                if (cont == null || !cont || monitor.isCanceled()) {
                    launch.terminate();
                    return;
                }
            }
            for (LaunchThread lt : lts) {
                lt.start();
            }
        } catch (Exception e) {
            launch.terminate();
            abort("Internal error", e, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
        }
    } catch (Exception e) {
        p.exception(e, "While starting a launch %s", configuration);
    } finally {
        if (!p.isOk()) {
            IStatus status = Central.toStatus(p, "Errors detected during the launch");
            IStatusHandler prompter = new LaunchStatusHandler();
            prompter.handleStatus(status, null);
            launch.terminate();
        }
        monitor.done();
        IO.close(p);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) Processor(aQute.bnd.osgi.Processor) ArrayList(java.util.ArrayList) ProjectLauncher(aQute.bnd.build.ProjectLauncher) Run(aQute.bnd.build.Run) Callable(java.util.concurrent.Callable) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) Project(aQute.bnd.build.Project) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatusHandler(org.eclipse.debug.core.IStatusHandler) RunSession(aQute.bnd.build.RunSession) File(java.io.File) IResource(org.eclipse.core.resources.IResource) LaunchStatusHandler(bndtools.launch.ui.internal.LaunchStatusHandler)

Example 78 with Project

use of aQute.bnd.build.Project in project bndtools by bndtools.

the class ProjectLaunchTabPiece method loadProjects.

static List<IProject> loadProjects() {
    Collection<Project> projects;
    try {
        Workspace workspace = Central.getWorkspace();
        projects = workspace.getAllProjects();
    } catch (Exception e) {
        logger.logError("Internal error querying projects.", e);
        return Collections.emptyList();
    }
    List<IProject> result = new ArrayList<IProject>(projects.size());
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    for (Project project : projects) {
        IProject iproject = workspaceRoot.getProject(project.getName());
        if (iproject != null && iproject.isOpen()) {
            result.add(iproject);
        }
    }
    return result;
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(aQute.bnd.build.Project) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ArrayList(java.util.ArrayList) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) Workspace(aQute.bnd.build.Workspace)

Example 79 with Project

use of aQute.bnd.build.Project in project bndtools by bndtools.

the class LaunchUtils method getLaunchProjectName.

public static String getLaunchProjectName(IResource launchResource) {
    String result;
    IProject project = launchResource.getProject();
    Project bnd;
    try {
        bnd = Central.getWorkspace().getProject(project.getName());
    } catch (Exception e) {
        bnd = null;
    }
    result = (bnd != null) ? bnd.getName() : Project.BNDCNF;
    return result;
}
Also used : Project(aQute.bnd.build.Project) IProject(org.eclipse.core.resources.IProject) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException)

Example 80 with Project

use of aQute.bnd.build.Project in project bndtools by bndtools.

the class ReleaseAction method run.

public void run(IAction action) {
    if (bndFiles != null) {
        if (ReleaseHelper.getReleaseRepositories().length == 0) {
            Activator.message(Messages.noReleaseRepos);
            return;
        }
        if (!PlatformUI.getWorkbench().saveAllEditors(true)) {
            return;
        }
        for (Map.Entry<Project, List<File>> me : bndFiles.entrySet()) {
            Project project;
            try {
                project = me.getKey();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            ReleaseDialogJob job;
            if (isBndBndSelected(me.getValue())) {
                job = new ReleaseDialogJob(project, null);
            } else {
                job = new ReleaseDialogJob(project, me.getValue());
            }
            job.schedule();
        }
    }
}
Also used : Project(aQute.bnd.build.Project) IProject(org.eclipse.core.resources.IProject) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Project (aQute.bnd.build.Project)140 Workspace (aQute.bnd.build.Workspace)70 File (java.io.File)45 ArrayList (java.util.ArrayList)22 IProject (org.eclipse.core.resources.IProject)21 Container (aQute.bnd.build.Container)19 IOException (java.io.IOException)17 ProjectLauncher (aQute.bnd.build.ProjectLauncher)15 Version (aQute.bnd.version.Version)12 Description (aQute.lib.getopt.Description)12 Jar (aQute.bnd.osgi.Jar)11 Builder (aQute.bnd.osgi.Builder)10 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)10 IJavaProject (org.eclipse.jdt.core.IJavaProject)9 Run (aQute.bnd.build.Run)8 BuildException (org.apache.tools.ant.BuildException)8 CoreException (org.eclipse.core.runtime.CoreException)8 IFile (org.eclipse.core.resources.IFile)7 ProjectBuilder (aQute.bnd.build.ProjectBuilder)6 ProjectTester (aQute.bnd.build.ProjectTester)5