@ -1,5 +1,5 @@
/ *
/ *
* Copyright 2012 - 201 6 the original author or authors .
* Copyright 2012 - 201 7 the original author or authors .
*
*
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -20,6 +20,7 @@ import java.io.File;
import java.io.IOException ;
import java.io.IOException ;
import java.util.jar.JarFile ;
import java.util.jar.JarFile ;
import org.gradle.tooling.BuildLauncher ;
import org.gradle.tooling.ProjectConnection ;
import org.gradle.tooling.ProjectConnection ;
import org.junit.BeforeClass ;
import org.junit.BeforeClass ;
import org.junit.Test ;
import org.junit.Test ;
@ -46,24 +47,20 @@ public class RepackagingTests {
@Test
@Test
public void repackagingEnabled ( ) throws IOException {
public void repackagingEnabled ( ) throws IOException {
project . newBuild ( ) . forTasks ( "clean" , "build" )
createBuildForTasks ( "clean" , "build" )
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=true" ,
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=true" ) . run ( ) ;
"-PexcludeDevtools=false" )
. run ( ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
File repackageFile = new File ( buildLibs , "repackage.jar" ) ;
File repackageFile = new File ( buildLibs , "repackage.jar" ) ;
assertThat ( repackageFile . exists ( ) ) . isTrue ( ) ;
assertThat ( repackageFile . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage.jar.original" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage.jar.original" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage-sources.jar.original" ) . exists ( ) )
assertThat ( new File ( buildLibs , "repackage-sources.jar.original" ) . exists ( ) )
. isFalse ( ) ;
. isFalse ( ) ;
assertThat ( isDevToolsJarIncluded ( repackageFile ) ) . isTrue ( ) ;
}
}
@Test
@Test
public void repackagingDisabled ( ) {
public void repackagingDisabled ( ) {
project . newBuild ( ) . forTasks ( "clean" , "build" )
createBuildForTasks ( "clean" , "build" )
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=false" ,
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=false" )
"-PexcludeDevtools=false" )
. run ( ) ;
. run ( ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
assertThat ( new File ( buildLibs , "repackage.jar" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage.jar" ) . exists ( ) ) . isTrue ( ) ;
@ -74,9 +71,8 @@ public class RepackagingTests {
@Test
@Test
public void repackagingDisabledWithCustomRepackagedJar ( ) {
public void repackagingDisabledWithCustomRepackagedJar ( ) {
project . newBuild ( ) . forTasks ( "clean" , "build" , "customRepackagedJar" )
createBuildForTasks ( "clean" , "build" , "customRepackagedJar" )
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=false" ,
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=false" )
"-PexcludeDevtools=false" )
. run ( ) ;
. run ( ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
assertThat ( new File ( buildLibs , "repackage.jar" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage.jar" ) . exists ( ) ) . isTrue ( ) ;
@ -91,8 +87,7 @@ public class RepackagingTests {
public void repackagingDisabledWithCustomRepackagedJarUsingStringJarTaskReference ( ) {
public void repackagingDisabledWithCustomRepackagedJarUsingStringJarTaskReference ( ) {
project . newBuild ( )
project . newBuild ( )
. forTasks ( "clean" , "build" , "customRepackagedJarWithStringReference" )
. forTasks ( "clean" , "build" , "customRepackagedJarWithStringReference" )
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=false" ,
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=false" )
"-PexcludeDevtools=false" )
. run ( ) ;
. run ( ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
assertThat ( new File ( buildLibs , "repackage.jar" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage.jar" ) . exists ( ) ) . isTrue ( ) ;
@ -105,10 +100,8 @@ public class RepackagingTests {
@Test
@Test
public void repackagingEnabledWithCustomRepackagedJar ( ) {
public void repackagingEnabledWithCustomRepackagedJar ( ) {
project . newBuild ( ) . forTasks ( "clean" , "build" , "customRepackagedJar" )
createBuildForTasks ( "clean" , "build" , "customRepackagedJar" )
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=true" ,
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=true" ) . run ( ) ;
"-PexcludeDevtools=false" )
. run ( ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
assertThat ( new File ( buildLibs , "repackage.jar" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage.jar" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage.jar.original" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage.jar.original" ) . exists ( ) ) . isTrue ( ) ;
@ -122,9 +115,7 @@ public class RepackagingTests {
public void repackagingEnableWithCustomRepackagedJarUsingStringJarTaskReference ( ) {
public void repackagingEnableWithCustomRepackagedJarUsingStringJarTaskReference ( ) {
project . newBuild ( )
project . newBuild ( )
. forTasks ( "clean" , "build" , "customRepackagedJarWithStringReference" )
. forTasks ( "clean" , "build" , "customRepackagedJarWithStringReference" )
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=true" ,
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=true" ) . run ( ) ;
"-PexcludeDevtools=false" )
. run ( ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
assertThat ( new File ( buildLibs , "repackage.jar" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage.jar" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage.jar.original" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage.jar.original" ) . exists ( ) ) . isTrue ( ) ;
@ -138,10 +129,8 @@ public class RepackagingTests {
public void repackageWithFileDependency ( ) throws Exception {
public void repackageWithFileDependency ( ) throws Exception {
FileCopyUtils . copy ( new File ( "src/test/resources/foo.jar" ) ,
FileCopyUtils . copy ( new File ( "src/test/resources/foo.jar" ) ,
new File ( "target/repackage/foo.jar" ) ) ;
new File ( "target/repackage/foo.jar" ) ) ;
project . newBuild ( ) . forTasks ( "clean" , "build" )
createBuildForTasks ( "clean" , "build" )
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=true" ,
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=true" ) . run ( ) ;
"-PexcludeDevtools=false" )
. run ( ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
JarFile jarFile = new JarFile ( new File ( buildLibs , "repackage.jar" ) ) ;
JarFile jarFile = new JarFile ( new File ( buildLibs , "repackage.jar" ) ) ;
assertThat ( jarFile . getEntry ( "BOOT-INF/lib/foo.jar" ) ) . isNotNull ( ) ;
assertThat ( jarFile . getEntry ( "BOOT-INF/lib/foo.jar" ) ) . isNotNull ( ) ;
@ -149,10 +138,23 @@ public class RepackagingTests {
}
}
@Test
@Test
public void repackagingEnabledExcludeDevtools ( ) throws IOException {
public void devtoolsIsExcludedByDefault ( ) throws IOException {
project . newBuild ( ) . forTasks ( "clean" , "build" )
createBuildForTasks ( "clean" , "bootRepackage" )
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=true" ) . run ( ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
File repackageFile = new File ( buildLibs , "repackage.jar" ) ;
assertThat ( repackageFile . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage.jar.original" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage-sources.jar.original" ) . exists ( ) )
. isFalse ( ) ;
assertThat ( isDevToolsJarIncluded ( repackageFile ) ) . isFalse ( ) ;
}
@Test
public void devtoolsCanBeIncludedUsingTheExtension ( ) throws IOException {
createBuildForTasks ( "clean" , "bootRepackage" )
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=true" ,
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=true" ,
"-PexcludeDevtools=true" )
"-PexcludeDevtools OnExtension=fals e")
. run ( ) ;
. run ( ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
File repackageFile = new File ( buildLibs , "repackage.jar" ) ;
File repackageFile = new File ( buildLibs , "repackage.jar" ) ;
@ -160,20 +162,40 @@ public class RepackagingTests {
assertThat ( new File ( buildLibs , "repackage.jar.original" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage.jar.original" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage-sources.jar.original" ) . exists ( ) )
assertThat ( new File ( buildLibs , "repackage-sources.jar.original" ) . exists ( ) )
. isFalse ( ) ;
. isFalse ( ) ;
assertThat ( isDevToolsJarIncluded ( repackageFile ) ) . isFalse ( ) ;
assertThat ( isDevToolsJarIncluded ( repackageFile ) ) . isTrue ( ) ;
}
@Test
public void devtoolsCanBeIncludedUsingBootRepackage ( ) throws IOException {
createBuildForTasks ( "clean" , "bootRepackage" )
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=true" ,
"-PexcludeDevtoolsOnBootRepackage=false" )
. run ( ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
File repackageFile = new File ( buildLibs , "repackage.jar" ) ;
assertThat ( repackageFile . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage.jar.original" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "repackage-sources.jar.original" ) . exists ( ) )
. isFalse ( ) ;
assertThat ( isDevToolsJarIncluded ( repackageFile ) ) . isTrue ( ) ;
}
}
@Test
@Test
public void customRepackagingTaskWithOwnMainClassNameAnNoGlobalMainClassName ( ) {
public void customRepackagingTaskWithOwnMainClassNameAnNoGlobalMainClassName ( ) {
project . newBuild ( ) . forTasks ( "clean" , "customRepackagedJarWithOwnMainClass" )
createBuildF orTasks( "clean" , "customRepackagedJarWithOwnMainClass" )
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=true" ,
. withArguments ( "-PbootVersion=" + BOOT_VERSION , "-Prepackage=true" ,
"-PexcludeDevtools=false" , "-PnoMainClass=true" )
"-P noMainClass=true")
. run ( ) ;
. run ( ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
File buildLibs = new File ( "target/repackage/build/libs" ) ;
assertThat ( new File ( buildLibs , "custom.jar" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "custom.jar" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "custom.jar.original" ) . exists ( ) ) . isTrue ( ) ;
assertThat ( new File ( buildLibs , "custom.jar.original" ) . exists ( ) ) . isTrue ( ) ;
}
}
private BuildLauncher createBuildForTasks ( String . . . taskNames ) {
return project . newBuild ( ) . setStandardError ( System . err )
. setStandardOutput ( System . out ) . forTasks ( taskNames ) ;
}
private boolean isDevToolsJarIncluded ( File repackageFile ) throws IOException {
private boolean isDevToolsJarIncluded ( File repackageFile ) throws IOException {
JarFile jarFile = new JarFile ( repackageFile ) ;
JarFile jarFile = new JarFile ( repackageFile ) ;
try {
try {