Search in sources :

Example 1 with Reporter

use of aQute.service.reporter.Reporter in project bnd by bndtools.

the class bnd method _bash.

@Description("Generate autocompletion file for bash")
public void _bash(Options options) throws Exception {
    File tmp = File.createTempFile("bnd-completion", ".tmp");
    tmp.deleteOnExit();
    try {
        IO.copy(getClass().getResource("bnd-completion.bash"), tmp);
        Sed sed = new Sed(tmp);
        sed.setBackup(false);
        Reporter r = new ReporterAdapter();
        CommandLine c = new CommandLine(r);
        Map<String, Method> commands = c.getCommands(this);
        StringBuilder sb = new StringBuilder();
        for (String commandName : commands.keySet()) {
            sb.append(" " + commandName);
        }
        sb.append(" help");
        sed.replace("%listCommands%", sb.toString().substring(1));
        sed.doIt();
        IO.copy(tmp, out);
    } finally {
        IO.delete(tmp);
    }
}
Also used : CommandLine(aQute.lib.getopt.CommandLine) Sed(aQute.libg.sed.Sed) ReporterAdapter(aQute.libg.reporter.ReporterAdapter) Reporter(aQute.service.reporter.Reporter) Method(java.lang.reflect.Method) File(java.io.File) Description(aQute.lib.getopt.Description)

Example 2 with Reporter

use of aQute.service.reporter.Reporter in project bnd by bndtools.

the class BaselineMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        logger.debug("skip project as configured");
        return;
    }
    Artifact artifact = RepositoryUtils.toArtifact(project.getArtifact());
    List<RemoteRepository> aetherRepos = getRepositories(artifact);
    setupBase(artifact);
    try {
        if (base.getVersion() == null || base.getVersion().isEmpty()) {
            searchForBaseVersion(artifact, aetherRepos);
        }
        if (base.getVersion() != null && !base.getVersion().isEmpty()) {
            ArtifactResult artifactResult = locateBaseJar(aetherRepos);
            Reporter reporter;
            if (fullReport) {
                reporter = new ReporterAdapter(System.out);
                ((ReporterAdapter) reporter).setTrace(true);
            } else {
                reporter = new ReporterAdapter();
            }
            Baseline baseline = new Baseline(reporter, new DiffPluginImpl());
            if (checkFailures(artifact, artifactResult, baseline)) {
                if (continueOnError) {
                    logger.warn("The baselining check failed when checking {} against {} but the bnd-baseline-maven-plugin is configured not to fail the build.", artifact, artifactResult.getArtifact());
                } else {
                    throw new MojoExecutionException("The baselining plugin detected versioning errors");
                }
            } else {
                logger.info("Baselining check succeeded checking {} against {}", artifact, artifactResult.getArtifact());
            }
        } else {
            if (failOnMissing) {
                throw new MojoExecutionException("Unable to locate a previous version of the artifact");
            } else {
                logger.warn("No previous version of {} could be found to baseline against", artifact);
            }
        }
    } catch (RepositoryException re) {
        throw new MojoExecutionException("Unable to locate a previous version of the artifact", re);
    } catch (Exception e) {
        throw new MojoExecutionException("An error occurred while calculating the baseline", e);
    }
}
Also used : DiffPluginImpl(aQute.bnd.differ.DiffPluginImpl) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ReporterAdapter(aQute.libg.reporter.ReporterAdapter) Reporter(aQute.service.reporter.Reporter) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) RepositoryException(org.eclipse.aether.RepositoryException) Baseline(aQute.bnd.differ.Baseline) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) RepositoryException(org.eclipse.aether.RepositoryException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 3 with Reporter

use of aQute.service.reporter.Reporter in project bnd by bndtools.

the class OBRFragment method parse.

public static Reporter parse(File file, ResourceBuilder resource, String base) throws Exception {
    try (Jar jar = new Jar(file)) {
        Reporter reporter = parse(jar, resource);
        if (!reporter.isOk())
            return reporter;
        CapReqBuilder content = new CapReqBuilder(ContentNamespace.CONTENT_NAMESPACE);
        String sha = SHA1.digest(file).asHex();
        content.addAttribute(ContentNamespace.CONTENT_NAMESPACE, sha);
        content.addAttribute(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE, file.length());
        content.addAttribute(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE, MIME_TYPE_OSGI_BUNDLE);
        if (base != null) {
            String path = file.getAbsolutePath();
            if (base.startsWith(path)) {
                content.addAttribute(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, path.substring(base.length()).replace(File.separatorChar, '/'));
            } else {
                reporter.error("Base path %s is not parent of file path: %s", base, file.getAbsolutePath());
            }
        }
        resource.addCapability(content);
        return reporter;
    }
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Reporter(aQute.service.reporter.Reporter) Jar(aQute.bnd.osgi.Jar)

Example 4 with Reporter

use of aQute.service.reporter.Reporter in project bnd by bndtools.

the class Platform method parseCompletion.

public void parseCompletion(Object target, File f) throws Exception {
    IO.copy(getClass().getResource("unix/jpm-completion.bash"), f);
    Sed sed = new Sed(f);
    sed.setBackup(false);
    Reporter r = new ReporterAdapter();
    CommandLine c = new CommandLine(r);
    Map<String, Method> commands = c.getCommands(target);
    StringBuilder sb = new StringBuilder();
    for (String commandName : commands.keySet()) {
        sb.append(" " + commandName);
    }
    sb.append(" help");
    sed.replace("%listJpmCommands%", sb.toString().substring(1));
    sed.doIt();
}
Also used : CommandLine(aQute.lib.getopt.CommandLine) Sed(aQute.libg.sed.Sed) ReporterAdapter(aQute.libg.reporter.ReporterAdapter) Reporter(aQute.service.reporter.Reporter) Method(java.lang.reflect.Method)

Example 5 with Reporter

use of aQute.service.reporter.Reporter in project bnd by bndtools.

the class HttpRedirectionTest method testFollowRedirect.

public void testFollowRedirect() throws Exception {
    Reporter reporter = mock(Reporter.class);
    NanoHTTPD httpd = new NanoHTTPD(0, new File(".")) {

        @Override
        public Response serve(String uri, String method, Properties header, Properties parms, Properties files) {
            Response r;
            if ("/foo".equals(uri)) {
                r = new Response("302 Found", "text/plain", "over there");
                r.header.put("Location", "/bar");
            } else if ("/bar".equals(uri)) {
                r = new Response(NanoHTTPD.HTTP_OK, "text/plain", "got it");
            } else {
                r = new Response(NanoHTTPD.HTTP_BADREQUEST, "text/plain", "sod off");
            }
            return r;
        }
    };
    String baseUrl = "http://localhost:" + httpd.getPort() + "/";
    String originalUrl = baseUrl + "foo";
    String redirectUrl = baseUrl + "bar";
    DefaultURLConnector connector = new DefaultURLConnector();
    connector.setReporter(reporter);
    InputStream stream = connector.connect(new URL(originalUrl));
    String result = IO.collect(stream);
    assertEquals("got it", result);
    verify(reporter).warning("HTTP address redirected from %s to %s", originalUrl, redirectUrl);
}
Also used : InputStream(java.io.InputStream) Reporter(aQute.service.reporter.Reporter) NanoHTTPD(test.lib.NanoHTTPD) Properties(java.util.Properties) File(java.io.File) URL(java.net.URL)

Aggregations

Reporter (aQute.service.reporter.Reporter)8 ReporterAdapter (aQute.libg.reporter.ReporterAdapter)3 Baseline (aQute.bnd.differ.Baseline)2 DiffPluginImpl (aQute.bnd.differ.DiffPluginImpl)2 Jar (aQute.bnd.osgi.Jar)2 Processor (aQute.bnd.osgi.Processor)2 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)2 CommandLine (aQute.lib.getopt.CommandLine)2 PromiseCollectors.toPromise (aQute.lib.promise.PromiseCollectors.toPromise)2 Sed (aQute.libg.sed.Sed)2 File (java.io.File)2 Method (java.lang.reflect.Method)2 Collections (java.util.Collections)2 List (java.util.List)2 Objects (java.util.Objects)2 ExecutorService (java.util.concurrent.ExecutorService)2 Executors (java.util.concurrent.Executors)2 Template (org.bndtools.templating.Template)2 TemplateLoader (org.bndtools.templating.TemplateLoader)2 Constants (org.osgi.framework.Constants)2