Search in sources :

Example 21 with ArtifactLocation

use of com.google.idea.blaze.base.ideinfo.ArtifactLocation in project intellij by bazelbuild.

the class SourceDirectoryCalculator method sortArtifactLocationsByRootDirectory.

private static Multimap<WorkspacePath, SourceArtifact> sortArtifactLocationsByRootDirectory(BlazeContext context, ImportRoots importRoots, Collection<SourceArtifact> sources) {
    Multimap<WorkspacePath, SourceArtifact> result = ArrayListMultimap.create();
    for (SourceArtifact sourceArtifact : sources) {
        String sourcePath = sourceArtifact.artifactLocation.getRelativePath();
        if (importRoots.excludeDirectories().stream().anyMatch(excluded -> isUnderRootDirectory(excluded, sourcePath))) {
            continue;
        }
        WorkspacePath foundWorkspacePath = importRoots.rootDirectories().stream().filter(rootDirectory -> isUnderRootDirectory(rootDirectory, sourcePath)).findFirst().orElse(null);
        if (foundWorkspacePath != null) {
            result.put(foundWorkspacePath, sourceArtifact);
        } else if (sourceArtifact.artifactLocation.isSource()) {
            ArtifactLocation sourceFile = sourceArtifact.artifactLocation;
            String message = String.format("Did not add %s. You're probably using a java file from outside the workspace" + " that has been exported using export_files. Don't do that.", sourceFile);
            IssueOutput.warn(message).submit(context);
        }
    }
    return result;
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation)

Example 22 with ArtifactLocation

use of com.google.idea.blaze.base.ideinfo.ArtifactLocation in project intellij by bazelbuild.

the class BlazeClassJarProviderIntegrationTest method javaInfoWithCheckedInJars.

private JavaIdeInfo.Builder javaInfoWithCheckedInJars(String... relativeJarPaths) {
    JavaIdeInfo.Builder builder = JavaIdeInfo.builder();
    for (String relativeJarPath : relativeJarPaths) {
        ArtifactLocation jar = ArtifactLocation.builder().setRelativePath(relativeJarPath).setIsSource(true).build();
        builder.addJar(LibraryArtifact.builder().setClassJar(jar));
        fileSystem.createFile(jar.getExecutionRootRelativePath());
    }
    return builder;
}
Also used : ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo)

Example 23 with ArtifactLocation

use of com.google.idea.blaze.base.ideinfo.ArtifactLocation in project intellij by bazelbuild.

the class BlazeRenderErrorContributorTest method createTargetMapWithNonStandardAndroidManifestNameInDependency.

private void createTargetMapWithNonStandardAndroidManifestNameInDependency() {
    Label mainResourceTarget = Label.create("//com/google/example:main");
    Label dependencyResourceTarget = Label.create("//com/google/example:dependency");
    ArtifactLocation mainManifest = artifact("com/google/example/main/AndroidManifest.xml", true);
    ArtifactLocation mainResource = artifact("com/google/example/main/res", true);
    ArtifactLocation mainBuildFile = artifact("com/google/example/main/BUILD", true);
    ArtifactLocation dependencyManifest = artifact("com/google/example/dependency/MyManifest.xml", true);
    ArtifactLocation dependencyResource = artifact("com/google/example/dependency/res", true);
    ArtifactLocation dependencyBuildFile = artifact("com/google/example/dependency/BUILD", true);
    AndroidResourceModuleRegistry registry = AndroidResourceModuleRegistry.getInstance(project);
    registry.put(module, AndroidResourceModule.builder(TargetKey.forPlainTarget(mainResourceTarget)).addResource(mainResource).addTransitiveResourceDependency(dependencyResourceTarget).addTransitiveResource(dependencyResource).build());
    registry.put(mock(Module.class), AndroidResourceModule.builder(TargetKey.forPlainTarget(dependencyResourceTarget)).addResource(dependencyResource).build());
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel(mainResourceTarget).setBuildFile(mainBuildFile).setAndroidInfo(AndroidIdeInfo.builder().setGenerateResourceClass(true).setManifestFile(mainManifest).addResource(mainResource))).addTarget(TargetIdeInfo.builder().setLabel(dependencyResourceTarget).setBuildFile(dependencyBuildFile).setAndroidInfo(AndroidIdeInfo.builder().setGenerateResourceClass(true).setManifestFile(dependencyManifest).addResource(dependencyResource))).build();
    projectDataManager.setTargetMap(targetMap);
}
Also used : Label(com.google.idea.blaze.base.model.primitives.Label) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) AndroidResourceModuleRegistry(com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry) MockModule(com.intellij.mock.MockModule) Module(com.intellij.openapi.module.Module) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) SourceToTargetMap(com.google.idea.blaze.base.targetmaps.SourceToTargetMap) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap)

Example 24 with ArtifactLocation

use of com.google.idea.blaze.base.ideinfo.ArtifactLocation 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");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) GeneratedAndroidResourcesSection(com.google.idea.blaze.android.projectview.GeneratedAndroidResourcesSection) BlazeAndroidJavaSyncAugmenter(com.google.idea.blaze.android.sync.BlazeAndroidJavaSyncAugmenter) PrefetchService(com.google.idea.blaze.base.prefetch.PrefetchService) JavaWorkingSet(com.google.idea.blaze.java.sync.workingset.JavaWorkingSet) WorkingSet(com.google.idea.blaze.base.sync.workspace.WorkingSet) JavaLikeLanguage(com.google.idea.blaze.java.sync.source.JavaLikeLanguage) BlazeAndroidLibrarySource(com.google.idea.blaze.android.sync.BlazeAndroidLibrarySource) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) ImmutableSet(com.google.common.collect.ImmutableSet) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) Predicate(java.util.function.Predicate) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) Collectors(java.util.stream.Collectors) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) BlazeAndroidImportResult(com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult) SourceArtifact(com.google.idea.blaze.java.sync.source.SourceArtifact) List(java.util.List) ErrorCollector(com.google.idea.blaze.base.scope.ErrorCollector) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) JavaSourcePackageReader(com.google.idea.blaze.java.sync.source.JavaSourcePackageReader) PackageManifestReader(com.google.idea.blaze.java.sync.source.PackageManifestReader) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) DirectorySection(com.google.idea.blaze.base.projectview.section.sections.DirectorySection) RunWith(org.junit.runner.RunWith) BlazeJavaWorkspaceImporter(com.google.idea.blaze.java.sync.importer.BlazeJavaWorkspaceImporter) MockJdepsMap(com.google.idea.blaze.java.sync.jdeps.MockJdepsMap) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) ExperimentService(com.google.idea.common.experiments.ExperimentService) BlazeResourceLibrary(com.google.idea.blaze.android.sync.model.BlazeResourceLibrary) MockBlazeExecutor(com.google.idea.blaze.base.async.executor.MockBlazeExecutor) AndroidIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidIdeInfo) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) WorkspaceType(com.google.idea.blaze.base.model.primitives.WorkspaceType) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) BuildSystem(com.google.idea.blaze.base.settings.Blaze.BuildSystem) AarLibrary(com.google.idea.blaze.android.sync.model.AarLibrary) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Nullable(javax.annotation.Nullable) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) BlazeTestCase(com.google.idea.blaze.base.BlazeTestCase) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) AndroidAarIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidAarIdeInfo) MockPrefetchService(com.google.idea.blaze.base.prefetch.MockPrefetchService) BlazeJavaSyncAugmenter(com.google.idea.blaze.java.sync.BlazeJavaSyncAugmenter) File(java.io.File) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) Label(com.google.idea.blaze.base.model.primitives.Label) MockExperimentService(com.google.idea.common.experiments.MockExperimentService) GenfilesPath(com.google.idea.blaze.android.projectview.GenfilesPath) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ListSection(com.google.idea.blaze.base.projectview.section.ListSection) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) BlazeAndroidJavaSyncAugmenter(com.google.idea.blaze.android.sync.BlazeAndroidJavaSyncAugmenter) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) File(java.io.File) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 25 with ArtifactLocation

use of com.google.idea.blaze.base.ideinfo.ArtifactLocation in project intellij by bazelbuild.

the class BlazeAndroidWorkspaceImporter method addSourceTarget.

private void addSourceTarget(WorkspaceBuilder workspaceBuilder, TransitiveResourceMap transitiveResourceMap, TargetIdeInfo target) {
    AndroidIdeInfo androidIdeInfo = target.androidIdeInfo;
    assert androidIdeInfo != null;
    if (shouldGenerateResources(androidIdeInfo) && shouldGenerateResourceModule(androidIdeInfo, whitelistedGenResourcePaths)) {
        AndroidResourceModule.Builder builder = new AndroidResourceModule.Builder(target.key);
        workspaceBuilder.androidResourceModules.add(builder);
        for (ArtifactLocation artifactLocation : androidIdeInfo.resources) {
            if (artifactLocation.isSource()) {
                builder.addResource(artifactLocation);
            } else {
                workspaceBuilder.generatedResourceLocations.add(artifactLocation);
                if (whitelistedGenResourcePaths.contains(artifactLocation.relativePath)) {
                    // Still track location in generatedResourceLocations, so that we can warn if a
                    // whitelist entry goes unused and can be removed.
                    builder.addResource(artifactLocation);
                }
            }
        }
        TransitiveResourceMap.TransitiveResourceInfo transitiveResourceInfo = transitiveResourceMap.get(target.key);
        for (ArtifactLocation artifactLocation : transitiveResourceInfo.transitiveResources) {
            if (artifactLocation.isSource()) {
                builder.addTransitiveResource(artifactLocation);
            } else {
                workspaceBuilder.generatedResourceLocations.add(artifactLocation);
                if (whitelistedGenResourcePaths.contains(artifactLocation.relativePath)) {
                    builder.addTransitiveResource(artifactLocation);
                }
            }
        }
        for (TargetKey resourceDependency : transitiveResourceInfo.transitiveResourceTargets) {
            if (!resourceDependency.equals(target.key)) {
                builder.addTransitiveResourceDependency(resourceDependency);
            }
        }
    }
}
Also used : AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) TransitiveResourceMap(com.google.idea.blaze.android.sync.importer.aggregators.TransitiveResourceMap) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) AndroidIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidIdeInfo)

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