Skip to content

Commit

Permalink
Update to gradle 5.1.1, update deps, tweak logging to stop the silly …
Browse files Browse the repository at this point in the history
…error spam.
  • Loading branch information
cpw committed Jan 13, 2019
1 parent 36fb035 commit a129906
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 92 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
/repo/
/buildSrc/
/out/
/repo/
/src/generated-sources/
/logs/

*.tokens
/forge-deobfed-out.jar
/forge-deobfed-new.jar
/forge-deobfed.jar
/out.log
70 changes: 41 additions & 29 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id 'org.ajoberstar.reckon' version '0.8.0'
id 'com.github.johnrengelman.shadow' version '2.0.4'
id 'org.ajoberstar.grgit' version '2.2.1'
id 'org.ajoberstar.reckon' version '0.9.0'
id 'org.ajoberstar.grgit' version '3.0.0'
id 'com.github.johnrengelman.shadow' version '4.0.3'
id 'com.github.ben-manes.versions' version '0.20.0'
}
apply plugin: 'maven'
apply plugin: 'maven-publish'
Expand All @@ -25,6 +28,19 @@ reckon {

reckonTagCreate.dependsOn check

dependencyUpdates.resolutionStrategy {
componentSelection { rules ->
rules.all { ComponentSelection selection ->
boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm', 'preview'].any { qualifier ->
selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/
}
if (rejected) {
selection.reject('Release candidate')
}
}
}
}

test {
useJUnitPlatform()
}
Expand Down Expand Up @@ -73,16 +89,16 @@ ext.sharedManifest = manifest {
'Specification-Vendor': 'Forge',
'Specification-Version': '1', // Currently version 1 of the accesstransformer specification
'Implementation-Title': project.name,
'Implementation-Version': "${version}+${System.getenv("BUILD_NUMBER")?:0}+${grgit.head().getAbbreviatedId(8)}",
'Implementation-Version': "${version}+${System.getenv("BUILD_NUMBER")?:0}+${grgit.head().abbreviatedId}",
'Implementation-Vendor': 'Forge',
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
'Git-Commit': grgit.head().getAbbreviatedId(8),
'Git-Commit': grgit.head().abbreviatedId,
'Git-Branch': grgit.branch.current().getName() ],
'net/minecraftforge/accesstransformer/service/')
}

task mlserviceJar(type: Jar) {
classifier = 'service'
archiveClassifier = 'service'
from sourceSets.main.output
from sourceSets.mlservice.output
manifest = project.manifest {
Expand All @@ -91,12 +107,12 @@ task mlserviceJar(type: Jar) {
}

task testsJar(type: Jar) {
classifier = 'testsjar'
archiveClassifier = 'testsjar'
from sourceSets.testJars.output
}

task sourcesJar(type: Jar) {
classifier = 'sources'
archiveClassifier = 'sources'
from sourceSets.main.allSource
from sourceSets.mlservice.allSource
}
Expand All @@ -114,32 +130,32 @@ repositories {
}

dependencies {
testImplementation('org.junit.jupiter:junit-jupiter-api:5.2.+')
testImplementation('org.powermock:powermock-core:1.7.+')
testImplementation('cpw.mods:modlauncher:0.1+')
testImplementation('org.junit.jupiter:junit-jupiter-api:5.3.+')
testImplementation('org.powermock:powermock-core:2.0+')
testImplementation('cpw.mods:modlauncher:0.6+')
testImplementation('com.google.code.gson:gson:2.8.5')
testCompileOnly(sourceSets.mlservice.output)
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.2.+')
testRuntime('org.apache.logging.log4j:log4j-core:2.11.+')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.3.+')
testRuntime(sourceSets.testJars.runtimeClasspath)
testRuntime(sourceSets.mlservice.output)
implementation(sourceSets.antlr4.output)
implementation('org.antlr:antlr4-runtime:4.7.1')
implementation('org.antlr:antlr4-runtime:4.7.2')
implementation('net.sf.jopt-simple:jopt-simple:5.0.4')
implementation('org.ow2.asm:asm:6.2')
implementation('org.ow2.asm:asm-commons:6.2')
implementation('org.ow2.asm:asm-tree:6.2')
implementation('org.apache.logging.log4j:log4j-api:2.11.+')
implementation('cpw.mods:modlauncher:0.1+:api')
mlserviceImplementation('cpw.mods:modlauncher:0.1+:api')
implementation('org.apache.logging.log4j:log4j-core:2.11.+')
implementation('cpw.mods:modlauncher:0.6+:api')
mlserviceImplementation('cpw.mods:modlauncher:0.6+:api')
mlserviceImplementation(sourceSets.main.output)
antlr4Compile('org.antlr:antlr4:4.7.1')
antlr4Compile('org.antlr:antlr4:4.7.2')
}


// Shadow Jar with antlr embedded
shadowJar {
classifier = 'shadowed'
archiveClassifier = 'shadowed'
from sourceSets.main.output
from sourceSets.mlservice.output
manifest {
Expand All @@ -153,8 +169,8 @@ shadowJar {
}
}

task fatJar(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
classifier = 'fatjar'
task fatJar(type: ShadowJar) {
archiveClassifier = 'fatjar'
from sourceSets.main.output
from sourceSets.mlservice.output
configurations = shadowJar.configurations
Expand Down Expand Up @@ -222,15 +238,11 @@ publishing {
}
repositories {
maven {
if (project.hasProperty('forgeMavenPassword')) {
credentials {
username project.properties.forgeMavenUser
password project.properties.forgeMavenPassword
}
url 'http://files.minecraftforge.net/maven/manage/upload'
} else {
url 'file://' + rootProject.file('repo').getAbsolutePath()
credentials {
username project.properties.forgeMavenUser?:'fake'
password project.properties.forgeMavenPassword?:'news'
}
url 'http://files.minecraftforge.net/maven/manage/upload'
}
}
}
Expand All @@ -243,5 +255,5 @@ generateGrammarSource {
main = 'org.antlr.v4.Tool'
classpath = configurations.antlr4Compile
def pkg = antlr.grammarpackage.replaceAll("\\.", "/")
args = ['-o', "${antlr.destinationDir}/${pkg}", '-visitor', '-package', antlr.grammarpackage, grammars.files].flatten()
args = ["-o", "${antlr.destinationDir}/${pkg}", '-visitor', '-package', antlr.grammarpackage, grammars.files].flatten()
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
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-4.8.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,45 @@

import joptsimple.*;
import joptsimple.util.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.core.config.*;
import org.apache.logging.log4j.*;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configurator;
import org.objectweb.asm.*;
import org.objectweb.asm.tree.*;

import java.io.*;
import java.net.*;
import java.nio.file.*;
import java.util.*;
import java.util.stream.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;

public class TransformerProcessor {

private static final Logger LOGGER = LogManager.getLogger("AXFORM");
static {
Configurator.initialize("", "atlog4j2.xml");
}
private static final Logger LOGGER = LogManager.getLogger();
private static final Marker AXFORM_MARKER = MarkerManager.getMarker("AXFORM");

public static void main(String... args) {
Configurator.initialize("", "atlog4j2.xml");
final OptionParser optionParser = new OptionParser();
final ArgumentAcceptingOptionSpec<Path> inputJar = optionParser.accepts("inJar", "Input JAR file to apply transformation to").withRequiredArg().withValuesConvertedBy(new PathConverter(PathProperties.FILE_EXISTING)).required();
final ArgumentAcceptingOptionSpec<Path> atFiles = optionParser.acceptsAll(list("atfile", "atFile"), "Access Transformer File").withRequiredArg().withValuesConvertedBy(new PathConverter(PathProperties.FILE_EXISTING)).required();
final ArgumentAcceptingOptionSpec<Path> outputJar = optionParser.accepts("outJar", "Output JAR file").withRequiredArg().withValuesConvertedBy(new PathConverter(PathProperties.NOT_EXISTING));
final ArgumentAcceptingOptionSpec<String> logFilePath = optionParser.accepts("logFile", "Log file for logging").withRequiredArg();

final OptionSet optionSet;
Path inputJarPath;
Path outputJarPath;
List<Path> atFilePaths;
try {
optionSet = optionParser.parse(args);
final String logFile = logFilePath.value(optionSet);
if (logFile != null) {
final LoggerContext logcontext = LoggerContext.getContext(false);
logcontext.getConfiguration().getProperties().put("logfilename", logFile);
logcontext.getConfiguration().getProperties().put("loglevel", "INFO");
logcontext.updateLoggers();
}
inputJarPath = inputJar.value(optionSet).toAbsolutePath();
final String s = inputJarPath.getFileName().toString();
outputJarPath = outputJar.value(optionSet);
Expand All @@ -45,7 +50,7 @@ public static void main(String... args) {
outputJarPath = outputJarPath.toAbsolutePath();
}

atFilePaths = atFiles.values(optionSet).stream().map(a -> a.toAbsolutePath()).collect(Collectors.toList());
atFilePaths = atFiles.values(optionSet).stream().map(Path::toAbsolutePath).collect(Collectors.toList());
} catch (Exception e) {
LOGGER.error(AXFORM_MARKER,"Option Parsing Error", e);
return;
Expand All @@ -72,55 +77,55 @@ private static void processJar(final Path inputJar, final Path outputJarPath, fi
LOGGER.debug(AXFORM_MARKER,"Loaded transformers {}", path);
});

try (FileOutputStream fos = new FileOutputStream(outputJarPath.toFile());
ZipOutputStream zout = new ZipOutputStream(fos);
ZipFile zin = new ZipFile(inputJar.toFile())) {
for(Enumeration<? extends ZipEntry> enu = zin.entries(); enu.hasMoreElements();) {
ZipEntry entry = enu.nextElement();
if (entry.isDirectory()) {
continue; //IDGAF about directories
}

putEntry(zout, entry);
if (entry.getName().endsWith(".class")) {
try (InputStream is = zin.getInputStream(entry)) {
final ClassReader classReader = new ClassReader(is);
final ClassNode cn = new ClassNode();
classReader.accept(cn, 0);
final Type type = Type.getType('L'+cn.name.replaceAll("\\.","/")+';');
if (AccessTransformerEngine.INSTANCE.handlesClass(type)) {
LOGGER.debug(AXFORM_MARKER,"Transforming class {}", type);
AccessTransformerEngine.INSTANCE.transform(cn, type);
ClassWriter cw = new ClassWriter(Opcodes.ASM5);
cn.accept(cw);
zout.write(cw.toByteArray());
} else {
LOGGER.debug(AXFORM_MARKER,"Skipping {}", type);
copy(zin.getInputStream(entry), zout);
zout.closeEntry();
}
}
} else {
LOGGER.debug(AXFORM_MARKER,"Copying {}", entry.getName());
copy(zin.getInputStream(entry), zout);
}
zout.closeEntry();
final URI toUri = outputJarPath.toUri();
final URI outJarURI = URI.create("jar:"+toUri.getScheme()+":"+toUri.getPath());
try (FileSystem outJar = FileSystems.newFileSystem(outJarURI, new HashMap<String, String>() {{
put("create", "true");
}})) {
final Path outRoot = StreamSupport.stream(outJar.getRootDirectories().spliterator(), false).findFirst().get();
try (FileSystem jarFile = FileSystems.newFileSystem(inputJar, ClassLoader.getSystemClassLoader())) {
Files.walk(StreamSupport.stream(jarFile.getRootDirectories().spliterator(), false).findFirst().orElseThrow(() -> new IllegalArgumentException("The JAR has no root?!")))
.forEach(path -> {
Path outPath = outJar.getPath(path.toAbsolutePath().toString());
if (Files.isDirectory(path)) {
try {
Files.createDirectory(outPath);
} catch (IOException e) {
// spammy
}
}
if (path.getNameCount() > 0 && path.getFileName().toString().endsWith(".class")) {
try (InputStream is = Files.newInputStream(path)) {
final ClassReader classReader = new ClassReader(is);
final ClassNode cn = new ClassNode();
classReader.accept(cn, 0);
final Type type = Type.getType('L'+cn.name.replaceAll("\\.","/")+';');
if (AccessTransformerEngine.INSTANCE.handlesClass(type)) {
LOGGER.debug(AXFORM_MARKER,"Transforming class {}", type);
AccessTransformerEngine.INSTANCE.transform(cn, type);
ClassWriter cw = new ClassWriter(Opcodes.ASM5);
cn.accept(cw);
Files.write(outPath, cw.toByteArray());
} else {
LOGGER.debug(AXFORM_MARKER,"Skipping {}", type);
Files.copy(path, outPath);
}
} catch (IOException e) {
LOGGER.error(AXFORM_MARKER,"Reading {}", path, e);
}
} else if (!Files.exists(outPath)){
try {
Files.copy(path, outPath);
} catch (IOException e) {
LOGGER.error(AXFORM_MARKER,"Copying {}", path, e);
}
}
});
} catch (IOException e) {
LOGGER.error(AXFORM_MARKER,"Reading JAR", e);
}
} catch (IOException e) {
LOGGER.error(AXFORM_MARKER,"Processing JAR", e);
}
}

private static void putEntry(ZipOutputStream out, ZipEntry old) throws IOException {
ZipEntry ent = new ZipEntry(old.getName());
ent.setTime(0); //Stabilizes times
out.putNextEntry(ent);
}
public static void copy(InputStream input, OutputStream output) throws IOException {
byte[] buf = new byte[0x100];
int n = 0;
while ((n = input.read(buf)) != -1) {
output.write(buf, 0, n);
LOGGER.error(AXFORM_MARKER,"Writing JAR", e);
}
}
}
13 changes: 11 additions & 2 deletions src/main/resources/atlog4j2.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Properties>
<Property name="loglevel">DEBUG</Property>
<Property name="logfilename">out.log</Property>
</Properties>
<Appenders>
<Console name="SysOut" target="SYSTEM_OUT">
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n"/>
<ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="ACCEPT"/>
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
</Console>
<Console name="SysErr" target="SYSTEM_ERR">
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n"/>
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
</Console>
<File name="logfile" fileName="${logfilename}" createOnDemand="true" append="false">
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n"/>
<ThresholdFilter level="${loglevel}" onMatch="ACCEPT" onMismatch="DENY"/>
</File>
</Appenders>
<Loggers>
<Root level="info">
<Root level="debug">
<AppenderRef ref="SysOut"/>
<AppenderRef ref="SysErr"/>
<AppenderRef ref="logfile"/>
</Root>
</Loggers>
</Configuration>

0 comments on commit a129906

Please sign in to comment.