Search in sources :

Example 1 with Parameters

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

the class OsmorcFacetConfiguration method writeExternal.

@Override
public void writeExternal(Element element) throws WriteExternalException {
    element.setAttribute(MANIFEST_GENERATION_MODE, getManifestGenerationMode().name());
    element.setAttribute(MANIFEST_LOCATION, getManifestLocation());
    element.setAttribute(JAR_FILE_LOCATION, myJarFileLocation != null ? myJarFileLocation : "");
    element.setAttribute(OUTPUT_PATH_TYPE, getOutputPathType().name());
    element.setAttribute(BND_FILE_LOCATION, getBndFileLocation());
    element.setAttribute(BUNDLOR_FILE_LOCATION, getBundlorFileLocation());
    element.setAttribute(BUNDLE_ACTIVATOR, getBundleActivator());
    element.setAttribute(BUNDLE_SYMBOLIC_NAME, getBundleSymbolicName());
    element.setAttribute(BUNDLE_VERSION, getBundleVersion());
    element.setAttribute(IGNORE_FILE_PATTERN, getIgnoreFilePattern());
    element.setAttribute(USE_PROJECT_DEFAULT_MANIFEST_FILE_LOCATION, String.valueOf(isUseProjectDefaultManifestFileLocation()));
    element.setAttribute(ALWAYS_REBUILD_BUNDLE_JAR, String.valueOf(isAlwaysRebuildBundleJAR()));
    element.setAttribute(DO_NOT_SYNCHRONIZE_WITH_MAVEN, String.valueOf(myDoNotSynchronizeWithMaven));
    Element props = new Element(ADDITIONAL_PROPERTIES);
    Map<String, String> map = getAdditionalPropertiesAsMap();
    for (String key : map.keySet()) {
        String value = map.get(key);
        if (key.equals(INCLUDE_RESOURCE)) {
            // there are paths in there, collapse these so the IML files don't get mixed up on every machine. The built in macro manager
            // does not recognize these, so we have to do this manually here.
            Parameters parameters = OSGiHeader.parseHeader(value);
            PathMacroManager macroManager = PathMacroManager.getInstance(myFacet.getModule());
            StringBuilder result = new StringBuilder(value.length());
            int last = 0;
            for (String pair : parameters.keySet()) {
                if (StringUtil.startsWithChar(pair, '{') && StringUtil.endsWithChar(pair, '}')) {
                    pair = pair.substring(1, pair.length() - 1).trim();
                }
                int p = pair.indexOf('=');
                String source = (p < 0 ? pair : pair.substring(p + 1)).trim();
                if (StringUtil.startsWithChar(source, '@')) {
                    source = source.substring(1);
                }
                String collapsedSource = macroManager.collapsePath(source);
                int sourceStart = value.indexOf(source, last);
                result.append(value, last, sourceStart).append(collapsedSource);
                last = sourceStart + source.length();
            }
            result.append(value, last, value.length());
            value = result.toString();
        }
        Element prop = new Element(PROPERTY);
        prop.setAttribute(KEY, key);
        prop.setAttribute(VALUE, value);
        props.addContent(prop);
    }
    element.addContent(props);
    Element additionalJARContentsElement = new Element("additionalJARContents");
    List<Pair<String, String>> additionalJARContents = getAdditionalJARContents();
    for (Pair<String, String> additionalJARContent : additionalJARContents) {
        Element entry = new Element("entry");
        entry.setAttribute("source", additionalJARContent.getFirst());
        entry.setAttribute("dest", additionalJARContent.getSecond());
        additionalJARContentsElement.addContent(entry);
    }
    element.addContent(additionalJARContentsElement);
}
Also used : Parameters(aQute.bnd.header.Parameters) Element(org.jdom.Element) PathMacroManager(com.intellij.openapi.components.PathMacroManager) Pair(com.intellij.openapi.util.Pair)

Example 2 with Parameters

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

the class ImporterUtil method sanitizeIncludedResources.

/**
   * Sanitizes the Include-Resource header by resolving relative paths to the maven project's root and converting backslashes to slashes.
   */
private static void sanitizeIncludedResources(@NotNull Map<String, String> props, @NotNull MavenProject project) {
    String includeResourceHeader = props.get(Constants.INCLUDE_RESOURCE);
    if (StringUtil.isEmpty(includeResourceHeader)) {
        return;
    }
    Parameters parameters = OSGiHeader.parseHeader(includeResourceHeader);
    StringBuilder sanitizedHeader = new StringBuilder();
    for (Iterator<String> iterator = parameters.keySet().iterator(); iterator.hasNext(); ) {
        String name = iterator.next();
        String prefix = "";
        String suffix = "";
        if (StringUtil.startsWithChar(name, '{') && name.endsWith("}")) {
            name = name.substring(1, name.length() - 1).trim();
            prefix = "{" + prefix;
            suffix += "}";
        }
        String[] parts = name.split("\\s*=\\s*");
        String source = parts[0];
        String target = "";
        if (parts.length == 2) {
            source = parts[1];
            target = parts[0];
        }
        if (StringUtil.startsWithChar(source, '@')) {
            source = source.substring(1);
            prefix += "@";
        }
        String sanitizedSource = source.replace('\\', '/');
        String sanitizedTarget = target.replace('\\', '/');
        // check if it's relative
        VirtualFile relativeFile = VfsUtil.findRelativeFile(project.getDirectoryFile(), sanitizedSource.split("/"));
        if (relativeFile != null) {
            sanitizedSource = relativeFile.getPath();
        }
        sanitizedHeader.append(prefix);
        if (!StringUtil.isEmpty(sanitizedTarget)) {
            sanitizedHeader.append(sanitizedTarget).append("=");
        }
        sanitizedHeader.append(sanitizedSource);
        sanitizedHeader.append(suffix);
        if (iterator.hasNext()) {
            sanitizedHeader.append(",");
        }
    }
    props.put(Constants.INCLUDE_RESOURCE, sanitizedHeader.toString());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Parameters(aQute.bnd.header.Parameters)

Example 3 with Parameters

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

the class AnnotationHeadersTest method testMultipleManifestHeaders.

/**
	 * Say I want to define a capability namespace for web applications, e.g.
	 * Provide-Capability: webapp; webapp=Petstore. Web application components
	 * necessarily require an HTTP implementation so they should
	 * Require-Capability: osgi.implementation;
	 * filter:="(osgi.implementation=osgi.http)". I want to define an annotation
	 * that I can put onto a component that implies both the above provide and
	 * require. I tried the following:
	 * 
	 * <pre>
	 * &#64;ProvideCapability(ns = "webapp")
	 * &#64;RequireCapability(ns = "osgi.implementation", filter = "(osgi.implementation=osgi.http)")
	 * &#64;interface WebApplication {
	 * 	String name();
	 * }
	 * 
	 * &#64;WebApplication(name = "Petstore")
	 * &#64;Component
	 * public class PetstoreAppComponent {
	 * 	// ..
	 * }
	 * </pre>
	 * 
	 * However this only generated the Provide, it did not generate the Require.
	 * If I switch the order of annotations so that @RequireCapability is first,
	 * then it only generates the Require.
	 */
public void testMultipleManifestHeaders() throws Exception {
    try (Builder b = new Builder()) {
        b.addClasspath(IO.getFile("bin"));
        b.setPrivatePackage("test.annotationheaders.multiple");
        b.build();
        assertTrue(b.check());
        b.getJar().getManifest().write(System.out);
        Attributes mainAttributes = b.getJar().getManifest().getMainAttributes();
        Parameters req = new Parameters(mainAttributes.getValue(Constants.REQUIRE_CAPABILITY));
        Parameters cap = new Parameters(mainAttributes.getValue(Constants.PROVIDE_CAPABILITY));
        assertTrue(cap.get("provide") != null);
        assertTrue(req.get("require") != null);
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes)

Example 4 with Parameters

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

the class AnnotationHeadersTest method testWithAttrs.

public void testWithAttrs() throws Exception {
    Builder b = new Builder();
    try {
        b.addClasspath(new File("bin"));
        b.setProperty("Private-Package", "test.annotationheaders.attrs");
        b.build();
        assertTrue(b.check());
        Manifest m = b.getJar().getManifest();
        m.write(System.out);
        Parameters p = new Parameters(m.getMainAttributes().getValue("Provide-Capability"));
        Attrs attrs = p.get("nsx");
        assertNotNull(attrs);
        assertEquals(Long.valueOf(3), attrs.getTyped("foo"));
        p = new Parameters(m.getMainAttributes().getValue("Bundle-License"));
        attrs = p.get("license");
        assertNotNull(attrs);
        assertEquals("abc", attrs.get("foo"));
        p = new Parameters(m.getMainAttributes().getValue("Require-Capability"));
        // namespaces must be "osgi.ee", "nsx" and "nsy" ONLY
        assertNotNull(p.get("nsx"));
        assertNotNull(p.get("nsy"));
        assertNotNull(p.get("nsz"));
        assertNotNull(p.get("param"));
        assertNotNull(p.get("osgi.ee"));
        assertEquals("spurious Require-Capability namespaces", 5, p.size());
        attrs = p.get("nsx");
        assertEquals(Arrays.asList("abc", "def"), attrs.getTyped("foo"));
        attrs = p.get("nsy");
        assertEquals("hello", attrs.get("value"));
        attrs = p.get("nsz");
        assertEquals("(nsz=*)", attrs.get("filter:"));
        assertEquals("world", attrs.get("hello"));
        attrs = p.get("param");
        assertEquals("(&(a=hello)(b=goodbye))", attrs.get("filter:"));
    } finally {
        b.close();
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Attrs(aQute.bnd.header.Attrs) Manifest(java.util.jar.Manifest) File(java.io.File)

Example 5 with Parameters

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

the class VersionPolicyTest method testProviderTypeR6.

/**
	 * Test if the implementation of "AnnotatedProviderInterface", which is
	 * annotated with OSGi R6 @ProviderType, causes import of the api package to
	 * use the provider version policy
	 */
public static void testProviderTypeR6() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setPrivatePackage("test.versionpolicy.implemented.osgi");
    b.setProperty("build", "123");
    Jar jar = b.build();
    assertTrue(b.check());
    Manifest m = jar.getManifest();
    m.write(System.err);
    Domain d = Domain.domain(m);
    Parameters params = d.getImportPackage();
    Attrs attrs = params.get("test.version.annotations.osgi");
    assertNotNull(attrs);
    assertEquals("[1.2,1.3)", attrs.get("version"));
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Attrs(aQute.bnd.header.Attrs) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Aggregations

Parameters (aQute.bnd.header.Parameters)167 Attrs (aQute.bnd.header.Attrs)80 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)23 Map (java.util.Map)19 Attributes (java.util.jar.Attributes)17 IOException (java.io.IOException)15 HashMap (java.util.HashMap)15 Version (aQute.bnd.version.Version)11 HashSet (java.util.HashSet)10 Instructions (aQute.bnd.osgi.Instructions)9 FileNotFoundException (java.io.FileNotFoundException)8 Properties (java.util.Properties)8 Matcher (java.util.regex.Matcher)8 Analyzer (aQute.bnd.osgi.Analyzer)7 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)7