forked from reactor/reactor-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
215 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...tools/src/buildPluginTest/java/reactor/tools/agent/ApplyingByteBuddyPluginGradleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2021 VMware Inc. or its affiliates, All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package reactor.tools.agent; | ||
|
||
import java.io.File; | ||
|
||
import org.gradle.testkit.runner.BuildResult; | ||
import org.gradle.testkit.runner.BuildTask; | ||
import org.gradle.testkit.runner.GradleRunner; | ||
import org.gradle.testkit.runner.TaskOutcome; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
/** | ||
* @author Simon Baslé | ||
*/ | ||
class ApplyingByteBuddyPluginGradleTest { | ||
|
||
static File testProjectDir; | ||
|
||
@BeforeEach | ||
void setup() { | ||
String testProjectPath = System.getProperty("mock-gradle-dir"); | ||
assertNotNull(testProjectPath, "Cannot find testProjectPath, set or verify -Dmock-gradle-dir"); | ||
testProjectDir = new File(testProjectPath); | ||
assertTrue(testProjectDir.exists() && testProjectDir.isDirectory(), "testProjectDir not created correctly"); | ||
} | ||
|
||
@Test | ||
void applyingByteBuddyPluginDuringGradleBuild() { | ||
BuildResult result = GradleRunner.create() | ||
.withProjectDir(testProjectDir) | ||
.withDebug(true) | ||
.withArguments("test", "--info", "--stacktrace") | ||
.build(); | ||
|
||
//the test task in reactor-tools/src/buildPluginTest/resources/mock-gradle/src/test/java/demo/SomeClassTest.java | ||
//checks that applying the reactor-tool ByteBuddy plugin in Gradle instruments prod code but not test code. | ||
|
||
assertTrue(result.getOutput().contains("test")); | ||
final BuildTask task = result.task(":test"); | ||
assertNotNull(task); | ||
assertEquals(TaskOutcome.SUCCESS, task.getOutcome()); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
reactor-tools/src/buildPluginTest/resources/mock-gradle/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2021 VMware Inc. or its affiliates, All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
//the plugin feature only works with the -original jar !! | ||
//otherwise implemented Plugin interface is the shaded one | ||
classpath files("@AGENT@") | ||
} | ||
} | ||
|
||
plugins { | ||
id "net.bytebuddy.byte-buddy-gradle-plugin" version "@BYTE_BUDDY_VERSION@" | ||
id 'java' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
ext { | ||
//smoke test to fail the mock gradle if it is wrongly configured with the shaded jar rather than the original | ||
if (!"@AGENT@".endsWith("-original.jar")) { | ||
throw new GradleException("The build file must be configured with reactor-tools' -original.jar version !!") | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation "org.reactivestreams:reactive-streams:@REACTIVE_STREAMS_VERSION@" | ||
implementation files("@CORE@") | ||
|
||
testImplementation platform("org.junit:junit-bom:@JUNIT_BOM_VERSION@") | ||
testImplementation "org.junit.jupiter:junit-jupiter-api" | ||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine" | ||
|
||
testImplementation "org.assertj:assertj-core:3.20.2" | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} | ||
|
||
byteBuddy { | ||
transformation { | ||
plugin = reactor.tools.agent.ReactorDebugByteBuddyPlugin.class | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
reactor-tools/src/buildPluginTest/resources/mock-gradle/settings.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright (c) 2021 VMware Inc. or its affiliates, All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
rootProject.name = 'bytebuddy-and-reactoragent' |
27 changes: 27 additions & 0 deletions
27
reactor-tools/src/buildPluginTest/resources/mock-gradle/src/main/java/demo/SomeClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2021 VMware Inc. or its affiliates, All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package demo; | ||
|
||
import reactor.core.publisher.Flux; | ||
|
||
public class SomeClass { | ||
|
||
public Flux<Integer> obtainFlux() { | ||
return Flux.just(1); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters