use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class BlazeRenderErrorContributor method reportIssues.
@Override
public Collection<RenderErrorModel.Issue> reportIssues() {
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData == null || !logger.hasErrors()) {
return getIssues();
}
TargetMap targetMap = blazeProjectData.targetMap;
ArtifactLocationDecoder decoder = blazeProjectData.artifactLocationDecoder;
AndroidResourceModule resourceModule = AndroidResourceModuleRegistry.getInstance(project).get(module);
if (resourceModule == null) {
return getIssues();
}
TargetIdeInfo target = targetMap.get(resourceModule.targetKey);
if (target == null) {
return getIssues();
}
reportGeneratedResources(resourceModule, targetMap, decoder);
reportNonStandardAndroidManifestName(target, decoder);
reportResourceTargetShouldDependOnClassTarget(target, targetMap, decoder);
return getIssues();
}
use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class BlazeIdeInterfaceAspectsImpl method updateState.
@Nullable
static State updateState(Project project, BlazeContext parentContext, @Nullable State prevState, ImmutableMap<File, Long> fileState, BlazeConfigurationHandler configHandler, WorkspaceLanguageSettings workspaceLanguageSettings, ImportRoots importRoots, AspectStrategy aspectStrategy, List<File> newFiles, List<File> removedFiles, boolean mergeWithOldState) {
Result<State> result = Scope.push(parentContext, (ScopedFunction<Result<State>>) context -> {
context.push(new TimingScope("UpdateTargetMap", EventType.Other));
ImmutableMap<File, Long> nextFileState = fileState;
if (mergeWithOldState && prevState != null) {
ImmutableMap.Builder<File, Long> fileStateBuilder = ImmutableMap.<File, Long>builder().putAll(fileState);
for (Map.Entry<File, Long> entry : prevState.fileState.entrySet()) {
if (!fileState.containsKey(entry.getKey())) {
fileStateBuilder.put(entry);
}
}
nextFileState = fileStateBuilder.build();
}
State state = new State();
state.fileState = nextFileState;
state.workspaceLanguageSettings = workspaceLanguageSettings;
state.aspectStrategyName = aspectStrategy.getName();
Map<TargetKey, TargetIdeInfo> targetMap = Maps.newHashMap();
if (prevState != null) {
targetMap.putAll(prevState.targetMap.map());
state.fileToTargetMapKey.putAll(prevState.fileToTargetMapKey);
}
if (!mergeWithOldState) {
for (File removedFile : removedFiles) {
TargetKey key = state.fileToTargetMapKey.remove(removedFile);
if (key != null) {
targetMap.remove(key);
}
}
}
AtomicLong totalSizeLoaded = new AtomicLong(0);
Set<LanguageClass> ignoredLanguages = Sets.newConcurrentHashSet();
ListeningExecutorService executor = BlazeExecutor.getInstance().getExecutor();
List<ListenableFuture<TargetFilePair>> futures = Lists.newArrayList();
for (File file : newFiles) {
futures.add(executor.submit(() -> {
totalSizeLoaded.addAndGet(file.length());
IntellijIdeInfo.TargetIdeInfo message = aspectStrategy.readAspectFile(file);
TargetIdeInfo target = protoToTarget(workspaceLanguageSettings, importRoots, message, ignoredLanguages);
return new TargetFilePair(file, target);
}));
}
Set<TargetKey> newTargets = new HashSet<>();
Set<String> configurations = new LinkedHashSet<>();
configurations.add(configHandler.defaultConfigurationPathComponent);
int duplicateTargetLabels = 0;
try {
for (TargetFilePair targetFilePair : Futures.allAsList(futures).get()) {
if (targetFilePair.target != null) {
File file = targetFilePair.file;
String config = configHandler.getConfigurationPathComponent(file);
configurations.add(config);
TargetKey key = targetFilePair.target.key;
if (targetMap.putIfAbsent(key, targetFilePair.target) == null) {
state.fileToTargetMapKey.forcePut(file, key);
} else {
if (!newTargets.add(key)) {
duplicateTargetLabels++;
}
if (Objects.equals(config, configHandler.defaultConfigurationPathComponent)) {
targetMap.put(key, targetFilePair.target);
state.fileToTargetMapKey.forcePut(file, key);
}
}
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return Result.error(null);
} catch (ExecutionException e) {
return Result.error(e);
}
context.output(PrintOutput.log(String.format("Loaded %d aspect files, total size %dkB", newFiles.size(), totalSizeLoaded.get() / 1024)));
if (duplicateTargetLabels > 0) {
context.output(new PerformanceWarning(String.format("There were %d duplicate rules, built with the following " + "configurations: %s.\nYour IDE sync is slowed down by ~%d%%.", duplicateTargetLabels, configurations, (100 * duplicateTargetLabels / targetMap.size()))));
}
ignoredLanguages.retainAll(LanguageSupport.availableAdditionalLanguages(workspaceLanguageSettings.getWorkspaceType()));
warnIgnoredLanguages(project, context, ignoredLanguages);
state.targetMap = new TargetMap(ImmutableMap.copyOf(targetMap));
return Result.of(state);
});
if (result.error != null) {
logger.error(result.error);
return null;
}
return result.result;
}
use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class ReverseDependencyMapTest method testSingleDep.
@Test
public void testSingleDep() {
TargetMapBuilder builder = TargetMapBuilder.builder();
TargetMap targetMap = builder.addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l1").setKind("java_library").addDependency("//l:l2")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l2").setKind("java_library")).build();
ImmutableMultimap<TargetKey, TargetKey> reverseDependencies = ReverseDependencyMap.createRdepsMap(targetMap);
assertThat(reverseDependencies).containsEntry(TargetKey.forPlainTarget(Label.create("//l:l2")), TargetKey.forPlainTarget(Label.create("//l:l1")));
}
use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class ReverseDependencyMapTest method testTwoLabelsDepOnSameLabel.
@Test
public void testTwoLabelsDepOnSameLabel() {
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")).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")));
}
use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.
the class ReverseDependencyMapTest method testLabelDepsOnTwoLabels.
@Test
public void testLabelDepsOnTwoLabels() {
TargetMapBuilder builder = TargetMapBuilder.builder();
TargetMap targetMap = builder.addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l1").setKind("java_library").addDependency("//l:l2").addDependency("//l:l3")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l2").setKind("java_library")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//l:l3").setKind("java_library")).build();
ImmutableMultimap<TargetKey, TargetKey> reverseDependencies = ReverseDependencyMap.createRdepsMap(targetMap);
assertThat(reverseDependencies).containsEntry(TargetKey.forPlainTarget(Label.create("//l:l2")), TargetKey.forPlainTarget(Label.create("//l:l1")));
assertThat(reverseDependencies).containsEntry(TargetKey.forPlainTarget(Label.create("//l:l3")), TargetKey.forPlainTarget(Label.create("//l:l1")));
}
Aggregations