Search in sources :

Example 1 with TargetKey

use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.

the class FastBuildCompilerFactoryImplTest method testMultipleJavaToolchains.

@Test
public void testMultipleJavaToolchains() {
    Map<TargetKey, TargetIdeInfo> targetMap = new HashMap<>();
    TargetIdeInfo buildTargetInfo = TargetIdeInfo.builder().setLabel(Label.create("//our/build:target")).addDependency(Label.create("//some/jdk:langtools")).addDependency(Label.create("//other/jdk:langtools")).build();
    targetMap.put(TargetKey.forPlainTarget(Label.create("//our/build:target")), buildTargetInfo);
    targetMap.put(TargetKey.forPlainTarget(Label.create("//some/jdk:langtools")), TargetIdeInfo.builder().setJavaToolchainIdeInfo(JavaToolchainIdeInfo.builder().setJavacJar(ArtifactLocation.builder().setRelativePath(JAVAC_JAR.getPath()).build())).build());
    targetMap.put(TargetKey.forPlainTarget(Label.create("//other/jdk:langtools")), TargetIdeInfo.builder().setJavaToolchainIdeInfo(JavaToolchainIdeInfo.builder().setJavacJar(ArtifactLocation.builder().setRelativePath(JAVAC_JAR.getPath()).build())).build());
    configureTestForTargetMap(targetMap);
    try {
        compilerFactory.getCompilerFor(buildTargetInfo);
        fail("Should have thrown FastBuildException");
    } catch (FastBuildException e) {
        assertThat(e.getMessage()).contains("Java toolchain");
    }
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) HashMap(java.util.HashMap) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Test(org.junit.Test)

Example 2 with TargetKey

use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.

the class BlazeAndroidProjectStructureSyncer method ensureRunConfigurationModule.

/**
 * Ensures a suitable module exists for the given android target.
 */
@Nullable
public static Module ensureRunConfigurationModule(Project project, Label label) {
    TargetKey targetKey = TargetKey.forPlainTarget(label);
    String moduleName = moduleNameForAndroidModule(targetKey);
    Module module = ModuleFinder.getInstance(project).findModuleByName(moduleName);
    if (module != null) {
        return module;
    }
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return null;
    }
    AndroidSdkPlatform androidSdkPlatform = SdkUtil.getAndroidSdkPlatform(blazeProjectData);
    if (androidSdkPlatform == null) {
        return null;
    }
    TargetIdeInfo target = blazeProjectData.targetMap.get(targetKey);
    if (target == null) {
        return null;
    }
    if (target.androidIdeInfo == null) {
        return null;
    }
    // invokeAndWait it because the caller may have a read action.
    if (!ApplicationManager.getApplication().isDispatchThread()) {
        return null;
    }
    BlazeSyncPlugin.ModuleEditor moduleEditor = ModuleEditorProvider.getInstance().getModuleEditor(project, BlazeImportSettingsManager.getInstance(project).getImportSettings());
    Module newModule = moduleEditor.createModule(moduleName, StdModuleTypes.JAVA);
    ApplicationManager.getApplication().runWriteAction(() -> {
        AndroidFacetModuleCustomizer.createAndroidFacet(newModule);
        moduleEditor.commit();
    });
    File moduleDirectory = moduleDirectoryForAndroidTarget(WorkspaceRoot.fromProject(project), target);
    updateModuleFacetInMemoryState(project, androidSdkPlatform, newModule, moduleDirectory, manifestFileForAndroidTarget(blazeProjectData.artifactLocationDecoder, target.androidIdeInfo, moduleDirectory), target.androidIdeInfo.resourceJavaPackage, ImmutableList.of(), null);
    return newModule;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) AndroidSdkPlatform(com.google.idea.blaze.android.sync.model.AndroidSdkPlatform) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Module(com.intellij.openapi.module.Module) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 3 with TargetKey

use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.

the class BlazeAndroidProjectStructureSyncer method getRunConfigurationTargets.

// Collect potential android run configuration targets
private static List<TargetIdeInfo> getRunConfigurationTargets(Project project, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, Set<TargetKey> androidResourceModules) {
    List<TargetIdeInfo> result = Lists.newArrayList();
    Set<Label> runConfigurationModuleTargets = Sets.newHashSet();
    // Doing this now will cut down on root changes later
    for (TargetExpression targetExpression : projectViewSet.listItems(TargetSection.KEY)) {
        if (!(targetExpression instanceof Label)) {
            continue;
        }
        Label label = (Label) targetExpression;
        runConfigurationModuleTargets.add(label);
    }
    // Get any pre-existing targets
    for (RunConfiguration runConfiguration : RunManager.getInstance(project).getAllConfigurationsList()) {
        BlazeAndroidRunConfigurationHandler handler = BlazeAndroidRunConfigurationHandler.getHandlerFrom(runConfiguration);
        if (handler == null) {
            continue;
        }
        runConfigurationModuleTargets.add(handler.getLabel());
    }
    for (Label label : runConfigurationModuleTargets) {
        TargetKey targetKey = TargetKey.forPlainTarget(label);
        // If it's a resource module, it will already have been created
        if (androidResourceModules.contains(targetKey)) {
            continue;
        }
        // Ensure the label is a supported android rule that exists
        TargetIdeInfo target = blazeProjectData.targetMap.get(targetKey);
        if (target == null) {
            continue;
        }
        if (!target.kindIsOneOf(Kind.ANDROID_BINARY, Kind.ANDROID_TEST)) {
            continue;
        }
        result.add(target);
    }
    return result;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BlazeAndroidRunConfigurationHandler(com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationHandler) Label(com.google.idea.blaze.base.model.primitives.Label) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey)

Example 4 with TargetKey

use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.

the class BlazeClassJarProvider method getModuleExternalLibraries.

@Override
public List<File> getModuleExternalLibraries(Module module) {
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return ImmutableList.of();
    }
    TargetMap targetMap = blazeProjectData.targetMap;
    ArtifactLocationDecoder decoder = blazeProjectData.artifactLocationDecoder;
    AndroidResourceModuleRegistry registry = AndroidResourceModuleRegistry.getInstance(project);
    TargetIdeInfo target = targetMap.get(registry.getTargetKey(module));
    if (target == null) {
        return ImmutableList.of();
    }
    AppResourceRepository repository = AppResourceRepository.getOrCreateInstance(module);
    ImmutableList.Builder<File> results = ImmutableList.builder();
    for (TargetKey dependencyTargetKey : TransitiveDependencyMap.getInstance(project).getTransitiveDependencies(target.key)) {
        TargetIdeInfo dependencyTarget = targetMap.get(dependencyTargetKey);
        if (dependencyTarget == null) {
            continue;
        }
        // Add all import jars as external libraries.
        JavaIdeInfo javaIdeInfo = dependencyTarget.javaIdeInfo;
        if (javaIdeInfo != null) {
            for (LibraryArtifact jar : javaIdeInfo.jars) {
                if (jar.classJar != null && jar.classJar.isSource()) {
                    results.add(decoder.decode(jar.classJar));
                }
            }
        }
        // Tell ResourceClassRegistry which repository contains our resources and the java packages of
        // the resources that we're interested in.
        // When the class loader tries to load a custom view, and the view references resource
        // classes, layoutlib will ask the class loader for these resource classes.
        // If these resource classes are in a separate jar from the target (i.e., in a dependency),
        // then offering their jars will lead to a conflict in the resource IDs.
        // So instead, the resource class generator will produce dummy resource classes with
        // non-conflicting IDs to satisfy the class loader.
        // The resource repository remembers the dynamic IDs that it handed out and when the layoutlib
        // calls to ask about the name and content of a given resource ID, the repository can just
        // answer what it has already stored.
        AndroidIdeInfo androidIdeInfo = dependencyTarget.androidIdeInfo;
        if (androidIdeInfo != null && !Strings.isNullOrEmpty(androidIdeInfo.resourceJavaPackage) && repository != null) {
            ResourceClassRegistry.get(module.getProject()).addLibrary(repository, androidIdeInfo.resourceJavaPackage);
        }
    }
    return results.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) AndroidResourceModuleRegistry(com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry) AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) AndroidIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidIdeInfo) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap)

Example 5 with TargetKey

use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.

the class SourceToTargetMapImpl method computeSourceToTargetMap.

@SuppressWarnings("unused")
private static ImmutableMultimap<File, TargetKey> computeSourceToTargetMap(Project project, BlazeProjectData blazeProjectData) {
    ArtifactLocationDecoder artifactLocationDecoder = blazeProjectData.artifactLocationDecoder;
    ImmutableMultimap.Builder<File, TargetKey> sourceToTargetMap = ImmutableMultimap.builder();
    for (TargetIdeInfo target : blazeProjectData.targetMap.targets()) {
        TargetKey key = target.key;
        for (ArtifactLocation sourceArtifact : target.sources) {
            sourceToTargetMap.put(artifactLocationDecoder.decode(sourceArtifact), key);
        }
    }
    return sourceToTargetMap.build();
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) File(java.io.File)

Aggregations

TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)52 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)25 File (java.io.File)19 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)14 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)14 Nullable (javax.annotation.Nullable)12 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)11 List (java.util.List)11 Test (org.junit.Test)11 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)9 Project (com.intellij.openapi.project.Project)9 Map (java.util.Map)9 ImmutableList (com.google.common.collect.ImmutableList)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 Collection (java.util.Collection)8 Set (java.util.Set)8 Sets (com.google.common.collect.Sets)7 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)7 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)7 ExecutionException (java.util.concurrent.ExecutionException)7