Search in sources :

Example 6 with JavaSdk

use of com.intellij.openapi.projectRoots.JavaSdk in project intellij-community by JetBrains.

the class JavaProjectDataService method importData.

@Override
public void importData(@NotNull final Collection<DataNode<JavaProjectData>> toImport, @Nullable final ProjectData projectData, @NotNull final Project project, @NotNull final IdeModifiableModelsProvider modelsProvider) {
    if (toImport.isEmpty() || projectData == null) {
        return;
    }
    if (toImport.size() != 1) {
        throw new IllegalArgumentException(String.format("Expected to get a single project but got %d: %s", toImport.size(), toImport));
    }
    final DataNode<JavaProjectData> javaProjectDataNode = toImport.iterator().next();
    final DataNode<ProjectData> projectDataNode = ExternalSystemApiUtil.findParent(javaProjectDataNode, ProjectKeys.PROJECT);
    assert projectDataNode != null;
    if (!ExternalSystemApiUtil.isOneToOneMapping(project, projectDataNode.getData())) {
        return;
    }
    JavaProjectData javaProjectData = javaProjectDataNode.getData();
    // JDK.
    JavaSdkVersion version = javaProjectData.getJdkVersion();
    JavaSdk javaSdk = JavaSdk.getInstance();
    ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
    Sdk sdk = rootManager.getProjectSdk();
    if (sdk != null) {
        JavaSdkVersion currentVersion = javaSdk.getVersion(sdk);
        if (currentVersion == null || !currentVersion.isAtLeast(version)) {
            updateSdk(project, version);
        }
    } else {
        updateSdk(project, version);
    }
    // Language level.
    setLanguageLevel(javaProjectData.getLanguageLevel(), project);
}
Also used : JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 7 with JavaSdk

use of com.intellij.openapi.projectRoots.JavaSdk in project android by JetBrains.

the class AndroidTreeStructureProvider method modify.

@Override
@NotNull
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    Project project = parent.getProject();
    if (project != null && AndroidProjectInfo.getInstance(project).requiresAndroidModel()) {
        if (parent instanceof NamedLibraryElementNode) {
            NamedLibraryElement value = ((NamedLibraryElementNode) parent).getValue();
            LibraryOrSdkOrderEntry orderEntry = value.getOrderEntry();
            if (orderEntry instanceof JdkOrderEntry) {
                Sdk sdk = ((JdkOrderEntry) orderEntry).getJdk();
                if (sdk.getSdkType() instanceof JavaSdk) {
                    List<AbstractTreeNode> newChildren = Lists.newArrayList();
                    for (AbstractTreeNode child : children) {
                        if (isRtJar(child)) {
                            newChildren.add(child);
                        }
                    }
                    if (!newChildren.isEmpty()) {
                        myEventDispatcher.getMulticaster().nodeChanged(parent, newChildren);
                        return newChildren;
                    }
                }
            }
        } else if (isRtJar(parent)) {
            List<AbstractTreeNode> newChildren = Lists.newArrayList();
            for (AbstractTreeNode child : children) {
                if (child instanceof PsiDirectoryNode) {
                    VirtualFile file = ((PsiDirectoryNode) child).getVirtualFile();
                    if (file != null && ("java".equals(file.getName()) || "javax".equals(file.getName()))) {
                        newChildren.add(child);
                    }
                }
            }
            if (!newChildren.isEmpty()) {
                myEventDispatcher.getMulticaster().nodeChanged(parent, newChildren);
                return newChildren;
            }
        }
    }
    return children;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) NamedLibraryElement(com.intellij.ide.projectView.impl.nodes.NamedLibraryElement) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) LibraryOrSdkOrderEntry(com.intellij.openapi.roots.LibraryOrSdkOrderEntry) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) List(java.util.List) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) NamedLibraryElementNode(com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with JavaSdk

use of com.intellij.openapi.projectRoots.JavaSdk in project android by JetBrains.

the class RenderErrorContributor method isBuiltByJdk7OrHigher.

static boolean isBuiltByJdk7OrHigher(@NotNull Module module) {
    Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    if (sdk == null) {
        return false;
    }
    AndroidSdks androidSdks = AndroidSdks.getInstance();
    if (androidSdks.isAndroidSdk(sdk)) {
        AndroidSdkAdditionalData data = androidSdks.getAndroidSdkAdditionalData(sdk);
        if (data != null) {
            Sdk jdk = data.getJavaSdk();
            if (jdk != null) {
                sdk = jdk;
            }
        }
    }
    return sdk.getSdkType() instanceof JavaSdk && JavaSdk.getInstance().isOfVersionOrHigher(sdk, JavaSdkVersion.JDK_1_7);
}
Also used : AndroidSdks(com.android.tools.idea.sdk.AndroidSdks) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 9 with JavaSdk

use of com.intellij.openapi.projectRoots.JavaSdk in project android by JetBrains.

the class NewModuleWizardTest method collectAllowedRoots.

@Override
protected void collectAllowedRoots(final List<String> roots) throws IOException {
    JavaSdk javaSdk = JavaSdk.getInstance();
    final List<String> jdkPaths = Lists.newArrayList(javaSdk.suggestHomePaths());
    jdkPaths.add(SystemProperties.getJavaHome());
    roots.addAll(jdkPaths);
    for (final String jdkPath : jdkPaths) {
        FileUtil.processFilesRecursively(new File(jdkPath), file -> {
            try {
                String path = file.getCanonicalPath();
                if (!FileUtil.isAncestor(jdkPath, path, false)) {
                    roots.add(path);
                }
            } catch (IOException ignore) {
            }
            return true;
        });
    }
}
Also used : JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) IOException(java.io.IOException) File(java.io.File)

Aggregations

JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)9 Sdk (com.intellij.openapi.projectRoots.Sdk)8 JavaSdkVersion (com.intellij.openapi.projectRoots.JavaSdkVersion)4 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 AndroidTargetManager (com.android.sdklib.repository.targets.AndroidTargetManager)1 AndroidSdks (com.android.tools.idea.sdk.AndroidSdks)1 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)1 CantRunException (com.intellij.execution.CantRunException)1 NamedLibraryElement (com.intellij.ide.projectView.impl.nodes.NamedLibraryElement)1 NamedLibraryElementNode (com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode)1 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)1 JavaSdkType (com.intellij.openapi.projectRoots.JavaSdkType)1 JdkOrderEntry (com.intellij.openapi.roots.JdkOrderEntry)1 LibraryOrSdkOrderEntry (com.intellij.openapi.roots.LibraryOrSdkOrderEntry)1 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1