Search in sources :

Example 31 with BlazeContext

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;
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) Callable(java.util.concurrent.Callable) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) ProcessHandlerLaunchStatus(com.android.tools.idea.run.util.ProcessHandlerLaunchStatus) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Example 32 with BlazeContext

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();
}
Also used : BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) IDevice(com.android.ddmlib.IDevice) DeviceFutures(com.android.tools.idea.run.DeviceFutures) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) ScopedTask(com.google.idea.blaze.base.scope.ScopedTask) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BlazeApkDeployInfoProtoHelper(com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper) CancellationException(java.util.concurrent.CancellationException) ExecutionException(com.intellij.execution.ExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) File(java.io.File)

Example 33 with BlazeContext

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);
}
Also used : SyncMode(com.google.idea.blaze.base.sync.BlazeSyncParams.SyncMode) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) SdkConstants(com.android.SdkConstants) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) FileCache(com.google.idea.blaze.base.filecache.FileCache) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ImmutableList(com.google.common.collect.ImmutableList) BlazeDataStorage(com.google.idea.blaze.base.sync.data.BlazeDataStorage) Map(java.util.Map) AarLibrary(com.google.idea.blaze.android.sync.model.AarLibrary) Project(com.intellij.openapi.project.Project) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Nullable(javax.annotation.Nullable) BiMap(com.google.common.collect.BiMap) Files(java.nio.file.Files) BlazeLibraryCollector(com.google.idea.blaze.base.sync.libraries.BlazeLibraryCollector) Collection(java.util.Collection) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) IOException(java.io.IOException) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Collectors(java.util.stream.Collectors) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) File(java.io.File) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) HashBiMap(com.google.common.collect.HashBiMap) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) FileCacheSynchronizerTraits(com.google.idea.blaze.base.filecache.FileCacheSynchronizerTraits) Paths(java.nio.file.Paths) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Preconditions(com.google.common.base.Preconditions) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) ZipUtil(com.intellij.util.io.ZipUtil) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) FileCacheSynchronizer(com.google.idea.blaze.base.filecache.FileCacheSynchronizer) AarLibrary(com.google.idea.blaze.android.sync.model.AarLibrary) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) File(java.io.File)

Example 34 with BlazeContext

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);
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BlazeJavaSyncPlugin(com.google.idea.blaze.java.sync.BlazeJavaSyncPlugin) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin)

Example 35 with BlazeContext

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());
}
Also used : BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) JavaLikeLanguage(com.google.idea.blaze.java.sync.source.JavaLikeLanguage) ScalaJavaLikeLanguage(com.google.idea.blaze.scala.sync.source.ScalaJavaLikeLanguage) PackageManifestReader(com.google.idea.blaze.java.sync.source.PackageManifestReader) ScalaJavaLikeLanguage(com.google.idea.blaze.scala.sync.source.ScalaJavaLikeLanguage) SourceArtifact(com.google.idea.blaze.java.sync.source.SourceArtifact) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) MockPrefetchService(com.google.idea.blaze.base.prefetch.MockPrefetchService) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) JavaSourcePackageReader(com.google.idea.blaze.java.sync.source.JavaSourcePackageReader) Nullable(javax.annotation.Nullable)

Aggregations

BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)42 ImmutableList (com.google.common.collect.ImmutableList)18 Nullable (javax.annotation.Nullable)18 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)17 List (java.util.List)16 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)15 Project (com.intellij.openapi.project.Project)15 File (java.io.File)15 Set (java.util.Set)15 Lists (com.google.common.collect.Lists)13 BlazeSyncPlugin (com.google.idea.blaze.base.sync.BlazeSyncPlugin)12 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)12 Logger (com.intellij.openapi.diagnostic.Logger)12 Collection (java.util.Collection)12 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)11 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)10 Map (java.util.Map)10 ImmutableSet (com.google.common.collect.ImmutableSet)9 BlazeCommand (com.google.idea.blaze.base.command.BlazeCommand)9 Collectors (java.util.stream.Collectors)9