use of com.google.idea.blaze.base.scope.BlazeContext 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;
}
use of com.google.idea.blaze.base.scope.BlazeContext in project intellij by bazelbuild.
the class BlazeApkBuildStepMobileInstall method build.
@Override
public boolean build(BlazeContext context, BlazeAndroidDeviceSelector.DeviceSession deviceSession) {
ScopedTask<Void> buildTask = new ScopedTask<Void>(context) {
@Override
protected Void execute(BlazeContext context) {
DeviceFutures deviceFutures = deviceSession.deviceFutures;
assert deviceFutures != null;
IDevice device = resolveDevice(context, deviceFutures);
if (device == null) {
return null;
}
BlazeCommand.Builder command = BlazeCommand.builder(Blaze.getBuildSystemProvider(project).getBinaryPath(), BlazeCommandName.MOBILE_INSTALL);
command.addBlazeFlags(BlazeFlags.DEVICE, device.getSerialNumber());
// Redundant, but we need this to get around bug in bazel.
// https://github.com/bazelbuild/bazel/issues/4922
command.addBlazeFlags(BlazeFlags.ADB_ARG + "-s ", BlazeFlags.ADB_ARG + device.getSerialNumber());
if (USE_SDK_ADB.getValue()) {
File adb = AndroidSdkUtils.getAdb(project);
if (adb != null) {
command.addBlazeFlags(BlazeFlags.ADB, adb.toString());
}
}
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
BlazeApkDeployInfoProtoHelper deployInfoHelper = new BlazeApkDeployInfoProtoHelper(project, blazeFlags);
BuildResultHelper buildResultHelper = deployInfoHelper.getBuildResultHelper();
command.addTargets(label).addBlazeFlags(blazeFlags).addBlazeFlags(buildResultHelper.getBuildFlags()).addBlazeFlags("--output_groups=android_deploy_info").addExeFlags(exeFlags);
SaveUtil.saveAllFiles();
int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
FileCaches.refresh(project);
if (retVal != 0) {
context.setHasError();
return null;
}
deployInfo = deployInfoHelper.readDeployInfo(context);
if (deployInfo == null) {
IssueOutput.error("Could not read apk deploy info from build").submit(context);
}
return null;
}
};
ListenableFuture<Void> buildFuture = ProgressiveTaskWithProgressIndicator.builder(project).setTitle(String.format("Executing %s apk build", Blaze.buildSystemName(project))).submitTaskWithResult(buildTask);
try {
Futures.get(buildFuture, ExecutionException.class);
} catch (ExecutionException e) {
context.setHasError();
} catch (CancellationException e) {
context.setCancelled();
}
return context.shouldContinue();
}
use of com.google.idea.blaze.base.scope.BlazeContext in project intellij by bazelbuild.
the class UnpackedAars method onSync.
void onSync(BlazeContext context, ProjectViewSet projectViewSet, BlazeProjectData projectData, BlazeSyncParams.SyncMode syncMode) {
Collection<BlazeLibrary> libraries = BlazeLibraryCollector.getLibraries(projectViewSet, projectData);
boolean fullRefresh = syncMode == SyncMode.FULL;
boolean removeMissingFiles = syncMode == SyncMode.INCREMENTAL;
if (!enabled || fullRefresh) {
clearCache();
}
if (!enabled) {
return;
}
List<AarLibrary> aarLibraries = libraries.stream().filter(library -> library instanceof AarLibrary).map(library -> (AarLibrary) library).collect(Collectors.toList());
ArtifactLocationDecoder artifactLocationDecoder = projectData.artifactLocationDecoder;
BiMap<File, String> sourceAarFileToCacheKey = HashBiMap.create(aarLibraries.size());
BiMap<File, String> sourceJarFileToCacheKey = HashBiMap.create(aarLibraries.size());
for (AarLibrary library : aarLibraries) {
File aarFile = artifactLocationDecoder.decode(library.aarArtifact);
String cacheKey = cacheKeyForAar(aarFile);
sourceAarFileToCacheKey.put(aarFile, cacheKey);
File jarFile = artifactLocationDecoder.decode(library.libraryArtifact.jarForIntellijLibrary());
// Use the aar key for the jar as well.
sourceJarFileToCacheKey.put(jarFile, cacheKey);
}
this.aarTraits = new AarTraits(cacheDir, sourceAarFileToCacheKey);
this.jarTraits = new JarTraits(cacheDir, sourceJarFileToCacheKey);
refresh(context, removeMissingFiles);
}
use of com.google.idea.blaze.base.scope.BlazeContext in project intellij by bazelbuild.
the class BlazeScalaSyncPluginTest method initTest.
@Override
protected void initTest(@NotNull Container applicationServices, @NotNull Container projectServices) {
super.initTest(applicationServices, projectServices);
ExtensionPointImpl<BlazeSyncPlugin> syncPlugins = registerExtensionPoint(BlazeSyncPlugin.EP_NAME, BlazeSyncPlugin.class);
syncPlugins.registerExtension(new BlazeJavaSyncPlugin());
syncPlugins.registerExtension(new BlazeScalaSyncPlugin());
context = new BlazeContext();
context.addOutputSink(IssueOutput.class, errorCollector);
}
use of com.google.idea.blaze.base.scope.BlazeContext in project intellij by bazelbuild.
the class BlazeScalaWorkspaceImporterTest method initTest.
@Override
// False positive on getDeclaredPackageOfJavaFile.
@SuppressWarnings("FunctionalInterfaceClash")
protected void initTest(@NotNull Container applicationServices, @NotNull Container projectServices) {
super.initTest(applicationServices, projectServices);
context = new BlazeContext();
context.addOutputSink(IssueOutput.class, errorCollector);
registerExtensionPoint(BlazeJavaSyncAugmenter.EP_NAME, BlazeJavaSyncAugmenter.class);
BlazeImportSettingsManager importSettingsManager = new BlazeImportSettingsManager();
importSettingsManager.setImportSettings(new BlazeImportSettings("", "", "", "", BuildSystem.Blaze));
projectServices.register(BlazeImportSettingsManager.class, importSettingsManager);
applicationServices.register(PrefetchService.class, new MockPrefetchService());
applicationServices.register(PackageManifestReader.class, new PackageManifestReader());
// 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;
}
});
ExtensionPoint<JavaLikeLanguage> javaLikeLanguages = registerExtensionPoint(JavaLikeLanguage.EP_NAME, JavaLikeLanguage.class);
javaLikeLanguages.registerExtension(new JavaLikeLanguage.Java());
javaLikeLanguages.registerExtension(new ScalaJavaLikeLanguage());
}
Aggregations