Search in sources :

Example 1 with SdkTypeId

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

the class AntCommandLineBuilder method setBuildFile.

public void setBuildFile(AbstractProperty.AbstractPropertyContainer container, File buildFile) throws CantRunException {
    String jdkName = AntBuildFileImpl.CUSTOM_JDK_NAME.get(container);
    Sdk jdk;
    if (jdkName != null && jdkName.length() > 0) {
        jdk = GlobalAntConfiguration.findJdk(jdkName);
    } else {
        jdkName = AntConfigurationImpl.DEFAULT_JDK_NAME.get(container);
        if (jdkName == null || jdkName.length() == 0) {
            throw new CantRunException(AntBundle.message("project.jdk.not.specified.error.message"));
        }
        jdk = GlobalAntConfiguration.findJdk(jdkName);
    }
    if (jdk == null) {
        throw new CantRunException(AntBundle.message("jdk.with.name.not.configured.error.message", jdkName));
    }
    VirtualFile homeDirectory = jdk.getHomeDirectory();
    if (homeDirectory == null) {
        throw new CantRunException(AntBundle.message("jdk.with.name.bad.configured.error.message", jdkName));
    }
    myCommandLine.setJdk(jdk);
    final ParametersList vmParametersList = myCommandLine.getVMParametersList();
    vmParametersList.add("-Xmx" + AntBuildFileImpl.MAX_HEAP_SIZE.get(container) + "m");
    vmParametersList.add("-Xss" + AntBuildFileImpl.MAX_STACK_SIZE.get(container) + "m");
    final AntInstallation antInstallation = AntBuildFileImpl.ANT_INSTALLATION.get(container);
    if (antInstallation == null) {
        throw new CantRunException(AntBundle.message("ant.installation.not.configured.error.message"));
    }
    final String antHome = AntInstallation.HOME_DIR.get(antInstallation.getProperties());
    vmParametersList.add("-Dant.home=" + antHome);
    final String libraryDir = antHome + (antHome.endsWith("/") || antHome.endsWith(File.separator) ? "" : File.separator) + "lib";
    vmParametersList.add("-Dant.library.dir=" + libraryDir);
    String[] urls = jdk.getRootProvider().getUrls(OrderRootType.CLASSES);
    final String jdkHome = homeDirectory.getPath().replace('/', File.separatorChar);
    @NonNls final String pathToJre = jdkHome + File.separator + "jre" + File.separator;
    for (String url : urls) {
        final String path = PathUtil.toPresentableUrl(url);
        if (!path.startsWith(pathToJre)) {
            myCommandLine.getClassPath().add(path);
        }
    }
    myCommandLine.getClassPath().addAllFiles(AntBuildFileImpl.ALL_CLASS_PATH.get(container));
    myCommandLine.getClassPath().addAllFiles(AntBuildFileImpl.getUserHomeLibraries());
    final SdkTypeId sdkType = jdk.getSdkType();
    if (sdkType instanceof JavaSdkType) {
        final String toolsJar = ((JavaSdkType) sdkType).getToolsPath(jdk);
        if (toolsJar != null) {
            myCommandLine.getClassPath().add(toolsJar);
        }
    }
    PathUtilEx.addRtJar(myCommandLine.getClassPath());
    myCommandLine.setMainClass(AntMain2.class.getName());
    final ParametersList programParameters = myCommandLine.getProgramParametersList();
    final String additionalParams = AntBuildFileImpl.ANT_COMMAND_LINE_PARAMETERS.get(container);
    if (additionalParams != null) {
        for (String param : ParametersList.parse(additionalParams)) {
            if (param.startsWith("-J")) {
                final String cutParam = param.substring("-J".length());
                if (cutParam.length() > 0) {
                    vmParametersList.add(cutParam);
                }
            } else {
                programParameters.add(param);
            }
        }
    }
    if (!(programParameters.getList().contains(LOGGER_PARAMETER))) {
        programParameters.add(LOGGER_PARAMETER, IdeaAntLogger2.class.getName());
    }
    if (!programParameters.getList().contains(INPUT_HANDLER_PARAMETER)) {
        programParameters.add(INPUT_HANDLER_PARAMETER, IdeaInputHandler.class.getName());
    }
    myProperties = AntBuildFileImpl.ANT_PROPERTIES.get(container);
    myBuildFilePath = buildFile.getAbsolutePath();
    myCommandLine.setWorkingDirectory(buildFile.getParent());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonNls(org.jetbrains.annotations.NonNls) IdeaInputHandler(com.intellij.rt.ant.execution.IdeaInputHandler) AntMain2(com.intellij.rt.ant.execution.AntMain2) JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) CantRunException(com.intellij.execution.CantRunException) IdeaAntLogger2(com.intellij.rt.ant.execution.IdeaAntLogger2) ParametersList(com.intellij.execution.configurations.ParametersList) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId)

Example 2 with SdkTypeId

use of com.intellij.openapi.projectRoots.SdkTypeId in project intellij-plugins by JetBrains.

the class FlexSdkComboBoxWithBrowseButton method rebuildSdkListAndSelectSdk.

private void rebuildSdkListAndSelectSdk(@Nullable final Sdk selectedSdk) {
    final String previousSelectedSdkName = getSelectedSdkRaw();
    final List<Object> sdkList = new ArrayList<>();
    if (myShowBCSdk) {
        sdkList.add(myBCSdk);
    }
    final Sdk[] sdks = FlexSdkUtils.getAllSdks();
    for (final Sdk sdk : sdks) {
        if (mySdkFilter.value(sdk)) {
            sdkList.add(sdk);
        }
    }
    if (!sdkList.isEmpty()) {
        // sort by version descending, Flexmojos SDKs - to the end of the list
        Collections.sort(sdkList, (sdk1, sdk2) -> {
            if (sdk1 == myBCSdk && sdk2 != myBCSdk)
                return -1;
            if (sdk1 != myBCSdk && sdk2 == myBCSdk)
                return 1;
            if (sdk1 instanceof Sdk && sdk2 instanceof Sdk) {
                final SdkTypeId type1 = ((Sdk) sdk1).getSdkType();
                final SdkTypeId type2 = ((Sdk) sdk2).getSdkType();
                if (type1 == type2)
                    return -StringUtil.compareVersionNumbers(((Sdk) sdk1).getVersionString(), ((Sdk) sdk2).getVersionString());
                if (type1 == FlexSdkType2.getInstance())
                    return -1;
                if (type2 == FlexSdkType2.getInstance())
                    return 1;
            }
            return 0;
        });
        getComboBox().setModel(new DefaultComboBoxModel(ArrayUtil.toObjectArray(sdkList)));
        if (selectedSdk != null) {
            setSelectedSdkRaw(selectedSdk.getName(), false);
        } else if (previousSelectedSdkName != null) {
            setSelectedSdkRaw(previousSelectedSdkName, false);
        }
    } else {
        getComboBox().setModel(new DefaultComboBoxModel(new Object[] { null }));
    }
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId)

Example 3 with SdkTypeId

use of com.intellij.openapi.projectRoots.SdkTypeId in project intellij-plugins by JetBrains.

the class DependenciesConfigurable method createUIComponents.

private void createUIComponents() {
    final Condition<SdkTypeId> sdkTypeFilter = Conditions.oneOf(FlexSdkType2.getInstance(), FlexmojosSdkType.getInstance());
    Condition<Sdk> sdkCondition = JdkComboBox.getSdkFilter(sdkTypeFilter);
    mySdkCombo = new JdkComboBox(mySkdsModel, sdkTypeFilter, sdkCondition, Conditions.is(FlexSdkType2.getInstance()), false);
}
Also used : SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId) Sdk(com.intellij.openapi.projectRoots.Sdk) JdkComboBox(com.intellij.openapi.roots.ui.configuration.JdkComboBox)

Example 4 with SdkTypeId

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

the class BuildPropertiesImpl method createJdkGenerators.

protected void createJdkGenerators(final Project project) {
    final Sdk[] jdks = getUsedJdks(project);
    if (jdks.length > 0) {
        add(new Comment(CompilerBundle.message("generated.ant.build.jdk.definitions.comment")), 1);
        for (final Sdk jdk : jdks) {
            if (jdk.getHomeDirectory() == null) {
                continue;
            }
            final SdkTypeId sdkType = jdk.getSdkType();
            if (!(sdkType instanceof JavaSdkType) || ((JavaSdkType) sdkType).getBinPath(jdk) == null) {
                continue;
            }
            final File home = VfsUtil.virtualToIoFile(jdk.getHomeDirectory());
            File homeDir;
            try {
                // use canonical path in order to resolve symlinks
                homeDir = home.getCanonicalFile();
            } catch (IOException e) {
                homeDir = home;
            }
            final String jdkName = jdk.getName();
            final String jdkHomeProperty = getJdkHomeProperty(jdkName);
            final FileSet fileSet = new FileSet(propertyRef(jdkHomeProperty));
            final String[] urls = jdk.getRootProvider().getUrls(OrderRootType.CLASSES);
            for (String url : urls) {
                final String path = GenerationUtils.trimJarSeparator(VirtualFileManager.extractPath(url));
                final File pathElement = new File(path);
                final String relativePath = FileUtil.getRelativePath(homeDir, pathElement);
                if (relativePath != null) {
                    fileSet.add(new Include(relativePath.replace(File.separatorChar, '/')));
                }
            }
            final File binPath = toCanonicalFile(new File(((JavaSdkType) sdkType).getBinPath(jdk)));
            final String relativePath = FileUtil.getRelativePath(homeDir, binPath);
            if (relativePath != null) {
                add(new Property(BuildProperties.getJdkBinProperty(jdkName), propertyRef(jdkHomeProperty) + "/" + FileUtil.toSystemIndependentName(relativePath)), 1);
            } else {
                add(new Property(BuildProperties.getJdkBinProperty(jdkName), FileUtil.toSystemIndependentName(binPath.getPath())), 1);
            }
            final Path jdkPath = new Path(getJdkPathId(jdkName));
            jdkPath.add(fileSet);
            add(jdkPath);
        }
    }
    final Sdk projectJdk = ProjectRootManager.getInstance(project).getProjectSdk();
    add(new Property(PROPERTY_PROJECT_JDK_HOME, projectJdk != null ? propertyRef(getJdkHomeProperty(projectJdk.getName())) : ""), 1);
    add(new Property(PROPERTY_PROJECT_JDK_BIN, projectJdk != null ? propertyRef(getJdkBinProperty(projectJdk.getName())) : ""));
    add(new Property(PROPERTY_PROJECT_JDK_CLASSPATH, projectJdk != null ? getJdkPathId(projectJdk.getName()) : ""));
}
Also used : IOException(java.io.IOException) JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId) File(java.io.File)

Example 5 with SdkTypeId

use of com.intellij.openapi.projectRoots.SdkTypeId in project intellij-elixir by KronicDeth.

the class MixExUnitRunConfigurationProducer method setupConfigurationFromContextImpl.

private boolean setupConfigurationFromContextImpl(@NotNull MixExUnitRunConfiguration configuration, @NotNull PsiElement psiElement) {
    boolean contextApplicable = false;
    if (psiElement instanceof PsiDirectory) {
        PsiDirectory psiDirectory = (PsiDirectory) psiElement;
        Module module = ModuleUtilCore.findModuleForPsiElement(psiDirectory);
        Sdk sdk;
        if (module != null) {
            ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
            sdk = moduleRootManager.getSdk();
        } else {
            ProjectRootManager projectRootManager = ProjectRootManager.getInstance(psiDirectory.getProject());
            sdk = projectRootManager.getProjectSdk();
        }
        SdkTypeId sdkTypeId = null;
        if (sdk != null) {
            sdkTypeId = sdk.getSdkType();
        }
        if ((sdkTypeId == null || sdkTypeId.equals(ElixirSdkType.getInstance())) && ProjectRootsUtil.isInTestSource(psiDirectory.getVirtualFile(), psiDirectory.getProject())) {
            String basePath = psiElement.getProject().getBasePath();
            String workingDirectory = workingDirectory(psiElement, basePath);
            configuration.setWorkingDirectory(workingDirectory);
            PsiDirectory dir = (PsiDirectory) psiElement;
            configuration.setName(configurationName(dir, workingDirectory, basePath));
            configuration.setProgramParameters(programParameters(dir, workingDirectory));
            contextApplicable = true;
        }
    } else {
        PsiFile containingFile = psiElement.getContainingFile();
        if (!(containingFile instanceof ElixirFile || containingFile instanceof PsiDirectory))
            return false;
        if (ProjectRootsUtil.isInTestSource(containingFile)) {
            String basePath = psiElement.getProject().getBasePath();
            String workingDirectory = workingDirectory(psiElement, basePath);
            configuration.setWorkingDirectory(workingDirectory);
            int lineNumber = lineNumber(psiElement);
            configuration.setName(configurationName(containingFile, lineNumber, workingDirectory, basePath));
            configuration.setProgramParameters(programParameters(containingFile, lineNumber, workingDirectory));
            contextApplicable = true;
        }
    }
    return contextApplicable;
}
Also used : ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) ElixirFile(org.elixir_lang.psi.ElixirFile)

Aggregations

SdkTypeId (com.intellij.openapi.projectRoots.SdkTypeId)8 Sdk (com.intellij.openapi.projectRoots.Sdk)7 JavaSdkType (com.intellij.openapi.projectRoots.JavaSdkType)3 Nullable (org.jetbrains.annotations.Nullable)3 CantRunException (com.intellij.execution.CantRunException)2 Module (com.intellij.openapi.module.Module)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PythonSdkType (com.jetbrains.python.sdk.PythonSdkType)2 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ApplicationConfiguration (com.intellij.execution.application.ApplicationConfiguration)1 JavaParameters (com.intellij.execution.configurations.JavaParameters)1 ParametersList (com.intellij.execution.configurations.ParametersList)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 NamedLibraryElement (com.intellij.ide.projectView.impl.nodes.NamedLibraryElement)1 NamedLibraryElementNode (com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode)1 ExternalSystemTaskExecutionSettings (com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)1 ExternalSystemRunConfiguration (com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration)1 JdkOrderEntry (com.intellij.openapi.roots.JdkOrderEntry)1 LibraryOrSdkOrderEntry (com.intellij.openapi.roots.LibraryOrSdkOrderEntry)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1