/** * @return Returns the output directory for .class file. */ public File classes() { SourceSet sourceSet = sourceSet(project); return sourceSet.getRuntimeClasspath().getFiles().stream() .filter(f -> f.exists() && f.isDirectory() && f.toString().contains("classes")) .findFirst() .get(); }
if (!alwaysUsePathingJar && !classpath.filter(f -> f.getAbsolutePath().contains("restli-tools-scala")).isEmpty()) { LOG.info("Compiling Scala resource classes. Disabling pathing jar for " + taskName + " to avoid breaking Scala compilation"); return classpath; FileCollection filteredClasspath = classpath.filter(f -> !f.isDirectory()); File destinationDir = new File(project.getBuildDir(), taskName); destinationDir.mkdirs(); String cp = ClasspathManifest.relativeClasspathManifest(destinationDir, filteredClasspath.getFiles()); jarOutputStream.close(); return classpath.filter(File::isDirectory).plus(project.files(pathingJarPath));
@Override public void exec() { if (Utils.isNullOrEmpty(url) || Utils.isNullOrEmpty(output)) { throw new IllegalArgumentException("Schema URL and output path can't be empty"); } setScript(new File(getProject().getTasks().getByPath(ApolloCodegenInstallTask.NAME).getOutputs().getFiles() .getAsPath(), ApolloLocalCodegenGenerationTask.APOLLO_CODEGEN_EXEC_FILE)); List<String> args = Lists.newArrayList("introspect-schema", url, "--output", getProject().file(output) .getAbsolutePath()); if (!headers.isEmpty()) { for(String h : headers) { args.add("--header"); args.add(h); } } if (insecure) { args.add("--insecure"); args.add("true"); } setArgs(args); super.exec(); }
/** If the user hasn't specified the files yet, we'll assume he/she means all of the kotlin files. */ @Override protected void setupTask(SpotlessTask task) { if (target == null) { JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class); if (javaPlugin == null) { throw new GradleException("You must either specify 'target' manually or apply a kotlin plugin."); } FileCollection union = getProject().files(); for (SourceSet sourceSet : javaPlugin.getSourceSets()) { union = union.plus(sourceSet.getAllSource().filter(file -> { String name = file.getName(); return name.endsWith(".kt") || name.endsWith(".kts"); })); } target = union; } super.setupTask(task); } }
FileCollection jawaSources = spec.getSource().filter(new Spec<File>() { public boolean isSatisfiedBy(File file) { return hasExtension(file, ".jawa"); File[] sources = jawaSources.getFiles().toArray(new File[jawaSources.getFiles().size()]); File[] outputDirs = new File[]{spec.getDestinationDir()}; PrintReporter reporter = new PrintReporter(MsgLevel.WARNING()); FileCollection javaSources = spec.getSource().filter(new Spec<File>() { public boolean isSatisfiedBy(File file) { return hasExtension(file, ".java"); if(!javaSources.isEmpty()) { spec.setSource(javaSources); javaCompiler.execute(spec);
public SpotBugsSpec build() { ArrayList<String> args = new ArrayList<>(); args.add("-pluginList"); args.add(pluginsList==null ? "" : pluginsList.getAsPath()); args.add("-sortByClass"); args.add("-timestampNow"); args.add(sources.getAsPath()); args.add(classpath.filter(new Spec<File>() { @Override public boolean isSatisfiedBy(File element) { return element.exists(); }).getAsPath()); for (File classFile : classes.getFiles()) { args.add(classFile.getAbsolutePath());
private List<String> getClassNames(FileCollection classesOutput) { Set<String> classesDirs = classesOutput.getFiles().stream().map(File::getPath).collect(Collectors.toSet()); List<String> classNames = classesOutput.getAsFileTree().getFiles().stream() .filter(it -> it.isFile() && it.getName().endsWith(".class")) .map(it -> { for (String dirPath : classesDirs) { if (it.getPath().startsWith(dirPath)) { String classString = it.getPath().substring(dirPath.length() + 1) .replace(".class", "") .replace(File.separator, "."); // return classString; } } //TODO: this is error file ... logger.error("class[{}] not startsWith in {}", it, classesDirs); return it.getPath(); }) .collect(Collectors.toList()); return classNames; }
private boolean has(FileCollection fileCollection) { return fileCollection != null && !fileCollection.isEmpty(); }
/** * Register an API Gateway API that should have its DefinitionBody property updated in the * Cloudformation template * * @param ref the Cloudformation Ref of the API to update * @param swagger the file containing the swagger definition of the API */ public void api(String ref, FileCollection swagger) { getInputs().files(swagger); apis.put(ref, swagger.getSingleFile()); }
public void submit(Action<ClojureWorkerConfiguration> action) { ClojureWorkerConfiguration config = new ClojureWorkerConfiguration(); action.execute(config); FileCollection realClasspath = config.getClasspath().plus(resolveShim()); workerExecutor.submit(ClojureWorker.class, worker -> { worker.setIsolationMode(IsolationMode.PROCESS); worker.params(config.getNamespace(), config.getFunction(), config.getArgs()); config.getConfigureFork().forEach(worker::forkOptions); worker.forkOptions(fork -> fork.systemProperty("shim.classpath", realClasspath.getAsPath())); worker.classpath(resolveWorker()); }); }
@Override public void apply(Project project) { project.getTasks().withType(War.class, war -> { WarArchiveClassesConvention archiveClassesConvention = new WarArchiveClassesConvention(); war.getConvention().getPlugins().put("archiveClasses", archiveClassesConvention); Jar warClassesJar = project.getTasks().create(war.getName() + "ClassesJar", Jar.class); warClassesJar.getConventionMapping().map("baseName", war::getBaseName); warClassesJar.getConventionMapping().map("appendix", war::getAppendix); warClassesJar.getConventionMapping().map("version", war::getVersion); warClassesJar.getConventionMapping().map("classifier", war::getClassifier); project.afterEvaluate(p -> { warClassesJar.setEnabled(archiveClassesConvention.isArchiveClasses()); if (archiveClassesConvention.isArchiveClasses()) { FileCollection warClasspath = war.getClasspath(); warClassesJar.from(warClasspath != null ? warClasspath.filter(File::isDirectory) : Collections.emptyList()); war.setClasspath(warClasspath == null ? null : warClasspath.filter(File::isFile).plus(project.files(warClassesJar))); } }); }); } }
private void configureJavadocTask(final Javadoc javadoc, final ImmutableSet<String> moduleNameIset) { setModuleNamesInputProperty(javadoc, moduleNameIset); javadoc.doFirst(task -> { final FileCollection classpath = javadoc.getClasspath(); if (! classpath.isEmpty()) { ((CoreJavadocOptions) javadoc.getOptions()).addStringOption(JAVADOC_TASK_OPTION_MODULE_PATH, classpath.getAsPath()); javadoc.setClasspath(javadoc.getProject().files()); } }); }
public void configure(Project project) { project.afterEvaluate(c -> { JavaExec execTask = (JavaExec) project.getTasks().findByName(ApplicationPlugin.TASK_RUN_NAME); if (execTask != null) { JavaFXOptions javaFXOptions = project.getExtensions().getByType(JavaFXOptions.class); JavaFXModule.validateModules(javaFXOptions.getModules()); var definedJavaFXModuleNames = new TreeSet<>(javaFXOptions.getModules()); if (!definedJavaFXModuleNames.isEmpty()) { ModuleOptions moduleOptions = execTask.getExtensions().findByType(ModuleOptions.class); if (moduleOptions != null) { definedJavaFXModuleNames.forEach(javaFXModule -> moduleOptions.getAddModules().add(javaFXModule)); } else { var javaFXModuleJvmArgs = List.of( "--module-path", execTask.getClasspath() .filter(jar -> isJavaFXJar(jar, javaFXOptions.getVersion(), javaFXOptions.getPlatform())) .getAsPath()); var jvmArgs = new ArrayList<String>(); jvmArgs.add("--add-modules"); jvmArgs.add(String.join(",", definedJavaFXModuleNames)); jvmArgs.addAll(execTask.getJvmArgs()); jvmArgs.addAll(javaFXModuleJvmArgs); execTask.setJvmArgs(jvmArgs); } } } }); }
private static List<SourceClassInfo> parseSourceItems(FileCollection sourceItems) { List<SourceClassInfo> ret = new ArrayList<>(); sourceItems.getAsFileTree() .filter(File::exists) .filter(File::isFile) .filter(f -> f.getName().endsWith(".java")) .forEach(file -> { try { SourceClassInfo info = new SourceClassInfo();
@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); } }
private void copyFreezeConfigIfChanged(File workingDir) { if (isFreezeConfigChanged()) { /* Copy the project-global freeze file into the working directory. */ File tmpFreezeConfig = null; try { tmpFreezeConfig = freezeConfigFile .filter(file -> file.getName().endsWith(".freeze")).getSingleFile(); } catch (IllegalStateException e) { throw new GradleException ("The freezeConfig file collection contains more than one element!", e); } final File freezeConfig = tmpFreezeConfig; project.copy(copySpec -> { copySpec.from(freezeConfig); copySpec.into(workingDir); }); } } }
@Override public void visitContents(FileCollectionResolveContext context) { for (FileCollection collection : CompositeFileCollection.this.getSourceCollections()) { context.add(collection.filter(filterSpec)); } }