Search in sources :

Example 16 with Project

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

the class bnd method _export.

public void _export(ExportOptions opts) throws Exception {
    Project project = getProject(opts.project());
    if (project == null) {
        error("No project");
        return;
    }
    // temporary
    project.getWorkspace().addBasicPlugin(new SubsystemExporter());
    List<Exporter> exporters = project.getPlugins(Exporter.class);
    Exporter exporter = null;
    for (Exporter e : exporters) {
        String[] types = e.getTypes();
        for (String type : types) {
            if (type.equals(opts.exporter()))
                ;
        }
    }
    for (String bndrun : opts._arguments()) {
        File f = getFile(bndrun);
        if (!f.isFile()) {
            error("No such file: %s", f);
            continue;
        }
        Run run = new Run(project.getWorkspace(), getBase(), f);
        run.getSettings(this);
        Parameters exports = new Parameters();
        List<String> types = opts.exporter();
        if (types != null) {
            for (String type : types) {
                exports.putAll(new Parameters(type, this));
            }
        } else {
            String exportTypes = run.getProperty(Constants.EXPORTTYPE);
            exports.putAll(new Parameters(exportTypes, this));
        }
        for (Entry<String, Attrs> e : exports.entrySet()) {
            logger.debug("exporting {} to {} with {}", run, e.getKey(), e.getValue());
            Map.Entry<String, Resource> result = run.export(e.getKey(), e.getValue());
            getInfo(run);
            if (result != null && isOk()) {
                String name = result.getKey();
                File output = new File(project.getTarget(), opts.output() == null ? name : opts.output());
                if (output.isDirectory())
                    output = new File(output, name);
                IO.mkdirs(output.getParentFile());
                logger.debug("Got a result for {}, store in {}", e.getKey(), output);
                IO.copy(result.getValue().openInputStream(), output);
            }
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) FileResource(aQute.bnd.osgi.FileResource) Resource(aQute.bnd.osgi.Resource) Run(aQute.bnd.build.Run) Exporter(aQute.bnd.service.export.Exporter) Project(aQute.bnd.build.Project) File(java.io.File) MultiMap(aQute.lib.collections.MultiMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 17 with Project

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

the class bnd method __par.

/**
	 * Lets see if we can build in parallel
	 * 
	 * @throws Exception
	 */
public void __par(final ParallelBuildOptions options) throws Exception {
    ExecutorService pool = Executors.newCachedThreadPool();
    final AtomicBoolean quit = new AtomicBoolean();
    try {
        final Project p = getProject(options.project());
        final Workspace workspace = p == null || options.full() ? Workspace.getWorkspace(getBase()) : p.getWorkspace();
        if (!workspace.exists()) {
            error("cannot find workspace");
            return;
        }
        final Collection<Project> targets = p == null ? workspace.getAllProjects() : p.getDependson();
        final Forker<Project> forker = new Forker<Project>(pool);
        for (final Project dep : targets) {
            forker.doWhen(dep.getDependson(), dep, new Runnable() {

                public void run() {
                    if (!quit.get()) {
                        try {
                            dep.compile(false);
                            if (!quit.get())
                                dep.build();
                            if (!dep.isOk())
                                quit.set(true);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            });
        }
        System.err.flush();
        forker.start(20000);
        for (Project dep : targets) {
            getInfo(dep, dep + ": ");
        }
        if (p != null && p.isOk() && !options.full()) {
            p.compile(options.test());
            p.build();
            if (options.test() && p.isOk())
                p.test();
            getInfo(p);
        }
        workspace.close();
    } finally {
        pool.shutdownNow();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Project(aQute.bnd.build.Project) ExecutorService(java.util.concurrent.ExecutorService) Forker(aQute.libg.forker.Forker) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ZipException(java.util.zip.ZipException) Workspace(aQute.bnd.build.Workspace)

Example 18 with Project

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

the class bnd method _info.

@Description("Show key project variables")
public void _info(infoOptions options) throws Exception {
    Project p = getProject(options.project());
    if (p == null) {
        messages.NoProject();
        return;
    }
    boolean any = options.runbundles() || options.buildpath() || options.classpath() || options.dependsOn() || options.vmpath();
    MultiMap<String, Object> table = new MultiMap<String, Object>();
    if (any || options.runbundles()) {
        table.addAll("Run", p.getRunbundles());
    }
    if (any || options.buildpath()) {
        table.addAll("Build", p.getBuildpath());
    }
    if (any || options.buildpath()) {
        table.addAll("Depends on", p.getDependson());
    }
    if (any || options.sourcepath()) {
        table.addAll("Source", p.getSourcePath());
    }
    if (any || options.classpath()) {
        table.addAll("Class path", p.getClasspath());
    }
    if (any || options.vmpath()) {
        table.addAll("Run path", p.getRunpath());
    }
    printMultiMap(table);
}
Also used : Project(aQute.bnd.build.Project) MultiMap(aQute.lib.collections.MultiMap) Description(aQute.lib.getopt.Description)

Example 19 with Project

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

the class bnd method _find.

public void _find(FindOptions options) throws Exception {
    List<File> files = new ArrayList<File>();
    List<String> args = options._arguments();
    if (args.size() == 0) {
        Project p = getProject();
        if (p == null) {
            error("This is not a project directory and you have specified no jar files ...");
            return;
        }
        File output = p.getOutput();
        if (output.exists()) {
            files.add(output);
        }
        for (Container c : p.getBuildpath()) {
            files.add(c.getFile());
        }
    } else {
        for (String f : args) {
            File file = getFile(f);
            files.add(file);
        }
    }
    for (File f : files) {
        logger.debug("find {}", f);
        try (Jar jar = new Jar(f)) {
            Manifest m = jar.getManifest();
            if (m != null) {
                Domain domain = Domain.domain(m);
                if (options.exports() != null) {
                    Parameters ep = domain.getExportPackage();
                    for (Glob g : options.exports()) {
                        for (Entry<String, Attrs> exp : ep.entrySet()) {
                            if (g.matcher(exp.getKey()).matches()) {
                                String v = exp.getValue().get(VERSION_ATTRIBUTE);
                                if (v == null)
                                    v = "0";
                                out.printf(">%s: %s-%s%n", f.getPath(), exp.getKey(), v);
                            }
                        }
                    }
                }
                if (options.imports() != null) {
                    Parameters ip = domain.getImportPackage();
                    for (Glob g : options.imports()) {
                        for (Entry<String, Attrs> imp : ip.entrySet()) {
                            if (g.matcher(imp.getKey()).matches()) {
                                String v = imp.getValue().get(VERSION_ATTRIBUTE);
                                if (v == null)
                                    v = "0";
                                out.printf("<%s: %s-%s%n", f.getPath(), imp.getKey(), v);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) ArrayList(java.util.ArrayList) Attrs(aQute.bnd.header.Attrs) Manifest(java.util.jar.Manifest) PomFromManifest(aQute.bnd.maven.PomFromManifest) Project(aQute.bnd.build.Project) Container(aQute.bnd.build.Container) Glob(aQute.libg.glob.Glob) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Example 20 with Project

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

the class bnd method doRun.

private void doRun(List<String> args, boolean verify, String project) throws Exception {
    Project run = null;
    if (args.isEmpty()) {
        run = getProject(project);
        if (run == null) {
            messages.NoProject();
            return;
        }
    } else {
        File f = getFile(args.get(0));
        File dir = f.getParentFile();
        File wsdir = dir.getParentFile();
        if (wsdir == null) {
            // We are in the filesystem root?? Create a standalone run.
            run = Run.createRun(null, f);
        } else {
            Workspace workspace = Workspace.getWorkspaceWithoutException(wsdir);
            run = Run.createRun(workspace, f);
        }
    }
    verifyDependencies(run, verify, false);
    try {
        run.run();
    } catch (Exception e) {
        messages.Failed__(e, "Running " + run);
    }
    getInfo(run);
    getInfo(run.getWorkspace());
}
Also used : Project(aQute.bnd.build.Project) 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) Workspace(aQute.bnd.build.Workspace)

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