Search in sources :

Example 1 with Artifact

use of org.apache.felix.fileinstall.plugins.installer.Artifact in project felix by apache.

the class DeploymentInstaller method installArtifacts.

private List<Bundle> installArtifacts(InstallableUnitImpl unit) {
    Supplier<List<Bundle>> func = () -> {
        State oldState = unit.getState();
        unit.setState(State.INSTALLING);
        notifyListeners(Collections.singleton(new InstallableUnitEvent(oldState, State.INSTALLING, unit)));
        try {
            // Install Bundles
            Collection<Artifact> artifacts = unit.getArtifacts();
            List<String> locations = artifacts.stream().map(Artifact::getLocation).collect(Collectors.toList());
            List<Bundle> installed = this.frameworkInstaller.addLocations(unit, locations);
            // Start bundles
            for (Bundle bundle : installed) {
                if (!isFragment(bundle)) {
                    bundle.start();
                }
            }
            // Mark unit installed
            oldState = unit.getState();
            unit.setState(State.INSTALLED);
            notifyListeners(Collections.singleton(new InstallableUnitEvent(oldState, State.INSTALLED, unit)));
            return installed;
        } catch (BundleException | IOException e) {
            oldState = unit.getState();
            unit.setState(State.ERROR);
            unit.setErrorMessage(e.getMessage());
            if (log != null) {
                log.log(LogService.LOG_ERROR, "Error installing artifact(s)", e);
            }
            notifyListeners(Collections.singleton(new InstallableUnitEvent(oldState, State.ERROR, unit)));
            return Collections.emptyList();
        }
    };
    return withLock(this.unitsLock.writeLock(), func);
}
Also used : State(org.apache.felix.fileinstall.plugins.installer.State) Bundle(org.osgi.framework.Bundle) Collection(java.util.Collection) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Artifact(org.apache.felix.fileinstall.plugins.installer.Artifact) InstallableUnitEvent(org.apache.felix.fileinstall.plugins.installer.InstallableUnitEvent)

Example 2 with Artifact

use of org.apache.felix.fileinstall.plugins.installer.Artifact 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

ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Artifact (org.apache.felix.fileinstall.plugins.installer.Artifact)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 InstallableUnitEvent (org.apache.felix.fileinstall.plugins.installer.InstallableUnitEvent)1 State (org.apache.felix.fileinstall.plugins.installer.State)1 ResolveRequest (org.apache.felix.fileinstall.plugins.resolver.ResolveRequest)1 ResolveResult (org.apache.felix.fileinstall.plugins.resolver.ResolveResult)1 Bundle (org.osgi.framework.Bundle)1 BundleException (org.osgi.framework.BundleException)1 Capability (org.osgi.resource.Capability)1 Resource (org.osgi.resource.Resource)1