Search in sources :

Example 11 with ProjectBuilder

use of aQute.bnd.build.ProjectBuilder 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)) {
            ProjectBuilder pb = bndProject.getBuilder(null);
            boolean close = true;
            try {
                b = pb.getSubBuilders().get(0);
                if (b == pb) {
                    close = false;
                } else {
                    pb.removeClose(b);
                }
            } finally {
                if (close) {
                    pb.close();
                }
            }
        } 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) ProjectBuilder(aQute.bnd.build.ProjectBuilder) Builder(aQute.bnd.osgi.Builder) ProjectBuilder(aQute.bnd.build.ProjectBuilder) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject)

Example 12 with ProjectBuilder

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

the class RepositoryTreeContentProvider method getProjectBundles.

Object[] getProjectBundles(Project project) {
    ProjectBundle[] result = null;
    try (ProjectBuilder pb = project.getBuilder(null)) {
        List<Builder> builders = pb.getSubBuilders();
        result = new ProjectBundle[builders.size()];
        int i = 0;
        for (Builder builder : builders) {
            ProjectBundle bundle = new ProjectBundle(project, builder.getBsn());
            result[i++] = bundle;
        }
    } catch (Exception e) {
        logger.logError(MessageFormat.format("Error querying sub-bundles for project {0}.", project.getName()), e);
    }
    return result;
}
Also used : ProjectBuilder(aQute.bnd.build.ProjectBuilder) ProjectBuilder(aQute.bnd.build.ProjectBuilder) Builder(aQute.bnd.osgi.Builder)

Example 13 with ProjectBuilder

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

the class DiffHelper method createBaseline.

public static Baseline createBaseline(Builder builder) {
    try {
        if (builder instanceof ProjectBuilder) {
            ProjectBuilder projectBuilder = (ProjectBuilder) builder;
            Jar jar = null;
            Jar currentJar = null;
            try {
                jar = projectBuilder.build();
                currentJar = projectBuilder.getBaselineJar();
                if (currentJar == null) {
                    currentJar = projectBuilder.getLastRevision();
                }
                if (currentJar == null) {
                    // $NON-NLS-1$
                    currentJar = new Jar(".");
                }
                DiffPluginImpl differ = new DiffPluginImpl();
                String diffignore = projectBuilder.getProperty(Constants.DIFFIGNORE);
                if (diffignore != null)
                    differ.setIgnore(diffignore);
                Baseline baseline = new Baseline(projectBuilder, differ);
                baseline.baseline(jar, currentJar, null);
                return baseline;
            } finally {
                if (jar != null)
                    jar.close();
                if (currentJar != null)
                    currentJar.close();
            }
        }
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    return null;
}
Also used : DiffPluginImpl(aQute.bnd.differ.DiffPluginImpl) ProjectBuilder(aQute.bnd.build.ProjectBuilder) Jar(aQute.bnd.osgi.Jar) Baseline(aQute.bnd.differ.Baseline)

Example 14 with ProjectBuilder

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

the class ReleaseDialogJob method run.

@Override
protected IStatus run(IProgressMonitor monitor) {
    try {
        monitor.beginTask(Messages.cleaningProject, 100);
        monitor.setTaskName(Messages.releasing);
        monitor.worked(33);
        monitor.subTask(Messages.checkingExported);
        final List<Baseline> diffs = new ArrayList<Baseline>();
        try (ProjectBuilder pb = project.getBuilder(null)) {
            for (Builder builder : pb.getSubBuilders()) {
                if (subBundles != null) {
                    if (!subBundles.contains(builder.getPropertiesFile())) {
                        continue;
                    }
                }
                Baseline diff = DiffHelper.createBaseline(builder);
                if (diff != null) {
                    diffs.add(diff);
                }
            }
        }
        if (diffs.size() == 0) {
            // TODO: message
            return Status.OK_STATUS;
        }
        monitor.worked(33);
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                List<ProjectDiff> projectDiffs = new ArrayList<ProjectDiff>();
                projectDiffs.add(new ProjectDiff(project, diffs));
                ReleaseHelper.initializeProjectDiffs(projectDiffs);
                WorkspaceReleaseDialog dialog = new WorkspaceReleaseDialog(shell, projectDiffs, true);
                if (dialog.open() == Window.OK) {
                    boolean runJob = false;
                    for (ProjectDiff diff : projectDiffs) {
                        if (diff.isRelease()) {
                            runJob = true;
                            break;
                        }
                    }
                    if (!runJob) {
                        return;
                    }
                    WorkspaceReleaseJob releaseJob = new WorkspaceReleaseJob(projectDiffs, dialog.getReleaseOption(), dialog.isShowMessage());
                    releaseJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
                    releaseJob.schedule();
                }
            }
        };
        if (Display.getCurrent() == null) {
            Display.getDefault().asyncExec(runnable);
        } else {
            runnable.run();
        }
        monitor.worked(33);
        return Status.OK_STATUS;
    } catch (Exception e) {
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error : " + e.getMessage(), e);
    } finally {
        monitor.done();
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ProjectBuilder(aQute.bnd.build.ProjectBuilder) Builder(aQute.bnd.osgi.Builder) ArrayList(java.util.ArrayList) WorkspaceReleaseDialog(bndtools.release.ui.WorkspaceReleaseDialog) Baseline(aQute.bnd.differ.Baseline) ProjectBuilder(aQute.bnd.build.ProjectBuilder)

Aggregations

ProjectBuilder (aQute.bnd.build.ProjectBuilder)14 Builder (aQute.bnd.osgi.Builder)10 Project (aQute.bnd.build.Project)7 Baseline (aQute.bnd.differ.Baseline)5 Jar (aQute.bnd.osgi.Jar)4 File (java.io.File)3 IStatus (org.eclipse.core.runtime.IStatus)3 DiffPluginImpl (aQute.bnd.differ.DiffPluginImpl)2 WorkspaceReleaseDialog (bndtools.release.ui.WorkspaceReleaseDialog)2 ArrayList (java.util.ArrayList)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 Status (org.eclipse.core.runtime.Status)2 Workspace (aQute.bnd.build.Workspace)1 BundleInfo (aQute.bnd.differ.Baseline.BundleInfo)1 Info (aQute.bnd.differ.Baseline.Info)1 Attrs (aQute.bnd.header.Attrs)1 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)1 Version (aQute.bnd.version.Version)1 Description (aQute.lib.getopt.Description)1