Skip to content

Commit

Permalink
Re-initialise field on setClasspath
Browse files Browse the repository at this point in the history
Without that change, it became illegal to do something like
`setClasspath(files(someFile, getClasspath())` which can be used to
prepend values to the classpath.

Fixes #8748
  • Loading branch information
ljacomet committed Mar 13, 2019
1 parent 396b3ae commit ca39853
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ public List<CommandLineArgumentProvider> getArgumentProviders() {
}

public JavaExecHandleBuilder setClasspath(FileCollection classpath) {
doGetClasspath().setFrom(classpath);
ConfigurableFileCollection newClasspath = fileCollectionFactory.configurableFiles("classpath");
newClasspath.setFrom(classpath);
this.classpath = newClasspath;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.gradle.api.internal.file.FileCollectionFactory
import org.gradle.api.internal.file.TestFiles
import org.gradle.initialization.DefaultBuildCancellationToken
import org.gradle.internal.jvm.Jvm
import spock.lang.Issue
import spock.lang.Specification
import spock.lang.Unroll

Expand Down Expand Up @@ -104,6 +105,22 @@ class JavaExecHandleBuilderTest extends Specification {
builder.classpath.contains(jar2)
}

@Issue("gradle/gradle#8748")
def "can prepend to classpath"() {
given:
File jar1 = new File("file1.jar").canonicalFile
File jar2 = new File("file2.jar").canonicalFile

builder.classpath(jar1)

when:
builder.setClasspath(fileCollectionFactory.resolving(jar2, builder.getClasspath()))

then:
builder.commandLine.contains("$jar2$File.pathSeparator$jar1".toString())

}

def "detects null entries early"() {
when: builder.args(1, null)
then: thrown(IllegalArgumentException)
Expand Down

0 comments on commit ca39853

Please sign in to comment.