Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate redundant TestFile in functional tests #1083

Merged
merged 10 commits into from
Dec 3, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ class PublishingSpec extends PluginSpecification {
run('publish')

then:
File publishedFile = publishingRepo.rootDir.file('shadow/maven-all/1.0/maven-all-1.0.jar').canonicalFile
File publishedFile = publishingRepo.rootDir.resolve('shadow/maven-all/1.0/maven-all-1.0.jar').canonicalFile
assert publishedFile.exists()

and:
contains(publishedFile, ['a.properties', 'a2.properties'])

and:
File pom = publishingRepo.rootDir.file('shadow/maven-all/1.0/maven-all-1.0.pom').canonicalFile
File pom = publishingRepo.rootDir.resolve('shadow/maven-all/1.0/maven-all-1.0.pom').canonicalFile
assert pom.exists()

def contents = new XmlSlurper().parse(pom)
Expand Down Expand Up @@ -128,7 +128,7 @@ class PublishingSpec extends PluginSpecification {
run('publish')

then:
File publishedFile = publishingRepo.rootDir.file('shadow/maven-all/1.0/maven-all-1.0-my-classifier.my-ext').canonicalFile
File publishedFile = publishingRepo.rootDir.resolve('shadow/maven-all/1.0/maven-all-1.0-my-classifier.my-ext').canonicalFile
assert publishedFile.exists()
}

Expand Down Expand Up @@ -209,14 +209,14 @@ class PublishingSpec extends PluginSpecification {
run('publish')

then:
File publishedFile = publishingRepo.rootDir.file('shadow/maven-all/1.0/maven-all-1.0.jar').canonicalFile
File publishedFile = publishingRepo.rootDir.resolve('shadow/maven-all/1.0/maven-all-1.0.jar').canonicalFile
assert publishedFile.exists()

and:
contains(publishedFile, ['a.properties', 'a2.properties'])

and:
File pom = publishingRepo.rootDir.file('shadow/maven-all/1.0/maven-all-1.0.pom').canonicalFile
File pom = publishingRepo.rootDir.resolve('shadow/maven-all/1.0/maven-all-1.0.pom').canonicalFile
assert pom.exists()

def contents = new XmlSlurper().parse(pom)
Expand Down Expand Up @@ -273,17 +273,17 @@ class PublishingSpec extends PluginSpecification {
run('publish')

then:
File mainJar = publishingRepo.rootDir.file('com/acme/maven/1.0/maven-1.0.jar').canonicalFile
File shadowJar = publishingRepo.rootDir.file('com/acme/maven/1.0/maven-1.0-all.jar').canonicalFile
File mainJar = publishingRepo.rootDir.resolve('com/acme/maven/1.0/maven-1.0.jar').canonicalFile
File shadowJar = publishingRepo.rootDir.resolve('com/acme/maven/1.0/maven-1.0-all.jar').canonicalFile
assert mainJar.exists()
assert shadowJar.exists()

and:
contains(shadowJar, ['a.properties', 'a2.properties'])

and: "publishes both a POM file and a Gradle metadata file"
File pom = publishingRepo.rootDir.file('com/acme/maven/1.0/maven-1.0.pom').canonicalFile
File gmm = publishingRepo.rootDir.file('com/acme/maven/1.0/maven-1.0.module').canonicalFile
File pom = publishingRepo.rootDir.resolve('com/acme/maven/1.0/maven-1.0.pom').canonicalFile
File gmm = publishingRepo.rootDir.resolve('com/acme/maven/1.0/maven-1.0.module').canonicalFile
pom.exists()
gmm.exists()

Expand Down Expand Up @@ -328,13 +328,13 @@ class PublishingSpec extends PluginSpecification {

and: "verify shadow publication"
assertions {
shadowJar = publishingRepo.rootDir.file('com/acme/maven-all/1.0/maven-all-1.0-all.jar').canonicalFile
shadowJar = publishingRepo.rootDir.resolve('com/acme/maven-all/1.0/maven-all-1.0-all.jar').canonicalFile
assert shadowJar.exists()
contains(shadowJar, ['a.properties', 'a2.properties'])
}

assertions {
pom = publishingRepo.rootDir.file('com/acme/maven-all/1.0/maven-all-1.0.pom').canonicalFile
pom = publishingRepo.rootDir.resolve('com/acme/maven-all/1.0/maven-all-1.0.pom').canonicalFile
assert pom.exists()
pomContents = new XmlSlurper().parse(pom)
assert pomContents.dependencies[0].dependency.size() == 1
Expand All @@ -351,7 +351,7 @@ class PublishingSpec extends PluginSpecification {
}

assertions {
gmm = publishingRepo.rootDir.file('com/acme/maven-all/1.0/maven-all-1.0.module').canonicalFile
gmm = publishingRepo.rootDir.resolve('com/acme/maven-all/1.0/maven-all-1.0.module').canonicalFile
assert gmm.exists()
gmmContents = new JsonSlurper().parse(gmm)
assert gmmContents.variants.size() == 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AppendableMavenFileRepository extends MavenFileRepository {

@Override
AppendableMavenFileModule module(String groupId, String artifactId, Object version = '1.0') {
def artifactDir = rootDir.file("${groupId.replace('.', '/')}/$artifactId/$version")
def artifactDir = rootDir.resolve("${groupId.replace('.', '/')}/$artifactId/$version")
return new AppendableMavenFileModule(artifactDir, groupId, artifactId, version as String)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.jengelman.gradle.plugins.shadow.util

/**
* TODO: this is used as extensions for Groovy, could be replaced after migrated to Kotlin.
* Registered in resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule.
*/
final class FileExtensions {
static final File resolve(File file, String relativePath) {
try {
return new File(file, relativePath)
} catch (RuntimeException e) {
throw new RuntimeException(String.format("Could not locate file '%s' relative to '%s'.", Arrays.toString(relativePath), file), e)
}
}

static final File createDir(File file) {
if (file.mkdirs()) {
return file
}
if (file.isDirectory()) {
return file
}
throw new AssertionError("Problems creating dir: " + file
+ ". Diagnostics: exists=" + file.exists() + ", isFile=" + file.isFile() + ", isDirectory=" + file.isDirectory())
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.jengelman.gradle.plugins.shadow.util

import com.github.jengelman.gradle.plugins.shadow.util.file.TestFile
import org.codehaus.plexus.util.IOUtil
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
Expand Down Expand Up @@ -121,7 +120,7 @@ abstract class PluginSpecification extends Specification {
}

AppendableMavenFileRepository repo(String path = 'maven-repo') {
new AppendableMavenFileRepository(new TestFile(dir.toFile(), path))
new AppendableMavenFileRepository(dir.resolve(path).toFile())
}

void assertJarFileContentsEqual(File f, String path, String contents) {
Expand Down

This file was deleted.

Loading
Loading