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

Use common pkger #96

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {
}

dependencies {
implementation "io.gatling:gatling-enterprise-plugin-commons:1.8.0"
implementation "io.gatling:gatling-enterprise-plugin-commons:1.9.0-M6"
implementation "org.apache.ant:ant:1.10.11"
constraints {
implementation('com.fasterxml.jackson.core:jackson-databind') {
Expand Down
132 changes: 75 additions & 57 deletions src/main/groovy/io/gatling/gradle/GatlingEnterprisePackageTask.groovy
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
package io.gatling.gradle

import io.gatling.plugin.pkg.Dependency
import io.gatling.plugin.pkg.EnterprisePackager
import org.gradle.api.DefaultTask
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ResolvedConfiguration
import org.gradle.api.artifacts.ResolvedDependency
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.file.FileCollection
import org.gradle.api.internal.file.copy.CopyAction
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Classpath
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.plugins.BasePluginExtension
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.*

@CacheableTask
class GatlingEnterprisePackageTask extends Jar {
class GatlingEnterprisePackageTask extends DefaultTask {

private static final Set<String> EXCLUDED_NETTY_ARTIFACTS = [ "netty-all", "netty-resolver-dns-classes-macos", "netty-resolver-dns-native-macos" ].asUnmodifiable()
private static final Set<String> EXCLUDED_NETTY_ARTIFACTS = ["netty-all", "netty-resolver-dns-classes-macos", "netty-resolver-dns-native-macos"].asUnmodifiable()
private static final String JAR_EXTENSION = '.jar'
private static final ARCHIVE_CLASSIFIER = 'tests'

@Classpath @Optional
List<Configuration> configurations

GatlingEnterprisePackageTask() {
super()
setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
}

@TaskAction
void copy() {
String gatlingVersion = gatlingVersion()
manifest {
attributes("Manifest-Version": "1.0",
"Implementation-Title": project.name,
"Implementation-Version": project.version,
"Implementation-Vendor": project.group,
"Specification-Vendor": "GatlingCorp",
"Gatling-Version": gatlingVersion,
"Gatling-Packager": "gradle")
}
from(getIncludedDependencies())
super.copy()
private static Set<Dependency> toDependencies(Set<ResolvedDependency> deps) {
deps.collectMany { resolvedDependency ->
resolvedDependency.getModuleArtifacts().collect(moduleArtifact ->
new Dependency(
resolvedDependency.module.id.group,
resolvedDependency.module.id.name,
resolvedDependency.module.id.version,
moduleArtifact.file
))
}.toSet()
}

@Classpath
FileCollection getIncludedDependencies() {
ResolvedConfiguration resolvedConfiguration = getResolvedConfiguration()
@Optional
List<Configuration> configurations

Set<ResolvedDependency> gatlingDependencies = new HashSet<ResolvedDependency>()
collectGatlingDepsRec(resolvedConfiguration.getFirstLevelModuleDependencies(), gatlingDependencies)
@Internal
BasePluginExtension basePluginExtension = project.extensions.getByType(BasePluginExtension)

project.files(resolvedConfiguration.files) - project.files(gatlingDependencies.collect {
it.moduleArtifacts*.file
}.flatten())
}
@OutputFile
final RegularFileProperty outputFile = project.objects.fileProperty().fileValue(getJarFile())

@Override
protected CopyAction createCopyAction() {
return new GatlingEnterpriseCopyAction(
this.archiveFile.get().asFile,
getMetadataCharset(),
getMainSpec().buildRootResolver().getPatternSet(),
isPreserveFileTimestamps(),
getEntryCompression(),
isZip64()
@TaskAction
void createArchive() {
EnterprisePackager packager = new EnterprisePackager(new GradlePluginIO(logger).getLogger())
ResolvedConfiguration resolvedConfiguration = getResolvedConfiguration()
packager.createEnterprisePackage(
getClassDirectories(),
collectGatlingDependencies(resolvedConfiguration.getFirstLevelModuleDependencies()),
collectExtraDependencies(resolvedConfiguration.getFirstLevelModuleDependencies()),
project.group,
project.name,
project.version,
'gradle',
getClass().getPackage().getImplementationVersion(),
outputFile.asFile.get()
)
}

private String gatlingVersion() {
for (artifact in getResolvedConfiguration().resolvedArtifacts.flatten()) {
def id = artifact.moduleVersion.id
if (id.group == "io.gatling" && id.name == "gatling-app") {
logger.debug("Detected Gatling compile version: {}", id.version)
return id.version
private File getJarFile() {
String jarVersion = project.version != 'unspecified' ? '-' + (project.version) : ''
new File(
basePluginExtension.libsDirectory.get().asFile,
project.name +
jarVersion +
'-' + ARCHIVE_CLASSIFIER +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure: does this generate the same file name as before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, that's my intention. I started to map what you done in the maven plugin (with the .shaded.jar extension) and the integration tests were no longer passing.

So I reproduce the name schema of the AbstractArchiveTask that the previous task inherit before.

Now, IT still ok, and there is the version before de tests classifier when a version is defined.

JAR_EXTENSION)
}

private List<File> getClassDirectories() {
project.getAllprojects().collect { p ->
JavaPluginExtension javaPluginExtension = p.getExtensions().getByType(JavaPluginExtension.class)
slandelle marked this conversation as resolved.
Show resolved Hide resolved
javaPluginExtension.getSourceSets().collect {
sourceSet -> sourceSet.output.asList()
}
}
throw new IllegalArgumentException("Couldn't locate io.gatling:gatling-app in dependencies")
}.flatten()
}

private ResolvedConfiguration getResolvedConfiguration() {
Expand All @@ -100,4 +100,22 @@ class GatlingEnterprisePackageTask extends Jar {
}
}
}

private Set<Dependency> collectAllDependencies(Set<ResolvedDependency> firstLevelDependencies) {
Set<ResolvedDependency> deps = new HashSet<>()
for (dependency in firstLevelDependencies) {
collectDepAndChildren(dependency, deps)
}
return toDependencies(deps)
}

private Set<Dependency> collectGatlingDependencies(Set<ResolvedDependency> firstLevelDependencies) {
Set<ResolvedDependency> deps = new HashSet<>()
collectGatlingDepsRec(firstLevelDependencies, deps)
return toDependencies(deps)
}

private Set<Dependency> collectExtraDependencies(Set<ResolvedDependency> firstLevelDependencies) {
return collectAllDependencies(firstLevelDependencies) - collectGatlingDependencies(firstLevelDependencies)
}
}
38 changes: 0 additions & 38 deletions src/main/groovy/io/gatling/gradle/GatlingPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -125,48 +125,10 @@ final class GatlingPlugin implements Plugin<Project> {

TaskProvider<GatlingEnterprisePackageTask> registerEnterprisePackageTask(Project project) {
TaskProvider<GatlingEnterprisePackageTask> gatlingEnterprisePackage = project.tasks.register(ENTERPRISE_PACKAGE_TASK_NAME, GatlingEnterprisePackageTask.class) {packageTask ->
packageTask.archiveClassifier.set("tests")

packageTask.exclude(
"module-info.class",
"META-INF/LICENSE",
"META-INF/MANIFEST.MF",
"META-INF/versions/**",
"META-INF/maven/**",
"**/*.SF",
"**/*.DSA",
"**/*.RSA"
)

packageTask.from(project.sourceSets.gatling.output)

packageTask.configurations = [
project.configurations.gatlingRuntimeClasspath
]

packageTask.metaInf {
def tempDir = new File(packageTask.getTemporaryDir(), "META-INF")
def maven = new File(tempDir, "maven")
maven.mkdirs()
new File(maven,"pom.properties").text =
"""groupId=${project.group}
|artifactId=${project.name}
|version=${project.version}
|""".stripMargin()
new File(maven, "pom.xml").text =
"""<?xml version="1.0" encoding="UTF-8"?>
|<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
| <modelVersion>4.0.0</modelVersion>
| <groupId>${project.group}</groupId>
| <artifactId>${project.name}</artifactId>
| <version>${project.version}</version>
|</project>
|""".stripMargin()
from (tempDir)
}
}

gatlingEnterprisePackage
}

Expand Down