Search in sources :

Example 26 with ArtifactLocation

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);
    }
}
Also used : ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) File(java.io.File) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) HashSet(java.util.HashSet)

Example 27 with ArtifactLocation

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"));
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) Test(org.junit.Test)

Example 28 with ArtifactLocation

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());
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Test(org.junit.Test)

Example 29 with ArtifactLocation

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);
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 30 with ArtifactLocation

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));
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) HashMap(java.util.HashMap) QualifiedName(com.intellij.psi.util.QualifiedName) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)

Aggregations

ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)39 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)13 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)10 File (java.io.File)10 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)9 Test (org.junit.Test)9 JavaIdeInfo (com.google.idea.blaze.base.ideinfo.JavaIdeInfo)8 LibraryArtifact (com.google.idea.blaze.base.ideinfo.LibraryArtifact)8 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)8 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)8 Nullable (javax.annotation.Nullable)8 ImmutableList (com.google.common.collect.ImmutableList)7 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)7 List (java.util.List)7 Label (com.google.idea.blaze.base.model.primitives.Label)6 Lists (com.google.common.collect.Lists)5 AndroidResourceModule (com.google.idea.blaze.android.sync.model.AndroidResourceModule)5 SourceToTargetMap (com.google.idea.blaze.base.targetmaps.SourceToTargetMap)5 Map (java.util.Map)5 ImmutableSet (com.google.common.collect.ImmutableSet)4