|
7 | 7 | import org.comroid.api.attr.Named; |
8 | 8 | import org.comroid.api.java.gen.JavaSourcecodeWriter; |
9 | 9 | import org.gradle.api.DefaultTask; |
10 | | -import org.gradle.api.tasks.InputDirectory; |
11 | | -import org.gradle.api.tasks.OutputDirectory; |
| 10 | +import org.gradle.api.Task; |
| 11 | +import org.gradle.api.artifacts.ConfigurationContainer; |
12 | 12 | import org.gradle.api.tasks.SourceSetContainer; |
13 | 13 | import org.gradle.api.tasks.TaskAction; |
14 | 14 | import org.intellij.lang.annotations.Language; |
|
39 | 39 | public abstract class GenerateSpigotResourceClassesTask extends DefaultTask { |
40 | 40 | private final Set<String> terminalNodes = new HashSet<>(); |
41 | 41 |
|
42 | | - @InputDirectory |
43 | | - public File getPluginResourcesDirectory() { |
44 | | - return getProject().getExtensions().getByType(SourceSetContainer.class) |
45 | | - .getByName("main").getResources() |
46 | | - .getSrcDirs().iterator().next(); |
47 | | - } |
| 42 | + { |
| 43 | + var src = getProject().getExtensions().getByType(SourceSetContainer.class); |
| 44 | + var srcMain = src.getByName("main"); |
| 45 | + |
| 46 | + var outputDir = srcMain.getJava().getAsPath().replace("main", "generated"); |
| 47 | + var srcGen = src.create("generated", it -> { |
| 48 | + it.getJava().srcDir(outputDir); |
| 49 | + it.setCompileClasspath(srcMain.getCompileClasspath()); |
| 50 | + it.setRuntimeClasspath(srcMain.getRuntimeClasspath()); |
| 51 | + }); |
| 52 | + |
| 53 | + var inputs = getInputs(); |
| 54 | + inputs.dir(srcMain.getResources().getSourceDirectories()); |
| 55 | + inputs.dir(getProject().getTasks().getByName("processResources").getOutputs()); |
| 56 | + |
| 57 | + var outputs = getOutputs(); |
| 58 | + outputs.dir(outputDir); |
48 | 59 |
|
49 | | - @OutputDirectory |
50 | | - public File getGeneratedSourceCodeDirectory() { |
51 | | - return new File(getProject().getLayout().getBuildDirectory().getAsFile().get(), "generated/sources/r/"); |
| 60 | + var cfgs = getProject().getConfigurations(); |
| 61 | + var cfgMain = cfgs.getByName(srcMain.getCompileClasspathConfigurationName()); |
| 62 | + var cfgGen = cfgs.getByName(srcGen.getCompileClasspathConfigurationName()); |
| 63 | + cfgGen.extendsFrom(cfgMain); |
52 | 64 | } |
53 | 65 |
|
54 | 66 | @TaskAction |
55 | 67 | public void generate() { |
56 | | - try (var pluginYml = new FileInputStream(new File(getPluginResourcesDirectory(), "plugin.yml"))) { |
| 68 | + try (var pluginYml = new FileInputStream(getInputs().getFiles().filter(f -> "plugin.yml".equals(f.getName())).getSingleFile())) { |
57 | 69 | Map<String, Object> yml = new Yaml().load(pluginYml); |
58 | 70 | var main = (String) yml.get("main"); |
59 | 71 | var lio = main.lastIndexOf('.'); |
60 | 72 | var pkg = main.substring(0, lio); |
61 | | - var pkgDir = new File(getGeneratedSourceCodeDirectory(), pkg.replace('.', '/')); |
| 73 | + var pkgDir = new File(getOutputs().getFiles().filter(f -> "java".equals(f.getName())).getAsPath() + '/' + pkg.replace('.', '/')); |
62 | 74 | if (!pkgDir.exists() && !pkgDir.mkdirs()) |
63 | 75 | throw new RuntimeException("Unable to create output directory"); |
64 | 76 | try ( |
@@ -143,7 +155,7 @@ private void generateCommandsEnum(JavaSourcecodeWriter java, Map<String, Object> |
143 | 155 | private void cleanupKeys(Map<String, Map<String, Object>> permissions, String compoundKey, int depth) { |
144 | 156 | for (var permissionKey : permissions.keySet().toArray(String[]::new)) { |
145 | 157 | // only when path blob count differs from depth |
146 | | - var count = permissionKey.chars().filter(x->x=='.').count(); |
| 158 | + var count = permissionKey.chars().filter(x -> x == '.').count(); |
147 | 159 | if (count == depth) continue; |
148 | 160 | if (count < depth) throw new IllegalArgumentException("Inner permissionKey does not have enough path blobs: " + permissionKey); |
149 | 161 |
|
|
0 commit comments