Search in sources :

Example 6 with Coordinator

use of org.osgi.service.coordinator.Coordinator in project bnd by bndtools.

the class LocalIndexedRepo method putArtifact.

protected File putArtifact(File tmpFile) throws Exception {
    assert (tmpFile != null);
    assert (tmpFile.isFile());
    init();
    try (Jar jar = new Jar(tmpFile)) {
        String bsn = jar.getBsn();
        if (bsn == null || !Verifier.isBsn(bsn))
            throw new IllegalArgumentException("Jar does not have a symbolic name");
        File dir = new File(storageDir, bsn);
        if (dir.exists() && !dir.isDirectory())
            throw new IllegalArgumentException("Path already exists but is not a directory: " + dir.getAbsolutePath());
        IO.mkdirs(dir);
        String versionString = jar.getVersion();
        if (versionString == null)
            versionString = "0";
        else if (!Verifier.isVersion(versionString))
            throw new IllegalArgumentException("Invalid version " + versionString + " in file " + tmpFile);
        Version version = Version.parseVersion(versionString);
        String fName = bsn + "-" + version.getWithoutQualifier() + ".jar";
        File file = new File(dir, fName);
        // check overwrite policy
        if (!overwrite && file.exists())
            return null;
        // An open jar on file will fail rename on windows
        jar.close();
        IO.rename(tmpFile, file);
        synchronized (newFilesInCoordination) {
            newFilesInCoordination.add(file.toURI());
        }
        Coordinator coordinator = (registry != null) ? registry.getPlugin(Coordinator.class) : null;
        if (!(coordinator != null && coordinator.addParticipant(this))) {
            finishPut();
        }
        return file;
    }
}
Also used : Version(aQute.bnd.version.Version) Jar(aQute.bnd.osgi.Jar) Coordinator(org.osgi.service.coordinator.Coordinator) File(java.io.File)

Example 7 with Coordinator

use of org.osgi.service.coordinator.Coordinator in project bndtools by bndtools.

the class ResolveOperation method run.

@Override
public void run(IProgressMonitor monitor) {
    MultiStatus status = new MultiStatus(Plugin.PLUGIN_ID, 0, Messages.ResolveOperation_errorOverview, null);
    // Start a coordination
    BundleContext bc = Plugin.getDefault().getBundleContext();
    ServiceReference<Coordinator> coordSvcRef = bc.getServiceReference(Coordinator.class);
    Coordinator coordinator = coordSvcRef != null ? (Coordinator) bc.getService(coordSvcRef) : null;
    Coordination coordination = coordinator != null ? coordinator.begin(ResolveOperation.class.getName(), 0) : null;
    // Begin resolve
    ResolveProcess resolve = new ResolveProcess();
    ResolverLogger logger = new ResolverLogger();
    try {
        BndResolver bndResolver = new BndResolver(logger);
        ReporterLogService log = new ReporterLogService(model.getWorkspace());
        Map<Resource, List<Wire>> wirings = resolve.resolveRequired(model, model.getWorkspace(), bndResolver, callbacks, log);
        Map<Resource, List<Wire>> optionalResources = new HashMap<Resource, List<Wire>>(resolve.getOptionalResources().size());
        for (Resource optional : resolve.getOptionalResources()) {
            optionalResources.put(optional, new ArrayList<Wire>(resolve.getOptionalReasons(optional)));
        }
        result = new ResolutionResult(Outcome.Resolved, wirings, optionalResources, null, status, logger.getLog());
        if (coordination != null)
            coordination.end();
    } catch (ResolveCancelledException e) {
        result = new ResolutionResult(Outcome.Cancelled, null, null, null, status, logger.getLog());
        if (coordination != null)
            coordination.fail(e);
    } catch (ResolutionException e) {
        status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, e.getLocalizedMessage(), e));
        result = new ResolutionResult(Outcome.Unresolved, null, null, e, status, logger.getLog());
        if (coordination != null)
            coordination.fail(e);
    } catch (Exception e) {
        status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Exception during resolution.", e));
        result = new ResolutionResult(Outcome.Error, null, null, null, status, logger.getLog());
        if (coordination != null)
            coordination.fail(e);
    } finally {
        if (coordinator != null)
            bc.ungetService(coordSvcRef);
    }
}
Also used : ReporterLogService(aQute.bnd.deployer.repository.ReporterLogService) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Coordination(org.osgi.service.coordinator.Coordination) ResolverLogger(biz.aQute.resolve.ResolverLogger) HashMap(java.util.HashMap) Resource(org.osgi.resource.Resource) MultiStatus(org.eclipse.core.runtime.MultiStatus) Coordinator(org.osgi.service.coordinator.Coordinator) Wire(org.osgi.resource.Wire) ResolutionException(org.osgi.service.resolver.ResolutionException) ResolutionException(org.osgi.service.resolver.ResolutionException) ResolveProcess(biz.aQute.resolve.ResolveProcess) ArrayList(java.util.ArrayList) List(java.util.List) BndResolver(biz.aQute.resolve.BndResolver) BundleContext(org.osgi.framework.BundleContext)

Aggregations

Coordinator (org.osgi.service.coordinator.Coordinator)7 TransactionManager (javax.transaction.TransactionManager)3 BundleContext (org.osgi.framework.BundleContext)2 Coordination (org.osgi.service.coordinator.Coordination)2 ReporterLogService (aQute.bnd.deployer.repository.ReporterLogService)1 Jar (aQute.bnd.osgi.Jar)1 Version (aQute.bnd.version.Version)1 BndResolver (biz.aQute.resolve.BndResolver)1 ResolveProcess (biz.aQute.resolve.ResolveProcess)1 ResolverLogger (biz.aQute.resolve.ResolverLogger)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Transaction (javax.transaction.Transaction)1 ComponentDefinitionRegistry (org.apache.aries.blueprint.ComponentDefinitionRegistry)1 MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)1 GenericHeader (org.apache.aries.subsystem.core.archive.GenericHeader)1 SubsystemContentHeader (org.apache.aries.subsystem.core.archive.SubsystemContentHeader)1 SubsystemTest (org.apache.aries.subsystem.itests.SubsystemTest)1