Search in sources :

Example 16 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class State method pushState.

private ProvisioningConfig pushState(Action action, PmSession pmSession) throws IOException, ProvisioningException {
    action.doAction(config, builder);
    try {
        ProvisioningConfig newConfig = buildNewConfig(pmSession);
        stack.push(action);
        return newConfig;
    } catch (Exception ex) {
        // ex.printStackTrace();
        try {
            action.undoAction(builder);
        } catch (Exception ex2) {
            ex.addSuppressed(ex2);
        }
        throw ex;
    }
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) IOException(java.io.IOException) ProvisioningException(org.jboss.galleon.ProvisioningException)

Example 17 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class FeaturePackLocationResolverTestCase method testResolutionLocalPathInstalled.

@Test
public void testResolutionLocalPathInstalled() throws Exception {
    FeaturePackLocation fpl = FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5#5.0.0.Final");
    MavenArtifact artifact = new MavenArtifact().setGroupId(FP_GROUP_ID).setArtifactId(PRODUCER1_FP_ARTIFACT_ID).setExtension("zip").setVersion("5.0.0.Final");
    FeaturePackCreator.getInstance().addArtifactResolver(repo).newFeaturePack().setFPID(fpl.getFPID()).getCreator().install();
    Path path = resolver.resolve(fpl);
    Assert.assertEquals(artifact.getArtifactFileName(), path.getFileName().toString());
    Path externalPath = repoHome.resolve("external").resolve(path.getFileName().toString());
    IoUtils.copy(path, externalPath);
    IoUtils.recursiveDelete(path);
    try {
        resolver.resolve(fpl);
        Assert.fail(String.format("The %s artifact is still installed in the local repository", artifact.getCoordsAsString()));
    } catch (ProvisioningException e) {
    // Expected exception
    }
    UniverseResolver resolver = UniverseResolver.builder().addArtifactResolver(repo).addLocalFeaturePack(externalPath).build();
    try {
        path = resolver.resolve(fpl);
        Assert.assertEquals(artifact.getArtifactFileName(), path.getFileName().toString());
    } catch (ProvisioningException e) {
        Assert.fail(String.format("Cannot resolve %s artifact using a resolved with a local feature pack location", artifact.getCoordsAsString()));
    }
}
Also used : Path(java.nio.file.Path) ProvisioningException(org.jboss.galleon.ProvisioningException) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) UniverseResolver(org.jboss.galleon.universe.UniverseResolver) MavenArtifact(org.jboss.galleon.universe.maven.MavenArtifact) Test(org.junit.Test)

Example 18 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class FeaturePackLocationResolverTestCase method testMain.

@Test
public void testMain() throws Exception {
    try {
        resolver.resolve(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5/alpha"));
        Assert.fail("Artifact does not exist");
    } catch (ProvisioningException e) {
        final MavenArtifact artifact = new MavenArtifact();
        artifact.setGroupId(FP_GROUP_ID);
        artifact.setArtifactId(PRODUCER1_FP_ARTIFACT_ID);
        artifact.setExtension("zip");
        artifact.setVersionRange("[5.0-alpha,6.0-alpha)");
        Assert.assertEquals(MavenErrors.artifactNotFound(artifact, repoHome).getLocalizedMessage(), e.getLocalizedMessage());
    }
    installFp(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5#5.1.0.Alpha1"));
    try {
        resolver.resolve(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5"));
        Assert.fail("No final releases yet");
    } catch (ProvisioningException e) {
    // ignore
    }
    MavenArtifact artifact = new MavenArtifact().setGroupId(FP_GROUP_ID).setArtifactId(PRODUCER1_FP_ARTIFACT_ID).setExtension("zip").setVersion("5.1.0.Alpha1");
    Path path = resolver.resolve(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5/alpha"));
    Assert.assertEquals(artifact.getArtifactFileName(), path.getFileName().toString());
    installFp(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):4#4.1.0.Beta2"));
    path = resolver.resolve(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5/alpha"));
    Assert.assertEquals(artifact.getArtifactFileName(), path.getFileName().toString());
    installFp(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5#5.2.0.Final"));
    artifact.setVersion("5.2.0.Final");
    path = resolver.resolve(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5/alpha"));
    Assert.assertEquals(artifact.getArtifactFileName(), path.getFileName().toString());
    path = resolver.resolve(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5"));
    Assert.assertEquals(artifact.getArtifactFileName(), path.getFileName().toString());
    installFp(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5#5.2.1.Beta1"));
    artifact.setVersion("5.2.1.Beta1");
    path = resolver.resolve(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5/alpha"));
    Assert.assertEquals(artifact.getArtifactFileName(), path.getFileName().toString());
    path = resolver.resolve(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5/beta"));
    Assert.assertEquals(artifact.getArtifactFileName(), path.getFileName().toString());
    path = resolver.resolve(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5"));
    artifact.setVersion("5.2.0.Final");
    Assert.assertEquals(artifact.getArtifactFileName(), path.getFileName().toString());
    installFp(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):6#6.0.0.Alpha1"));
    path = resolver.resolve(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5"));
    Assert.assertEquals(artifact.getArtifactFileName(), path.getFileName().toString());
    path = resolver.resolve(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5/alpha"));
    artifact.setVersion("5.2.1.Beta1");
    Assert.assertEquals(artifact.getArtifactFileName(), path.getFileName().toString());
    installFp(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):6#6.0.0.Final"));
    path = resolver.resolve(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5"));
    artifact.setVersion("5.2.0.Final");
    Assert.assertEquals(artifact.getArtifactFileName(), path.getFileName().toString());
    artifact.setVersion("5.1.0.Alpha1");
    path = resolver.resolve(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5#5.1.0.Alpha1"));
    Assert.assertEquals(artifact.getArtifactFileName(), path.getFileName().toString());
    artifact.setVersion("4.1.0.Beta2");
    path = resolver.resolve(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + '(' + universeArt.getCoordsAsString() + "):5#4.1.0.Beta2"));
    Assert.assertEquals(artifact.getArtifactFileName(), path.getFileName().toString());
}
Also used : Path(java.nio.file.Path) ProvisioningException(org.jboss.galleon.ProvisioningException) MavenArtifact(org.jboss.galleon.universe.maven.MavenArtifact) Test(org.junit.Test)

Example 19 with ProvisioningException

use of org.jboss.galleon.ProvisioningException 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 20 with ProvisioningException

use of org.jboss.galleon.ProvisioningException 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

ProvisioningException (org.jboss.galleon.ProvisioningException)101 IOException (java.io.IOException)45 Path (java.nio.file.Path)35 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)24 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)15 XMLStreamException (javax.xml.stream.XMLStreamException)13 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)10 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)10 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)9 ProvisioningManager (org.jboss.galleon.ProvisioningManager)9 BufferedReader (java.io.BufferedReader)8 HashMap (java.util.HashMap)8 ConfigId (org.jboss.galleon.config.ConfigId)8 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)8 ProducerSpec (org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 Map (java.util.Map)7 FeatureContainerPathConsumer (org.jboss.galleon.cli.path.FeatureContainerPathConsumer)7 BufferedWriter (java.io.BufferedWriter)6