Search in sources :

Example 16 with BlazeJarLibrary

use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.

the class BlazeJavaWorkspaceImporterTest method testLibraryWithSourceJar.

/**
 * Test library with a source jar
 */
@Test
public void testLibraryWithSourceJar() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/apps/example"))).add(DirectoryEntry.include(new WorkspacePath("javatests/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(gen("java/apps/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.apps.example")).addDependency("//thirdparty/some/library:library").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/example_debug.jar")).setClassJar(gen("java/apps/example/example_debug.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//thirdparty/some/library:library").setBuildFile(source("/thirdparty/some/library/BUILD")).setKind("java_import").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/some/library.jar")).setClassJar(gen("thirdparty/some/library.jar")).addSourceJar(gen("thirdparty/some/library.srcjar")))));
    BlazeJavaImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
    errorCollector.assertNoIssues();
    BlazeJarLibrary library = findLibrary(result.libraries, "library.jar");
    assertNotNull(library);
    assertThat(library.libraryArtifact.sourceJars).isNotEmpty();
}
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) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) Test(org.junit.Test)

Example 17 with BlazeJarLibrary

use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporter method importWorkspace.

public BlazeScalaImportResult importWorkspace() {
    ProjectViewTargetImportFilter importFilter = new ProjectViewTargetImportFilter(project, workspaceRoot, projectViewSet);
    Collection<Kind> scalaKinds = Kind.allKindsForLanguage(LanguageClass.SCALA);
    List<TargetKey> scalaSourceTargets = targetMap.targets().stream().filter(target -> target.javaIdeInfo != null).filter(target -> target.kindIsOneOf(scalaKinds)).filter(importFilter::isSourceTarget).map(target -> target.key).collect(Collectors.toList());
    Map<LibraryKey, BlazeJarLibrary> libraries = Maps.newHashMap();
    // but since they'll all merged into one set, we will end up with exactly one of each.
    for (TargetKey dependency : TransitiveDependencyMap.getTransitiveDependencies(scalaSourceTargets, targetMap)) {
        TargetIdeInfo target = targetMap.get(dependency);
        if (target == null) {
            continue;
        }
        // Except source targets.
        if (JavaSourceFilter.importAsSource(importFilter, target)) {
            continue;
        }
        if (target.javaIdeInfo != null) {
            target.javaIdeInfo.jars.stream().map(BlazeJarLibrary::new).forEach(library -> libraries.putIfAbsent(library.key, library));
        }
    }
    return new BlazeScalaImportResult(ImmutableMap.copyOf(libraries));
}
Also used : LibraryKey(com.google.idea.blaze.base.model.LibraryKey) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) TransitiveDependencyMap(com.google.idea.blaze.base.targetmaps.TransitiveDependencyMap) List(java.util.List) Map(java.util.Map) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Project(com.intellij.openapi.project.Project) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ProjectViewTargetImportFilter(com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) ProjectViewTargetImportFilter(com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) LibraryKey(com.google.idea.blaze.base.model.LibraryKey) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult)

Example 18 with BlazeJarLibrary

use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.

the class LibraryGlobFilter method test.

@Override
public boolean test(BlazeLibrary blazeLibrary) {
    if (!(blazeLibrary instanceof BlazeJarLibrary)) {
        return true;
    }
    BlazeJarLibrary jarLibrary = (BlazeJarLibrary) blazeLibrary;
    ArtifactLocation interfaceJar = jarLibrary.libraryArtifact.interfaceJar;
    ArtifactLocation classJar = jarLibrary.libraryArtifact.classJar;
    boolean matches = (interfaceJar != null && excludedLibraries.matches(interfaceJar.getRelativePath())) || (classJar != null && excludedLibraries.matches(classJar.getRelativePath()));
    return !matches;
}
Also used : BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation)

Example 19 with BlazeJarLibrary

use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.

the class BlazeJavaWorkspaceImporter method addProtoLegacyLibrariesFromDirectDepsForFlavor.

private void addProtoLegacyLibrariesFromDirectDepsForFlavor(TargetMap targetMap, ProtoLibraryLegacyInfo.ApiFlavor apiFlavor, List<TargetKey> targetKeys, Map<LibraryKey, BlazeJarLibrary> result) {
    for (TargetKey key : targetKeys) {
        TargetIdeInfo target = targetMap.get(key);
        if (target == null) {
            continue;
        }
        ProtoLibraryLegacyInfo protoLibraryLegacyInfo = target.protoLibraryLegacyInfo;
        if (protoLibraryLegacyInfo == null) {
            continue;
        }
        final Collection<LibraryArtifact> libraries;
        switch(apiFlavor) {
            case VERSION_1:
                libraries = protoLibraryLegacyInfo.jarsV1;
                break;
            case MUTABLE:
                libraries = protoLibraryLegacyInfo.jarsMutable;
                break;
            case IMMUTABLE:
                libraries = protoLibraryLegacyInfo.jarsImmutable;
                break;
            default:
                // Can't happen
                libraries = null;
                break;
        }
        if (libraries != null) {
            for (LibraryArtifact libraryArtifact : libraries) {
                BlazeJarLibrary library = new BlazeJarLibrary(libraryArtifact);
                result.put(library.key, library);
            }
        }
    }
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) ProtoLibraryLegacyInfo(com.google.idea.blaze.base.ideinfo.ProtoLibraryLegacyInfo)

Example 20 with BlazeJarLibrary

use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.

the class BlazeJavaWorkspaceImporter method addTargetAsSource.

private void addTargetAsSource(WorkspaceBuilder workspaceBuilder, TargetIdeInfo target, Collection<ArtifactLocation> javaSources) {
    JavaIdeInfo javaIdeInfo = target.javaIdeInfo;
    if (javaIdeInfo == null) {
        return;
    }
    TargetKey targetKey = target.key;
    Collection<String> jars = jdepsMap.getDependenciesForTarget(targetKey);
    if (jars != null) {
        workspaceBuilder.jdeps.addAll(jars);
    }
    // Add all deps if this rule is in the current working set
    if (workingSet == null || workingSet.isTargetInWorkingSet(target)) {
        // Add self, so we pick up our own gen jars if in working set
        workspaceBuilder.directDeps.add(targetKey);
        for (Dependency dep : target.dependencies) {
            if (dep.dependencyType != DependencyType.COMPILE_TIME) {
                continue;
            }
            // forward deps from java proto_library aspect targets
            TargetIdeInfo depTarget = targetMap.get(dep.targetKey);
            if (depTarget != null && Kind.JAVA_PROTO_LIBRARY_KINDS.contains(depTarget.kind)) {
                workspaceBuilder.directDeps.addAll(depTarget.dependencies.stream().map(d -> d.targetKey).collect(Collectors.toList()));
            } else {
                workspaceBuilder.directDeps.add(dep.targetKey);
            }
        }
    }
    for (ArtifactLocation artifactLocation : javaSources) {
        if (artifactLocation.isSource()) {
            duplicateSourceDetector.add(targetKey, artifactLocation);
            workspaceBuilder.sourceArtifacts.add(new SourceArtifact(targetKey, artifactLocation));
            workspaceBuilder.addedSourceFiles.add(artifactLocation);
        }
    }
    ArtifactLocation manifest = javaIdeInfo.packageManifest;
    if (manifest != null) {
        workspaceBuilder.javaPackageManifests.put(targetKey, manifest);
    }
    for (LibraryArtifact libraryArtifact : javaIdeInfo.jars) {
        ArtifactLocation classJar = libraryArtifact.classJar;
        if (classJar != null) {
            workspaceBuilder.buildOutputJars.add(classJar);
        }
    }
    workspaceBuilder.generatedJarsFromSourceTargets.addAll(javaIdeInfo.generatedJars.stream().map(BlazeJarLibrary::new).collect(Collectors.toList()));
    if (javaIdeInfo.filteredGenJar != null) {
        workspaceBuilder.generatedJarsFromSourceTargets.add(new BlazeJarLibrary(javaIdeInfo.filteredGenJar));
    }
    for (BlazeJavaSyncAugmenter augmenter : augmenters) {
        augmenter.addJarsForSourceTarget(workspaceLanguageSettings, projectViewSet, target, workspaceBuilder.outputJarsFromSourceTargets.get(targetKey), workspaceBuilder.generatedJarsFromSourceTargets);
    }
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeJavaSyncAugmenter(com.google.idea.blaze.java.sync.BlazeJavaSyncAugmenter) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Dependency(com.google.idea.blaze.base.ideinfo.Dependency) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) SourceArtifact(com.google.idea.blaze.java.sync.source.SourceArtifact)

Aggregations

BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)21 LibraryArtifact (com.google.idea.blaze.base.ideinfo.LibraryArtifact)11 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)9 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)9 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)7 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)7 ImmutableList (com.google.common.collect.ImmutableList)6 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)6 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Nullable (javax.annotation.Nullable)6 JavaIdeInfo (com.google.idea.blaze.base.ideinfo.JavaIdeInfo)5 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)5 Kind (com.google.idea.blaze.base.model.primitives.Kind)5 LanguageClass (com.google.idea.blaze.base.model.primitives.LanguageClass)5 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)5 Test (org.junit.Test)5 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)4 BlazeLibrary (com.google.idea.blaze.base.model.BlazeLibrary)4