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; } }); } } } }
protected void waitForAllTasks() { try { mExecutor.waitForTasksWithQuickFail(true); } catch (InterruptedException | LoggedErrorException e) { throw new RuntimeException(e); } }
public void setUseExecutor(boolean useExecutor) { if (useExecutor) { mExecutor = new WaitableExecutor<Void>(); } else { mExecutor = null; } }
searcher.search(fileGatherer); WaitableExecutor<Void> mExecutor = WaitableExecutor.useGlobalSharedThreadPool(); mExecutor.execute(new Callable<Void>() { @Override public Void call() throws Exception { mExecutor.waitForTasksWithQuickFail(true /*cancelRemaining*/);
searcher.search(fileGatherer); WaitableExecutor<Void> mExecutor = new WaitableExecutor<Void>(); mExecutor.execute(new Callable<Void>() { @Override public Void call() throws Exception { mExecutor.waitForTasksWithQuickFail(true /*cancelRemaining*/);
executor.execute(() -> generateSplitApk(split)); } catch (Exception e) { throw new RuntimeException(e); executor.waitForTasksWithQuickFail(true /* cancelRemaining */); } catch (LoggedErrorException e) { logger.error("Exception while generating split APKs " + e.getMessage());
@NonNull ILogger logger) throws TestException, NoAuthorizedDeviceFoundException, InterruptedException { WaitableExecutor<Boolean> executor = new WaitableExecutor<Boolean>(maxThreads); executor.execute(new SimpleTestCallable(device, projectName, variantName, testApk, testedApks, mAdbExec, testData, resultsDir, coverageDir, timeoutInMs, installOptions, logger)); List<WaitableExecutor.TaskResult<Boolean>> results = executor.waitForAllTasks();
threadPoolSize = deviceList.size(); WaitableExecutor<Boolean> executor = WaitableExecutor.useNewFixedSizeThreadPool(threadPoolSize); testData, resultsDir, coverageDir, timeoutInMs, logger, shardProvider); shardedTestCallable.setProgressListener(progressListener); executor.execute(shardedTestCallable); testData, resultsDir, coverageDir, timeoutInMs, installOptions, logger); executor.execute(testCallable); List<WaitableExecutor.TaskResult<Boolean>> results = executor.waitForAllTasks();
public static void extractAarInParallel( @NonNull Project project, @NonNull GradleVariantConfiguration config, @NonNull Optional<FileCache> buildCache) throws LoggedErrorException, InterruptedException, IOException { WaitableExecutor<Void> executor = WaitableExecutor.useGlobalSharedThreadPool(); Set<AndroidDependency> dependencies = Sets.newHashSet(config.getFlatCompileAndroidLibraries()); dependencies.addAll(config.getFlatPackageAndroidLibraries()); for (AndroidDependency androidDependency :dependencies) { if (androidDependency.getProjectPath() != null) { // Don't need to explode sub-module library. continue; } File input = androidDependency.getArtifactFile(); File output = androidDependency.getExtractedFolder(); boolean useBuildCache = PrepareLibraryTask.shouldUseBuildCache(buildCache.isPresent(), androidDependency.getCoordinates()); PrepareLibraryTask.prepareLibrary( input, output, buildCache.isPresent() ? buildCache.get() : null, createAction(project, executor, input), project.getLogger(), useBuildCache); } executor.waitForTasksWithQuickFail(false); }
private void processNonCachedOnes(List<Path> classpath) throws IOException, ProcessException { int parallelExecutions = waitableExecutor.getParallelism(); waitableExecutor.execute(callable);
public void setUseExecutor(boolean useExecutor) { if (useExecutor) { mExecutor = WaitableExecutor.useGlobalSharedThreadPool(); } else { mExecutor = null; } }
WaitableExecutor<Void> executor = WaitableExecutor.useGlobalSharedThreadPool(); executor.execute(new Callable<Void>() { @Override public Void call() throws Exception { if (impactedData != null) { for (final DependencyData data: impactedData) { executor.execute(new Callable<Void>() { @Override public Void call() throws Exception { final DependencyData data2 = mainFileMap.get(entry.getKey().getAbsolutePath()); if (data2 != null) { executor.execute(new Callable<Void>() { @Override public Void call() throws Exception { executor.waitForTasksWithQuickFail(true /*cancelRemaining*/); } catch (Throwable t) { FileUtils.delete(incrementalData);
final WaitableExecutor<Void> executor = new WaitableExecutor<Void>(); final List<File> inputFileDetails = Lists.newArrayList(); executor.execute(action); executor.waitForTasksWithQuickFail(false);
private void incrementalRun( @NonNull Collection<TransformInput> inputs, @NonNull Collection<TransformInput> referencedInputs, @NonNull TransformOutputProvider output) throws IOException { try { Stopwatch stopwatch = Stopwatch.createStarted(); JavaSerializationShrinkerGraph graph = JavaSerializationShrinkerGraph.readFromDir( incrementalDir, this.getClass().getClassLoader()); logTime("loading state", stopwatch); ProguardConfig config = getConfig(); ShrinkerLogger shrinkerLogger = new ShrinkerLogger(config.getFlags().getDontWarnSpecs(), logger); IncrementalShrinker<String> shrinker = new IncrementalShrinker<>( WaitableExecutor.<Void>useGlobalSharedThreadPool(), graph, shrinkerLogger); shrinker.incrementalRun(inputs, output); checkForWarnings(config, shrinkerLogger); } catch (IncrementalShrinker.IncrementalRunImpossibleException e) { logger.warn("Incremental shrinker run impossible: " + e.getMessage()); // Log the full stack trace at INFO level for debugging. logger.info("Incremental shrinker run impossible: " + e.getMessage(), e); fullRun(inputs, referencedInputs, output); } }
WaitableExecutor<Void> executor = WaitableExecutor.useGlobalSharedThreadPool(); executor.execute(() -> { extractJar(outJarFolder, jarFile, extractCode); return null; switch (jarInput.getStatus()) { case CHANGED: executor.execute(() -> { FileUtils.cleanOutputDir(outJarFolder); extractJar(outJarFolder, jarFile, extractCode); break; case ADDED: executor.execute(() -> { extractJar(outJarFolder, jarFile, extractCode); return null; break; case REMOVED: executor.execute( () -> { FileUtils.cleanOutputDir(outJarFolder); executor.waitForTasksWithQuickFail(true);
private void handleInterfaceInheritance(@NonNull Set<T> interfaceInheritance) { for (final T klass : interfaceInheritance) { 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 fullRun( @NonNull Collection<TransformInput> inputs, @NonNull Collection<TransformInput> referencedInputs, @NonNull TransformOutputProvider output) throws IOException { ProguardConfig config = getConfig(); ShrinkerLogger shrinkerLogger = new ShrinkerLogger(config.getFlags().getDontWarnSpecs(), logger); FullRunShrinker<String> shrinker = new FullRunShrinker<>( WaitableExecutor.<Void>useGlobalSharedThreadPool(), JavaSerializationShrinkerGraph.empty(incrementalDir), platformJars, shrinkerLogger); // Only save state if incremental mode is enabled. boolean saveState = this.isIncremental(); shrinker.run( inputs, referencedInputs, output, ImmutableMap.<CounterSet, KeepRules>of( CounterSet.SHRINK, new ProguardFlagsKeepRules(config.getFlags(), shrinkerLogger)), saveState); checkForWarnings(config, shrinkerLogger); }
"externalLibJarFiles %s: ", Joiner.on(",").join(externalLibJarFiles)); WaitableExecutor<Void> executor = WaitableExecutor.useGlobalSharedThreadPool(); : Optional.empty()); logger.verbose("Adding PreDexTask for %s : %s", entry.getKey(), action); executor.execute(action); executor.execute(() -> { FileUtils.deletePath(file); return null; executor.waitForTasksWithQuickFail(false); logger.verbose("Done with all dexing");
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; }); }