Search in sources :

Example 11 with Project

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

the class bnd method runtTest.

/**
	 * Help function to run the tests
	 */
private int runtTest(File testFile, Workspace ws, File reportDir, Tag summary) throws Exception {
    File tmpDir = new File(reportDir, "tmp");
    IO.mkdirs(tmpDir);
    tmpDir.deleteOnExit();
    Tag test = new Tag(summary, "test");
    test.addAttribute("path", testFile.getAbsolutePath());
    if (!testFile.isFile()) {
        error("No bnd file: %s", testFile);
        test.addAttribute("exception", "No bnd file found");
        error("No bnd file found for %s", testFile.getAbsolutePath());
        return 1;
    }
    Project project = new Project(ws, testFile.getAbsoluteFile().getParentFile(), testFile.getAbsoluteFile());
    project.use(this);
    project.setProperty(NOBUNDLES, "true");
    ProjectTester tester = project.getProjectTester();
    if (!project.isOk()) {
        getInfo(project, project.toString() + ": " + testFile.getName() + ":");
        // Indicate failure but do not abort
        return 1;
    }
    tester.setContinuous(false);
    tester.setReportDir(tmpDir);
    test.addAttribute("title", project.toString());
    long start = System.currentTimeMillis();
    try {
        int errors = tester.test();
        Collection<File> reports = tester.getReports();
        for (File report : reports) {
            Tag bundle = new Tag(test, "bundle");
            File dest = new File(reportDir, report.getName());
            IO.rename(report, dest);
            bundle.addAttribute("file", dest.getAbsolutePath());
            doPerReport(bundle, dest);
        }
        switch(errors) {
            case ProjectLauncher.OK:
                return 0;
            case ProjectLauncher.CANCELED:
                test.addAttribute("failed", "canceled");
                return 1;
            case ProjectLauncher.DUPLICATE_BUNDLE:
                test.addAttribute("failed", "duplicate bundle");
                return 1;
            case ProjectLauncher.ERROR:
                test.addAttribute("failed", "unknown reason");
                return 1;
            case ProjectLauncher.RESOLVE_ERROR:
                test.addAttribute("failed", "resolve error");
                return 1;
            case ProjectLauncher.TIMEDOUT:
                test.addAttribute("failed", "timed out");
                return 1;
            case ProjectLauncher.WARNING:
                test.addAttribute("warning", "true");
                return 1;
            case ProjectLauncher.ACTIVATOR_ERROR:
                test.addAttribute("failed", "activator error");
                return 1;
            default:
                if (errors > 0) {
                    test.addAttribute("errors", errors);
                    return errors;
                }
                test.addAttribute("failed", "unknown reason");
                return errors;
        }
    } catch (Exception e) {
        test.addAttribute("failed", e);
        exception(e, "Exception in run %s", e);
        return 1;
    } finally {
        long duration = System.currentTimeMillis() - start;
        test.addAttribute("duration", (duration + 500) / 1000);
        getInfo(project, project.toString() + ": ");
    }
}
Also used : Project(aQute.bnd.build.Project) Tag(aQute.lib.tag.Tag) ProjectTester(aQute.bnd.build.ProjectTester) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ZipException(java.util.zip.ZipException)

Example 12 with Project

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

the class bnd method _release.

/**
	 * Release the project
	 * 
	 * @throws Exception
	 */
@Description("Release this project")
public void _release(releaseOptions options) throws Exception {
    Set<Project> projects = new LinkedHashSet<Project>();
    Workspace ws = Workspace.findWorkspace(getBase());
    if (ws == null) {
        error("Workspace option was specified but cannot find a workspace from %s", getBase());
        return;
    }
    if (options.workspace()) {
        projects.addAll(ws.getAllProjects());
    }
    Project project = getProject(options.project());
    if (project != null) {
        projects.add(project);
    }
    if (projects.isEmpty()) {
        error("Cannot find any projects");
        return;
    }
    String repo = options.repo();
    if (repo != null) {
        RepositoryPlugin repository = ws.getRepository(repo);
        if (repository == null) {
            error("No such release repo %s%nFound:%n%s", repository, Strings.join("\n", ws.getRepositories()));
        }
    }
    for (Project p : projects) {
        if (repo != null) {
            p.setProperty(Constants.RELEASEREPO, repo);
        }
        p.release(options.test());
    }
    getInfo(project);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Project(aQute.bnd.build.Project) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Workspace(aQute.bnd.build.Workspace) Description(aQute.lib.getopt.Description)

Example 13 with Project

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

the class bnd method _bsn2url.

public void _bsn2url(Bsn2UrlOptions opts) throws Exception {
    Project p = getProject(opts.project());
    if (p == null) {
        error("You need to be in a project or specify the project with -p/--project");
        return;
    }
    MultiMap<String, Version> revisions = new MultiMap<String, Version>();
    for (RepositoryPlugin repo : p.getPlugins(RepositoryPlugin.class)) {
        if (!(repo instanceof InfoRepository))
            continue;
        for (String bsn : repo.list(null)) {
            revisions.addAll(bsn, repo.versions(bsn));
        }
    }
    for (List<Version> versions : revisions.values()) {
        Collections.sort(versions, Collections.reverseOrder());
    }
    List<String> files = opts._arguments();
    for (String f : files) {
        try (BufferedReader r = IO.reader(getFile(f))) {
            String line;
            nextLine: while ((line = r.readLine()) != null) {
                Matcher matcher = LINE_P.matcher(line);
                if (!matcher.matches())
                    continue nextLine;
                line = matcher.group(1);
                Parameters bundles = new Parameters(line, this);
                for (Map.Entry<String, Attrs> entry : bundles.entrySet()) {
                    String bsn = entry.getKey();
                    VersionRange range = new VersionRange(entry.getValue().getVersion());
                    List<Version> versions = revisions.get(bsn);
                    if (versions == null) {
                        error("No for versions for %s", bsn);
                        break nextLine;
                    }
                    for (Version version : versions) {
                        if (range.includes(version)) {
                            for (RepositoryPlugin repo : p.getPlugins(RepositoryPlugin.class)) {
                                if (!(repo instanceof InfoRepository))
                                    continue;
                                InfoRepository rp = (InfoRepository) repo;
                                ResourceDescriptor descriptor = rp.getDescriptor(bsn, version);
                                if (descriptor == null) {
                                    error("Found bundle, but no descriptor %s;version=%s", bsn, version);
                                    return;
                                }
                                out.println(descriptor.url + " #" + descriptor.bsn + ";version=" + descriptor.version);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            error("failed to create url list from file %s : %s", f, e);
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Matcher(java.util.regex.Matcher) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) VersionRange(aQute.bnd.version.VersionRange) InfoRepository(aQute.bnd.service.repository.InfoRepository) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ZipException(java.util.zip.ZipException) Project(aQute.bnd.build.Project) MultiMap(aQute.lib.collections.MultiMap) Entry(java.util.Map.Entry) Version(aQute.bnd.version.Version) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) ExtList(aQute.lib.collections.ExtList) List(java.util.List) SortedList(aQute.lib.collections.SortedList) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 14 with Project

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

the class bnd method _deliverables.

@Description("Show all deliverables from this workspace. with their current version and path.")
public void _deliverables(deliverableOptions options) throws Exception {
    Project project = getProject(options.project());
    if (project == null) {
        messages.NoProject();
        return;
    }
    Collection<Project> projects;
    if (options.limit())
        projects = Arrays.asList(project);
    else
        projects = project.getWorkspace().getAllProjects();
    List<Container> containers = new ArrayList<Container>();
    for (Project p : projects) {
        containers.addAll(p.getDeliverables());
    }
    for (Container c : containers) {
        Version v = new Version(c.getVersion());
        err.printf("%-40s %8s  %s\n", c.getBundleSymbolicName(), v.getWithoutQualifier(), c.getFile());
    }
    getInfo(project);
}
Also used : Project(aQute.bnd.build.Project) Container(aQute.bnd.build.Container) Version(aQute.bnd.version.Version) ArrayList(java.util.ArrayList) Description(aQute.lib.getopt.Description)

Example 15 with Project

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

the class bnd method _bump.

/**
	 * Bump a version number
	 * 
	 * @throws Exception
	 */
@Description("Bumps the version of a project")
public void _bump(bumpoptions options) throws Exception {
    Project project = getProject(options.project());
    if (project == null) {
        messages.NoProject();
        return;
    }
    String mask = null;
    if (!options._arguments().isEmpty()) {
        mask = options._arguments().get(0);
        if (mask.equalsIgnoreCase("major"))
            mask = "+00";
        else if (mask.equalsIgnoreCase("minor"))
            mask = "=+0";
        else if (mask.equalsIgnoreCase("micro"))
            mask = "==+";
        else if (!mask.matches("[+=0]{1,3}")) {
            messages.InvalidBumpMask_(mask);
            return;
        }
    }
    if (mask == null)
        project.bump();
    else
        project.bump(mask);
    getInfo(project);
    err.println(project.getProperty(BUNDLE_VERSION, "No version found"));
}
Also used : Project(aQute.bnd.build.Project) Description(aQute.lib.getopt.Description)

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