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;
}
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;
}
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);
}
}
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);
}
}
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;
}
Aggregations