Search in sources :

Example 1 with ResolveRequest

use of org.apache.felix.fileinstall.plugins.resolver.ResolveRequest in project felix by apache.

the class DeploymentInstaller method analyseFile.

private ResolveRequest analyseFile(File file) throws IOException {
    log(LogService.LOG_INFO, null, "Resolving bundle archive: %s", file.getAbsolutePath());
    String fileUriStr = file.toURI().toString();
    String indexUriStr;
    String name;
    String symbolicName;
    String version = "";
    List<Requirement> requirements = new LinkedList<>();
    try (JarFile jar = new JarFile(file)) {
        Attributes manifestAttribs = jar.getManifest().getMainAttributes();
        symbolicName = manifestAttribs.getValue(Constants.DEPLOYMENT_SYMBOLIC_NAME);
        if (symbolicName == null) {
            symbolicName = file.getName();
        }
        name = manifestAttribs.getValue(Constants.DEPLOYMENT_NAME);
        if (name == null) {
            name = symbolicName;
        }
        version = manifestAttribs.getValue(Constants.DEPLOYMENT_VERSION);
        if (version == null) {
            version = UNKNOWN_DEPLOYMENT_VERSION;
        }
        requirements.addAll(RequirementParser.parseRequireBundle(manifestAttribs.getValue(org.osgi.framework.Constants.REQUIRE_BUNDLE)));
        requirements.addAll(RequirementParser.parseRequireCapability(manifestAttribs.getValue(org.osgi.framework.Constants.REQUIRE_CAPABILITY)));
        if (requirements.isEmpty()) {
            throw new IllegalArgumentException(String.format("Missing %s or %s header in manifest in %s", org.osgi.framework.Constants.REQUIRE_BUNDLE, org.osgi.framework.Constants.REQUIRE_CAPABILITY, file.getAbsolutePath()));
        }
        JarEntry indexEntry = findEntry(jar, Constants.INDEX_FILE, Constants.DEFAULT_INDEX_FILE);
        if (indexEntry == null) {
            throw new IllegalArgumentException("Missing index entry in " + file.getAbsolutePath());
        }
        indexUriStr = "jar:" + fileUriStr + "!/" + indexEntry.getName();
    }
    try {
        ResolveRequest request = new ResolveRequest(name, symbolicName, version, Collections.singletonList(new URI(indexUriStr)), requirements);
        return request;
    } catch (URISyntaxException e) {
        throw new IOException("Unable to convert index URI " + indexUriStr, e);
    }
}
Also used : Requirement(org.osgi.resource.Requirement) Attributes(java.util.jar.Attributes) ResolveRequest(org.apache.felix.fileinstall.plugins.resolver.ResolveRequest) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) URI(java.net.URI) LinkedList(java.util.LinkedList)

Example 2 with ResolveRequest

use of org.apache.felix.fileinstall.plugins.resolver.ResolveRequest in project felix by apache.

the class DeploymentInstaller method performResolve.

private InstallableUnitImpl performResolve(File file) {
    debug("Starting resolve for file: %s", file);
    ResolveRequest request;
    try {
        request = analyseFile(file);
    } catch (Exception e) {
        debug("Failed to analyse file %s: %s", file, e.getMessage());
        return newFailedUnit(file, file.getName(), file.getName(), "UNKNOWN_VERSION", String.format("Error reading archive file %s: %s", file.getAbsolutePath(), e.getMessage()));
    }
    ResolveResult result;
    try {
        result = this.resolver.resolve(request);
    } catch (Exception e) {
        debug("Failed to resolve file %s: %s", file, e.getMessage());
        return newFailedUnit(file, request.getName(), request.getSymbolicName(), request.getVersion(), "Resolution failed: " + e.getMessage());
    }
    List<Artifact> artifacts = new ArrayList<>(result.getResources().size());
    for (Entry<Resource, String> resourceEntry : result.getResources().entrySet()) {
        Capability idCap = getIdentityCapability(resourceEntry.getKey());
        ArtifactImpl artifact = new ArtifactImpl(getIdentity(idCap), getVersion(idCap), resourceEntry.getValue(), getContentHash(resourceEntry.getKey()));
        artifacts.add(artifact);
    }
    debug("Sucessful resolve for file %s: Deployment-Name=%s, Deployment-SymbolicName=%s, Deployment-Version= %s", file, request.getName(), request.getSymbolicName(), request.getVersion());
    return newResolvedUnit(file, request.getName(), request.getSymbolicName(), request.getVersion(), artifacts);
}
Also used : Capability(org.osgi.resource.Capability) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) ResolveRequest(org.apache.felix.fileinstall.plugins.resolver.ResolveRequest) ResolveResult(org.apache.felix.fileinstall.plugins.resolver.ResolveResult) URISyntaxException(java.net.URISyntaxException) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) Artifact(org.apache.felix.fileinstall.plugins.installer.Artifact)

Aggregations

IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 ResolveRequest (org.apache.felix.fileinstall.plugins.resolver.ResolveRequest)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Attributes (java.util.jar.Attributes)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 Artifact (org.apache.felix.fileinstall.plugins.installer.Artifact)1 ResolveResult (org.apache.felix.fileinstall.plugins.resolver.ResolveResult)1 BundleException (org.osgi.framework.BundleException)1 Capability (org.osgi.resource.Capability)1 Requirement (org.osgi.resource.Requirement)1 Resource (org.osgi.resource.Resource)1