Search in sources :

Example 11 with JavaSdkVersion

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

the class JavaSuppressionUtil method canHave15Suppressions.

public static boolean canHave15Suppressions(@NotNull PsiElement file) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    if (module == null)
        return false;
    final Sdk jdk = ModuleRootManager.getInstance(module).getSdk();
    if (jdk == null)
        return false;
    JavaSdkVersion version = getVersion(jdk);
    if (version == null)
        return false;
    final boolean is_1_5 = version.isAtLeast(JavaSdkVersion.JDK_1_5);
    return DaemonCodeAnalyzerSettings.getInstance().isSuppressWarnings() && is_1_5 && PsiUtil.isLanguageLevel5OrHigher(file);
}
Also used : JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Example 12 with JavaSdkVersion

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

the class DebuggerManagerImpl method checkTargetJPDAInstalled.

/* Remoting */
private static void checkTargetJPDAInstalled(JavaParameters parameters) throws ExecutionException {
    final Sdk jdk = parameters.getJdk();
    if (jdk == null) {
        throw new ExecutionException(DebuggerBundle.message("error.jdk.not.specified"));
    }
    final JavaSdkVersion version = JavaSdk.getInstance().getVersion(jdk);
    String versionString = jdk.getVersionString();
    if (version == JavaSdkVersion.JDK_1_0 || version == JavaSdkVersion.JDK_1_1) {
        throw new ExecutionException(DebuggerBundle.message("error.unsupported.jdk.version", versionString));
    }
    if (SystemInfo.isWindows && version == JavaSdkVersion.JDK_1_2) {
        final VirtualFile homeDirectory = jdk.getHomeDirectory();
        if (homeDirectory == null || !homeDirectory.isValid()) {
            throw new ExecutionException(DebuggerBundle.message("error.invalid.jdk.home", versionString));
        }
        //noinspection HardCodedStringLiteral
        File dllFile = new File(homeDirectory.getPath().replace('/', File.separatorChar) + File.separator + "bin" + File.separator + "jdwp.dll");
        if (!dllFile.exists()) {
            GetJPDADialog dialog = new GetJPDADialog();
            dialog.show();
            throw new ExecutionException(DebuggerBundle.message("error.debug.libraries.missing"));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) GetJPDADialog(com.intellij.debugger.ui.GetJPDADialog)

Example 13 with JavaSdkVersion

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

the class LanguageLevelCombo method sdkUpdated.

void sdkUpdated(Sdk sdk, boolean isDefaultProject) {
    LanguageLevel newLevel = null;
    if (sdk != null) {
        JavaSdkVersion version = JavaSdk.getInstance().getVersion(sdk);
        if (version != null) {
            newLevel = version.getMaxLanguageLevel();
        }
    }
    updateDefaultLevel(newLevel, isDefaultProject);
}
Also used : JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) LanguageLevel(com.intellij.pom.java.LanguageLevel)

Example 14 with JavaSdkVersion

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

the class CompilingEvaluatorImpl method compile.

@Override
@NotNull
protected Collection<ClassObject> compile(@Nullable JavaSdkVersion debuggeeVersion) throws EvaluateException {
    if (myCompiledClasses == null) {
        Module module = ReadAction.compute(() -> ModuleUtilCore.findModuleForPsiElement(myPsiContext));
        List<String> options = new ArrayList<>();
        options.add("-encoding");
        options.add("UTF-8");
        List<File> platformClasspath = new ArrayList<>();
        List<File> classpath = new ArrayList<>();
        AnnotationProcessingConfiguration profile = null;
        if (module != null) {
            assert myProject.equals(module.getProject()) : module + " is from another project";
            profile = CompilerConfiguration.getInstance(myProject).getAnnotationProcessingConfiguration(module);
            ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
            for (String s : rootManager.orderEntries().compileOnly().recursively().exportedOnly().withoutSdk().getPathsList().getPathList()) {
                classpath.add(new File(s));
            }
            for (String s : rootManager.orderEntries().compileOnly().sdkOnly().getPathsList().getPathList()) {
                platformClasspath.add(new File(s));
            }
        }
        JavaBuilder.addAnnotationProcessingOptions(options, profile);
        Pair<Sdk, JavaSdkVersion> runtime = BuildManager.getJavacRuntimeSdk(myProject);
        JavaSdkVersion buildRuntimeVersion = runtime.getSecond();
        // if compiler or debuggee version or both are unknown, let source and target be the compiler's defaults
        if (buildRuntimeVersion != null && debuggeeVersion != null) {
            JavaSdkVersion minVersion = buildRuntimeVersion.ordinal() > debuggeeVersion.ordinal() ? debuggeeVersion : buildRuntimeVersion;
            String sourceOption = getSourceOption(minVersion.getMaxLanguageLevel());
            options.add("-source");
            options.add(sourceOption);
            options.add("-target");
            options.add(sourceOption);
        }
        CompilerManager compilerManager = CompilerManager.getInstance(myProject);
        File sourceFile = null;
        try {
            sourceFile = generateTempSourceFile(compilerManager.getJavacCompilerWorkingDir());
            File srcDir = sourceFile.getParentFile();
            List<File> sourcePath = Collections.emptyList();
            Set<File> sources = Collections.singleton(sourceFile);
            myCompiledClasses = compilerManager.compileJavaCode(options, platformClasspath, classpath, Collections.emptyList(), sourcePath, sources, srcDir);
        } catch (CompilationException e) {
            StringBuilder res = new StringBuilder("Compilation failed:\n");
            for (CompilationException.Message m : e.getMessages()) {
                if (m.getCategory() == CompilerMessageCategory.ERROR) {
                    res.append(m.getText()).append("\n");
                }
            }
            throw new EvaluateException(res.toString());
        } catch (Exception e) {
            throw new EvaluateException(e.getMessage());
        } finally {
            if (sourceFile != null) {
                FileUtil.delete(sourceFile);
            }
        }
    }
    return myCompiledClasses;
}
Also used : CompilationException(com.intellij.openapi.compiler.CompilationException) JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) CompilerManager(com.intellij.openapi.compiler.CompilerManager) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) AnnotationProcessingConfiguration(org.jetbrains.jps.model.java.compiler.AnnotationProcessingConfiguration) CompilationException(com.intellij.openapi.compiler.CompilationException) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) IOException(java.io.IOException) PrepareFailedException(com.intellij.refactoring.extractMethod.PrepareFailedException) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with JavaSdkVersion

use of com.intellij.openapi.projectRoots.JavaSdkVersion 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)

Aggregations

JavaSdkVersion (com.intellij.openapi.projectRoots.JavaSdkVersion)18 Sdk (com.intellij.openapi.projectRoots.Sdk)13 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)10 Module (com.intellij.openapi.module.Module)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 File (java.io.File)5 JavaSdkType (com.intellij.openapi.projectRoots.JavaSdkType)3 LanguageLevel (com.intellij.pom.java.LanguageLevel)3 IOException (java.io.IOException)3 NotNull (org.jetbrains.annotations.NotNull)3 ExecutionException (com.intellij.execution.ExecutionException)2 Project (com.intellij.openapi.project.Project)2 Nullable (org.jetbrains.annotations.Nullable)2 JpsJavaSdkType (org.jetbrains.jps.model.java.JpsJavaSdkType)2 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 AndroidTargetManager (com.android.sdklib.repository.targets.AndroidTargetManager)1 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)1 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)1 CompilerConfiguration (com.intellij.compiler.CompilerConfiguration)1 CompilerWorkspaceConfiguration (com.intellij.compiler.CompilerWorkspaceConfiguration)1