org.gradle.api.file.FileTreeElement Java Examples

The following examples show how to use org.gradle.api.file.FileTreeElement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GroovyBasePlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 7 votes vote down vote up
private void configureSourceSetDefaults(final JavaBasePlugin javaBasePlugin) {
    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() {
        public void execute(SourceSet sourceSet) {
            final DefaultGroovySourceSet groovySourceSet = new DefaultGroovySourceSet(((DefaultSourceSet) sourceSet).getDisplayName(), fileResolver);
            new DslObject(sourceSet).getConvention().getPlugins().put("groovy", groovySourceSet);

            groovySourceSet.getGroovy().srcDir(String.format("src/%s/groovy", sourceSet.getName()));
            sourceSet.getResources().getFilter().exclude(new Spec<FileTreeElement>() {
                public boolean isSatisfiedBy(FileTreeElement element) {
                    return groovySourceSet.getGroovy().contains(element.getFile());
                }
            });
            sourceSet.getAllJava().source(groovySourceSet.getGroovy());
            sourceSet.getAllSource().source(groovySourceSet.getGroovy());

            String compileTaskName = sourceSet.getCompileTaskName("groovy");
            GroovyCompile compile = project.getTasks().create(compileTaskName, GroovyCompile.class);
            javaBasePlugin.configureForSourceSet(sourceSet, compile);
            compile.dependsOn(sourceSet.getCompileJavaTaskName());
            compile.setDescription(String.format("Compiles the %s Groovy source.", sourceSet.getName()));
            compile.setSource(groovySourceSet.getGroovy());

            project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(compileTaskName);
        }
    });
}
 
Example #2
Source File: DefaultSourceSet.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public DefaultSourceSet(String name, FileResolver fileResolver) {
    this.name = name;
    displayName = GUtil.toWords(this.name);

    String javaSrcDisplayName = String.format("%s Java source", displayName);

    javaSource = new DefaultSourceDirectorySet(javaSrcDisplayName, fileResolver);
    javaSource.getFilter().include("**/*.java");

    allJavaSource = new DefaultSourceDirectorySet(javaSrcDisplayName, fileResolver);
    allJavaSource.getFilter().include("**/*.java");
    allJavaSource.source(javaSource);

    String resourcesDisplayName = String.format("%s resources", displayName);
    resources = new DefaultSourceDirectorySet(resourcesDisplayName, fileResolver);
    resources.getFilter().exclude(new Spec<FileTreeElement>() {
        public boolean isSatisfiedBy(FileTreeElement element) {
            return javaSource.contains(element.getFile());
        }
    });

    String allSourceDisplayName = String.format("%s source", displayName);
    allSource = new DefaultSourceDirectorySet(allSourceDisplayName, fileResolver);
    allSource.source(resources);
    allSource.source(javaSource);
}
 
Example #3
Source File: DefaultSourceSet.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public DefaultSourceSet(String name, FileResolver fileResolver) {
    this.name = name;
    displayName = GUtil.toWords(this.name);

    String javaSrcDisplayName = String.format("%s Java source", displayName);

    javaSource = new DefaultSourceDirectorySet(javaSrcDisplayName, fileResolver);
    javaSource.getFilter().include("**/*.java");

    allJavaSource = new DefaultSourceDirectorySet(javaSrcDisplayName, fileResolver);
    allJavaSource.getFilter().include("**/*.java");
    allJavaSource.source(javaSource);

    String resourcesDisplayName = String.format("%s resources", displayName);
    resources = new DefaultSourceDirectorySet(resourcesDisplayName, fileResolver);
    resources.getFilter().exclude(new Spec<FileTreeElement>() {
        public boolean isSatisfiedBy(FileTreeElement element) {
            return javaSource.contains(element.getFile());
        }
    });

    String allSourceDisplayName = String.format("%s source", displayName);
    allSource = new DefaultSourceDirectorySet(allSourceDisplayName, fileResolver);
    allSource.source(resources);
    allSource.source(javaSource);
}
 
Example #4
Source File: GroovyBasePlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void configureSourceSetDefaults(final JavaBasePlugin javaBasePlugin) {
    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() {
        public void execute(SourceSet sourceSet) {
            final DefaultGroovySourceSet groovySourceSet = new DefaultGroovySourceSet(((DefaultSourceSet) sourceSet).getDisplayName(), fileResolver);
            new DslObject(sourceSet).getConvention().getPlugins().put("groovy", groovySourceSet);

            groovySourceSet.getGroovy().srcDir(String.format("src/%s/groovy", sourceSet.getName()));
            sourceSet.getResources().getFilter().exclude(new Spec<FileTreeElement>() {
                public boolean isSatisfiedBy(FileTreeElement element) {
                    return groovySourceSet.getGroovy().contains(element.getFile());
                }
            });
            sourceSet.getAllJava().source(groovySourceSet.getGroovy());
            sourceSet.getAllSource().source(groovySourceSet.getGroovy());

            String compileTaskName = sourceSet.getCompileTaskName("groovy");
            GroovyCompile compile = project.getTasks().create(compileTaskName, GroovyCompile.class);
            javaBasePlugin.configureForSourceSet(sourceSet, compile);
            compile.dependsOn(sourceSet.getCompileJavaTaskName());
            compile.setDescription(String.format("Compiles the %s Groovy source.", sourceSet.getName()));
            compile.setSource(groovySourceSet.getGroovy());

            project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(compileTaskName);
        }
    });
}
 
Example #5
Source File: DefaultSourceSet.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public DefaultSourceSet(String name, FileResolver fileResolver) {
    this.name = name;
    displayName = GUtil.toWords(this.name);

    String javaSrcDisplayName = String.format("%s Java source", displayName);

    javaSource = new DefaultSourceDirectorySet(javaSrcDisplayName, fileResolver);
    javaSource.getFilter().include("**/*.java");

    allJavaSource = new DefaultSourceDirectorySet(javaSrcDisplayName, fileResolver);
    allJavaSource.getFilter().include("**/*.java");
    allJavaSource.source(javaSource);

    String resourcesDisplayName = String.format("%s resources", displayName);
    resources = new DefaultSourceDirectorySet(resourcesDisplayName, fileResolver);
    resources.getFilter().exclude(new Spec<FileTreeElement>() {
        public boolean isSatisfiedBy(FileTreeElement element) {
            return javaSource.contains(element.getFile());
        }
    });

    String allSourceDisplayName = String.format("%s source", displayName);
    allSource = new DefaultSourceDirectorySet(allSourceDisplayName, fileResolver);
    allSource.source(resources);
    allSource.source(javaSource);
}
 
Example #6
Source File: DefaultSourceSet.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public DefaultSourceSet(String name, FileResolver fileResolver) {
    this.name = name;
    displayName = GUtil.toWords(this.name);

    String javaSrcDisplayName = String.format("%s Java source", displayName);

    javaSource = new DefaultSourceDirectorySet(javaSrcDisplayName, fileResolver);
    javaSource.getFilter().include("**/*.java");

    allJavaSource = new DefaultSourceDirectorySet(javaSrcDisplayName, fileResolver);
    allJavaSource.getFilter().include("**/*.java");
    allJavaSource.source(javaSource);

    String resourcesDisplayName = String.format("%s resources", displayName);
    resources = new DefaultSourceDirectorySet(resourcesDisplayName, fileResolver);
    resources.getFilter().exclude(new Spec<FileTreeElement>() {
        public boolean isSatisfiedBy(FileTreeElement element) {
            return javaSource.contains(element.getFile());
        }
    });

    String allSourceDisplayName = String.format("%s source", displayName);
    allSource = new DefaultSourceDirectorySet(allSourceDisplayName, fileResolver);
    allSource.source(resources);
    allSource.source(javaSource);
}
 
Example #7
Source File: PatternSet.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Spec<FileTreeElement> getAsExcludeSpec() {
    Collection<String> allExcludes = Sets.newLinkedHashSet(excludes);
    Collections.addAll(allExcludes, DirectoryScanner.getDefaultExcludes());

    List<Spec<FileTreeElement>> matchers = Lists.newArrayList();
    for (String exclude : allExcludes) {
        Spec<RelativePath> patternMatcher = PatternMatcherFactory.getPatternMatcher(false, caseSensitive, exclude);
        matchers.add(new RelativePathSpec(patternMatcher));
    }

    matchers.addAll(excludeSpecs);
    return new OrSpec<FileTreeElement>(matchers);
}
 
Example #8
Source File: DexSplitTools.java    From DexKnifePlugin with Apache License 2.0 5 votes vote down vote up
private static boolean isAtMainDex(
        Map<String, Boolean> mainCls, String sMapCls,
        ClassFileTreeElement treeElement, Spec<FileTreeElement> asSpec, boolean logFilter) {
    boolean isRecommend = false;

    // adt推荐
    if (mainCls != null) {
        Boolean value = mainCls.get(sMapCls);
        if (value != null) {
            isRecommend = value;
        }
    }

    // 全局过滤
    boolean inGlobalFilter = asSpec != null && asSpec.isSatisfiedBy(treeElement);

    if (logFilter) {
        String ret;
        if (isRecommend && inGlobalFilter) {
            ret = "true";
        } else if (isRecommend) {
            ret = "Recommend";
        } else if (inGlobalFilter) {
            ret = "Global";
        } else {
            ret = "false";
        }

        String s = "AtMainDex: " + treeElement.getPath() + " [" + ret + "]";

        if (isRecommend || inGlobalFilter) {
            System.err.println(s);
        } else {
            System.out.println(s);
        }
    }

    // 合并结果
    return isRecommend || inGlobalFilter;
}
 
Example #9
Source File: DexSplitTools.java    From DexKnifePlugin with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #10
Source File: DexSplitTools.java    From DexKnifePlugin with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #11
Source File: DexSplitTools.java    From DexKnifePlugin with Apache License 2.0 5 votes vote down vote up
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;
    }
 
Example #12
Source File: PatternSet.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Spec<FileTreeElement> getAsExcludeSpec() {
    Collection<String> allExcludes = Sets.newLinkedHashSet(excludes);
    Collections.addAll(allExcludes, DirectoryScanner.getDefaultExcludes());

    List<Spec<FileTreeElement>> matchers = Lists.newArrayList();
    for (String exclude : allExcludes) {
        Spec<RelativePath> patternMatcher = PatternMatcherFactory.getPatternMatcher(false, caseSensitive, exclude);
        matchers.add(new RelativePathSpec(patternMatcher));
    }

    matchers.addAll(excludeSpecs);
    return new OrSpec<FileTreeElement>(matchers);
}
 
Example #13
Source File: SingleIncludePatternFileTree.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public SingleIncludePatternFileTree(File baseDir, String includePattern, Spec<FileTreeElement> excludeSpec) {
    this.baseDir = baseDir;
    if (includePattern.endsWith("/") || includePattern.endsWith("\\")) {
        includePattern += "**";
    }
    this.includePattern = includePattern;
    this.patternSegments = Arrays.asList(includePattern.split("[/\\\\]"));
    this.excludeSpec = excludeSpec;
}
 
Example #14
Source File: PatternSet.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Spec<FileTreeElement> getAsIncludeSpec() {
    List<Spec<FileTreeElement>> matchers = Lists.newArrayList();
    for (String include : includes) {
        Spec<RelativePath> patternMatcher = PatternMatcherFactory.getPatternMatcher(true, caseSensitive, include);
        matchers.add(new RelativePathSpec(patternMatcher));
    }

    matchers.addAll(includeSpecs);
    return new OrSpec<FileTreeElement>(matchers);
}
 
Example #15
Source File: PatternSet.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Spec<FileTreeElement> getAsIncludeSpec() {
    List<Spec<FileTreeElement>> matchers = Lists.newArrayList();
    for (String include : includes) {
        Spec<RelativePath> patternMatcher = PatternMatcherFactory.getPatternMatcher(true, caseSensitive, include);
        matchers.add(new RelativePathSpec(patternMatcher));
    }

    matchers.addAll(includeSpecs);
    return new OrSpec<FileTreeElement>(matchers);
}
 
Example #16
Source File: PatternSet.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Spec<FileTreeElement> getAsExcludeSpec() {
    Collection<String> allExcludes = Sets.newLinkedHashSet(excludes);
    Collections.addAll(allExcludes, DirectoryScanner.getDefaultExcludes());

    List<Spec<FileTreeElement>> matchers = Lists.newArrayList();
    for (String exclude : allExcludes) {
        Spec<RelativePath> patternMatcher = PatternMatcherFactory.getPatternMatcher(false, caseSensitive, exclude);
        matchers.add(new RelativePathSpec(patternMatcher));
    }

    matchers.addAll(excludeSpecs);
    return new OrSpec<FileTreeElement>(matchers);
}
 
Example #17
Source File: SingleIncludePatternFileTree.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public SingleIncludePatternFileTree(File baseDir, String includePattern, Spec<FileTreeElement> excludeSpec) {
    this.baseDir = baseDir;
    if (includePattern.endsWith("/") || includePattern.endsWith("\\")) {
        includePattern += "**";
    }
    this.includePattern = includePattern;
    this.patternSegments = Arrays.asList(includePattern.split("[/\\\\]"));
    this.excludeSpec = excludeSpec;
}
 
Example #18
Source File: SingleIncludePatternFileTree.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public SingleIncludePatternFileTree(File baseDir, String includePattern, Spec<FileTreeElement> excludeSpec) {
    this.baseDir = baseDir;
    if (includePattern.endsWith("/") || includePattern.endsWith("\\")) {
        includePattern += "**";
    }
    this.includePattern = includePattern;
    this.patternSegments = Arrays.asList(includePattern.split("[/\\\\]"));
    this.excludeSpec = excludeSpec;
}
 
Example #19
Source File: PatternSet.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Spec<FileTreeElement> getAsExcludeSpec() {
    Collection<String> allExcludes = Sets.newLinkedHashSet(excludes);
    Collections.addAll(allExcludes, DirectoryScanner.getDefaultExcludes());

    List<Spec<FileTreeElement>> matchers = Lists.newArrayList();
    for (String exclude : allExcludes) {
        Spec<RelativePath> patternMatcher = PatternMatcherFactory.getPatternMatcher(false, caseSensitive, exclude);
        matchers.add(new RelativePathSpec(patternMatcher));
    }

    matchers.addAll(excludeSpecs);
    return new OrSpec<FileTreeElement>(matchers);
}
 
Example #20
Source File: WarOverlay.java    From gradle-plugins with MIT License 4 votes vote down vote up
public void exclude(Spec<FileTreeElement> excludeSpec) {
    getWarCopySpec().exclude(excludeSpec);
}
 
Example #21
Source File: PatternSet.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Set<Spec<FileTreeElement>> getIncludeSpecs() {
    return includeSpecs;
}
 
Example #22
Source File: PatternSet.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Spec<FileTreeElement> getAsSpec() {
    return new AndSpec<FileTreeElement>(getAsIncludeSpec(), new NotSpec<FileTreeElement>(getAsExcludeSpec()));
}
 
Example #23
Source File: DefaultSourceDirectorySet.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public PatternFilterable exclude(Spec<FileTreeElement> excludeSpec) {
    patterns.exclude(excludeSpec);
    return this;
}
 
Example #24
Source File: DefaultSourceDirectorySet.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public PatternFilterable include(Spec<FileTreeElement> includeSpec) {
    patterns.include(includeSpec);
    return this;
}
 
Example #25
Source File: PatternSet.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public PatternSet exclude(Closure closure) {
    exclude(Specs.<FileTreeElement>convertClosureToSpec(closure));
    return this;
}
 
Example #26
Source File: PatternSet.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public PatternSet exclude(Spec<FileTreeElement> spec) {
    excludeSpecs.add(spec);
    return this;
}
 
Example #27
Source File: DefaultAndroidSourceDirectorySet.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public PatternFilterable exclude(Spec<FileTreeElement> excludeSpec) {
    filter.exclude(excludeSpec);
    return this;
}
 
Example #28
Source File: Test.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Test exclude(Spec<FileTreeElement> excludeSpec) {
    patternSet.exclude(excludeSpec);
    return this;
}
 
Example #29
Source File: DefaultConfigurableFileTree.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultConfigurableFileTree include(Spec<FileTreeElement> includeSpec) {
    patternSet.include(includeSpec);
    return this;
}
 
Example #30
Source File: DefaultConfigurableFileTree.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultConfigurableFileTree exclude(Spec<FileTreeElement> excludeSpec) {
    patternSet.exclude(excludeSpec);
    return this;
}