Search in sources :

Example 56 with Workspace

use of aQute.bnd.build.Workspace 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 57 with Workspace

use of aQute.bnd.build.Workspace 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)

Example 58 with Workspace

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

the class bnd method main.

public static void main(String[] args) throws Exception {
    Workspace.setDriver(Constants.BNDDRIVER_BND);
    Workspace.addGestalt(Constants.GESTALT_SHELL, null);
    Workspace.addGestalt(Constants.GESTALT_INTERACTIVE, null);
    Workspace ws = Workspace.findWorkspace(IO.work);
    try (bnd main = new bnd()) {
        // ws == null ? new bnd() : new bnd(ws);
        main.start(args);
    }
    exitWithCode(0);
}
Also used : Workspace(aQute.bnd.build.Workspace)

Example 59 with Workspace

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

the class BndEditor method loadEditModel.

private void loadEditModel() throws Exception {
    // Create the bnd edit model and workspace
    Workspace ws = Central.getWorkspaceIfPresent();
    Project bndProject = Run.createRun(ws, inputFile);
    model.setWorkspace(bndProject.getWorkspace());
    model.setProject(bndProject);
    // Load content into the edit model
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            final IDocumentProvider docProvider = sourcePage.getDocumentProvider();
            // #1625: Ensure the IDocumentProvider is not null.
            if (docProvider != null) {
                IDocument document = docProvider.getDocument(getEditorInput());
                try {
                    model.loadFrom(new IDocumentWrapper(document));
                    model.setBndResource(inputFile);
                } catch (IOException e) {
                    logger.logError("Unable to load edit model", e);
                }
                for (int i = 0; i < getPageCount(); i++) {
                    Control control = getControl(i);
                    if (control instanceof ScrolledForm) {
                        ScrolledForm form = (ScrolledForm) control;
                        if (SYNC_MESSAGE.equals(form.getMessage())) {
                            form.setMessage(null, IMessageProvider.NONE);
                        }
                    }
                }
            }
        }
    });
}
Also used : Project(aQute.bnd.build.Project) Control(org.eclipse.swt.widgets.Control) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) IOException(java.io.IOException) IDocumentWrapper(bndtools.editor.model.IDocumentWrapper) IDocument(org.eclipse.jface.text.IDocument) Workspace(aQute.bnd.build.Workspace)

Example 60 with Workspace

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

the class BndEditorPart method refresh.

@Override
public final void refresh() {
    if (!Central.hasWorkspaceDirectory()) {
        refreshFromModel();
    } else {
        Central.onWorkspaceInit(new Success<Workspace, Void>() {

            @Override
            public Promise<Void> call(Promise<Workspace> resolved) throws Exception {
                try {
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            refreshFromModel();
                            ScrolledForm form = getManagedForm().getForm();
                            if (BndEditor.SYNC_MESSAGE.equals(form.getMessage())) {
                                form.setMessage(null, IMessageProvider.NONE);
                            }
                        }
                    });
                } catch (Exception e) {
                }
                return Promises.resolved(null);
            }
        });
    }
    super.refresh();
}
Also used : Promise(org.osgi.util.promise.Promise) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) Workspace(aQute.bnd.build.Workspace)

Aggregations

Workspace (aQute.bnd.build.Workspace)164 Project (aQute.bnd.build.Project)69 File (java.io.File)62 Processor (aQute.bnd.osgi.Processor)26 IOException (java.io.IOException)20 HashMap (java.util.HashMap)20 Container (aQute.bnd.build.Container)15 ArrayList (java.util.ArrayList)15 Version (aQute.bnd.version.Version)13 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)12 IProject (org.eclipse.core.resources.IProject)10 Run (aQute.bnd.build.Run)9 CoreException (org.eclipse.core.runtime.CoreException)9 Description (aQute.lib.getopt.Description)7 Collection (java.util.Collection)6 BndEditModel (aQute.bnd.build.model.BndEditModel)5 Jar (aQute.bnd.osgi.Jar)5 HttpTestServer (aQute.http.testservers.HttpTestServer)5 BuildException (org.apache.tools.ant.BuildException)5 IResource (org.eclipse.core.resources.IResource)5