Search in sources :

Example 31 with ArtifactLocation

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

the class TestTargetSourcesHeuristic method matchesSource.

@Override
public boolean matchesSource(Project project, TargetInfo target, @Nullable PsiFile sourcePsiFile, File sourceFile, @Nullable TestSize testSize) {
    Optional<ImmutableList<ArtifactLocation>> sources = target.getSources();
    if (!sources.isPresent()) {
        return false;
    }
    BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (projectData == null) {
        return false;
    }
    ArtifactLocationDecoder decoder = projectData.artifactLocationDecoder;
    for (ArtifactLocation src : sources.get()) {
        if (decoder.decode(src).equals(sourceFile)) {
            return true;
        }
    }
    return false;
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)

Example 32 with ArtifactLocation

use of com.google.idea.blaze.base.ideinfo.ArtifactLocation 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 33 with ArtifactLocation

use of com.google.idea.blaze.base.ideinfo.ArtifactLocation 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)

Example 34 with ArtifactLocation

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

the class BlazeJavaWorkspaceImporter method addLibraryToJdeps.

private void addLibraryToJdeps(Map<String, BlazeJarLibrary> jdepsPathToLibrary, BlazeJarLibrary library) {
    LibraryArtifact libraryArtifact = library.libraryArtifact;
    ArtifactLocation interfaceJar = libraryArtifact.interfaceJar;
    if (interfaceJar != null) {
        jdepsPathToLibrary.put(interfaceJar.getExecutionRootRelativePath(), library);
    }
    ArtifactLocation classJar = libraryArtifact.classJar;
    if (classJar != null) {
        jdepsPathToLibrary.put(classJar.getExecutionRootRelativePath(), library);
    }
}
Also used : ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact)

Example 35 with ArtifactLocation

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

the class JdepsFileReader method doLoadJdepsFiles.

private JdepsState doLoadJdepsFiles(Project project, BlazeContext context, ArtifactLocationDecoder artifactLocationDecoder, @Nullable JdepsState oldState, Iterable<TargetIdeInfo> targetsToLoad) {
    JdepsState state = new JdepsState();
    if (oldState != null) {
        state.targetToJdeps = Maps.newHashMap(oldState.targetToJdeps);
        state.fileToTargetMap = Maps.newHashMap(oldState.fileToTargetMap);
    }
    Map<File, TargetKey> fileToTargetMap = Maps.newHashMap();
    for (TargetIdeInfo target : targetsToLoad) {
        assert target != null;
        JavaIdeInfo javaIdeInfo = target.javaIdeInfo;
        if (javaIdeInfo != null) {
            ArtifactLocation jdepsFile = javaIdeInfo.jdepsFile;
            if (jdepsFile != null) {
                fileToTargetMap.put(artifactLocationDecoder.decode(jdepsFile), target.key);
            }
        }
    }
    List<File> updatedFiles = Lists.newArrayList();
    List<File> removedFiles = Lists.newArrayList();
    state.fileState = FileDiffer.updateFiles(oldState != null ? oldState.fileState : null, fileToTargetMap.keySet(), updatedFiles, removedFiles);
    ListenableFuture<?> fetchFuture = PrefetchService.getInstance().prefetchFiles(project, updatedFiles, true, false);
    if (!FutureUtil.waitForFuture(context, fetchFuture).timed("FetchJdeps", EventType.Prefetching).withProgressMessage("Reading jdeps files...").run().success()) {
        return null;
    }
    for (File removedFile : removedFiles) {
        TargetKey targetKey = state.fileToTargetMap.remove(removedFile);
        if (targetKey != null) {
            state.targetToJdeps.remove(targetKey);
        }
    }
    AtomicLong totalSizeLoaded = new AtomicLong(0);
    List<ListenableFuture<Result>> futures = Lists.newArrayList();
    for (File updatedFile : updatedFiles) {
        futures.add(submit(() -> {
            totalSizeLoaded.addAndGet(updatedFile.length());
            try (InputStream inputStream = new FileInputStream(updatedFile)) {
                Deps.Dependencies dependencies = Deps.Dependencies.parseFrom(inputStream);
                if (dependencies != null) {
                    List<String> dependencyStringList = Lists.newArrayList();
                    for (Deps.Dependency dependency : dependencies.getDependencyList()) {
                        // available for use in the same package
                        if (dependency.getKind() == Deps.Dependency.Kind.EXPLICIT || dependency.getKind() == Deps.Dependency.Kind.IMPLICIT) {
                            dependencyStringList.add(dependency.getPath());
                        }
                    }
                    TargetKey targetKey = fileToTargetMap.get(updatedFile);
                    return new Result(updatedFile, targetKey, dependencyStringList);
                }
            } catch (FileNotFoundException e) {
                logger.info("Could not open jdeps file: " + updatedFile);
            }
            return null;
        }));
    }
    try {
        for (Result result : Futures.allAsList(futures).get()) {
            if (result != null) {
                state.fileToTargetMap.put(result.file, result.targetKey);
                state.targetToJdeps.put(result.targetKey, result.dependencies);
            }
        }
        context.output(PrintOutput.log(String.format("Loaded %d jdeps files, total size %dkB", updatedFiles.size(), totalSizeLoaded.get() / 1024)));
    } catch (InterruptedException | ExecutionException e) {
        logger.error(e);
        return null;
    }
    return state;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) AtomicLong(java.util.concurrent.atomic.AtomicLong) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) List(java.util.List) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File)

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