Skip to content

Commit 0f9544c

Browse files
committed
new gradle templating
1 parent f3af534 commit 0f9544c

8 files changed

Lines changed: 245 additions & 212 deletions

File tree

build.gradle

Lines changed: 18 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,47 @@
11
plugins {
22
id 'java'
3-
id 'maven'
43
id 'groovy'
54
id 'maven-publish'
6-
id "java-gradle-plugin"
7-
id "com.gradle.plugin-publish" version "0.11.0"
85
}
96

107
group 'cam72cam.universalmodcore'
11-
version '0.1.3'
8+
version '0.1.0'
129
sourceCompatibility = 1.8
1310

1411
repositories {
1512
mavenCentral()
1613
}
1714

18-
dependencies {
19-
compile 'org.apache.commons:commons-io:1.3.2'
20-
compile 'com.google.code.gson:gson:2.8.6'
21-
compile 'org.eclipse.jgit:org.eclipse.jgit:4.4.1.201607150455-r'
22-
}
23-
24-
task javadocJar(type: Jar, dependsOn: javadoc) {
25-
from javadoc.destinationDir
26-
classifier = 'javadoc'
27-
}
28-
29-
task sourcesJar(type: Jar) {
30-
from sourceSets.main.allSource
31-
classifier = 'sources'
15+
configurations {
16+
shade
17+
implementation.extendsFrom shade
3218
}
3319

34-
artifacts {
35-
archives jar
36-
archives javadocJar
37-
archives sourcesJar
20+
dependencies {
21+
shade 'org.apache.commons:commons-io:1.3.2'
22+
shade 'com.google.code.gson:gson:2.8.6'
23+
shade 'org.eclipse.jgit:org.eclipse.jgit:4.4.1.201607150455-r'
3824
}
3925

40-
gradlePlugin {
41-
plugins {
42-
curseGradlePlugin {
43-
id = 'cam72cam.universalmodcore'
44-
implementationClass = 'cam72cam.universalmodcore.UMCPlugin'
45-
}
26+
jar {
27+
configurations.shade.each { dep ->
28+
from(project.zipTree(dep)){
29+
exclude 'META-INF', 'META-INF/**'
4630
}
47-
}
48-
31+
}
4932

50-
pluginBundle {
51-
website = 'https://github.com/TeamOpenIndustry/UniversalModCoreGradle'
52-
vcsUrl = 'https://github.com/TeamOpenIndustry/UniversalModCoreGradle'
53-
description = 'Allow users to build the same code for any minecraft version'
54-
55-
plugins() {
56-
curseGradlePlugin {
57-
displayName = 'Universal Mod Core'
58-
version = project.version
59-
tags = ['maven', 'minecraft', 'forge']
60-
}
61-
}
33+
manifest {
34+
attributes(
35+
'Main-Class': 'cam72cam.universalmodcore.Setup'
36+
)
37+
}
6238
}
6339

6440

6541
publishing {
6642
publications {
6743
mavenJava(MavenPublication) {
6844
from components.java
69-
70-
artifact sourcesJar {
71-
classifier "sources"
72-
}
73-
}
74-
}
75-
}
76-
77-
task deployJar(type: Jar)
78-
79-
configurations {
80-
deployerJars
81-
}
82-
83-
dependencies {
84-
deployerJars "org.apache.maven.wagon:wagon-ssh:2.9"
85-
}
86-
87-
uploadArchives {
88-
repositories.mavenDeployer {
89-
configuration = configurations.deployerJars
90-
repository(url: "scp://teamopenindustry.cc/var/www/html/maven/") {
91-
authentication(userName: "mavenci", privateKey: "publish_key")
9245
}
9346
}
9447
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
rootProject.name = 'UniversalModCoreGradle'
1+
rootProject.name = 'UMCSetup'
Lines changed: 141 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,172 @@
11
package cam72cam.universalmodcore;
22

3+
import com.google.gson.JsonObject;
4+
import org.apache.commons.io.FileUtils;
35
import org.apache.commons.io.IOUtils;
4-
import org.gradle.api.Project;
6+
import org.eclipse.jgit.api.errors.GitAPIException;
57

68
import java.io.*;
79
import java.net.URL;
10+
import java.nio.file.Files;
11+
import java.nio.file.Paths;
812
import java.util.*;
13+
import java.util.stream.Collectors;
914

1015
public class Config {
11-
public String modPackage;
12-
public String modClass;
13-
public String modName;
14-
public String modId;
15-
public String modVersion;
16+
public final Mod mod;
17+
public final Integration integration;
18+
public final UMC umc;
19+
private final Map<String, String> vars = new HashMap<>();
20+
public final String minecraftLoader;
21+
22+
public static class Mod {
23+
public final String pkg;
24+
public final String cls;
25+
public final String name;
26+
public final String id;
27+
public final String version;
28+
public final List<Dependency> dependencies;
29+
30+
public static class Dependency {
31+
public final String id;
32+
public final String versions;
33+
public Dependency(String id, JsonObject data) {
34+
this.id = id;
35+
this.versions = data.get("versions").getAsString();
36+
}
37+
public Dependency(String id, String versions) {
38+
this.id = id;
39+
this.versions = versions;
40+
}
41+
}
42+
43+
public Mod(JsonObject data) {
44+
this.pkg = data.get("pkg").getAsString();
45+
this.cls = data.get("cls").getAsString();
46+
this.name = data.get("name").getAsString();
47+
this.id = data.get("id").getAsString();
48+
this.version = data.get("version").getAsString();
49+
this.dependencies = data.get("dependencies").getAsJsonObject().entrySet().stream()
50+
.map((e) -> new Dependency(e.getKey(), e.getValue().getAsJsonObject()))
51+
.collect(Collectors.toList());
52+
}
53+
}
1654

17-
public String umcVersion;
18-
public String umcPath;
55+
public static class Integration {
56+
public final String repo;
57+
public final String branch;
58+
public final String path;
1959

20-
public Config(Project project) {
21-
// What to do here?
60+
public Integration(JsonObject data) {
61+
this.repo = data.get("repo").getAsString();
62+
this.branch = data.get("branch").getAsString();
63+
this.path = data.get("path").getAsString();
64+
}
2265
}
2366

24-
private final Map<String, String> vars = new HashMap<>();
67+
public static class UMC {
68+
public final String version;
69+
public final String path;
2570

26-
public void init() {
27-
vars.clear();
28-
vars.put("PACKAGE", require("modPackage", modPackage));
29-
vars.put("PACKAGEPATH", require("modPackage", modPackage).replace(".", File.separator));
30-
vars.put("CLASS", require("modClass", modClass));
31-
vars.put("NAME", require("modName", modName));
32-
vars.put("ID", require("modId", modId));
33-
vars.put("VERSION", require("modVersion", modVersion));
34-
35-
String loaderVersion = System.getProperty("umc.loader");
36-
if (loaderVersion == null || loaderVersion.length() == 0) {
37-
throw new RuntimeException("Missing command argument: -D umc.loader=<loader>_<version>");
71+
public UMC(JsonObject data) {
72+
this.version = data.get("version").getAsString();
73+
this.path = data.has("path") ? data.get("path").getAsString() : null;
3874
}
75+
}
3976

40-
vars.put("LOADER_VERSION", require("loaderVersion", loaderVersion));
77+
public Config(JsonObject data, String loaderBranch) throws GitAPIException, IOException {
78+
mod = new Mod(data.get("mod").getAsJsonObject());
79+
integration = data.has("integration") ? new Integration(data.get("integration").getAsJsonObject()) : null;
80+
umc = new UMC(data.get("umc").getAsJsonObject());
81+
String minecraft = loaderBranch.split("-")[0];
82+
String loader = loaderBranch.split("-")[1];
83+
this.minecraftLoader = minecraft + "-" + loader;
84+
85+
vars.clear();
86+
vars.put("PACKAGE", require("mod.package", mod.pkg));
87+
vars.put("PACKAGEPATH", require("mod.package", mod.pkg).replace(".", File.separator));
88+
vars.put("CLASS", require("mod.class", mod.cls));
89+
vars.put("NAME", require("mod.name", mod.name));
90+
vars.put("ID", require("mod.id", mod.id));
91+
vars.put("VERSION", require("mod.version", mod.version));
92+
vars.put("LOADER_VERSION", loaderBranch);
93+
vars.put("MINECRAFT", minecraft);
94+
vars.put("LOADER", loader);
95+
96+
String version = require("umc.version", umc.version);
97+
98+
if (version.equals("latest")) {
99+
File path;
100+
File temp = null;
101+
if (umc.path == null) {
102+
temp = Files.createTempDirectory("umc-loader").toFile();
103+
Util.gitClone("https://github.com/TeamOpenIndustry/UniversalModCore.git", loaderBranch, temp, false);
104+
path = temp;
105+
} else {
106+
path = Paths.get(System.getProperty("user.dir"), umc.path).toFile();
107+
}
108+
version = Files.readAllLines(Paths.get(path.getPath(), "build.gradle")).stream()
109+
.filter(x -> x.startsWith("String umcVersion = "))
110+
.findFirst()
111+
.get()
112+
.replace("String umcVersion = ", "")
113+
.replace("\"", "")
114+
.trim();
115+
version += "-" + Util.gitRevision(path);
116+
117+
if (temp != null) {
118+
FileUtils.deleteDirectory(temp);
119+
}
120+
}
41121

42-
String version = require("umcVersion", umcVersion);
43-
vars.put("UMC_VERSION", version);
44122
String[] versionParts = version.split("\\.");
45123
int major = Integer.parseInt(versionParts[0]);
46124
int minor = Integer.parseInt(versionParts[1]);
47125
vars.put("UMC_API", String.format("%d.%d", major, minor));
48126
vars.put("UMC_API_NEXT", String.format("%d.%d", major, minor + 1));
49127

128+
vars.put("UMC_VERSION", version);
50129

51-
if (umcPath != null && umcPath.length() != 0) {
52-
File jar = new File(umcPath, String.format("UniversalModCore-%s-%s.jar", loaderVersion, umcVersion));
130+
131+
if (umc.path != null && umc.path.length() != 0) {
132+
File jar = new File(umc.path, String.format("build/libs/UniversalModCore-%s-%s.jar", loaderBranch, version));
53133
if (!jar.exists()) {
54134
throw new RuntimeException(String.format("Unable to find UMC jar: %s", jar));
55135
}
56136
vars.put("UMC_REPO", String.format("repositories { flatDir { dirs '%s' } }", jar.getParent()));
57137
vars.put("UMC_DEPENDENCY", String.format("name: '%s'", jar.getName().replace(".jar", "")));
58138
vars.put("UMC_FILE", jar.getPath());
59139
} else {
60-
vars.put("UMC_DOWNLOAD", String.format("https://teamopenindustry.cc/maven/cam72cam/universalmodcore/UniversalModCore/%s-%s/UniversalModCore-%s-%s.jar", loaderVersion, version, loaderVersion, version));
61-
vars.put("UMC_DEPENDENCY", String.format("'cam72cam.universalmodcore:UniversalModCore:%s-%s'", loaderVersion, version));
62140
vars.put("UMC_REPO", "repositories { maven { url = \"https://teamopenindustry.cc/maven\" }}");
63-
141+
vars.put("UMC_DEPENDENCY", String.format("'cam72cam.universalmodcore:UniversalModCore:%s-%s'", loaderBranch, version));
142+
vars.put("UMC_DOWNLOAD", String.format("https://teamopenindustry.cc/maven/cam72cam/universalmodcore/UniversalModCore/%s-%s/UniversalModCore-%s-%s.jar", loaderBranch, version, loaderBranch, version));
64143
}
144+
145+
ArrayList<Mod.Dependency> dependencies = new ArrayList<>(mod.dependencies);
146+
dependencies.add(new Mod.Dependency(
147+
"universalmodcore",
148+
String.format("[%s, %s)", vars.get("UMC_API"), vars.get("UMC_API_NEXT"))
149+
));
150+
151+
152+
String forgeStringDependencies = dependencies.stream()
153+
.map(dep -> String.format("required-after:%s@%s", dep.id, dep.versions))
154+
.collect(Collectors.joining("; "));
155+
vars.put("FORGE_STRING_DEPENDENCIES", forgeStringDependencies);
156+
157+
String forgeTomlDependencies = dependencies.stream()
158+
.map(dep ->
159+
String.format("[[dependencies.%s]]%n", mod.id) +
160+
String.format(" modId=\"%s\"%n", dep.id) +
161+
String.format(" mandatory=true%n") +
162+
String.format(" versionRange=\"%s\"%n", dep.versions) +
163+
String.format(" ordering=\"BEFORE\"%n") +
164+
String.format(" side=\"BOTH\"%n")
165+
)
166+
.collect(Collectors.joining(System.lineSeparator() + System.lineSeparator()));
167+
vars.put("FORGE_TOML_DEPENDENCIES", forgeTomlDependencies);
168+
169+
vars.put("FABRIC_SOMETHING_DEPENDENCIES", "TODO");
65170
}
66171

67172

@@ -79,6 +184,10 @@ public InputStream openJarStream() throws IOException {
79184
return new FileInputStream(vars.get("UMC_FILE"));
80185
}
81186

187+
public String replace(String s) {
188+
return replace(s, true);
189+
}
190+
82191
public String replace(String s, boolean hash) {
83192
List<String> keys = new ArrayList<>(vars.keySet());
84193
keys.sort(Comparator.comparingInt(String::length).reversed());
@@ -94,7 +203,7 @@ public String replace(String s, boolean hash) {
94203

95204
public InputStream replaceAll(InputStream input, boolean hash) throws IOException {
96205
String data = IOUtils.toString(input);
97-
data = replace(data, true);
206+
data = replace(data);
98207
return new ByteArrayInputStream(data.getBytes());
99208
}
100209
}

src/main/java/cam72cam/universalmodcore/CurseForge.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)