org.gradle.api.tasks.util.PatternSet Java Examples

The following examples show how to use org.gradle.api.tasks.util.PatternSet. 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: WindowsResourcesCompileTaskConfig.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
    }
}
 
Example #2
Source File: DefaultScalaJavaJointCompiler.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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;
        }
    };
}
 
Example #3
Source File: DefaultScalaJavaJointCompiler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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;
        }
    };
}
 
Example #4
Source File: FileCollectionBackedArchiveTextResource.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
}
 
Example #5
Source File: DefaultScalaJavaJointCompiler.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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;
        }
    };
}
 
Example #6
Source File: FileCollectionBackedArchiveTextResource.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
}
 
Example #7
Source File: WindowsResourcesCompileTaskConfig.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
    }
}
 
Example #8
Source File: IncrementalCompilationInitializer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
}
 
Example #9
Source File: DefaultScalaJavaJointCompiler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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;
        }
    };
}
 
Example #10
Source File: DefaultCopySpec.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #11
Source File: DefaultCopySpec.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #12
Source File: AbstractFileCollection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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;
}
 
Example #13
Source File: DefaultCopySpec.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #14
Source File: AbstractFileCollection.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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;
}
 
Example #15
Source File: DefaultCopySpec.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #16
Source File: SelectiveCompilation.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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());
}
 
Example #17
Source File: SingleIncludePatternFileTree.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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();
    }
}
 
Example #18
Source File: AbstractFileCollection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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;
}
 
Example #19
Source File: DefaultCopySpec.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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
}
 
Example #20
Source File: DefaultRebuildInfo.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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"));
        }
    }
}
 
Example #21
Source File: AbstractFileCollection.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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;
}
 
Example #22
Source File: SingleIncludePatternFileTree.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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();
    }
}
 
Example #23
Source File: SelectiveCompilation.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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());
}
 
Example #24
Source File: DefaultRebuildInfo.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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"));
        }
    }
}
 
Example #25
Source File: CompressFileOperationsImpl.java    From gradle-plugins with MIT License 5 votes vote down vote up
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);
}
 
Example #26
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 #27
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 #28
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 #29
Source File: GitPublishExtension.java    From gradle-git-publish with Apache License 2.0 5 votes vote down vote up
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/**/*");
}
 
Example #30
Source File: CompressFileOperationsImpl.java    From gradle-plugins with MIT License 5 votes vote down vote up
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);
}