Search in sources :

Example 11 with FileResource

use of aQute.bnd.osgi.FileResource in project bnd by bndtools.

the class MavenBndRepository method put.

@Override
public PutResult put(InputStream stream, PutOptions options) throws Exception {
    init();
    File binaryFile = File.createTempFile("put", ".jar");
    File pomFile = File.createTempFile("pom", ".xml");
    LocalPutResult result = new LocalPutResult();
    try {
        if (options == null)
            options = new PutOptions();
        else {
            result.options = options;
        }
        IO.copy(stream, binaryFile);
        if (options.digest != null) {
            byte[] digest = SHA1.digest(binaryFile).digest();
            if (!Arrays.equals(options.digest, digest))
                throw new IllegalArgumentException("The given sha-1 does not match the contents sha-1");
        }
        if (options.context == null) {
            options.context = registry.getPlugin(Workspace.class);
            if (options.context == null)
                options.context = new Processor();
        }
        ReleaseDTO instructions = getReleaseDTO(options.context);
        try (Jar binary = new Jar(binaryFile)) {
            Resource pomResource;
            if (instructions.pom.path != null) {
                File f = options.context.getFile(instructions.pom.path);
                if (!f.isFile())
                    throw new IllegalArgumentException("-maven-release specifies " + f + " as pom file but this file is not found");
                pomResource = new FileResource(f);
            } else {
                pomResource = getPomResource(binary);
                if (pomResource == null) {
                    pomResource = createPomResource(binary, options.context);
                    if (pomResource == null)
                        throw new IllegalArgumentException("No POM resource in META-INF/maven/... The Maven Bnd Repository requires this pom.");
                }
            }
            IO.copy(pomResource.openInputStream(), pomFile);
            IPom pom;
            try (InputStream fin = IO.stream(pomFile)) {
                pom = storage.getPom(fin);
            }
            Archive binaryArchive = pom.binaryArchive();
            checkRemotePossible(instructions, binaryArchive.isSnapshot());
            if (!binaryArchive.isSnapshot()) {
                releasePlugin.add(options.context, pom);
                if (storage.exists(binaryArchive)) {
                    logger.debug("Already released {} to {}", pom.getRevision(), this);
                    result.alreadyReleased = true;
                    return result;
                }
            }
            logger.debug("Put release {}", pom.getRevision());
            try (Release releaser = storage.release(pom.getRevision(), options.context.getProperties())) {
                if (releaser == null) {
                    logger.debug("Already released {}", pom.getRevision());
                    return result;
                }
                if (instructions.snapshot >= 0)
                    releaser.setBuild(instructions.snapshot, null);
                if (isLocal(instructions))
                    releaser.setLocalOnly();
                releaser.add(pom.getRevision().pomArchive(), pomFile);
                releaser.add(binaryArchive, binaryFile);
                result.binaryArchive = binaryArchive;
                result.pomArchive = pom.getRevision().pomArchive();
                if (!isLocal(instructions)) {
                    try (Tool tool = new Tool(options.context, binary)) {
                        if (instructions.javadoc != null) {
                            if (!NONE.equals(instructions.javadoc.path)) {
                                try (Jar jar = getJavadoc(tool, options.context, instructions.javadoc.path, instructions.javadoc.options, instructions.javadoc.packages == JavadocPackages.EXPORT)) {
                                    save(releaser, pom.getRevision(), jar, "javadoc");
                                }
                            }
                        }
                        if (instructions.sources != null) {
                            if (!NONE.equals(instructions.sources.path)) {
                                try (Jar jar = getSource(tool, options.context, instructions.sources.path)) {
                                    save(releaser, pom.getRevision(), jar, "sources");
                                }
                            }
                        }
                    }
                }
            }
            if (configuration.noupdateOnRelease() == false && !binaryArchive.isSnapshot())
                index.add(binaryArchive);
        }
        return result;
    } catch (Exception e) {
        result.failed = e.getMessage();
        throw e;
    } finally {
        IO.delete(binaryFile);
        IO.delete(pomFile);
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) Archive(aQute.maven.api.Archive) InputStream(java.io.InputStream) IPom(aQute.maven.api.IPom) Resource(aQute.bnd.osgi.Resource) FileResource(aQute.bnd.osgi.FileResource) PomResource(aQute.bnd.maven.PomResource) FileResource(aQute.bnd.osgi.FileResource) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Jar(aQute.bnd.osgi.Jar) File(java.io.File) Release(aQute.maven.api.Release) Workspace(aQute.bnd.build.Workspace)

Example 12 with FileResource

use of aQute.bnd.osgi.FileResource in project bnd by bndtools.

the class bnd method add.

/**
	 * Helper for the jar create function, adds files to the jar
	 * 
	 * @param jar
	 * @param base
	 * @param path
	 * @param report
	 * @throws IOException
	 */
private void add(Jar jar, File base, String path, boolean report) throws IOException {
    if (path.endsWith("/"))
        path = path.substring(0, path.length() - 1);
    File f;
    if (path.equals("."))
        f = base;
    else
        f = getFile(base, path);
    err.printf("Adding: %s\n", path);
    if (f.isFile()) {
        jar.putResource(path, new FileResource(f));
    } else if (f.isDirectory()) {
        if (path.equals("."))
            path = "";
        else
            path += "/";
        String[] subs = f.list();
        for (String sub : subs) {
            add(jar, base, path + sub, report);
        }
    }
}
Also used : FileResource(aQute.bnd.osgi.FileResource) File(java.io.File)

Example 13 with FileResource

use of aQute.bnd.osgi.FileResource in project bnd by bndtools.

the class SubsystemExporter method export.

@Override
public Map.Entry<String, Resource> export(String type, final Project project, Map<String, String> options) throws Exception {
    Jar jar = new Jar(".");
    project.addClose(jar);
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().putValue("Manifest-Version", "1.0");
    manifest.getMainAttributes().putValue("Subsystem-ManifestVersion", "1");
    List<Container> distro = project.getBundles(Strategy.LOWEST, project.getProperty(Constants.DISTRO), Constants.DISTRO);
    List<File> distroFiles = getBundles(distro, project);
    List<File> files = getBundles(project.getRunbundles(), project);
    MultiMap<String, Attrs> imports = new MultiMap<String, Attrs>();
    MultiMap<String, Attrs> exports = new MultiMap<String, Attrs>();
    Parameters requirements = new Parameters();
    Parameters capabilities = new Parameters();
    for (File file : files) {
        Domain domain = Domain.domain(file);
        String bsn = domain.getBundleSymbolicName().getKey();
        String version = domain.getBundleVersion();
        for (Entry<String, Attrs> e : domain.getImportPackage().entrySet()) {
            imports.add(e.getKey(), e.getValue());
        }
        for (Entry<String, Attrs> e : domain.getExportPackage().entrySet()) {
            exports.add(e.getKey(), e.getValue());
        }
        String path = bsn + "-" + version + ".jar";
        jar.putResource(path, new FileResource(file));
    }
    headers(project, manifest.getMainAttributes());
    set(manifest.getMainAttributes(), SUBSYSTEM_TYPE, OSGI_SUBSYSTEM_FEATURE);
    String ssn = project.getName();
    Collection<String> bsns = project.getBsns();
    if (bsns.size() > 0) {
        ssn = bsns.iterator().next();
    }
    set(manifest.getMainAttributes(), SUBSYSTEM_SYMBOLIC_NAME, ssn);
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    manifest.write(bout);
    jar.putResource(OSGI_INF_SUBSYSTEM_MF, new EmbeddedResource(bout.toByteArray(), 0));
    final JarResource jarResource = new JarResource(jar);
    final String name = ssn + ".esa";
    return new Map.Entry<String, Resource>() {

        @Override
        public String getKey() {
            return name;
        }

        @Override
        public Resource getValue() {
            return jarResource;
        }

        @Override
        public Resource setValue(Resource arg0) {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : Parameters(aQute.bnd.header.Parameters) JarResource(aQute.bnd.osgi.JarResource) Attrs(aQute.bnd.header.Attrs) FileResource(aQute.bnd.osgi.FileResource) JarResource(aQute.bnd.osgi.JarResource) FileResource(aQute.bnd.osgi.FileResource) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Resource(aQute.bnd.osgi.Resource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Manifest(java.util.jar.Manifest) MultiMap(aQute.lib.collections.MultiMap) Container(aQute.bnd.build.Container) Entry(java.util.Map.Entry) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Example 14 with FileResource

use of aQute.bnd.osgi.FileResource in project bnd by bndtools.

the class ClassParserTest method testGenericsSignature2.

public static void testGenericsSignature2() throws Exception {
    Clazz c = new Clazz(a, "genericstest", new FileResource(IO.getFile("src/test/generics.clazz")));
    c.parseClassFile();
    assertTrue(c.getReferred().contains(a.getPackageRef("javax/swing/table")));
    assertTrue(c.getReferred().contains(a.getPackageRef("javax/swing")));
}
Also used : FileResource(aQute.bnd.osgi.FileResource) Clazz(aQute.bnd.osgi.Clazz)

Example 15 with FileResource

use of aQute.bnd.osgi.FileResource in project bnd by bndtools.

the class ClassParserTest method testCodehauseGROOVY_6169.

/**
	 * https://jira.codehaus.org/browse/GROOVY-6169 There are several components
	 * involved here, but the symptoms point to the Groovy compiler. Gradle uses
	 * BND to populate the OSGi 'Import-Package' manifest header. The import
	 * from Groovy source is lost and does not appear in the OSGi manifest. This
	 * causes problems when deploying the bundle to OSGi. There's a repro
	 * package attached. It includes two Gradle projects, one using Java, one
	 * using Groovy. They use the same source file contents, but with different
	 * file types. They produce different manifest files, one that imports slf4j
	 * and one that doesn't. You can tweak the build.gradle to use different
	 * Groovy releases. I first discovered this problem using v1.8.7, but saw
	 * the same results with v1.8.9. The problem was apparently fixed in v2.1,
	 * using a groovy-all-2.1.0 a correct manifest file is created.
	 */
public static void testCodehauseGROOVY_6169() throws Exception {
    Clazz c = new Clazz(a, "foo", new FileResource(IO.getFile("jar/BugReproLoggerGroovy189.jclass")));
    c.parseClassFile();
    assertTrue(c.getReferred().contains(a.getPackageRef("org.slf4j")));
}
Also used : FileResource(aQute.bnd.osgi.FileResource) Clazz(aQute.bnd.osgi.Clazz)

Aggregations

FileResource (aQute.bnd.osgi.FileResource)19 File (java.io.File)13 Jar (aQute.bnd.osgi.Jar)10 Manifest (java.util.jar.Manifest)7 Clazz (aQute.bnd.osgi.Clazz)6 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)6 Analyzer (aQute.bnd.osgi.Analyzer)5 Resource (aQute.bnd.osgi.Resource)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Container (aQute.bnd.build.Container)3 Parameters (aQute.bnd.header.Parameters)3 URLResource (aQute.bnd.osgi.URLResource)3 Attrs (aQute.bnd.header.Attrs)2 Domain (aQute.bnd.osgi.Domain)2 JarResource (aQute.bnd.osgi.JarResource)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Workspace (aQute.bnd.build.Workspace)1 PomResource (aQute.bnd.maven.PomResource)1