public void setUseExecutor(boolean useExecutor) { if (useExecutor) { mExecutor = WaitableExecutor.useGlobalSharedThreadPool(); } else { mExecutor = null; } }
public void setUseExecutor(boolean useExecutor) { if (useExecutor) { mExecutor = new WaitableExecutor<Void>(); } else { mExecutor = null; } }
protected void waitForAllTasks() { try { mExecutor.waitForTasksWithQuickFail(true); } catch (InterruptedException | LoggedErrorException e) { throw new RuntimeException(e); } }
private void handleInterfaceInheritance(@NonNull Set<T> interfaceInheritance) { for (final T klass : interfaceInheritance) { mExecutor.execute(new Callable<Void>() { @Override public Void call() throws Exception {
public static void setThreadPoolSize(Project project) { Integer size = AndroidGradleOptions.getThreadPoolSize(project); if (size == null) { return; } ExecutorSingleton.setThreadPoolSize(size); } }
/** * Returns an {@link PngCruncher} using aapt underneath * @return an PngCruncher object */ @NonNull public PngCruncher getAaptCruncher() { checkState(mTargetInfo != null, "Cannot call getAaptCruncher() before setTargetInfo() is called."); return new AaptCruncher( mTargetInfo.getBuildTools().getPath(BuildToolInfo.PathId.AAPT), mProcessExecutor, mProcessOutputHandler); }
@NonNull Iterable<PostProcessingData.UnresolvedReference<T>> unresolvedReferences) { for (final PostProcessingData.UnresolvedReference<T> unresolvedReference : unresolvedReferences) { mExecutor.execute(new Callable<Void>() { @Override public Void call() {
public void search(@NonNull SourceFileProcessor processor) throws ProcessException, LoggedErrorException, InterruptedException, IOException { for (File file : mSourceFolders) { // pass both the root folder (the source folder) and the file/folder to process, // in this case the source folder as well. processFile(file, file, processor); } if (mExecutor != null) { mExecutor.waitForTasksWithQuickFail(true /*cancelRemaining*/); } }
public static void setThreadPoolSize(Project project) { if (!project.hasProperty(THREAD_POOL_SIZE_PROPERTY)) { return; } String threadPoolSizeProperty = project.property(THREAD_POOL_SIZE_PROPERTY).toString(); try { ExecutorSingleton.setThreadPoolSize(Integer.parseInt(threadPoolSizeProperty)); } catch (NumberFormatException e) { project.getLogger().error("com.android.threadPoolSize should be an integer."); } } }
mExecutor.execute(new Callable<Void>() { @Override public Void call() throws Exception {
public void search(@NonNull SourceFileProcessor processor) throws ProcessException, LoggedErrorException, InterruptedException, IOException { for (File file : mSourceFolders) { // pass both the root folder (the source folder) and the file/folder to process, // in this case the source folder as well. processFile(file, file, processor); } if (mExecutor != null) { mExecutor.waitForTasksWithQuickFail(true /*cancelRemaining*/); } }
private void processJarFile(File platformJar, final ByteCodeConsumer consumer) throws IOException { try (JarFile jarFile = new JarFile(platformJar)) { for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements(); ) { JarEntry entry = entries.nextElement(); if (!entry.getName().endsWith(".class")) { continue; } try (InputStream inputStream = jarFile.getInputStream(entry)) { final byte[] bytes = ByteStreams.toByteArray(inputStream); mExecutor.execute(new Callable<Void>() { @Override public Void call() throws Exception { consumer.process(bytes); return null; } }); } } } }
/** * Gradle's entry-point into this task. Determines whether or not it's possible to do this task * incrementally and calls either doIncrementalTaskAction() if an incremental build is possible, * and doFullTaskAction() if not. */ @TaskAction void taskAction(IncrementalTaskInputs inputs) throws Exception { initDesugarJar(getProject().getExtensions().findByType(JFXMobileExtension.class).getAndroidExtension().getBuildCache()); if (Files.notExists(inputDir.toPath())) { PathUtils.deleteIfExists(outputDir.toPath()); } else { processSingle(inputDir.toPath(), outputDir.toPath(), Collections.emptySet()); } waitableExecutor.waitForTasksWithQuickFail(true); processNonCachedOnes(getClasspath()); waitableExecutor.waitForTasksWithQuickFail(true); }
private static Consumer<File> createAction( @NonNull Project project, @NonNull WaitableExecutor<Void> executor, @NonNull File input) { return (outputDir) -> executor.execute(() -> { PrepareLibraryTask.extract( input, outputDir, project); return null; }); }
/** * Walks the entire graph, starting from the roots, and increments counters for reachable nodes. */ protected void setCounters(@NonNull final CounterSet counterSet) { Map<T, DependencyType> roots = mGraph.getRoots(counterSet); for (final Map.Entry<T, DependencyType> toIncrementEntry : roots.entrySet()) { mExecutor.execute(new Callable<Void>() { @Override public Void call() throws Exception { incrementCounter( toIncrementEntry.getKey(), toIncrementEntry.getValue(), counterSet); return null; } }); } waitForAllTasks(); }
mExecutor.execute(new Callable<Void>() { Set<T> methods = mGraph.getMethods(klass);
private void processSingle( @NonNull Path input, @NonNull Path output, @NonNull Set<? super QualifiedContent.Scope> scopes) throws Exception { waitableExecutor.execute( () -> { if (output.toString().endsWith(SdkConstants.DOT_JAR)) { Files.createDirectories(output.getParent()); } else { Files.createDirectories(output); } FileCache cacheToUse; if (Files.isRegularFile(input) && Objects.equals( scopes, Collections.singleton(QualifiedContent.Scope.EXTERNAL_LIBRARIES))) { cacheToUse = userCache; } else { cacheToUse = null; } processUsingCache(input, output, cacheToUse); return null; }); }
/** * Sets the roots (i.e. entry points) of the graph and marks all nodes reachable from them. */ private void setCounters(@NonNull ImmutableMap<CounterSet, KeepRules> allKeepRules) { final CounterSet counterSet = CounterSet.SHRINK; final KeepRules keepRules = allKeepRules.get(counterSet); for (final T klass : mGraph.getAllProgramClasses()) { mExecutor.execute(new Callable<Void>() { @Override public Void call() throws Exception { mGraph.addRoots(keepRules.getSymbolsToKeep(klass, mGraph), counterSet); return null; } }); } waitForAllTasks(); setCounters(counterSet); }
private void processFile( @NonNull final File rootFolder, @NonNull final File file, @NonNull final SourceFileProcessor processor) throws ProcessException, IOException { if (file.isFile()) { // get the extension of the file. if (checkExtension(file)) { if (mExecutor != null) { mExecutor.execute(new Callable<Void>() { @Override public Void call() throws Exception { processor.processFile(rootFolder, file); return null; } }); } else { processor.processFile(rootFolder, file); } } } else if (file.isDirectory()) { File[] children = file.listFiles(); if (children != null) { for (File child : children) { processFile(rootFolder, child, processor); } } } }
mExecutor.execute(new Callable<Void>() { @Override public Void call() throws Exception {