public IncrementalCompilerFactory(FileOperations fileOperations, FileHasher snapshotter, String compileDisplayName, CleaningJavaCompiler cleaningJavaCompiler, List<Object> source, CompileCaches compileCaches, IncrementalTaskInputsInternal inputs) { this.inputs = inputs; //bunch of services that enable incremental java compilation. FileHasher hasher = new DefaultFileHasher(); //TODO SF use caching hasher ClassDependenciesAnalyzer analyzer = new CachingClassDependenciesAnalyzer(new DefaultClassDependenciesAnalyzer(), hasher, compileCaches.getClassAnalysisCache()); JarSnapshotter jarSnapshotter = new CachingJarSnapshotter(snapshotter, analyzer, compileCaches.getJarSnapshotCache()); JarClasspathSnapshotMaker jarClasspathSnapshotMaker = new JarClasspathSnapshotMaker(compileCaches.getLocalJarClasspathSnapshotStore(), new JarClasspathSnapshotFactory(jarSnapshotter), new ClasspathJarFinder(fileOperations)); CompilationSourceDirs sourceDirs = new CompilationSourceDirs(source); SourceToNameConverter sourceToNameConverter = new SourceToNameConverter(sourceDirs); //TODO SF replace with converter that parses input source class RecompilationSpecProvider recompilationSpecProvider = new RecompilationSpecProvider(sourceToNameConverter, fileOperations); ClassSetAnalysisUpdater classSetAnalysisUpdater = new ClassSetAnalysisUpdater(compileCaches.getLocalClassSetAnalysisStore(), fileOperations, analyzer); IncrementalCompilationInitializer compilationInitializer = new IncrementalCompilationInitializer(fileOperations); incrementalSupport = new IncrementalCompilerDecorator(jarClasspathSnapshotMaker, compileCaches, compilationInitializer, cleaningJavaCompiler, compileDisplayName, recompilationSpecProvider, classSetAnalysisUpdater, sourceDirs); }
@Override public void init(final Object target, ServiceRegistry services) { super.init(target, services); this.__scriptServices = services; loggingManager = services.get(LoggingManager.class); Instantiator instantiator = services.get(Instantiator.class); FileLookup fileLookup = services.get(FileLookup.class); DirectoryFileTreeFactory directoryFileTreeFactory = services.get(DirectoryFileTreeFactory.class); if (target instanceof FileOperations) { fileOperations = (FileOperations) target; } else { File sourceFile = getScriptSource().getResource().getLocation().getFile(); if (sourceFile != null) { fileOperations = new DefaultFileOperations(fileLookup.getFileResolver(sourceFile.getParentFile()), null, null, instantiator, fileLookup, directoryFileTreeFactory); } else { fileOperations = new DefaultFileOperations(fileLookup.getFileResolver(), null, null, instantiator, fileLookup, directoryFileTreeFactory); } } processOperations = (ProcessOperations) fileOperations; }
@Override public void visitFile(final FileVisitDetails fileDetails) { final File outputFileDir = new File(destinationDir, fileDetails.getRelativePath().getParent().getPathString()); // Copy the raw form FileOperations fileOperations = (ProjectInternal) getProject(); fileOperations.copy(new Action<CopySpec>() { @Override public void execute(CopySpec copySpec) { copySpec.from(fileDetails.getFile()).into(outputFileDir); } }); // Capture the relative file relativeFiles.add(new RelativeFile(fileDetails.getFile(), fileDetails.getRelativePath())); }
/** * Create Checkstyle tasks * * @param tasks Task container * @param checkstyleConfig Checkstyle configuration * @param sources Source sets * @param files * @param context */ @Finalize public void configureCheckstyleTasks(ModelMap<Checkstyle> tasks, CheckstyleConfig checkstyleConfig, ProjectSourceSet sources, FileOperations files, ProjectContext context) { for (JavaSourceSet source : sources.withType(JavaSourceSet.class)) { String taskName = getCheckstyleTaskName(source); if (!checkstyleConfig.getIgnoreSourceSets().contains(source.getParentName())) { tasks.named(taskName, t -> { File checkstyleConfigFile = getCheckstyleConfigFile(source.getParentName(), files); t.setGroup(JavaBasePlugin.VERIFICATION_GROUP); t.setConfigFile(checkstyleConfigFile); if (checkstyleConfigFile.getParentFile() != null) { t.setConfigDir(context.provider(() -> checkstyleConfigFile.getParentFile())); } t.dependsOn(getUpdateConfigTaskName(source)); }); } } }
public IncrementalCompilerFactory(FileOperations fileOperations, String compileDisplayName, CleaningJavaCompiler cleaningJavaCompiler, List<Object> source, CompileCaches compileCaches, IncrementalTaskInputsInternal inputs) { this.inputs = inputs; //bunch of services that enable incremental java compilation. Hasher hasher = new DefaultHasher(); //TODO SF use caching hasher ClassDependenciesAnalyzer analyzer = new CachingClassDependenciesAnalyzer(new DefaultClassDependenciesAnalyzer(), hasher, compileCaches.getClassAnalysisCache()); JarSnapshotter jarSnapshotter = new CachingJarSnapshotter(hasher, analyzer, compileCaches.getJarSnapshotCache(), inputs.getInputFilesSnapshot()); JarClasspathSnapshotMaker jarClasspathSnapshotMaker = new JarClasspathSnapshotMaker(compileCaches.getLocalJarClasspathSnapshotStore(), new JarClasspathSnapshotFactory(jarSnapshotter), new ClasspathJarFinder(fileOperations)); CompilationSourceDirs sourceDirs = new CompilationSourceDirs(source); SourceToNameConverter sourceToNameConverter = new SourceToNameConverter(sourceDirs); //TODO SF replace with converter that parses input source class RecompilationSpecProvider recompilationSpecProvider = new RecompilationSpecProvider(sourceToNameConverter, fileOperations); ClassSetAnalysisUpdater classSetAnalysisUpdater = new ClassSetAnalysisUpdater(compileCaches.getLocalClassSetAnalysisStore(), fileOperations, analyzer); IncrementalCompilationInitializer compilationInitializer = new IncrementalCompilationInitializer(fileOperations); incrementalSupport = new IncrementalCompilerDecorator(jarClasspathSnapshotMaker, compileCaches, compilationInitializer, cleaningJavaCompiler, compileDisplayName, recompilationSpecProvider, classSetAnalysisUpdater, sourceDirs); }
public FileCollectionBackedArchiveTextResource(final FileOperations fileOperations, final TemporaryFileProvider tempFileProvider, final FileCollection fileCollection, final String path, Charset charset) { super(tempFileProvider, new LazilyInitializedFileTree() { @Override public FileTree createDelegate() { File archiveFile = fileCollection.getSingleFile(); String fileExtension = Files.getFileExtension(archiveFile.getName()); FileTree archiveContents = fileExtension.equals("jar") || fileExtension.equals("zip") ? fileOperations.zipTree(archiveFile) : fileOperations.tarTree(archiveFile); PatternSet patternSet = new PatternSet(); patternSet.include(path); return archiveContents.matching(patternSet); } public TaskDependency getBuildDependencies() { return fileCollection.getBuildDependencies(); } }, charset); }
public void init(final Object target, ServiceRegistry services) { super.init(target, services); this.__scriptServices = services; loggingManager = services.get(LoggingManager.class); Instantiator instantiator = services.get(Instantiator.class); FileLookup fileLookup = services.get(FileLookup.class); if (target instanceof FileOperations) { fileOperations = (FileOperations) target; } else if (getScriptSource().getResource().getFile() != null) { fileOperations = new DefaultFileOperations(fileLookup.getFileResolver(getScriptSource().getResource().getFile().getParentFile()), null, null, instantiator, fileLookup); } else { fileOperations = new DefaultFileOperations(fileLookup.getFileResolver(), null, null, instantiator, fileLookup); } processOperations = (ProcessOperations) fileOperations; }
/** * Finalize the wsimport components * * @param wsimportComponents Wsimport components to finalize * @param files File operations */ @Finalize public void createWsdlSourceSets(ModelMap<WsimportComponent> wsimportComponents, FileOperations files) { for (String componentName : DEFAULT_SOURCE_SET_NAMES) { File sourceDirectory = getSourceDirectory(componentName, "wsdl"); String wsdlComponentName = getWsdlComponentName(componentName); wsimportComponents.create(wsdlComponentName, c -> { if (files.file(sourceDirectory).isDirectory()) { c.getSources().create("wsdl", WsdlSourceSet.class, s -> { s.getSource().setSrcDirs(Collections.singleton(sourceDirectory)); }); } }); } }
public void execute(final FileCollection source, File destDir, boolean use, boolean noTimestamp, boolean noVersionStamp, String windowTitle, String docTitle, String header, String footer, String overview, boolean includePrivate, final Set<Groovydoc.Link> links, final Iterable<File> groovyClasspath, Iterable<File> classpath, Project project) { final File tmpDir = new File(project.getBuildDir(), "tmp/groovydoc"); FileOperations fileOperations = (ProjectInternal) project; fileOperations.delete(tmpDir); fileOperations.copy(new Action<CopySpec>() { public void execute(CopySpec copySpec) { copySpec.from(source).into(tmpDir); } }); List<File> combinedClasspath = ImmutableList.<File>builder() .addAll(classpath) .addAll(groovyClasspath) .build(); VersionNumber version = VersionNumber.parse(getGroovyVersion(combinedClasspath)); final Map<String, Object> args = Maps.newLinkedHashMap(); args.put("sourcepath", tmpDir.toString()); args.put("destdir", destDir); args.put("use", use); if (isAtLeast(version, "2.4.6")) { args.put("noTimestamp", noTimestamp); args.put("noVersionStamp", noVersionStamp); } args.put("private", includePrivate); putIfNotNull(args, "windowtitle", windowTitle); putIfNotNull(args, "doctitle", docTitle); putIfNotNull(args, "header", header); putIfNotNull(args, "footer", footer); if (overview != null) { args.put("overview", overview); } invokeGroovydoc(links, combinedClasspath, args); }
public FileCollectionBackedArchiveTextResource(final FileOperations fileOperations, final TemporaryFileProvider tempFileProvider, final FileCollection fileCollection, final String path, Charset charset) { super(tempFileProvider, new LazilyInitializedFileCollection() { @Override public String getDisplayName() { return String.format("entry '%s' in archive %s", path, fileCollection); } @Override public FileCollection createDelegate() { File archiveFile = fileCollection.getSingleFile(); String fileExtension = Files.getFileExtension(archiveFile.getName()); FileTree archiveContents = fileExtension.equals("jar") || fileExtension.equals("zip") ? fileOperations.zipTree(archiveFile) : fileOperations.tarTree(archiveFile); PatternSet patternSet = new PatternSet(); patternSet.include(path); return archiveContents.matching(patternSet); } @Override public void visitDependencies(TaskDependencyResolveContext context) { context.add(fileCollection); } }, charset); }
@Defaults void createDistributions(@Path("distributions") PlayDistributionContainer distributions, @Path("binaries") ModelMap<PlayApplicationBinarySpecInternal> playBinaries, PlayPluginConfigurations configurations, ServiceRegistry serviceRegistry) { FileOperations fileOperations = serviceRegistry.get(FileOperations.class); Instantiator instantiator = serviceRegistry.get(Instantiator.class); for (PlayApplicationBinarySpecInternal binary : playBinaries) { PlayDistribution distribution = instantiator.newInstance(DefaultPlayDistribution.class, binary.getProjectScopedName(), fileOperations.copySpec(), binary); distribution.setBaseName(binary.getProjectScopedName()); distributions.add(distribution); } }
/** * Initialize the project configuration * * <ul> * <li>Add the checkstyle config files to the files ignored by version control * </ul> * * @param projectConfig Project configuration to update * @param checkstyleConfig Checkstyle configuration * @param sources Source sets * @param files File operations object to resolve file names */ @Defaults public void initializeProjectConfig(ProjectConfig projectConfig, CheckstyleConfig checkstyleConfig, ProjectSourceSet sources, FileOperations files) { VersionControl versionControl = projectConfig.getVersionControl(); for (JavaSourceSet source : sources.withType(JavaSourceSet.class)) { if (!checkstyleConfig.getIgnoreSourceSets().contains(source.getParentName())) { File configFile = getCheckstyleConfigFile(source.getParentName(), files); versionControl.ignore("/" + Validate.notNull(files.relativePath(configFile))); } } }
/** * Create tasks to update Checkstyle configuration * * @param tasks Task container * @param sources Source sets to add tasks for * @param files File operations object to resolve file names */ @Mutate public void createUpdateTasks(ModelMap<Task> tasks, ProjectSourceSet sources, FileOperations files) { tasks.create(CONFIGURE_CHECKSTYLE_TASK_NAME, Task.class, t -> { t.setDescription("Update checkstyle configuration"); t.setGroup("Build Setup"); }); for (JavaSourceSet source : sources.withType(JavaSourceSet.class)) { File configFile = getCheckstyleConfigFile(source.getParentName(), files); String resourceName = "checkstyle_" + source.getParentName() + ".xml"; String config = Classes.getResourceString(CheckstyleConfigPlugin.class, resourceName).orElseGet( () -> Classes.getResourceString(CheckstyleConfigPlugin.class, "checkstyle.xml").get()); String taskName = getUpdateConfigTaskName(source); tasks.create(taskName, CheckstyleConfigUpdate.class, t -> { t.setDescription(String.format("Update checkstyle configuration for source set '%s'", source.getParentName())); t.setGroup("Build Setup"); t.setConfig(config); t.setConfigFile(configFile); }); tasks.named(getCheckstyleTaskName(source), t -> { t.dependsOn(taskName); }); tasks.named(CONFIGURE_CHECKSTYLE_TASK_NAME, t -> { t.dependsOn(taskName); }); } }
/** * Create eclipse tasks to generate Checkstyle settings * * @param tasks Task container to create tasks * @param sources Source sets * @param files File operations object to resolve file names */ @Mutate public void createEclipseCheckstyleTask(ModelMap<Task> tasks, ProjectSourceSet sources, FileOperations files) { List<String> sourceNames = sources.withType(JavaSourceSet.class).stream().map(s -> s.getParentName()) .collect(Collectors.toList()); tasks.create(ECLIPSE_CHECKSTYLE_TASK_NAME, GenerateEclipseCheckstyle.class, t -> { t.setDescription("Generates Checkstyle configuration for Eclipse."); t.setGroup("IDE"); t.setSourceSets(sourceNames); t.setSettingsFile(files.file(".checkstyle")); }); }
@TaskAction protected void compile(IncrementalTaskInputs inputs) { if (!compileOptions.isIncremental()) { compile(); return; } SingleMessageLogger.incubatingFeatureUsed("Incremental java compilation"); DefaultJavaCompileSpec spec = createSpec(); final CacheRepository repository1 = getCacheRepository(); final JavaCompile javaCompile1 = this; final GeneralCompileCaches generalCaches1 = getGeneralCompileCaches(); CompileCaches compileCaches = new CompileCaches() { private final CacheRepository repository = repository1; private final JavaCompile javaCompile = javaCompile1; private final GeneralCompileCaches generalCaches = generalCaches1; public ClassAnalysisCache getClassAnalysisCache() { return generalCaches.getClassAnalysisCache(); } public JarSnapshotCache getJarSnapshotCache() { return generalCaches.getJarSnapshotCache(); } public LocalJarClasspathSnapshotStore getLocalJarClasspathSnapshotStore() { return new LocalJarClasspathSnapshotStore(repository, javaCompile); } public LocalClassSetAnalysisStore getLocalClassSetAnalysisStore() { return new LocalClassSetAnalysisStore(repository, javaCompile); } }; IncrementalCompilerFactory factory = new IncrementalCompilerFactory( (FileOperations) getProject(), getPath(), createCompiler(spec), source, compileCaches, (IncrementalTaskInputsInternal) inputs); Compiler<JavaCompileSpec> compiler = factory.createCompiler(); performCompilation(spec, compiler); }
private boolean maybeCompileIncrementally(IncrementalTaskInputs inputs) { if (!compileOptions.isIncremental()) { return false; } //hack List<File> sourceDirs = getSourceDirs(); if (sourceDirs.isEmpty()) { LOG.lifecycle("{} cannot run incrementally because Gradle cannot infer the source directories.", getPath()); return false; } if (!inputs.isIncremental()) { LOG.lifecycle("{} is not incremental (e.g. outputs have changed, no previous execution, etc). Using regular compile.", getPath()); return false; } ClassDependencyInfoSerializer dependencyInfoSerializer = getDependencyInfoSerializer(); if (!dependencyInfoSerializer.isInfoAvailable()) { //TODO SF let's unit test a scenario when after regular compilation incremental compilation is scheduled LOG.lifecycle("{} is not incremental because there is no class dependency data left from previous incremental build.", getPath()); return false; } SingleMessageLogger.incubatingFeatureUsed("Incremental java compilation"); SelectiveJavaCompiler compiler = new SelectiveJavaCompiler(javaCompiler, getProject().fileTree(getDestinationDir())); SelectiveCompilation selectiveCompilation = new SelectiveCompilation(inputs, getSource(), getClasspath(), getDestinationDir(), dependencyInfoSerializer, getJarSnapshotCache(), compiler, sourceDirs, (FileOperations) getProject()); if (!selectiveCompilation.getCompilationNeeded()) { LOG.lifecycle("{} does not require recompilation. Skipping the compiler.", getPath()); return true; } Clock clock = new Clock(); performCompilation(selectiveCompilation.getSource(), selectiveCompilation.getClasspath(), selectiveCompilation.getFullRebuildRequired()? cleaningCompiler : compiler); LOG.lifecycle("{} - incremental compilation took {}", getPath(), clock.getTime()); return true; }
public SelectiveCompilation(IncrementalTaskInputs inputs, FileTree source, FileCollection compileClasspath, final File compileDestination, final ClassDependencyInfoSerializer dependencyInfoSerializer, final JarSnapshotCache jarSnapshotCache, final SelectiveJavaCompiler compiler, Iterable<File> sourceDirs, final FileOperations operations) { this.operations = operations; this.jarSnapshotFeeder = new JarSnapshotFeeder(jarSnapshotCache, new JarSnapshotter(new DefaultHasher())); this.compiler = compiler; Clock clock = new Clock(); final InputOutputMapper mapper = new InputOutputMapper(sourceDirs, compileDestination); //load dependency info final ClassDependencyInfo dependencyInfo = dependencyInfoSerializer.readInfo(); //including only source java classes that were changed final PatternSet changedSourceOnly = new PatternSet(); InputFileDetailsAction action = new InputFileDetailsAction(mapper, compiler, changedSourceOnly, dependencyInfo); inputs.outOfDate(action); inputs.removed(action); if (fullRebuildNeeded != null) { LOG.lifecycle("Stale classes detection completed in {}. Rebuild needed: {}.", clock.getTime(), fullRebuildNeeded); this.classpath = compileClasspath; this.source = source; return; } compiler.deleteStaleClasses(); Set<File> filesToCompile = source.matching(changedSourceOnly).getFiles(); if (filesToCompile.isEmpty()) { this.compilationNeeded = false; this.classpath = compileClasspath; this.source = source; } else { this.classpath = compileClasspath.plus(new SimpleFileCollection(compileDestination)); this.source = source.matching(changedSourceOnly); } LOG.lifecycle("Stale classes detection completed in {}. Compile include patterns: {}.", clock.getTime(), changedSourceOnly.getIncludes()); }
@Inject protected FileOperations getFileOperations() { throw new UnsupportedOperationException(); }
public JarChangeProcessor(FileOperations fileOperations, JarClasspathSnapshot jarClasspathSnapshot, PreviousCompilation previousCompilation) { this.fileOperations = fileOperations; this.jarClasspathSnapshot = jarClasspathSnapshot; this.previousCompilation = previousCompilation; }
public ClasspathJarFinder(FileOperations fileOperations) { this.fileOperations = fileOperations; }
public ClassSetAnalysisUpdater(Stash<ClassSetAnalysisData> stash, FileOperations fileOperations, ClassDependenciesAnalyzer analyzer) { this.stash = stash; this.fileOperations = fileOperations; this.analyzer = analyzer; }
public RecompilationSpecProvider(SourceToNameConverter sourceToNameConverter, FileOperations fileOperations) { this.sourceToNameConverter = sourceToNameConverter; this.fileOperations = fileOperations; }
public IncrementalCompilationInitializer(FileOperations fileOperations) { this.fileOperations = fileOperations; }
@Hidden @Model FileOperations fileOperations(ServiceRegistry serviceRegistry) { return serviceRegistry.get(FileOperations.class); }
@Inject protected FileOperations getFileOperations() { // Decoration takes care of the implementation throw new UnsupportedOperationException(); }
public DefaultResourceHandler(FileOperations fileOperations, TemporaryFileProvider tempFileProvider) { this.fileOperations = fileOperations; textResourceFactory = new DefaultTextResourceFactory(fileOperations, tempFileProvider); }
public DefaultTextResourceFactory(FileOperations fileOperations, TemporaryFileProvider tempFileProvider) { this.fileOperations = fileOperations; this.tempFileProvider = tempFileProvider; }
public DefaultDistributionContainer(Class<Distribution> type, Instantiator instantiator, FileOperations fileOperations) { super(type, instantiator); this.fileOperations = fileOperations; }
@Inject public DistributionPlugin(Instantiator instantiator, FileOperations fileOperations) { this.instantiator = instantiator; this.fileOperations = fileOperations; }
public void execute(final FileCollection source, File destDir, boolean use, String windowTitle, String docTitle, String header, String footer, String overview, boolean includePrivate, final Set<Groovydoc.Link> links, final Iterable<File> groovyClasspath, Iterable<File> classpath, Project project) { final File tmpDir = new File(project.getBuildDir(), "tmp/groovydoc"); FileOperations fileOperations = (ProjectInternal) project; fileOperations.delete(tmpDir); fileOperations.copy(new Action<CopySpec>() { public void execute(CopySpec copySpec) { copySpec.from(source).into(tmpDir); } }); final Map<String, Object> args = Maps.newLinkedHashMap(); args.put("sourcepath", tmpDir.toString()); args.put("destdir", destDir); args.put("use", use); args.put("private", includePrivate); putIfNotNull(args, "windowtitle", windowTitle); putIfNotNull(args, "doctitle", docTitle); putIfNotNull(args, "header", header); putIfNotNull(args, "footer", footer); putIfNotNull(args, "overview", overview); List<File> combinedClasspath = ImmutableList.<File>builder() .addAll(classpath) .addAll(groovyClasspath) .build(); ant.withClasspath(combinedClasspath).execute(new Closure<Object>(this, this) { @SuppressWarnings("UnusedDeclaration") public Object doCall(Object it) { final GroovyObjectSupport antBuilder = (GroovyObjectSupport) it; antBuilder.invokeMethod("taskdef", ImmutableMap.of( "name", "groovydoc", "classname", "org.codehaus.groovy.ant.Groovydoc" )); antBuilder.invokeMethod("groovydoc", new Object[]{args, new Closure<Object>(this, this) { public Object doCall(Object ignore) { for (Groovydoc.Link link : links) { antBuilder.invokeMethod("link", new Object[]{ ImmutableMap.of( "packages", Joiner.on(",").join(link.getPackages()), "href", link.getUrl() ) }); } return null; } }}); return null; } }); }