Search in sources :

Example 16 with UTF8Properties

use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.

the class Analyzer method getManifest.

/**
	 * Specifically for Maven
	 * 
	 */
public static Properties getManifest(File dirOrJar) throws Exception {
    try (Analyzer analyzer = new Analyzer()) {
        analyzer.setJar(dirOrJar);
        Properties properties = new UTF8Properties();
        properties.put(IMPORT_PACKAGE, "*");
        properties.put(EXPORT_PACKAGE, "*");
        analyzer.setProperties(properties);
        Manifest m = analyzer.calcManifest();
        Properties result = new UTF8Properties();
        for (Iterator<Object> i = m.getMainAttributes().keySet().iterator(); i.hasNext(); ) {
            Attributes.Name name = (Attributes.Name) i.next();
            result.put(name.toString(), m.getMainAttributes().getValue(name));
        }
        return result;
    }
}
Also used : Attributes(java.util.jar.Attributes) Name(java.util.jar.Attributes.Name) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) Properties(java.util.Properties) Manifest(java.util.jar.Manifest) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) Name(java.util.jar.Attributes.Name)

Example 17 with UTF8Properties

use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.

the class PomParser method getProperties.

public Properties getProperties(File pom) throws Exception {
    DocumentBuilder db = dbf.newDocumentBuilder();
    XPath xpath = xpathf.newXPath();
    pom = pom.getAbsoluteFile();
    Document doc = db.parse(pom);
    Properties p = new UTF8Properties();
    // Check if there is a parent pom
    String relativePath = xpath.evaluate("project/parent/relativePath", doc);
    if (relativePath != null && relativePath.length() != 0) {
        File parentPom = IO.getFile(pom.getParentFile(), relativePath);
        if (parentPom.isFile()) {
            Properties parentProps = getProperties(parentPom);
            p.putAll(parentProps);
        } else {
            error("Parent pom for %s is not an existing file (could be directory): %s", pom, parentPom);
        }
    }
    Element e = doc.getDocumentElement();
    traverse("pom", e, p);
    String[] scopes = { "provided", "runtime", "test", "system" };
    NodeList set = (NodeList) xpath.evaluate("//dependency[not(scope) or scope='compile']", doc, XPathConstants.NODESET);
    if (set.getLength() != 0)
        p.put("pom.scope.compile", toBsn(set));
    for (String scope : scopes) {
        set = (NodeList) xpath.evaluate("//dependency[scope='" + scope + "']", doc, XPathConstants.NODESET);
        if (set.getLength() != 0)
            p.put("pom.scope." + scope, toBsn(set));
    }
    return p;
}
Also used : XPath(javax.xml.xpath.XPath) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) Properties(java.util.Properties) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) File(java.io.File) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 18 with UTF8Properties

use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.

the class HttpBasicAuthURLConnector method init.

protected void init() {
    if (inited.compareAndSet(false, true)) {
        mappings.clear();
        StringTokenizer tokenizer = new StringTokenizer(configFileList, ",");
        while (tokenizer.hasMoreTokens()) {
            String configFileName = tokenizer.nextToken().trim();
            File file = new File(configFileName);
            if (file.exists()) {
                Properties props = new UTF8Properties();
                try (InputStream stream = IO.stream(file)) {
                    props.load(stream);
                    for (Object key : props.keySet()) {
                        String name = (String) key;
                        if (name.startsWith(PREFIX_PATTERN)) {
                            String id = name.substring(PREFIX_PATTERN.length());
                            Glob glob = new Glob(props.getProperty(name));
                            String uid = props.getProperty(PREFIX_USER + id);
                            String pwd = props.getProperty(PREFIX_PASSWORD + id);
                            mappings.add(new Mapping(id, glob, uid, pwd));
                        }
                    }
                } catch (IOException e) {
                    if (reporter != null)
                        reporter.error("Failed to load %s", configFileName);
                }
            }
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) InputStream(java.io.InputStream) Glob(aQute.libg.glob.Glob) IOException(java.io.IOException) Properties(java.util.Properties) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) File(java.io.File) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 19 with UTF8Properties

use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.

the class BndrunResolveContext method findAdditionalAugmentsFromResource.

private void findAdditionalAugmentsFromResource(Processor augments, Capability capability) {
    Resource resource = capability.getResource();
    Map<URI, String> locations = ResourceUtils.getLocations(resource);
    if (locations == null || locations.isEmpty())
        return;
    Object pathObject = capability.getAttributes().get("path");
    if (pathObject == null)
        pathObject = "augments.bnd";
    if (pathObject instanceof String) {
        String path = (String) pathObject;
        HttpClient http = registry.getPlugin(HttpClient.class);
        for (URI uri : locations.keySet()) try {
            logger.debug("loading augments from {}", uri);
            File file = http.build().age(24, TimeUnit.HOURS).useCache().go(uri);
            try (Jar jar = new Jar(file)) {
                aQute.bnd.osgi.Resource rs = jar.getResource(path);
                try (InputStream in = rs.openInputStream()) {
                    UTF8Properties p = new UTF8Properties();
                    p.load(in, file, project);
                    augments.getProperties().putAll(p);
                    return;
                }
            }
        } catch (Exception e) {
            project.warning("Failed to handle augment resource from repo %s", uri);
        }
    }
}
Also used : InputStream(java.io.InputStream) HttpClient(aQute.bnd.http.HttpClient) Resource(org.osgi.resource.Resource) Jar(aQute.bnd.osgi.Jar) URI(java.net.URI) File(java.io.File) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 20 with UTF8Properties

use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.

the class BndMavenPlugin method loadProjectProperties.

private File loadProjectProperties(Builder builder, MavenProject project) throws Exception {
    // Load parent project properties first
    MavenProject parentProject = project.getParent();
    if (parentProject != null) {
        loadProjectProperties(builder, parentProject);
    }
    // Merge in current project properties
    Xpp3Dom configuration = project.getGoalConfiguration("biz.aQute.bnd", "bnd-maven-plugin", mojoExecution.getExecutionId(), mojoExecution.getGoal());
    File baseDir = project.getBasedir();
    if (baseDir != null) {
        // file system based pom
        File pomFile = project.getFile();
        builder.updateModified(pomFile.lastModified(), "POM: " + pomFile);
        // check for bnd file
        String bndFileName = Project.BNDFILE;
        if (configuration != null) {
            Xpp3Dom bndfileElement = configuration.getChild("bndfile");
            if (bndfileElement != null) {
                bndFileName = bndfileElement.getValue();
            }
        }
        File bndFile = IO.getFile(baseDir, bndFileName);
        if (bndFile.isFile()) {
            logger.debug("loading bnd properties from file: {}", bndFile);
            // we use setProperties to handle -include
            builder.setProperties(bndFile.getParentFile(), builder.loadProperties(bndFile));
            return bndFile;
        }
    // no bnd file found, so we fall through
    }
    // check for bnd-in-pom configuration
    if (configuration != null) {
        Xpp3Dom bndElement = configuration.getChild("bnd");
        if (bndElement != null) {
            logger.debug("loading bnd properties from bnd element in pom: {}", project);
            UTF8Properties properties = new UTF8Properties();
            properties.load(bndElement.getValue(), project.getFile(), builder);
            if (baseDir != null) {
                String here = baseDir.toURI().getPath();
                here = Matcher.quoteReplacement(here.substring(0, here.length() - 1));
                properties = properties.replaceAll("\\$\\{\\.\\}", here);
            }
            // we use setProperties to handle -include
            builder.setProperties(baseDir, properties);
        }
    }
    return project.getFile();
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) MavenProject(org.apache.maven.project.MavenProject) IO.getFile(aQute.lib.io.IO.getFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Aggregations

UTF8Properties (aQute.lib.utf8properties.UTF8Properties)33 Properties (java.util.Properties)18 File (java.io.File)14 InputStream (java.io.InputStream)11 IOException (java.io.IOException)10 Jar (aQute.bnd.osgi.Jar)7 Attributes (java.util.jar.Attributes)5 Manifest (java.util.jar.Manifest)5 FileNotFoundException (java.io.FileNotFoundException)4 StringReader (java.io.StringReader)4 Parameters (aQute.bnd.header.Parameters)3 Processor (aQute.bnd.osgi.Processor)3 MalformedURLException (java.net.MalformedURLException)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Builder (aQute.bnd.osgi.Builder)2 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)2 Resource (aQute.bnd.osgi.Resource)2 LauncherConstants (aQute.launcher.constants.LauncherConstants)2 Command (aQute.libg.command.Command)2