Search in sources :

Example 1 with JarResource

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);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) JarResource(aQute.bnd.osgi.JarResource) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Jar(aQute.bnd.osgi.Jar) PutResult(aQute.bnd.service.RepositoryPlugin.PutResult) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with JarResource

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);
}
Also used : JarResource(aQute.bnd.osgi.JarResource) Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Properties(java.util.Properties)

Example 3 with JarResource

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();
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) JarResource(aQute.bnd.osgi.JarResource) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Jar(aQute.bnd.osgi.Jar) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Example 4 with JarResource

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;
}
Also used : Parameters(aQute.bnd.header.Parameters) JarResource(aQute.bnd.osgi.JarResource) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) File(java.io.File)

Example 5 with JarResource

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;
}
Also used : Parameters(aQute.bnd.header.Parameters) JarResource(aQute.bnd.osgi.JarResource) Jar(aQute.bnd.osgi.Jar) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) File(java.io.File)

Aggregations

Jar (aQute.bnd.osgi.Jar)12 JarResource (aQute.bnd.osgi.JarResource)12 File (java.io.File)8 Builder (aQute.bnd.osgi.Builder)5 Resource (aQute.bnd.osgi.Resource)5 Manifest (java.util.jar.Manifest)5 Parameters (aQute.bnd.header.Parameters)3 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)3 Properties (java.util.Properties)3 Container (aQute.bnd.build.Container)2 Domain (aQute.bnd.osgi.Domain)2 FileResource (aQute.bnd.osgi.FileResource)2 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 Attrs (aQute.bnd.header.Attrs)1 Verifier (aQute.bnd.osgi.Verifier)1 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)1 PutResult (aQute.bnd.service.RepositoryPlugin.PutResult)1 MultiMap (aQute.lib.collections.MultiMap)1