From 43922c001bb3674e9c3cee1d336b833e4bf5c59f Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Fri, 1 Feb 2019 10:36:03 +0100 Subject: [PATCH] [GAL-240] an option to not record provisioning state in .galleon dir --- .../cli/cmd/maingrp/InstallCommand.java | 12 +- .../jboss/galleon/ProvisioningManager.java | 99 ++++++++++++---- .../galleon/config/ConfigCustomizations.java | 2 +- .../galleon/config/FeaturePackConfig.java | 11 +- .../galleon/config/FeaturePackDepsConfig.java | 23 +++- .../jboss/galleon/config/PackageConfig.java | 7 +- .../galleon/config/ProvisioningConfig.java | 21 +--- .../galleon/runtime/ProvisioningRuntime.java | 26 +++-- .../runtime/ProvisioningRuntimeBuilder.java | 6 + .../org/jboss/galleon/util/PathsUtils.java | 22 ---- .../galleon/test/FeaturePackRepoTestBase.java | 12 +- .../org/jboss/galleon/test/PmTestBase.java | 43 +++++-- .../maven/plugin/FeaturePackInstallMojo.java | 8 +- .../maven/plugin/ProvisionStateMojo.java | 14 ++- .../plugin/util/FeaturePackInstaller.java | 9 +- ...tatePersistenceOnFreshInstallTestCase.java | 75 ++++++++++++ ...ipStatePersistenceOnReinstallTestCase.java | 107 ++++++++++++++++++ 17 files changed, 402 insertions(+), 95 deletions(-) create mode 100644 testsuite/src/test/java/org/jboss/galleon/state/test/SkipStatePersistenceOnFreshInstallTestCase.java create mode 100644 testsuite/src/test/java/org/jboss/galleon/state/test/SkipStatePersistenceOnReinstallTestCase.java diff --git a/cli/src/main/java/org/jboss/galleon/cli/cmd/maingrp/InstallCommand.java b/cli/src/main/java/org/jboss/galleon/cli/cmd/maingrp/InstallCommand.java index af2003f90..c7d694a21 100644 --- a/cli/src/main/java/org/jboss/galleon/cli/cmd/maingrp/InstallCommand.java +++ b/cli/src/main/java/org/jboss/galleon/cli/cmd/maingrp/InstallCommand.java @@ -206,12 +206,14 @@ protected void runCommand(PmCommandInvocation session, Map optio model, config, loc).build(), options); } - if (!loc.hasBuild()) { - loc = getManager(session).getProvisioningConfig().getFeaturePackDep(loc.getProducer()).getLocation(); - } session.println("Feature pack installed."); - StateInfoUtil.printFeaturePack(session, - session.getPmSession().getExposedLocation(manager.getInstallationHome(), loc)); + if(manager.isRecordState()) { + if (!loc.hasBuild()) { + loc = manager.getProvisioningConfig().getFeaturePackDep(loc.getProducer()).getLocation(); + } + StateInfoUtil.printFeaturePack(session, + session.getPmSession().getExposedLocation(manager.getInstallationHome(), loc)); + } } catch (ProvisioningException | IOException ex) { throw new CommandExecutionException(session.getPmSession(), CliErrors.installFailed(), ex); } diff --git a/core/src/main/java/org/jboss/galleon/ProvisioningManager.java b/core/src/main/java/org/jboss/galleon/ProvisioningManager.java index 3d24fca75..7334600a0 100644 --- a/core/src/main/java/org/jboss/galleon/ProvisioningManager.java +++ b/core/src/main/java/org/jboss/galleon/ProvisioningManager.java @@ -72,6 +72,7 @@ public static class Builder extends UniverseResolverBuilder { private MessageWriter messageWriter; private UniverseResolver resolver; private boolean logTime; + private boolean recordState = true; private Builder() { } @@ -129,6 +130,11 @@ public Builder setLogTime(boolean logTime) { return this; } + public Builder setRecordState(boolean recordState) { + this.recordState = recordState; + return this; + } + public ProvisioningManager build() throws ProvisioningException { return new ProvisioningManager(this); } @@ -151,6 +157,7 @@ public static Builder builder() { private ProvisioningLayoutFactory layoutFactory; private boolean closeLayoutFactory; private ProvisioningConfig provisioningConfig; + private boolean recordState; private ProvisioningManager(Builder builder) throws ProvisioningException { PathsUtils.assertInstallationDir(builder.installationHome); @@ -165,6 +172,7 @@ private ProvisioningManager(Builder builder) throws ProvisioningException { universeResolver = builder.getUniverseResolver(); } this.logTime = builder.logTime; + this.recordState = builder.recordState; } /** @@ -207,6 +215,19 @@ public void setLogTime(boolean logTime) { this.logTime = logTime; } + /** + * Whether provisioning state will be recorded after (re-)provisioning. + * + * @return true if the provisioning state is recorded after provisioning, otherwise false + */ + public boolean isRecordState() { + return recordState; + } + + public void setRecordState(boolean recordState) { + this.recordState = recordState; + } + /** * Add named universe spec to the provisioning configuration * @@ -619,7 +640,8 @@ private ProvisioningRuntime getRuntimeInternal(ProvisioningLayout layout, F final boolean freshInstall = PathsUtils.isNewHome(home); try (ProvisioningRuntime runtime = getRuntimeInternal(layout, fsDiff, freshInstall)) { runtime.provision(); - if (runtime.getProvisioningConfig().hasFeaturePackDeps()) { - persistHashes(runtime); - } - if (undo) { - final Map undoTasks = StateHistoryUtils.readUndoTasks(home, log); - if (!undoTasks.isEmpty()) { - final Path staged = runtime.getStagedDir(); - for (Map.Entry entry : undoTasks.entrySet()) { - final Path stagedPath = staged.resolve(entry.getKey()); - if (entry.getValue()) { - final Path homePath = home.resolve(entry.getKey()); - if (Files.exists(homePath)) { - try { - IoUtils.copy(homePath, stagedPath); - } catch (IOException e) { - throw new ProvisioningException(Errors.copyFile(homePath, stagedPath), e); + if(recordState) { + if (runtime.getProvisioningConfig().hasFeaturePackDeps()) { + persistHashes(runtime); + } + if (undo) { + final Map undoTasks = StateHistoryUtils.readUndoTasks(home, log); + if (!undoTasks.isEmpty()) { + final Path staged = runtime.getStagedDir(); + for (Map.Entry entry : undoTasks.entrySet()) { + final Path stagedPath = staged.resolve(entry.getKey()); + if (entry.getValue()) { + final Path homePath = home.resolve(entry.getKey()); + if (Files.exists(homePath)) { + try { + IoUtils.copy(homePath, stagedPath); + } catch (IOException e) { + throw new ProvisioningException(Errors.copyFile(homePath, stagedPath), e); + } } + } else { + IoUtils.recursiveDelete(stagedPath); } - } else { - IoUtils.recursiveDelete(stagedPath); } } } @@ -658,8 +682,41 @@ private void doProvision(ProvisioningLayout layout, F if (fsDiff != null && !fsDiff.isEmpty()) { undoTasks = FsDiff.replay(fsDiff, runtime.getStagedDir(), log); } - if(!freshInstall) { - PathsUtils.replaceDist(runtime.getStagedDir(), home, undo, undoTasks, log); + + if(freshInstall) { + return; + } + + log.verbose("Moving the provisioned installation from the staged directory to %s", home); + final Path stagedDir = runtime.getStagedDir(); + // copy from the staged to the target installation directory + if (Files.exists(home)) { + if (recordState) { + if (undo) { + StateHistoryUtils.removeLastUndoConfig(home, stagedDir, log); + } else { + StateHistoryUtils.addNewUndoConfig(home, stagedDir, undoTasks, log); + } + IoUtils.recursiveDelete(home); + } else if(Files.exists(PathsUtils.getProvisionedStateDir(home))) { + try(DirectoryStream stream = Files.newDirectoryStream(home)) { + for(Path p : stream) { + if(p.getFileName().toString().equals(Constants.PROVISIONED_STATE_DIR)) { + continue; + } + IoUtils.recursiveDelete(p); + } + } catch (IOException e) { + throw new ProvisioningException(Errors.readDirectory(home), e); + } + } else { + IoUtils.recursiveDelete(home); + } + } + try { + IoUtils.copy(stagedDir, home); + } catch (IOException e) { + throw new ProvisioningException(Errors.copyFile(stagedDir, home)); } } finally { this.provisioningConfig = null; diff --git a/core/src/main/java/org/jboss/galleon/config/ConfigCustomizations.java b/core/src/main/java/org/jboss/galleon/config/ConfigCustomizations.java index f4b245e03..b5f32681d 100644 --- a/core/src/main/java/org/jboss/galleon/config/ConfigCustomizations.java +++ b/core/src/main/java/org/jboss/galleon/config/ConfigCustomizations.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 Red Hat, Inc. and/or its affiliates + * Copyright 2016-2019 Red Hat, Inc. and/or its affiliates * and other contributors as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/core/src/main/java/org/jboss/galleon/config/FeaturePackConfig.java b/core/src/main/java/org/jboss/galleon/config/FeaturePackConfig.java index 930dcfc4e..b1fa4c1c4 100644 --- a/core/src/main/java/org/jboss/galleon/config/FeaturePackConfig.java +++ b/core/src/main/java/org/jboss/galleon/config/FeaturePackConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 Red Hat, Inc. and/or its affiliates + * Copyright 2016-2019 Red Hat, Inc. and/or its affiliates * and other contributors as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -383,8 +383,13 @@ public String toString() { } buf.append(fpl.toString()); if(!patches.isEmpty()) { - buf.append(" patches="); - StringUtils.append(buf, patches); + StringUtils.append(buf.append(" patches="), patches); + } + if(!excludedPackages.isEmpty()) { + StringUtils.append(buf.append(" excludedPackages="), excludedPackages); + } + if(!includedPackages.isEmpty()) { + StringUtils.append(buf.append(" includedPackages="), includedPackages.values()); } append(buf); return buf.append(']').toString(); diff --git a/core/src/main/java/org/jboss/galleon/config/FeaturePackDepsConfig.java b/core/src/main/java/org/jboss/galleon/config/FeaturePackDepsConfig.java index 5645e6235..6261712ae 100644 --- a/core/src/main/java/org/jboss/galleon/config/FeaturePackDepsConfig.java +++ b/core/src/main/java/org/jboss/galleon/config/FeaturePackDepsConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 Red Hat, Inc. and/or its affiliates + * Copyright 2016-2019 Red Hat, Inc. and/or its affiliates * and other contributors as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,6 +27,7 @@ import org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec; import org.jboss.galleon.universe.UniverseSpec; import org.jboss.galleon.util.CollectionUtils; +import org.jboss.galleon.util.StringUtils; /** * @@ -203,4 +204,24 @@ public boolean equals(Object obj) { return false; return true; } + + protected void append(StringBuilder buf) { + if(defaultUniverse != null) { + buf.append("default-universe=").append(defaultUniverse); + } + if(!universeSpecs.isEmpty()) { + if(defaultUniverse != null) { + buf.append(' '); + } + buf.append("universes=["); + StringUtils.append(buf, universeSpecs.entrySet()); + buf.append("] "); + } + if(!transitiveDeps.isEmpty()) { + StringUtils.append(buf.append("transitive="), transitiveDeps.values()); + buf.append(' '); + } + StringUtils.append(buf, fpDeps.values()); + super.append(buf); + } } diff --git a/core/src/main/java/org/jboss/galleon/config/PackageConfig.java b/core/src/main/java/org/jboss/galleon/config/PackageConfig.java index c3c5ff166..e7ee4eb09 100644 --- a/core/src/main/java/org/jboss/galleon/config/PackageConfig.java +++ b/core/src/main/java/org/jboss/galleon/config/PackageConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 Red Hat, Inc. and/or its affiliates + * Copyright 2016-2019 Red Hat, Inc. and/or its affiliates * and other contributors as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -61,4 +61,9 @@ public boolean equals(Object obj) { return false; return true; } + + @Override + public String toString() { + return name; + } } diff --git a/core/src/main/java/org/jboss/galleon/config/ProvisioningConfig.java b/core/src/main/java/org/jboss/galleon/config/ProvisioningConfig.java index 200b1f798..a2fa8be59 100644 --- a/core/src/main/java/org/jboss/galleon/config/ProvisioningConfig.java +++ b/core/src/main/java/org/jboss/galleon/config/ProvisioningConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 Red Hat, Inc. and/or its affiliates + * Copyright 2016-2019 Red Hat, Inc. and/or its affiliates * and other contributors as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -176,28 +176,11 @@ public boolean equals(Object obj) { @Override public String toString() { final StringBuilder buf = new StringBuilder().append('['); - if(defaultUniverse != null) { - buf.append("default-universe=").append(defaultUniverse); - } - if(!universeSpecs.isEmpty()) { - if(defaultUniverse != null) { - buf.append(' '); - } - buf.append("universes=["); - StringUtils.append(buf, universeSpecs.entrySet()); - buf.append("] "); - } + append(buf); if(!options.isEmpty()) { buf.append("options="); StringUtils.append(buf, options.entrySet()); } - if(!transitiveDeps.isEmpty()) { - buf.append("transitive="); - StringUtils.append(buf, transitiveDeps.values()); - buf.append(' '); - } - StringUtils.append(buf, fpDeps.values()); - append(buf); return buf.append(']').toString(); } } diff --git a/core/src/main/java/org/jboss/galleon/runtime/ProvisioningRuntime.java b/core/src/main/java/org/jboss/galleon/runtime/ProvisioningRuntime.java index 8619ac361..674936083 100644 --- a/core/src/main/java/org/jboss/galleon/runtime/ProvisioningRuntime.java +++ b/core/src/main/java/org/jboss/galleon/runtime/ProvisioningRuntime.java @@ -64,6 +64,7 @@ public class ProvisioningRuntime implements FeaturePackSet, private final ProvisioningLayout layout; private final MessageWriter messageWriter; private Boolean emptyStagedDir; + private final boolean recordState; private List configs = Collections.emptyList(); ProvisioningRuntime(final ProvisioningRuntimeBuilder builder, final MessageWriter messageWriter) throws ProvisioningException { @@ -99,6 +100,7 @@ public FeaturePackRuntime transform(FeaturePackRuntimeBuilder other) throws Prov throw e; } + this.recordState = builder.recordState; this.messageWriter = messageWriter; } @@ -306,18 +308,20 @@ public void visitPlugin(InstallPlugin plugin) throws ProvisioningException { } }, InstallPlugin.class); - // save the config - try { - ProvisioningXmlWriter.getInstance().write(config, PathsUtils.getProvisioningXml(stagedDir)); - } catch (XMLStreamException | IOException e) { - throw new FeaturePackInstallException(Errors.writeFile(PathsUtils.getProvisioningXml(stagedDir)), e); - } + if(recordState) { + // save the config + try { + ProvisioningXmlWriter.getInstance().write(config, PathsUtils.getProvisioningXml(stagedDir)); + } catch (XMLStreamException | IOException e) { + throw new FeaturePackInstallException(Errors.writeFile(PathsUtils.getProvisioningXml(stagedDir)), e); + } - // save the provisioned state - try { - ProvisionedStateXmlWriter.getInstance().write(this, PathsUtils.getProvisionedStateXml(stagedDir)); - } catch (XMLStreamException | IOException e) { - throw new FeaturePackInstallException(Errors.writeFile(PathsUtils.getProvisionedStateXml(stagedDir)), e); + // save the provisioned state + try { + ProvisionedStateXmlWriter.getInstance().write(this, PathsUtils.getProvisionedStateXml(stagedDir)); + } catch (XMLStreamException | IOException e) { + throw new FeaturePackInstallException(Errors.writeFile(PathsUtils.getProvisionedStateXml(stagedDir)), e); + } } emptyStagedDir = null; diff --git a/core/src/main/java/org/jboss/galleon/runtime/ProvisioningRuntimeBuilder.java b/core/src/main/java/org/jboss/galleon/runtime/ProvisioningRuntimeBuilder.java index d857faf01..4c998feaf 100644 --- a/core/src/main/java/org/jboss/galleon/runtime/ProvisioningRuntimeBuilder.java +++ b/core/src/main/java/org/jboss/galleon/runtime/ProvisioningRuntimeBuilder.java @@ -89,6 +89,7 @@ public static ProvisioningRuntimeBuilder newInstance(final MessageWriter message ProvisioningConfig config; ProvisioningLayout layout; Path stagedDir; + boolean recordState; FsDiff fsDiff; private final MessageWriter messageWriter; @@ -153,6 +154,11 @@ public ProvisioningRuntimeBuilder setStagedDir(Path p) { return this; } + public ProvisioningRuntimeBuilder setRecordState(boolean recordState) { + this.recordState = recordState; + return this; + } + public ProvisioningRuntime build() throws ProvisioningException { try { return doBuild(); diff --git a/core/src/main/java/org/jboss/galleon/util/PathsUtils.java b/core/src/main/java/org/jboss/galleon/util/PathsUtils.java index 19015d6f0..73ac626de 100644 --- a/core/src/main/java/org/jboss/galleon/util/PathsUtils.java +++ b/core/src/main/java/org/jboss/galleon/util/PathsUtils.java @@ -22,11 +22,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Iterator; -import java.util.Map; - import org.jboss.galleon.Constants; import org.jboss.galleon.Errors; -import org.jboss.galleon.MessageWriter; import org.jboss.galleon.ProvisioningException; /** @@ -101,23 +98,4 @@ public static String toForwardSlashSeparator(String path) { } return path.replace(File.separatorChar, '/'); } - - public static void replaceDist(Path stagedDir, Path home, boolean asUndo, Map undoTasks, MessageWriter log) throws ProvisioningException { - log.verbose("Moving the provisioned installation from the staged directory to %s", home); - - // copy from the staged to the target installation directory - if (Files.exists(home)) { - if(asUndo) { - StateHistoryUtils.removeLastUndoConfig(home, stagedDir, log); - } else { - StateHistoryUtils.addNewUndoConfig(home, stagedDir, undoTasks, log); - } - IoUtils.recursiveDelete(home); - } - try { - IoUtils.copy(stagedDir, home); - } catch (IOException e) { - throw new ProvisioningException(Errors.copyFile(stagedDir, home)); - } - } } diff --git a/core/src/test/java/org/jboss/galleon/test/FeaturePackRepoTestBase.java b/core/src/test/java/org/jboss/galleon/test/FeaturePackRepoTestBase.java index ae61b0639..db30c310d 100644 --- a/core/src/test/java/org/jboss/galleon/test/FeaturePackRepoTestBase.java +++ b/core/src/test/java/org/jboss/galleon/test/FeaturePackRepoTestBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 Red Hat, Inc. and/or its affiliates + * Copyright 2016-2019 Red Hat, Inc. and/or its affiliates * and other contributors as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -46,6 +46,7 @@ public class FeaturePackRepoTestBase { private Path tmpDir; protected RepositoryArtifactResolver repo; protected FeaturePackCreator creator; + private boolean recordState = true; @Before public void before() throws Exception { @@ -68,6 +69,14 @@ public void after() throws Exception { protected void doAfter() throws Exception { } + protected void setRecordState(boolean recordState) { + this.recordState = recordState; + } + + protected boolean isRecordState() { + return recordState; + } + protected RepositoryArtifactResolver initRepoManager(Path repoHome) { return LegacyGalleon1RepositoryManager.newInstance(repoHome); } @@ -80,6 +89,7 @@ protected ProvisioningManager getPm() throws ProvisioningException { return ProvisioningManager.builder() .addArtifactResolver(repo) .setInstallationHome(installHome) + .setRecordState(recordState) .build(); } diff --git a/core/src/test/java/org/jboss/galleon/test/PmTestBase.java b/core/src/test/java/org/jboss/galleon/test/PmTestBase.java index af758c648..305580a49 100644 --- a/core/src/test/java/org/jboss/galleon/test/PmTestBase.java +++ b/core/src/test/java/org/jboss/galleon/test/PmTestBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 Red Hat, Inc. and/or its affiliates + * Copyright 2016-2019 Red Hat, Inc. and/or its affiliates * and other contributors as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +16,9 @@ */ package org.jboss.galleon.test; +import static org.junit.Assert.fail; + +import java.nio.file.Files; import java.util.Arrays; import org.jboss.galleon.Constants; @@ -78,7 +81,11 @@ protected void doBefore() throws Exception { } protected DirBuilder newDirBuilder() { - return DirState.rootBuilder().skip(Constants.PROVISIONED_STATE_DIR); + final DirBuilder builder = DirState.rootBuilder(); + if(isRecordState() || initialProvisioningConfig != null) { + builder.skip(Constants.PROVISIONED_STATE_DIR); + } + return builder; } protected String[] pmErrors() throws ProvisioningException { @@ -97,8 +104,17 @@ public void main() throws Throwable { if(errors != null) { Assert.fail("Expected failures: " + Arrays.asList(errors)); } - assertProvisionedConfig(pm); - assertProvisionedState(pm); + if(isRecordState()) { + assertProvisionedConfig(pm); + assertProvisionedState(pm); + } else if(initialProvisioningConfig != null) { + pm.close(); + pm = getPm(); + assertProvisionedConfig(pm); + assertProvisionedState(pm); + } else { + assertNoState(); + } } catch(AssertionError e) { throw e; } catch(Throwable t) { @@ -109,8 +125,15 @@ public void main() throws Throwable { assertErrors(t, errors); } if(pm != null) { - assertProvisioningConfig(pm, initialProvisioningConfig); - assertProvisionedState(pm, initialProvisionedState); + if(isRecordState()) { + assertProvisioningConfig(pm, initialProvisioningConfig); + assertProvisionedState(pm, initialProvisionedState); + } else if(initialProvisioningConfig != null) { + pm.close(); + pm = getPm(); + assertProvisioningConfig(pm, initialProvisioningConfig); + assertProvisionedState(pm, initialProvisionedState); + } } } finally { if(pm != null) { @@ -126,7 +149,7 @@ public void main() throws Throwable { if(failed || initialProvisioningConfig != null) { expectedHomeDir = initialHomeDirState; } else { - expectedHomeDir = DirState.rootBuilder().skip(Constants.PROVISIONED_STATE_DIR).build(); + expectedHomeDir = newDirBuilder().build(); } } expectedHomeDir.assertState(installHome); @@ -148,6 +171,12 @@ protected void assertProvisionedConfig(final ProvisioningManager pm) throws Prov assertProvisioningConfig(pm, provisionedConfig()); } + protected void assertNoState() throws ProvisioningException { + if(Files.exists(installHome.resolve(Constants.PROVISIONED_STATE_DIR))) { + fail("Unexpected provisioning state " + installHome.resolve(Constants.PROVISIONED_STATE_DIR)); + } + } + protected void assertErrors(Throwable t, String... msgs) { int i = 0; if(msgs != null) { diff --git a/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/FeaturePackInstallMojo.java b/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/FeaturePackInstallMojo.java index 44942523b..b274fad02 100644 --- a/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/FeaturePackInstallMojo.java +++ b/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/FeaturePackInstallMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 Red Hat, Inc. and/or its affiliates + * Copyright 2016-2019 Red Hat, Inc. and/or its affiliates * and other contributors as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -136,6 +136,12 @@ public class FeaturePackInstallMojo extends AbstractMojo { @Parameter(alias = "plugin-options", required = false) private Map pluginOptions = Collections.emptyMap(); + /** + * Whether to record provisioned state in .galleon directory. + */ + @Parameter(alias = "record-state", defaultValue = "true") + private boolean recordState = true; + @Override public void execute() throws MojoExecutionException, MojoFailureException { diff --git a/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/ProvisionStateMojo.java b/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/ProvisionStateMojo.java index 744ea60b2..6310621ed 100644 --- a/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/ProvisionStateMojo.java +++ b/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/ProvisionStateMojo.java @@ -58,6 +58,7 @@ import org.jboss.galleon.universe.maven.MavenArtifact; import org.jboss.galleon.universe.maven.MavenUniverseException; import org.jboss.galleon.universe.maven.repo.MavenRepoManager; +import org.jboss.galleon.util.IoUtils; import org.jboss.galleon.xml.ConfigXmlParser; /** @@ -134,6 +135,12 @@ public class ProvisionStateMojo extends AbstractMojo { @Parameter(alias = "log-time", defaultValue = "false") private boolean logTime; + /** + * Whether to record provisioned state in .galleon directory. + */ + @Parameter(alias = "record-state", defaultValue = "true") + private boolean recordState = true; + /** * A list of artifacts and paths pointing to feature-pack archives that should be resolved locally without * involving the universe-based feature-pack resolver at provisioning time. @@ -168,10 +175,15 @@ private void doProvision() throws MojoExecutionException, ProvisioningException final RepositoryArtifactResolver artifactResolver = offline ? new MavenArtifactRepositoryManager(repoSystem, repoSession) : new MavenArtifactRepositoryManager(repoSystem, repoSession, repositories); + final Path home = installDir.toPath(); + if(!recordState) { + IoUtils.recursiveDelete(home); + } try (ProvisioningManager pm = ProvisioningManager.builder().addArtifactResolver(artifactResolver) - .setInstallationHome(installDir.toPath()) + .setInstallationHome(home) .setMessageWriter(new DefaultMessageWriter(System.out, System.err, getLog().isDebugEnabled())) .setLogTime(logTime) + .setRecordState(recordState) .build()) { for (FeaturePack fp : featurePacks) { diff --git a/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/util/FeaturePackInstaller.java b/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/util/FeaturePackInstaller.java index d5a583fc4..298fcb7cd 100644 --- a/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/util/FeaturePackInstaller.java +++ b/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/util/FeaturePackInstaller.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 Red Hat, Inc. and/or its affiliates + * Copyright 2016-2019 Red Hat, Inc. and/or its affiliates * and other contributors as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -57,6 +57,7 @@ public static FeaturePackInstaller newInstance(Path repoHome, Path installationD private List includedPackages = Collections.emptyList(); private List excludedPackages = Collections.emptyList(); private Map pluginOptions = Collections.emptyMap(); + private boolean recordState = true; private FeaturePackInstaller(Path repoHome, Path installationDir) { this.repoHome = repoHome; @@ -132,10 +133,16 @@ public FeaturePackInstaller setPluginOptions(Map options) { return this; } + public FeaturePackInstaller setRecordState(boolean recordState) { + this.recordState = recordState; + return this; + } + public void install() { try(ProvisioningManager manager = ProvisioningManager.builder() .addArtifactResolver(LegacyGalleon1RepositoryManager.newInstance(repoHome)) .setInstallationHome(installationDir) + .setRecordState(recordState) .build()) { System.setProperty("org.wildfly.logging.skipLogManagerCheck", "true"); ConfigModel config = null; diff --git a/testsuite/src/test/java/org/jboss/galleon/state/test/SkipStatePersistenceOnFreshInstallTestCase.java b/testsuite/src/test/java/org/jboss/galleon/state/test/SkipStatePersistenceOnFreshInstallTestCase.java new file mode 100644 index 000000000..74c677f0a --- /dev/null +++ b/testsuite/src/test/java/org/jboss/galleon/state/test/SkipStatePersistenceOnFreshInstallTestCase.java @@ -0,0 +1,75 @@ +/* + * Copyright 2016-2019 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.galleon.state.test; + +import org.jboss.galleon.ProvisioningException; +import org.jboss.galleon.config.FeaturePackConfig; +import org.jboss.galleon.config.ProvisioningConfig; +import org.jboss.galleon.creator.FeaturePackCreator; +import org.jboss.galleon.test.util.fs.state.DirState; +import org.jboss.galleon.universe.FeaturePackLocation; +import org.jboss.galleon.universe.MvnUniverse; +import org.jboss.galleon.universe.ProvisionFromUniverseTestBase; + +/** + * + * @author Alexey Loubyansky + */ +public class SkipStatePersistenceOnFreshInstallTestCase extends ProvisionFromUniverseTestBase { + + private FeaturePackLocation prod1; + + @Override + protected void doBefore() throws Exception { + super.doBefore(); + setRecordState(false); + } + + @Override + protected void createProducers(MvnUniverse universe) throws ProvisioningException { + universe.createProducer("prod1"); + } + + @Override + protected void createFeaturePacks(FeaturePackCreator creator) throws ProvisioningException { + + prod1 = newFpl("prod1", "1", "1.0.0.Final"); + + creator.newFeaturePack() + .setFPID(prod1.getFPID()) + .newPackage("p1", true) + .writeContent("p1.txt", "p1 package"); + + creator.install(); + } + + @Override + protected ProvisioningConfig provisioningConfig() throws ProvisioningException { + return ProvisioningConfig.builder() + .addFeaturePackDep(FeaturePackConfig.builder(prod1) + .build()) + .build(); + } + + @Override + protected DirState provisionedHomeDir() { + return newDirBuilder() + .addFile("p1.txt", "p1 package") + .build(); + } +} \ No newline at end of file diff --git a/testsuite/src/test/java/org/jboss/galleon/state/test/SkipStatePersistenceOnReinstallTestCase.java b/testsuite/src/test/java/org/jboss/galleon/state/test/SkipStatePersistenceOnReinstallTestCase.java new file mode 100644 index 000000000..e9acf2be4 --- /dev/null +++ b/testsuite/src/test/java/org/jboss/galleon/state/test/SkipStatePersistenceOnReinstallTestCase.java @@ -0,0 +1,107 @@ +/* + * Copyright 2016-2019 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.galleon.state.test; + +import org.jboss.galleon.ProvisioningException; +import org.jboss.galleon.config.FeaturePackConfig; +import org.jboss.galleon.config.ProvisioningConfig; +import org.jboss.galleon.creator.FeaturePackCreator; +import org.jboss.galleon.state.ProvisionedFeaturePack; +import org.jboss.galleon.state.ProvisionedState; +import org.jboss.galleon.test.util.fs.state.DirState; +import org.jboss.galleon.universe.FeaturePackLocation; +import org.jboss.galleon.universe.MvnUniverse; +import org.jboss.galleon.universe.ProvisionFromUniverseTestBase; + +/** + * + * @author Alexey Loubyansky + */ +public class SkipStatePersistenceOnReinstallTestCase extends ProvisionFromUniverseTestBase { + + private FeaturePackLocation prod1; + + @Override + protected void createProducers(MvnUniverse universe) throws ProvisioningException { + universe.createProducer("prod1"); + } + + @Override + protected void createFeaturePacks(FeaturePackCreator creator) throws ProvisioningException { + + prod1 = newFpl("prod1", "1", "1.0.0.Final"); + + creator.newFeaturePack() + .setFPID(prod1.getFPID()) + .newPackage("p1", true) + .writeContent("p1.txt", "p1 package") + .getFeaturePack() + .newPackage("p2") + .writeContent("p2.txt", "p2 package"); + + creator.install(); + } + + @Override + protected void doBefore() throws Exception { + super.doBefore(); + setRecordState(false); + } + + @Override + protected ProvisioningConfig initialState() throws ProvisioningException { + return ProvisioningConfig.builder() + .addFeaturePackDep(FeaturePackConfig.builder(prod1) + .build()) + .build(); + } + + @Override + protected ProvisioningConfig provisioningConfig() throws ProvisioningException { + return ProvisioningConfig.builder() + .addFeaturePackDep(FeaturePackConfig.builder(prod1) + .excludePackage("p1") + .includePackage("p2") + .build()) + .build(); + } + + @Override + protected ProvisioningConfig provisionedConfig() throws ProvisioningException { + return ProvisioningConfig.builder() + .addFeaturePackDep(FeaturePackConfig.builder(prod1) + .build()) + .build(); + } + + @Override + protected ProvisionedState provisionedState() throws ProvisioningException { + return ProvisionedState.builder() + .addFeaturePack(ProvisionedFeaturePack.builder(prod1.getFPID()) + .addPackage("p1") + .build()) + .build(); + } + + @Override + protected DirState provisionedHomeDir() { + return newDirBuilder() + .addFile("p2.txt", "p2 package") + .build(); + } +} \ No newline at end of file