Search in sources :

Example 51 with TargetIdeInfo

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

the class BlazeIdeInterfaceAspectsImplTest method testTargetIdeInfoIsSerializable.

@Test
public void testTargetIdeInfoIsSerializable() {
    IntellijIdeInfo.TargetIdeInfo ideProto = IntellijIdeInfo.TargetIdeInfo.newBuilder().setLabel("//test:test").setKindString("android_binary").addDependencies("//test:dep").addTags("tag").setJavaIdeInfo(IntellijIdeInfo.JavaIdeInfo.newBuilder().addJars(IntellijIdeInfo.LibraryArtifact.newBuilder().setJar(artifactLocation("jar.jar")).build()).addGeneratedJars(IntellijIdeInfo.LibraryArtifact.newBuilder().setJar(artifactLocation("jar.jar")).build()).addSources(artifactLocation("source.java"))).setAndroidIdeInfo(IntellijIdeInfo.AndroidIdeInfo.newBuilder().addResources(artifactLocation("res")).setApk(artifactLocation("apk")).addDependencyApk(artifactLocation("apk")).setJavaPackage("package")).build();
    TargetIdeInfo target = IdeInfoFromProtobuf.makeTargetIdeInfo(ideProto);
    TestUtils.assertIsSerializable(target);
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) IntellijIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo) Test(org.junit.Test)

Example 52 with TargetIdeInfo

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

the class IdeInfoFromProtobuf method makeTargetIdeInfo.

@Nullable
public static TargetIdeInfo makeTargetIdeInfo(IntellijIdeInfo.TargetIdeInfo message) {
    Kind kind = getKind(message);
    if (kind == null) {
        return null;
    }
    TargetKey key = getKey(message);
    ArtifactLocation buildFile = getBuildFile(message);
    final Collection<Dependency> dependencies;
    if (message.getDepsCount() > 0) {
        dependencies = message.getDepsList().stream().map(IdeInfoFromProtobuf::makeDependency).collect(toList());
    } else {
        dependencies = Lists.newArrayListWithCapacity(message.getDependenciesCount() + message.getRuntimeDepsCount());
        dependencies.addAll(makeDependencyListFromLabelList(message.getDependenciesList(), DependencyType.COMPILE_TIME));
        dependencies.addAll(makeDependencyListFromLabelList(message.getRuntimeDepsList(), DependencyType.RUNTIME));
    }
    Collection<String> tags = ImmutableList.copyOf(message.getTagsList());
    Collection<ArtifactLocation> sources = Lists.newArrayList();
    CIdeInfo cIdeInfo = null;
    if (message.hasCIdeInfo()) {
        cIdeInfo = makeCIdeInfo(message.getCIdeInfo());
        sources.addAll(cIdeInfo.sources);
        sources.addAll(cIdeInfo.headers);
        sources.addAll(cIdeInfo.textualHeaders);
    }
    CToolchainIdeInfo cToolchainIdeInfo = null;
    if (message.hasCToolchainIdeInfo()) {
        cToolchainIdeInfo = makeCToolchainIdeInfo(message.getCToolchainIdeInfo());
    }
    JavaIdeInfo javaIdeInfo = null;
    if (message.hasJavaIdeInfo()) {
        javaIdeInfo = makeJavaIdeInfo(message.getJavaIdeInfo());
        Collection<ArtifactLocation> javaSources = makeArtifactLocationList(message.getJavaIdeInfo().getSourcesList());
        sources.addAll(javaSources);
    }
    AndroidIdeInfo androidIdeInfo = null;
    if (message.hasAndroidIdeInfo()) {
        androidIdeInfo = makeAndroidIdeInfo(message.getAndroidIdeInfo());
    }
    AndroidSdkIdeInfo androidSdkIdeInfo = null;
    if (message.hasAndroidSdkIdeInfo()) {
        androidSdkIdeInfo = makeAndroidSdkIdeInfo(message.getAndroidSdkIdeInfo());
    }
    AndroidAarIdeInfo androidAarIdeInfo = null;
    if (message.hasAndroidAarIdeInfo()) {
        androidAarIdeInfo = makeAndroidAarIdeInfo(message.getAndroidAarIdeInfo());
    }
    PyIdeInfo pyIdeInfo = null;
    if (message.hasPyIdeInfo()) {
        pyIdeInfo = makePyIdeInfo(message.getPyIdeInfo());
        sources.addAll(pyIdeInfo.sources);
    }
    GoIdeInfo goIdeInfo = null;
    if (message.hasGoIdeInfo()) {
        goIdeInfo = makeGoIdeInfo(message.getGoIdeInfo());
        sources.addAll(goIdeInfo.sources);
    }
    JsIdeInfo jsIdeInfo = null;
    if (message.hasJsIdeInfo()) {
        jsIdeInfo = makeJsIdeInfo(message.getJsIdeInfo());
        sources.addAll(jsIdeInfo.sources);
    }
    TsIdeInfo tsIdeInfo = null;
    if (message.hasTsIdeInfo()) {
        tsIdeInfo = makeTsIdeInfo(message.getTsIdeInfo());
        sources.addAll(tsIdeInfo.sources);
    }
    DartIdeInfo dartIdeInfo = null;
    if (message.hasDartIdeInfo()) {
        dartIdeInfo = makeDartIdeInfo(message.getDartIdeInfo());
        sources.addAll(dartIdeInfo.sources);
    }
    TestIdeInfo testIdeInfo = null;
    if (message.hasTestInfo()) {
        testIdeInfo = makeTestIdeInfo(message.getTestInfo());
    }
    ProtoLibraryLegacyInfo protoLibraryLegacyInfo = null;
    if (message.hasProtoLibraryLegacyJavaIdeInfo()) {
        protoLibraryLegacyInfo = makeProtoLibraryLegacyInfo(message.getProtoLibraryLegacyJavaIdeInfo());
    }
    JavaToolchainIdeInfo javaToolchainIdeInfo = null;
    if (message.hasJavaToolchainIdeInfo()) {
        javaToolchainIdeInfo = makeJavaToolchainIdeInfo(message.getJavaToolchainIdeInfo());
    }
    return new TargetIdeInfo(key, kind, buildFile, dependencies, tags, sources, cIdeInfo, cToolchainIdeInfo, javaIdeInfo, androidIdeInfo, androidSdkIdeInfo, androidAarIdeInfo, pyIdeInfo, goIdeInfo, jsIdeInfo, tsIdeInfo, dartIdeInfo, testIdeInfo, protoLibraryLegacyInfo, javaToolchainIdeInfo);
}
Also used : TsIdeInfo(com.google.idea.blaze.base.ideinfo.TsIdeInfo) PyIdeInfo(com.google.idea.blaze.base.ideinfo.PyIdeInfo) JsIdeInfo(com.google.idea.blaze.base.ideinfo.JsIdeInfo) GoIdeInfo(com.google.idea.blaze.base.ideinfo.GoIdeInfo) Dependency(com.google.idea.blaze.base.ideinfo.Dependency) DartIdeInfo(com.google.idea.blaze.base.ideinfo.DartIdeInfo) TestIdeInfo(com.google.idea.blaze.base.ideinfo.TestIdeInfo) ProtoLibraryLegacyInfo(com.google.idea.blaze.base.ideinfo.ProtoLibraryLegacyInfo) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) JavaToolchainIdeInfo(com.google.idea.blaze.base.ideinfo.JavaToolchainIdeInfo) CToolchainIdeInfo(com.google.idea.blaze.base.ideinfo.CToolchainIdeInfo) AndroidAarIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidAarIdeInfo) Kind(com.google.idea.blaze.base.model.primitives.Kind) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) CIdeInfo(com.google.idea.blaze.base.ideinfo.CIdeInfo) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) AndroidIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidIdeInfo) AndroidSdkIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidSdkIdeInfo) Nullable(javax.annotation.Nullable)

Example 53 with TargetIdeInfo

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

the class AddLibraryTargetDirectoryToProjectViewAction method getDirectoryToAddForLibrary.

@Nullable
static WorkspacePath getDirectoryToAddForLibrary(Project project, Library library) {
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return null;
    }
    BlazeJarLibrary blazeLibrary = LibraryActionHelper.findLibraryFromIntellijLibrary(project, blazeProjectData, library);
    if (blazeLibrary == null) {
        return null;
    }
    TargetKey originatingTarget = findOriginatingTargetForLibrary(blazeProjectData, blazeLibrary);
    if (originatingTarget == null) {
        return null;
    }
    TargetIdeInfo target = blazeProjectData.targetMap.get(originatingTarget);
    if (target == null) {
        return null;
    }
    // It makes no sense to add directories for java_imports and the like
    if (!target.kind.isOneOf(Kind.JAVA_LIBRARY, Kind.ANDROID_LIBRARY, Kind.PROTO_LIBRARY)) {
        return null;
    }
    if (target.buildFile == null) {
        return null;
    }
    File buildFile = new File(target.buildFile.getRelativePath());
    WorkspacePath workspacePath = new WorkspacePath(Strings.nullToEmpty(buildFile.getParent()));
    ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
    if (projectViewSet == null) {
        return null;
    }
    boolean exists = WorkspacePathUtil.isUnderAnyWorkspacePath(projectViewSet.listItems(DirectorySection.KEY).stream().filter(entry -> entry.included).map(entry -> entry.directory).collect(toList()), workspacePath);
    if (exists) {
        return null;
    }
    return workspacePath;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) DirectorySection(com.google.idea.blaze.base.projectview.section.sections.DirectorySection) Presentation(com.intellij.openapi.actionSystem.Presentation) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) BlazeProjectAction(com.google.idea.blaze.base.actions.BlazeProjectAction) Strings(com.google.common.base.Strings) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) Library(com.intellij.openapi.roots.libraries.Library) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ImmutableList(com.google.common.collect.ImmutableList) BlazeSyncManager(com.google.idea.blaze.base.sync.BlazeSyncManager) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) Nullable(javax.annotation.Nullable) WorkspacePathUtil(com.google.idea.blaze.base.util.WorkspacePathUtil) Set(java.util.Set) Sets(com.google.common.collect.Sets) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ProjectViewEdit(com.google.idea.blaze.base.projectview.ProjectViewEdit) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) BlazeUserSettings(com.google.idea.blaze.base.settings.BlazeUserSettings) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ListSection(com.google.idea.blaze.base.projectview.section.ListSection) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 54 with TargetIdeInfo

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

the class BlazeGoRootsProvider method createGoPathSourceRoot.

/**
 * Creates the .gopath root under the project data directory. Then {@link #createSymLinks} for
 * each go target discovered in the target map into the root directory.
 */
public static synchronized void createGoPathSourceRoot(Project project, BlazeProjectData projectData) {
    File goRoot = getGoRoot(project);
    if (goRoot == null) {
        return;
    }
    FileOperationProvider provider = FileOperationProvider.getInstance();
    if (provider.exists(goRoot)) {
        try {
            provider.deleteRecursively(goRoot);
        } catch (IOException e) {
            logger.error(e);
            return;
        }
    }
    if (!provider.mkdirs(goRoot)) {
        logger.error("Failed to create " + goRoot);
        return;
    }
    ArtifactLocationDecoder decoder = projectData.artifactLocationDecoder;
    for (TargetIdeInfo target : projectData.targetMap.targets()) {
        if (target.goIdeInfo == null || target.goIdeInfo.importPath == null) {
            continue;
        }
        String importPath = target.goIdeInfo.importPath;
        createSymLinks(goRoot, importPath, getGoSources(target, decoder, projectData.blazeInfo));
    }
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 55 with TargetIdeInfo

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

the class BlazeGoTestLocator method findTestPackage.

/**
 * @param path for "//foo/bar:baz" would be "foo/bar/baz".
 */
@SuppressWarnings("rawtypes")
private static List<Location> findTestPackage(Project project, String path) {
    TargetIdeInfo target = getGoTestTarget(project, path);
    if (target == null) {
        return ImmutableList.of();
    }
    // Exactly one source file, we'll go to the file.
    if (target.sources.size() == 1) {
        List<VirtualFile> goFiles = getGoFiles(project, target);
        if (!goFiles.isEmpty()) {
            PsiFile psiFile = PsiManager.getInstance(project).findFile(goFiles.get(0));
            if (psiFile != null) {
                return ImmutableList.of(new PsiLocation<>(psiFile));
            }
        }
    }
    // More than one source file or we failed to get one source file, we'll point to the rule.
    PsiElement rule = BuildReferenceManager.getInstance(project).resolveLabel(target.key.label);
    if (!(rule instanceof FuncallExpression)) {
        return ImmutableList.of();
    }
    Kind kind = ((FuncallExpression) rule).getRuleKind();
    if (kind != null && kind.languageClass.equals(LanguageClass.GO) && kind.ruleType.equals(RuleType.TEST)) {
        return ImmutableList.of(new PsiLocation<>(rule));
    }
    return ImmutableList.of();
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Kind(com.google.idea.blaze.base.model.primitives.Kind) PsiFile(com.intellij.psi.PsiFile) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) PsiElement(com.intellij.psi.PsiElement)

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