Java源码示例:org.gradle.api.tasks.util.PatternSet
示例1
public WorkResult execute(ScalaJavaJointCompileSpec spec) {
scalaCompiler.execute(spec);
PatternFilterable patternSet = new PatternSet();
patternSet.include("**/*.java");
FileTree javaSource = spec.getSource().getAsFileTree().matching(patternSet);
if (!javaSource.isEmpty()) {
spec.setSource(javaSource);
javaCompiler.execute(spec);
}
return new WorkResult() {
public boolean getDidWork() {
return true;
}
};
}
示例2
private void configureResourceCompileTask(WindowsResourceCompile task, final NativeBinarySpecInternal binary, final WindowsResourceSet sourceSet) {
task.setDescription(String.format("Compiles resources of the %s of %s", sourceSet, binary));
task.setToolChain(binary.getToolChain());
task.setTargetPlatform(binary.getTargetPlatform());
task.includes(new Callable<Set<File>>() {
public Set<File> call() {
return sourceSet.getExportedHeaders().getSrcDirs();
}
});
task.source(sourceSet.getSource());
final Project project = task.getProject();
task.setOutputDir(project.file(String.valueOf(project.getBuildDir()) + "/objs/" + binary.getNamingScheme().getOutputDirectoryBase() + "/" + ((LanguageSourceSetInternal) sourceSet).getFullName()));
PreprocessingTool rcCompiler = (PreprocessingTool) ((ExtensionAware) binary).getExtensions().getByName("rcCompiler");
task.setMacros(rcCompiler.getMacros());
task.setCompilerArgs(rcCompiler.getArgs());
FileTree resourceOutputs = task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.res"));
binary.getTasks().getCreateOrLink().source(resourceOutputs);
if (binary instanceof StaticLibraryBinarySpecInternal) {
((StaticLibraryBinarySpecInternal) binary).additionalLinkFiles(resourceOutputs);
}
}
示例3
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);
}
示例4
public WorkResult execute(ScalaJavaJointCompileSpec spec) {
scalaCompiler.execute(spec);
PatternFilterable patternSet = new PatternSet();
patternSet.include("**/*.java");
FileTree javaSource = spec.getSource().getAsFileTree().matching(patternSet);
if (!javaSource.isEmpty()) {
spec.setSource(javaSource);
javaCompiler.execute(spec);
}
return new WorkResult() {
public boolean getDidWork() {
return true;
}
};
}
示例5
public WorkResult execute(ScalaJavaJointCompileSpec spec) {
scalaCompiler.execute(spec);
PatternFilterable patternSet = new PatternSet();
patternSet.include("**/*.java");
FileTree javaSource = spec.getSource().getAsFileTree().matching(patternSet);
if (!javaSource.isEmpty()) {
spec.setSource(javaSource);
javaCompiler.execute(spec);
}
return new WorkResult() {
public boolean getDidWork() {
return true;
}
};
}
示例6
public void initializeCompilation(JavaCompileSpec spec, Collection<String> staleClasses) {
if (staleClasses.isEmpty()) {
spec.setSource(new SimpleFileCollection());
return; //do nothing. No classes need recompilation.
}
PatternSet classesToDelete = new PatternSet();
PatternSet sourceToCompile = new PatternSet();
preparePatterns(staleClasses, classesToDelete, sourceToCompile);
//selectively configure the source
spec.setSource(spec.getSource().getAsFileTree().matching(sourceToCompile));
//since we're compiling selectively we need to include the classes compiled previously
spec.setClasspath(Iterables.concat(spec.getClasspath(), asList(spec.getDestinationDir())));
//get rid of stale files
FileTree deleteMe = fileOperations.fileTree(spec.getDestinationDir()).matching(classesToDelete);
fileOperations.delete(deleteMe);
}
示例7
private void configureResourceCompileTask(WindowsResourceCompile task, final NativeBinarySpecInternal binary, final WindowsResourceSet sourceSet) {
task.setDescription(String.format("Compiles resources of the %s of %s", sourceSet, binary));
task.setToolChain(binary.getToolChain());
task.setTargetPlatform(binary.getTargetPlatform());
task.includes(new Callable<Set<File>>() {
public Set<File> call() {
return sourceSet.getExportedHeaders().getSrcDirs();
}
});
task.source(sourceSet.getSource());
final Project project = task.getProject();
task.setOutputDir(project.file(String.valueOf(project.getBuildDir()) + "/objs/" + binary.getNamingScheme().getOutputDirectoryBase() + "/" + ((LanguageSourceSetInternal) sourceSet).getFullName()));
PreprocessingTool rcCompiler = (PreprocessingTool) ((ExtensionAware) binary).getExtensions().getByName("rcCompiler");
task.setMacros(rcCompiler.getMacros());
task.setCompilerArgs(rcCompiler.getArgs());
FileTree resourceOutputs = task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.res"));
binary.getTasks().getCreateOrLink().source(resourceOutputs);
if (binary instanceof StaticLibraryBinarySpecInternal) {
((StaticLibraryBinarySpecInternal) binary).additionalLinkFiles(resourceOutputs);
}
}
示例8
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);
}
示例9
public WorkResult execute(ScalaJavaJointCompileSpec spec) {
scalaCompiler.execute(spec);
PatternFilterable patternSet = new PatternSet();
patternSet.include("**/*.java");
FileTree javaSource = spec.getSource().getAsFileTree().matching(patternSet);
if (!javaSource.isEmpty()) {
spec.setSource(javaSource);
javaCompiler.execute(spec);
}
return new WorkResult() {
public boolean getDidWork() {
return true;
}
};
}
示例10
void preparePatterns(Collection<String> staleClasses, PatternSet classesToDelete, PatternSet sourceToCompile) {
assert !staleClasses.isEmpty(); //if stale classes are empty (e.g. nothing to recompile), the patterns will not have any includes and will match all (e.g. recompile everything).
for (String staleClass : staleClasses) {
String path = staleClass.replaceAll("\\.", "/");
classesToDelete.include(path.concat(".class"));
classesToDelete.include(path.concat("$*.class"));
//the stale class might be a source class that was deleted
//it's no harm to include it in sourceToCompile anyway
sourceToCompile.include(path.concat(".java"));
}
}
示例11
private void doVisit(FileVisitor visitor, File file, LinkedList<String> relativePath, int segmentIndex, AtomicBoolean stopFlag) {
if (stopFlag.get()) {
return;
}
String segment = patternSegments.get(segmentIndex);
if (segment.contains("**")) {
PatternSet patternSet = new PatternSet();
patternSet.include(includePattern);
patternSet.exclude(excludeSpec);
DirectoryFileTree fileTree = new DirectoryFileTree(baseDir, patternSet);
fileTree.visitFrom(visitor, file, new RelativePath(file.isFile(), relativePath.toArray(new String[relativePath.size()])));
} else if (segment.contains("*") || segment.contains("?")) {
PatternStep step = PatternStepFactory.getStep(segment, false);
File[] children = file.listFiles();
if (children == null) {
if (!file.canRead()) {
throw new GradleException(String.format("Could not list contents of directory '%s' as it is not readable.", file));
}
// else, might be a link which points to nothing, or has been removed while we're visiting, or ...
throw new GradleException(String.format("Could not list contents of '%s'.", file));
}
for (File child : children) {
if (stopFlag.get()) { break; }
if (step.matches(child.getName())) {
relativePath.addLast(child.getName());
doVisitDirOrFile(visitor, child, relativePath, segmentIndex + 1, stopFlag);
relativePath.removeLast();
}
}
} else {
relativePath.addLast(segment);
doVisitDirOrFile(visitor, new File(file, segment), relativePath, segmentIndex + 1, stopFlag);
relativePath.removeLast();
}
}
示例12
public DefaultCopySpec(FileResolver resolver, Instantiator instantiator) {
this.fileResolver = resolver;
this.instantiator = instantiator;
sourcePaths = new LinkedHashSet<Object>();
childSpecs = new ArrayList<CopySpecInternal>();
patternSet = new PatternSet();
duplicatesStrategy = null;
}
示例13
public PatternSet getPatternSet() {
PatternSet patterns = new PatternSet();
patterns.setCaseSensitive(isCaseSensitive());
patterns.include(this.getAllIncludes());
patterns.includeSpecs(getAllIncludeSpecs());
patterns.exclude(this.getAllExcludes());
patterns.excludeSpecs(getAllExcludeSpecs());
return patterns;
}
示例14
/**
* Returns this collection as a set of {@link DirectoryFileTree} instances.
*/
protected Collection<DirectoryFileTree> getAsFileTrees() {
List<DirectoryFileTree> fileTrees = new ArrayList<DirectoryFileTree>();
for (File file : getFiles()) {
if (file.isFile()) {
PatternSet patternSet = new PatternSet();
patternSet.include(new String[]{file.getName()});
fileTrees.add(new DirectoryFileTree(file.getParentFile(), patternSet));
}
}
return fileTrees;
}
示例15
private void doVisit(FileVisitor visitor, File file, LinkedList<String> relativePath, int segmentIndex, AtomicBoolean stopFlag) {
if (stopFlag.get()) {
return;
}
String segment = patternSegments.get(segmentIndex);
if (segment.contains("**")) {
PatternSet patternSet = new PatternSet();
patternSet.include(includePattern);
patternSet.exclude(excludeSpec);
DirectoryFileTree fileTree = new DirectoryFileTree(baseDir, patternSet);
fileTree.visitFrom(visitor, file, new RelativePath(file.isFile(), relativePath.toArray(new String[relativePath.size()])));
} else if (segment.contains("*") || segment.contains("?")) {
PatternStep step = PatternStepFactory.getStep(segment, false);
File[] children = file.listFiles();
if (children == null) {
if (!file.canRead()) {
throw new GradleException(String.format("Could not list contents of directory '%s' as it is not readable.", file));
}
// else, might be a link which points to nothing, or has been removed while we're visiting, or ...
throw new GradleException(String.format("Could not list contents of '%s'.", file));
}
for (File child : children) {
if (stopFlag.get()) { break; }
if (step.matches(child.getName())) {
relativePath.addLast(child.getName());
doVisitDirOrFile(visitor, child, relativePath, segmentIndex + 1, stopFlag);
relativePath.removeLast();
}
}
} else {
relativePath.addLast(segment);
doVisitDirOrFile(visitor, new File(file, segment), relativePath, segmentIndex + 1, stopFlag);
relativePath.removeLast();
}
}
示例16
/**
* Returns this collection as a set of {@link DirectoryFileTree} instances.
*/
protected Collection<DirectoryFileTree> getAsFileTrees() {
List<DirectoryFileTree> fileTrees = new ArrayList<DirectoryFileTree>();
for (File file : getFiles()) {
if (file.isFile()) {
PatternSet patternSet = new PatternSet();
patternSet.include(new String[]{file.getName()});
fileTrees.add(new DirectoryFileTree(file.getParentFile(), patternSet));
}
}
return fileTrees;
}
示例17
public DefaultCopySpec(FileResolver resolver, Instantiator instantiator, DefaultCopySpec parentSpec) {
this.parentSpec = parentSpec;
this.resolver = resolver;
this.instantiator = instantiator;
this.pathNotationParser = new PathNotationParser<String>();
sourcePaths = new LinkedHashSet<Object>();
childSpecs = new ArrayList<CopySpecInternal>();
patternSet = new PatternSet();
duplicatesStrategy = null; //inherit from parent
}
示例18
public void configureCompilation(PatternSet changedSourceOnly, SelectiveJavaCompiler compiler, ClassDependencyInfo dependencyInfo) {
for (String c : changedClassesInJar) {
Set<String> actualDependents = dependencyInfo.getActualDependents(c);
for (String d : actualDependents) {
compiler.addStaleClass(d);
changedSourceOnly.include(d.replaceAll("\\.", "/").concat(".java"));
}
}
}
示例19
/**
* Returns this collection as a set of {@link DirectoryFileTree} instances.
*/
protected Collection<DirectoryFileTree> getAsFileTrees() {
List<DirectoryFileTree> fileTrees = new ArrayList<DirectoryFileTree>();
for (File file : getFiles()) {
if (file.isFile()) {
PatternSet patternSet = new PatternSet();
patternSet.include(new String[]{file.getName()});
fileTrees.add(new DirectoryFileTree(file.getParentFile(), patternSet));
}
}
return fileTrees;
}
示例20
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());
}
示例21
public void configureCompilation(PatternSet changedSourceOnly, SelectiveJavaCompiler compiler, ClassDependencyInfo dependencyInfo) {
for (String c : changedClassesInJar) {
Set<String> actualDependents = dependencyInfo.getActualDependents(c);
for (String d : actualDependents) {
compiler.addStaleClass(d);
changedSourceOnly.include(d.replaceAll("\\.", "/").concat(".java"));
}
}
}
示例22
public CompressFileOperationsImpl(ProjectInternal project) {
fileOperations = project.getFileOperations();
temporaryFileProvider = project.getServices().get(TemporaryFileProvider.class);
fileHasher = project.getServices().get(FileHasher.class);
fileSystem = project.getServices().get(FileSystem.class);
directoryFileTreeFactory = project.getServices().get(DirectoryFileTreeFactory.class);
patternSetFactory = project.getServices().getFactory(PatternSet.class);
}
示例23
private static Spec<FileTreeElement> getMaindexSpec(PatternSet patternSet) {
Spec<FileTreeElement> maindexSpec = null;
if (patternSet != null) {
Spec<FileTreeElement> includeSpec = null;
Spec<FileTreeElement> excludeSpec = null;
if (!patternSet.getIncludes().isEmpty()) {
includeSpec = patternSet.getAsIncludeSpec();
}
if (!patternSet.getExcludes().isEmpty()) {
excludeSpec = patternSet.getAsExcludeSpec();
}
if (includeSpec != null && excludeSpec != null) {
maindexSpec = new OrSpec<>(includeSpec, new NotSpec<>(excludeSpec));
} else {
if (excludeSpec != null) { // only exclude
maindexSpec = new NotSpec<>(excludeSpec);
} else if (includeSpec != null) { // only include
maindexSpec = includeSpec;
}
}
}
// if (maindexSpec == null) {
// maindexSpec = Specs.satisfyAll();
// }
return maindexSpec;
}
示例24
/**
* Gets main classes from jar.
*
* @param jarMergingOutputFile the jar merging output file
* @param mainDexPattern the main dex pattern
* @param adtMainCls the filter mapping of suggest classes
* @param logFilter
* @return the main classes from jar
* @throws Exception the exception
* @author ceabie
*/
private static ArrayList<String> getMainClassesFromJar(
File jarMergingOutputFile, PatternSet mainDexPattern, Map<String, Boolean> adtMainCls, boolean logFilter)
throws Exception {
ZipFile clsFile = new ZipFile(jarMergingOutputFile);
Spec<FileTreeElement> asSpec = getMaindexSpec(mainDexPattern);
ClassFileTreeElement treeElement = new ClassFileTreeElement();
// lists classes from jar.
ArrayList<String> mainDexList = new ArrayList<>();
Enumeration<? extends ZipEntry> entries = clsFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
String entryName = entry.getName();
if (entryName.endsWith(CLASS_SUFFIX)) {
treeElement.setClassPath(entryName);
if (isAtMainDex(adtMainCls, entryName, treeElement, asSpec, logFilter)) {
mainDexList.add(entryName);
}
}
}
clsFile.close();
return mainDexList;
}
示例25
/**
* Gets main classes from mapping.
*
* @param mapping the mapping file
* @param mainDexPattern the main dex pattern
* @param recommendMainCls the filter mapping of suggest classes
* @param logFilter
* @return the main classes from mapping
* @throws Exception the exception
* @author ceabie
*/
private static List<String> getMainClassesFromMapping(
File mapping,
PatternSet mainDexPattern,
Map<String, Boolean> recommendMainCls, boolean logFilter) throws Exception {
String line;
List<String> mainDexList = new ArrayList<>();
BufferedReader reader = new BufferedReader(new FileReader(mapping)); // all classes
ClassFileTreeElement filterElement = new ClassFileTreeElement();
Spec<FileTreeElement> asSpec = getMaindexSpec(mainDexPattern);
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.endsWith(":")) {
int flagPos = line.indexOf(MAPPING_FLAG);
if (flagPos != -1) {
String sOrgCls = line.substring(0, flagPos).replace('.', '/') + CLASS_SUFFIX;
String sMapCls = line.substring(flagPos + MAPPING_FLAG_LEN, line.length() - 1)
.replace('.', '/') + CLASS_SUFFIX;
filterElement.setClassPath(sOrgCls);
if (isAtMainDex(recommendMainCls, sMapCls, filterElement, asSpec, logFilter)) {
mainDexList.add(sMapCls);
}
}
}
}
reader.close();
return mainDexList;
}
示例26
public GitPublishExtension(Project project) {
this.repoDir = project.getObjects().directoryProperty();
this.repoUri = project.getObjects().property(String.class);
this.referenceRepoUri = project.getObjects().property(String.class);
this.branch = project.getObjects().property(String.class);
this.commitMessage = project.getObjects().property(String.class);
this.sign = project.getObjects().property(Boolean.class);
this.contents = project.copySpec();
this.preserve = new PatternSet();
this.preserve.include(".git/**/*");
}
示例27
public CompressFileOperationsImpl(ProjectInternal project) {
fileOperations = project.getFileOperations();
temporaryFileProvider = project.getServices().get(TemporaryFileProvider.class);
fileHasher = project.getServices().get(FileHasher.class);
fileSystem = project.getServices().get(FileSystem.class);
directoryFileTreeFactory = project.getServices().get(DirectoryFileTreeFactory.class);
patternSetFactory = project.getServices().getFactory(PatternSet.class);
}
示例28
private void doVisit(FileVisitor visitor, File file, LinkedList<String> relativePath, int segmentIndex, AtomicBoolean stopFlag) {
if (stopFlag.get()) {
return;
}
String segment = patternSegments.get(segmentIndex);
if (segment.contains("**")) {
PatternSet patternSet = new PatternSet();
patternSet.include(includePattern);
patternSet.exclude(excludeSpec);
DirectoryFileTree fileTree = new DirectoryFileTree(baseDir, patternSet);
fileTree.visitFrom(visitor, file, new RelativePath(file.isFile(), relativePath.toArray(new String[relativePath.size()])));
} else if (segment.contains("*") || segment.contains("?")) {
PatternStep step = PatternStepFactory.getStep(segment, false);
File[] children = file.listFiles();
if (children == null) {
if (!file.canRead()) {
throw new GradleException(String.format("Could not list contents of directory '%s' as it is not readable.", file));
}
// else, might be a link which points to nothing, or has been removed while we're visiting, or ...
throw new GradleException(String.format("Could not list contents of '%s'.", file));
}
for (File child : children) {
if (stopFlag.get()) { break; }
if (step.matches(child.getName())) {
relativePath.addLast(child.getName());
doVisitDirOrFile(visitor, child, relativePath, segmentIndex + 1, stopFlag);
relativePath.removeLast();
}
}
} else {
relativePath.addLast(segment);
doVisitDirOrFile(visitor, new File(file, segment), relativePath, segmentIndex + 1, stopFlag);
relativePath.removeLast();
}
}
示例29
public DefaultCopySpec(FileResolver resolver, Instantiator instantiator) {
this.fileResolver = resolver;
this.instantiator = instantiator;
sourcePaths = new LinkedHashSet<Object>();
childSpecs = new ArrayList<CopySpecInternal>();
patternSet = new PatternSet();
duplicatesStrategy = null;
}
示例30
public PatternSet getPatternSet() {
PatternSet patterns = new PatternSet();
patterns.setCaseSensitive(isCaseSensitive());
patterns.include(this.getAllIncludes());
patterns.includeSpecs(getAllIncludeSpecs());
patterns.exclude(this.getAllExcludes());
patterns.excludeSpecs(getAllExcludeSpecs());
return patterns;
}