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);
}
}
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);
}
}
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;
}
}
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();
}
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);
}
Aggregations