From 1f0dc02a5dc7ca7473c387f8a391d7c21cf96baa Mon Sep 17 00:00:00 2001 From: SciWhiz12 Date: Sat, 15 May 2021 11:22:48 +0800 Subject: Update build.gradle to new Forge Maven url --- build.gradle | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index a1aa9e9..f73cc9b 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,9 @@ sourceSets { repositories { jcenter() mavenCentral() + maven { + url = 'https://maven.minecraftforge.net' + } } configurations { @@ -147,12 +150,15 @@ publishing { } repositories { maven { - if (project.hasProperty('mavenPassword')) { + if (System.env.MAVEN_USER) { + url 'https://maven.minecraftforge.net/' + authentication { + basic(BasicAuthentication) + } credentials { - username = project.properties.mavenUser - password = project.properties.mavenPassword + username = System.env.MAVEN_USER ?: 'not' + password = System.env.MAVEN_PASSWORD ?: 'set' } - url 'https://files.minecraftforge.net/maven/manage/upload' } else { url 'file://' + rootProject.file('repo').getAbsolutePath() } -- cgit From 6218dc6442d90e7fa0e385b39ef1dbd8c36b9a1d Mon Sep 17 00:00:00 2001 From: SciWhiz12 Date: Sat, 15 May 2021 11:23:10 +0800 Subject: Update Jenkinsfile Based off of ForgeGradle's Jenkinsfile. --- Jenkinsfile | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ff1ebbf..7e93cc7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,18 +3,23 @@ pipeline { agent { docker { - image 'gradlewrapper:j10' + image 'gradle:jdk8' args '-v gradlecache:/gradlecache' } } environment { - GRADLE_ARGS = '-Dorg.gradle.daemon.idletimeout=5000 --console=plain' + GRADLE_ARGS = '-Dorg.gradle.daemon.idletimeout=5000' DISCORD_WEBHOOK = credentials('forge-discord-jenkins-webhook') DISCORD_PREFIX = "Job: Artifactural Branch: ${BRANCH_NAME} Build: #${BUILD_NUMBER}" JENKINS_HEAD = 'https://wiki.jenkins-ci.org/download/attachments/2916393/headshot.png' } stages { + stage('fetch') { + steps { + checkout scm + } + } stage('notify_start') { when { not { @@ -33,7 +38,9 @@ pipeline { } stage('buildandtest') { steps { - sh './gradlew ${GRADLE_ARGS} --refresh-dependencies --continue build test' + withGradle { + sh './gradlew ${GRADLE_ARGS} --refresh-dependencies --continue build test' + } script { env.MYGROUP = sh(returnStdout: true, script: './gradlew properties -q | grep "group:" | awk \'{print $2}\'').trim() env.MYARTIFACT = sh(returnStdout: true, script: './gradlew properties -q | grep "name:" | awk \'{print $2}\'').trim() @@ -47,12 +54,17 @@ pipeline { changeRequest() } } - environment { - FORGE_MAVEN = credentials('forge-maven-forge-user') - } steps { - sh './gradlew ${GRADLE_ARGS} publish -PmavenUser=${FORGE_MAVEN_USR} -PmavenPassword=${FORGE_MAVEN_PSW}' - sh 'curl --user ${FORGE_MAVEN} https://files.minecraftforge.net/maven/manage/promote/latest/${MYGROUP}.${MYARTIFACT}/${MYVERSION}' + withCredentials([usernamePassword(credentialsId: 'maven-forge-user', usernameVariable: 'MAVEN_USER', passwordVariable: 'MAVEN_PASSWORD')]) { + withGradle { + sh './gradlew ${GRADLE_ARGS} publish' + } + } + } + post { + success { + build job: 'filegenerator', parameters: [string(name: 'COMMAND', value: "promote ${env.MYGROUP}:${env.MYARTIFACT} ${env.MYVERSION} latest")], propagate: false, wait: false + } } } } @@ -72,4 +84,4 @@ pipeline { } } } -} \ No newline at end of file +} -- cgit From bf76791ab0cfef81b5ae16736938913903fe676f Mon Sep 17 00:00:00 2001 From: SciWhiz12 Date: Sat, 15 May 2021 11:24:36 +0800 Subject: Use UnsafeHacks to set final fields Removes always definalizing fields --- build.gradle | 1 + .../minecraftforge/artifactural/gradle/ReflectionUtils.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index f73cc9b..6b06ff4 100644 --- a/build.gradle +++ b/build.gradle @@ -42,6 +42,7 @@ dependencies { gradlecompImplementation sourceSets.shared.output gradlecompImplementation gradleApi() gradlecompImplementation 'com.google.guava:guava:30.1-jre' + gradlecompImplementation 'net.minecraftforge:unsafe:0.2.0' compile sourceSets.api.output compile sourceSets.shared.output diff --git a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java index 4e18885..1c8cdac 100644 --- a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java +++ b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java @@ -19,8 +19,11 @@ package net.minecraftforge.artifactural.gradle; +import net.minecraftforge.fml.unsafe.UnsafeHacks; + import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.function.UnaryOperator; public class ReflectionUtils { @@ -39,7 +42,11 @@ public class ReflectionUtils { T oldV = (T)f.get(target); T newV = operator.apply(oldV); - f.set(target, newV); + if (Modifier.isFinal(f.getModifiers())) { + UnsafeHacks.setField(f, target, newV); + } else { + f.set(target, newV); + } if (f.get(target) != newV) { throw new IllegalStateException("Failed to set new value on " + f.getDeclaringClass().getName() + "." + f.getName()); @@ -68,9 +75,6 @@ public class ReflectionUtils { for (Field f : clazz.getDeclaredFields()) { if (f.getName().equals(name)) { f.setAccessible(true); - if (!ModifierAccess.definalize(f)) { - System.out.println("Could not definalize field " + f.getDeclaringClass().getName() + "." + f.getName() + " Exception ate, lets see if it works"); - } return f; } } -- cgit From 499ff87b31ad4714acfc7b160a89494547ad55a4 Mon Sep 17 00:00:00 2001 From: SciWhiz12 Date: Sat, 15 May 2021 12:03:09 +0800 Subject: Remove ModifierAccess and java9 source set/project --- build.gradle | 43 ---------------- settings.gradle | 3 +- .../artifactural/gradle/ModifierAccess.java | 55 --------------------- .../artifactural/gradle/ModifierAccess.java | 57 ---------------------- 4 files changed, 1 insertion(+), 157 deletions(-) delete mode 100644 src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ModifierAccess.java delete mode 100644 src/java9/net/minecraftforge/artifactural/gradle/ModifierAccess.java diff --git a/build.gradle b/build.gradle index 6b06ff4..9fff891 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,6 @@ sourceSets { api shared gradlecomp - java9 } repositories { @@ -35,8 +34,6 @@ configurations { } dependencies { - java9Implementation files(sourceSets.main.output.classesDirs) { builtBy compileJava } - sharedImplementation sourceSets.api.output gradlecompImplementation sourceSets.shared.output @@ -58,50 +55,10 @@ java { toolchain.languageVersion = JavaLanguageVersion.of(8) } -project(':artifactural9') { - apply plugin: 'java' - apply plugin: 'eclipse' - group = rootProject.group - java.toolchain.languageVersion = JavaLanguageVersion.of(9) - - sourceSets { - java9.java.srcDirs = [rootProject.file('src/java9').getAbsolutePath()] - } - - eclipse { - project { - name rootProject.name + '9' - linkedResource name: 'java9', type: '2', location: rootProject.file('src/java9').getAbsolutePath() - } - jdt { - sourceCompatibility = targetCompatibility = 9 - } - } - - tasks.withType(JavaCompile) { - options.encoding = 'utf-8' - javaCompiler = javaToolchains.compilerFor { - languageVersion = JavaLanguageVersion.of(9) - } - } -} - - - jar { from sourceSets.api.output from sourceSets.shared.output from(sourceSets.gradlecomp.output) - - into('META-INF/versions/9') { - from project(':artifactural9').sourceSets.java9.output - } - - manifest { - attributes( - 'Multi-Release': 'true' - ) - } } task sourcesJar(type: Jar, dependsOn: classes) { diff --git a/settings.gradle b/settings.gradle index c0a8d84..20e6c4f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1 @@ -rootProject.name = 'artifactural' -include 'artifactural9' +rootProject.name = 'artifactural' \ No newline at end of file diff --git a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ModifierAccess.java b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ModifierAccess.java deleted file mode 100644 index fb68144..0000000 --- a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ModifierAccess.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Artifactural - * Copyright (c) 2018-2021. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -package net.minecraftforge.artifactural.gradle; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; - -public class ModifierAccess { - private static Field MODIFIER_ACCESS = null; - private static boolean accessAttempted = false; - - public static synchronized boolean definalize(Field target) { - if ((target.getModifiers() & Modifier.FINAL) == 0) { - return true; - } - - if (MODIFIER_ACCESS == null && !accessAttempted) { - try { - final Field modifiers = Field.class.getDeclaredField("modifiers"); - modifiers.setAccessible(true); - MODIFIER_ACCESS = modifiers; - } catch (NoSuchFieldException e) { - throw new RuntimeException("Could not access Field.modifiers to definalize reflection object. Use Java 8, current version: " + System.getProperty("java.version"), e); - } - accessAttempted = true; - } - if (MODIFIER_ACCESS != null) { - try { - MODIFIER_ACCESS.setInt(target, target.getModifiers() & ~Modifier.FINAL); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new RuntimeException("Could not definalize field " + target.getDeclaringClass().getName() + "." + target.getName(), e); - } - return true; - } - return false; - } - -} diff --git a/src/java9/net/minecraftforge/artifactural/gradle/ModifierAccess.java b/src/java9/net/minecraftforge/artifactural/gradle/ModifierAccess.java deleted file mode 100644 index cf6f65f..0000000 --- a/src/java9/net/minecraftforge/artifactural/gradle/ModifierAccess.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Artifactural - * Copyright (c) 2018. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -package net.minecraftforge.artifactural.gradle; - -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodHandles.Lookup; -import java.lang.invoke.VarHandle; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; - -public class ModifierAccess { - private static VarHandle MODIFIER_ACCESS = null; - private static boolean accessAttempted = false; - - public static synchronized boolean definalize(Field target) { - if ((target.getModifiers() & Modifier.FINAL) == 0) { - return true; - } - - if (MODIFIER_ACCESS == null && !accessAttempted) { - try { - Lookup lookup = MethodHandles.privateLookupIn(Field.class, MethodHandles.lookup()); - MODIFIER_ACCESS = lookup.findVarHandle(Field.class, "modifiers", int.class); - } catch (NoSuchFieldException | IllegalAccessException e) { - throw new RuntimeException("Could not access Field.modifiers to definalize reflection object. Use Java 8, current version: " + System.getProperty("java.version"), e); - } - accessAttempted = true; - } - if (MODIFIER_ACCESS != null) { - try { - MODIFIER_ACCESS.set(target, target.getModifiers() & ~Modifier.FINAL); - } catch (IllegalArgumentException e) { - throw new RuntimeException("Could not definalize field " + target.getDeclaringClass().getName() + "." + target.getName(), e); - } - return true; - } - return false; - } - -} -- cgit From e4905257d00e72c8b72a575a263633d1cf4a5b77 Mon Sep 17 00:00:00 2001 From: SciWhiz12 Date: Sat, 15 May 2021 12:06:32 +0800 Subject: Update Gradle wrapper to 6.9 --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index da9702f..549d844 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -- cgit From a4fe3e095ffdffb6022327def06744948d061571 Mon Sep 17 00:00:00 2001 From: SciWhiz12 Date: Sat, 15 May 2021 12:24:25 +0800 Subject: Cleanup buildscript, update plugins Licenser plugin changed from 'net.minecrell' to 'org.cadixdev'. Changed from using publications DSL to explicit creation call, fixes issues with IDE not recognizing the DSL correctly. --- build.gradle | 71 +++++++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/build.gradle b/build.gradle index 9fff891..ec0d95f 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id 'java-library' id 'maven-publish' id 'eclipse' - id 'net.minecrell.licenser' version '0.3' + id 'org.cadixdev.licenser' version '0.6.0' id 'org.ajoberstar.grgit' version '4.1.0' } @@ -29,8 +29,8 @@ configurations { sharedImplementation.extendsFrom apiImplementation gradlecompImplementation.extendsFrom sharedImplementation - compile.extendsFrom sharedImplementation - compile.extendsFrom gradlecompImplementation + implementation.extendsFrom sharedImplementation + implementation.extendsFrom gradlecompImplementation } dependencies { @@ -41,9 +41,9 @@ dependencies { gradlecompImplementation 'com.google.guava:guava:30.1-jre' gradlecompImplementation 'net.minecraftforge:unsafe:0.2.0' - compile sourceSets.api.output - compile sourceSets.shared.output - compile sourceSets.gradlecomp.output + implementation sourceSets.api.output + implementation sourceSets.shared.output + implementation sourceSets.gradlecomp.output } @@ -51,57 +51,54 @@ tasks.withType(JavaCompile) { options.encoding = 'utf-8' options.deprecation = true } + java { toolchain.languageVersion = JavaLanguageVersion.of(8) + withSourcesJar() } jar { from sourceSets.api.output from sourceSets.shared.output - from(sourceSets.gradlecomp.output) + from sourceSets.gradlecomp.output } -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' +sourcesJar { from sourceSets.api.allSource from sourceSets.shared.allSource from sourceSets.gradlecomp.allSource } - license { header = file("$rootDir/LICENSE-header.txt") } publishing { - publications { - mavenJava(MavenPublication) { - from components.java - artifact tasks.sourcesJar - pom { - groupId = project.group - version = project.version - artifactId = project.archivesBaseName - name = project.archivesBaseName - packaging = 'jar' - description = 'A Gradle artifact processing and management tool' + publications.create("mavenJava", MavenPublication) { + from components.java + pom { + groupId = project.group + version = project.version + artifactId = project.archivesBaseName + name = project.archivesBaseName + packaging = 'jar' + description = 'A Gradle artifact processing and management tool' + url = 'https://github.com/MinecraftForge/Artifactural/' + + scm { url = 'https://github.com/MinecraftForge/Artifactural/' - - scm { - url = 'https://github.com/MinecraftForge/Artifactural/' - connection = 'scm:git:git://github.com/MinecraftForge/Artifactural.git' - developerConnection = 'scm:git:git@github.com:MinecraftForge/Artifactural.git' - } - issueManagement { - system = 'github' - url = 'https://github.com/MinecraftForge/Artifactural/issues' - } - licenses { - license { - name = 'LGPL-2.1' - url = 'https://www.gnu.org/licenses/lgpl-2.1.txt' - distribution = 'repo' - } + connection = 'scm:git:git://github.com/MinecraftForge/Artifactural.git' + developerConnection = 'scm:git:git@github.com:MinecraftForge/Artifactural.git' + } + issueManagement { + system = 'github' + url = 'https://github.com/MinecraftForge/Artifactural/issues' + } + licenses { + license { + name = 'LGPL-2.1' + url = 'https://www.gnu.org/licenses/lgpl-2.1.txt' + distribution = 'repo' } } } -- cgit