Search in sources :

Example 1 with ParsedManifest

use of com.google.idea.blaze.android.manifest.ManifestParser.ParsedManifest in project intellij by bazelbuild.

the class BlazeApkDeployInfoProtoHelper method extractDeployInfoAndInvalidateManifests.

public BlazeAndroidDeployInfo extractDeployInfoAndInvalidateManifests(Project project, File executionRoot, AndroidDeployInfo deployInfoProto) throws GetDeployInfoException {
    File mergedManifestFile = new File(executionRoot, deployInfoProto.getMergedManifest().getExecRootPath());
    ParsedManifest mergedManifest = getParsedManifestSafe(project, mergedManifestFile);
    ParsedManifestService.getInstance(project).invalidateCachedManifest(mergedManifestFile);
    // android_test targets uses additional merged manifests field of the deploy info proto to hold
    // the manifest of the test target APK.
    ParsedManifest testTargetMergedManifest = null;
    List<Artifact> additionalManifests = deployInfoProto.getAdditionalMergedManifestsList();
    if (additionalManifests.size() == 1) {
        File testTargetMergedManifestFile = new File(executionRoot, additionalManifests.get(0).getExecRootPath());
        testTargetMergedManifest = getParsedManifestSafe(project, testTargetMergedManifestFile);
        ParsedManifestService.getInstance(project).invalidateCachedManifest(testTargetMergedManifestFile);
    }
    ImmutableList<File> apksToDeploy = deployInfoProto.getApksToDeployList().stream().map(artifact -> new File(executionRoot, artifact.getExecRootPath())).collect(ImmutableList.toImmutableList());
    return new BlazeAndroidDeployInfo(mergedManifest, testTargetMergedManifest, apksToDeploy);
}
Also used : Predicate(java.util.function.Predicate) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) GetArtifactsException(com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException) ParsedBepOutput(com.google.idea.blaze.base.command.buildresult.ParsedBepOutput) Collectors(java.util.stream.Collectors) File(java.io.File) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) OutputArtifact(com.google.idea.blaze.base.command.buildresult.OutputArtifact) ParsedManifest(com.google.idea.blaze.android.manifest.ManifestParser.ParsedManifest) List(java.util.List) Stream(java.util.stream.Stream) ImmutableList(com.google.common.collect.ImmutableList) ParsedManifestService(com.google.idea.blaze.android.manifest.ParsedManifestService) Label(com.google.idea.blaze.base.model.primitives.Label) AndroidDeployInfo(com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo) Project(com.intellij.openapi.project.Project) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Logger(com.intellij.openapi.diagnostic.Logger) Artifact(com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.Artifact) InputStream(java.io.InputStream) ParsedManifest(com.google.idea.blaze.android.manifest.ManifestParser.ParsedManifest) File(java.io.File) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) OutputArtifact(com.google.idea.blaze.base.command.buildresult.OutputArtifact) Artifact(com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.Artifact)

Example 2 with ParsedManifest

use of com.google.idea.blaze.android.manifest.ManifestParser.ParsedManifest in project intellij by bazelbuild.

the class BlazeApkDeployInfoProtoHelperTest method readDeployInfoForNormalBuild_onlyMainManifest.

@Test
public void readDeployInfoForNormalBuild_onlyMainManifest() throws Exception {
    // setup
    AndroidDeployInfo deployInfoProto = AndroidDeployInfo.newBuilder().setMergedManifest(makeArtifact("path/to/manifest")).addApksToDeploy(makeArtifact("path/to/apk")).build();
    File mainApk = new File("execution_root/path/to/apk");
    File mainManifestFile = new File("execution_root/path/to/manifest");
    ParsedManifest parsedMainManifest = new ParsedManifest("main", null, null);
    when(mockParsedManifestService.getParsedManifest(mainManifestFile)).thenReturn(parsedMainManifest);
    // perform
    BlazeAndroidDeployInfo deployInfo = new BlazeApkDeployInfoProtoHelper().extractDeployInfoAndInvalidateManifests(getProject(), new File("execution_root"), deployInfoProto);
    // verify
    assertThat(deployInfo.getApksToDeploy()).containsExactly(mainApk);
    assertThat(deployInfo.getMergedManifest()).isEqualTo(parsedMainManifest);
    assertThat(deployInfo.getTestTargetMergedManifest()).isNull();
    verify(mockParsedManifestService, times(1)).invalidateCachedManifest(mainManifestFile);
}
Also used : AndroidDeployInfo(com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo) ParsedManifest(com.google.idea.blaze.android.manifest.ManifestParser.ParsedManifest) File(java.io.File) Test(org.junit.Test)

Example 3 with ParsedManifest

use of com.google.idea.blaze.android.manifest.ManifestParser.ParsedManifest in project intellij by bazelbuild.

the class BlazeApkDeployInfoProtoHelper method extractInstrumentationTestDeployInfoAndInvalidateManifests.

public BlazeAndroidDeployInfo extractInstrumentationTestDeployInfoAndInvalidateManifests(Project project, File executionRoot, AndroidDeployInfo instrumentorProto, AndroidDeployInfo appProto) throws GetDeployInfoException {
    File instrumentorManifest = new File(executionRoot, instrumentorProto.getMergedManifest().getExecRootPath());
    ParsedManifest parsedInstrumentorManifest = getParsedManifestSafe(project, instrumentorManifest);
    ParsedManifestService.getInstance(project).invalidateCachedManifest(instrumentorManifest);
    File appManifest = new File(executionRoot, appProto.getMergedManifest().getExecRootPath());
    ParsedManifest parsedAppManifest = getParsedManifestSafe(project, appManifest);
    ParsedManifestService.getInstance(project).invalidateCachedManifest(appManifest);
    ImmutableList<File> apksToDeploy = Stream.concat(instrumentorProto.getApksToDeployList().stream(), appProto.getApksToDeployList().stream()).map(artifact -> new File(executionRoot, artifact.getExecRootPath())).collect(ImmutableList.toImmutableList());
    return new BlazeAndroidDeployInfo(parsedInstrumentorManifest, parsedAppManifest, apksToDeploy);
}
Also used : Predicate(java.util.function.Predicate) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) GetArtifactsException(com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException) ParsedBepOutput(com.google.idea.blaze.base.command.buildresult.ParsedBepOutput) Collectors(java.util.stream.Collectors) File(java.io.File) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) OutputArtifact(com.google.idea.blaze.base.command.buildresult.OutputArtifact) ParsedManifest(com.google.idea.blaze.android.manifest.ManifestParser.ParsedManifest) List(java.util.List) Stream(java.util.stream.Stream) ImmutableList(com.google.common.collect.ImmutableList) ParsedManifestService(com.google.idea.blaze.android.manifest.ParsedManifestService) Label(com.google.idea.blaze.base.model.primitives.Label) AndroidDeployInfo(com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo) Project(com.intellij.openapi.project.Project) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Logger(com.intellij.openapi.diagnostic.Logger) Artifact(com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.Artifact) InputStream(java.io.InputStream) ParsedManifest(com.google.idea.blaze.android.manifest.ManifestParser.ParsedManifest) File(java.io.File)

Example 4 with ParsedManifest

use of com.google.idea.blaze.android.manifest.ManifestParser.ParsedManifest in project intellij by bazelbuild.

the class BlazeAndroidBinaryApplicationIdProviderTest method getApplicationId.

@Test
public void getApplicationId() throws Exception {
    ParsedManifest manifest = new ParsedManifest("package.name", ImmutableList.of(), null);
    BlazeAndroidDeployInfo deployInfo = new BlazeAndroidDeployInfo(manifest, null, ImmutableList.of());
    ApkBuildStep mockBuildStep = mock(ApkBuildStep.class);
    when(mockBuildStep.getDeployInfo()).thenReturn(deployInfo);
    BlazeAndroidBinaryApplicationIdProvider provider = new BlazeAndroidBinaryApplicationIdProvider(mockBuildStep);
    assertThat(provider.getPackageName()).isEqualTo("package.name");
}
Also used : ParsedManifest(com.google.idea.blaze.android.manifest.ManifestParser.ParsedManifest) ApkBuildStep(com.google.idea.blaze.android.run.runner.ApkBuildStep) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) Test(org.junit.Test)

Example 5 with ParsedManifest

use of com.google.idea.blaze.android.manifest.ManifestParser.ParsedManifest in project intellij by bazelbuild.

the class BlazeAndroidBinaryApplicationIdProviderTest method getApplicationId_noPackageNameInMergedManifest.

@Test
public void getApplicationId_noPackageNameInMergedManifest() throws Exception {
    ParsedManifest manifest = new ParsedManifest(null, ImmutableList.of(), null);
    BlazeAndroidDeployInfo deployInfo = new BlazeAndroidDeployInfo(manifest, null, ImmutableList.of());
    ApkBuildStep mockBuildStep = mock(ApkBuildStep.class);
    when(mockBuildStep.getDeployInfo()).thenReturn(deployInfo);
    BlazeAndroidBinaryApplicationIdProvider provider = new BlazeAndroidBinaryApplicationIdProvider(mockBuildStep);
    try {
        provider.getPackageName();
        fail();
    } catch (ApkProvisionException ex) {
    // An exception should be thrown if the package name is not available because it's a
    // serious error and should not fail silently.
    }
}
Also used : ParsedManifest(com.google.idea.blaze.android.manifest.ManifestParser.ParsedManifest) ApkBuildStep(com.google.idea.blaze.android.run.runner.ApkBuildStep) ApkProvisionException(com.android.tools.idea.run.ApkProvisionException) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) Test(org.junit.Test)

Aggregations

ParsedManifest (com.google.idea.blaze.android.manifest.ManifestParser.ParsedManifest)6 AndroidDeployInfo (com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo)4 File (java.io.File)4 Test (org.junit.Test)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableList (com.google.common.collect.ImmutableList)2 Artifact (com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.Artifact)2 ParsedManifestService (com.google.idea.blaze.android.manifest.ParsedManifestService)2 BlazeAndroidDeployInfo (com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo)2 ApkBuildStep (com.google.idea.blaze.android.run.runner.ApkBuildStep)2 BlazeArtifact (com.google.idea.blaze.base.command.buildresult.BlazeArtifact)2 BuildResultHelper (com.google.idea.blaze.base.command.buildresult.BuildResultHelper)2 GetArtifactsException (com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException)2 OutputArtifact (com.google.idea.blaze.base.command.buildresult.OutputArtifact)2 ParsedBepOutput (com.google.idea.blaze.base.command.buildresult.ParsedBepOutput)2 Label (com.google.idea.blaze.base.model.primitives.Label)2 Logger (com.intellij.openapi.diagnostic.Logger)2 Project (com.intellij.openapi.project.Project)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2