Search in sources :

Example 46 with Description

use of aQute.lib.getopt.Description in project bnd by bndtools.

the class bnd method _wrap.

/**
	 * Wrap a jar to a bundle.
	 * 
	 * @throws Exception
	 */
@Description("Wrap a jar")
public void _wrap(wrapOptions options) throws Exception {
    List<File> classpath = Create.list();
    File properties = getBase();
    if (options.properties() != null) {
        properties = getFile(options.properties());
    }
    if (options.classpath() != null)
        for (String cp : options.classpath()) {
            classpath.add(getFile(cp));
        }
    for (String j : options._arguments()) {
        File file = getFile(j);
        if (!file.isFile()) {
            error("File does not exist %s", file);
            continue;
        }
        try (Analyzer wrapper = new Analyzer(this)) {
            wrapper.use(this);
            for (File f : classpath) wrapper.addClasspath(f);
            wrapper.setJar(file);
            File outputFile = wrapper.getOutputFile(options.output());
            if (outputFile.getCanonicalFile().equals(file.getCanonicalFile())) {
                // #267: CommandLine wrap deletes target even if file equals
                // source
                error("Output file %s and source file %s are the same file, they must be different", outputFile, file);
                return;
            }
            IO.delete(outputFile);
            String stem = file.getName();
            if (stem.endsWith(".jar"))
                stem = stem.substring(0, stem.length() - 4) + ".bnd";
            File p = getPropertiesFile(properties, file, stem);
            if (p == null) {
                wrapper.setImportPackage("*;resolution:=optional");
                wrapper.setExportPackage("*");
                warning("Using defaults for wrap, which means no export versions");
            } else if (p.isFile())
                wrapper.setProperties(p);
            else {
                error("No valid property file: %s", p);
            }
            if (options.bsn() != null)
                wrapper.setBundleSymbolicName(options.bsn());
            if (options.version() != null)
                wrapper.setBundleVersion(options.version());
            Manifest m = wrapper.calcManifest();
            if (wrapper.isOk()) {
                wrapper.getJar().setManifest(m);
                wrapper.save(outputFile, options.force());
            }
            getInfo(wrapper, file.toString());
        }
    }
}
Also used : Analyzer(aQute.bnd.osgi.Analyzer) Manifest(java.util.jar.Manifest) PomFromManifest(aQute.bnd.maven.PomFromManifest) File(java.io.File) Description(aQute.lib.getopt.Description)

Example 47 with Description

use of aQute.lib.getopt.Description in project bnd by bndtools.

the class bnd method _verify.

/**
	 * Verify jars.
	 * 
	 * @throws Exception
	 */
@Description("Verify jars")
public void _verify(verifyOptions opts) throws Exception {
    for (String path : opts._arguments()) {
        File f = getFile(path);
        if (!f.isFile()) {
            error("No such file: %s", f);
        } else {
            Jar jar = new Jar(f);
            if (jar.getManifest() == null || jar.getBsn() == null)
                error("Not a bundle %s", f);
            else {
                Verifier v = new Verifier(jar);
                getInfo(v, f.getName());
                v.close();
            }
            jar.close();
        }
    }
}
Also used : Jar(aQute.bnd.osgi.Jar) Verifier(aQute.bnd.osgi.Verifier) File(java.io.File) Description(aQute.lib.getopt.Description)

Example 48 with Description

use of aQute.lib.getopt.Description in project bnd by bndtools.

the class bnd method _add.

@Description("Add a workspace, or a project or a plugin to the workspace")
public void _add(AddOptions opts) throws Exception {
    List<String> args = opts._arguments();
    String what = args.remove(0);
    if ("project".equals(what)) {
        Workspace ws = Workspace.findWorkspace(getBase());
        if (ws == null) {
            error("No workspace found from %s", getBase());
            return;
        }
        for (String pname : args) {
            ws.createProject(pname);
        }
        getInfo(ws);
        return;
    }
    if ("workspace".equals(what)) {
        for (String pname : args) {
            File wsdir = getFile(pname);
            ws = Workspace.createWorkspace(wsdir);
            if (ws == null) {
                error("Could not create workspace");
            }
        }
        getInfo(ws);
        return;
    }
    if ("plugin".equals(what)) {
        Workspace ws = getWorkspace(getBase());
        if (ws == null) {
            error("No workspace found from %s", getBase());
            return;
        }
        CommandLine cl = new CommandLine(this);
        String help = cl.execute(new Plugins(this, ws), "add", new ExtList<String>(args));
        if (help != null)
            out.println(help);
        getInfo(ws);
        return;
    }
}
Also used : CommandLine(aQute.lib.getopt.CommandLine) File(java.io.File) Workspace(aQute.bnd.build.Workspace) Description(aQute.lib.getopt.Description)

Example 49 with Description

use of aQute.lib.getopt.Description in project bnd by bndtools.

the class bnd method _maven.

/**
	 * Maven command
	 * 
	 * @throws Exception
	 */
@Description("Maven bundle command")
public void _maven(Options options) throws Exception {
    MavenCommand mc = new MavenCommand(this);
    mc.use(this);
    mc.run(options._arguments().toArray(new String[0]), 1);
    getInfo(mc);
}
Also used : MavenCommand(aQute.bnd.maven.MavenCommand) Description(aQute.lib.getopt.Description)

Example 50 with Description

use of aQute.lib.getopt.Description in project bnd by bndtools.

the class bnd method _clean.

@Description("Clean a project")
public void _clean(cleanOptions opts) throws Exception {
    Project project = getProject(opts.project());
    if (project == null) {
        messages.NoProject();
        return;
    }
    project.clean();
    getInfo(project);
}
Also used : Project(aQute.bnd.build.Project) Description(aQute.lib.getopt.Description)

Aggregations

Description (aQute.lib.getopt.Description)63 File (java.io.File)31 Jar (aQute.bnd.osgi.Jar)14 Project (aQute.bnd.build.Project)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 Instructions (aQute.bnd.osgi.Instructions)10 CommandLine (aQute.lib.getopt.CommandLine)10 Justif (aQute.lib.justif.Justif)8 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 Workspace (aQute.bnd.build.Workspace)7 PomFromManifest (aQute.bnd.maven.PomFromManifest)7 Service (aQute.jpm.lib.Service)7 Manifest (java.util.jar.Manifest)7 FileResource (aQute.bnd.osgi.FileResource)6 Resource (aQute.bnd.osgi.Resource)6 Analyzer (aQute.bnd.osgi.Analyzer)5 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)5 CommandData (aQute.jpm.lib.CommandData)5 ServiceData (aQute.jpm.lib.ServiceData)5