private static void generateProjectBuild(URI workspace, File output, DevProject project) throws IOException { StringBuilder builder = new StringBuilder(); File src = project.getExternalSrcDir(); File res = project.getExternalResDir(); File testSrc = project.getExternalTestSrcDir(); File testRes = project.getExternalTestResDir(); // @formatter:off // why use relatvie paths? so the eclipse hack below can work correctly. // add extra sourceDirs append(builder, "sourceSets {", NEWLINE); append( builder, INDENT, "main.java.srcDir 'src/main/start'", NEWLINE); // add start dir to gradle sources if (src != null) append(builder, INDENT, "main.java.srcDir '", relative(workspace, src), "'", NEWLINE); if (res != null) append(builder, INDENT, "main.resources.srcDir '", relative(workspace, res), "'", NEWLINE); if (testSrc != null) append(builder, INDENT, "test.java.srcDir '", relative(workspace, testSrc), "'", NEWLINE); if (testRes != null) append( builder, INDENT, "test.resources.srcDir '", relative(workspace, testRes), "'", NEWLINE); append(builder, "}"); // @formatter:on // write Files.write(builder.toString(), output, Constants.CHARSET); }
@OutputFiles public List<File> getGeneratedFiles() { List<File> files = new ArrayList<File>(2 + projects.size()); File workspace = getWorkspaceDir(); files.add(new File(workspace, "build.gradle")); files.add(new File(workspace, "settings.gradle")); for (DevProject p : projects.values()) { files.add(new File(p.getProjectDir(workspace) + "/build.gradle")); } return files; }
@TaskAction public void executeTask() throws IOException { File workspace = getWorkspaceDir(); workspace.mkdirs(); // make run dir just in case new File(workspace, "run").mkdirs(); generateRootBuild(new File(workspace, "build.gradle")); generateRootSettings(new File(workspace, "settings.gradle"), projects.keySet()); URI workspaceUri = workspace.toURI(); for (DevProject project : projects.values()) { File projectDir = project.getProjectDir(workspace); projectDir.mkdirs(); generateProjectBuild(workspaceUri, new File(projectDir, "build.gradle"), project); } }