Skip to content

Commit 1dfadbf

Browse files
authored
Fixed prepWatch preprocessing into the wrong folder (#28)
2 parents 119b8de + 6f4bc82 commit 1dfadbf

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

src/main/java/com/minecrafttas/discombobulator/tasks/TaskCollectBuilds.java

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package com.minecrafttas.discombobulator.tasks;
22

3-
import java.io.File;
3+
import java.io.IOException;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
import java.nio.file.StandardCopyOption;
47
import java.util.HashMap;
58
import java.util.List;
69
import java.util.Map;
710
import java.util.Map.Entry;
11+
import java.util.stream.Stream;
812

913
import org.gradle.api.DefaultTask;
1014
import org.gradle.api.Project;
@@ -21,17 +25,43 @@ public class TaskCollectBuilds extends DefaultTask {
2125
/**
2226
* List of all build dirs
2327
*/
24-
private Map<String, File> buildDirs = new HashMap<>();
28+
private Map<String, Path> buildDirs = new HashMap<>();
2529

2630
@TaskAction
2731
public void collectBuilds() {
28-
File collectDir = getBuildDir(getProject());
29-
collectDir.mkdirs();
30-
for (Entry<String, File> entry : buildDirs.entrySet()) {
31-
File buildDir = entry.getValue();
32-
for (File artifact : buildDir.listFiles()) {
33-
artifact.renameTo(new File(collectDir, artifact.getName()));
32+
Path collectDir = getBuildDir(getProject());
33+
34+
try {
35+
if (!Files.exists(collectDir))
36+
Files.createDirectory(collectDir);
37+
} catch (IOException e) {
38+
e.printStackTrace();
39+
return;
40+
}
41+
42+
for (Entry<String, Path> entry : buildDirs.entrySet()) {
43+
Path buildDir = entry.getValue();
44+
Stream<Path> stream;
45+
46+
try {
47+
stream = Files.list(buildDir);
48+
} catch (IOException e) {
49+
e.printStackTrace();
50+
return;
3451
}
52+
53+
stream.forEach(path -> {
54+
Path targetFile = collectDir.resolve(path.getFileName());
55+
56+
try {
57+
Files.move(path, targetFile, StandardCopyOption.REPLACE_EXISTING);
58+
} catch (IOException e) {
59+
e.printStackTrace();
60+
return;
61+
}
62+
});
63+
64+
stream.close();
3565
}
3666
}
3767

@@ -43,7 +73,7 @@ public void collectBuilds() {
4373
public void updateCompileTasks(List<Task> compileTasks) {
4474
for (Task task : compileTasks) {
4575
Project project = task.getProject();
46-
this.buildDirs.put(project.getName(), new File(getBuildDir(project), "libs"));
76+
this.buildDirs.put(project.getName(), getBuildDir(project).resolve("libs"));
4777
}
4878
this.setDependsOn(compileTasks);
4979
}
@@ -52,7 +82,7 @@ public void updateCompileTasks(List<Task> compileTasks) {
5282
* @param project The project to use
5383
* @return The build directory from the project
5484
*/
55-
private File getBuildDir(Project project) {
56-
return project.getLayout().getBuildDirectory().getAsFile().get();
85+
private Path getBuildDir(Project project) {
86+
return project.getLayout().getBuildDirectory().get().getAsFile().toPath();
5787
}
5888
}

src/main/java/com/minecrafttas/discombobulator/tasks/TaskPreprocessWatch.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,10 @@ protected void onModifyFile(Path path) {
172172
for (Entry<String, Path> versionPair : versions.entrySet()) {
173173
String versionName = versionPair.getKey();
174174
Path targetProject = versionPair.getValue();
175+
Path targetSubSourceDir = targetProject.resolve("src");
175176

176177
// Write file
177-
Path outFile = targetProject.resolve(inFile);
178+
Path outFile = targetSubSourceDir.resolve(inFile);
178179

179180
if (ignore) {
180181
Files.copy(inFile, outFile, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES);
@@ -185,7 +186,7 @@ protected void onModifyFile(Path path) {
185186
List<String> outLines = Discombobulator.processor.preprocess(versionName, linesToProcess, filename, extension);
186187

187188
// If the version equals the original version, then skip it
188-
if (targetProject.equals(subSourceDir)) {
189+
if (targetSubSourceDir.equals(subSourceDir)) {
189190
currentFileUpdater = Triple.of(outLines, path, outFile);
190191
continue;
191192
}

0 commit comments

Comments
 (0)