Skip to content

Commit 27249b9

Browse files
committed
Fix javadocs injection
1 parent 59fb3ce commit 27249b9

File tree

5 files changed

+26
-30
lines changed

5 files changed

+26
-30
lines changed

src/main/java/net/minecraftforge/mcmaven/cli/MCPTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public static void run(String[] args) throws Exception {
218218
? new ParchmentMappings(options.valueOf(parchmentO))
219219
: new Mappings("official", null).withMCVersion(MinecraftMaven.mcpToMcVersion(artifact.getVersion()));
220220

221-
var renameTask = new RenameTask(side.getBuildFolder(), pipeline, side, sourcesTask, mappings);
221+
var renameTask = new RenameTask(side.getBuildFolder(), pipeline, side, sourcesTask, mappings, false);
222222
sources = renameTask.execute();
223223
} finally {
224224
Log.pop(indent);

src/main/java/net/minecraftforge/mcmaven/impl/repo/forge/ForgeRepo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private List<PendingArtifact> processV3(String version, Mappings mappings) {
133133

134134
var patcher = new Patcher(build, this, userdev);
135135
var joined = patcher.getMCP().getSide(MCPSide.JOINED);
136-
var sourcesTask = new RenameTask(build, userdev, joined, patcher.get(), mappings);
136+
var sourcesTask = new RenameTask(build, userdev.getName(), joined, patcher.get(), mappings, true);
137137
var recompile = new RecompileTask(build, name, patcher.getMCP(), patcher::getClasspath, sourcesTask, mappings);
138138
var classesTask = new InjectTask(build, this.cache, name, patcher, recompile, mappings);
139139

src/main/java/net/minecraftforge/mcmaven/impl/repo/mcpconfig/MCPConfigRepo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public List<PendingArtifact> process(Artifact artifact, Mappings mappings) {
117117
default -> {
118118
var pending = new ArrayList<PendingArtifact>();
119119

120-
var sourcesTask = new RenameTask(build, name, mcpSide, mcpSide.getSources(), mappings);
120+
var sourcesTask = new RenameTask(build, name.getName(), mcpSide, mcpSide.getSources(), mappings, true);
121121
var recompile = new RecompileTask(build, name, mcpSide.getMCP(), mcpSide::getClasspath, sourcesTask, mappings);
122122
var classesTask = mergeExtra(build, side, recompile, mcpSide.getTasks().getExtra(), mappings);
123123

src/main/java/net/minecraftforge/mcmaven/impl/tasks/MCPNames.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@
3737
// TODO [Mavenizer][MCPNames] This is also in ForgeDev! Consolidate this!
3838
// TODO [Mavenizer][MCPNames] GARBAGE GARBAGE GARBAGE, CLEAN UP OR RE-IMPLEMENT
3939
record MCPNames(String hash, Map<String, String> names, Map<String, String> docs) {
40+
// We use \n here because we want to normalize line endings no matter the operating system we are running on.
41+
private static final String LINE_SEPERATOR = "\n"; //System.lineSeparator();
4042
//@formatter:off
4143
private static final Pattern
4244
SRG_FINDER = Pattern.compile("[fF]unc_\\d+_[a-zA-Z_]+|m_\\d+_|[fF]ield_\\d+_[a-zA-Z_]+|f_\\d+_|p_\\w+_\\d+_|p_\\d+_"),
43-
CONSTRUCTOR_JAVADOC_PATTERN = Pattern.compile("^(?<indent>(?: {3})+|\\t+)(public |private|protected |)(?<generic><[\\w\\W]*>\\s+)?(?<name>[\\w.]+)\\((?<parameters>.*)\\)\\s+(?:throws[\\w.,\\s]+)?\\{"),
44-
METHOD_JAVADOC_PATTERN = Pattern.compile("^(?<indent>(?: {3})+|\\t+)(?!return)(?:\\w+\\s+)*(?<generic><[\\w\\W]*>\\s+)?(?<return>\\w+[\\w$.]*(?:<[\\w\\W]*>)?[\\[\\]]*)\\s+(?<name>(?:func_|m_)[0-9]+_[a-zA-Z_]*)\\("),
45-
FIELD_JAVADOC_PATTERN = Pattern.compile("^(?<indent>(?: {3})+|\\t+)(?!return)(?:\\w+\\s+)*\\w+[\\w$.]*(?:<[\\w\\W]*>)?[\\[\\]]*\\s+(?<name>(?:field_|f_)[0-9]+_[a-zA-Z_]*) *[=;]"),
45+
CONSTRUCTOR_JAVADOC_PATTERN = Pattern.compile("^(?<indent> *|\\t+)(public |private|protected |)(?<generic><[\\w\\W]*>\\s+)?(?<name>[\\w.]+)\\((?<parameters>.*)\\)\\s+(?:throws[\\w.,\\s]+)?\\{"),
46+
METHOD_JAVADOC_PATTERN = Pattern.compile("^(?<indent> *|\\t+)(?!return)(?:\\w+\\s+)*(?<generic><[\\w\\W]*>\\s+)?(?<return>\\w+[\\w$.]*(?:<[\\w\\W]*>)?[\\[\\]]*)\\s+(?<name>(?:func_|m_)[0-9]+_[a-zA-Z_]*)\\("),
47+
FIELD_JAVADOC_PATTERN = Pattern.compile("^(?<indent> *|\\t+)(?!return)(?:\\w+\\s+)*\\w+[\\w$.]*(?:<[\\w\\W]*>)?[\\[\\]]*\\s+(?<name>(?:field_|f_)[0-9]+_[a-zA-Z_]*) *[=;]"),
4648
CLASS_JAVADOC_PATTERN = Pattern.compile("^(?<indent> *|\\t*)([\\w|@]*\\s)*(class|interface|@interface|enum) (?<name>[\\w]+)"),
4749
CLOSING_CURLY_BRACE = Pattern.compile("^(?<indent> *|\\t*)}"),
4850
PACKAGE_DECL = Pattern.compile("^[\\s]*package(\\s)*(?<name>[\\w|.]+);$"),
@@ -67,8 +69,10 @@ private static Data loadData(File data) throws IOException {
6769
names.put(searge, row.getField("name"));
6870
if (header.contains("desc")) {
6971
String desc = row.getField("desc");
70-
if (!desc.isBlank())
72+
if (!desc.isBlank()) {
73+
desc = desc.replace("\\n", "\n");
7174
docs.put(searge, desc);
75+
}
7276
}
7377
}
7478
}
@@ -134,7 +138,7 @@ String rename(InputStream stream, boolean javadocs, boolean lambdas, Charset sou
134138
}
135139
lines.add(replaceInLine(line, blacklist));
136140
}
137-
return String.join(System.lineSeparator(), lines);
141+
return String.join(LINE_SEPERATOR, lines);
138142
}
139143

140144
/**
@@ -279,18 +283,18 @@ static String buildJavadoc(String indent, String javadoc, boolean multiline) {
279283
if (list.size() > 1 || multiline) {
280284
builder.append(indent);
281285
builder.append("/**");
282-
builder.append(System.lineSeparator());
286+
builder.append(LINE_SEPERATOR);
283287

284288
for (String line : list) {
285289
builder.append(indent);
286290
builder.append(" * ");
287291
builder.append(line);
288-
builder.append(System.lineSeparator());
292+
builder.append(LINE_SEPERATOR);
289293
}
290294

291295
builder.append(indent);
292296
builder.append(" */");
293-
//builder.append(System.lineSeparator());
297+
//builder.append(LINE_SEPERATOR);
294298

295299
}
296300
// one line
@@ -299,7 +303,7 @@ static String buildJavadoc(String indent, String javadoc, boolean multiline) {
299303
builder.append("/** ");
300304
builder.append(javadoc);
301305
builder.append(" */");
302-
//builder.append(System.lineSeparator());
306+
//builder.append(LINE_SEPERATOR);
303307
}
304308

305309
return builder.toString().replace(indent, indent);

src/main/java/net/minecraftforge/mcmaven/impl/tasks/RenameTask.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
public final class RenameTask implements Task {
3232
private final String name;
3333
private final MCPSide side;
34+
private final boolean javadocs;
3435
private final Task task;
3536

3637
/**
@@ -39,21 +40,12 @@ public final class RenameTask implements Task {
3940
* @param build The directory where the output will be stored
4041
* @param name The development artifact, only used for the task name
4142
* @param sources The task that creates the unnamed sources
43+
* @param javadocs Wither to inject javadocs and rename lambda parameters, false is used for ForgeDev as we remap to SRG patches when making userdev
4244
*/
43-
public RenameTask(File build, Artifact name, MCPSide side, Task sources, Mappings mappings) {
44-
this(build, name.getName(), side, sources, mappings);
45-
}
46-
47-
/**
48-
* Creates a new renamer for the given patcher.
49-
*
50-
* @param build The directory where the output will be stored
51-
* @param name The development artifact, only used for the task name
52-
* @param sources The task that creates the unnamed sources
53-
*/
54-
public RenameTask(File build, String name, MCPSide side, Task sources, Mappings mappings) {
45+
public RenameTask(File build, String name, MCPSide side, Task sources, Mappings mappings, boolean javadocs) {
5546
this.name = name;
5647
this.side = side;
48+
this.javadocs = javadocs;
5749
this.task = this.remapSources(sources, mappings.getFolder(build), mappings);
5850
}
5951

@@ -73,21 +65,22 @@ public String name() {
7365
}
7466

7567
private Task remapSources(Task input, File outputDir, Mappings provider) {
76-
var output = new File(outputDir, "remapped.jar");
68+
var output = new File(outputDir, !this.javadocs ? "remapped.jar" : "remapped-javadoc.jar");
7769
var mappings = provider.getCsvZip(side);
78-
return Task.named("remap[" + this.name + "][" + provider + ']',
70+
return Task.named("remap[" + this.name + "][" + provider + ']' + (!this.javadocs ? "" : "[javadoc]"),
7971
Task.deps(input, mappings),
80-
() -> remapSourcesImpl(input, mappings, output)
72+
() -> remapSourcesImpl(input, mappings, output, javadocs)
8173
);
8274
}
8375

84-
private static File remapSourcesImpl(Task inputTask, Task mappingsTask, File output) {
76+
private static File remapSourcesImpl(Task inputTask, Task mappingsTask, File output, boolean javadocs) {
8577
var input = inputTask.execute();
8678
var mappings = mappingsTask.execute();
8779

8880
var cache = HashStore.fromFile(output);
8981
cache.add("input", input);
9082
cache.add("mappings", mappings);
83+
cache.add("javadocs", javadocs ? "true" : "false");
9184

9285
if (output.exists() && cache.isSame())
9386
return output;
@@ -96,7 +89,6 @@ private static File remapSourcesImpl(Task inputTask, Task mappingsTask, File out
9689

9790
try {
9891
var names = MCPNames.load(mappings);
99-
names.rename(new FileInputStream(input), true);
10092

10193
// TODO: [MCMavenizer][Renamer] This garbage was copy-pasted from FG.
10294
// I changed the while loop to a for loop, though. I guess it is fine?
@@ -107,7 +99,7 @@ private static File remapSourcesImpl(Task inputTask, Task mappingsTask, File out
10799
zout.putNextEntry(FileUtils.getStableEntry(entry.getName()));
108100

109101
if (entry.getName().endsWith(".java")) {
110-
var mapped = names.rename(zin, false);
102+
var mapped = names.rename(zin, javadocs, javadocs);
111103
IOUtils.write(mapped, zout, StandardCharsets.UTF_8);
112104
} else {
113105
IOUtils.copy(zin, zout);

0 commit comments

Comments
 (0)