use of aQute.bnd.osgi.JarResource in project bnd by bndtools.
the class TestLocalIndexGeneration method testOverwrite.
public void testOverwrite() throws Exception {
config.put("overwrite", "false");
repo.setProperties(config);
PutResult r = repo.put(new BufferedInputStream(new FileInputStream("testdata/bundles/name.njbartlett.osgi.emf.minimal-2.6.1.jar")), new RepositoryPlugin.PutOptions());
File originalFile = new File(r.artifact);
assertEquals(IO.getFile(outputDir, "name.njbartlett.osgi.emf.minimal/name.njbartlett.osgi.emf.minimal-2.6.1.jar").getAbsolutePath(), originalFile.getAbsolutePath());
Jar newJar = new Jar(IO.getFile("testdata/bundles/name.njbartlett.osgi.emf.minimal-2.6.1.jar"));
Jar dummyJar = new Jar(IO.getFile("testdata/bundles/dummybundle.jar"));
newJar.putResource("testOverwrite/dummybundle.jar", new JarResource(dummyJar));
newJar.write("testdata/bundles/name.njbartlett.osgi.emf.minimal-2.6.1-testOverwrite.jar");
r = repo.put(new BufferedInputStream(new FileInputStream("testdata/bundles/name.njbartlett.osgi.emf.minimal-2.6.1-testOverwrite.jar")), new RepositoryPlugin.PutOptions());
IO.delete(IO.getFile("testdata/bundles/name.njbartlett.osgi.emf.minimal-2.6.1-testOverwrite.jar"));
assertNull(r.artifact);
}
use of aQute.bnd.osgi.JarResource in project bnd by bndtools.
the class MakeTest method testJarInJarInJar.
/**
* Check if we can create a JAR recursively
*
* @throws Exception
*/
public static void testJarInJarInJar() throws Exception {
Builder bmaker = new Builder();
Properties p = new Properties();
p.setProperty("-plugin", "aQute.bnd.make.MakeBnd, aQute.bnd.make.MakeCopy");
p.setProperty("-resourceonly", "true");
p.setProperty("-make", "(*).jar;type=bnd;recipe=bnd/$1.bnd");
p.setProperty("Include-Resource", "makesondemand.jar");
bmaker.setProperties(p);
bmaker.setClasspath(new String[] { "bin" });
Jar jar = bmaker.build();
JarResource resource = (JarResource) jar.getResource("makesondemand.jar");
assertNotNull(resource);
jar = resource.getJar();
resource = (JarResource) jar.getResource("ondemand.jar");
assertNotNull(resource);
report(bmaker);
}
use of aQute.bnd.osgi.JarResource in project bndtools by bndtools.
the class ReleaseHelper method release.
private static boolean release(ReleaseContext context, List<IReleaseParticipant> participants, Builder builder) throws Exception {
Jar jar = null;
try {
if (context.getReleaseOption() == ReleaseOption.UPDATE_RELEASE) {
jar = builder.build();
} else {
// No need to rebuild if release only
File jarFile = new File(context.getProject().getTarget(), builder.getBsn() + ".jar");
if (jarFile.isFile()) {
jar = new Jar(jarFile);
} else {
jar = builder.build();
}
}
handleBuildErrors(context, builder, jar);
String symbName = ReleaseUtils.getBundleSymbolicName(jar);
String version = ReleaseUtils.getBundleVersion(jar);
boolean proceed = preJarRelease(context, participants, jar);
if (!proceed) {
postRelease(context, participants, false);
displayErrors(context);
return false;
}
try (JarResource jr = new JarResource(jar);
InputStream is = new BufferedInputStream(jr.openInputStream())) {
context.getProject().release(context.getReleaseRepository().getName(), jar.getName(), is);
if (!context.getProject().isOk()) {
handleBuildErrors(context, context.getProject(), jar);
displayErrors(context);
context.getProject().clear();
return false;
}
}
File file = context.getReleaseRepository().get(symbName, Version.parseVersion(version), null);
Jar releasedJar = null;
if (file != null && file.exists()) {
IResource resource = ReleaseUtils.toResource(file);
if (resource != null) {
resource.refreshLocal(IResource.DEPTH_ZERO, null);
}
releasedJar = jar;
jar = null;
}
if (releasedJar == null) {
handleReleaseErrors(context, context.getProject(), symbName, version);
postRelease(context, participants, false);
displayErrors(context);
return false;
}
context.addReleasedJar(releasedJar);
postJarRelease(context, participants, releasedJar);
return true;
} finally {
if (jar != null) {
jar.close();
}
}
}
use of aQute.bnd.osgi.JarResource in project bnd by bndtools.
the class MavenDeploy method deploy.
/**
*/
public boolean deploy(Project project, String jarName, InputStream jarStream) throws Exception {
Parameters deploy = project.parseHeader(project.getProperty(Constants.DEPLOY));
Map<String, String> maven = deploy.get(repository);
if (maven == null)
// we're not playing for this bundle
return false;
logger.info(LIFECYCLE, "deploying {} to Maven repo: {}", jarName, repository);
File target = project.getTarget();
File tmp = Processor.getFile(target, repository);
IO.mkdirs(tmp);
try (Jar original = new Jar(jarName, jarStream)) {
Manifest manifest = original.getManifest();
if (manifest == null)
project.error("Jar has no manifest: %s", original);
else {
logger.info(LIFECYCLE, "Writing pom.xml");
PomResource pom = new PomResource(manifest);
pom.setProperties(maven);
File pomFile = write(tmp, pom, "pom.xml");
try (Jar main = new Jar("main");
Jar src = new Jar("src")) {
split(original, main, src);
Parameters exports = project.parseHeader(manifest.getMainAttributes().getValue(Constants.EXPORT_PACKAGE));
File jdoc = new File(tmp, "jdoc");
IO.mkdirs(jdoc);
logger.info(LIFECYCLE, "Generating Javadoc for: {}", exports.keySet());
Jar javadoc = javadoc(jdoc, project, exports.keySet());
logger.info(LIFECYCLE, "Writing javadoc jar");
File javadocFile = write(tmp, new JarResource(javadoc), "javadoc.jar");
logger.info(LIFECYCLE, "Writing main file");
File mainFile = write(tmp, new JarResource(main), "main.jar");
logger.info(LIFECYCLE, "Writing sources file");
File srcFile = write(tmp, new JarResource(main), "src.jar");
logger.info(LIFECYCLE, "Deploying main file");
maven_gpg_sign_and_deploy(project, mainFile, null, pomFile);
logger.info(LIFECYCLE, "Deploying main sources file");
maven_gpg_sign_and_deploy(project, srcFile, "sources", null);
logger.info(LIFECYCLE, "Deploying main javadoc file");
maven_gpg_sign_and_deploy(project, javadocFile, "javadoc", null);
}
}
}
return true;
}
use of aQute.bnd.osgi.JarResource in project bnd by bndtools.
the class MavenDeployCmd method deploy.
/**
*/
public boolean deploy(Project project, Jar original) throws Exception {
Parameters deploy = project.parseHeader(project.getProperty(Constants.DEPLOY));
Map<String, String> maven = deploy.get(repository);
if (maven == null)
// we're not playing for this bundle
return false;
logger.info(LIFECYCLE, "deploying {} to Maven repo: {}", original, repository);
File target = project.getTarget();
File tmp = Processor.getFile(target, repository);
if (!tmp.exists() && !tmp.mkdirs()) {
throw new IOException("Could not create directory " + tmp);
}
Manifest manifest = original.getManifest();
if (manifest == null)
project.error("Jar has no manifest: %s", original);
else {
logger.info(LIFECYCLE, "Writing pom.xml");
PomResource pom = new PomResource(manifest);
pom.setProperties(maven);
File pomFile = write(tmp, pom, "pom.xml");
try (Jar main = new Jar("main");
Jar src = new Jar("src")) {
split(original, main, src);
Parameters exports = project.parseHeader(manifest.getMainAttributes().getValue(Constants.EXPORT_PACKAGE));
File jdoc = new File(tmp, "jdoc");
IO.mkdirs(jdoc);
logger.info(LIFECYCLE, "Generating Javadoc for: {}", exports.keySet());
Jar javadoc = javadoc(jdoc, project, exports.keySet());
logger.info(LIFECYCLE, "Writing javadoc jar");
File javadocFile = write(tmp, new JarResource(javadoc), "javadoc.jar");
logger.info(LIFECYCLE, "Writing main file");
File mainFile = write(tmp, new JarResource(main), "main.jar");
logger.info(LIFECYCLE, "Writing sources file");
File srcFile = write(tmp, new JarResource(main), "src.jar");
logger.info(LIFECYCLE, "Deploying main file");
maven_gpg_sign_and_deploy(project, mainFile, null, pomFile);
logger.info(LIFECYCLE, "Deploying main sources file");
maven_gpg_sign_and_deploy(project, srcFile, "sources", null);
logger.info(LIFECYCLE, "Deploying main javadoc file");
maven_gpg_sign_and_deploy(project, javadocFile, "javadoc", null);
}
}
return true;
}
Aggregations