Search in sources :

Example 1 with FPID

use of org.jboss.galleon.universe.FeaturePackLocation.FPID in project galleon by wildfly.

the class UnknownDefaultPackageTestCase method testMain.

@Test
public void testMain() throws Exception {
    final FPID fp1Gav = LegacyGalleon1Universe.newFPID("org.pm.test:fp-install", "1", "1.0.0.Beta1");
    try {
        FeaturePackDescription.builder(FeaturePackSpec.builder(fp1Gav).addDefaultPackage("default")).addPackage(PackageSpec.forName("a")).build();
        Assert.fail("Non-existing default package");
    } catch (ProvisioningDescriptionException e) {
        Assert.assertEquals(Errors.unknownPackage(fp1Gav, "default"), e.getMessage());
    }
}
Also used : FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) Test(org.junit.Test)

Example 2 with FPID

use of org.jboss.galleon.universe.FeaturePackLocation.FPID in project galleon by wildfly.

the class PersistChangesTestBase method provisionedState.

@Override
protected ProvisionedState provisionedState() throws ProvisioningException {
    final ProvisionedState.Builder builder = ProvisionedState.builder();
    final FPID[] fpids = provisionedFpids();
    if (fpids != null && fpids.length > 0) {
        for (FPID fpid : fpids) {
            builder.addFeaturePack(ProvisionedFeaturePack.forFPID(fpid));
        }
        final ProvisionedConfig[] configs = provisionedConfigModels();
        if (configs != null && configs.length > 0) {
            for (ProvisionedConfig config : configs) {
                builder.addConfig(config);
            }
        }
    }
    return builder.build();
}
Also used : FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ProvisionedState(org.jboss.galleon.state.ProvisionedState) ProvisionedConfig(org.jboss.galleon.state.ProvisionedConfig)

Example 3 with FPID

use of org.jboss.galleon.universe.FeaturePackLocation.FPID in project galleon by wildfly.

the class ProvisioningLayout method layout.

private void layout(FeaturePackDepsConfig config, Map<ProducerSpec, FPID> branch, int type) throws ProvisioningException {
    if (!config.hasFeaturePackDeps()) {
        return;
    }
    List<ProducerSpec> added = Collections.emptyList();
    if (config.hasTransitiveDeps()) {
        if (transitiveDeps == null) {
            transitiveDeps = new HashSet<>();
        }
        for (FeaturePackConfig transitiveConfig : config.getTransitiveDeps()) {
            FeaturePackLocation fpl = transitiveConfig.getLocation();
            if (transitiveConfig.hasPatches()) {
                addPatches(transitiveConfig);
            }
            final FPID branchId = branch.get(fpl.getProducer());
            if (branchId != null) {
                if (!branchId.getChannel().getName().equals(fpl.getChannel().getName())) {
                    addConflict(fpl.getFPID(), branchId);
                }
                continue;
            }
            if (fpl.isMavenCoordinates()) {
                final F f = resolveFeaturePack(fpl, FeaturePackLayout.TRANSITIVE_DEP, true);
                fpl = f.getSpec().getFPID().getLocation();
                registerResolvedVersion(transitiveConfig.getLocation().getProducer(), fpl);
                registerMavenProducer(transitiveConfig.getLocation().getProducer(), f);
            }
            transitiveDeps.add(fpl.getProducer());
            branch.put(fpl.getProducer(), fpl.getFPID());
            added = CollectionUtils.add(added, fpl.getProducer());
        }
    }
    final Collection<FeaturePackConfig> fpDeps = config.getFeaturePackDeps();
    List<F> queue = new ArrayList<>(fpDeps.size());
    for (FeaturePackConfig fpConfig : fpDeps) {
        FeaturePackLocation fpl = fpConfig.getLocation();
        if (fpConfig.hasPatches()) {
            addPatches(fpConfig);
        }
        FPID branchId = branch.get(fpl.getProducer());
        fpl = resolveVersion(fpl, branchId);
        F fp = null;
        if (!fpl.isMavenCoordinates()) {
            fp = featurePacks.get(fpl.getProducer());
            if (fp != null) {
                converge(branchId, fpl.getFPID(), fp.getFPID());
                continue;
            }
        }
        fp = resolveFeaturePack(fpl, type, true);
        if (fpl.isMavenCoordinates()) {
            if (branchId == null) {
                branchId = branch.get(fp.getFPID().getProducer());
            }
            final FeaturePackLocation resolvedFpl = resolveVersion(fp.getFPID().getLocation(), branchId);
            F resolvedFp = featurePacks.get(resolvedFpl.getProducer());
            if (resolvedFp != null) {
                converge(branchId, resolvedFpl.getFPID(), resolvedFp.getFPID());
                if (!fpl.equals(resolvedFpl)) {
                    registerMavenProducer(fpl.getProducer(), resolvedFp);
                }
                continue;
            }
            if (!fpl.equals(resolvedFpl)) {
                if (branchId != null) {
                    fp = resolveFeaturePack(resolvedFpl, type, true);
                } else {
                    registerResolvedVersion(fpl.getProducer(), resolvedFpl);
                }
                registerMavenProducer(fpl.getProducer(), fp);
                fpl = resolvedFpl;
            }
        }
        registerFeaturePack(fpl.getProducer(), fp);
        queue.add(fp);
        if (branchId == null || branchId.getBuild() == null) {
            branch.put(fpl.getProducer(), fpl.getFPID());
            added = CollectionUtils.add(added, fpl.getProducer());
        }
    }
    if (!queue.isEmpty()) {
        for (F p : queue) {
            final FeaturePackSpec spec = p.getSpec();
            layout(spec, branch, FeaturePackLayout.TRANSITIVE_DEP);
            if (spec.hasPlugins()) {
                pluginLocations = CollectionUtils.putAll(pluginLocations, spec.getPlugins());
            }
            handle.copyResources(p.getDir());
            ordered.add(p);
        }
    }
    if (!added.isEmpty()) {
        for (ProducerSpec producer : added) {
            branch.remove(producer);
        }
    }
}
Also used : FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ProducerSpec(org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec) ArrayList(java.util.ArrayList) FeaturePackSpec(org.jboss.galleon.spec.FeaturePackSpec) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 4 with FPID

use of org.jboss.galleon.universe.FeaturePackLocation.FPID 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 5 with FPID

use of org.jboss.galleon.universe.FeaturePackLocation.FPID in project galleon by wildfly.

the class ProvisioningLayout method doBuild.

private void doBuild(boolean cleanupTransitive, boolean trackProgress) throws ProvisioningException {
    buildTracker = getBuildTracker(trackProgress);
    buildTracker.starting(-1);
    final Map<ProducerSpec, FPID> depBranch = new HashMap<>();
    layout(config, depBranch, FeaturePackLayout.DIRECT_DEP);
    if (!conflicts.isEmpty()) {
        throw new ProvisioningDescriptionException(Errors.fpVersionCheckFailed(conflicts.values()));
    }
    if (transitiveDeps != null) {
        ProvisioningConfig.Builder newConfig = null;
        List<ProducerSpec> notUsedTransitive = Collections.emptyList();
        for (ProducerSpec producer : transitiveDeps) {
            if (featurePacks.containsKey(producer)) {
                continue;
            }
            if (cleanupTransitive && config.hasTransitiveDep(producer)) {
                if (newConfig == null) {
                    newConfig = ProvisioningConfig.builder(config);
                }
                newConfig.removeTransitiveDep(producer.getLocation().getFPID());
                continue;
            }
            notUsedTransitive = CollectionUtils.add(notUsedTransitive, producer);
        }
        if (!notUsedTransitive.isEmpty()) {
            throw new ProvisioningDescriptionException(Errors.transitiveDependencyNotFound(notUsedTransitive.toArray(new ProducerSpec[notUsedTransitive.size()])));
        }
        if (newConfig != null) {
            config = newConfig.build();
        }
        transitiveDeps = null;
    }
    if (resolvedVersions != null) {
        final ProvisioningConfig.Builder builder = ProvisioningConfig.builder().addOptions(config.getOptions()).initUniverses(config).initConfigs(config);
        addFpDeps(builder, config.getFeaturePackDeps());
        if (config.hasTransitiveDeps()) {
            addFpDeps(builder, config.getTransitiveDeps());
        }
        if (!resolvedVersions.isEmpty()) {
            for (FeaturePackLocation fpl : resolvedVersions.values()) {
                final FeaturePackConfig existing = builder.getTransitiveFeaturePackDep(fpl.getProducer());
                if (existing == null) {
                    builder.addTransitiveDep(fpl);
                } else if (!existing.getLocation().hasBuild()) {
                    builder.updateFeaturePackDep(FeaturePackConfig.builder(fpl).init(existing).build());
                }
            }
        }
        config = builder.build();
        resolvedVersions = null;
    }
    // apply patches
    if (!fpPatches.isEmpty()) {
        for (F f : ordered) {
            final List<F> patches = fpPatches.get(f.getFPID());
            if (patches == null) {
                if (f.getSpec().hasPlugins()) {
                    pluginLocations = CollectionUtils.putAll(pluginLocations, f.getSpec().getPlugins());
                }
                final Path fpResources = f.getDir().resolve(Constants.RESOURCES);
                if (Files.exists(fpResources)) {
                    patchDir(getResources(), fpResources);
                }
                final Path fpPlugins = f.getDir().resolve(Constants.PLUGINS);
                if (Files.exists(fpPlugins)) {
                    patchDir(getPluginsDir(), fpPlugins);
                }
                continue;
            }
            final Path fpDir = LayoutUtils.getFeaturePackDir(handle.getPatchedDir(), f.getFPID(), false);
            try {
                Files.createDirectories(fpDir);
                IoUtils.copy(f.getDir(), fpDir);
            } catch (IOException e) {
                throw new ProvisioningException("Failed to patch feature-pack dir for " + f.getFPID(), e);
            }
            f.dir = fpDir;
            for (F patch : patches) {
                final Path patchDir = patch.getDir();
                patchFpDir(fpDir, patchDir, Constants.PACKAGES);
                patchFpDir(fpDir, patchDir, Constants.FEATURES);
                patchFpDir(fpDir, patchDir, Constants.FEATURE_GROUPS);
                patchFpDir(fpDir, patchDir, Constants.CONFIGS);
                patchFpDir(fpDir, patchDir, Constants.LAYERS);
                Path patchContent = patchDir.resolve(Constants.PLUGINS);
                if (Files.exists(patchContent)) {
                    patchDir(fpDir.resolve(Constants.PLUGINS), patchContent);
                    patchDir(getPluginsDir(), patchContent);
                }
                patchContent = patchDir.resolve(Constants.RESOURCES);
                if (Files.exists(patchContent)) {
                    patchDir(fpDir.resolve(Constants.RESOURCES), patchContent);
                    patchDir(getResources(), patchContent);
                }
                if (patch.getSpec().hasPlugins()) {
                    pluginLocations = CollectionUtils.putAll(pluginLocations, patch.getSpec().getPlugins());
                }
            }
        }
    }
    if (!pluginLocations.isEmpty()) {
        handle.addPlugins(pluginLocations.values());
    }
    buildTracker.complete();
}
Also used : Path(java.nio.file.Path) FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ProducerSpec(org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) IOException(java.io.IOException) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ProvisioningException(org.jboss.galleon.ProvisioningException) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Aggregations

FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)23 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)14 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)11 ArrayList (java.util.ArrayList)8 ProvisioningException (org.jboss.galleon.ProvisioningException)8 IOException (java.io.IOException)5 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)5 Path (java.nio.file.Path)4 HashMap (java.util.HashMap)4 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)4 Table (org.jboss.galleon.cli.cmd.Table)4 FeaturePackLayout (org.jboss.galleon.layout.FeaturePackLayout)4 FeaturePackSpec (org.jboss.galleon.spec.FeaturePackSpec)4 ProducerSpec (org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec)4 HashSet (java.util.HashSet)3 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)3 Cell (org.jboss.galleon.cli.cmd.Table.Cell)3 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2