public Set<File> sources() { SourceSet sourceSet = sourceSet(project); // conf & public Set<File> src = new LinkedHashSet<>(sourceSet.getResources().getSrcDirs()); // source java: always add parent file: should be src/main sourceSet.getJava().getSrcDirs().forEach(f -> src.add(f.getParentFile())); return src; }
private void configureSourceSetDefaults(final JavaBasePlugin javaBasePlugin) { _project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet -> { GosuSourceSet gosuSourceSet = new DefaultGosuSourceSet(sourceSet.getName(), _sourceDirectorySetFactory); Convention sourceSetConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention"); sourceSetConvention.getPlugins().put("gosu", gosuSourceSet); gosuSourceSet.getGosu().srcDir("src/" + sourceSet.getName() + "/gosu"); sourceSet.getResources().getFilter().exclude(element -> gosuSourceSet.getGosu().contains(element.getFile())); sourceSet.getAllSource().source(gosuSourceSet.getGosu()); configureGosuCompile(javaBasePlugin, sourceSet, gosuSourceSet); }); }
private void addSourceDir(String srcDirPath) { this.sourceSet.getJava().srcDir(srcDirPath); DebugLogger.debug(() -> "add source dir : " + srcDirPath); }
System.out.println(sourceSets.getAsMap()); System.out.println("--sourceSets.getByName------"); System.out.println(sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getJava().getSrcDirs()); System.out.println(sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getJava().getOutputDir()); System.out.println(sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getResources().getSrcDirs()); System.out.println(sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME).getJava().getSrcDirs()); System.out.println(sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME).getResources().getSrcDirs());
public void execute(final SourceSet sourceSet) { FregeSourceSetDirectoryFactory factory = new FregeSourceSetDirectoryFactory((ProjectInternal) project, fileResolver); final DefaultFregeSourceSet fregeSourceSet = new DefaultFregeSourceSet(((DefaultSourceSet) sourceSet).getDisplayName(), factory); new DslObject(sourceSet).getConvention().getPlugins().put("frege", fregeSourceSet); final String defaultSourcePath = String.format("src/%s/frege", sourceSet.getName()); fregeSourceSet.getFrege().srcDir(defaultSourcePath); sourceSet.getResources().getFilter().exclude(new Spec<FileTreeElement>() { public boolean isSatisfiedBy(FileTreeElement element) { return fregeSourceSet.getFrege().contains(element.getFile()); } }); sourceSet.getAllJava().source(fregeSourceSet.getFrege()); sourceSet.getAllSource().source(fregeSourceSet.getFrege()); String compileTaskName = sourceSet.getCompileTaskName("frege"); FregeCompile compile = project.getTasks().create(compileTaskName, FregeCompile.class); compile.setModule(project.file(defaultSourcePath).getAbsolutePath()); javaBasePlugin.configureForSourceSet(sourceSet, compile); compile.getConventionMapping().map("fregepath", new Callable() { public Object call() throws Exception { return sourceSet.getCompileClasspath(); } }); compile.dependsOn(sourceSet.getCompileJavaTaskName()); compile.setDescription(String.format("Compiles the %s Frege source.", sourceSet.getName())); compile.setSource(fregeSourceSet.getFrege()); project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(compileTaskName); sourceSet.compiledBy(compile); } });
new DslObject(sourceSet).getConvention().getPlugins().put("velocity", velocitySourceSet); final String srcDir = String.format("src/%s/velocity", sourceSet.getName()); velocitySourceSet.getVelocity().srcDir(srcDir); sourceSet.getAllSource().source(velocitySourceSet.getVelocity()); File outputDir = new File(outputDirectoryName); velocityTask.setOutputDir(outputDir); sourceSet.getJava().srcDir(outputDir);
@TaskAction public void run() throws IOException { final PatternSet patternSet = new PatternSet(); patternSet.setIncludes(this.input.getIncludes()); patternSet.setExcludes(this.input.getExcludes()); for (final DirectoryTree dirTree : this.input.getSrcDirTrees()) { final File dir = dirTree.getDir(); if (!dir.exists() || !dir.isDirectory()) { continue; } final FileTree tree = this.getProject().fileTree(dir).matching(this.input.getFilter()).matching(patternSet); for (final File file : tree) { final Map<Integer, String> matches = this.getFileMatches(Files.toString(file, Charsets.UTF_8)); if (!matches.isEmpty()) { System.out.println(); LOGGER.warn("{} TODO{} found in `{}`", matches.size(), matches.size() == 1 ? "" : "s", file.getName()); for (final Map.Entry<Integer, String> match : matches.entrySet()) { LOGGER.warn("L{}: {}", match.getKey(), match.getValue().trim()); } } } } }
@InputFiles public FileCollection getSourceDirs() { if (sourceDirectories != null) { return sourceDirectories.getSourceDirectories(); } else { return project.files(); } }
@Inject public DefaultEtaSourceSet(SourceSet sourceSet, String name, String displayName, SourceDirectorySetFactory sourceDirectorySetFactory) { this.sourceSet = sourceSet; this.eta = sourceDirectorySetFactory.create(name, displayName + " Eta source"); eta.getFilter().include("**/*.eta", "**/*.hs"); }
public DefaultFregeSourceSet(String displayName, FregeSourceSetDirectoryFactory sourceSetFactory) { this.frege = sourceSetFactory.newSourceSetDirectory(String.format("%s Frege source", new Object[]{displayName})); this.frege.getFilter().include(new String[]{"**/*.fr"}); this.allFrege = sourceSetFactory.newSourceSetDirectory(String.format("%s Frege source", new Object[]{displayName})); this.allFrege.source(this.frege); this.allFrege.getFilter().include(new String[]{"**/*.fr"}); }
@Override public void execute(Task task) { List<String> args = new ArrayList<>(); args.add("--module-path"); args.add(testTask.getClasspath().getAsPath()); args.add("--add-modules"); args.add("ALL-MODULE-PATH"); args.add("--add-reads"); args.add(module.geName() + "=junit"); args.add("--patch-module"); args.add(module.geName() + "=" + test.getJava().getOutputDir()); testTask.setJvmArgs(args); testTask.setClasspath(project.files()); } });
public static void configureDevSource(JavaPluginConvention javaConvention, Function<SourceSet, SourceDirectorySet> languageMapper) { SourceSet main = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); SourceSet test = javaConvention.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME); SourceSet dev = javaConvention.getSourceSets().getByName(DEV_SOURCE_SET_NAME); languageMapper.apply(dev).source(languageMapper.apply(test)); languageMapper.apply(dev).source(languageMapper.apply(main)); } }
private static void configureForSourceSet(final SourceSet sourceSet, final SourceDirectorySet sourceDirectorySet, AbstractCompile compile, final Project target) { compile.setDescription("Compiles the " + sourceDirectorySet.getDisplayName() + "."); compile.setSource(sourceSet.getJava()); compile.getConventionMapping().map("classpath", () -> sourceSet.getCompileClasspath().plus(target.files(sourceSet.getJava().getOutputDir()))); configureOutputDirectoryForSourceSet(sourceSet, sourceDirectorySet, compile, target); }
private void configureSourceSetDefaults(final JavaBasePlugin javaBasePlugin) { _project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all( sourceSet -> { DefaultGosuSourceSet gosuSourceSet = new DefaultGosuSourceSet(((DefaultSourceSet) sourceSet).getDisplayName(), _fileResolver); new DslObject(sourceSet).getConvention().getPlugins().put("gosu", gosuSourceSet); gosuSourceSet.getGosu().srcDir("src/" + sourceSet.getName() + "/gosu"); sourceSet.getResources().getFilter().exclude( element -> { return gosuSourceSet.getGosu().contains(element.getFile()); }); sourceSet.getAllSource().source(gosuSourceSet.getGosu()); configureGosuCompile(javaBasePlugin, sourceSet, gosuSourceSet); }); }
@Override public void apply(Project project) { ParsecPluginExtension pluginExtension = project.getExtensions().create("parsec", ParsecPluginExtension.class); PathUtils pathUtils = new PathUtils(project, pluginExtension); TaskContainer tasks = project.getTasks(); // Create tasks (when applied as a plugin) ParsecInitTask initTask = tasks.create("parsec-init", ParsecInitTask.class); ParsecGenerateTask generateTask = tasks.create("parsec-generate", ParsecGenerateTask.class); // Make generate trigger init. generateTask.dependsOn(initTask); project.getPlugins().withType(JavaPlugin.class, plugin -> { SourceSet sourceSet = ((SourceSetContainer) project.getProperties().get("sourceSets")).getByName("main"); // Add ${buildDir}/generated-sources/java to sources sourceSet.getJava().srcDir(pathUtils.getGeneratedSourcesPath()); // Add ${buildDir}/generated-resources/parsec to resources sourceSet.getResources().srcDir(pathUtils.getGeneratedResourcesPath()); // Make compileJava trigger generate tasks.getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME).dependsOn(generateTask); }); } }
@TaskAction @SuppressWarnings("unused") public void checkSignatures() throws IOException { final AnimalSnifferToGradleLoggingBridge loggingBridge = new AnimalSnifferToGradleLoggingBridge( getLogger() ); for ( SourceSet sourceSet : config.getSourceSets() ) { for ( ResolvedArtifact resolvedArtifact : signatures.getResolvedConfiguration().getResolvedArtifacts() ) { final File signatureFile = resolvedArtifact.getFile(); getLogger().lifecycle( "Starting AnimalSniffer checks [" + signatureFile.getName() + "] against SourceSet [" + sourceSet.getName() + "]" ); final SignatureChecker signatureChecker = new SignatureChecker( new FileInputStream( signatureFile ), buildIgnores( sourceSet, loggingBridge ), loggingBridge ); signatureChecker.setCheckJars( false ); signatureChecker.setSourcePath( new ArrayList<>( sourceSet.getJava().getSrcDirs() ) ); signatureChecker.process( sourceSet.getJava().getOutputDir() ); if ( signatureChecker.isSignatureBroken() ) { throw new GradleException( "Signature errors found for SourceSet " + sourceSet.getName() + " against " + signatureFile.getAbsolutePath() + ". " + "Verify errors and ignore them with the proper annotation if needed." ); } } } }
public void run() throws IOException { final PatternSet patternSet = new PatternSet(); patternSet.setIncludes(this.input.getIncludes()); patternSet.setExcludes(this.input.getExcludes()); final Multimap<String, Map<String, String>> fileReplacements = this.resolveReplacementsByFile(); for (final DirectoryTree dirTree : this.input.getSrcDirTrees()) { File dir = dirTree.getDir(); final FileTree tree = this.getProject().fileTree(dir).matching(this.input.getFilter()).matching(patternSet);
@Override public void execute(Task task) { List<String> args = new ArrayList<>(); args.add("--module-path"); args.add(compileTestJava.getClasspath().getAsPath()); args.add("--add-modules"); args.add("junit"); args.add("--add-reads"); args.add(module.geName() + "=junit"); args.add("--patch-module"); args.add(module.geName() + "=" + test.getJava().getSourceDirectories().getAsPath()); compileTestJava.getOptions().setCompilerArgs(args); compileTestJava.setClasspath(project.files()); } });
public VelocitySourceSet(String displayName, FileResolver fileResolver) { velocity = new DefaultSourceDirectorySet(String.format("Velocity %s source", displayName), fileResolver); velocity.getFilter().include("**/*.java"); }
public DefaultGosuSourceSet( String name, SourceDirectorySetFactory sourceDirectorySetFactory ) { this.name = name; this.baseName = name.equals(SourceSet.MAIN_SOURCE_SET_NAME) ? "" : GUtil.toCamelCase(name); displayName = GUtil.toWords(this.name); _gosu = sourceDirectorySetFactory.create("gosu", displayName + " Gosu source"); _gosu.getFilter().include(_gosuAndJavaExtensions); _allGosu = sourceDirectorySetFactory.create("gosu", displayName + " Gosu source"); _allGosu.getFilter().include(_gosuExtensionsOnly); _allGosu.source(_gosu); }