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);
}
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);
}
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);
}
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");
}
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.
}
}
Aggregations