예제 #1
0
  protected PatternSet doCopyFrom(PatternSet from) {
    includes.clear();
    excludes.clear();
    includeSpecs.clear();
    excludeSpecs.clear();
    caseSensitive = from.caseSensitive;

    if (from instanceof IntersectionPatternSet) {
      PatternSet other = ((IntersectionPatternSet) from).other;
      PatternSet otherCopy = new PatternSet().copyFrom(other);
      PatternSet intersectCopy = new IntersectionPatternSet(otherCopy);
      intersectCopy.includes.addAll(from.includes);
      intersectCopy.excludes.addAll(from.excludes);
      intersectCopy.includeSpecs.addAll(from.includeSpecs);
      intersectCopy.excludeSpecs.addAll(from.excludeSpecs);
      includeSpecs.add(intersectCopy.getAsSpec());
    } else {
      includes.addAll(from.includes);
      excludes.addAll(from.excludes);
      includeSpecs.addAll(from.includeSpecs);
      excludeSpecs.addAll(from.excludeSpecs);
    }

    return this;
  }
예제 #2
0
 public List<Spec<FileTreeElement>> getAllExcludeSpecs() {
   List<Spec<FileTreeElement>> result = new ArrayList<Spec<FileTreeElement>>();
   if (parentSpec != null) {
     result.addAll(parentSpec.getAllExcludeSpecs());
   }
   result.addAll(patternSet.getExcludeSpecs());
   return result;
 }
예제 #3
0
 @Override
 public List<FileTreeElement> filter(PatternSet patternSet) {
   ImmutableList.Builder<FileTreeElement> filtered = ImmutableList.builder();
   final Spec<FileTreeElement> spec = patternSet.getAsSpec();
   for (FileTreeElement element : entries) {
     if (spec.isSatisfiedBy(element)) {
       filtered.add(element);
     }
   }
   return filtered.build();
 }
예제 #4
0
 public PatternSet getPatternSet() {
   PatternSet patterns = new PatternSet();
   patterns.setCaseSensitive(isCaseSensitive());
   patterns.include(getAllIncludes());
   patterns.includeSpecs(getAllIncludeSpecs());
   patterns.exclude(getAllExcludes());
   patterns.excludeSpecs(getAllExcludeSpecs());
   return patterns;
 }
예제 #5
0
  @TaskAction
  public void doTask() throws IOException {
    File dest = getDestinationDir();

    if (shouldClean()) {
      delete(dest);
    }

    dest.mkdirs();

    ExtractionVisitor visitor =
        new ExtractionVisitor(dest, isIncludeEmptyDirs(), patternSet.getAsSpec());

    for (File source : getSourcePaths()) {
      getLogger().debug("Extracting: " + source);
      (new ZipFileTree(source)).visit(visitor);
    }
  }
 public DefaultConfigurableFileTree include(Spec<FileTreeElement> includeSpec) {
   patternSet.include(includeSpec);
   return this;
 }
예제 #7
0
 @Override
 public PatternFilterable setIncludes(Iterable<String> arg0) {
   return patternSet.setIncludes(arg0);
 }
예제 #8
0
 @Override
 public PatternFilterable include(Spec<FileTreeElement> arg0) {
   return patternSet.include(arg0);
 }
예제 #9
0
 @Override
 public Set<String> getIncludes() {
   return patternSet.getIncludes();
 }
예제 #10
0
 public Set<String> getExcludes() {
   return patternSet.getExcludes();
 }
  /**
   * Perform the source replacement task.
   *
   * @throws IOException
   */
  @TaskAction
  public void run() throws IOException {
    final PatternSet patternSet = new PatternSet();
    patternSet.setIncludes(this.input.getIncludes());
    patternSet.setExcludes(this.input.getExcludes());

    if (this.output.exists()) {
      // Remove the output directory if it exists to prevent any possible conflicts
      FileUtil.deleteDirectory(this.output);
    }

    this.output.mkdirs();
    this.output = this.output.getCanonicalFile();

    // Resolve global and by-file replacements
    final Map<String, String> globalReplacements = this.resolveReplacementsGlobal();
    final Multimap<String, Map<String, String>> fileReplacements = this.resolveReplacementsByFile();

    for (final DirectoryTree dirTree : this.input.getSrcDirTrees()) {
      File dir = dirTree.getDir();

      // handle non-existent source directories
      if (!dir.exists() || !dir.isDirectory()) {
        continue;
      } else {
        dir = dir.getCanonicalFile();
      }

      // this could be written as .matching(source), but it doesn't actually work
      // because later on gradle casts it directly to PatternSet and crashes
      final FileTree tree =
          this.getProject().fileTree(dir).matching(this.input.getFilter()).matching(patternSet);

      for (final File file : tree) {
        final File destination = getDestination(file, dir, this.output);
        destination.getParentFile().mkdirs();
        destination.createNewFile();

        boolean wasChanged = false;
        String text = Files.toString(file, Charsets.UTF_8);

        if (this.isIncluded(file)) {
          for (Map.Entry<String, String> entry : globalReplacements.entrySet()) {
            text = text.replaceAll(entry.getKey(), entry.getValue());
          }

          wasChanged = true;
        }

        final String path = this.getFilePath(file);
        Collection<Map<String, String>> collection = fileReplacements.get(path);
        if (collection != null && !collection.isEmpty()) {
          for (Map<String, String> map : collection) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
              text = text.replaceAll(entry.getKey(), entry.getValue());
            }
          }

          wasChanged = true;
        }

        if (wasChanged) {
          Files.write(text, destination, Charsets.UTF_8);
        } else {
          Files.copy(file, destination);
        }
      }
    }
  }
 public DefaultConfigurableFileTree exclude(Closure excludeSpec) {
   patternSet.exclude(excludeSpec);
   return this;
 }
 public DefaultConfigurableFileTree exclude(Spec<FileTreeElement> excludeSpec) {
   patternSet.exclude(excludeSpec);
   return this;
 }
 public DefaultConfigurableFileTree exclude(Iterable<String> excludes) {
   patternSet.exclude(excludes);
   return this;
 }
예제 #15
0
 public CopySpec exclude(Spec<FileTreeElement> excludeSpec) {
   patternSet.exclude(excludeSpec);
   return this;
 }
예제 #16
0
 public CopySpec exclude(Closure excludeSpec) {
   patternSet.exclude(excludeSpec);
   return this;
 }
예제 #17
0
 public CopySpec include(String... includes) {
   patternSet.include(includes);
   return this;
 }
예제 #18
0
 public CopySpecImpl setExcludes(Iterable<String> excludes) {
   patternSet.setExcludes(excludes);
   return this;
 }
예제 #19
0
 public CopySpec include(Iterable<String> includes) {
   patternSet.include(includes);
   return this;
 }
예제 #20
0
 @Override
 public PatternFilterable exclude(String... arg0) {
   return patternSet.exclude(arg0);
 }
예제 #21
0
 public CopySpec include(Spec<FileTreeElement> includeSpec) {
   patternSet.include(includeSpec);
   return this;
 }
예제 #22
0
 @Override
 public PatternFilterable include(Iterable<String> arg0) {
   return patternSet.include(arg0);
 }
예제 #23
0
 public CopySpec include(Closure includeSpec) {
   patternSet.include(includeSpec);
   return this;
 }
예제 #24
0
 @Override
 @SuppressWarnings("rawtypes")
 public PatternFilterable include(Closure arg0) {
   return patternSet.include(arg0);
 }
예제 #25
0
 public CopySpec setIncludes(Iterable<String> includes) {
   patternSet.setIncludes(includes);
   return this;
 }
예제 #26
0
 public CopySpec exclude(String... excludes) {
   patternSet.exclude(excludes);
   return this;
 }
예제 #27
0
 public CopySpec exclude(Iterable<String> excludes) {
   patternSet.exclude(excludes);
   return this;
 }
예제 #28
0
 public Spec<FileTreeElement> getAsSpec() {
   return Specs.and(super.getAsSpec(), other.getAsSpec());
 }
 public DefaultConfigurableFileTree include(Iterable<String> includes) {
   patternSet.include(includes);
   return this;
 }