Skip to content
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
57 changes: 52 additions & 5 deletions buildSrc/src/main/groovy/MuzzlePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MuzzlePlugin implements Plugin<Project> {
RemoteRepository akka = new RemoteRepository.Builder("akka", "default", "https://dl.bintray.com/akka/maven/").build()
RemoteRepository atlassian = new RemoteRepository.Builder("atlassian", "default", "https://maven.atlassian.com/content/repositories/atlassian-public/").build()
// MUZZLE_REPOS = Arrays.asList(central, sonatype, jcenter, spring, jboss, typesafe, akka, atlassian)
MUZZLE_REPOS = Arrays.asList(central, jcenter, typesafe)
MUZZLE_REPOS = Collections.unmodifiableList(Arrays.asList(central, jcenter, typesafe))
Comment thread
richardstartin marked this conversation as resolved.
Outdated
}

@Override
Expand Down Expand Up @@ -239,7 +239,7 @@ class MuzzlePlugin implements Plugin<Project> {
final Artifact directiveArtifact = new DefaultArtifact(muzzleDirective.group, muzzleDirective.module, "jar", muzzleDirective.versions)

final VersionRangeRequest rangeRequest = new VersionRangeRequest()
rangeRequest.setRepositories(MUZZLE_REPOS)
rangeRequest.setRepositories(muzzleDirective.getRepositories(MUZZLE_REPOS))
rangeRequest.setArtifact(directiveArtifact)
final VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest)
final Set<Version> versions = filterAndLimitVersions(rangeResult, muzzleDirective.skipVersions)
Expand All @@ -265,13 +265,14 @@ class MuzzlePlugin implements Plugin<Project> {
final Artifact allVersionsArtifact = new DefaultArtifact(muzzleDirective.group, muzzleDirective.module, "jar", "[,)")
final Artifact directiveArtifact = new DefaultArtifact(muzzleDirective.group, muzzleDirective.module, "jar", muzzleDirective.versions)

def repos = muzzleDirective.getRepositories(MUZZLE_REPOS)
final VersionRangeRequest allRangeRequest = new VersionRangeRequest()
allRangeRequest.setRepositories(MUZZLE_REPOS)
allRangeRequest.setRepositories(repos)
allRangeRequest.setArtifact(allVersionsArtifact)
final VersionRangeResult allRangeResult = system.resolveVersionRange(session, allRangeRequest)

final VersionRangeRequest rangeRequest = new VersionRangeRequest()
rangeRequest.setRepositories(MUZZLE_REPOS)
rangeRequest.setRepositories(repos)
rangeRequest.setArtifact(directiveArtifact)
final VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest)
final Set<Version> versions = rangeResult.versions.toSet()
Expand Down Expand Up @@ -422,7 +423,8 @@ class MuzzlePlugin implements Plugin<Project> {
private static filterVersion(Set<Version> list, Set<String> skipVersions) {
list.removeIf {
def version = it.toString().toLowerCase()
return version.contains("rc") ||
return version.endsWith("-snapshot") ||
version.contains("rc") ||
version.contains(".cr") ||
version.contains("alpha") ||
version.contains("beta") ||
Expand Down Expand Up @@ -464,6 +466,7 @@ class MuzzleDirective {
String versions
Set<String> skipVersions = new HashSet<>()
List<String> additionalDependencies = new ArrayList<>()
List<RemoteRepository> additionalRepositories = new ArrayList<>();
boolean assertPass
boolean assertInverse = false
boolean coreJdk = false
Expand All @@ -481,6 +484,34 @@ class MuzzleDirective {
additionalDependencies.add(compileString)
}

/**
* Adds extra repositories to the current muzzle test.
*
* @param id the repository id
* @param url the url of the repository
* @param type the type of repository, defaults to "default"
*/
void extraRepository(String id, String url, String type = "default") {
additionalRepositories.add(new RemoteRepository.Builder(id, type, url).build())
}

/**
* Get the list of repositories to use for this muzzle directive.
*
* @param defaults the default repositories
* @return a list of the default repositories followed by any additional repositories
*/
List<RemoteRepository> getRepositories(List<RemoteRepository> defaults) {
if (additionalRepositories.isEmpty()) {
return defaults
} else {
def repositories = new ArrayList<RemoteRepository>(defaults.size() + additionalRepositories.size())
repositories.addAll(defaults)
repositories.addAll(additionalRepositories)
return repositories
}
}

/**
* Slug of directive name.
*
Expand Down Expand Up @@ -509,6 +540,7 @@ class MuzzleDirective {
class MuzzleExtension {
final List<MuzzleDirective> directives = new ArrayList<>()
private final ObjectFactory objectFactory
private final List<RemoteRepository> additionalRepositories = new ArrayList<>()

@javax.inject.Inject
MuzzleExtension(final ObjectFactory objectFactory) {
Expand All @@ -531,10 +563,25 @@ class MuzzleExtension {
directives.add(fail)
}

/**
* Adds extra repositories to the current muzzle section. Repositories will only be added to directives
* created after this.
*
* @param id the repository id
* @param url the url of the repository
* @param type the type of repository, defaults to "default"
*/
void extraRepository(String id, String url, String type = "default") {
additionalRepositories.add(new RemoteRepository.Builder(id, type, url).build())
}


private postConstruct(MuzzleDirective directive) {
// Make skipVersions case insensitive.
directive.skipVersions = directive.skipVersions.collect {
it.toLowerCase()
}
// Add existing repositories
directive.additionalRepositories.addAll(additionalRepositories)
}
}
142 changes: 142 additions & 0 deletions dd-java-agent/instrumentation/mule-4/mule-4.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
}

muzzle {
extraRepository('anypoint-releases', 'https://maven.anypoint.mulesoft.com/api/v2/maven')
extraRepository('mulesoft-releases', 'https://repository.mulesoft.org/releases')
extraRepository('mulesoft-public', 'https://repository.mulesoft.org/nexus/content/repositories/public')

pass {
group = 'org.mule.runtime'
module = 'mule-core'
versions = '[,]'
assertInverse = true
}

fail {
group = 'org.mule'
module = 'mule-core'
versions = '[3.2.0,)' // First version where muzzle can resolve all dependencies
}
}

apply from: "$rootDir/gradle/java.gradle"

def muleVersion = '4.2.2'
def muleBaseDir = "$buildDir/mule"
def appDir = "$projectDir/mule-application"
def generatedResourcesDir = "$buildDir/generated-resources/test"

clean.doFirst {
delete muleBaseDir
}

repositories {
maven {
name "anypoint-releases"
url "https://maven.anypoint.mulesoft.com/api/v2/maven"
}
maven {
name "mulesoft-releases"
url "https://repository.mulesoft.org/releases"
}
maven {
name "mulesoft-public"
url "https://repository.mulesoft.org/nexus/content/repositories/public"
}
}

configurations {
muleServices
}

configurations.all {
// don't allow mule to do slf4j over log4j
exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j-impl'
}

sourceSets {
test {
output.dir(generatedResourcesDir, builtBy: 'generateAppResources')
}
}

compileTestGroovy {
dependsOn 'mvnPackage', 'extractMuleServices'
}

dependencies {
main_java8CompileOnly group: 'org.mule.runtime', name: 'mule-core', version: muleVersion

testImplementation project(':dd-java-agent:instrumentation:reactor-core-3.1')
testImplementation project(':dd-java-agent:instrumentation:grizzly-http-2.3.20')
testImplementation group: 'org.mule.runtime', name: 'mule-module-launcher', version: muleVersion
testImplementation group: 'org.mule.runtime', name: 'mule-core', version: muleVersion
testImplementation group: 'org.mule.runtime', name: 'mule-module-extensions-spring-support', version: muleVersion
testImplementation group: 'org.mule.runtime', name: 'mule-module-service', version: muleVersion
// this is needed for mule to find removed javax.* APIs on Java 11+
testImplementation group: 'org.mule.runtime', name: 'mule-module-javaee', version: muleVersion

muleServices group: 'org.mule.services', name: 'mule-service-http', version: '1.4.7', classifier: 'mule-service'
muleServices group: 'org.mule.services', name: 'mule-service-scheduler', version: '1.2.4', classifier: 'mule-service'
muleServices group: 'org.mule.services', name: 'mule-service-weave', version: '2.2.2', classifier: 'mule-service'
}

// extract the enabled services into the mule base directory
task extractMuleServices(type: Sync) {
dependsOn configurations.muleServices

configurations.muleServices.resolvedConfiguration.resolvedArtifacts.findAll {
it.classifier == "mule-service"
} collect { artifact ->
def id = artifact.moduleVersion.id
from(zipTree(artifact.file)) {
into("${id.name}-${id.version}")
}
}

into "$muleBaseDir/services"
}

// build the mule application via maven
task mvnPackage(type:Exec) {
workingDir "$appDir"
commandLine 'mvn', "-Ddatadog.builddir=$buildDir", "-Ddatadog.name=mule-http-test-server", "-Ddatadog.version=$version", 'package'
outputs.dir("$buildDir/target")
inputs.dir("$appDir/src")
inputs.file("$appDir/pom.xml")
inputs.file("$appDir/mule-artifact.json")
Comment thread
bantonsson marked this conversation as resolved.
}

// generate a properties file so the test knows where to run mule, and what jar to deploy
task generateAppResources {
outputs.dir generatedResourcesDir
doLast {
def generated = new File(generatedResourcesDir, "test-build.properties")
generated.text = """|mule.base=$muleBaseDir
|MuleHttpServerTest.jar=$buildDir/target/mule-http-test-server-$version-mule-application.jar
|MuleHttpServerTest.name=mule-http-test-server-$version-mule-application""".stripMargin()
}
}

tasks.test {
outputs.upToDateWhen {
!mvnPackage.didWork && !extractMuleServices.didWork
}
}

spotless {
java {
target fileTree("$appDir/src") {
include "**/*.java"
}
}
format 'xml', {
target fileTree('.') {
include '**/*.xml', '**/*.xsd'
exclude '**/build/**', '**/target/**'
}
eclipseWtp('xml').configFile(project.rootProject.rootDir.path + '/gradle/enforcement/spotless-xml.properties')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.mule
28 changes: 28 additions & 0 deletions dd-java-agent/instrumentation/mule-4/mule-application/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Working with the Mule Application

This directory contains a Mule application. It is built using maven, and unless
you know your Mule xml by heart the _easiest_ way is to download
[Anypoint Studio 7](https://www.mulesoft.com/lp/dl/studio).

## Configure Anypoint Studio

This Mule Application is currently built using version `4.2.2.` of Mule, so to avoid
problems, it is best to install the `4.2.2` runtime into Anypoint Studio.

Follow the instructions on how to [install a different mule runtime](https://mulesy.com/install-different-mule-runtime-version-in-studio/),
and select the `4.2.2 EE` version.

> **_Note:_** As of version 4 of Mule, there is no longer an update site that provides
> community versions of the Mule runtime, so the Enterprise Edition needs to be installed,
> even though the application can't use any of them.

## Importing the project into Anypoint Studio

* Start Anypoint Studio and create a _workspace_ somewhere unrelated to this directory.
* From the menu, select: **File** -> **Import...**.
* In the import dialog select: **Anypoint Studio** -> **Anypoint Studio project from File System**.
* Uncheck the **Copy project into workspace** checkbox.
* Select this directory as **Project Root**.
* Change **Server Runtime** to **Mule Server 4.2.2 EE**.
* Make sure that you have **unchecked** the **Copy project into workspace** checkbox.
* Press **Finish**.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"minMuleVersion": "4.2.2"
}
Loading