Search in sources :

Example 16 with Description

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

the class bnd method _runtests.

/**
	 * Run the tests from a prepared bnd file.
	 * 
	 * @throws Exception
	 */
@Description("Run OSGi tests and create report")
public void _runtests(runtestsOptions opts) throws Exception {
    int errors = 0;
    File cwd = new File("").getAbsoluteFile();
    Workspace ws = new Workspace(cwd);
    try {
        File reportDir = getFile("reports");
        IO.delete(reportDir);
        Tag summary = new Tag("summary");
        summary.addAttribute("date", new Date());
        summary.addAttribute("ws", ws.getBase());
        if (opts.reportdir() != null) {
            reportDir = getFile(opts.reportdir());
        }
        IO.mkdirs(reportDir);
        if (!reportDir.isDirectory())
            error("reportdir must be a directory %s (tried to create it ...)", reportDir);
        if (opts.title() != null)
            summary.addAttribute("title", opts.title());
        if (opts.dir() != null)
            cwd = getFile(opts.dir());
        if (opts.workspace() != null) {
            ws.close();
            ws = Workspace.getWorkspace(getFile(opts.workspace()));
        }
        // TODO check all the arguments
        boolean hadOne = false;
        try {
            for (String arg : opts._arguments()) {
                logger.debug("will run test {}", arg);
                File f = getFile(arg);
                errors += runtTest(f, ws, reportDir, summary);
                hadOne = true;
            }
            if (!hadOne) {
                // See if we had any, if so, just use all files in
                // the current directory
                File[] files = cwd.listFiles();
                for (File f : files) {
                    if (f.getName().endsWith(".bnd")) {
                        errors += runtTest(f, ws, reportDir, summary);
                    }
                }
            }
        } catch (Throwable e) {
            if (isExceptions()) {
                printExceptionSummary(e, out);
            }
            exception(e, "FAILURE IN RUNTESTS");
            errors++;
        }
        if (errors > 0)
            summary.addAttribute("errors", errors);
        for (String error : getErrors()) {
            Tag e = new Tag("error");
            e.addContent(error);
        }
        for (String warning : getWarnings()) {
            Tag e = new Tag("warning");
            e.addContent(warning);
        }
        File r = getFile(reportDir, "summary.xml");
        try (PrintWriter pw = IO.writer(r, UTF_8)) {
            summary.print(0, pw);
        }
        if (errors != 0)
            error("Errors found %s", errors);
    } finally {
        ws.close();
    }
}
Also used : Tag(aQute.lib.tag.Tag) File(java.io.File) Date(java.util.Date) Workspace(aQute.bnd.build.Workspace) PrintWriter(java.io.PrintWriter) Description(aQute.lib.getopt.Description)

Example 17 with Description

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

the class bnd method _buildx.

@Description("Build project, is deprecated but here for backward compatibility")
public void _buildx(buildxOptions options) throws Exception {
    // Create a build order
    List<Builder> builders = new ArrayList<Builder>();
    List<String> order = new ArrayList<String>();
    List<String> active = new ArrayList<String>();
    for (String s : options._arguments()) {
        prebuild(active, order, builders, s);
    }
    for (Builder b : builders) {
        if (options.classpath() != null) {
            for (String f : options.classpath()) {
                b.addClasspath(getFile(f));
            }
        }
        if (options.sourcepath() != null) {
            for (String f : options.sourcepath()) {
                b.addSourcepath(getFile(f));
            }
        }
        if (options.sources())
            b.setSources(true);
        if (options.eclipse()) {
            EclipseClasspath ep = new EclipseClasspath(this, getBase().getParentFile(), getBase());
            b.addClasspath(ep.getClasspath());
            b.addClasspath(ep.getBootclasspath());
            b.addSourcepath(ep.getSourcepath());
        }
        Jar jar = b.build();
        File outputFile = b.getOutputFile(options.output());
        if (options.pom()) {
            Resource r = new PomFromManifest(jar.getManifest());
            jar.putResource("pom.xml", r);
            String path = outputFile.getName().replaceAll("\\.jar$", ".pom");
            if (path.equals(outputFile.getName()))
                path = outputFile.getName() + ".pom";
            File pom = new File(outputFile.getParentFile(), path);
            try (OutputStream os = IO.outputStream(pom)) {
                r.write(os);
            }
        }
        getInfo(b, b.getPropertiesFile().getName());
        if (isOk()) {
            b.save(outputFile, options.force());
        }
        b.close();
    }
}
Also used : EclipseClasspath(aQute.bnd.osgi.eclipse.EclipseClasspath) Builder(aQute.bnd.osgi.Builder) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) FileResource(aQute.bnd.osgi.FileResource) Resource(aQute.bnd.osgi.Resource) PomFromManifest(aQute.bnd.maven.PomFromManifest) Jar(aQute.bnd.osgi.Jar) File(java.io.File) Description(aQute.lib.getopt.Description)

Example 18 with Description

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

the class AbstractConsoleApp method __main.

/**
	 * Initialize the repository and other global vars.
	 * 
	 * @param opts the options
	 * @throws IOException
	 */
@Description("")
public void __main(MainOptions opts) throws IOException {
    try {
        setExceptions(opts.exceptions());
        setTrace(opts.trace());
        setPedantic(opts.pedantic());
        if (opts.base() != null)
            setBase(IO.getFile(getBase(), opts.base()));
        else
            setBase(IO.work);
        if (opts.width() > 0)
            this.width = opts.width();
        CommandLine handler = opts._command();
        List<String> arguments = opts._arguments();
        if (arguments.isEmpty()) {
            Justif j = new Justif();
            Formatter f = j.formatter();
            handler.help(f, this);
            err.println(j.wrap());
        } else {
            String cmd = arguments.remove(0);
            String help = handler.execute(this, cmd, arguments);
            if (help != null) {
                err.println(help);
            }
        }
    } catch (InvocationTargetException t) {
        Throwable tt = t;
        while (tt instanceof InvocationTargetException) tt = ((InvocationTargetException) tt).getTargetException();
        exception(tt, "%s", tt);
    } catch (Throwable t) {
        exception(t, "Failed %s", t);
    } finally {
        // Check if we need to wait for it to finish
        if (opts.key()) {
            System.out.println("Hit a key to continue ...");
            System.in.read();
        }
    }
    if (!check(opts.failok())) {
        System.exit(getErrors().size());
    }
}
Also used : CommandLine(aQute.lib.getopt.CommandLine) Justif(aQute.lib.justif.Justif) Formatter(java.util.Formatter) InvocationTargetException(java.lang.reflect.InvocationTargetException) Description(aQute.lib.getopt.Description)

Example 19 with Description

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

the class ResolveCommand method _resolve.

@Description("Resolve a bndrun file")
public void _resolve(ResolveOptions options) throws Exception {
    Project project = bnd.getProject(options.project());
    Workspace ws = null;
    if (options.workspace() != null) {
        File file = bnd.getFile(options.workspace());
        if (file.isDirectory()) {
            ws = Workspace.getWorkspace(file);
            if (!ws.isValid()) {
                error("Invalid workspace %s", file);
                return;
            }
        } else {
            error("Workspace directory %s is not a directory", file);
            return;
        }
    } else {
        if (project != null)
            ws = project.getWorkspace();
    }
    List<String> paths = options._arguments();
    for (String path : paths) {
        File f = getFile(path);
        if (!f.isFile()) {
            error("Missing bndrun file: %s", f);
        } else {
            try (Bndrun bndrun = Bndrun.createBndrun(ws, f)) {
                try {
                    String runbundles = bndrun.resolve(false, options.write(), runbundlesFormatter);
                    if (bndrun.isOk()) {
                        System.out.printf("# %-50s ok%n", f.getName());
                        if (options.bundles()) {
                            System.out.println(runbundles);
                        }
                    }
                } catch (Exception e) {
                    System.out.printf("%-50s %s\n", f.getName(), e);
                    exception(e, "Failed to resolve %s: %s", f, e);
                }
                getInfo(bndrun);
            }
        }
    }
}
Also used : Project(aQute.bnd.build.Project) File(java.io.File) Bndrun(biz.aQute.resolve.Bndrun) Workspace(aQute.bnd.build.Workspace) Description(aQute.lib.getopt.Description)

Example 20 with Description

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

the class Main method _status.

/**
	 * Status a service.
	 * 
	 * @param options
	 * @throws InterruptedException
	 */
@Description("Status of a service/services")
public void _status(statusOptions options) throws InterruptedException {
    while (true) {
        for (String s : options._arguments()) {
            String runs = "false";
            String status = "no service";
            try {
                Service service = jpm.getService(s);
                if (service != null) {
                    runs = service.isRunning() + "";
                    status = service.status();
                }
            } catch (Exception e) {
                status = e.toString();
                exception(e, "could not fetch status information from service %s, due to %s", s, status);
            }
            out.printf("%-40s %8s %s\r", s, runs, status);
        }
        if (!options.continuous()) {
            out.println();
            return;
        }
        Thread.sleep(1000);
    }
}
Also used : Service(aQute.jpm.lib.Service) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) 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