forked from MinecraftForge/MinecraftMavenizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMavenTask.java
More file actions
223 lines (185 loc) · 9.4 KB
/
MavenTask.java
File metadata and controls
223 lines (185 loc) · 9.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.mcmaven.cli;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import joptsimple.OptionParser;
import joptsimple.OptionSpecBuilder;
import net.minecraftforge.mcmaven.impl.Mavenizer;
import net.minecraftforge.mcmaven.impl.MinecraftMaven;
import net.minecraftforge.mcmaven.impl.cache.Cache;
import net.minecraftforge.mcmaven.impl.mappings.Mappings;
import net.minecraftforge.mcmaven.impl.mappings.ParchmentMappings;
import net.minecraftforge.mcmaven.impl.util.Artifact;
import net.minecraftforge.mcmaven.impl.util.Constants;
import static net.minecraftforge.mcmaven.impl.Mavenizer.LOGGER;
class MavenTask {
static OptionParser run(String[] args, boolean getParser) throws Exception {
var parser = new OptionParser();
parser.allowsUnrecognizedOptions();
//@formatter:off
// help message
var helpO = parser.accepts("help",
"Displays this help message and exits")
.forHelp();
// root cache directory
var cacheO = parser.accepts("cache",
"Directory to store data needed for this program")
.withRequiredArg().ofType(File.class).defaultsTo(new File("cache"));
// per-projct cache directory, This is where all the post processed files are cached
var localCacheO = parser.accepts("local-cache",
"Directory to store the project specific cache files, opposed to the global cache")
.withRequiredArg().ofType(File.class).defaultsTo(new File("cache/local"));
// jdk cache directory
var jdkCacheO = parser.accepts("jdk-cache",
"Directory to store jdks downloaded from the disoco api")
.withRequiredArg().ofType(File.class).defaultsTo(new File("cache/jdks"));
// artifact version (NOT "display the program version")
var versionO = parser.accepts("version",
"The specific artifact version to generate")//, if none is specified, will attempt the 'latest' and 'recommended' for each Minecraft version")
.withOptionalArg().ofType(String.class);
// artifact to generate
var artifactO = parser.accepts("artifact",
"The artifact to attempt to generate, see the code for supported formats")
.withRequiredArg().ofType(String.class).defaultsTo(Constants.FORGE_ARTIFACT);
// root output directory
var outputO = parser.accepts("output",
"Root directory to generate the maven repository")
.withRequiredArg().ofType(File.class).defaultsTo(new File("output"));
// dependencies only
var dependenciesOnlyO = parser.accepts("dependencies-only",
"Outputs the maven containing only the Gradle Module and POM for the artifact's dependencies without outputting the artifact itself");
// offline mode, fail on downloads
var offlineO = parser.accepts("offline",
"Do not attempt to download anything (allows offline operations, if possible)")
.forHelp();
// cache only, fail if out-of-date
var cacheOnlyO = parser.accepts("cache-only",
"Only use caches, fail if any downloads need to occur or if a task needs to do work");
// ignore caches, currently only invalidates HashStore entries
var ignoreCacheO = parser.accepts("ignore-cache",
"Forces all cache checks to fail, which results in all tasks re-running")
.availableUnless(cacheOnlyO);
cacheOnlyO.availableUnless(ignoreCacheO);
// Add extra memory to the java decompile and recompile tasks
var decompileMemoryO = parser.accepts("decompile-memory",
"Overrides the -Xmx argument passed into the decompile sub-processes")
.withRequiredArg();
var mappingsO = parser.accepts("mappings",
"Mappings to use for this artifact. Formatted as channel:version")
.withRequiredArg().ofType(String.class).defaultsTo("official");
var parchmentO = parser.accepts("parchment",
"Version of parchment mappings to use, snapshots are not supported")
.availableUnless(mappingsO)
.withRequiredArg();
var foreignRepositoryO = parser.accepts("repository",
"EXPERIMENTAL: URL of a foreign maven repository to use for dependencies. The format is \"name,url\". The name must not include any commas.")
.withRequiredArg().ofType(String.class);
var globalAuxiliaryVariantsO = parser.accepts("global-auxiliary-variants",
"Declares sources and javadoc jars as global variants, no matter the mapping version. This is used to work around gradle/gradle#35065");
var disableGradleO = parser.accepts("disable-gradle",
"Disabels the gradle module file, and writes all mappings to the main artifact files.");
var stubO = parser.accepts("stub",
"Runs any generated jar through a stub tool, deleteing data files and stubing all class files. The resulting jar can be compiled against but is non-functional.");
var accessTransformerO = parser.accepts("access-transformer",
"An AccessTransformer config to apply to the artifacts have been built. This is a work around for Gradle's broken ArtifactTransformer system. https://github.com/MinecraftForge/ForgeGradle/issues/1023")
.withRequiredArg().ofType(File.class);
var facadeConfigO = parser.accepts("facade-config",
"A Facade Config, which allows injecting interfaces to the built artifacts.")
.withRequiredArg().ofType(File.class);
var outputJsonO = parser.accepts("output-json",
"File to write extended output data to. Not compatible with bulk operations.")
.withRequiredArg().ofType(File.class);
var shorthandOptions = new HashMap<String, OptionSpecBuilder>();
var artifacts = Map.of(
"forge", Constants.FORGE_ARTIFACT,
"fml", Constants.FMLONLY_ARTIFACT,
"mc", "net.minecraft:joined",
"joined", "net.minecraft:joined",
"client", "net.minecraft:client",
"server", "net.minecraft:server",
"mapping-data", "net.minecraft:mappings"
);
for (var entry : artifacts.entrySet()) {
var key = entry.getKey();
var option = parser.accepts(entry.getKey(),
"Shorthand for --artifact " + entry.getValue());
shorthandOptions.put(key, option);
// do not allow with --artifact
option.availableUnless(artifactO);
}
shorthandOptions.forEach((key, option) -> {
// do not allow with other keys in the artifacts map
for (var other : shorthandOptions.keySet()) {
if (!other.equals(key))
option.availableUnless(other);
}
});
//@formatter:on
if (getParser)
return parser;
var options = parser.parse(args);
if (options.has(helpO)) {
parser.printHelpOn(LOGGER.getInfo());
LOGGER.release();
return parser;
}
// global options
if (options.has(offlineO))
Mavenizer.setOffline();
if (options.has(cacheOnlyO))
Mavenizer.setCacheOnly();
if (options.has(ignoreCacheO))
Mavenizer.setIgnoreCache();
if (options.has(decompileMemoryO))
Mavenizer.setDecompileMemory(options.valueOf(decompileMemoryO));
var output = options.valueOf(outputO);
var cache = options.valueOf(cacheO);
var jdkCache = !options.has(cacheO) || options.has(jdkCacheO)
? options.valueOf(jdkCacheO)
: new File(cache, "jdks");
var localCache = !options.has(cacheO) || options.has(localCacheO)
? options.valueOf(localCacheO)
: new File(cache, "local");
Artifact artifact = null;
for (var entry : artifacts.entrySet()) {
if (options.has(entry.getKey())) {
artifact = Artifact.from(entry.getValue());
break;
}
}
if (artifact == null)
artifact = Artifact.from(options.valueOf(artifactO));
if (artifact.getVersion() == null)
artifact = artifact.withVersion(options.valueOf(versionO));
var mappings = options.has(parchmentO)
? new ParchmentMappings(options.valueOf(parchmentO))
: Mappings.of(options.valueOf(mappingsO));
var foreignRepositories = new HashMap<String, String>();
for (var s : options.valuesOf(foreignRepositoryO)) {
var split = s.split(",", 2);
foreignRepositories.put(split[0], split[1]);
}
var mcmaven = new MinecraftMaven(
output,
options.has(dependenciesOnlyO),
new Cache(cache, localCache, jdkCache, foreignRepositories),
mappings,
foreignRepositories,
options.has(globalAuxiliaryVariantsO),
options.has(disableGradleO),
options.has(stubO),
new HashSet<>(),
new ArrayList<>(options.valuesOf(accessTransformerO)),
new ArrayList<>(options.valuesOf(facadeConfigO)),
options.valueOf(outputJsonO)
);
mcmaven.run(artifact);
return parser;
}
}