Search in sources :

Example 91 with Parameters

use of aQute.bnd.header.Parameters in project intellij-plugins by JetBrains.

the class AbstractDependencyFilter method processInstructions.

protected final void processInstructions(String header) throws DependencyEmbedderException {
    Parameters instructions = OSGiHeader.parseHeader(MISSING_KEY_PATTERN.matcher(header).replaceAll("$1$2*;$3"));
    Collection<MavenArtifact> availableDependencies = new LinkedHashSet<>(m_dependencyArtifacts);
    DependencyFilter filter;
    for (Iterator<Map.Entry<String, Attrs>> clauseIterator = instructions.entrySet().iterator(); clauseIterator.hasNext(); ) {
        String inline = "false";
        // always start with a fresh *modifiable* collection for each unique clause
        Collection<MavenArtifact> filteredDependencies = new LinkedHashSet<>(availableDependencies);
        // CLAUSE: REGEXP --> { ATTRIBUTE MAP }
        Map.Entry<String, Attrs> clause = clauseIterator.next();
        String primaryKey = (clause.getKey()).replaceFirst("~+$", "");
        boolean isNegative = primaryKey.startsWith("!");
        if (isNegative) {
            primaryKey = primaryKey.substring(1);
        }
        if (!"*".equals(primaryKey)) {
            filter = new DependencyFilter(primaryKey) {

                boolean matches(MavenArtifact dependency) {
                    return super.matches(dependency.getArtifactId());
                }
            };
            // FILTER ON MAIN CLAUSE
            filter.filter(filteredDependencies);
        }
        for (Map.Entry<String, String> entry : (clause.getValue()).entrySet()) {
            // ATTRIBUTE: KEY --> REGEXP
            Map.Entry attr = (Map.Entry) entry;
            if ("groupId".equals(attr.getKey())) {
                filter = new DependencyFilter((String) attr.getValue()) {

                    boolean matches(MavenArtifact dependency) {
                        return super.matches(dependency.getGroupId());
                    }
                };
            } else if ("artifactId".equals(attr.getKey())) {
                filter = new DependencyFilter((String) attr.getValue()) {

                    boolean matches(MavenArtifact dependency) {
                        return super.matches(dependency.getArtifactId());
                    }
                };
            } else if ("version".equals(attr.getKey())) {
                filter = new DependencyFilter((String) attr.getValue()) {

                    boolean matches(MavenArtifact dependency) {
                        try {
                            // use the symbolic version if available (ie. 1.0.0-SNAPSHOT)
                            return super.matches(dependency.getVersion());
                        } catch (Exception e) {
                            return super.matches(dependency.getVersion());
                        }
                    }
                };
            } else if ("scope".equals(attr.getKey())) {
                filter = new DependencyFilter((String) attr.getValue(), "compile") {

                    boolean matches(MavenArtifact dependency) {
                        return super.matches(dependency.getScope());
                    }
                };
            } else if ("type".equals(attr.getKey())) {
                filter = new DependencyFilter((String) attr.getValue(), "jar") {

                    boolean matches(MavenArtifact dependency) {
                        return super.matches(dependency.getType());
                    }
                };
            } else if ("classifier".equals(attr.getKey())) {
                filter = new DependencyFilter((String) attr.getValue()) {

                    boolean matches(MavenArtifact dependency) {
                        return super.matches(dependency.getClassifier());
                    }
                };
            } else if ("optional".equals(attr.getKey())) {
                filter = new DependencyFilter((String) attr.getValue(), "false") {

                    boolean matches(MavenArtifact dependency) {
                        return super.matches(String.valueOf(dependency.isOptional()));
                    }
                };
            } else if ("inline".equals(attr.getKey())) {
                inline = (String) attr.getValue();
                continue;
            } else {
                throw new DependencyEmbedderException("Unexpected attribute " + attr.getKey());
            }
            // FILTER ON EACH ATTRIBUTE
            filter.filter(filteredDependencies);
        }
        if (isNegative) {
            // negative clauses reduce the set of available artifacts
            availableDependencies.removeAll(filteredDependencies);
            if (!clauseIterator.hasNext()) {
                // assume there's an implicit * missing at the end
                processDependencies(availableDependencies, inline);
            }
        } else {
            // positive clause; doesn't alter the available artifacts
            processDependencies(filteredDependencies, inline);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) MavenArtifact(org.jetbrains.idea.maven.model.MavenArtifact) Map(java.util.Map)

Example 92 with Parameters

use of aQute.bnd.header.Parameters 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 93 with Parameters

use of aQute.bnd.header.Parameters 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)

Example 94 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class Baseline method baseline.

/**
	 * This method compares a jar to a baseline jar and returns version
	 * suggestions if the baseline does not agree with the newer jar. The
	 * returned set contains all the exported packages.
	 * 
	 * @param newer
	 * @param older
	 * @return null if ok, otherwise a set of suggested versions for all
	 *         packages (also the ones that were ok).
	 * @throws Exception
	 */
public Set<Info> baseline(Jar newer, Jar older, Instructions packageFilters) throws Exception {
    Tree n = differ.tree(newer);
    Parameters nExports = getExports(newer);
    Tree o = differ.tree(older);
    Parameters oExports = getExports(older);
    if (packageFilters == null)
        packageFilters = new Instructions();
    return baseline(n, nExports, o, oExports, packageFilters);
}
Also used : Parameters(aQute.bnd.header.Parameters) Tree(aQute.bnd.service.diff.Tree) Instructions(aQute.bnd.osgi.Instructions)

Example 95 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class BndrunResolveContextTest method testResolveProvidedCapabilitiesWithDistro.

public static void testResolveProvidedCapabilitiesWithDistro() throws Exception {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
    BndEditModel model = new BndEditModel();
    model.genericSet("-runprovidedcapabilities", "osgi.service;objectClass=foo.bar.FooBarService;effective:=active");
    model.setDistro(Arrays.asList("testdata/distro.jar;version=file"));
    List<Requirement> requires = new ArrayList<Requirement>();
    List<Capability> caps = CapReqBuilder.getCapabilitiesFrom(new Parameters("osgi.service;objectClass=foo.bar.FooBarService;effective:=active"));
    Requirement req = CapReqBuilder.createRequirementFromCapability(caps.get(0)).buildSyntheticRequirement();
    requires.add(req);
    model.setRunRequires(requires);
    BndrunResolveContext context = new BndrunResolveContext(model, registry, log);
    context.setLevel(0);
    context.init();
    Resolver resolver = new BndResolver(new ResolverLogger(4));
    resolver.resolve(context);
}
Also used : Requirement(org.osgi.resource.Requirement) Parameters(aQute.bnd.header.Parameters) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Resolver(org.osgi.service.resolver.Resolver) MockRegistry(test.lib.MockRegistry) ArrayList(java.util.ArrayList) BndEditModel(aQute.bnd.build.model.BndEditModel)

Aggregations

Parameters (aQute.bnd.header.Parameters)157 Attrs (aQute.bnd.header.Attrs)78 File (java.io.File)45 Jar (aQute.bnd.osgi.Jar)44 Manifest (java.util.jar.Manifest)39 Builder (aQute.bnd.osgi.Builder)35 Domain (aQute.bnd.osgi.Domain)24 ArrayList (java.util.ArrayList)20 Map (java.util.Map)16 Attributes (java.util.jar.Attributes)16 IOException (java.io.IOException)14 HashMap (java.util.HashMap)13 Version (aQute.bnd.version.Version)11 Instructions (aQute.bnd.osgi.Instructions)9 HashSet (java.util.HashSet)9 Requirement (org.osgi.resource.Requirement)9 FileNotFoundException (java.io.FileNotFoundException)8 Properties (java.util.Properties)8 Matcher (java.util.regex.Matcher)8 Analyzer (aQute.bnd.osgi.Analyzer)7