Skip to content

Commit

Permalink
Merge pull request #790 from raphw/gradle-build-2
Browse files Browse the repository at this point in the history
Use coordinate of current Byte Buddy build
  • Loading branch information
raphw committed Dec 11, 2019
2 parents 9926e9d + 5ae2acb commit 8f6fbdf
Show file tree
Hide file tree
Showing 24 changed files with 198 additions and 104 deletions.
File renamed without changes.
15 changes: 2 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ jobs:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- name: Install JDK and build project (without Gradle)
- name: Install JDK and build project
run: |
. ./.github/scripts/install-jdk.sh --feature ea --os linux-x64
./mvnw verify -Pjava14 -pl !byte-buddy-gradle-plugin
./mvnw verify -Pjava14 -pl !byte-buddy-gradle-plugin
./mvnw verify -Pjava14
hotspot-supported:
name: HotSpot (supported)
strategy:
Expand All @@ -41,10 +40,6 @@ jobs:
architecture: x64
- name: Build project
run: ./mvnw verify -Pintegration -Pjava${{ matrix.java }}
if: matrix.java < 13
- name: Build project (without Gradle)
run: ./mvnw verify -Pintegration -Pjava${{ matrix.java }} -pl !byte-buddy-gradle-plugin
if: matrix.java > 12
hotspot-unsupported:
name: HotSpot (unsupported)
strategy:
Expand Down Expand Up @@ -90,12 +85,6 @@ jobs:
run: |
. ./.github/scripts/install-jdk.sh --url "https://api.adoptopenjdk.net/v2/binary/releases/openjdk${{ matrix.java }}?openjdk_impl=openj9&os=linux&arch=x64&release=latest&type=jdk&heap_size=normal"
./mvnw verify -Pintegration -Pjava${{ matrix.java }}
if: matrix.java < 13
- name: Install JDK and build project (without Gradle)
run: |
. ./.github/scripts/install-jdk.sh --url "https://api.adoptopenjdk.net/v2/binary/releases/openjdk${{ matrix.java }}?openjdk_impl=openj9&os=linux&arch=x64&release=latest&type=jdk&heap_size=normal"
./mvnw verify -Pintegration -Pjava${{ matrix.java }} -pl !byte-buddy-gradle-plugin
if: matrix.java > 12
coverage:
name: Coverage
runs-on: ubuntu-18.04
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ site/

# Gradle
byte-buddy-gradle-plugin/build/
byte-buddy-gradle-plugin/buildSrc
byte-buddy-gradle-plugin/gradle/build
.gradle/

Expand Down
2 changes: 1 addition & 1 deletion byte-buddy-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.10.2</version>
<version>1.10.4</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class JavaVersionRule implements MethodRule {

public JavaVersionRule() {
currentVersion = ClassFileVersion.ofThisVm();
openJ9 = System.getProperty("java.vm.vendor", "").toUpperCase(Locale.US).contains("J9");
openJ9 = System.getProperty("java.vm.name", "").toUpperCase(Locale.US).contains("J9");
}

public Statement apply(Statement base, FrameworkMethod method, Object target) {
Expand All @@ -40,9 +40,9 @@ public Statement apply(Statement base, FrameworkMethod method, Object target) {
if (openJ9 && !enforce.openJ9()) {
return new OpenJ9Statement();
} else if (enforce.value() != UNDEFINED && !version.isAtLeast(ClassFileVersion.ofJavaVersion(enforce.value()))) {
return new NoOpStatement(enforce.value(), "at least");
return new NoOpStatement(enforce.value(), "at least", enforce.target());
} else if (enforce.atMost() != UNDEFINED && !version.isAtMost(ClassFileVersion.ofJavaVersion(enforce.atMost()))) {
return new NoOpStatement(enforce.atMost(), "at most");
return new NoOpStatement(enforce.atMost(), "at most", enforce.target());
}
}
return base;
Expand All @@ -67,13 +67,18 @@ private static class NoOpStatement extends Statement {

private final String sort;

private NoOpStatement(int requiredVersion, String sort) {
private final Class<?> target;

private NoOpStatement(int requiredVersion, String sort, Class<?> target) {
this.requiredVersion = requiredVersion;
this.sort = sort;
this.target = target;
}

public void evaluate() {
Logger.getLogger("net.bytebuddy").warning("Ignoring test case: Requires a Java version of " + sort + " " + requiredVersion);
Logger.getLogger("net.bytebuddy").warning("Ignoring test case: Requires a Java version " +
"of " + sort + " " + requiredVersion
+ (target == void.class ? "" : (" for target " + target)));
}
}

Expand Down
6 changes: 3 additions & 3 deletions byte-buddy-dep/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<plugin>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-maven-plugin</artifactId>
<version>1.10.2</version>
<version>1.10.4</version>
<executions>
<execution>
<phase>compile</phase>
Expand All @@ -116,13 +116,13 @@
<transformation>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.10.2</version>
<version>1.10.4</version>
<plugin>net.bytebuddy.build.HashCodeAndEqualsPlugin$WithNonNullableFields</plugin>
</transformation>
<transformation>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.10.2</version>
<version>1.10.4</version>
<plugin>net.bytebuddy.build.CachedReturnPlugin</plugin>
</transformation>
</transformations>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ public S load() {
* @param annotation The annotation to convert.
* @return A mapping of property names to their annotation value.
*/
@SuppressWarnings("unchecked")
private static Map<String, AnnotationValue<?, ?>> asValue(Annotation annotation) {
Map<String, AnnotationValue<?, ?>> annotationValues = new HashMap<String, AnnotationValue<?, ?>>();
for (Method property : annotation.annotationType().getDeclaredMethods()) {
Expand Down Expand Up @@ -621,6 +622,7 @@ public S load() {
/**
* {@inheritDoc}
*/
@SuppressWarnings("deprecation")
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Exception should always be wrapped for clarity")
public AnnotationValue<?, ?> getValue(MethodDescription.InDefinedShape property) {
if (!property.getDeclaringType().represents(annotation.annotationType())) {
Expand Down Expand Up @@ -1040,7 +1042,6 @@ public Builder defineTypeArray(String property, Class<?>... type) {
* @param typeDescription Descriptions of the types that should be contained by the array.
* @return A builder with the additional type array property.
*/
@SuppressWarnings("unchecked")
public Builder defineTypeArray(String property, TypeDescription... typeDescription) {
return define(property, AnnotationValue.ForDescriptionArray.of(typeDescription));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,7 @@ public void testConstructorIsAccessibleFromDifferentPackage() throws Exception {
.make()
.load(Foo.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
.getLoaded()
.getConstructor()
.newInstance(), instanceOf(ProtectedConstructor.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class JavaVersionRule implements MethodRule {

public JavaVersionRule() {
currentVersion = ClassFileVersion.ofThisVm();
openJ9 = System.getProperty("java.vm.vendor", "").toUpperCase(Locale.US).contains("J9");
openJ9 = System.getProperty("java.vm.name", "").toUpperCase(Locale.US).contains("J9");
}

public Statement apply(Statement base, FrameworkMethod method, Object target) {
Expand All @@ -40,9 +40,9 @@ public Statement apply(Statement base, FrameworkMethod method, Object target) {
if (openJ9 && !enforce.openJ9()) {
return new OpenJ9Statement();
} else if (enforce.value() != UNDEFINED && !version.isAtLeast(ClassFileVersion.ofJavaVersion(enforce.value()))) {
return new NoOpStatement(enforce.value(), "at least");
return new NoOpStatement(enforce.value(), "at least", enforce.target());
} else if (enforce.atMost() != UNDEFINED && !version.isAtMost(ClassFileVersion.ofJavaVersion(enforce.atMost()))) {
return new NoOpStatement(enforce.atMost(), "at most");
return new NoOpStatement(enforce.atMost(), "at most", enforce.target());
}
}
return base;
Expand All @@ -67,13 +67,18 @@ private static class NoOpStatement extends Statement {

private final String sort;

private NoOpStatement(int requiredVersion, String sort) {
private final Class<?> target;

private NoOpStatement(int requiredVersion, String sort, Class<?> target) {
this.requiredVersion = requiredVersion;
this.sort = sort;
this.target = target;
}

public void evaluate() {
Logger.getLogger("net.bytebuddy").warning("Ignoring test case: Requires a Java version of " + sort + " " + requiredVersion);
Logger.getLogger("net.bytebuddy").warning("Ignoring test case: Requires a Java version " +
"of " + sort + " " + requiredVersion
+ (target == void.class ? "" : (" for target " + target)));
}
}

Expand Down
50 changes: 49 additions & 1 deletion byte-buddy-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,54 @@
plugins {
id 'java'
id 'java-gradle-plugin'
id 'com.gradle.plugin-publish' version '0.10.1'
}

apply from: './main.gradle'
apply from: './main.gradle'

version = pom.parent.version.text().toString()

if (gradle.gradleVersion.startsWith("2.")) { // support legacy version
dependencies {
compile gradleApi()
compile "net.bytebuddy:byte-buddy:${version}"
testCompile gradleTestKit()
testCompile group: 'junit', name: 'junit', version: outerPom.properties.'version.junit'
testCompile(group: 'org.mockito', name: 'mockito-core', version: outerPom.properties.'version.mockito') {
exclude group: 'net.bytebuddy'
}
}
} else {
dependencies {
implementation gradleApi()
implementation "net.bytebuddy:byte-buddy:${version}"
testImplementation gradleTestKit()
testImplementation group: 'junit', name: 'junit', version: outerPom.properties.'version.junit'
testImplementation(group: 'org.mockito', name: 'mockito-core', version: outerPom.properties.'version.mockito') {
exclude group: 'net.bytebuddy'
}
}
}

configurations.all {
resolutionStrategy.dependencySubstitution {
substitute module("net.bytebuddy:byte-buddy:${version}") with project(":mavenBridge")
}
}

pluginBundle {
website = 'https://bytebuddy.net'
vcsUrl = 'https://github.com/raphw/byte-buddy'
tags = ['Byte Buddy', 'bytecode', 'enhancement']
}

gradlePlugin {
plugins {
byteBuddyPlugin {
id = pom.parent.groupId.text().toString() + '.' + pom.artifactId.text().toString()
displayName = pom.name.text().toString()
description = pom.description.text().toString()
implementationClass = 'net.bytebuddy.build.gradle.ByteBuddyPlugin'
}
}
}
42 changes: 42 additions & 0 deletions byte-buddy-gradle-plugin/build.simple.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
plugins {
id 'java'
id 'java-gradle-plugin'
}

apply from: './main.gradle'

version = pom.parent.version.text().toString()

// At this point, it is not given that any artifact from the Maven build can be found in a repository.
def location = new File(project.buildscript.sourceFile.getParentFile(), "../byte-buddy/target/byte-buddy-${version}.jar").canonicalFile
logger.info("Relying on ${location.absolutePath} as Byte Buddy dependency")

if (gradle.gradleVersion.startsWith("2.")) { // support legacy version
dependencies {
compile gradleApi()
if (location.exists()) {
compile files(location.absolutePath)
} else {
logger.warn("${location.absolutePath} does not exist, can clean but not build project")
}
testCompile gradleTestKit()
testCompile group: 'junit', name: 'junit', version: outerPom.properties.'version.junit'
testCompile(group: 'org.mockito', name: 'mockito-core', version: outerPom.properties.'version.mockito') {
exclude group: 'net.bytebuddy'
}
}
} else {
dependencies {
implementation gradleApi()
if (location.exists()) {
implementation files(location.absolutePath)
} else {
logger.warn("${location.absolutePath} does not exist, can clean but not build project")
}
testImplementation gradleTestKit()
testImplementation group: 'junit', name: 'junit', version: outerPom.properties.'version.junit'
testImplementation(group: 'org.mockito', name: 'mockito-core', version: outerPom.properties.'version.mockito') {
exclude group: 'net.bytebuddy'
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=gradle-5.4.1-bin.zip
distributionUrl=gradle-6.0.1-bin.zip
4 changes: 2 additions & 2 deletions byte-buddy-gradle-plugin/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ case "`uname`" in
esac

# Java 6 and 7 are no longer supported by Gradle 5 which is why we are using an old version of Gradle if those are detected.
if `java -fullversion 2>&1 >/dev/null | awk '{print $4}' | grep -Eq "^\"1\.[67]\."`; then
if `$JAVA_HOME/bin/java -fullversion 2>&1 >/dev/null | awk '{print $4}' | grep -Eq "^\"1\.[67]\."`; then
GRADLE_VERSION="2.14.1"
else
GRADLE_VERSION="5.4.1"
GRADLE_VERSION="6.0.1"
fi

CLASSPATH=$APP_HOME/gradle/${GRADLE_VERSION}/gradle-wrapper.jar
Expand Down
4 changes: 2 additions & 2 deletions byte-buddy-gradle-plugin/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ set CMD_LINE_ARGS=%*
@rem Setup the command line

@rem Java 6 and 7 are no longer supported by Gradle 5 which is why we are using an old version of Gradle if those are detected.
for /f tokens^=2-5^ delims^=.-_^" %%j in ('java -fullversion 2^>^&1') do set "JAVA_VERSION_STRING=%%j%%k%%l%%m"
for /f tokens^=2-5^ delims^=.-_^" %%j in ('%JAVA_HOME%\bin\java -fullversion 2^>^&1') do set "JAVA_VERSION_STRING=%%j%%k%%l%%m"
IF "%JAVA_VERSION_STRING:~0,3%"=="160" (
set "GRADLE_VERSION=2.14.1"
) ELSE (IF "%JAVA_VERSION_STRING:~0,3%"=="170" (
set "GRADLE_VERSION=2.14.1"
) ELSE (
set "GRADLE_VERSION=5.4.1"
set "GRADLE_VERSION=6.0.1"
))

set CLASSPATH=%APP_HOME%\gradle\%GRADLE_VERSION%\gradle-wrapper.jar
Expand Down
25 changes: 4 additions & 21 deletions byte-buddy-gradle-plugin/main.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
def pom = new XmlSlurper().parse(file('./pom.xml'))
def outerPom = new XmlSlurper().parse(file('../pom.xml'))
ext.pom = new XmlSlurper().parse(file('./pom.xml'))
ext.outerPom = new XmlSlurper().parse(file('../pom.xml'))

group = pom.parent.groupId.text().toString()
version = pom.parent.version.text().toString()
description = pom.description.text().toString()

// Gradle cannot process all version strings such that JavaVersion.current() fails.
def raw = System.getProperty("java.version")
def current;
def current
if (!raw.startsWith("1.") && raw.contains(".")) {
current = JavaVersion.toVersion(raw.substring(0, raw.indexOf('.')))
} else {
Expand Down Expand Up @@ -42,23 +42,6 @@ repositories {
mavenCentral()
}

dependencies {
compile gradleApi()
// At this point, it is not given that any artifact from the Maven build can be found in a repository.
def location = new File(project.buildscript.sourceFile.getParentFile(), "../byte-buddy/target/byte-buddy-${version}.jar").canonicalFile
logger.info("Relying on ${location.absolutePath} as Byte Buddy dependency")
if (location.exists()) {
compile files(location.absolutePath)
} else {
logger.warn("${location.absolutePath} does not exist, can clean but not build project")
}
testCompile gradleTestKit()
testCompile group: 'junit', name: 'junit', version: outerPom.properties.'version.junit'
testCompile(group: 'org.mockito', name: 'mockito-core', version: outerPom.properties.'version.mockito') {
exclude group: 'net.bytebuddy'
}
}

// Without the extras property, creating a javadoc artifact is not necessary.
if (Boolean.getBoolean('net.bytebuddy.misc.extras')) {
task javadocJar(type: Jar, dependsOn: javadoc) {
Expand All @@ -80,7 +63,7 @@ task copyLicense(type: Copy) {
from '..'
include 'LICENSE', 'NOTICE'
into "$buildDir/resources/main/META-INF"
def pattern = java.util.regex.Pattern.compile('\\$\\{([a-zA-Z0-9\\-._]+)}');
def pattern = java.util.regex.Pattern.compile('\\$\\{([a-zA-Z0-9\\-._]+)}')
filter { String line ->
def matcher = pattern.matcher(line)
def buffer = new StringBuffer()
Expand Down
18 changes: 18 additions & 0 deletions byte-buddy-gradle-plugin/mavenBridge/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version = pom.parent.version.toString()

configurations {
mavenBridge {
canBeResolved = false
canBeConsumed = true
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, 'java-runtime'))
}
outgoing.artifact(objects.fileProperty().fileProvider(providers.provider {
def file = rootProject.file("../byte-buddy/target/byte-buddy-${version}.jar")
if (!file.exists()) {
throw new GradleException("Cannot resolve ${version} of byte-buddy artifact what is required for a substitution")
}
file
}))
}
}
Loading

0 comments on commit 8f6fbdf

Please sign in to comment.