use of com.google.idea.blaze.base.scope.output.PerformanceWarning in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporter method buildAndroidResourceModules.
private ImmutableList<AndroidResourceModule> buildAndroidResourceModules(WorkspaceBuilder workspaceBuilder) {
// Filter empty resource modules
Stream<AndroidResourceModule> androidResourceModuleStream = workspaceBuilder.androidResourceModules.stream().map(AndroidResourceModule.Builder::build).filter(androidResourceModule -> !androidResourceModule.isEmpty()).filter(androidResourceModule -> !androidResourceModule.resources.isEmpty());
List<AndroidResourceModule> androidResourceModules = androidResourceModuleStream.collect(Collectors.toList());
// Detect, filter, and warn about multiple R classes
Multimap<String, AndroidResourceModule> javaPackageToResourceModule = ArrayListMultimap.create();
for (AndroidResourceModule androidResourceModule : androidResourceModules) {
TargetIdeInfo target = targetMap.get(androidResourceModule.targetKey);
AndroidIdeInfo androidIdeInfo = target.androidIdeInfo;
assert androidIdeInfo != null;
javaPackageToResourceModule.put(androidIdeInfo.resourceJavaPackage, androidResourceModule);
}
List<AndroidResourceModule> result = Lists.newArrayList();
for (String resourceJavaPackage : javaPackageToResourceModule.keySet()) {
Collection<AndroidResourceModule> androidResourceModulesWithJavaPackage = javaPackageToResourceModule.get(resourceJavaPackage);
if (androidResourceModulesWithJavaPackage.size() == 1) {
result.addAll(androidResourceModulesWithJavaPackage);
} else {
StringBuilder messageBuilder = new StringBuilder();
messageBuilder.append("Multiple R classes generated with the same java package ").append(resourceJavaPackage).append(".R: ");
messageBuilder.append('\n');
for (AndroidResourceModule androidResourceModule : androidResourceModulesWithJavaPackage) {
messageBuilder.append(" ").append(androidResourceModule.targetKey).append('\n');
}
String message = messageBuilder.toString();
context.output(new PerformanceWarning(message));
IssueOutput.warn(message).submit(context);
result.add(selectBestAndroidResourceModule(androidResourceModulesWithJavaPackage));
}
}
Collections.sort(result, (lhs, rhs) -> lhs.targetKey.compareTo(rhs.targetKey));
return ImmutableList.copyOf(result);
}
use of com.google.idea.blaze.base.scope.output.PerformanceWarning 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.scope.output.PerformanceWarning in project intellij by bazelbuild.
the class BlazeJavaSyncPlugin method warnAboutDeployJars.
/**
* Looks at your jars for anything that seems to be a deploy jar and warns about it. This often
* turns out to be a duplicate copy of all your application's code, so you don't want it in your
* project.
*/
private static void warnAboutDeployJars(BlazeContext context, BlazeJavaSyncData syncData) {
for (BlazeLibrary library : syncData.importResult.libraries.values()) {
if (!(library instanceof BlazeJarLibrary)) {
continue;
}
BlazeJarLibrary jarLibrary = (BlazeJarLibrary) library;
LibraryArtifact libraryArtifact = jarLibrary.libraryArtifact;
ArtifactLocation artifactLocation = libraryArtifact.jarForIntellijLibrary();
if (artifactLocation.getRelativePath().endsWith("deploy.jar") || artifactLocation.getRelativePath().endsWith("deploy-ijar.jar") || artifactLocation.getRelativePath().endsWith("deploy-hjar.jar")) {
context.output(new PerformanceWarning("Performance warning: You have added a deploy jar as a library. " + "This can lead to poor indexing performance, and the debugger may " + "become confused and step into the deploy jar instead of your code. " + "Consider redoing the rule to not use deploy jars, exclude the target " + "from your .blazeproject, or exclude the library.\n" + "Library path: " + artifactLocation.getRelativePath()));
}
}
}
use of com.google.idea.blaze.base.scope.output.PerformanceWarning in project intellij by bazelbuild.
the class DuplicateSourceDetector method reportDuplicates.
public void reportDuplicates(BlazeContext context) {
List<Duplicate> duplicates = Lists.newArrayList();
for (ArtifactLocation key : artifacts.keySet()) {
Collection<TargetKey> labels = artifacts.get(key);
if (labels.size() > 1) {
// Workaround for aspect bug. Can be removed after the next blaze release, as of May 27 2016
Set<TargetKey> labelSet = Sets.newHashSet(labels);
if (labelSet.size() > 1) {
duplicates.add(new Duplicate(key, labelSet));
}
}
}
if (duplicates.isEmpty()) {
return;
}
duplicates.sort(Comparator.comparing(lhs -> lhs.artifactLocation.getRelativePath()));
context.output(new PerformanceWarning("Duplicate sources detected:"));
for (Duplicate duplicate : duplicates) {
ArtifactLocation artifactLocation = duplicate.artifactLocation;
context.output(new PerformanceWarning(" Source: " + artifactLocation.getRelativePath()));
context.output(new PerformanceWarning(" Consumed by rules:"));
for (TargetKey targetKey : duplicate.targets) {
context.output(new PerformanceWarning(" " + targetKey.label));
}
// Newline
context.output(new PerformanceWarning(""));
}
}
use of com.google.idea.blaze.base.scope.output.PerformanceWarning in project intellij by bazelbuild.
the class PerformanceWarningScope method onScopeEnd.
@Override
public void onScopeEnd(BlazeContext context) {
if (outputs.isEmpty()) {
return;
}
context.output(new PrintOutput("\n===== PERFORMANCE WARNINGS =====\n"));
context.output(new PrintOutput("Your IDE isn't as fast as it could be."));
context.output(new PrintOutput("You can turn these off via Blaze > Sync > Show Performance Warnings."));
context.output(new PrintOutput(""));
for (PerformanceWarning output : outputs) {
context.output(new PrintOutput(output.text));
}
}
Aggregations