Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5239d07
Migrate AbstractMavenModule to using Maven model APIs
Goooler Dec 10, 2024
fd998e5
Migrate MavenFileModule to using Maven model APIs
Goooler Dec 10, 2024
69c10b6
Use Dependency in AbstractMavenModule
Goooler Dec 11, 2024
d515e92
Tweak dependsOn params
Goooler Dec 11, 2024
9d773c4
Replace getMetaDataFileContent with getMetaData
Goooler Dec 11, 2024
5359464
Replace publishWithWriter with publishWithStream
Goooler Dec 11, 2024
bb11c97
Convert AbstractMavenModule
Goooler Dec 17, 2024
eb2e48d
Convert MavenFileModule
Goooler Dec 17, 2024
4f4940a
Convert MavenFileRepository
Goooler Dec 17, 2024
91696ab
Update AppendableJar
Goooler Dec 17, 2024
4b38755
Convert AppendableMavenFileModule
Goooler Dec 17, 2024
0e55748
Convert AppendableMavenFileRepository
Goooler Dec 17, 2024
37c0696
Rename PluginSpecification to BasePluginSpecification
Goooler Dec 17, 2024
a93eba6
Apply suggestions from code review
Goooler Dec 17, 2024
14ca389
Cleanups
Goooler Dec 17, 2024
290ac5a
Simplify JarBuilder
Goooler Dec 20, 2024
fc470ae
Simplify HashUtil
Goooler Dec 21, 2024
970bd5d
Simplify AbstractModule
Goooler Dec 21, 2024
83dfbbf
Mark rootDir public
Goooler Dec 25, 2024
b75ef13
Rename onPublish to postPublish
Goooler Dec 25, 2024
0e1d01c
Migrate File usages to Path
Goooler Dec 25, 2024
675403f
Simplify publish and postPublish
Goooler Dec 25, 2024
6877f81
Remove FileExtensions for Groovy
Goooler Dec 25, 2024
7b1314f
Seems we don't need escapedPath
Goooler Dec 25, 2024
1aee7bc
We don't need the overload for module
Goooler Dec 25, 2024
f9dffa7
Simplify AppendableMavenFileModule
Goooler Dec 25, 2024
4690e5d
Revert "Seems we don't need escapedPath"
Goooler Dec 25, 2024
d25fe18
Tweak AppendableJar
Goooler Dec 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ val intiTestRuntimeOnly: Configuration by configurations.getting {
val funcTest: SourceSet by sourceSets.creating
val funcTestImplementation: Configuration by configurations.getting {
extendsFrom(configurations.testImplementation.get())
// TODO: this will be removed after we migrated all functional tests to Kotlin.
extendsFrom(intiTestImplementation)
}
val funcTestRuntimeOnly: Configuration by configurations.getting {
extendsFrom(configurations.testRuntimeOnly.get())
Expand Down Expand Up @@ -88,6 +90,10 @@ dependencies {
funcTestImplementation(sourceSets.main.get().output)
funcTestImplementation(intiTest.output)

intiTestImplementation(libs.okio)
intiTestImplementation(libs.apache.maven.modelBuilder)
intiTestImplementation(libs.apache.maven.repositoryMetadata)

lintChecks(libs.androidx.gradlePluginLints)
lintChecks(libs.assertk.lint)
}
Expand Down
6 changes: 6 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
[versions]
maven = "3.9.9"

[libraries]
apache-ant = "org.apache.ant:ant:1.10.15"
apache-commonsIo = "commons-io:commons-io:2.18.0"
apache-commonsLang = "org.apache.commons:commons-lang3:3.17.0"
apache-log4j = "org.apache.logging.log4j:log4j-core:2.24.3"
apache-maven-modelBuilder = { module = "org.apache.maven:maven-model-builder", version.ref = "maven" }
apache-maven-repositoryMetadata = { module = "org.apache.maven:maven-repository-metadata", version.ref = "maven" }
asm = "org.ow2.asm:asm-commons:9.7.1"
jdependency = "org.vafer:jdependency:2.11"
jdom2 = "org.jdom:jdom2:2.0.6.1"
plexus-utils = "org.codehaus.plexus:plexus-utils:4.0.2"
plexus-xml = "org.codehaus.plexus:plexus-xml:4.0.4"
xmlunit = "org.xmlunit:xmlunit-legacy:2.10.0"
okio = "com.squareup.okio:okio:3.9.1"

pluginPublish = "com.gradle.publish:plugin-publish-plugin:1.3.0"
mavenPublish = "com.vanniktech:gradle-maven-publish-plugin:0.30.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.github.jengelman.gradle.plugins.shadow

import com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification
import org.apache.tools.zip.ZipFile
import org.gradle.testkit.runner.BuildResult
import spock.lang.Issue

import java.util.jar.Attributes
import java.util.jar.JarFile

class ApplicationSpec extends PluginSpecification {
class ApplicationSpec extends BasePluginSpecification {

def 'integration with application plugin'() {
given:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package com.github.jengelman.gradle.plugins.shadow.util
package com.github.jengelman.gradle.plugins.shadow

import com.github.jengelman.gradle.plugins.shadow.util.AppendableJar
import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenFileRepository
import org.codehaus.plexus.util.IOUtil
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import spock.lang.Specification
import spock.lang.TempDir

import java.nio.file.Path
import java.nio.file.Paths
import java.util.function.Function
import java.util.jar.JarEntry
import java.util.jar.JarFile

abstract class PluginSpecification extends Specification {
abstract class BasePluginSpecification extends Specification {

@TempDir
Path dir
Expand Down Expand Up @@ -118,7 +121,7 @@ abstract class PluginSpecification extends Specification {
}

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

void assertJarFileContentsEqual(File f, String path, String contents) {
Expand Down Expand Up @@ -161,7 +164,7 @@ abstract class PluginSpecification extends Specification {
}

AppendableJar buildJar(String path) {
return new AppendableJar(file(path))
return new AppendableJar(file(path).toPath())
}

protected File getOutput() {
Expand All @@ -172,8 +175,8 @@ abstract class PluginSpecification extends Specification {
getFile("build/libs/${name}")
}

protected File getTestJar(String name = 'junit-3.8.2.jar') {
return new File(this.class.classLoader.getResource(name).toURI())
protected Path getTestJar(String name = 'junit-3.8.2.jar') {
return Paths.get(this.class.classLoader.getResource(name).toURI())
}

protected static File getTestKitDir() {
Expand All @@ -183,4 +186,8 @@ abstract class PluginSpecification extends Specification {
}
return new File(gradleUserHome, "testkit")
}

protected static String escapedPath(Path path) {
return path.toString().replaceAll('\\\\', '\\\\\\\\')
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.github.jengelman.gradle.plugins.shadow

import com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification

class ConfigurationCacheSpec extends PluginSpecification {
class ConfigurationCacheSpec extends BasePluginSpecification {

@Override
def setup() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.github.jengelman.gradle.plugins.shadow

import com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification


class ConfigureShadowRelocationSpec extends PluginSpecification {
class ConfigureShadowRelocationSpec extends BasePluginSpecification {

def "auto relocate plugin dependencies"() {
given:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.github.jengelman.gradle.plugins.shadow

import com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.TaskOutcome
import spock.lang.Ignore
import spock.lang.Issue

class FilteringSpec extends PluginSpecification {
class FilteringSpec extends BasePluginSpecification {

@Override
def setup() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.github.jengelman.gradle.plugins.shadow

import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenFileRepository
import com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification
import groovy.json.JsonSlurper
import groovy.xml.XmlSlurper
import org.gradle.api.attributes.Bundling
import org.gradle.api.attributes.Usage
import spock.lang.Issue

class PublishingSpec extends PluginSpecification {
class PublishingSpec extends BasePluginSpecification {

AppendableMavenFileRepository publishingRepo

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

then:
File publishedFile = publishingRepo.rootDir.resolve('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').toFile().canonicalFile
assert publishedFile.exists()

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

and:
File pom = publishingRepo.rootDir.resolve('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').toFile().canonicalFile
assert pom.exists()

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

then:
File publishedFile = publishingRepo.rootDir.resolve('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').toFile().canonicalFile
assert publishedFile.exists()
}

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

then:
File publishedFile = publishingRepo.rootDir.resolve('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').toFile().canonicalFile
assert publishedFile.exists()

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

and:
File pom = publishingRepo.rootDir.resolve('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').toFile().canonicalFile
assert pom.exists()

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

then:
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
File mainJar = publishingRepo.rootDir.resolve('com/acme/maven/1.0/maven-1.0.jar').toFile().canonicalFile
File shadowJar = publishingRepo.rootDir.resolve('com/acme/maven/1.0/maven-1.0-all.jar').toFile().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.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
File pom = publishingRepo.rootDir.resolve('com/acme/maven/1.0/maven-1.0.pom').toFile().canonicalFile
File gmm = publishingRepo.rootDir.resolve('com/acme/maven/1.0/maven-1.0.module').toFile().canonicalFile
pom.exists()
gmm.exists()

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

and: "verify shadow publication"
assertions {
shadowJar = publishingRepo.rootDir.resolve('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').toFile().canonicalFile
assert shadowJar.exists()
contains(shadowJar, ['a.properties', 'a2.properties'])
}

assertions {
pom = publishingRepo.rootDir.resolve('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').toFile().canonicalFile
assert pom.exists()
pomContents = new XmlSlurper().parse(pom)
assert pomContents.dependencies[0].dependency.size() == 1
Expand All @@ -351,7 +350,7 @@ class PublishingSpec extends PluginSpecification {
}

assertions {
gmm = publishingRepo.rootDir.resolve('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').toFile().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
@@ -1,13 +1,12 @@
package com.github.jengelman.gradle.plugins.shadow

import com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification
import spock.lang.Ignore
import spock.lang.Issue

import java.util.jar.Attributes
import java.util.jar.JarFile

class RelocationSpec extends PluginSpecification {
class RelocationSpec extends BasePluginSpecification {

@Issue('SHADOW-58')
def "relocate dependency files"() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.jengelman.gradle.plugins.shadow

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
Expand All @@ -17,7 +16,7 @@ import spock.lang.Unroll
import java.util.jar.Attributes
import java.util.jar.JarFile

class ShadowPluginSpec extends PluginSpecification {
class ShadowPluginSpec extends BasePluginSpecification {

def 'apply plugin'() {
given:
Expand Down Expand Up @@ -63,7 +62,7 @@ class ShadowPluginSpec extends PluginSpecification {
@Unroll
def 'Compatible with Gradle #version'() {
given:
File one = buildJar('one.jar').insertFile('META-INF/services/shadow.Shadow',
def one = buildJar('one.jar').insert('META-INF/services/shadow.Shadow',
'one # NOTE: No newline terminates this line/file').write()

repo.module('shadow', 'two', '1.0').insertFile('META-INF/services/shadow.Shadow',
Expand Down Expand Up @@ -1272,8 +1271,4 @@ class ShadowPluginSpec extends PluginSpecification {
def jarFile = new JarFile(output("shadow-1.0-tests.jar"))
assert jarFile.getEntry('junit') != null
}

private String escapedPath(File file) {
file.path.replaceAll('\\\\', '\\\\\\\\')
}
}
Loading
Loading