use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class JdepsFileReader method loadJdepsFiles.
/**
* Loads any updated jdeps files since the last invocation of this method.
*/
@Nullable
public JdepsMap loadJdepsFiles(Project project, BlazeContext parentContext, ArtifactLocationDecoder artifactLocationDecoder, Iterable<TargetIdeInfo> targetsToLoad, SyncState.Builder syncStateBuilder, @Nullable SyncState previousSyncState) {
JdepsState oldState = previousSyncState != null ? previousSyncState.get(JdepsState.class) : null;
JdepsState jdepsState = Scope.push(parentContext, (context) -> {
context.push(new TimingScope("LoadJdepsFiles", EventType.Other));
return doLoadJdepsFiles(project, context, artifactLocationDecoder, oldState, targetsToLoad);
});
if (jdepsState == null) {
return null;
}
syncStateBuilder.put(JdepsState.class, jdepsState);
return targetKey -> jdepsState.targetToJdeps.get(targetKey);
}
use of com.google.idea.blaze.base.ideinfo.TargetKey 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;
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class BlazeRenderErrorContributor method reportGeneratedResources.
/**
* We can't find generated resources. If a layout uses them, the layout won't render correctly.
*/
private void reportGeneratedResources(AndroidResourceModule resourceModule, TargetMap targetMap, ArtifactLocationDecoder decoder) {
Map<String, Throwable> brokenClasses = logger.getBrokenClasses();
if (brokenClasses == null || brokenClasses.isEmpty()) {
return;
}
// Sorted entries for deterministic error message.
SortedMap<ArtifactLocation, TargetIdeInfo> generatedResources = Maps.newTreeMap(getGeneratedResources(targetMap.get(resourceModule.targetKey)));
for (TargetKey dependency : resourceModule.transitiveResourceDependencies) {
generatedResources.putAll(getGeneratedResources(targetMap.get(dependency)));
}
if (generatedResources.isEmpty()) {
return;
}
HtmlBuilder builder = new HtmlBuilder();
builder.add("Generated resources will not be discovered by the IDE:");
builder.beginList();
for (Map.Entry<ArtifactLocation, TargetIdeInfo> entry : generatedResources.entrySet()) {
ArtifactLocation resource = entry.getKey();
TargetIdeInfo target = entry.getValue();
builder.listItem().add(resource.getRelativePath()).add(" from ");
addTargetLink(builder, target, decoder);
}
builder.endList().add("Please avoid using generated resources, ").addLink("then ", "sync the project", " ", getLinkManager().createSyncProjectUrl()).addLink("and ", "refresh the layout", ".", getLinkManager().createRefreshRenderUrl());
addIssue().setSeverity(HighlightSeverity.ERROR, // Reported above broken classes
HIGH_PRIORITY + 1).setSummary("Generated resources").setHtmlContent(builder).build();
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class BlazeRenderErrorContributor method reportResourceTargetShouldDependOnClassTarget.
/**
* Blaze doesn't resolve class dependencies from resources until building the final
* android_binary, so we could end up with resources that ultimately build correctly, but fail to
* find their class dependencies during rendering in the layout editor.
*/
private void reportResourceTargetShouldDependOnClassTarget(TargetIdeInfo target, TargetMap targetMap, ArtifactLocationDecoder decoder) {
Collection<String> missingClasses = logger.getMissingClasses();
if (missingClasses == null || missingClasses.isEmpty()) {
return;
}
// Sorted entries for deterministic error message.
SortedSetMultimap<String, TargetKey> missingClassToTargetMap = TreeMultimap.create();
SourceToTargetMap sourceToTargetMap = SourceToTargetMap.getInstance(project);
ImmutableCollection transitiveDependencies = TransitiveDependencyMap.getInstance(project).getTransitiveDependencies(target.key);
for (String missingClass : missingClasses) {
File sourceFile = getSourceFileForClass(missingClass);
if (sourceFile == null) {
continue;
}
ImmutableCollection<TargetKey> sourceTargets = sourceToTargetMap.getRulesForSourceFile(sourceFile);
if (sourceTargets.stream().noneMatch(sourceTarget -> sourceTarget.equals(target.key) || transitiveDependencies.contains(sourceTarget))) {
missingClassToTargetMap.putAll(missingClass, sourceTargets);
}
}
if (missingClassToTargetMap.isEmpty()) {
return;
}
HtmlBuilder builder = new HtmlBuilder();
addTargetLink(builder, target, decoder).add(" contains resource files that reference these classes:").beginList();
for (String missingClass : missingClassToTargetMap.keySet()) {
builder.listItem().addLink(missingClass, getLinkManager().createOpenClassUrl(missingClass)).add(" from ");
for (TargetKey targetKey : missingClassToTargetMap.get(missingClass)) {
addTargetLink(builder, targetMap.get(targetKey), decoder).add(" ");
}
}
builder.endList().add("Please fix your dependencies so that ");
addTargetLink(builder, target, decoder).add(" correctly depends on these classes, ").addLink("then ", "sync the project", " ", getLinkManager().createSyncProjectUrl()).addLink("and ", "refresh the layout", ".", getLinkManager().createRefreshRenderUrl()).newline().newline().addBold("NOTE: blaze can still build with the incorrect dependencies " + "due to the way it handles resources, " + "but the layout editor needs them to be correct.");
addIssue().setSeverity(HighlightSeverity.ERROR, // Reported above missing classes.
HIGH_PRIORITY + 1).setSummary("Missing class dependencies").setHtmlContent(builder).build();
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class ReverseDependencyMapTest method testThreeLevelGraph.
@Test
public void testThreeLevelGraph() {
TargetMapBuilder builder = TargetMapBuilder.builder();
TargetMap targetMap = builder.addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l1").setKind("java_library").addDependency("//l:l3")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l2").addDependency("//l:l3").setKind("java_library")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l3").setKind("java_library")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l4").addDependency("//l:l3").setKind("java_library")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l5").addDependency("//l:l4").setKind("java_library")).build();
ImmutableMultimap<TargetKey, TargetKey> reverseDependencies = ReverseDependencyMap.createRdepsMap(targetMap);
assertThat(reverseDependencies).containsEntry(TargetKey.forPlainTarget(Label.create("//l:l3")), TargetKey.forPlainTarget(Label.create("//l:l1")));
assertThat(reverseDependencies).containsEntry(TargetKey.forPlainTarget(Label.create("//l:l3")), TargetKey.forPlainTarget(Label.create("//l:l2")));
assertThat(reverseDependencies).containsEntry(TargetKey.forPlainTarget(Label.create("//l:l3")), TargetKey.forPlainTarget(Label.create("//l:l4")));
assertThat(reverseDependencies).containsEntry(TargetKey.forPlainTarget(Label.create("//l:l4")), TargetKey.forPlainTarget(Label.create("//l:l5")));
}
Aggregations