use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo 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.TargetIdeInfo 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.TargetIdeInfo in project intellij by bazelbuild.
the class BlazeAndroidTestRunConfigurationHandler method getInstrumentationBinary.
@Nullable
private Label getInstrumentationBinary(Label label) {
BlazeProjectData projectData = BlazeProjectDataManager.getInstance(configuration.getProject()).getBlazeProjectData();
if (projectData == null) {
return null;
}
TargetMap targetMap = projectData.targetMap;
TargetIdeInfo instrumentationTest = targetMap.get(TargetKey.forPlainTarget(label));
for (Dependency dependency : instrumentationTest.dependencies) {
TargetIdeInfo dependencyInfo = targetMap.get(dependency.targetKey);
// Should exist via test_app attribute, and be unique.
if (dependencyInfo != null && dependencyInfo.kind == Kind.ANDROID_BINARY) {
return dependency.targetKey.label;
}
}
return null;
}
use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.
the class BlazeApkBuildStepNormalBuild method getTargetToBuild.
/**
* In case we're dealing with an {@link Kind#ANDROID_INSTRUMENTATION_TEST}, build the underlying
* {@link Kind#ANDROID_BINARY} instead.
*/
private Label getTargetToBuild() {
BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (projectData == null) {
return label;
}
TargetMap targetMap = projectData.targetMap;
TargetIdeInfo target = targetMap.get(TargetKey.forPlainTarget(label));
if (target == null || target.kind != Kind.ANDROID_INSTRUMENTATION_TEST) {
return label;
}
for (Dependency dependency : target.dependencies) {
TargetIdeInfo dependencyInfo = targetMap.get(dependency.targetKey);
// Should exist via test_app attribute, and be unique.
if (dependencyInfo != null && dependencyInfo.kind == Kind.ANDROID_BINARY) {
return dependency.targetKey.label;
}
}
return label;
}
use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo 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();
}
Aggregations