use of com.google.idea.blaze.base.ideinfo.ArtifactLocation in project intellij by bazelbuild.
the class GeneratedResourceWarnings method submit.
public static void submit(Project project, BlazeContext context, ProjectViewSet projectViewSet, ArtifactLocationDecoder artifactLocationDecoder, Set<ArtifactLocation> generatedResourceLocations, Set<String> whitelistedLocations) {
if (generatedResourceLocations.isEmpty()) {
return;
}
Set<ArtifactLocation> nonWhitelistedLocations = new HashSet<>();
Set<String> unusedWhitelistEntries = new HashSet<>();
filterWhitelistedEntries(generatedResourceLocations, whitelistedLocations, nonWhitelistedLocations, unusedWhitelistEntries);
// Tag any warnings with the project view file.
File projectViewFile = projectViewSet.getTopLevelProjectViewFile().projectViewFile;
if (!nonWhitelistedLocations.isEmpty()) {
GeneratedResourceClassifier classifier = new GeneratedResourceClassifier(nonWhitelistedLocations, artifactLocationDecoder, BlazeExecutor.getInstance().getExecutor());
ImmutableSortedMap<ArtifactLocation, Integer> interestingDirectories = classifier.getInterestingDirectories();
if (!interestingDirectories.isEmpty()) {
IssueOutput.warn(String.format("Dropping %d generated resource directories.\n" + "R classes will not contain resources from these directories.\n" + "Double-click to add to project view if needed to resolve references.", interestingDirectories.size())).inFile(projectViewFile).onLine(1).inColumn(1).submit(context);
for (Map.Entry<ArtifactLocation, Integer> entry : interestingDirectories.entrySet()) {
IssueOutput.warn(String.format("Dropping generated resource directory '%s' w/ %d subdirs", entry.getKey(), entry.getValue())).inFile(projectViewFile).navigatable(new AddGeneratedResourceDirectoryNavigatable(project, projectViewFile, entry.getKey())).submit(context);
}
}
}
// Warn about unused parts of the whitelist.
if (!unusedWhitelistEntries.isEmpty()) {
IssueOutput.warn(String.format("%d unused entries in project view section \"%s\":\n%s", unusedWhitelistEntries.size(), GeneratedAndroidResourcesSection.KEY.getName(), String.join("\n ", unusedWhitelistEntries))).inFile(projectViewFile).submit(context);
}
}
use of com.google.idea.blaze.base.ideinfo.ArtifactLocation in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporterTest method testSingleModule.
@Test
public void testSingleModule() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/apps/example")))).build();
TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example:example_debug").setBuildFile(source("java/apps/example/BUILD")).setKind("android_binary").addSource(source("java/apps/example/MainActivity.java")).addSource(source("java/apps/example/subdir/SubdirHelper.java")).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/apps/example/AndroidManifest.xml")).addResource(source("java/apps/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.apps.example")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/example_debug-ijar.jar")).setClassJar(gen("java/apps/example/example_debug.jar")))));
BlazeJavaImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
errorCollector.assertNoIssues();
assertThat(result.buildOutputJars).hasSize(1);
ArtifactLocation compilerOutputLib = result.buildOutputJars.iterator().next();
assertNotNull(compilerOutputLib);
assertThat(compilerOutputLib.relativePath).endsWith("example_debug.jar");
assertThat(result.contentEntries).containsExactly(BlazeContentEntry.builder("/root/java/apps/example").addSource(BlazeSourceDirectory.builder("/root/java/apps/example").setPackagePrefix("apps.example").build()).build());
assertThat(result.javaSourceFiles).containsExactly(source("java/apps/example/MainActivity.java"), source("java/apps/example/subdir/SubdirHelper.java"));
}
use of com.google.idea.blaze.base.ideinfo.ArtifactLocation in project intellij by bazelbuild.
the class SourceDirectoryCalculatorTest method testManifestMissingSourcesFallback.
@Test
public void testManifestMissingSourcesFallback() throws Exception {
setPackageManifest("/root/java/com/test.manifest", ImmutableList.of("java/com/google/Bla.java", "java/com/google/Foo.java"), ImmutableList.of("com.google", "com.google"));
mockInputStreamProvider.addFile("/root/java/com/google/subpackage/Bla.java", "package com.google.different;\n public class Bla {}");
ImmutableMap<TargetKey, ArtifactLocation> manifests = ImmutableMap.of(TargetKey.forPlainTarget(LABEL), ArtifactLocation.builder().setRelativePath("java/com/test.manifest").setIsSource(true).build());
List<SourceArtifact> sourceArtifacts = ImmutableList.of(SourceArtifact.builder(TargetKey.forPlainTarget(LABEL)).setArtifactLocation(ArtifactLocation.builder().setRelativePath("java/com/google/Bla.java").setIsSource(true)).build(), SourceArtifact.builder(TargetKey.forPlainTarget(LABEL)).setArtifactLocation(ArtifactLocation.builder().setRelativePath("java/com/google/Foo.java").setIsSource(true)).build(), SourceArtifact.builder(TargetKey.forPlainTarget(LABEL)).setArtifactLocation(ArtifactLocation.builder().setRelativePath("java/com/google/subpackage/Bla.java").setIsSource(true)).build());
ImmutableList<BlazeContentEntry> result = sourceDirectoryCalculator.calculateContentEntries(project, context, workspaceRoot, getDecoder(), buildImportRoots(ImmutableList.of(new WorkspacePath("java/com/google")), ImmutableList.of()), sourceArtifacts, manifests);
issues.assertNoIssues();
assertThat(result).containsExactly(BlazeContentEntry.builder("/root/java/com/google").addSource(BlazeSourceDirectory.builder("/root/java/com/google").setPackagePrefix("com.google").build()).addSource(BlazeSourceDirectory.builder("/root/java/com/google/subpackage").setPackagePrefix("com.google.different").build()).build());
}
use of com.google.idea.blaze.base.ideinfo.ArtifactLocation in project intellij by bazelbuild.
the class BlazeKotlinSyncPlugin method maybeAttachSourceJars.
private static void maybeAttachSourceJars(ArtifactLocationDecoder artifactLocationDecoder, BlazeJarLibrary lib, Library.ModifiableModel modifiableIjLibrary) {
if (modifiableIjLibrary.getFiles(OrderRootType.SOURCES).length == 0) {
for (ArtifactLocation sourceJar : lib.libraryArtifact.sourceJars) {
File srcJarFile = artifactLocationDecoder.decode(sourceJar);
VirtualFile vfSourceJar = VfsUtil.findFileByIoFile(srcJarFile, false);
if (vfSourceJar != null) {
VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(vfSourceJar);
if (jarRoot != null) {
modifiableIjLibrary.addRoot(jarRoot, OrderRootType.SOURCES);
}
}
}
}
}
use of com.google.idea.blaze.base.ideinfo.ArtifactLocation in project intellij by bazelbuild.
the class AbstractPyImportResolverStrategy method buildSourcesIndex.
@SuppressWarnings("unused")
private PySourcesIndex buildSourcesIndex(Project project, BlazeProjectData projectData) {
ImmutableSetMultimap.Builder<String, QualifiedName> shortNames = ImmutableSetMultimap.builder();
Map<QualifiedName, PsiElementProvider> map = new HashMap<>();
ArtifactLocationDecoder decoder = projectData.artifactLocationDecoder;
for (TargetIdeInfo target : projectData.targetMap.targets()) {
for (ArtifactLocation source : getPySources(target)) {
QualifiedName name = toImportString(source);
if (name == null || name.getLastComponent() == null) {
continue;
}
shortNames.put(name.getLastComponent(), name);
PsiElementProvider psiProvider = psiProviderFromArtifact(decoder, source);
map.put(name, psiProvider);
if (includeParentDirectory(source)) {
map.put(name.removeTail(1), PsiElementProvider.getParent(psiProvider));
}
}
}
return new PySourcesIndex(shortNames.build(), ImmutableMap.copyOf(map));
}
Aggregations