Skip to content

Commit

Permalink
CORDA-3228: Update Quasar utils plugin to support excluding classload…
Browse files Browse the repository at this point in the history
…ers. (#249)
  • Loading branch information
chrisr3 authored Sep 17, 2019
1 parent b3ad726 commit a6cd4cd
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 19 deletions.
5 changes: 4 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

### Version 5.0.3

* `webserver`: The `corda-webserver` component has been renamed to `corda-testserver.`
* `quasar-utils`: Add `excludeClassLoaders` option to the `quasar` extension. This option requires Quasar 0.7.12_r3 and above, excluding 0.8.0.

* `cordformation`: The `corda-webserver` component has been renamed to `corda-testserver.`

* `jar-filter`: Support for byte-code compiled by Kotlin >= 1.3.40 (See [KT-30289](https://youtrack.jetbrains.com/issue/KT-30289)).

### Version 5.0.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ class QuasarExtension {
* - debug
* - verbose
* - globs of packages not to instrument.
* - globs of classloaders not to instrument.
*/
final Property<Boolean> debug

final Property<Boolean> verbose

final ListProperty<String> excludePackages

final ListProperty<String> excludeClassLoaders

@PackageScope
final Provider<String> options

Expand All @@ -51,7 +54,8 @@ class QuasarExtension {
String defaultGroup,
String defaultVersion,
String defaultClassifier,
Iterable<? extends String> initialExclusions
Iterable<? extends String> initialPackageExclusions,
Iterable<? extends String> initialClassLoaderExclusions
) {
group = objects.property(String).convention(defaultGroup)
version = objects.property(String).convention(defaultVersion)
Expand All @@ -67,21 +71,28 @@ class QuasarExtension {
debug = objects.property(Boolean).convention(false)
verbose = objects.property(Boolean).convention(false)
excludePackages = objects.listProperty(String)
excludePackages.set(initialExclusions)
options = excludePackages.flatMap { excludes ->
debug.flatMap { isDebug ->
verbose.map { isVerbose ->
def builder = new StringBuilder('=')
if (isDebug) {
builder.append('d')
}
if (isVerbose) {
builder.append('v')
}
if (!excludes.isEmpty()) {
builder.append('x(').append(excludes.join(';')).append(')')
excludePackages.set(initialPackageExclusions)
excludeClassLoaders = objects.listProperty(String)
excludeClassLoaders.set(initialClassLoaderExclusions)
options = excludePackages.flatMap { packages ->
excludeClassLoaders.flatMap { classLoaders ->
debug.flatMap { isDebug ->
verbose.map { isVerbose ->
def builder = new StringBuilder('=')
if (isDebug) {
builder.append('d')
}
if (isVerbose) {
builder.append('v')
}
if (!packages.isEmpty()) {
builder.append('x(').append(packages.join(';')).append(')')
}
if (!classLoaders.isEmpty()) {
builder.append('l(').append(classLoaders.join(';')).append(')')
}
builder.length() == 1 ? '' : builder.toString()
}
builder.length() == 1 ? '' : builder.toString()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ class QuasarPlugin implements Plugin<Project> {
def quasarGroup = rootProject.hasProperty('quasar_group') ? rootProject.property('quasar_group') : defaultGroup
def quasarVersion = rootProject.hasProperty('quasar_version') ? rootProject.property('quasar_version') : defaultVersion
def quasarClassifier = rootProject.hasProperty('quasar_classifier') ? rootProject.property('quasar_classifier') : defaultClassifier
def quasarExclusions = rootProject.hasProperty("quasar_exclusions") ? rootProject.property('quasar_exclusions') : Collections.emptyList()
if (!(quasarExclusions instanceof Iterable<?>)) {
def quasarPackageExclusions = rootProject.hasProperty("quasar_exclusions") ? rootProject.property('quasar_exclusions') : Collections.emptyList()
if (!(quasarPackageExclusions instanceof Iterable<?>)) {
throw new InvalidUserDataException("quasar_exclusions property must be an Iterable<String>")
}
def quasarExtension = project.extensions.create(QUASAR, QuasarExtension, objects, quasarGroup, quasarVersion, quasarClassifier, quasarExclusions)
def quasarClassLoaderExclusions = rootProject.hasProperty("quasar_classloader_exclusions") ? rootProject.property('quasar_classloader_exclusions') : Collections.emptyList()
if (!(quasarClassLoaderExclusions instanceof Iterable<?>)) {
throw new InvalidUserDataException("quasar_classloader_exclusions property must be an Iterable<String>")
}
def quasarExtension = project.extensions.create(QUASAR, QuasarExtension, objects,
quasarGroup, quasarVersion, quasarClassifier, quasarPackageExclusions, quasarClassLoaderExclusions)

addQuasarDependencies(project, quasarExtension)
configureQuasarTasks(project, quasarExtension)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class QuasarPluginTest {

@BeforeEach
void setup() {
Utilities.installResource(testProjectDir, "gradle.properties")
Utilities.installResource(testProjectDir, "settings.gradle")
Utilities.installResource(testProjectDir, "repositories.gradle")
Utilities.installResource(testProjectDir, "src/test/java/BasicTest.java")
Expand Down Expand Up @@ -445,6 +446,41 @@ test {
}
}

@Test
void testExcludeClassLoaders() {
def output = runGradleFor """
plugins {
id 'net.corda.plugins.quasar-utils' apply false
}
apply plugin: 'net.corda.plugins.quasar-utils'
apply from: 'repositories.gradle'
dependencies {
testImplementation 'junit:junit:4.12'
}
quasar {
version = '0.7.12_r3'
excludeClassLoaders = [ 'net.corda.**', 'org.testing.*' ]
}
jar {
enabled = false
}
test {
doLast {
allJvmArgs.forEach {
println "TEST-JVM: \${it}"
}
}
}
""", "test"
assertThat(output).anyMatch {
it.startsWith("TEST-JVM: -javaagent:") && it.endsWith('=l(net.corda.**;org.testing.*)')
}
}

private List<String> runGradleFor(String script, String taskName) {
def result = runnerFor(script, taskName).build()
println result.output
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions quasar-utils/src/test/resources/repositories.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
repositories {
mavenCentral()
maven {
url 'https://software.r3.com/artifactory/corda-dependencies'
}
}

0 comments on commit a6cd4cd

Please sign in to comment.