Skip to content

Commit

Permalink
Major cleanup, use Gradle properties and providers (#794)
Browse files Browse the repository at this point in the history
* Cleanup buildscript and dependencies

 - Set wrapper task version in buildscript to 7.0.2
 - Remove jcenter and gradle libs repositories
 - Update to cadixdev.licenser plugin 0.6.0, ben-manes.versions plugin 0.39.0,
   srgutils 0.4.3
 - Remove commented out shadow plugin
 - Remove lzma-java and javaxdelta library
   LZMA-java and javaxdelta was used for creating binary patches, which is
   now done using Forge's BinaryPatcher tool.

* Standardize tasks subpackages to `tasks` instead of `task`
* Standardize tasks names by removing `Task` affixes
* Convert tasks to use lazy task properties
Also cleanup imports in affected files, and converts ReobfuscateJar to
be a subclass of JarExec.

* Convert extensions to use lazy properties
* Cleanup plugin logic to use lazy properties more smartly
Most of the changes do not move any code, but instead cleanup the
existing code in place.

* Move environment checks to separate class outside of Utils
* Make MCPFunction serializable
Fixes issue where Gradle couldn't serialize a property with MCPFunctions.
* Cleanup Patcher and Userdev plugins
* Change group for run tasks to 'ForgeGradle runs'
This is more descriptive than 'fg_runs', and will look better in the
tasks list.
* Move download utility functions from Utils to separate class
* Modify Util#createRunConfigTasks to use task providers
* Add manual property fields for properties with setters
Gradle doesn't manage properties which have a non-abstract setter, so
we have to provide the property ourselves.

* Remove deprecated method in MojangLicenseHelper
* Cleanup Artifact and HashFunction classes
* Add package-infos with NonnullApi nullability annotation
* Cleanup and add nullable annotations to util classes
* Cleanup and add nullability annotations to deobf, mcp, repo, and config classes
* Cleanup and simplify parts of regexes
* Fix compilation error undetected by IDE
* Ensure binary patches tasks run after patch generation task
* Define gradle plugins using `gradlePlugin` block
* Add jar artifact to pluginMaven publication manually
Somehow, using the gradlePlugins block and disabling the automated
publishing removed the jar artifact from the pluginMaven publication

* Apply code review suggestions from @pupnewfster
Also adds a few additional nullability annotations.
* Update to Gradle 7.1, Licenser plugin 6.1
* Remove uses of deprecated code

Notably, Gradle 8 is moving towards removal of Conventions in favor of
Extensions. Most of the deprecation warnings are from `Project#getConvention()`
and `JavaPluginConvention`, which has been replaced by `JavaPluginExtension`.

* Use automated publishing once more
* Disable automated publishing once more
* Add helper methods for adding access transformers

Since this is a user-facing extension, and access transformers are
commonly used by modders, this eases the upgrade path from FG4 to FG5.

Equivalent helpers are not added for sided annotation strippers, as these
are not meant for normal modder use.

* Mark classpath property in JarExec with proper annotation
* Fix incorrect method call
* Fix source and target compatibility with JarExec
* Fix replaceArgs bug
* Update SpecialSource
* Use SRGUtils instead of manual parsing
* Use `named()` to retrieve tasks
* Update EnvironmentChecks#checkEnvironment javadoc
* Update JavadocAdder to use google commons `Lists`
* Allow setting the runtime java version for JarExec
  • Loading branch information
sciwhiz12 committed Jun 25, 2021
1 parent 9b4b4ee commit 6b322d4
Show file tree
Hide file tree
Showing 105 changed files with 3,785 additions and 4,234 deletions.
48 changes: 38 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ plugins {
id 'java-gradle-plugin'
id 'eclipse'
id 'maven-publish'
id 'org.cadixdev.licenser' version '0.5.0'
id 'org.cadixdev.licenser' version '0.6.1'
id 'org.ajoberstar.grgit' version '4.1.0'
id 'com.github.ben-manes.versions' version '0.36.0'
//id 'com.github.johnrengelman.shadow' version '2.0.4'
id 'com.github.ben-manes.versions' version '0.39.0'
}

version = (grgit.describe(longDescr: true, tags: true) ?: 'unknown-unknown-unknown').split('-').with { "${it[0]}.${it[1]}" }
Expand Down Expand Up @@ -46,10 +45,8 @@ task sourcesJar(type: Jar) {
}

repositories {
mavenLocal()
jcenter()
mavenLocal()
maven { url = 'https://maven.minecraftforge.net/' }
maven { url = 'https://repo.gradle.org/gradle/libs-releases-local/' }
}

license {
Expand All @@ -65,22 +62,20 @@ license {
}

wrapper {
gradleVersion = '6.8'
gradleVersion = '7.1'
distributionType = Wrapper.DistributionType.ALL
}

dependencies {
commonImplementation gradleApi()
commonImplementation 'commons-io:commons-io:2.8.0'
commonImplementation 'com.github.jponge:lzma-java:1.3' // replaces the LZMA binary
commonImplementation 'com.nothome:javaxdelta:2.0.1' // GDIFF implementation for BinPatches
commonImplementation 'com.google.code.gson:gson:2.8.6'
commonImplementation 'com.google.guava:guava:30.1-jre'
commonImplementation 'de.siegmar:fastcsv:2.0.0'
commonImplementation 'net.minecraftforge:artifactural:3.0.8'
commonImplementation 'org.apache.maven:maven-artifact:3.6.3'
commonImplementation 'org.apache.httpcomponents:httpclient:4.5.13'
commonImplementation 'net.minecraftforge:srgutils:0.4.1'
commonImplementation 'net.minecraftforge:srgutils:0.4.3'
commonImplementation 'net.minecraftforge:DiffPatch:2.0.7:all'

mcpImplementation sourceSets.common.output
Expand All @@ -105,9 +100,42 @@ project.extensions.eclipse.classpath.file.whenMerged { Classpath cp ->
}
}

gradlePlugin {
plugins {
mcp {
id = 'net.minecraftforge.gradle.mcp'
implementationClass = 'net.minecraftforge.gradle.mcp.MCPPlugin'
}
patcher {
id = 'net.minecraftforge.gradle.patcher'
implementationClass = 'net.minecraftforge.gradle.patcher.PatcherPlugin'
}
userdev {
id = 'net.minecraftforge.gradle'
implementationClass = 'net.minecraftforge.gradle.userdev.UserDevPlugin'
}

// legacy definitions
forgedev_mcp {
id = 'net.minecraftforge.gradle.forgedev.mcp'
implementationClass = 'net.minecraftforge.gradle.mcp.MCPPlugin'
}
forgedev_patcher {
id = 'net.minecraftforge.gradle.forgedev.patcher'
implementationClass = 'net.minecraftforge.gradle.patcher.PatcherPlugin'
}
forgedev {
id = 'net.minecraftforge.gradle.forgedev'
implementationClass = 'net.minecraftforge.gradle.patcher.PatcherPlugin'
}
}
automatedPublishing = false
}

publishing {
publications {
pluginMaven(MavenPublication) {
from components.java
artifact sourcesJar
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@

package net.minecraftforge.gradle.common.config;

import net.minecraftforge.gradle.common.util.Utils;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.Type;
Expand All @@ -29,13 +36,7 @@
import java.util.Map.Entry;
import java.util.stream.Collectors;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;

import net.minecraftforge.gradle.common.util.Utils;
import javax.annotation.Nullable;

public class MCPConfigV1 extends Config {
public static MCPConfigV1 get(InputStream stream) {
Expand All @@ -46,9 +47,13 @@ public static MCPConfigV1 get(byte[] data) {
}

protected String version; // Minecraft version
@Nullable
protected Map<String, Object> data;
@Nullable
protected Map<String, List<Step>> steps;
@Nullable
protected Map<String, Function> functions;
@Nullable
protected Map<String, List<String>> libraries;

public String getVersion() {
Expand All @@ -60,6 +65,7 @@ public Map<String, Object> getData() {
}

@SuppressWarnings("unchecked")
@Nullable
public String getData(String... path) {
if (data == null)
return null;
Expand All @@ -81,6 +87,7 @@ public List<Step> getSteps(String side) {
return ret == null ? Collections.emptyList() : ret;
}

@Nullable
public Function getFunction(String name) {
return functions == null ? null : functions.get(name);
}
Expand All @@ -97,9 +104,10 @@ public List<String> getLibraries(String side) {
public static class Step {
private final String type;
private final String name;
@Nullable
private final Map<String, String> values;

private Step(String type, String name, Map<String, String> values) {
private Step(String type, String name, @Nullable Map<String, String> values) {
this.type = type;
this.name = name;
this.values = values;
Expand All @@ -117,6 +125,7 @@ public Map<String, String> getValues() {
return values == null ? Collections.emptyMap() : values;
}

@Nullable
public String getValue(String key) {
return values == null ? null : values.get(key);
}
Expand All @@ -139,8 +148,11 @@ public Step deserialize(JsonElement json, Type typeOfT, JsonDeserializationConte

public static class Function {
protected String version; //Maven artifact for the jar to run
@Nullable
protected String repo; //Maven repo to download the jar from
@Nullable
protected List<String> args;
@Nullable
protected List<String> jvmargs;

public String getVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@

package net.minecraftforge.gradle.common.config;

import net.minecraftforge.gradle.common.util.Utils;

import org.apache.commons.io.IOUtils;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import org.apache.commons.io.IOUtils;

import net.minecraftforge.gradle.common.util.Utils;
import javax.annotation.Nullable;

public class MCPConfigV2 extends MCPConfigV1 {
public static MCPConfigV2 get(InputStream stream) {
Expand Down Expand Up @@ -58,6 +60,7 @@ public static MCPConfigV2 getFromArchive(File path) throws IOException {

private boolean official = false;
private int java_target = 8;
@Nullable
private String encoding = "UTF-8";

public boolean isOfficial() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

package net.minecraftforge.gradle.common.config;

import net.minecraftforge.gradle.common.config.MCPConfigV1.Function;
import net.minecraftforge.gradle.common.util.RunConfig;
import net.minecraftforge.gradle.common.util.Utils;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
Expand All @@ -28,9 +32,7 @@
import java.util.List;
import java.util.Map;

import net.minecraftforge.gradle.common.config.MCPConfigV1.Function;
import net.minecraftforge.gradle.common.util.RunConfig;
import net.minecraftforge.gradle.common.util.Utils;
import javax.annotation.Nullable;

public class UserdevConfigV1 extends Config {
public static UserdevConfigV1 get(InputStream stream) {
Expand All @@ -40,21 +42,34 @@ public static UserdevConfigV1 get(byte[] data) {
return get(new ByteArrayInputStream(data));
}

@Nullable
public String mcp; // Do not specify this unless there is no parent.
@Nullable
public String parent; // To fully resolve, we must walk the parents until we hit null, and that one must specify a MCP value.
@Nullable
public List<String> ats;
@Nullable
public List<String> sass;
@Nullable
public List<String> srgs;
@Nullable
public List<String> srg_lines;
public String binpatches; //To be applied to joined.jar, remapped, and added to the classpath
public Function binpatcher;
public String patches;
@Nullable
public String sources;
@Nullable
public String universal; //Remapped and added to the classpath, Contains new classes and resources
@Nullable
public List<String> libraries; //Additional libraries.
@Nullable
public String inject;
@Nullable
public Map<String, RunConfig> runs;
@Nullable
public String sourceCompatibility;
@Nullable
public String targetCompatibility;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

package net.minecraftforge.gradle.common.config;

import net.minecraftforge.gradle.common.config.MCPConfigV1.Function;
import net.minecraftforge.gradle.common.util.Utils;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.Charset;
Expand All @@ -30,8 +33,7 @@
import java.util.List;
import java.util.Map;

import net.minecraftforge.gradle.common.config.MCPConfigV1.Function;
import net.minecraftforge.gradle.common.util.Utils;
import javax.annotation.Nullable;

public class UserdevConfigV2 extends UserdevConfigV1 {
public static UserdevConfigV2 get(InputStream stream) {
Expand All @@ -44,7 +46,9 @@ public static UserdevConfigV2 get(byte[] data) {
public DataFunction processor;
public String patchesOriginalPrefix;
public String patchesModifiedPrefix;
@Nullable
private Boolean notchObf; //This is a Boolean so we can set to null and it won't be printed in the json.
@Nullable
private List<String> universalFilters;
private String sourceFileCharset = StandardCharsets.UTF_8.name();

Expand All @@ -53,7 +57,7 @@ public void setNotchObf(boolean value) {
}

public boolean getNotchObf() {
return this.notchObf == null ? false : this.notchObf;
return this.notchObf != null && this.notchObf;
}

public void setSourceFileCharset(String value) {
Expand Down Expand Up @@ -84,6 +88,7 @@ public Map<String, String> getData() {
return this.data == null ? Collections.emptyMap() : data;
}

@Nullable
public String setData(String name, String path) {
if (this.data == null)
this.data = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* ForgeGradle
* Copyright (C) 2018 Forge Development LLC
*
* 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; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
*/

@NonNullApi
package net.minecraftforge.gradle.common.config;

import org.gradle.api.NonNullApi;

0 comments on commit 6b322d4

Please sign in to comment.