use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method testAarImport_inSourcesAndNoJdeps_keepsAarLibrary.
@Test
public void testAarImport_inSourcesAndNoJdeps_keepsAarLibrary() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/example")))).build();
TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/example:lib").setBuildFile(source("java/example/BUILD")).setKind(Kind.ANDROID_LIBRARY).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/example/AndroidManifest.xml")).addResource(source("java/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.example")).setJavaInfo(JavaIdeInfo.builder()).addSource(source("java/example/Source.java")).addDependency("//java/example:an_aar").build()).addTarget(TargetIdeInfo.builder().setLabel("//java/example:an_aar").setBuildFile(source("java/example/BUILD")).setKind(Kind.AAR_IMPORT).setAndroidAarInfo(new AndroidAarIdeInfo(source("java/example/an_aar.aar"))).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setClassJar(gen("java/example/_aar/an_aar/" + "classes_and_libs_merged.jar")))).build());
BlazeJavaImportResult javaResult = importJavaWorkspace(workspaceRoot, targetMapBuilder, projectView);
BlazeAndroidImportResult androidResult = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
errorCollector.assertNoIssues();
assertThat(javaResult.libraries).isEmpty();
assertThat(androidResult.aarLibraries.stream().map(BlazeAndroidWorkspaceImporterTest::aarName).collect(Collectors.toList())).containsExactly("an_aar.aar");
}
use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method testMixingGeneratedAndNonGeneratedSourcesGeneratesIssue.
@Test
public void testMixingGeneratedAndNonGeneratedSourcesGeneratesIssue() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/example")))).build();
TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/example:lib").setBuildFile(source("java/example/BUILD")).setKind("android_library").setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/example/AndroidManifest.xml")).addResource(source("java/example/res")).addResource(gen("java/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.example")).build());
importWorkspace(workspaceRoot, targetMapBuilder, projectView);
errorCollector.assertIssueContaining("Dropping 1 generated resource");
}
use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method testAarImport_inSources_createsAarLibrary.
@Test
public void testAarImport_inSources_createsAarLibrary() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/example")))).build();
TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/example:lib").setBuildFile(source("java/example/BUILD")).setKind(Kind.ANDROID_LIBRARY).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/example/AndroidManifest.xml")).addResource(source("java/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.example")).setJavaInfo(JavaIdeInfo.builder()).addSource(source("java/example/Source.java")).addDependency("//java/example:an_aar").build()).addTarget(TargetIdeInfo.builder().setLabel("//java/example:an_aar").setBuildFile(source("java/example/BUILD")).setKind(Kind.AAR_IMPORT).setAndroidAarInfo(new AndroidAarIdeInfo(source("java/example/an_aar.aar"))).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setClassJar(gen("java/example/_aar/an_aar/" + "classes_and_libs_merged.jar")))).build());
jdepsMap.put(TargetKey.forPlainTarget(Label.create("//java/example:lib")), ImmutableList.of(jdepsPath("java/example/_aar/an_aar/classes_and_libs_merged.jar")));
BlazeJavaImportResult javaResult = importJavaWorkspace(workspaceRoot, targetMapBuilder, projectView);
BlazeAndroidImportResult androidResult = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
errorCollector.assertNoIssues();
assertThat(androidResult.aarLibraries.stream().map(BlazeAndroidWorkspaceImporterTest::aarJarName).collect(Collectors.toList())).containsExactly("classes_and_libs_merged.jar");
assertThat(androidResult.aarLibraries.stream().map(BlazeAndroidWorkspaceImporterTest::aarName).collect(Collectors.toList())).containsExactly("an_aar.aar");
assertThat(javaResult.libraries).hasSize(1);
BlazeAndroidLibrarySource.AarJarFilter aarFilter = new BlazeAndroidLibrarySource.AarJarFilter(androidResult.aarLibraries);
assertThat(aarFilter.test(javaResult.libraries.values().asList().get(0))).isFalse();
}
use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeEditProjectViewControl method updateBuilder.
public void updateBuilder(BlazeNewProjectBuilder builder) {
String projectName = projectNameField.getText().trim();
File projectDataDirectoryFile = new File(projectDataDirField.getText().trim());
if (workspaceOption.allowProjectDataInVcs()) {
projectDataDirectoryFile = new File(projectDataDirectoryFile, BlazeDataStorage.PROJECT_DATA_SUBDIRECTORY);
}
String projectDataDirectory = projectDataDirectoryFile.getPath();
File localProjectViewFile = ProjectViewStorageManager.getLocalProjectViewFileName(builder.getBuildSystem(), new File(projectDataDirectory));
BlazeSelectProjectViewOption selectProjectViewOption = builder.getProjectViewOption();
boolean useSharedProjectView = projectViewUi.getUseSharedProjectView();
// If we're using a shared project view, synthesize a local one that imports the shared one
ProjectViewSet parseResult = projectViewUi.parseProjectView(Lists.newArrayList());
final ProjectView projectView;
final ProjectViewSet projectViewSet;
if (useSharedProjectView && selectProjectViewOption.getSharedProjectView() != null) {
projectView = ProjectView.builder().add(ScalarSection.builder(ImportSection.KEY).set(selectProjectViewOption.getSharedProjectView())).build();
projectViewSet = ProjectViewSet.builder().addAll(parseResult.getProjectViewFiles()).add(localProjectViewFile, projectView).build();
} else {
ProjectViewSet.ProjectViewFile projectViewFile = parseResult.getTopLevelProjectViewFile();
assert projectViewFile != null;
projectView = projectViewFile.projectView;
projectViewSet = parseResult;
}
builder.setProjectView(projectView).setProjectViewFile(localProjectViewFile).setProjectViewSet(projectViewSet).setProjectName(projectName).setProjectDataDirectory(projectDataDirectory);
}
use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeEditProjectViewControl method modifyInitialProjectView.
private static String modifyInitialProjectView(BuildSystem buildSystem, String initialProjectViewText, WorkspacePathResolver workspacePathResolver) {
BlazeContext context = new BlazeContext();
ProjectViewParser projectViewParser = new ProjectViewParser(context, workspacePathResolver);
projectViewParser.parseProjectView(initialProjectViewText);
ProjectViewSet projectViewSet = projectViewParser.getResult();
ProjectViewFile projectViewFile = projectViewSet.getTopLevelProjectViewFile();
if (projectViewFile == null) {
return initialProjectViewText;
}
ProjectView projectView = projectViewFile.projectView;
// Sort default value providers to match the section order
List<SectionKey> sectionKeys = Sections.getParsers().stream().map(SectionParser::getSectionKey).collect(toList());
List<ProjectViewDefaultValueProvider> defaultValueProviders = Lists.newArrayList(ProjectViewDefaultValueProvider.EP_NAME.getExtensions());
defaultValueProviders.sort(Comparator.comparingInt(val -> sectionKeys.indexOf(val.getSectionKey())));
for (ProjectViewDefaultValueProvider defaultValueProvider : defaultValueProviders) {
projectView = defaultValueProvider.addProjectViewDefaultValue(buildSystem, projectViewSet, projectView);
}
return ProjectViewParser.projectViewToString(projectView);
}
Aggregations