use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method testIdlClassJarIsAddedAsLibrary.
@Test
public void testIdlClassJarIsAddedAsLibrary() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("example")))).build();
TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//example:lib").setBuildFile(source("example/BUILD")).setKind("android_binary").addSource(source("example/MainActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setResourceJavaPackage("example").setIdlJar(LibraryArtifact.builder().setInterfaceJar(gen("example/libidl.jar")).addSourceJar(gen("example/libidl.srcjar")).build()).setHasIdlSources(true)));
TargetMap targetMap = targetMapBuilder.build();
BlazeAndroidJavaSyncAugmenter syncAugmenter = new BlazeAndroidJavaSyncAugmenter();
List<BlazeJarLibrary> jars = Lists.newArrayList();
List<BlazeJarLibrary> genJars = Lists.newArrayList();
ImportRoots importRoots = ImportRoots.builder(workspaceRoot, BuildSystem.Blaze).add(ProjectViewSet.builder().add(projectView).build()).build();
ProjectViewSet projectViewSet = ProjectViewSet.builder().add(projectView).build();
for (TargetIdeInfo target : targetMap.targets()) {
if (importRoots.importAsSource(target.key.label)) {
syncAugmenter.addJarsForSourceTarget(workspaceLanguageSettings, projectViewSet, target, jars, genJars);
}
}
assertThat(genJars.stream().map(library -> library.libraryArtifact.interfaceJar).map(artifactLocation -> new File(artifactLocation.relativePath).getName()).collect(Collectors.toList())).containsExactly("libidl.jar");
}
use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporter method importWorkspace.
public BlazeAndroidImportResult importWorkspace() {
List<TargetIdeInfo> sourceTargets = targetMap.targets().stream().filter(target -> target.kind.languageClass == LanguageClass.ANDROID).filter(target -> target.androidIdeInfo != null).filter(importFilter::isSourceTarget).filter(target -> !importFilter.excludeTarget(target)).collect(Collectors.toList());
TransitiveResourceMap transitiveResourceMap = new TransitiveResourceMap(targetMap);
WorkspaceBuilder workspaceBuilder = new WorkspaceBuilder();
for (TargetIdeInfo target : sourceTargets) {
addSourceTarget(workspaceBuilder, transitiveResourceMap, target);
}
GeneratedResourceWarnings.submit(project, context, projectViewSet, artifactLocationDecoder, workspaceBuilder.generatedResourceLocations, whitelistedGenResourcePaths);
ImmutableList<AndroidResourceModule> androidResourceModules = buildAndroidResourceModules(workspaceBuilder);
BlazeResourceLibrary resourceLibrary = createResourceLibrary(androidResourceModules);
ImmutableList<AarLibrary> aarLibraries = createAarLibraries(sourceFilter.getLibraryTargets());
return new BlazeAndroidImportResult(androidResourceModules, resourceLibrary, aarLibraries, getJavacJar(targetMap.targets()));
}
use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.
the class BlazeAndroidProjectStructureSyncer method updateInMemoryState.
private static void updateInMemoryState(Project project, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, Module workspaceModule, AndroidResourceModuleRegistry registry, LightResourceClassService.Builder rClassBuilder) {
BlazeAndroidSyncData syncData = blazeProjectData.syncState.get(BlazeAndroidSyncData.class);
if (syncData == null) {
return;
}
AndroidSdkPlatform androidSdkPlatform = syncData.androidSdkPlatform;
if (androidSdkPlatform == null) {
return;
}
updateWorkspaceModuleFacetInMemoryState(project, workspaceRoot, workspaceModule, androidSdkPlatform);
ArtifactLocationDecoder artifactLocationDecoder = blazeProjectData.artifactLocationDecoder;
ModuleFinder moduleFinder = ModuleFinder.getInstance(project);
Executor resourceRepositoryExecutor = Executors.newSingleThreadExecutor();
Module libraryResourcesModule = moduleFinder.findModuleByName(LIBRARY_RESOURCES_MODULE_NAME);
if (libraryResourcesModule != null) {
updateLibraryResourcesModuleFacetInMemoryState(project, workspaceRoot, libraryResourcesModule, androidSdkPlatform, syncData.importResult.resourceLibrary == null ? ImmutableList.of() : artifactLocationDecoder.decodeAll(syncData.importResult.resourceLibrary.sources), resourceRepositoryExecutor);
} else if (useLibraryResourcesModule.getValue()) {
logger.warn("Library resources module missing.");
}
for (AndroidResourceModule androidResourceModule : syncData.importResult.androidResourceModules) {
TargetIdeInfo target = blazeProjectData.targetMap.get(androidResourceModule.targetKey);
String moduleName = moduleNameForAndroidModule(target.key);
Module module = moduleFinder.findModuleByName(moduleName);
if (module == null) {
logger.warn("No module found for resource target: " + target.key);
continue;
}
registry.put(module, androidResourceModule);
AndroidIdeInfo androidIdeInfo = target.androidIdeInfo;
assert androidIdeInfo != null;
updateModuleFacetInMemoryState(project, androidSdkPlatform, module, moduleDirectoryForAndroidTarget(workspaceRoot, target), manifestFileForAndroidTarget(artifactLocationDecoder, androidIdeInfo, moduleDirectoryForAndroidTarget(workspaceRoot, target)), androidIdeInfo.resourceJavaPackage, artifactLocationDecoder.decodeAll(useLibraryResourcesModule.getValue() ? androidResourceModule.resources : androidResourceModule.transitiveResources), resourceRepositoryExecutor);
rClassBuilder.addRClass(androidIdeInfo.resourceJavaPackage, module);
}
Set<TargetKey> androidResourceModules = syncData.importResult.androidResourceModules.stream().map(androidResourceModule -> androidResourceModule.targetKey).collect(toSet());
List<TargetIdeInfo> runConfigurationTargets = getRunConfigurationTargets(project, projectViewSet, blazeProjectData, androidResourceModules);
for (TargetIdeInfo target : runConfigurationTargets) {
String moduleName = moduleNameForAndroidModule(target.key);
Module module = moduleFinder.findModuleByName(moduleName);
if (module == null) {
logger.warn("No module found for run configuration target: " + target.key);
continue;
}
AndroidIdeInfo androidIdeInfo = target.androidIdeInfo;
assert androidIdeInfo != null;
updateModuleFacetInMemoryState(project, androidSdkPlatform, module, moduleDirectoryForAndroidTarget(workspaceRoot, target), manifestFileForAndroidTarget(artifactLocationDecoder, androidIdeInfo, moduleDirectoryForAndroidTarget(workspaceRoot, target)), androidIdeInfo.resourceJavaPackage, ImmutableList.of(), null);
}
}
use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.
the class CPrefetchFileSourceTest method testSourceFilesInProjectIgnored.
@Test
public void testSourceFilesInProjectIgnored() {
ProjectViewSet projectViewSet = parseProjectView("directories:", " java/com/google", "targets:", " //java/com/google:lib", "additional_languages:", " c", "android_sdk_platform: android-25");
BlazeProjectData projectData = MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("java/com/google/BUILD")).setLabel("//java/com/google:lib").setKind("cc_library").addSource(sourceRoot("java/com/google/native.cc")).addSource(sourceRoot("java/com/google/native.h"))).build()).setWorkspaceLanguageSettings(LanguageSupport.createWorkspaceLanguageSettings(projectViewSet)).build();
Set<File> filesToPrefetch = new HashSet<>();
new CPrefetchFileSource().addFilesToPrefetch(getProject(), projectViewSet, getImportRoots(projectViewSet), projectData, filesToPrefetch);
assertThat(filesToPrefetch).isEmpty();
}
use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.
the class CPrefetchFileSourceTest method testCppHeaderFilesOutsideProjectIncluded.
@Test
public void testCppHeaderFilesOutsideProjectIncluded() {
ProjectViewSet projectViewSet = parseProjectView("directories:", " java/com/google", "targets:", " //java/com/google:lib", "additional_languages:", " c", "android_sdk_platform: android-25");
BlazeProjectData projectData = MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("third_party/library/BUILD")).setLabel("//third_party/library:dep").setKind("cc_library").setCInfo(CIdeInfo.builder().addSource(sourceRoot("third_party/library/main.cc")).addHeader(sourceRoot("third_party/library/dep.h")).addHeader(sourceRoot("third_party/library/other.h")).addTextualHeader(sourceRoot("third_party/library/textual.h")))).build()).setWorkspaceLanguageSettings(LanguageSupport.createWorkspaceLanguageSettings(projectViewSet)).build();
Set<File> filesToPrefetch = new HashSet<>();
new CPrefetchFileSource().addFilesToPrefetch(getProject(), projectViewSet, getImportRoots(projectViewSet), projectData, filesToPrefetch);
assertThat(filesToPrefetch).containsExactly(workspaceFile("third_party/library/dep.h"), workspaceFile("third_party/library/other.h"), workspaceFile("third_party/library/textual.h"));
}
Aggregations