Search in sources :

Example 6 with FeaturePackSpec

use of org.jboss.galleon.spec.FeaturePackSpec in project galleon by wildfly.

the class ProvisioningLayout method dependsOn.

private boolean dependsOn(F f, ProducerSpec dep, Set<ProducerSpec> visitedFps) throws ProvisioningException {
    final FeaturePackSpec spec = f.getSpec();
    if (!spec.hasFeaturePackDeps()) {
        return false;
    }
    if (spec.hasFeaturePackDep(dep) || spec.hasTransitiveDep(dep)) {
        return true;
    }
    for (FeaturePackConfig fpConfig : spec.getFeaturePackDeps()) {
        final ProducerSpec producer = fpConfig.getLocation().getProducer();
        if (!visitedFps.add(producer)) {
            continue;
        }
        if (dependsOn(featurePacks.get(producer), dep, visitedFps)) {
            return true;
        }
        visitedFps.remove(producer);
    }
    return false;
}
Also used : ProducerSpec(org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec) FeaturePackSpec(org.jboss.galleon.spec.FeaturePackSpec) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 7 with FeaturePackSpec

use of org.jboss.galleon.spec.FeaturePackSpec in project galleon by wildfly.

the class ProvisioningLayout method install.

private ProvisioningConfig.Builder install(FeaturePackConfig fpConfig, ProvisioningConfig.Builder configBuilder) throws ProvisioningException {
    FeaturePackLocation fpl = fpConfig.getLocation();
    if (!fpl.hasBuild()) {
        fpl = layoutFactory.getUniverseResolver().resolveLatestBuild(fpl);
    }
    final FeaturePackSpec fpSpec = layoutFactory.resolveFeaturePack(fpl, FeaturePackLayout.DIRECT_DEP, fpFactory).getSpec();
    final FPID fpid = fpSpec.getFPID();
    if (fpSpec.isPatch()) {
        if (allPatches.containsKey(fpid)) {
            throw new ProvisioningException(Errors.patchAlreadyApplied(fpid));
        }
        F patchTarget = featurePacks.get(fpSpec.getPatchFor().getProducer());
        if (patchTarget == null || !patchTarget.getFPID().equals(fpSpec.getPatchFor())) {
            throw new ProvisioningException(Errors.patchNotApplicable(fpid, fpSpec.getPatchFor()));
        }
        FeaturePackConfig installedFpConfig = config.getFeaturePackDep(fpSpec.getPatchFor().getProducer());
        if (installedFpConfig == null) {
            installedFpConfig = config.getTransitiveDep(fpSpec.getPatchFor().getProducer());
        }
        if (installedFpConfig == null) {
            return configBuilder.addFeaturePackDep(FeaturePackConfig.transitiveBuilder(patchTarget.getFPID().getLocation()).addPatch(fpid).build());
        }
        return configBuilder.updateFeaturePackDep(FeaturePackConfig.builder(installedFpConfig.getLocation()).init(installedFpConfig).addPatch(fpid).build());
    }
    if (fpl.isMavenCoordinates()) {
        fpl = new FeaturePackLocation(fpid.getUniverse(), fpid.getProducer().getName(), fpid.getChannel().getName(), fpl.getFrequency(), fpid.getBuild());
        fpConfig = FeaturePackConfig.builder(fpl).init(fpConfig).build();
    }
    final F installedFp = featurePacks.get(fpid.getProducer());
    if (installedFp != null) {
        if (installedFp.isTransitiveDep() == fpConfig.isTransitive()) {
            return configBuilder.updateFeaturePackDep(fpConfig);
        }
        if (installedFp.isTransitiveDep()) {
            // transitive becomes direct
            if (config.hasTransitiveDep(fpid.getProducer())) {
                configBuilder.removeTransitiveDep(fpid);
            }
            return configBuilder.addFeaturePackDep(getIndexForDepToInstall(configBuilder, fpid.getProducer()), fpConfig);
        }
        // direct becomes transitive
        configBuilder.removeFeaturePackDep(fpid.getLocation());
    }
    return configBuilder.addFeaturePackDep(fpConfig);
}
Also used : FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ProvisioningException(org.jboss.galleon.ProvisioningException) FeaturePackSpec(org.jboss.galleon.spec.FeaturePackSpec) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 8 with FeaturePackSpec

use of org.jboss.galleon.spec.FeaturePackSpec in project galleon by wildfly.

the class ProvisioningLayout method resolveFeaturePack.

private F resolveFeaturePack(FeaturePackLocation fpl, int type, boolean translateSpecFpl) throws ProvisioningException {
    buildTracker.processing(fpl.getFPID());
    F fp = layoutFactory.resolveFeaturePack(fpl, type, fpFactory);
    buildTracker.processed(fpl.getFPID());
    if (!translateSpecFpl) {
        return fp;
    }
    FeaturePackSpec.Builder rebuilder = null;
    FeaturePackSpec fpSpec = fp.getSpec();
    if (fpSpec.hasTransitiveDeps()) {
        int i = 0;
        for (FeaturePackConfig dep : fpSpec.getTransitiveDeps()) {
            if (dep.getLocation().isMavenCoordinates()) {
                final F fpDep = resolveFeaturePack(dep.getLocation(), type, false);
                if (fpDep.getFPID().getLocation().isMavenCoordinates()) {
                    if (rebuilder != null) {
                        rebuilder.addFeaturePackDep(fpSpec.originOf(dep.getLocation().getProducer()), dep);
                    }
                } else {
                    if (rebuilder == null) {
                        rebuilder = getSpecRebuilder(fp.fpid, fpSpec);
                        if (i > 0) {
                            int j = 0;
                            for (FeaturePackConfig d : fpSpec.getTransitiveDeps()) {
                                rebuilder.addFeaturePackDep(fpSpec.originOf(dep.getLocation().getProducer()), d);
                                if (++j == i) {
                                    break;
                                }
                            }
                        }
                    }
                    rebuilder.addFeaturePackDep(fpSpec.originOf(dep.getLocation().getProducer()), FeaturePackConfig.transitiveBuilder(fpDep.getFPID().getLocation()).init(dep).build());
                }
            } else if (rebuilder != null) {
                rebuilder.addFeaturePackDep(fpSpec.originOf(dep.getLocation().getProducer()), dep);
            }
            i++;
        }
    }
    if (fpSpec.hasFeaturePackDeps()) {
        int i = 0;
        for (FeaturePackConfig dep : fpSpec.getFeaturePackDeps()) {
            if (dep.getLocation().isMavenCoordinates()) {
                final F fpDep = resolveFeaturePack(dep.getLocation(), type, false);
                if (fpDep.getFPID().getLocation().isMavenCoordinates()) {
                    if (rebuilder != null) {
                        rebuilder.addFeaturePackDep(fpSpec.originOf(dep.getLocation().getProducer()), dep);
                    }
                } else {
                    if (rebuilder == null) {
                        rebuilder = getSpecRebuilder(fp.fpid, fpSpec);
                        if (fpSpec.hasTransitiveDeps()) {
                            for (FeaturePackConfig d : fpSpec.getTransitiveDeps()) {
                                rebuilder.addFeaturePackDep(fpSpec.originOf(d.getLocation().getProducer()), d);
                            }
                        }
                        if (i > 0) {
                            int j = 0;
                            for (FeaturePackConfig d : fpSpec.getFeaturePackDeps()) {
                                rebuilder.addFeaturePackDep(fpSpec.originOf(d.getLocation().getProducer()), d);
                                if (++j == i) {
                                    break;
                                }
                            }
                        }
                    }
                    rebuilder.addFeaturePackDep(fpSpec.originOf(dep.getLocation().getProducer()), FeaturePackConfig.builder(fpDep.getFPID().getLocation()).init(dep).build());
                }
            } else if (rebuilder != null) {
                rebuilder.addFeaturePackDep(fpSpec.originOf(dep.getLocation().getProducer()), dep);
            }
            i++;
        }
    }
    if (rebuilder != null) {
        final FeaturePackSpec spec = rebuilder.build();
        fp = fpFactory.newFeaturePack(spec.getFPID().getLocation(), spec, fp.getDir(), fp.getType());
    }
    return fp;
}
Also used : FeaturePackSpec(org.jboss.galleon.spec.FeaturePackSpec) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 9 with FeaturePackSpec

use of org.jboss.galleon.spec.FeaturePackSpec in project galleon by wildfly.

the class ProvisioningLayoutFactory method resolveFeaturePack.

public <F extends FeaturePackLayout> F resolveFeaturePack(FeaturePackLocation location, int type, FeaturePackLayoutFactory<F> factory) throws ProvisioningException {
    final Path fpDir = resolveFeaturePackDir(location);
    final Path fpXml = fpDir.resolve(Constants.FEATURE_PACK_XML);
    if (!Files.exists(fpXml)) {
        throw new ProvisioningDescriptionException(Errors.pathDoesNotExist(fpXml));
    }
    try (BufferedReader reader = Files.newBufferedReader(fpXml)) {
        final FeaturePackSpec fpSpec = FeaturePackXmlParser.getInstance().parse(reader);
        if (location.isMavenCoordinates()) {
            final FPID specId = fpSpec.getFPID();
            final FeaturePackLocation fpl = new FeaturePackLocation(specId.getUniverse(), specId.getProducer().getName(), specId.getChannel().getName(), location.getFrequency(), specId.getBuild());
            synchronized (this) {
                cachedPacks.put(fpl.getFPID(), cachedPacks.get(location.getFPID()));
            }
            location = fpl;
        }
        return factory.newFeaturePack(location, fpSpec, fpDir, type);
    } catch (IOException | XMLStreamException e) {
        throw new ProvisioningException(Errors.parseXml(fpXml), e);
    }
}
Also used : Path(java.nio.file.Path) FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) XMLStreamException(javax.xml.stream.XMLStreamException) ProvisioningException(org.jboss.galleon.ProvisioningException) BufferedReader(java.io.BufferedReader) FeaturePackSpec(org.jboss.galleon.spec.FeaturePackSpec) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) IOException(java.io.IOException) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException)

Example 10 with FeaturePackSpec

use of org.jboss.galleon.spec.FeaturePackSpec in project galleon by wildfly.

the class ProvisioningLayout method loadPatch.

private void loadPatch(FPID patchId) throws ProvisioningException {
    final F patchFp = layoutFactory.resolveFeaturePack(patchId.getLocation(), FeaturePackLayout.PATCH, fpFactory);
    final FeaturePackSpec spec = patchFp.getSpec();
    if (!spec.isPatch()) {
        throw new ProvisioningDescriptionException(patchId + " is not a patch but listed as one");
    }
    allPatches = CollectionUtils.put(allPatches, patchId, patchFp);
    if (spec.hasFeaturePackDeps()) {
        for (FeaturePackConfig patchDep : spec.getFeaturePackDeps()) {
            final FPID patchDepId = patchDep.getLocation().getFPID();
            if (allPatches.containsKey(patchDepId)) {
                continue;
            }
            loadPatch(patchDepId);
        }
    }
    final FPID patchFor = spec.getPatchFor();
    List<F> patchList = fpPatches.get(patchFor);
    if (patchList == null) {
        fpPatches = CollectionUtils.put(fpPatches, patchFor, Collections.singletonList(patchFp));
    } else if (patchList.size() == 1) {
        final List<F> tmp = new ArrayList<>(2);
        tmp.add(patchList.get(0));
        tmp.add(patchFp);
        fpPatches = CollectionUtils.put(fpPatches, patchFor, tmp);
    } else {
        patchList.add(patchFp);
    }
}
Also used : FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) FeaturePackSpec(org.jboss.galleon.spec.FeaturePackSpec) ArrayList(java.util.ArrayList) List(java.util.List) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Aggregations

FeaturePackSpec (org.jboss.galleon.spec.FeaturePackSpec)12 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)6 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)4 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)4 Test (org.junit.Test)4 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)3 ProvisioningException (org.jboss.galleon.ProvisioningException)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 ConfigId (org.jboss.galleon.config.ConfigId)2 ConfigModel (org.jboss.galleon.config.ConfigModel)2 ProducerSpec (org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec)2 BufferedReader (java.io.BufferedReader)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 FeatureConfig (org.jboss.galleon.config.FeatureConfig)1 FeatureGroup (org.jboss.galleon.config.FeatureGroup)1