Search in sources :

Example 1 with ProjectBuilder

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

the class LocationTest method testBasic.

public void testBasic() throws Exception {
    Project project = ws.getProject("p1");
    assertNotNull(project);
    ProjectBuilder sub1 = project.getSubBuilder("sub1");
    assertNotNull(sub1);
    ProjectBuilder sub2 = project.getSubBuilder("sub2");
    assertNotNull(sub2);
    assertTrue(find(sub1, "sub1", "p1/sub1.bnd", 4));
    assertTrue(find(sub1, "bnd.bnd", "p1/bnd.bnd", 4));
    assertTrue(find(project, "bnd.bnd", "p1/bnd.bnd", 4));
    assertTrue(find(sub1, "i1", "p1/i1.bnd", 2));
    assertTrue(find(project, "i1", "p1/i1.bnd", 2));
    assertTrue(find(sub1, "i2", "p1/i2.bnd", 2));
    assertTrue(find(project, "i2", "p1/i2.bnd", 2));
    assertTrue(find(sub2, "sub2", "p1/sub2.bnd", 3));
    assertTrue(find(sub2, "bnd.bnd", "p1/bnd.bnd", 4));
    assertTrue(find(sub2, "workspace", "cnf/build.bnd", 6));
    assertTrue(find(project, "workspace", "cnf/build.bnd", 6));
    assertTrue(find(project.getWorkspace(), "workspace", "cnf/build.bnd", 6));
}
Also used : Project(aQute.bnd.build.Project) ProjectBuilder(aQute.bnd.build.ProjectBuilder)

Example 2 with ProjectBuilder

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

the class BundleVersionErrorHandler method generateMarkerData.

@Override
public List<MarkerData> generateMarkerData(IProject project, Project model, Location location) throws Exception {
    List<MarkerData> result = new LinkedList<MarkerData>();
    IFile bndFile = null;
    LineLocation loc = null;
    BundleInfo info = (BundleInfo) location.details;
    try (ProjectBuilder pb = model.getBuilder(null)) {
        for (Builder builder : pb.getSubBuilders()) {
            if (builder.getBsn().equals(info.bsn)) {
                File propsFile = builder.getPropertiesFile();
                // Try to find in the sub-bundle file
                if (propsFile != null) {
                    bndFile = project.getWorkspace().getRoot().getFileForLocation(new Path(propsFile.getAbsolutePath()));
                    if (bndFile != null) {
                        loc = findBundleVersionHeader(bndFile);
                    }
                }
                if (loc == null) {
                    // Not found in sub-bundle file, try bnd.bnd
                    bndFile = project.getFile(Project.BNDFILE);
                    loc = findBundleVersionHeader(bndFile);
                }
                if (loc == null) {
                    // Not found in bnd.bnd, try build.bnd. Marker will appear on bnd.bnd
                    IFile buildFile = Central.getWorkspaceBuildFile();
                    loc = findBundleVersionHeader(buildFile);
                    if (loc != null) {
                        loc = new LineLocation();
                        loc.lineNum = 1;
                        loc.start = 1;
                        loc.end = 1;
                    }
                }
                if (loc == null) {
                    // Not found in build.bnd, try included files. Marker will appear on bnd.bnd
                    List<File> extensions = Central.getWorkspace().getIncluded();
                    if (extensions != null) {
                        for (File extension : extensions) {
                            loc = findBundleVersionHeader(Central.toResource(extension));
                            if (loc != null) {
                                loc = new LineLocation();
                                loc.lineNum = 1;
                                loc.start = 1;
                                loc.end = 1;
                                break;
                            }
                        }
                    }
                }
                if (loc != null) {
                    Map<String, Object> attribs = new HashMap<String, Object>();
                    attribs.put(IMarker.MESSAGE, location.message);
                    attribs.put(IMarker.LINE_NUMBER, loc.lineNum);
                    attribs.put(IMarker.CHAR_START, loc.start);
                    attribs.put(IMarker.CHAR_END, loc.end);
                    String qualifier = null;
                    String currentVersion = builder.getUnprocessedProperty(Constants.BUNDLE_VERSION, "");
                    if (currentVersion != null) {
                        Matcher m = VERSION_ACCEPTING_MACRO.matcher(currentVersion);
                        if (m.matches()) {
                            qualifier = m.group(4);
                        }
                    }
                    attribs.put(PROP_SUGGESTED_VERSION, info.suggestedVersion.toString() + (qualifier != null ? '.' + qualifier : ""));
                    result.add(new MarkerData(bndFile, attribs, true, BndtoolsConstants.MARKER_JAVA_BASELINE));
                }
            }
        }
    }
    return result;
}
Also used : Path(org.eclipse.core.runtime.Path) MarkerData(org.bndtools.build.api.MarkerData) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) ProjectBuilder(aQute.bnd.build.ProjectBuilder) Builder(aQute.bnd.osgi.Builder) LinkedList(java.util.LinkedList) BundleInfo(aQute.bnd.differ.Baseline.BundleInfo) ProjectBuilder(aQute.bnd.build.ProjectBuilder) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 3 with ProjectBuilder

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

the class ReleaseHelper method doRelease.

private static boolean doRelease(ReleaseContext context, List<Baseline> diffs, List<IReleaseParticipant> participants) throws Exception {
    boolean ret = true;
    if (!preRelease(context, participants)) {
        postRelease(context, participants, false);
        displayErrors(context);
        return false;
    }
    try (ProjectBuilder pb = context.getProject().getBuilder(null)) {
        List<Builder> builders = pb.getSubBuilders();
        for (Baseline diff : diffs) {
            Builder builder = null;
            for (Builder b : builders) {
                if (b.getBsn().equals(diff.getBsn())) {
                    builder = b;
                    break;
                }
            }
            if (builder != null) {
                if (!release(context, participants, builder)) {
                    ret = false;
                }
            }
        }
    }
    return ret;
}
Also used : ProjectBuilder(aQute.bnd.build.ProjectBuilder) ProjectBuilder(aQute.bnd.build.ProjectBuilder) Builder(aQute.bnd.osgi.Builder) Baseline(aQute.bnd.differ.Baseline)

Example 4 with ProjectBuilder

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

the class ReleaseHelper method updateProject.

public static void updateProject(ReleaseContext context) throws Exception {
    try (ProjectBuilder pb = context.getProject().getBuilder(null)) {
        for (Builder builder : pb.getSubBuilders()) {
            Baseline current = getBaselineForBuilder(builder, context);
            if (current == null) {
                continue;
            }
            for (Info info : current.getPackageInfos()) {
                context.getProject().setPackageInfo(info.packageName, info.suggestedVersion);
            }
            updateBundleVersion(context, current, builder);
        }
    }
}
Also used : ProjectBuilder(aQute.bnd.build.ProjectBuilder) ProjectBuilder(aQute.bnd.build.ProjectBuilder) Builder(aQute.bnd.osgi.Builder) Baseline(aQute.bnd.differ.Baseline) Info(aQute.bnd.differ.Baseline.Info)

Example 5 with ProjectBuilder

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

the class WorkspaceAnalyserJob method run.

@Override
protected IStatus run(IProgressMonitor monitor) {
    IProgressMonitor mon = monitor;
    if (mon == null) {
        mon = new NullProgressMonitor();
    }
    try {
        Collection<Project> projects = Activator.getWorkspace().getAllProjects();
        mon.beginTask(Messages.workspaceReleaseJob, projects.size() * 2);
        List<Project> orderedProjects = getBuildOrder(mon, Activator.getWorkspace());
        if (mon.isCanceled()) {
            return Status.CANCEL_STATUS;
        }
        final List<ProjectDiff> projectDiffs = new ArrayList<ProjectDiff>();
        mon.setTaskName(Messages.processingProjects);
        for (Project project : orderedProjects) {
            IProject eProject = ReleaseUtils.getProject(project);
            if (!isIncluded(eProject)) {
                mon.worked(1);
                continue;
            }
            if ("".equals(project.getProperty(Constants.RELEASEREPO, null))) {
                mon.worked(1);
                continue;
            }
            if (eProject == null || !eProject.isOpen() || !eProject.isAccessible()) {
                mon.worked(1);
                continue;
            }
            List<Baseline> jarDiffs = null;
            try (ProjectBuilder pb = project.getBuilder(null)) {
                for (Builder b : pb.getSubBuilders()) {
                    mon.subTask(String.format(Messages.processingProject, b.getBsn()));
                    Baseline jarDiff = DiffHelper.createBaseline(b);
                    if (jarDiff != null) {
                        if (jarDiffs == null) {
                            jarDiffs = new ArrayList<Baseline>();
                        }
                        jarDiffs.add(jarDiff);
                    }
                }
            }
            if (jarDiffs != null && jarDiffs.size() > 0) {
                projectDiffs.add(new ProjectDiff(project, jarDiffs));
            }
            if (mon.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            mon.worked(1);
        }
        if (projectDiffs.size() == 0) {
            Runnable runnable = new Runnable() {

                @Override
                public void run() {
                    MessageDialog.openInformation(shell, Messages.releaseWorkspaceBundles, Messages.noBundlesRequireRelease);
                }
            };
            if (Display.getCurrent() == null) {
                Display.getDefault().syncExec(runnable);
            } else {
                runnable.run();
            }
            return Status.OK_STATUS;
        }
        ReleaseHelper.initializeProjectDiffs(projectDiffs);
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                WorkspaceReleaseDialog dialog = new WorkspaceReleaseDialog(shell, projectDiffs, false);
                int ret = dialog.open();
                if (ret == 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();
        }
    } catch (Exception e) {
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ProjectBuilder(aQute.bnd.build.ProjectBuilder) Builder(aQute.bnd.osgi.Builder) ArrayList(java.util.ArrayList) WorkspaceReleaseDialog(bndtools.release.ui.WorkspaceReleaseDialog) Baseline(aQute.bnd.differ.Baseline) IProject(org.eclipse.core.resources.IProject) IProject(org.eclipse.core.resources.IProject) Project(aQute.bnd.build.Project) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) 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