From d8f1db56f311544a009b85fed5488ef7b266f58b Mon Sep 17 00:00:00 2001 From: Jean-Francois Denise Date: Tue, 5 Dec 2023 15:58:07 +0100 Subject: [PATCH] Remove legacy patching --- .../bootablejar/BootableJarSupport.java | 30 -- .../goals/AbstractBuildBootableJarMojo.java | 60 --- tests/pom.xml | 30 -- .../maven/goals/PatchAddModuleTestCase.java | 75 --- .../maven/goals/PatchCPCleanupTestCase.java | 76 ---- .../maven/goals/PatchCPTestCase.java | 180 -------- .../goals/PatchExistingMiscTestCase.java | 56 --- .../goals/PatchExistingModuleTestCase.java | 88 ---- .../PatchUnexistingFailMiscTestCase.java | 55 --- .../PatchUnexistingFailModuleTestCase.java | 81 ---- .../goals/PatchUnexistingMiscTestCase.java | 59 --- .../goals/PatchUnexistingModuleTestCase.java | 83 ---- .../patching/ContentModificationUtils.java | 108 ----- .../plugins/bootablejar/patching/Module.java | 246 ---------- .../patching/PatchingTestUtil.java | 430 ------------------ .../bootablejar/patching/ResourceItem.java | 28 -- 16 files changed, 1685 deletions(-) delete mode 100644 tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchAddModuleTestCase.java delete mode 100644 tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchCPCleanupTestCase.java delete mode 100644 tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchCPTestCase.java delete mode 100644 tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchExistingMiscTestCase.java delete mode 100644 tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchExistingModuleTestCase.java delete mode 100644 tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchUnexistingFailMiscTestCase.java delete mode 100644 tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchUnexistingFailModuleTestCase.java delete mode 100644 tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchUnexistingMiscTestCase.java delete mode 100644 tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchUnexistingModuleTestCase.java delete mode 100644 tests/src/test/java/org/wildfly/plugins/bootablejar/patching/ContentModificationUtils.java delete mode 100644 tests/src/test/java/org/wildfly/plugins/bootablejar/patching/Module.java delete mode 100644 tests/src/test/java/org/wildfly/plugins/bootablejar/patching/PatchingTestUtil.java delete mode 100644 tests/src/test/java/org/wildfly/plugins/bootablejar/patching/ResourceItem.java diff --git a/core/src/main/java/org/wildfly/plugins/bootablejar/BootableJarSupport.java b/core/src/main/java/org/wildfly/plugins/bootablejar/BootableJarSupport.java index 8e3d8bd3..6ed55620 100644 --- a/core/src/main/java/org/wildfly/plugins/bootablejar/BootableJarSupport.java +++ b/core/src/main/java/org/wildfly/plugins/bootablejar/BootableJarSupport.java @@ -165,36 +165,6 @@ public static ScannedArtifacts scanArtifacts(ProvisioningManager pm, Provisionin cliArtifacts.add(a); continue; } - if ("wildfly-patching".equals(a.getArtifactId()) - && "org.wildfly.core".equals(a.getGroupId())) { - // We got it. - log.debug(fprt.getFPID(), a); - cliArtifacts.add(a); - continue; - } - // All the following ones are patching required dependencies: - if ("wildfly-controller".equals(a.getArtifactId()) - && "org.wildfly.core".equals(a.getGroupId())) { - // We got it. - log.debug(fprt.getFPID(), a); - cliArtifacts.add(a); - continue; - } - if ("wildfly-version".equals(a.getArtifactId()) - && "org.wildfly.core".equals(a.getGroupId())) { - // We got it. - log.debug(fprt.getFPID(), a); - cliArtifacts.add(a); - continue; - } - if ("vdx-core".equals(a.getArtifactId()) - && "org.projectodd.vdx".equals(a.getGroupId())) { - // We got it. - log.debug(fprt.getFPID(), a); - cliArtifacts.add(a); - continue; - } - // End patching dependencies. if (JBOSS_MODULES_ARTIFACT_ID.equals(a.getArtifactId()) && JBOSS_MODULES_GROUP_ID.equals(a.getGroupId())) { jbossModules = a; diff --git a/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/AbstractBuildBootableJarMojo.java b/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/AbstractBuildBootableJarMojo.java index 0f536b31..4c35e429 100644 --- a/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/AbstractBuildBootableJarMojo.java +++ b/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/AbstractBuildBootableJarMojo.java @@ -98,7 +98,6 @@ import org.wildfly.plugins.bootablejar.maven.cli.LocalCLIExecutor; import org.wildfly.plugins.bootablejar.maven.cli.RemoteCLIExecutor; import org.wildfly.plugins.bootablejar.maven.common.FeaturePack; -import org.wildfly.plugins.bootablejar.maven.common.LegacyPatchCleaner; import org.wildfly.plugins.bootablejar.maven.common.MavenRepositoriesEnricher; import org.wildfly.plugins.bootablejar.maven.common.OverriddenArtifact; import org.wildfly.plugins.bootablejar.maven.common.Utils; @@ -277,32 +276,6 @@ public abstract class AbstractBuildBootableJarMojo extends AbstractMojo { @Parameter(alias = "provisioning-file", property = "wildfly.bootable.provisioning.file", defaultValue = "${project.basedir}/galleon/provisioning.xml") private File provisioningFile; - /** - * Deprecated. Path to a CLI script that applies legacy patches. Content of such script - * should be composed of 'patch apply [path to zip file] [patch apply - * options]' commands. Due to the nature of a bootable JAR trimmed with - * Galleon, part of the content of the patch can be missing. In order to - * force the patch to apply use the '--override-all' option. The - * '--distribution' option is not needed, System property 'jboss.home.dir' - * is automatically set to the server that will be packaged in the bootable - * JAR. If the script file is not absolute, it has to be relative to the - * project base directory. - * NB: The server is patched with a legacy patch right after the server - * has been provisioned with Galleon. - */ - @Deprecated - @Parameter(alias = "legacy-patch-cli-script") - String legacyPatchCliScript; - - /** - * Deprecated. Set to true to enable patch cleanup. When cleanup is enabled, unused - * added modules, patched modules original directories, unused overlay - * directories and .installation/patches directory are deleted. - */ - @Deprecated - @Parameter(alias = "legacy-patch-clean-up", defaultValue = "false") - boolean legacyPatchCleanUp; - /** * By default executed CLI scripts output is not shown if execution is * successful. In order to display the CLI output, set this option to true. @@ -473,8 +446,6 @@ public void execute() throws MojoExecutionException, MojoFailureException { getLog().info("CLI executions are done in forked process"); } - // Legacy Patching point - legacyPatching(); copyExtraContentInternal(wildflyDir, contentDir); copyExtraContent(wildflyDir); List commands = new ArrayList<>(); @@ -564,37 +535,6 @@ private void restoreLoggingFile(Path originalLoggingFile) throws IOException { } } - private void legacyPatching() throws Exception { - if (legacyPatchCliScript != null) { - LegacyPatchCleaner patchCleaner = null; - if (legacyPatchCleanUp) { - patchCleaner = new LegacyPatchCleaner(wildflyDir, getLog()); - } - String prop = "jboss.home.dir"; - System.setProperty(prop, wildflyDir.toAbsolutePath().toString()); - try { - Path patchScript = resolvePath(Paths.get(legacyPatchCliScript)); - if (Files.notExists(patchScript)) { - throw new Exception("Patch CLI script " + patchScript + " doesn't exist"); - } - List cliPatchingSessions = new ArrayList<>(); - List files = new ArrayList<>(); - files.add(patchScript.toString()); - CliSession patchingSession = new CliSession(); - patchingSession.setResolveExpressions(true); - patchingSession.setScriptFiles(files); - cliPatchingSessions.add(patchingSession); - getLog().info("Patching server with " + patchScript + " CLI script."); - userScripts(wildflyDir, cliPatchingSessions, false); - if (patchCleaner != null) { - patchCleaner.clean(); - } - } finally { - System.clearProperty(prop); - } - } - } - private void copyExtraContent(Path wildflyDir) throws Exception { for (String path : extraServerContentDirs) { Path extraContent = Paths.get(path); diff --git a/tests/pom.xml b/tests/pom.xml index 3e3c606d..1caa1d46 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -124,35 +124,6 @@ - - - - org.jboss.galleon - galleon-maven-plugin - - - server-provisioning-for-patching - - provision - - process-test-resources - - ${jbossas.dist} - false - - true - - - - ${wildfly.groupId} - ${wildfly.artifactId} - ${version.wildfly} - - - - - - org.apache.maven.plugins maven-surefire-plugin @@ -170,7 +141,6 @@ ${test.version.wildfly-ee.upgrade} ${test.version.wildfly} ${project.version} - ${test.patch.version} ${jbossas.dist} ${wildfly.groupId} diff --git a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchAddModuleTestCase.java b/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchAddModuleTestCase.java deleted file mode 100644 index 255e8685..00000000 --- a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchAddModuleTestCase.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2020 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.wildfly.plugins.bootablejar.maven.goals; - -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -import org.junit.Test; -import org.wildfly.plugins.bootablejar.patching.Module; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.FILE_SEPARATOR; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.RELATIVE_MODULES_PATH; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.RELATIVE_PATCHES_PATH; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.buildModulePatch; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.randomString; -import org.wildfly.plugins.bootablejar.patching.ResourceItem; - -/** - * @author jdenise - */ -public class PatchAddModuleTestCase extends AbstractBootableJarMojoTestCase { - public PatchAddModuleTestCase() { - super("test15-pom.xml", true, null); - } - - @Test - public void testAddModulePatch() - throws Exception { - String patchid = randomString(); - String layerPatchID = randomString(); - Path patchContentDir = createTestDirectory("patch-test-content", patchid); - final String moduleName = "org.wildfly.test." + randomString(); - final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes(StandardCharsets.UTF_8)); - final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes(StandardCharsets.UTF_8)); - - Module newModule = new Module.Builder(moduleName) - .miscFile(resourceItem1) - .miscFile(resourceItem2) - .build(); - final Path dir = getTestDir(); - buildModulePatch(patchContentDir, false, dir, patchid, newModule, layerPatchID); - BuildBootableJarMojo mojo = lookupMojo("package"); - assertNotNull(mojo); - mojo.execute(); - Path home = checkAndGetWildFlyHome(dir, true, true, null, null, mojo.recordState); - try { - // original module doesn't exist - final String modulePath = home.toString() + FILE_SEPARATOR + RELATIVE_MODULES_PATH - + FILE_SEPARATOR + moduleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertFalse(Files.exists(Paths.get(modulePath))); - final String patchedModulePath = home.toString() + FILE_SEPARATOR + RELATIVE_PATCHES_PATH - + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + moduleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(patchedModulePath))); - checkJar(dir, true, true, null, null, mojo.recordState); - checkDeployment(dir, true); - } finally { - BuildBootableJarMojo.deleteDir(home); - } - } -} diff --git a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchCPCleanupTestCase.java b/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchCPCleanupTestCase.java deleted file mode 100644 index 3d50b566..00000000 --- a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchCPCleanupTestCase.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2020 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.wildfly.plugins.bootablejar.maven.goals; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.FILE_SEPARATOR; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.RELATIVE_MODULES_PATH; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.RELATIVE_PATCHES_PATH; - -/** - * @author jdenise - */ -public class PatchCPCleanupTestCase extends PatchCPTestCase { - - public PatchCPCleanupTestCase() { - super("test16-pom.xml", true, null); - } - - @Override - protected void checkFiles(Path home, String layerPatchID, String serverModuleName, String cliModuleName, - String moduleA, String moduleB, String moduleC, String moduleD, String moduleE) { - // original module doesn't exists because cleanup - final String modulePath = home.toString() + FILE_SEPARATOR + RELATIVE_MODULES_PATH - + FILE_SEPARATOR + serverModuleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertFalse(Files.exists(Paths.get(modulePath))); - // The patched module - final String patchedModulePath = home.toString() + FILE_SEPARATOR + RELATIVE_PATCHES_PATH - + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + serverModuleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(patchedModulePath))); - // The module doesn't exists because cleanup - final String cliModulePath = home.toString() + FILE_SEPARATOR + RELATIVE_PATCHES_PATH - + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + cliModuleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(cliModulePath))); - - final String moduleAPath = home.toString() + FILE_SEPARATOR + RELATIVE_PATCHES_PATH - + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + moduleA.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(moduleAPath))); - - final String moduleBPath = home.toString() + FILE_SEPARATOR + RELATIVE_PATCHES_PATH - + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + moduleB.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(moduleBPath))); - - final String moduleCPath = home.toString() + FILE_SEPARATOR + RELATIVE_PATCHES_PATH - + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + moduleC.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(moduleCPath))); - - final String moduleDPath = home.toString() + FILE_SEPARATOR + RELATIVE_PATCHES_PATH - + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + moduleD.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(moduleDPath))); - - // doesn't exists because cleanup - final String moduleEPath = home.toString() + FILE_SEPARATOR + RELATIVE_PATCHES_PATH - + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + moduleE.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertFalse(Files.exists(Paths.get(moduleEPath))); - - Path patches = home.resolve(".installation").resolve("patches"); - assertFalse(Files.exists(patches)); - - } -} diff --git a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchCPTestCase.java b/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchCPTestCase.java deleted file mode 100644 index 74b53687..00000000 --- a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchCPTestCase.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright 2020 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.wildfly.plugins.bootablejar.maven.goals; - -import java.io.File; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.jboss.as.patching.HashUtils; -import org.jboss.as.patching.metadata.ContentModification; - -import org.junit.Test; -import org.wildfly.plugins.bootablejar.patching.ContentModificationUtils; -import org.wildfly.plugins.bootablejar.patching.Module; -import org.wildfly.plugins.bootablejar.patching.PatchingTestUtil; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.AS_DISTRIBUTION; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.FILE_SEPARATOR; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.MODULES_PATH; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.RELATIVE_MODULES_PATH; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.RELATIVE_PATCHES_PATH; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.buildCPPatch; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.randomString; -import org.wildfly.plugins.bootablejar.patching.ResourceItem; - -/** - * @author jdenise - */ -public class PatchCPTestCase extends AbstractBootableJarMojoTestCase { - - public PatchCPTestCase() { - super("test15-pom.xml", true, null); - } - - protected PatchCPTestCase(final String pomFileName, final boolean copyWar, final String provisioning, final String... cli) { - super(pomFileName, copyWar, provisioning, cli); - } - - @Test - public void testCPPatch() - throws Exception { - String patchID = randomString(); - String layerPatchID = "layer" + patchID; - Path patchContentDir = createTestDirectory("patch-test-content", patchID); - - Module newModuleA = new Module.Builder("org.wildfly.test.A") - .dependency("org.wildfly.test.B") - .build(); - ContentModification moduleAddedA = ContentModificationUtils.addModule(patchContentDir.toFile(), layerPatchID, newModuleA); - Module newModuleB = new Module.Builder("org.wildfly.test.B") - .dependency("org.wildfly.test.C") - .dependency("org.wildfly.test.D") - .build(); - ContentModification moduleAddedB = ContentModificationUtils.addModule(patchContentDir.toFile(), layerPatchID, newModuleB); - Module newModuleC = new Module.Builder("org.wildfly.test.C") - .build(); - ContentModification moduleAddedC = ContentModificationUtils.addModule(patchContentDir.toFile(), layerPatchID, newModuleC); - Module newModuleD = new Module.Builder("org.wildfly.test.D") - .build(); - ContentModification moduleAddedD = ContentModificationUtils.addModule(patchContentDir.toFile(), layerPatchID, newModuleD); - Module newModuleE = new Module.Builder("org.wildfly.test.E") - .build(); - ContentModification moduleAddedE = ContentModificationUtils.addModule(patchContentDir.toFile(), layerPatchID, newModuleE); - - final String serverModuleName = "org.jboss.as.server"; - Path moduleDir = Paths.get(AS_DISTRIBUTION); - moduleDir = moduleDir.resolve("modules").resolve("system").resolve("layers"). - resolve("base").resolve("org").resolve("jboss").resolve("as").resolve("server").resolve("main"); - assertTrue(Files.exists(moduleDir)); - Path moduleFile = moduleDir.resolve("module.xml"); - Module updatedModule = new Module.Builder(serverModuleName) - .miscFile(new ResourceItem("res1", "new resource in the module".getBytes(StandardCharsets.UTF_8))) - .originalModuleXml(moduleFile) - .property("foo", "bar") - .dependency("org.wildfly.test.A") - .build(); - - // Add cli module that doesn't exist - final String cliModuleName = "org.jboss.as.cli"; - Path cliModuleDir = Paths.get(AS_DISTRIBUTION); - cliModuleDir = cliModuleDir.resolve("modules").resolve("system").resolve("layers"). - resolve("base").resolve("org").resolve("jboss").resolve("as").resolve("cli").resolve("main"); - assertTrue(Files.exists(cliModuleDir)); - Path cliModuleFile = cliModuleDir.resolve("module.xml"); - Module cliUpdatedModule = new Module.Builder(cliModuleName) - .miscFile(new ResourceItem("res1", "new resource in the module".getBytes(StandardCharsets.UTF_8))) - .originalModuleXml(cliModuleFile) - .property("foo", "bar") - .build(); - // create the patch with the updated module - ContentModification cliModuleModified = ContentModificationUtils.modifyModule(patchContentDir.toFile(), - layerPatchID, HashUtils.hashFile(cliModuleDir.toFile()), cliUpdatedModule); - - // Also see if we can update jboss-modules - Path installation = Paths.get(AS_DISTRIBUTION); - Path patchDir = patchContentDir.resolve(patchID); - final ContentModification jbossModulesModification = PatchingTestUtil.updateModulesJar(installation.toFile(), patchDir.toFile()); - - // create the patch with the updated module - ContentModification moduleModified = ContentModificationUtils.modifyModule(patchContentDir.toFile(), - layerPatchID, HashUtils.hashFile(moduleDir.toFile()), updatedModule); - - // Create the version module - final String cpAsVersion = "EAP with cp patch"; - final String versionModuleName = "org.jboss.as.version"; - final String slot = "main"; - final String originalVersionModulePath = MODULES_PATH + FILE_SEPARATOR + versionModuleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + slot; - final Module modifiedModule = PatchingTestUtil.createVersionModule(cpAsVersion); - ContentModification versionModuleModified = ContentModificationUtils.modifyModule(patchContentDir.toFile(), layerPatchID, HashUtils.hashFile(new File(originalVersionModulePath)), modifiedModule); - - final Path dir = getTestDir(); - buildCPPatch(patchContentDir, true, dir, patchID, cpAsVersion, moduleModified, - layerPatchID, versionModuleModified, cliModuleModified, jbossModulesModification, - moduleAddedA, moduleAddedB, moduleAddedC, moduleAddedD, moduleAddedE); - BuildBootableJarMojo mojo = lookupMojo("package"); - assertNotNull(mojo); - mojo.execute(); - Path home = checkAndGetWildFlyHome(dir, true, true, null, null, mojo.recordState); - try { - - checkJar(dir, true, true, null, null, mojo.recordState); - checkDeployment(dir, true); - } finally { - BuildBootableJarMojo.deleteDir(home); - } - } - - protected void checkFiles(Path home, String layerPatchID, String serverModuleName, String cliModuleName, - String moduleA, String moduleB, String moduleC, String moduleD, String moduleE) { - // original module - final String modulePath = home.toString() + FILE_SEPARATOR + RELATIVE_MODULES_PATH - + FILE_SEPARATOR + serverModuleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(modulePath))); - // The patched module - final String patchedModulePath = home.toString() + FILE_SEPARATOR + RELATIVE_PATCHES_PATH - + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + serverModuleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(patchedModulePath))); - // The module exists because override-all - final String cliModulePath = home.toString() + FILE_SEPARATOR + RELATIVE_PATCHES_PATH - + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + cliModuleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(cliModulePath))); - - final String moduleAPath = home.toString() + FILE_SEPARATOR + RELATIVE_PATCHES_PATH - + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + moduleA.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(moduleAPath))); - - final String moduleBPath = home.toString() + FILE_SEPARATOR + RELATIVE_PATCHES_PATH - + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + moduleB.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(moduleBPath))); - - final String moduleCPath = home.toString() + FILE_SEPARATOR + RELATIVE_PATCHES_PATH - + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + moduleC.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(moduleCPath))); - - final String moduleDPath = home.toString() + FILE_SEPARATOR + RELATIVE_PATCHES_PATH - + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + moduleD.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(moduleDPath))); - - final String moduleEPath = home.toString() + FILE_SEPARATOR + RELATIVE_PATCHES_PATH - + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + moduleE.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(moduleEPath))); - - Path patches = home.resolve(".installation").resolve("patches"); - assertTrue(Files.exists(patches)); - } -} diff --git a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchExistingMiscTestCase.java b/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchExistingMiscTestCase.java deleted file mode 100644 index d9d5d07b..00000000 --- a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchExistingMiscTestCase.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2020 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.wildfly.plugins.bootablejar.maven.goals; - -import java.nio.file.Path; - -import org.junit.Test; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.buildMiscPatch; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.randomString; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.readFile; - -/** - * @author jdenise - */ -public class PatchExistingMiscTestCase extends AbstractBootableJarMojoTestCase { - public PatchExistingMiscTestCase() { - super("test14-pom.xml", true, null); - } - - @Test - public void testMiscPatch() - throws Exception { - String patchid = randomString(); - Path patchContentDir = createTestDirectory("patch-test-content", patchid); - final String testContent = "test content"; - final Path dir = getTestDir(); - buildMiscPatch(patchContentDir, false, dir, patchid, testContent, "LICENSE.txt"); - BuildBootableJarMojo mojo = lookupMojo("package"); - assertNotNull(mojo); - mojo.execute(); - Path home = checkAndGetWildFlyHome(dir, true, true, null, null, mojo.recordState); - try { - Path patchedLicense = home.resolve("LICENSE.txt"); - String patchedContent = readFile(patchedLicense.toString()); - assertEquals("check content of file after patch", testContent, patchedContent); - checkJar(dir, true, true, null, null, mojo.recordState); - checkDeployment(dir, true); - } finally { - BuildBootableJarMojo.deleteDir(home); - } - } -} diff --git a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchExistingModuleTestCase.java b/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchExistingModuleTestCase.java deleted file mode 100644 index 250b006d..00000000 --- a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchExistingModuleTestCase.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2020 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.wildfly.plugins.bootablejar.maven.goals; - -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.jboss.as.patching.HashUtils; -import org.jboss.as.patching.metadata.ContentModification; - -import org.junit.Test; -import org.wildfly.plugins.bootablejar.patching.ContentModificationUtils; -import org.wildfly.plugins.bootablejar.patching.Module; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.AS_DISTRIBUTION; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.FILE_SEPARATOR; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.RELATIVE_MODULES_PATH; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.RELATIVE_PATCHES_PATH; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.buildModulePatch; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.randomString; -import org.wildfly.plugins.bootablejar.patching.ResourceItem; - -/** - * @author jdenise - */ -public class PatchExistingModuleTestCase extends AbstractBootableJarMojoTestCase { - - public PatchExistingModuleTestCase() { - super("test15-pom.xml", true, null); - } - - @Test - public void testUpdateModulePatch() - throws Exception { - String patchid = randomString(); - String baseLayerPatchID = randomString(); - Path patchContentDir = createTestDirectory("patch-test-content", patchid); - - final String moduleName = "org.jboss.as.server"; - Path moduleDir = Paths.get(AS_DISTRIBUTION); - moduleDir = moduleDir.resolve("modules").resolve("system").resolve("layers"). - resolve("base").resolve("org").resolve("jboss").resolve("as").resolve("server").resolve("main"); - assertTrue(Files.exists(moduleDir)); - Path moduleFile = moduleDir.resolve("module.xml"); - Module updatedModule = new Module.Builder(moduleName) - .miscFile(new ResourceItem("res1", "new resource in the module".getBytes(StandardCharsets.UTF_8))) - .originalModuleXml(moduleFile) - .property("foo", "bar") - .build(); - // create the patch with the updated module - ContentModification moduleModified = ContentModificationUtils.modifyModule(patchContentDir.toFile(), - baseLayerPatchID, HashUtils.hashFile(moduleDir.toFile()), updatedModule); - final Path dir = getTestDir(); - buildModulePatch(patchContentDir, false, dir, patchid, moduleModified, baseLayerPatchID); - BuildBootableJarMojo mojo = lookupMojo("package"); - assertNotNull(mojo); - mojo.execute(); - Path home = checkAndGetWildFlyHome(dir, true, true, null, null, mojo.recordState); - try { - // original module - final String modulePath = home.toString() + FILE_SEPARATOR + RELATIVE_MODULES_PATH - + FILE_SEPARATOR + moduleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(modulePath))); - // The patched module - final String patchedModulePath = home.toString() + FILE_SEPARATOR + RELATIVE_PATCHES_PATH - + FILE_SEPARATOR + baseLayerPatchID + FILE_SEPARATOR + moduleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(patchedModulePath))); - checkJar(dir, true, true, null, null, mojo.recordState); - checkDeployment(dir, true); - } finally { - BuildBootableJarMojo.deleteDir(home); - } - } -} diff --git a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchUnexistingFailMiscTestCase.java b/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchUnexistingFailMiscTestCase.java deleted file mode 100644 index 4b7623af..00000000 --- a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchUnexistingFailMiscTestCase.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2020 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.wildfly.plugins.bootablejar.maven.goals; - -import java.nio.file.Path; - -import org.junit.Test; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.buildMiscPatch; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.randomString; - -/** - * @author jdenise - */ -public class PatchUnexistingFailMiscTestCase extends AbstractBootableJarMojoTestCase { - public PatchUnexistingFailMiscTestCase() { - super("test15-pom.xml", true, null); - } - - @Test - public void testMiscPatch() - throws Exception { - String patchid = randomString(); - Path patchContentDir = createTestDirectory("patch-test-content", patchid); - final String testContent = "java -version"; - buildMiscPatch(patchContentDir, false, getTestDir(), patchid, testContent, "bin", "jboss-cli.sh"); - BuildBootableJarMojo mojo = lookupMojo("package"); - assertNotNull(mojo); - boolean failed = false; - try { - mojo.execute(); - failed = true; - } catch(Exception ex) { - // OK expected - System.err.println("EXPECTED exception"); - ex.printStackTrace(); - } - if (failed) { - throw new Exception("Should have failed"); - } - } -} diff --git a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchUnexistingFailModuleTestCase.java b/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchUnexistingFailModuleTestCase.java deleted file mode 100644 index 0a1ba038..00000000 --- a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchUnexistingFailModuleTestCase.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2020 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.wildfly.plugins.bootablejar.maven.goals; - -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.jboss.as.patching.HashUtils; -import org.jboss.as.patching.metadata.ContentModification; - -import org.junit.Test; -import org.wildfly.plugins.bootablejar.patching.ContentModificationUtils; -import org.wildfly.plugins.bootablejar.patching.Module; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.AS_DISTRIBUTION; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.buildModulePatch; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.randomString; -import org.wildfly.plugins.bootablejar.patching.ResourceItem; - -/** - * @author jdenise - */ -public class PatchUnexistingFailModuleTestCase extends AbstractBootableJarMojoTestCase { - - public PatchUnexistingFailModuleTestCase() { - super("test15-pom.xml", true, null); - } - - @Test - public void testUpdateModulePatch() - throws Exception { - String patchid = randomString(); - String baseLayerPatchID = randomString(); - Path patchContentDir = createTestDirectory("patch-test-content", patchid); - - final String moduleName = "org.jboss.as.jdr"; - Path moduleDir = Paths.get(AS_DISTRIBUTION); - moduleDir = moduleDir.resolve("modules").resolve("system").resolve("layers"). - resolve("base").resolve("org").resolve("jboss").resolve("as").resolve("jdr").resolve("main"); - assertTrue(Files.exists(moduleDir)); - Path moduleFile = moduleDir.resolve("module.xml"); - Module updatedModule = new Module.Builder(moduleName) - .miscFile(new ResourceItem("res1", "new resource in the module".getBytes(StandardCharsets.UTF_8))) - .originalModuleXml(moduleFile) - .property("foo", "bar") - .build(); - // create the patch with the updated module - ContentModification moduleModified = ContentModificationUtils.modifyModule(patchContentDir.toFile(), - baseLayerPatchID, HashUtils.hashFile(moduleDir.toFile()), updatedModule); - final Path dir = getTestDir(); - buildModulePatch(patchContentDir, false, dir, patchid, moduleModified, baseLayerPatchID); - BuildBootableJarMojo mojo = lookupMojo("package"); - assertNotNull(mojo); - boolean failed = false; - try { - mojo.execute(); - failed = true; - } catch (Exception ex) { - // OK expected - System.err.println("EXPECTED exception"); - ex.printStackTrace(); - } - if (failed) { - throw new Exception("Should have failed"); - } - } -} diff --git a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchUnexistingMiscTestCase.java b/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchUnexistingMiscTestCase.java deleted file mode 100644 index 728d5c47..00000000 --- a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchUnexistingMiscTestCase.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2020 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.wildfly.plugins.bootablejar.maven.goals; - -import java.nio.file.Files; -import java.nio.file.Path; - -import org.junit.Test; -import org.wildfly.plugins.bootablejar.patching.PatchingTestUtil; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.randomString; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.readFile; - -/** - * @author jdenise - */ -public class PatchUnexistingMiscTestCase extends AbstractBootableJarMojoTestCase { - public PatchUnexistingMiscTestCase() { - super("test15-pom.xml", true, null); - } - - @Test - public void testMiscPatch() - throws Exception { - String patchid = randomString(); - Path patchContentDir = createTestDirectory("patch-test-content", patchid); - final String testContent = "java -version"; - final Path dir = getTestDir(); - // Overrides so will not fail during patching. - PatchingTestUtil.buildMiscPatch(patchContentDir, true, dir, patchid, testContent, "bin", "jboss-cli.sh"); - BuildBootableJarMojo mojo = lookupMojo("package"); - assertNotNull(mojo); - mojo.execute(); - Path home = checkAndGetWildFlyHome(dir, true, true, null, null, mojo.recordState); - try { - Path patchedCli = home.resolve("bin").resolve("jboss-cli.sh"); - assertTrue(Files.exists(patchedCli)); - String patchedContent = readFile(patchedCli.toString()); - assertEquals("check content of file after patch", testContent, patchedContent); - checkJar(dir, true, true, null, null, mojo.recordState); - checkDeployment(dir, true); - } finally { - BuildBootableJarMojo.deleteDir(home); - } - } -} diff --git a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchUnexistingModuleTestCase.java b/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchUnexistingModuleTestCase.java deleted file mode 100644 index 578e5c2e..00000000 --- a/tests/src/test/java/org/wildfly/plugins/bootablejar/maven/goals/PatchUnexistingModuleTestCase.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2020 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.wildfly.plugins.bootablejar.maven.goals; - -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.jboss.as.patching.HashUtils; -import org.jboss.as.patching.metadata.ContentModification; - -import org.junit.Test; -import org.wildfly.plugins.bootablejar.patching.ContentModificationUtils; -import org.wildfly.plugins.bootablejar.patching.Module; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.AS_DISTRIBUTION; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.FILE_SEPARATOR; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.RELATIVE_PATCHES_PATH; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.buildModulePatch; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.randomString; -import org.wildfly.plugins.bootablejar.patching.ResourceItem; - -/** - * @author jdenise - */ -public class PatchUnexistingModuleTestCase extends AbstractBootableJarMojoTestCase { - - public PatchUnexistingModuleTestCase() { - super("test15-pom.xml", true, null); - } - - @Test - public void testUpdateModulePatch() - throws Exception { - String patchid = randomString(); - String baseLayerPatchID = randomString(); - Path patchContentDir = createTestDirectory("patch-test-content", patchid); - - final String moduleName = "org.jboss.as.cli"; - Path moduleDir = Paths.get(AS_DISTRIBUTION); - moduleDir = moduleDir.resolve("modules").resolve("system").resolve("layers"). - resolve("base").resolve("org").resolve("jboss").resolve("as").resolve("cli").resolve("main"); - assertTrue(Files.exists(moduleDir)); - Path moduleFile = moduleDir.resolve("module.xml"); - Module updatedModule = new Module.Builder(moduleName) - .miscFile(new ResourceItem("res1", "new resource in the module".getBytes(StandardCharsets.UTF_8))) - .originalModuleXml(moduleFile) - .property("foo", "bar") - .build(); - // create the patch with the updated module - ContentModification moduleModified = ContentModificationUtils.modifyModule(patchContentDir.toFile(), - baseLayerPatchID, HashUtils.hashFile(moduleDir.toFile()), updatedModule); - final Path dir = getTestDir(); - buildModulePatch(patchContentDir, true, dir, patchid, moduleModified, baseLayerPatchID); - BuildBootableJarMojo mojo = lookupMojo("package"); - assertNotNull(mojo); - mojo.execute(); - Path home = checkAndGetWildFlyHome(dir, true, true, null, null, mojo.recordState); - try { - // The module exists because override-all - final String modulePath = home.toString() + FILE_SEPARATOR + RELATIVE_PATCHES_PATH - + FILE_SEPARATOR + baseLayerPatchID + FILE_SEPARATOR + moduleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main"; - assertTrue(Files.exists(Paths.get(modulePath))); - checkJar(dir, true, true, null, null, mojo.recordState); - checkDeployment(dir, true); - } finally { - BuildBootableJarMojo.deleteDir(home); - } - } -} diff --git a/tests/src/test/java/org/wildfly/plugins/bootablejar/patching/ContentModificationUtils.java b/tests/src/test/java/org/wildfly/plugins/bootablejar/patching/ContentModificationUtils.java deleted file mode 100644 index b608315a..00000000 --- a/tests/src/test/java/org/wildfly/plugins/bootablejar/patching/ContentModificationUtils.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ - -package org.wildfly.plugins.bootablejar.patching; - -import static org.jboss.as.patching.Constants.MISC; -import static org.jboss.as.patching.Constants.MODULES; -import static org.jboss.as.patching.HashUtils.hashFile; -import static org.jboss.as.patching.IoUtils.NO_CONTENT; -import static org.jboss.as.patching.IoUtils.newFile; -import static org.jboss.as.patching.metadata.ModificationType.ADD; -import static org.jboss.as.patching.metadata.ModificationType.MODIFY; -import static org.jboss.as.patching.metadata.ModificationType.REMOVE; - -import java.io.File; -import java.io.IOException; - -import org.jboss.as.patching.metadata.ContentModification; -import org.jboss.as.patching.metadata.MiscContentItem; -import org.jboss.as.patching.metadata.ModuleItem; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.dump; -import static org.wildfly.plugins.bootablejar.patching.PatchingTestUtil.touch; - -/** - * @author Jeff Mesnil (c) 2013 Red Hat inc. - */ -public class ContentModificationUtils { - - public static ContentModification addModule(File patchDir, String patchElementID, Module newModule) throws IOException { - File baseDir = newFile(patchDir, patchElementID, MODULES); - File mainDir = newModule.writeToDisk(baseDir); - byte[] newHash = hashFile(mainDir); - ContentModification moduleAdded = new ContentModification(new ModuleItem(newModule.getName(), newModule.getSlot(), newHash), NO_CONTENT, ADD); - return moduleAdded; - } - - public static ContentModification removeModule(String moduleName, File existingModule) throws IOException { - byte[] existingHash = hashFile(existingModule); - return new ContentModification(new ModuleItem(moduleName, ModuleItem.MAIN_SLOT, NO_CONTENT), existingHash, REMOVE); - } - - public static ContentModification modifyModule(File patchDir, String patchElementID, byte[] existingHash, Module newModule) throws IOException { - File baseDir = newFile(patchDir, patchElementID, MODULES); - File mainDir = newModule.writeToDisk(baseDir); - byte[] newHash = hashFile(mainDir); - ContentModification moduleUpdated = new ContentModification(new ModuleItem(newModule.getName(), newModule.getSlot(), newHash), existingHash, MODIFY); - return moduleUpdated; - } - - public static ContentModification addMisc(File patchDir, String patchElementID, String content, String... fileSegments) throws IOException { - File miscDir = newFile(patchDir, patchElementID, MISC); - File addedFile = touch(miscDir, fileSegments); - dump(addedFile, content); - byte[] newHash = hashFile(addedFile); - String[] subdir = new String[fileSegments.length - 1]; - System.arraycopy(fileSegments, 0, subdir, 0, fileSegments.length - 1); - ContentModification fileAdded = new ContentModification(new MiscContentItem(addedFile.getName(), subdir, newHash), NO_CONTENT, ADD); - return fileAdded; - } - - public static ContentModification removeMisc(File existingFile, String... fileSegments) throws IOException { - byte[] existingHash = hashFile(existingFile); - String[] subdir = new String[0]; - if (fileSegments.length > 0) { - subdir = new String[fileSegments.length - 1]; - System.arraycopy(fileSegments, 0, subdir, 0, fileSegments.length - 1); - } - ContentModification fileRemoved = new ContentModification(new MiscContentItem(existingFile.getName(), subdir, NO_CONTENT), existingHash, REMOVE); - return fileRemoved; - } - - public static ContentModification modifyMisc(File patchDir, String patchElementID, String modifiedContent, File existingFile, String... fileSegments) throws IOException { - byte[] existingHash = hashFile(existingFile); - return modifyMisc(patchDir, patchElementID, modifiedContent, existingHash, fileSegments); - } - - public static ContentModification modifyMisc(File patchDir, String patchElementID, String modifiedContent, byte[] existingHash, String... fileSegments) throws IOException { - File miscDir = newFile(patchDir, patchElementID, MISC); - File modifiedFile = touch(miscDir, fileSegments); - dump(modifiedFile, modifiedContent); - byte[] modifiedHash = hashFile(modifiedFile); - String[] subdir = new String[0]; - if (fileSegments.length > 0) { - subdir = new String[fileSegments.length - 1]; - System.arraycopy(fileSegments, 0, subdir, 0, fileSegments.length - 1); - } - ContentModification fileUpdated = new ContentModification(new MiscContentItem(modifiedFile.getName(), subdir, modifiedHash), existingHash, MODIFY); - return fileUpdated; - } -} diff --git a/tests/src/test/java/org/wildfly/plugins/bootablejar/patching/Module.java b/tests/src/test/java/org/wildfly/plugins/bootablejar/patching/Module.java deleted file mode 100644 index 86ebfdd8..00000000 --- a/tests/src/test/java/org/wildfly/plugins/bootablejar/patching/Module.java +++ /dev/null @@ -1,246 +0,0 @@ -package org.wildfly.plugins.bootablejar.patching; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import org.jboss.as.patching.IoUtils; -import org.jboss.as.patching.metadata.ModuleItem; - -/** - * @author Martin Simka - */ -public class Module { - private String namespace; - private String name; - private String slot; - private Properties properties; - private List dependencies; - private List resourceRoots; - private List miscFiles; - private Path originalModuleXml; - - private Module(Builder builder) { - this.namespace = builder.namespace; - this.name = builder.name; - this.slot = builder.slot; - this.properties = builder.properties; - this.dependencies = builder.dependencies; - this.resourceRoots = builder.resourceRoots; - this.miscFiles = builder.miscFiles; - this.originalModuleXml = builder.originalModuleXml; - } - - public String getName() { - return name; - } - - public String getSlot() { - return slot; - } - - public String generateXml() throws IOException { - StringBuilder stringBuilder = new StringBuilder(); - if (originalModuleXml != null) { - String content = new String(Files.readAllBytes(originalModuleXml)); - if (!properties.isEmpty()) { - StringBuilder props = new StringBuilder(); - String propertyTemplate = " \n"; - for (String key : properties.stringPropertyNames()) { - props.append(String.format(propertyTemplate, key, properties.getProperty(key))); - } - content = content.replace("", "\n" + props.toString()); - } - if (!resourceRoots.isEmpty()) { - StringBuilder resources = new StringBuilder(); - String resourceRootTemplate = " \n"; - for (ResourceItem resourceRoot : resourceRoots) { - resources.append(String.format(resourceRootTemplate, resourceRoot.getItemName())); - } - content = content.replace("", "\n" + resources.toString()); - } - if (!dependencies.isEmpty()) { - StringBuilder deps = new StringBuilder(); - String dependencyTemplate = " \n"; - for (String module : dependencies) { - deps.append(String.format(dependencyTemplate, module)); - } - content = content.replace("", "\n" + deps.toString()); - } - stringBuilder.append(content); - } else { - stringBuilder.append("\n"); - String rootElementTemplate = "\n"; - stringBuilder.append(String.format(rootElementTemplate, namespace, name, slot)); - if (!properties.isEmpty()) { - stringBuilder.append(" \n"); - String propertyTemplate = " \n"; - for (String key : properties.stringPropertyNames()) { - stringBuilder.append(String.format(propertyTemplate, key, properties.getProperty(key))); - } - stringBuilder.append(" \n"); - } - - stringBuilder.append(" \n"); - String resourceRootTemplate = " \n"; - for (ResourceItem resourceRoot : resourceRoots) { - stringBuilder.append(String.format(resourceRootTemplate, resourceRoot.getItemName())); - } - stringBuilder.append(String.format(resourceRootTemplate, ".")); - stringBuilder.append(" \n"); - - if (!dependencies.isEmpty()) { - stringBuilder.append(" \n"); - String dependencyTemplate = " \n"; - for (String module : dependencies) { - stringBuilder.append(String.format(dependencyTemplate, module)); - } - stringBuilder.append(" \n"); - } - stringBuilder.append("\n"); - } - return stringBuilder.toString(); - } - - /** - * writes module to disk - * - * @param baseDir usually modules dir, written path starts with first part of module name - * @return main dir - * @throws java.io.IOException - */ - public File writeToDisk(File baseDir) throws IOException { - File mainDir = IoUtils.mkdir(baseDir, (name + "." + slot).split("\\.")); - File moduleXml = PatchingTestUtil.touch(mainDir, "module.xml"); - PatchingTestUtil.dump(moduleXml, generateXml().getBytes(StandardCharsets.UTF_8)); - for (ResourceItem resourceRoot : resourceRoots) { - File f = PatchingTestUtil.touch(mainDir, resourceRoot.getItemName()); - PatchingTestUtil.dump(f, resourceRoot.getContent()); - } - for (ResourceItem miscFile : miscFiles) { - File f = PatchingTestUtil.touch(mainDir, miscFile.getItemName()); - PatchingTestUtil.dump(f, miscFile.getContent()); - } - if (originalModuleXml != null) { - // copy all existing resources - Path parent = originalModuleXml.getParent(); - for (File f : parent.toFile().listFiles()) { - if (!f.getName().equals("module.xml")) { - Files.copy(f.toPath(), mainDir.toPath().resolve(f.getName())); - } - } - } - return mainDir; - } - - - public static class Builder { - private String namespace; - private String name; - private String slot; - private Properties properties; - private List dependencies; - private List resourceRoots; - private List miscFiles; - private Path originalModuleXml; - - public Builder(String name, String namespace) { - if (name == null) { - throw new NullPointerException("name"); - } - if (namespace == null) { - throw new NullPointerException("namespace"); - } - this.name = name; - this.namespace = namespace; - properties = new Properties(); - dependencies = new ArrayList(); - resourceRoots = new ArrayList(); - miscFiles = new ArrayList(); - } - - public Builder(String name) { - if (name == null) { - throw new NullPointerException("name"); - } - this.name = name; - this.namespace = "urn:jboss:module:1.2"; - properties = new Properties(); - dependencies = new ArrayList(); - resourceRoots = new ArrayList(); - miscFiles = new ArrayList(); - } - - public Builder slot(String slot) { - if (slot == null) { - throw new NullPointerException("slot"); - } - this.slot = slot; - return this; - } - - public Builder property(String name, String value) { - if (name == null) { - throw new NullPointerException("name"); - } - if (value == null) { - throw new NullPointerException("value"); - } - properties.setProperty(name, value); - return this; - } - - public Builder dependency(String moduleName) { - if (moduleName == null) { - throw new NullPointerException("moduleName"); - } - dependencies.add(moduleName); - return this; - } - - public Builder resourceRoot(ResourceItem resourceRoot) { - if (resourceRoot == null) { - throw new NullPointerException("resourceRoot"); - } - resourceRoots.add(resourceRoot); - return this; - } - - public Builder miscFile(ResourceItem miscFile) { - if (miscFile == null) { - throw new NullPointerException("miscFile"); - } - miscFiles.add(miscFile); - return this; - } - - public Builder originalModuleXml(Path path) { - if (path == null) { - throw new NullPointerException("path"); - } - if (!Files.exists(path)) { - throw new RuntimeException("Path doesn't exist " + path); - } - originalModuleXml = path; - return this; - } - - public Module build() { - assert notNull(name); - assert notNull(namespace); - if (slot == null) { - slot = ModuleItem.MAIN_SLOT; - } - return new Module(this); - } - - static boolean notNull(Object o) { - return o != null; - } - } -} diff --git a/tests/src/test/java/org/wildfly/plugins/bootablejar/patching/PatchingTestUtil.java b/tests/src/test/java/org/wildfly/plugins/bootablejar/patching/PatchingTestUtil.java deleted file mode 100644 index d8257da0..00000000 --- a/tests/src/test/java/org/wildfly/plugins/bootablejar/patching/PatchingTestUtil.java +++ /dev/null @@ -1,430 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ - -package org.wildfly.plugins.bootablejar.patching; - -import static java.lang.String.format; -import static org.jboss.as.patching.Constants.BASE; -import static org.jboss.as.patching.Constants.LAYERS; -import static org.jboss.as.patching.Constants.MODULES; -import static org.jboss.as.patching.Constants.OVERLAYS; -import static org.jboss.as.patching.Constants.SYSTEM; -import static org.jboss.as.patching.IoUtils.newFile; -import static org.jboss.as.patching.IoUtils.safeClose; -import static org.jboss.as.patching.logging.PatchLogger.ROOT_LOGGER; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.FileFilter; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.ThreadLocalRandom; - -import org.jboss.as.patching.Constants; -import org.jboss.as.patching.HashUtils; -import org.jboss.as.patching.IoUtils; -import org.jboss.as.patching.ZipUtils; -import org.jboss.as.patching.metadata.BundledPatch; -import org.jboss.as.patching.metadata.ContentModification; -import org.jboss.as.patching.metadata.MiscContentItem; -import org.jboss.as.patching.metadata.ModificationType; -import org.jboss.as.patching.metadata.Patch; -import org.jboss.as.patching.metadata.PatchBundleXml; -import org.jboss.as.patching.metadata.PatchXml; -import org.jboss.dmr.ModelNode; -import org.jboss.logging.Logger; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.StringAsset; -import org.jboss.shrinkwrap.api.exporter.ZipExporter; -import org.jboss.shrinkwrap.api.spec.JavaArchive; - -import com.google.common.base.Joiner; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.nio.file.Path; -import org.jboss.as.patching.metadata.PatchBuilder; -import org.jboss.shrinkwrap.api.asset.Asset; -import static org.junit.Assert.assertFalse; - -/** - * @author Jan Martiska, Jeff Mesnil - */ -public class PatchingTestUtil { - - private static final Logger logger = Logger.getLogger(PatchingTestUtil.class); - - private static final boolean isWindows = File.separatorChar == '\\'; - - public static final String CONTAINER = "jboss"; - public static final String AS_DISTRIBUTION = System.getProperty("jbossas.dist"); - public static final String FILE_SEPARATOR = File.separator; - public static final String RELATIVE_PATCHES_PATH = Joiner.on(FILE_SEPARATOR).join(new String[]{MODULES, SYSTEM, LAYERS, BASE, OVERLAYS}); - public static final String PATCHES_PATH = AS_DISTRIBUTION + FILE_SEPARATOR + RELATIVE_PATCHES_PATH; - public static final String RELATIVE_MODULES_PATH = Joiner.on(FILE_SEPARATOR).join(new String[]{MODULES, SYSTEM, LAYERS, BASE}); - public static final String MODULES_PATH = AS_DISTRIBUTION + FILE_SEPARATOR + RELATIVE_MODULES_PATH; - public static final File MODULES_DIRECTORY = newFile(new File(AS_DISTRIBUTION), MODULES); - public static final File LAYERS_DIRECTORY = newFile(MODULES_DIRECTORY, SYSTEM, LAYERS); - public static final File BASE_MODULE_DIRECTORY = newFile(LAYERS_DIRECTORY, BASE); - public static final boolean DO_CLEANUP = Boolean.getBoolean("cleanup.tmp"); - - public static final String AS_VERSION = System.getProperty("test.patch.version"); - public static final String PRODUCT = System.getProperty("test.patch.product"); - - public static String randomString() { - return UUID.randomUUID().toString(); - } - - public static String randomString(String prefix) { - return prefix + "-" + ThreadLocalRandom.current().nextInt(0, Integer.MAX_VALUE); - } - - public static void buildMiscPatch(Path patchContentDir, boolean overrides, Path testDir, String patchID, String testContent, String... segments) throws Exception { - Path targetFile = Paths.get(AS_DISTRIBUTION); - for(String str : segments) { - targetFile = targetFile.resolve(str); - } - final String originalContent = readFile(targetFile.toString()); - assertFalse(testContent.equals(originalContent)); - ContentModification miscFileModified = ContentModificationUtils.modifyMisc(patchContentDir.toFile(), - patchID, testContent, targetFile.toFile(), segments); - Patch oneOffPatch = PatchBuilder.create() - .setPatchId(patchID) - .setDescription("A one-off patch modifying a misc file.") - .oneOffPatchIdentity(PRODUCT, AS_VERSION) - .getParent() - .addContentModification(miscFileModified) - .build(); - generatePatchAndScript(oneOffPatch, patchContentDir, overrides, testDir); - } - - public static void buildModulePatch(Path patchContentDir, boolean overrides, Path testDir, String patchID, Module newModule, String layerPatchID) throws Exception { - ContentModification moduleAdded = ContentModificationUtils.addModule(patchContentDir.toFile(), layerPatchID, newModule); - Patch oneOffPatch = PatchBuilder.create() - .setPatchId(patchID) - .setDescription("A one-off patch adding a new module.") - .oneOffPatchIdentity(PRODUCT, AS_VERSION) - .getParent() - .oneOffPatchElement(layerPatchID, BASE, false) - .setDescription("New module for the base layer") - .addContentModification(moduleAdded) - .getParent() - .build(); - generatePatchAndScript(oneOffPatch, patchContentDir, overrides, testDir); - } - - public static void buildModulePatch(Path patchContentDir, boolean overrides, Path testDir, - String patchID, ContentModification moduleModified, String baseLayerPatchID) throws Exception { - Patch oneOffPatch = PatchBuilder.create() - .setPatchId(patchID) - .setDescription(randomString()) - .oneOffPatchIdentity(PRODUCT, AS_VERSION) - .getParent() - .oneOffPatchElement(baseLayerPatchID, BASE, false) - .addContentModification(moduleModified) - .getParent() - .build(); - generatePatchAndScript(oneOffPatch, patchContentDir, overrides, testDir); - } - - public static void buildCPPatch(Path patchContentDir, boolean overrides, Path testDir, - String patchID, String cpAsVersion, ContentModification moduleModified, - String baseLayerPatchID, ContentModification versionModuleModified, ContentModification cliModuleModified, - ContentModification jbossModulesModification, - ContentModification moduleA, - ContentModification moduleB, - ContentModification moduleC, - ContentModification moduleD, - ContentModification moduleE) throws Exception { - Patch cpPatch = PatchBuilder.create() - .setPatchId(patchID) - .setDescription("A cp patch.") - .upgradeIdentity(PRODUCT, AS_VERSION, cpAsVersion) - .getParent() - .upgradeElement(baseLayerPatchID, BASE, false) - .addContentModification(moduleModified) - .addContentModification(versionModuleModified) - .addContentModification(cliModuleModified) - .addContentModification(moduleA) - .addContentModification(moduleB) - .addContentModification(moduleC) - .addContentModification(moduleD) - .addContentModification(moduleE) - .getParent() - .addContentModification(jbossModulesModification) - .build(); - generatePatchAndScript(cpPatch, patchContentDir, overrides, testDir); - } - - private static void generatePatchAndScript(Patch patch, Path patchContentDir, boolean overrides, Path testDir) throws Exception { - createPatchXMLFile(patchContentDir.toFile(), patch); - File zippedPatch = createZippedPatchFile(patchContentDir.toFile(), "patch"); - Files.copy(zippedPatch.toPath(), testDir.resolve("patch.zip")); - Files.write(testDir.resolve("patch.cli"), ("patch apply " + zippedPatch + (overrides ? " --override-all" : "") + "\npatch info --json-output").getBytes()); - } - - - /** - * Converts the contents of a file into a String. - * - * @param filePath - * @return - * @throws java.io.FileNotFoundException - */ - public static String readFile(String filePath) throws IOException { - return new String(Files.readAllBytes(Paths.get(filePath)), StandardCharsets.UTF_8); - } - - public static void setFileContent(String filePath, String content) throws IOException { - Files.write(Paths.get(filePath), content.getBytes(StandardCharsets.UTF_8)); - } - - public static void tree(File dir) { - StringBuilder out = new StringBuilder(); - out.append(dir.getParentFile().getAbsolutePath() + "\n"); - tree0(out, dir, 1, " "); - logger.trace(out); - ROOT_LOGGER.trace(out.toString()); - } - - private static void tree0(StringBuilder out, File dir, int indent, String tab) { - StringBuilder shift = new StringBuilder(); - for (int i = 0; i < indent; i++) { - shift.append(tab); - } - out.append(shift + dir.getName() + "\n"); - for (File child : dir.listFiles()) { - if (child.isDirectory()) { - tree0(out, child, indent + 1, tab); - } else { - out.append(shift + tab + child.getName() + "\n"); - } - } - } - - public static File touch(File baseDir, String... segments) throws IOException { - File f = baseDir; - for (String segment : segments) { - f = new File(f, segment); - } - f.getParentFile().mkdirs(); - f.createNewFile(); - return f; - } - - public static void dump(File f, String content) throws IOException { - final OutputStream os = new FileOutputStream(f); - try { - os.write(content.getBytes(StandardCharsets.UTF_8)); - os.close(); - } finally { - IoUtils.safeClose(os); - } - } - - public static void dump(File f, byte[] content) throws IOException { - final OutputStream os = new FileOutputStream(f); - try { - os.write(content); - os.close(); - } finally { - IoUtils.safeClose(os); - } - } - - public static File createModuleXmlFile(File mainDir, String moduleName, String... resources) - throws IOException { - StringBuilder content = new StringBuilder("\n"); - content.append( - format("\n", moduleName)); - content.append(" \n"); - content.append(" \n"); - for (String resource : resources) { - content.append(format(" \n", resource)); - } - content.append(" \n"); - content.append("\n"); - ROOT_LOGGER.trace(content); - File moduleXMLFile = touch(mainDir, "module.xml"); - dump(moduleXMLFile, content.toString()); - return moduleXMLFile; - } - - public static void createPatchXMLFile(File dir, Patch patch) throws Exception { - File patchXMLfile = new File(dir, "patch.xml"); - FileOutputStream fos = new FileOutputStream(patchXMLfile); - try { - PatchXml.marshal(fos, patch); - } finally { - safeClose(fos); - } - } - - public static void createPatchBundleXMLFile(File dir, final List patches) throws Exception { - File bundleXMLFile = new File(dir, "patches.xml"); - FileOutputStream fos = new FileOutputStream(bundleXMLFile); - try { - PatchBundleXml.marshal(fos, new BundledPatch() { - @Override - public List getPatches() { - return patches; - } - }); - } finally { - safeClose(fos); - } - } - - public static File createZippedPatchFile(File sourceDir, String zipFileName) { - return createZippedPatchFile(sourceDir, zipFileName, null); - } - - public static File createZippedPatchFile(File sourceDir, String zipFileName, File targetDir) { - if (targetDir == null) { - targetDir = sourceDir.getParentFile(); - } - tree(sourceDir); - File zipFile = new File(targetDir, zipFileName + ".zip"); - ZipUtils.zip(sourceDir, zipFile); - return zipFile; - } - - public static void assertPatchElements(File baseModuleDir, String[] expectedPatchElements) { - assertPatchElements(baseModuleDir, expectedPatchElements, isWindows); // Skip this on windows - } - - public static void assertPatchElements(File baseModuleDir, String[] expectedPatchElements, boolean skipCheck) { - if (skipCheck) { - return; - } - - File modulesPatchesDir = new File(baseModuleDir, ".overlays"); - if (!modulesPatchesDir.exists()) { - assertNull("Overlay directory does not exist, but it should", expectedPatchElements); - return; - } - final List patchDirs = Arrays.asList(modulesPatchesDir.listFiles(new FileFilter() { - @Override - public boolean accept(File pathname) { - return pathname.isDirectory(); - } - })); - if (expectedPatchElements == null) { - assertTrue("Overlays directory should contain no directories, but contains: " + patchDirs.toString(), patchDirs.isEmpty()); - } else { - final List ids = Arrays.asList(expectedPatchElements); - assertEquals("Overlays directory should contain " + expectedPatchElements.length + " patches", - expectedPatchElements.length, patchDirs.size()); - for (File f : patchDirs) { - assertTrue("Unexpected patch in .overlays directory: " + f.getName(), ids.contains(f.getName())); - } - } - } - - public static void resetInstallationState(final File home, final File... layerDirs) { - resetPatchStreams(home); - for (final File root : layerDirs) { - final File overlays = new File(root, Constants.OVERLAYS); - IoUtils.recursiveDelete(overlays); - } - } - - protected static void resetPatchStreams(final File home) { - IoUtils.recursiveDelete(new File(home, Constants.INSTALLATION)); - } - - public static ContentModification updateModulesJar(final File installation, final File patchDir) throws IOException { - final String fileName = "jboss-modules.jar"; - final File source = new File(installation, fileName); - final File misc = new File(patchDir, "misc"); - misc.mkdirs(); - final File target = new File(misc, fileName); - - updateJar(source, target); - - final byte[] sourceHash = HashUtils.hashFile(source); - final byte[] targetHash = HashUtils.hashFile(target); - assert !Arrays.equals(sourceHash, targetHash); - - final MiscContentItem item = new MiscContentItem(fileName, new String[0], targetHash, false, false); - return new ContentModification(item, sourceHash, ModificationType.MODIFY); - - } - - static void updateJar(final File source, final File target) throws IOException { - final JavaArchive archive = ShrinkWrap.createFromZipFile(JavaArchive.class, source); - archive.add(new StringAsset("test " + randomString()), "testFile"); - archive.as(ZipExporter.class).exportTo(target); - } - - public static boolean isOneOffPatchContainedInHistory(List patchingHistory, String patchID) { - boolean found = false; - for (ModelNode node : patchingHistory) { - if (node.get("patch-id").asString().equals(patchID)) { found = true; } - } - return found; - } - - public static ResourceItem createVersionItem(final String targetVersion) { - final Asset newManifest = new Asset() { - @Override - public InputStream openStream() { - return new ByteArrayInputStream(createVersionString(targetVersion).getBytes(StandardCharsets.UTF_8)); - } - }; - - final JavaArchive versionModuleJar = ShrinkWrap.create(JavaArchive.class); - versionModuleJar.addPackage("org.jboss.as.version"); - versionModuleJar.addAsManifestResource(newManifest, "MANIFEST.MF"); - - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - versionModuleJar.as(ZipExporter.class).exportTo(baos); - return new ResourceItem("as-version.jar", baos.toByteArray()); - } - - public static Module createVersionModule(final String targetVersion) { - final ResourceItem item = createVersionItem(targetVersion); - return new Module.Builder("org.jboss.as.version") - .slot("main") - .resourceRoot(item) - .property("jboss.api", "private") - .dependency("org.jboss.logging") - .dependency("org.jboss.modules") - .build(); - } - - static String createVersionString(final String newVersion) { - final StringBuilder builder = new StringBuilder(); - builder.append("JBossAS-Release-Version: ").append(newVersion).append("\n"); - return builder.toString(); - } - - -} diff --git a/tests/src/test/java/org/wildfly/plugins/bootablejar/patching/ResourceItem.java b/tests/src/test/java/org/wildfly/plugins/bootablejar/patching/ResourceItem.java deleted file mode 100644 index 7fe7ff9f..00000000 --- a/tests/src/test/java/org/wildfly/plugins/bootablejar/patching/ResourceItem.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.wildfly.plugins.bootablejar.patching; - -/** - * @author Martin Simka - */ -public class ResourceItem { - private String itemName; - private byte[] content; - - public ResourceItem(String itemName, byte[] content) { - if (itemName == null) { - throw new NullPointerException("itemName"); - } - if (content == null) { - throw new NullPointerException("content"); - } - this.itemName = itemName; - this.content = content; - } - - public String getItemName() { - return itemName; - } - - public byte[] getContent() { - return content; - } -}