Search in sources :

Example 26 with Sdk

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

the class GenerateBinaryStubsFix method isApplicable.

/**
   * Checks if this fix can help you to generate binary stubs
   *
   * @param importStatementBase statement to fix
   * @return true if this fix could work
   */
public static boolean isApplicable(@NotNull final PyImportStatementBase importStatementBase) {
    if (importStatementBase.getFullyQualifiedObjectNames().isEmpty() && !(importStatementBase instanceof PyFromImportStatement && ((PyFromImportStatement) importStatementBase).isStarImport())) {
        return false;
    }
    final Sdk sdk = getPythonSdk(importStatementBase);
    if (sdk == null) {
        return false;
    }
    final PythonSdkFlavor flavor = PythonSdkFlavor.getFlavor(sdk);
    if (flavor instanceof IronPythonSdkFlavor) {
        return true;
    }
    return isGtk(importStatementBase);
}
Also used : IronPythonSdkFlavor(com.jetbrains.python.sdk.flavors.IronPythonSdkFlavor) PythonSdkFlavor(com.jetbrains.python.sdk.flavors.PythonSdkFlavor) IronPythonSdkFlavor(com.jetbrains.python.sdk.flavors.IronPythonSdkFlavor) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 27 with Sdk

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

the class SkeletonTestTask method runTestOn.

@Override
public void runTestOn(@NotNull final String sdkHome) throws IOException, InvalidSdkException {
    final Sdk sdk = createTempSdk(sdkHome, SdkCreationType.SDK_PACKAGES_ONLY);
    final File skeletonsPath = new File(PythonSdkType.getSkeletonsPath(PathManager.getSystemPath(), sdk.getHomePath()));
    // File with module skeleton
    File skeletonFileOrDirectory = new File(skeletonsPath, myModuleNameToBeGenerated);
    // Module may be stored in "moduleName.py" or "moduleName/__init__.py"
    if (skeletonFileOrDirectory.isDirectory()) {
        skeletonFileOrDirectory = new File(skeletonFileOrDirectory, PyNames.INIT_DOT_PY);
    } else {
        skeletonFileOrDirectory = new File(skeletonFileOrDirectory.getAbsolutePath() + PyNames.DOT_PY);
    }
    final File skeletonFile = skeletonFileOrDirectory;
    if (skeletonFile.exists()) {
        // To make sure we do not reuse it
        assert skeletonFile.delete() : "Failed to delete file " + skeletonFile;
    }
    ApplicationManager.getApplication().invokeAndWait(() -> {
        // File that uses CLR library
        myFixture.copyFileToProject("dotNet/" + mySourceFileToRunGenerationOn, mySourceFileToRunGenerationOn);
        // Library itself
        myFixture.copyFileToProject("dotNet/PythonLibs.dll", "PythonLibs.dll");
        // Another library
        myFixture.copyFileToProject("dotNet/SingleNameSpace.dll", "SingleNameSpace.dll");
        myFixture.configureByFile(mySourceFileToRunGenerationOn);
    }, ModalityState.NON_MODAL);
    // This inspection should suggest us to generate stubs
    myFixture.enableInspections(PyUnresolvedReferencesInspection.class);
    UIUtil.invokeAndWaitIfNeeded(new Runnable() {

        @Override
        public void run() {
            PsiDocumentManager.getInstance(myFixture.getProject()).commitAllDocuments();
            final String intentionName = PyBundle.message("sdk.gen.stubs.for.binary.modules", myUseQuickFixWithThisModuleOnly);
            final IntentionAction intention = myFixture.findSingleIntention(intentionName);
            Assert.assertNotNull("No intention found to generate skeletons!", intention);
            Assert.assertThat("Intention should be quick fix to run", intention, Matchers.instanceOf(QuickFixWrapper.class));
            final LocalQuickFix quickFix = ((QuickFixWrapper) intention).getFix();
            Assert.assertThat("Quick fix should be 'generate binary skeletons' fix to run", quickFix, Matchers.instanceOf(GenerateBinaryStubsFix.class));
            final Task fixTask = ((GenerateBinaryStubsFix) quickFix).getFixTask(myFixture.getFile());
            fixTask.run(new AbstractProgressIndicatorBase());
        }
    });
    FileUtil.copy(skeletonFile, new File(myFixture.getTempDirPath(), skeletonFile.getName()));
    if (myExpectedSkeletonFile != null) {
        final String actual = StreamUtil.readText(new FileInputStream(skeletonFile), Charset.defaultCharset());
        final String skeletonText = StreamUtil.readText(new FileInputStream(new File(getTestDataPath(), myExpectedSkeletonFile)), Charset.defaultCharset());
        // TODO: Move to separate method ?
        if (!Matchers.equalToIgnoringWhiteSpace(removeGeneratorVersion(skeletonText)).matches(removeGeneratorVersion(actual))) {
            throw new FileComparisonFailure("asd", skeletonText, actual, skeletonFile.getAbsolutePath());
        }
    }
    myFixture.configureByFile(skeletonFile.getName());
}
Also used : Task(com.intellij.openapi.progress.Task) PyExecutionFixtureTestTask(com.jetbrains.env.PyExecutionFixtureTestTask) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) AbstractProgressIndicatorBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorBase) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) FileInputStream(java.io.FileInputStream) FileComparisonFailure(com.intellij.rt.execution.junit.FileComparisonFailure)

Example 28 with Sdk

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

the class Pep8ExternalAnnotator method collectInformation.

@Nullable
@Override
public State collectInformation(@NotNull PsiFile file) {
    VirtualFile vFile = file.getVirtualFile();
    if (vFile == null || vFile.getFileType() != PythonFileType.INSTANCE) {
        return null;
    }
    Sdk sdk = PythonSdkType.findLocalCPython(ModuleUtilCore.findModuleForPsiElement(file));
    if (sdk == null) {
        if (!myReportedMissingInterpreter) {
            myReportedMissingInterpreter = true;
            reportMissingInterpreter();
        }
        return null;
    }
    final String homePath = sdk.getHomePath();
    if (homePath == null) {
        if (!myReportedMissingInterpreter) {
            myReportedMissingInterpreter = true;
            LOG.info("Could not find home path for interpreter " + homePath);
        }
        return null;
    }
    final InspectionProfile profile = InspectionProjectProfileManager.getInstance(file.getProject()).getCurrentProfile();
    final HighlightDisplayKey key = HighlightDisplayKey.find(PyPep8Inspection.INSPECTION_SHORT_NAME);
    if (!profile.isToolEnabled(key, file)) {
        return null;
    }
    if (file instanceof PyFileImpl && !((PyFileImpl) file).isAcceptedFor(PyPep8Inspection.class)) {
        return null;
    }
    final PyPep8Inspection inspection = (PyPep8Inspection) profile.getUnwrappedTool(PyPep8Inspection.KEY.toString(), file);
    final CodeStyleSettings commonSettings = CodeStyleSettingsManager.getInstance(file.getProject()).getCurrentSettings();
    final PyCodeStyleSettings customSettings = commonSettings.getCustomSettings(PyCodeStyleSettings.class);
    final List<String> ignoredErrors = Lists.newArrayList(inspection.ignoredErrors);
    if (!customSettings.SPACE_AFTER_NUMBER_SIGN) {
        // Block comment should start with a space
        ignoredErrors.add("E262");
        // Inline comment should start with a space
        ignoredErrors.add("E265");
    }
    if (!customSettings.SPACE_BEFORE_NUMBER_SIGN) {
        // At least two spaces before inline comment
        ignoredErrors.add("E261");
    }
    final int margin = commonSettings.getRightMargin(file.getLanguage());
    return new State(homePath, file.getText(), profile.getErrorLevel(key, file), ignoredErrors, margin, customSettings.HANG_CLOSING_BRACKETS);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) PyCodeStyleSettings(com.jetbrains.python.formatter.PyCodeStyleSettings) InspectionProfile(com.intellij.codeInspection.InspectionProfile) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) PyCodeStyleSettings(com.jetbrains.python.formatter.PyCodeStyleSettings) Sdk(com.intellij.openapi.projectRoots.Sdk) PyFileImpl(com.jetbrains.python.psi.impl.PyFileImpl) PyPep8Inspection(com.jetbrains.python.inspections.PyPep8Inspection) Nullable(org.jetbrains.annotations.Nullable)

Example 29 with Sdk

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

the class MvcRunConfiguration method getState.

@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
    final Module module = getModule();
    if (module == null) {
        throw new ExecutionException("Module is not specified");
    }
    if (!isSupport(module)) {
        throw new ExecutionException(getNoSdkMessage());
    }
    final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    final Sdk sdk = rootManager.getSdk();
    if (sdk == null || !(sdk.getSdkType() instanceof JavaSdkType)) {
        throw CantRunException.noJdkForModule(module);
    }
    return createCommandLineState(environment, module);
}
Also used : JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Example 30 with Sdk

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

the class GriffonFramework method createJavaParameters.

@Override
public JavaParameters createJavaParameters(@NotNull Module module, boolean forCreation, boolean forTests, boolean classpathFromDependencies, @NotNull MvcCommand command) throws ExecutionException {
    JavaParameters params = new JavaParameters();
    Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    params.setJdk(sdk);
    final VirtualFile sdkRoot = getSdkRoot(module);
    if (sdkRoot == null) {
        return params;
    }
    params.addEnv(getSdkHomePropertyName(), FileUtil.toSystemDependentName(sdkRoot.getPath()));
    final VirtualFile lib = sdkRoot.findChild("lib");
    if (lib != null) {
        for (final VirtualFile child : lib.getChildren()) {
            final String name = child.getName();
            if (name.startsWith("groovy-all-") && name.endsWith(".jar")) {
                params.getClassPath().add(child);
            }
        }
    }
    final VirtualFile dist = sdkRoot.findChild("dist");
    if (dist != null) {
        for (final VirtualFile child : dist.getChildren()) {
            final String name = child.getName();
            if (name.endsWith(".jar")) {
                if (name.startsWith("griffon-cli-") || name.startsWith("griffon-rt-") || name.startsWith("griffon-resources-")) {
                    params.getClassPath().add(child);
                }
            }
        }
    }
    /////////////////////////////////////////////////////////////
    params.setMainClass("org.codehaus.griffon.cli.support.GriffonStarter");
    final VirtualFile rootFile;
    if (forCreation) {
        VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
        if (roots.length != 1) {
            throw new ExecutionException("Failed to initialize griffon module: module " + module.getName() + " contains more than one root");
        }
        command.getArgs().add(0, roots[0].getName());
        rootFile = roots[0].getParent();
    } else {
        rootFile = findAppRoot(module);
        if (rootFile == null) {
            throw new ExecutionException("Failed to run griffon command: module " + module.getName() + " is not a Griffon module");
        }
    }
    String workDir = VfsUtilCore.virtualToIoFile(rootFile).getAbsolutePath();
    params.getVMParametersList().addParametersString(command.getVmOptions());
    if (!params.getVMParametersList().getParametersString().contains(XMX_JVM_PARAMETER)) {
        params.getVMParametersList().add("-Xmx256M");
    }
    final String griffonHomePath = FileUtil.toSystemDependentName(sdkRoot.getPath());
    params.getVMParametersList().add("-Dgriffon.home=" + griffonHomePath);
    params.getVMParametersList().add("-Dbase.dir=" + workDir);
    assert sdk != null;
    params.getVMParametersList().add("-Dtools.jar=" + ((JavaSdkType) sdk.getSdkType()).getToolsPath(sdk));
    final String confpath = griffonHomePath + GROOVY_STARTER_CONF;
    params.getVMParametersList().add("-Dgroovy.starter.conf=" + confpath);
    params.getVMParametersList().add("-Dgroovy.sanitized.stacktraces=\"groovy., org.codehaus.groovy., java., javax., sun., gjdk.groovy., gant., org.codehaus.gant.\"");
    params.getProgramParametersList().add("--main");
    params.getProgramParametersList().add("org.codehaus.griffon.cli.GriffonScriptRunner");
    params.getProgramParametersList().add("--conf");
    params.getProgramParametersList().add(confpath);
    if (!forCreation && classpathFromDependencies) {
        final String path = getApplicationClassPath(module).getPathsString();
        if (StringUtil.isNotEmpty(path)) {
            params.getProgramParametersList().add("--classpath");
            params.getProgramParametersList().add(path);
        }
    }
    params.setWorkingDirectory(workDir);
    ParametersList paramList = new ParametersList();
    command.addToParametersList(paramList);
    params.getProgramParametersList().add(paramList.getParametersString());
    params.setDefaultCharset(module.getProject());
    return params;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) ParametersList(com.intellij.execution.configurations.ParametersList) JavaParameters(com.intellij.execution.configurations.JavaParameters) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException)

Aggregations

Sdk (com.intellij.openapi.projectRoots.Sdk)437 VirtualFile (com.intellij.openapi.vfs.VirtualFile)105 Module (com.intellij.openapi.module.Module)85 Nullable (org.jetbrains.annotations.Nullable)63 File (java.io.File)56 Project (com.intellij.openapi.project.Project)49 NotNull (org.jetbrains.annotations.NotNull)43 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)37 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)34 ExecutionException (com.intellij.execution.ExecutionException)20 ModifiableFlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)19 ArrayList (java.util.ArrayList)18 ProjectJdkTable (com.intellij.openapi.projectRoots.ProjectJdkTable)17 IOException (java.io.IOException)16 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)16 IAndroidTarget (com.android.sdklib.IAndroidTarget)14 JavaSdkType (com.intellij.openapi.projectRoots.JavaSdkType)14 Library (com.intellij.openapi.roots.libraries.Library)14 JavaSdkVersion (com.intellij.openapi.projectRoots.JavaSdkVersion)13 BuildConfigurationNature (com.intellij.flex.model.bc.BuildConfigurationNature)11