|
| 1 | +/* |
| 2 | + * Copyright 2012-2014 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.gradle; |
| 18 | + |
| 19 | +import java.io.File; |
| 20 | +import java.io.IOException; |
| 21 | + |
| 22 | +import org.gradle.tooling.ProjectConnection; |
| 23 | +import org.junit.BeforeClass; |
| 24 | +import org.junit.Test; |
| 25 | +import org.springframework.boot.dependency.tools.ManagedDependencies; |
| 26 | + |
| 27 | +import static org.junit.Assert.assertFalse; |
| 28 | +import static org.junit.Assert.assertTrue; |
| 29 | + |
| 30 | +public class RepackagingTests { |
| 31 | + |
| 32 | + private static final String BOOT_VERSION = ManagedDependencies.get() |
| 33 | + .find("spring-boot").getVersion(); |
| 34 | + |
| 35 | + private static ProjectConnection project; |
| 36 | + |
| 37 | + @BeforeClass |
| 38 | + public static void createProject() throws IOException { |
| 39 | + project = new ProjectCreator().createProject("repackage"); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + public void repackagingEnabled() { |
| 44 | + project.newBuild().forTasks("clean", "build") |
| 45 | + .withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run(); |
| 46 | + File buildLibs = new File("target/repackage/build/libs"); |
| 47 | + assertTrue(new File(buildLibs, "repackage.jar").exists()); |
| 48 | + assertTrue(new File(buildLibs, "repackage.jar.original").exists()); |
| 49 | + assertFalse(new File(buildLibs, "repackage-sources.jar.original").exists()); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void repackagingDisabled() { |
| 54 | + project.newBuild().forTasks("clean", "build") |
| 55 | + .withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=false") |
| 56 | + .run(); |
| 57 | + File buildLibs = new File("target/repackage/build/libs"); |
| 58 | + assertTrue(new File(buildLibs, "repackage.jar").exists()); |
| 59 | + assertFalse(new File(buildLibs, "repackage.jar.original").exists()); |
| 60 | + assertFalse(new File(buildLibs, "repackage-sources.jar.original").exists()); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void repackagingDisabledWithCustomRepackagedJar() { |
| 65 | + project.newBuild().forTasks("clean", "build", "customRepackagedJar") |
| 66 | + .withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=false") |
| 67 | + .run(); |
| 68 | + File buildLibs = new File("target/repackage/build/libs"); |
| 69 | + assertTrue(new File(buildLibs, "repackage.jar").exists()); |
| 70 | + assertFalse(new File(buildLibs, "repackage.jar.original").exists()); |
| 71 | + assertFalse(new File(buildLibs, "repackage-sources.jar.original").exists()); |
| 72 | + assertTrue(new File(buildLibs, "custom.jar").exists()); |
| 73 | + assertTrue(new File(buildLibs, "custom.jar.original").exists()); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + public void repackagingDisabledWithCustomRepackagedJarUsingStringJarTaskReference() { |
| 78 | + project.newBuild() |
| 79 | + .forTasks("clean", "build", "customRepackagedJarWithStringReference") |
| 80 | + .withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=false") |
| 81 | + .run(); |
| 82 | + File buildLibs = new File("target/repackage/build/libs"); |
| 83 | + assertTrue(new File(buildLibs, "repackage.jar").exists()); |
| 84 | + assertFalse(new File(buildLibs, "repackage.jar.original").exists()); |
| 85 | + assertFalse(new File(buildLibs, "repackage-sources.jar.original").exists()); |
| 86 | + assertTrue(new File(buildLibs, "custom.jar").exists()); |
| 87 | + assertTrue(new File(buildLibs, "custom.jar.original").exists()); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + public void repackagingEnabledWithCustomRepackagedJar() { |
| 92 | + project.newBuild().forTasks("clean", "build", "customRepackagedJar") |
| 93 | + .withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run(); |
| 94 | + File buildLibs = new File("target/repackage/build/libs"); |
| 95 | + assertTrue(new File(buildLibs, "repackage.jar").exists()); |
| 96 | + assertTrue(new File(buildLibs, "repackage.jar.original").exists()); |
| 97 | + assertFalse(new File(buildLibs, "repackage-sources.jar.original").exists()); |
| 98 | + assertTrue(new File(buildLibs, "custom.jar").exists()); |
| 99 | + assertTrue(new File(buildLibs, "custom.jar.original").exists()); |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + public void repackagingEnableWithCustomRepackagedJarUsingStringJarTaskReference() { |
| 104 | + project.newBuild() |
| 105 | + .forTasks("clean", "build", "customRepackagedJarWithStringReference") |
| 106 | + .withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run(); |
| 107 | + File buildLibs = new File("target/repackage/build/libs"); |
| 108 | + assertTrue(new File(buildLibs, "repackage.jar").exists()); |
| 109 | + assertTrue(new File(buildLibs, "repackage.jar.original").exists()); |
| 110 | + assertFalse(new File(buildLibs, "repackage-sources.jar.original").exists()); |
| 111 | + assertTrue(new File(buildLibs, "custom.jar").exists()); |
| 112 | + assertTrue(new File(buildLibs, "custom.jar.original").exists()); |
| 113 | + } |
| 114 | +} |
0 commit comments