use of com.google.idea.blaze.base.async.executor.BlazeExecutor in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method initTest.
@Override
protected void initTest(Container applicationServices, Container projectServices) {
MockExperimentService mockExperimentService = new MockExperimentService();
applicationServices.register(ExperimentService.class, mockExperimentService);
BlazeExecutor blazeExecutor = new MockBlazeExecutor();
applicationServices.register(BlazeExecutor.class, blazeExecutor);
projectServices.register(BlazeImportSettingsManager.class, new BlazeImportSettingsManager());
BlazeImportSettingsManager.getInstance(getProject()).setImportSettings(DUMMY_IMPORT_SETTINGS);
MockFileOperationProvider mockFileOperationProvider = new MockFileOperationProvider();
applicationServices.register(FileOperationProvider.class, mockFileOperationProvider);
context = new BlazeContext();
context.addOutputSink(IssueOutput.class, errorCollector);
registerExtensionPoint(BlazeJavaSyncAugmenter.EP_NAME, BlazeJavaSyncAugmenter.class);
// For importJavaWorkspace.
applicationServices.register(JavaSourcePackageReader.class, new JavaSourcePackageReader() {
@Nullable
@Override
public String getDeclaredPackageOfJavaFile(BlazeContext context, ArtifactLocationDecoder artifactLocationDecoder, SourceArtifact sourceArtifact) {
return null;
}
});
applicationServices.register(PackageManifestReader.class, new PackageManifestReader());
applicationServices.register(PrefetchService.class, new MockPrefetchService());
registerExtensionPoint(JavaLikeLanguage.EP_NAME, JavaLikeLanguage.class).registerExtension(new JavaLikeLanguage.Java());
}
use of com.google.idea.blaze.base.async.executor.BlazeExecutor in project intellij by bazelbuild.
the class BuildFileFormatter method formatTextWithTimeout.
/**
* Format the BUILD file with a timeout. The tool may be fetched from a network filesystem, and we
* don't want to block the UI if there is a network issue.
*
* @return formatted text, or null if there is an error or timeout
*/
@Nullable
static String formatTextWithTimeout(String text) {
BlazeExecutor executor = BlazeExecutor.getInstance();
ListenableFuture<String> result = executor.submit(() -> formatText(text));
try {
return result.get(TIMEOUT_SECS, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
result.cancel(true);
return null;
} catch (ExecutionException | TimeoutException e) {
logger.warn(e);
result.cancel(true);
return null;
}
}
use of com.google.idea.blaze.base.async.executor.BlazeExecutor in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporterTest method initTest.
@Override
// False positive on getDeclaredPackageOfJavaFile.
@SuppressWarnings("FunctionalInterfaceClash")
protected void initTest(Container applicationServices, Container projectServices) {
applicationServices.register(ExperimentService.class, new MockExperimentService());
BlazeExecutor blazeExecutor = new MockBlazeExecutor();
applicationServices.register(BlazeExecutor.class, blazeExecutor);
projectServices.register(BlazeImportSettingsManager.class, new BlazeImportSettingsManager());
BlazeImportSettingsManager.getInstance(getProject()).setImportSettings(DUMMY_IMPORT_SETTINGS);
// will silently fall back to FilePathJavaPackageReader
applicationServices.register(JavaSourcePackageReader.class, new JavaSourcePackageReader() {
@Nullable
@Override
public String getDeclaredPackageOfJavaFile(BlazeContext context, ArtifactLocationDecoder artifactLocationDecoder, SourceArtifact sourceArtifact) {
return null;
}
});
applicationServices.register(PackageManifestReader.class, new PackageManifestReader());
applicationServices.register(PrefetchService.class, new MockPrefetchService());
context = new BlazeContext();
context.addOutputSink(IssueOutput.class, errorCollector);
augmenters = registerExtensionPoint(BlazeJavaSyncAugmenter.EP_NAME, BlazeJavaSyncAugmenter.class);
registerExtensionPoint(JavaLikeLanguage.EP_NAME, JavaLikeLanguage.class).registerExtension(new JavaLikeLanguage.Java());
}
use of com.google.idea.blaze.base.async.executor.BlazeExecutor in project intellij by bazelbuild.
the class SourceDirectoryCalculatorTest method initTest.
@Override
protected void initTest(Container applicationServices, Container projectServices) {
super.initTest(applicationServices, projectServices);
mockInputStreamProvider = new MockInputStreamProvider();
applicationServices.register(InputStreamProvider.class, mockInputStreamProvider);
applicationServices.register(JavaSourcePackageReader.class, new JavaSourcePackageReader());
applicationServices.register(PackageManifestReader.class, new PackageManifestReader());
applicationServices.register(FileOperationProvider.class, new MockFileOperationProvider());
context.addOutputSink(IssueOutput.class, issues);
sourceDirectoryCalculator = new SourceDirectoryCalculator();
BlazeExecutor blazeExecutor = new MockBlazeExecutor();
applicationServices.register(BlazeExecutor.class, blazeExecutor);
experimentService = new MockExperimentService();
applicationServices.register(ExperimentService.class, experimentService);
applicationServices.register(PrefetchService.class, new MockPrefetchService());
registerExtensionPoint(JavaLikeLanguage.EP_NAME, JavaLikeLanguage.class).registerExtension(new JavaLikeLanguage.Java());
}
use of com.google.idea.blaze.base.async.executor.BlazeExecutor in project intellij by bazelbuild.
the class BlazeAndroidTestLaunchTask method perform.
@Override
public boolean perform(@NotNull IDevice device, @NotNull LaunchStatus launchStatus, @NotNull ConsolePrinter printer) {
BlazeExecutor executor = BlazeExecutor.getInstance();
ProcessHandlerLaunchStatus processHandlerLaunchStatus = (ProcessHandlerLaunchStatus) launchStatus;
final ProcessHandler processHandler = processHandlerLaunchStatus.getProcessHandler();
blazeResult = executor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return Scope.root(new ScopedFunction<Boolean>() {
@Override
public Boolean execute(@NotNull BlazeContext context) {
ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
if (projectViewSet == null) {
IssueOutput.error("Could not load project view. Please resync project.").submit(context);
return false;
}
BlazeCommand.Builder commandBuilder = BlazeCommand.builder(Blaze.getBuildSystemProvider(project).getBinaryPath(), BlazeCommandName.TEST).addTargets(target);
// Build flags must match BlazeBeforeRunTask.
commandBuilder.addBlazeFlags(buildFlags);
// Run the test on the selected local device/emulator.
commandBuilder.addBlazeFlags(TEST_LOCAL_DEVICE, BlazeFlags.TEST_OUTPUT_STREAMED).addBlazeFlags(testDeviceSerialFlags(device.getSerialNumber())).addBlazeFlags(testFilter.getBlazeFlags());
if (debug) {
commandBuilder.addBlazeFlags(TEST_DEBUG, BlazeFlags.NO_CACHE_TEST_RESULTS);
}
BlazeCommand command = commandBuilder.build();
printer.stdout(String.format("Starting %s test...\n", Blaze.buildSystemName(project)));
printer.stdout(command + "\n");
LineProcessingOutputStream.LineProcessor stdoutLineProcessor = line -> {
printer.stdout(line);
return true;
};
LineProcessingOutputStream.LineProcessor stderrLineProcessor = line -> {
printer.stderr(line);
return true;
};
SaveUtil.saveAllFiles();
int retVal = ExternalTask.builder(WorkspaceRoot.fromProject(project)).addBlazeCommand(command).context(context).stdout(LineProcessingOutputStream.of(stdoutLineProcessor)).stderr(LineProcessingOutputStream.of(stderrLineProcessor)).build().run();
FileCaches.refresh(project);
if (retVal != 0) {
context.setHasError();
}
return !context.hasErrors();
}
});
}
});
blazeResult.addListener(runContext::onLaunchTaskComplete, PooledThreadExecutor.INSTANCE);
// The debug case is set up in ConnectBlazeTestDebuggerTask
if (!debug) {
waitAndSetUpForKillingBlazeOnStop(processHandler, launchStatus);
}
return true;
}
Aggregations