Search in sources :

Example 46 with TargetIdeInfo

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);
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) PrefetchService(com.google.idea.blaze.base.prefetch.PrefetchService) Callable(java.util.concurrent.Callable) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) Lists(com.google.common.collect.Lists) Scope(com.google.idea.blaze.base.scope.Scope) Map(java.util.Map) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) Nullable(javax.annotation.Nullable) FileDiffer(com.google.idea.blaze.base.filecache.FileDiffer) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ImmutableMap(com.google.common.collect.ImmutableMap) FutureUtil(com.google.idea.blaze.base.async.FutureUtil) SyncState(com.google.idea.blaze.base.model.SyncState) FileInputStream(java.io.FileInputStream) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Maps(com.google.common.collect.Maps) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Serializable(java.io.Serializable) ExecutionException(java.util.concurrent.ExecutionException) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) AtomicLong(java.util.concurrent.atomic.AtomicLong) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Deps(com.google.devtools.build.lib.view.proto.Deps) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) InputStream(java.io.InputStream) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) Nullable(javax.annotation.Nullable)

Example 47 with TargetIdeInfo

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;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) AtomicLong(java.util.concurrent.atomic.AtomicLong) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) List(java.util.List) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File)

Example 48 with TargetIdeInfo

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;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Dependency(com.google.idea.blaze.base.ideinfo.Dependency) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Nullable(javax.annotation.Nullable)

Example 49 with TargetIdeInfo

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;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Dependency(com.google.idea.blaze.base.ideinfo.Dependency) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap)

Example 50 with TargetIdeInfo

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();
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) HtmlBuilder(com.android.utils.HtmlBuilder) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Map(java.util.Map) TransitiveDependencyMap(com.google.idea.blaze.base.targetmaps.TransitiveDependencyMap) SourceToTargetMap(com.google.idea.blaze.base.targetmaps.SourceToTargetMap) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) SortedMap(java.util.SortedMap)

Aggregations

TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)57 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)28 File (java.io.File)20 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)19 Nullable (javax.annotation.Nullable)16 Kind (com.google.idea.blaze.base.model.primitives.Kind)15 ImmutableList (com.google.common.collect.ImmutableList)14 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)14 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)14 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)14 Project (com.intellij.openapi.project.Project)14 List (java.util.List)12 LibraryArtifact (com.google.idea.blaze.base.ideinfo.LibraryArtifact)11 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)11 LanguageClass (com.google.idea.blaze.base.model.primitives.LanguageClass)10 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)10 Collection (java.util.Collection)10 AndroidIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidIdeInfo)9 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)9 Set (java.util.Set)9