Skip to content

Commit 79bd2b8

Browse files
committed
Initial Commit
0 parents  commit 79bd2b8

27 files changed

+3748
-0
lines changed

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
* text eol=lf
2+
*.bat text eol=crlf
3+
*.java text eol=lf
4+
*.gradle text eol=crlf

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**/.gradle/
2+
/**/.classpath
3+
/**/.project
4+
/**/.settings/
5+
/**/bin/
6+
/**/test/
7+
/**/build/
8+
/repo/
9+
/cache/

LICENSE

Lines changed: 504 additions & 0 deletions
Large diffs are not rendered by default.

LICENSE-header.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Copyright (c) Forge Development LLC and contributors
2+
SPDX-License-Identifier: LGPL-2.1-only

build.gradle

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
plugins {
2+
id 'java-library'
3+
id 'maven-publish'
4+
id 'net.minecraftforge.licenser' version '1.0.1'
5+
id 'net.minecraftforge.gradleutils' version '2.3.6'
6+
id 'com.github.johnrengelman.shadow' version '8.1.1'
7+
}
8+
9+
repositories {
10+
mavenCentral()
11+
}
12+
13+
group = 'net.minecraftforge'
14+
15+
version = gradleutils.tagOffsetVersion
16+
println('Version: ' + version)
17+
18+
tasks.register('createJavaProbeClass', buildsrc.ClassGeneratorTask) { }
19+
20+
tasks.register('javaProbeJar', Jar) {
21+
destinationDirectory = layout.buildDirectory.dir('libs')
22+
archiveBaseName = project.name
23+
archiveClassifier = 'probe'
24+
manifest {
25+
attributes([
26+
'Main-Class': 'JavaProbe'
27+
] as LinkedHashMap)
28+
attributes([
29+
'Main-Class': 'JavaProbe',
30+
'Specification-Title': 'Java Probe',
31+
'Specification-Vendor': 'Forge Development LLC',
32+
'Specification-Version': gradleutils.gitInfo.tag,
33+
'Implementation-Title': 'javaprobe',
34+
'Implementation-Vendor': 'Forge Development LLC',
35+
'Implementation-Version': project.version
36+
] as LinkedHashMap)
37+
}
38+
39+
from(createJavaProbeClass.outputFile)
40+
}
41+
42+
dependencies {
43+
implementation libs.jopt
44+
implementation libs.gson
45+
implementation libs.jtar
46+
implementation javaProbeJar.outputs.files
47+
}
48+
49+
license {
50+
header project.file('LICENSE-header.txt')
51+
newLine false
52+
}
53+
54+
java {
55+
// Currently JOpt is the limiting, requiring java 8
56+
// But also toolchains don't support building for anything lower then 8
57+
toolchain.languageVersion = JavaLanguageVersion.of(8)
58+
withSourcesJar()
59+
}
60+
61+
shadowJar {
62+
ext.reloc = 'net.minecraftforge.jver.reloc.'
63+
relocate 'joptsimple', reloc + 'jopt'
64+
relocate 'com.google.gson', reloc + 'gson'
65+
relocate 'org.kamranzafar.jtar', reloc + 'jtar'
66+
}
67+
68+
jar {
69+
manifest {
70+
attributes([
71+
'Main-Class': 'net.minecraftforge.jver.Main'
72+
] as LinkedHashMap)
73+
attributes([
74+
'Specification-Title': 'Java Version',
75+
'Specification-Vendor': 'Forge Development LLC',
76+
'Specification-Version': gradleutils.gitInfo.tag,
77+
'Implementation-Title': 'Java Version',
78+
'Implementation-Vendor': 'Forge Development LLC',
79+
'Implementation-Version': project.version
80+
] as LinkedHashMap, 'net/minecraftforge/jver/')
81+
}
82+
from(createJavaProbeClass.outputFile)
83+
}
84+
85+
compileJava {
86+
dependsOn javaProbeJar
87+
options.encoding = 'UTF-8'
88+
}
89+
90+
changelog {
91+
from '1.0'
92+
}
93+
94+
artifacts {
95+
//archives javaProbeJar
96+
}
97+
98+
publishing {
99+
publications.register('mavenJava', MavenPublication).configure {
100+
artifactId = project.name
101+
from components.java
102+
artifact(javaProbeJar)
103+
104+
pom {
105+
name = project.name
106+
description = 'Minecraft Maven Repo Generator'
107+
url = 'https://github.com/MinecraftForge/java-version'
108+
109+
gradleutils.pom.setGitHubDetails(pom, 'java-version')
110+
111+
license gradleutils.pom.licenses.LGPLv2_1
112+
113+
developers {
114+
developer gradleutils.pom.Developers.LexManos
115+
}
116+
}
117+
}
118+
repositories {
119+
maven gradleutils.publishingForgeMaven
120+
}
121+
}

buildSrc/build.gradle

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
plugins {
2+
id 'java-library'
3+
id 'net.minecraftforge.licenser' version '1.0.1'
4+
}
5+
6+
repositories {
7+
mavenCentral()
8+
}
9+
10+
license {
11+
header rootProject.file('../LICENSE-header.txt')
12+
newLine false
13+
}
14+
15+
dependencies {
16+
implementation gradleApi()
17+
implementation 'org.ow2.asm:asm:9.7'
18+
implementation 'org.ow2.asm:asm-tree:9.7'
19+
implementation 'org.ow2.asm:asm-util:9.7'
20+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright (c) Forge Development LLC
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
package buildsrc;
6+
7+
import org.gradle.api.DefaultTask;
8+
import org.gradle.api.file.RegularFileProperty;
9+
import org.gradle.api.tasks.OutputFile;
10+
import org.gradle.api.tasks.TaskAction;
11+
12+
import org.objectweb.asm.ClassVisitor;
13+
import org.objectweb.asm.ClassWriter;
14+
import org.objectweb.asm.MethodVisitor;
15+
import static org.objectweb.asm.Opcodes.*;
16+
17+
import java.io.IOException;
18+
import java.nio.file.Files;
19+
import java.nio.file.Path;
20+
import java.nio.file.StandardOpenOption;
21+
22+
abstract class ClassGeneratorTask extends DefaultTask {
23+
@OutputFile
24+
abstract RegularFileProperty getOutputFile();
25+
26+
public ClassGeneratorTask() {
27+
// I don't think this is necessary, as the build cache should use the hash of this compiled class as the cache key
28+
// But just in case, this is how to make it always run.
29+
this.getOutputs().upToDateWhen(t -> false);
30+
this.getOutputFile().convention(this.getProject()
31+
.getLayout()
32+
.getBuildDirectory()
33+
.file(this.getName() + "/JavaProbe.class")
34+
);
35+
}
36+
37+
@TaskAction
38+
public void run() throws IOException {
39+
Path output = getOutputFile().getAsFile().get().toPath();
40+
byte[] data = buildClass();
41+
Files.write(output, data, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
42+
}
43+
44+
private byte[] buildClass() {
45+
ClassWriter writer = new ClassWriter(0);
46+
writer.visit(V1_1, ACC_PUBLIC | ACC_SUPER, "JavaProbe", null, "java/lang/Object", null);
47+
48+
constructor(writer);
49+
main(writer);
50+
51+
writer.visitEnd();
52+
return writer.toByteArray();
53+
}
54+
55+
private void constructor(ClassVisitor writer) {
56+
MethodVisitor mtd = writer.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
57+
mtd.visitCode();
58+
mtd.visitVarInsn(ALOAD, 0);
59+
mtd.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
60+
mtd.visitInsn(RETURN);
61+
mtd.visitMaxs(1, 1);
62+
mtd.visitEnd();
63+
}
64+
65+
private void main(ClassVisitor classWriter) {
66+
MethodVisitor mtd = classWriter.visitMethod(ACC_PUBLIC | ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
67+
mtd.visitCode();
68+
69+
for (String prop : new String[] {
70+
"java.home",
71+
"java.version",
72+
"java.vendor",
73+
"java.runtime.name",
74+
"java.runtime.version",
75+
"java.vm.name",
76+
"java.vm.version",
77+
"java.vm.vendor",
78+
"os.arch"
79+
}) {
80+
String prefix = "JAVA_PROBE: " + prop + " ";
81+
// System.out.print(prefix);
82+
mtd.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
83+
mtd.visitLdcInsn(prefix);
84+
mtd.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "print", "(Ljava/lang/String;)V", false);
85+
86+
// System.out.println(System.getProperty(prop, "unset"));
87+
mtd.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
88+
mtd.visitLdcInsn(prop);
89+
mtd.visitLdcInsn("unset");
90+
mtd.visitMethodInsn(INVOKESTATIC, "java/lang/System", "getProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
91+
mtd.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
92+
}
93+
94+
mtd.visitInsn(RETURN);
95+
96+
mtd.visitMaxs(3, 2);
97+
98+
mtd.visitEnd();
99+
}
100+
}

gradle/wrapper/gradle-wrapper.jar

42.4 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)