for ( File classesDir: sourceSet.getOutput().getClassesDirs() ) { final FileTree fileTree = project.fileTree( classesDir ); for ( File file : fileTree ) {
List<String> getOutputDirs() { List<String> list = new ArrayList<>(); FileCollection classesDirs = this.sourceSet.getOutput().getClassesDirs(); classesDirs.forEach(classesDir -> list.add(classesDir.getPath())); return list; }
/** * get directory urls of output (build directory contain .class and subdirectories) * uses main source set * * @param project * the project * * @return the set or empty value if input argument empty */ public static Set< URL > classPathsMainSourceSet( Project project ) { if( project == null ) { return Collections.emptySet(); } return sourceSetMain( project ).stream().map( SourceSet::getOutput ).flatMap( output -> StreamSupport.stream( output.getClassesDirs().spliterator() , false ) ).map( FileHelper::fileToUrl ).filter( Optional::isPresent ).map( Optional::get ).collect( toSet() ); }
@Override public FileCollection call() { ConfigurableFileTree fileTree = StreamSupport.stream(sourceSet.getOutput().getClassesDirs().spliterator(), false) .map(project::fileTree) .reduce((lhs, rhs) -> { lhs.plus(rhs); return lhs; }).orElseThrow(() -> new InvalidUserDataException("No classes dir configured for source set " + sourceSet.getName()) ); return fileTree.builtBy(sourceSet.getClassesTaskName()); } });
public GenerateConfig(Project project) { apiFiles = project.getConvention() .getPlugin( JavaPluginConvention.class ) .getSourceSets() .getByName( "main" ) .getOutput() .getClassesDirs(); project.afterEvaluate( p -> { if ( this.outputFile == null ) { this.outputFile = new File( new File( project.getBuildDir(), "signatures" ), project.getName() + '-' + project.getVersion() + ".signature" ); } } ); }
private FileCollection getOutputClassDir(Project project) { return project.getConvention() .getPlugin(JavaPluginConvention.class) .getSourceSets() .getByName("main") .getOutput() .getClassesDirs(); }
public ServiceLoaderTask() throws IOException { super.setDescription("Generate META-INF/services manifests for use with ServiceLoaders"); super.setGroup("Source Generation"); javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); this.main = javaConvention.getSourceSets().findByName(SourceSet.MAIN_SOURCE_SET_NAME); SourceSetOutput mainOutput = main.getOutput(); classesOutput = mainOutput.getClassesDirs(); outputDirectory = new File(mainOutput.getResourcesDir(), "META-INF/services"); }
private static Collection<File> getOutputDirs(SourceSet sourceSet) { Collection<File> result; if (GradleVersion.version("4.0").compareTo(GradleVersion.current()) <= 0) { result = sourceSet.getOutput().getClassesDirs().getFiles(); } else { result = Collections.singletonList(sourceSet.getOutput().getClassesDir()); } return exists(result); }
@Override void configure(Task task) { super.configure(task); Task prepareMonitorEnvTask = project.getTasks().findByName(AzurePlugin.PREPARE_MONITOR_ENV_TASK); Test t = (Test)task; t.setDescription("Test execution of the azureTest source set against production deployment."); t.dependsOn(prepareMonitorEnvTask); t.setClasspath(sourceSet.getRuntimeClasspath()); t.setTestClassesDirs(sourceSet.getOutput().getClassesDirs()); t.systemProperty("testEnvPath", azure.getMonitorEnvFile().get().getAsFile().getAbsolutePath()); t.setBinResultsDir(new File(project.getBuildDir(), "monitor-test-results/binary/test")); t.getReports().getHtml().setDestination(new File(project.getBuildDir(), "reports/monitor-test-results" )); t.getReports().getJunitXml().setDestination(new File(project.getBuildDir(), "monitor-test-results" )); } }
private static Collection<File> getOutputDirs(SourceSet sourceSet) { Collection<File> result; if (GradleVersion.version("4.0").compareTo(GradleVersion.current()) <= 0) { result = sourceSet.getOutput().getClassesDirs().getFiles(); } else { result = Collections.singletonList(sourceSet.getOutput().getClassesDir()); } return exists(result); }
private static void configureOutputDirectoryForSourceSet(final SourceSet sourceSet, final SourceDirectorySet sourceDirectorySet, AbstractCompile compile, final Project target) { final String sourceSetChildPath = "classes/" + sourceDirectorySet.getName() + "/" + sourceSet.getName(); sourceDirectorySet.setOutputDir(target.provider(() -> { if (sourceSet.getOutput().isLegacyLayout()) { return sourceSet.getOutput().getClassesDir(); } return new File(target.getBuildDir(), sourceSetChildPath); })); ((ConfigurableFileCollection) sourceSet.getOutput().getClassesDirs()).from(target.provider( sourceDirectorySet::getOutputDir)); compile.setDestinationDir(target.provider(sourceDirectorySet::getOutputDir)); }
@Override void configure(Task task) { super.configure(task); Task prepareTestEnvTask = project.getTasks().findByName(AzurePlugin.PREPARE_TEST_ENV_TASK); Task cleanupTestEnvTask = project.getTasks().findByName(AzurePlugin.CLEANUP_TEST_ENV_TASK); Task triggerTestCleanUpTask = project.getTasks().findByName(AzurePlugin.TRIGGER_CLEAN_TEST_ENV); Test t = (Test)task; t.setDescription("Test execution of the azureTest source set."); t.dependsOn(prepareTestEnvTask, triggerTestCleanUpTask); t.finalizedBy(cleanupTestEnvTask); t.setClasspath(sourceSet.getRuntimeClasspath()); t.setTestClassesDirs(sourceSet.getOutput().getClassesDirs()); t.systemProperty("testEnvPath", azure.getTestEnvFile().get().getAsFile().getAbsolutePath()); } }
private void createWarExploded(DevOption sdmOption) throws IOException { WarPluginConvention warConvention = getProject().getConvention().getPlugin(WarPluginConvention.class); JavaPluginConvention javaConvention = getProject().getConvention().getPlugin(JavaPluginConvention.class); File warDir = sdmOption.getWar(); ResourceUtils.copyDirectory(warConvention.getWebAppDir(), warDir); if (Boolean.TRUE.equals(sdmOption.getNoServer())) { File webInfDir = ResourceUtils.ensureDir(new File(warDir, "WEB-INF")); ResourceUtils.deleteDirectory(webInfDir); } else { SourceSet mainSourceSet = javaConvention.getSourceSets().getByName("main"); File classesDir = ResourceUtils.ensureDir(new File(warDir, "WEB-INF/classes")); for (File file : mainSourceSet.getResources().getSrcDirs()) { ResourceUtils.copyDirectory(file, classesDir); } for (File f: mainSourceSet.getOutput().getClassesDirs()) { ResourceUtils.copyDirectory(f, classesDir); } for (File file : mainSourceSet.getOutput().getFiles()) { if (file.exists() && file.isFile()) { ResourceUtils.copy(file, new File(classesDir, file.getName())); } } File libDir = ResourceUtils.ensureDir(new File(warDir, "WEB-INF/lib")); for (File file : mainSourceSet.getRuntimeClasspath()) { if (file.exists() && file.isFile()) { ResourceUtils.copy(file, new File(libDir, file.getName())); } } } }
private Task createClassycleTask(final Project project, final ClassycleExtension extension, final SourceSet sourceSet) { final String taskName = sourceSet.getTaskName("classycle", null); final FileCollection classesDirs = sourceSet.getOutput().getClassesDirs(); final File reportFile = getReportingExtension(project).file("classycle_" + sourceSet.getName() + ".txt"); final Task task = project.task(taskName); task.getInputs().files(classesDirs, extension.getDefinitionFile()); task.getOutputs().file(reportFile); task.doLast(new ClassyclePlugin.ClassycleAction(classesDirs, reportFile, extension)); // the classycle task depends on the corresponding classes task final String classesTask = sourceSet.getClassesTaskName(); task.dependsOn(classesTask); if (project.getLogger().isDebugEnabled()) { final StringBuilder sb = new StringBuilder(); for (final File file : classesDirs) { sb.append(file.getAbsolutePath()).append(" "); } project.getLogger() .debug("Created classycle task: " + taskName + ", report file: " + reportFile + ", depends on: " + classesTask + " - sourceSetDirs: " + sb.toString()); } return task; }
@Override protected void configureForSourceSet(final SourceSet sourceSet, SpotBugsTask task) { task.setDescription("Run SpotBugs analysis for " + sourceSet.getName() + " classes"); task.setSourceSet(sourceSet); ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("classes", (Callable<FileCollection>) () -> { /* * As a result of the changes made in gradle 4.0. * See https://docs.gradle.org/4.0/release-notes.html - Location of classes in the build directory * Compile no longer bundles all classes in one directory build-gradle/classes/main * but instead separates classes into build-gradle/classes/{language}/main. * * We must therefor retrieve all output directories. Filter away the once that don't exist. Add each * existing file tree dependency to specified task. And then return the complete fileCollection, contain * all .class files available for analysis. */ FileCollection presentClassDirs = sourceSet.getOutput().getClassesDirs().filter(File::exists); StreamSupport.stream(presentClassDirs.spliterator(), false) .map(file -> project.fileTree(file)) .forEach(tree -> tree.builtBy(sourceSet.getClassesTaskName())); return presentClassDirs.getAsFileTree(); }); taskMapping.map("classpath", sourceSet::getRuntimeClasspath); } }
@Override public void apply(Project project) { GenerateSchemaTask generateSchemaTask = project.getTasks().create(GenerateSchemaTask.NAME, GenerateSchemaTask.class); JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); generateSchemaTask.setClasses(mainSourceSet.getOutput().getClassesDirs()); Jar jar = (Jar) project.getTasks().getByName("jar"); jar.dependsOn(generateSchemaTask); SchemaGenExtension extension = new SchemaGenExtension(); extension.project = project; project.getExtensions().add("jpaSchemaGen", extension); project.afterEvaluate(p -> { // jar dependency needs to be deferred as its depends on the plugin extension configuration if (extension.getContinuousMode()) { jar.from(generateSchemaTask.getOutputDirectory()); } // dependant configuration is deffered as it is set be the user through the extension Configuration schemaGenConfig = project.getConfigurations().getByName(extension.getConfiguration()); generateSchemaTask.dependsOn(schemaGenConfig); generateSchemaTask.setDependencies(schemaGenConfig); // add to resource dir in order to be detected by IDE mainSourceSet.getResources().srcDir(generateSchemaTask.getOutputDirectory()); }); }
private void addSourceSet(ConfigurableFileCollection sources, Project project, String sourceSet) { JavaPluginConvention javaConvention = project.getConvention().findPlugin(JavaPluginConvention.class); if (javaConvention != null) { SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(sourceSet); sources .from(project.files(mainSourceSet.getOutput().getResourcesDir())) .from(project.files(mainSourceSet.getOutput().getClassesDirs())) .from(project.files(mainSourceSet.getAllSource().getSrcDirs())); } }
private void addSourceSet(FileCollection sources, Project project, String sourceSet) { JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(sourceSet); sources.add(project.files(mainSourceSet.getOutput().getResourcesDir())) .plus(project.files(mainSourceSet.getOutput().getClassesDirs())) .plus(project.files(mainSourceSet.getAllSource().getSrcDirs())); }
public void configure(final Project project, final PutnamiExtension extention) { final CompilerOption options = extention.getCompile(); options.init(getProject()); JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); final FileCollection sources = getProject() .files(project.files(mainSourceSet.getOutput().getResourcesDir())) .plus(project.files(mainSourceSet.getOutput().getClassesDirs())) .plus(getProject().files(mainSourceSet.getAllSource().getSrcDirs())); ConventionMapping mapping = ((IConventionAware) this).getConventionMapping(); mapping.map("modules", new Callable<List<String>>() { @Override public List<String> call() { return extention.getModule(); } }); mapping.map("war", new Callable<File>() { @Override public File call() { return new File(getProject().getBuildDir(), "out"); } }); mapping.map("src", new Callable<FileCollection>() { @Override public FileCollection call() { return sources; } }); }
public void configure(final Project project, final GwtExtension extention) { final CompilerOption options = extention.getCompile(); options.init(getProject()); JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); final FileCollection sources = getProject() .files(project.files(mainSourceSet.getOutput().getResourcesDir())) .plus(project.files(mainSourceSet.getOutput().getClassesDirs())) .plus(getProject().files(mainSourceSet.getAllSource().getSrcDirs())); ConventionMapping mapping = ((IConventionAware) this).getConventionMapping(); mapping.map("modules", new Callable<List<String>>() { @Override public List<String> call() { return extention.getModule(); } }); mapping.map("war", new Callable<File>() { @Override public File call() { return new File(getProject().getBuildDir(), "out"); } }); mapping.map("src", new Callable<FileCollection>() { @Override public FileCollection call() { return sources; } }); }