Search in sources :

Example 6 with GradleProjectSettings

use of org.jetbrains.plugins.gradle.settings.GradleProjectSettings in project intellij-community by JetBrains.

the class GradleModuleBuilder method setupModule.

@Override
protected void setupModule(Module module) throws ConfigurationException {
    super.setupModule(module);
    assert rootProjectPath != null;
    VirtualFile buildScriptFile = null;
    final BuildScriptDataBuilder buildScriptDataBuilder = getBuildScriptData(module);
    try {
        if (buildScriptDataBuilder != null) {
            buildScriptFile = buildScriptDataBuilder.getBuildScriptFile();
            final String text = buildScriptDataBuilder.build();
            appendToFile(buildScriptFile, "\n" + text);
        }
    } catch (IOException e) {
        LOG.warn("Unexpected exception on applying frameworks templates", e);
    }
    final Project project = module.getProject();
    if (myWizardContext.isCreatingNewProject()) {
        getExternalProjectSettings().setExternalProjectPath(rootProjectPath);
        AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID);
        project.putUserData(ExternalSystemDataKeys.NEWLY_CREATED_PROJECT, Boolean.TRUE);
        //noinspection unchecked
        settings.linkProject(getExternalProjectSettings());
    } else {
        FileDocumentManager.getInstance().saveAllDocuments();
        final GradleProjectSettings gradleProjectSettings = getExternalProjectSettings();
        final VirtualFile finalBuildScriptFile = buildScriptFile;
        Runnable runnable = () -> {
            if (myParentProject == null) {
                gradleProjectSettings.setExternalProjectPath(rootProjectPath);
                AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID);
                //noinspection unchecked
                settings.linkProject(gradleProjectSettings);
            }
            ImportSpec importSpec = new ImportSpecBuilder(project, GradleConstants.SYSTEM_ID).use(ProgressExecutionMode.IN_BACKGROUND_ASYNC).createDirectoriesForEmptyContentRoots().useDefaultCallback().build();
            ExternalSystemUtil.refreshProject(rootProjectPath, importSpec);
            final PsiFile psiFile;
            if (finalBuildScriptFile != null) {
                psiFile = PsiManager.getInstance(project).findFile(finalBuildScriptFile);
                if (psiFile != null) {
                    EditorHelper.openInEditor(psiFile);
                }
            }
        };
        // execute when current dialog is closed
        ExternalSystemUtil.invokeLater(project, ModalityState.NON_MODAL, runnable);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) BuildScriptDataBuilder(org.jetbrains.plugins.gradle.frameworkSupport.BuildScriptDataBuilder) PsiFile(com.intellij.psi.PsiFile) IOException(java.io.IOException) ImportSpec(com.intellij.openapi.externalSystem.importing.ImportSpec) ImportSpecBuilder(com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)

Example 7 with GradleProjectSettings

use of org.jetbrains.plugins.gradle.settings.GradleProjectSettings in project intellij-community by JetBrains.

the class GradleProjectCompositeSelectorDialog method createTree.

private CheckboxTree createTree() {
    final CheckedTreeNode root = new CheckedTreeNode();
    if (myCompositeRootSettings != null) {
        List<TreeNode> nodes = ContainerUtil.newArrayList();
        for (GradleProjectSettings projectSettings : GradleSettings.getInstance(myProject).getLinkedProjectsSettings()) {
            if (projectSettings == myCompositeRootSettings)
                continue;
            if (projectSettings.getCompositeBuild() != null && projectSettings.getCompositeBuild().getCompositeDefinitionSource() == CompositeDefinitionSource.SCRIPT) {
                continue;
            }
            GradleProjectSettings.CompositeBuild compositeBuild = myCompositeRootSettings.getCompositeBuild();
            boolean added = compositeBuild != null && compositeBuild.getCompositeParticipants().stream().anyMatch(participant -> pathsEqual(participant.getRootPath(), projectSettings.getExternalProjectPath()));
            String representationName = myExternalSystemUiAware.getProjectRepresentationName(projectSettings.getExternalProjectPath(), projectSettings.getExternalProjectPath());
            CheckedTreeNode treeNode = new CheckedTreeNode(Pair.create(representationName, projectSettings.getExternalProjectPath()));
            treeNode.setChecked(added);
            nodes.add(treeNode);
        }
        TreeUtil.addChildrenTo(root, nodes);
    }
    final CheckboxTree tree = new CheckboxTree(new CheckboxTree.CheckboxTreeCellRenderer(true, false) {

        @Override
        public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            if (!(value instanceof CheckedTreeNode))
                return;
            CheckedTreeNode node = (CheckedTreeNode) value;
            if (!(node.getUserObject() instanceof Pair))
                return;
            Pair pair = (Pair) node.getUserObject();
            ColoredTreeCellRenderer renderer = getTextRenderer();
            renderer.setIcon(myExternalSystemUiAware.getProjectIcon());
            String projectName = (String) pair.first;
            renderer.append(projectName, SimpleTextAttributes.REGULAR_ATTRIBUTES);
            String projectPath = StringUtil.trimMiddle((String) pair.second, MAX_PATH_LENGTH);
            renderer.append(" (" + projectPath + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
            setToolTipText((String) pair.second);
        }
    }, root);
    TreeUtil.expand(tree, 1);
    return tree;
}
Also used : AllIcons(com.intellij.icons.AllIcons) TreeNode(javax.swing.tree.TreeNode) TreeModel(javax.swing.tree.TreeModel) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) ContainerUtil(com.intellij.util.containers.ContainerUtil) JBLabel(com.intellij.ui.components.JBLabel) ActionToolbarPosition(com.intellij.openapi.actionSystem.ActionToolbarPosition) BuildParticipant(org.jetbrains.plugins.gradle.model.data.BuildParticipant) GradleSettings(org.jetbrains.plugins.gradle.settings.GradleSettings) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Project(com.intellij.openapi.project.Project) ExternalSystemUiUtil(com.intellij.openapi.externalSystem.util.ExternalSystemUiUtil) CompositeDefinitionSource(org.jetbrains.plugins.gradle.settings.CompositeDefinitionSource) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeUtil(com.intellij.util.ui.tree.TreeUtil) StringUtil(com.intellij.openapi.util.text.StringUtil) ExternalSystemUiAware(com.intellij.openapi.externalSystem.ExternalSystemUiAware) com.intellij.ui(com.intellij.ui) FileUtil.pathsEqual(com.intellij.openapi.util.io.FileUtil.pathsEqual) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Pair(com.intellij.openapi.util.Pair) GradleConstants(org.jetbrains.plugins.gradle.util.GradleConstants) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) javax.swing(javax.swing) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) TreeNode(javax.swing.tree.TreeNode) Pair(com.intellij.openapi.util.Pair)

Example 8 with GradleProjectSettings

use of org.jetbrains.plugins.gradle.settings.GradleProjectSettings in project intellij-community by JetBrains.

the class ImportFromGradleControl method getInitialProjectSettings.

@NotNull
private static GradleProjectSettings getInitialProjectSettings() {
    GradleProjectSettings result = new GradleProjectSettings();
    String gradleHome = GradleUtil.getLastUsedGradleHome();
    if (!StringUtil.isEmpty(gradleHome)) {
        result.setGradleHome(gradleHome);
    }
    return result;
}
Also used : GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with GradleProjectSettings

use of org.jetbrains.plugins.gradle.settings.GradleProjectSettings in project intellij-community by JetBrains.

the class GradleImportingTestCase method setUp.

@Override
public void setUp() throws Exception {
    myJdkHome = IdeaTestUtil.requireRealJdkHome();
    super.setUp();
    assumeThat(gradleVersion, versionMatcherRule.getMatcher());
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            Sdk oldJdk = ProjectJdkTable.getInstance().findJdk(GRADLE_JDK_NAME);
            if (oldJdk != null) {
                ProjectJdkTable.getInstance().removeJdk(oldJdk);
            }
            VirtualFile jdkHomeDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(myJdkHome));
            Sdk jdk = SdkConfigurationUtil.setupSdk(new Sdk[0], jdkHomeDir, JavaSdk.getInstance(), true, null, GRADLE_JDK_NAME);
            assertNotNull("Cannot create JDK for " + myJdkHome, jdk);
            ProjectJdkTable.getInstance().addJdk(jdk);
        }
    }.execute();
    myProjectSettings = new GradleProjectSettings();
    GradleSettings.getInstance(myProject).setGradleVmOptions("-Xmx128m -XX:MaxPermSize=64m");
    System.setProperty(ExternalSystemExecutionSettings.REMOTE_PROCESS_IDLE_TTL_IN_MS_KEY, String.valueOf(GRADLE_DAEMON_TTL_MS));
    configureWrapper();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) Result(com.intellij.openapi.application.Result)

Example 10 with GradleProjectSettings

use of org.jetbrains.plugins.gradle.settings.GradleProjectSettings in project kotlin by JetBrains.

the class GradleImportingTestCase method setUp.

@Override
public void setUp() throws Exception {
    myJdkHome = IdeaTestUtil.requireRealJdkHome();
    super.setUp();
    assumeThat(gradleVersion, versionMatcherRule.getMatcher());
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            Sdk oldJdk = ProjectJdkTable.getInstance().findJdk(GRADLE_JDK_NAME);
            if (oldJdk != null) {
                ProjectJdkTable.getInstance().removeJdk(oldJdk);
            }
            VirtualFile jdkHomeDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(myJdkHome));
            assert jdkHomeDir != null;
            Sdk jdk = SdkConfigurationUtil.setupSdk(new Sdk[0], jdkHomeDir, JavaSdk.getInstance(), true, null, GRADLE_JDK_NAME);
            assertNotNull("Cannot create JDK for " + myJdkHome, jdk);
            ProjectJdkTable.getInstance().addJdk(jdk);
        }
    }.execute();
    myProjectSettings = new GradleProjectSettings();
    GradleSettings.getInstance(myProject).setGradleVmOptions("-Xmx128m -XX:MaxPermSize=64m");
    System.setProperty(ExternalSystemExecutionSettings.REMOTE_PROCESS_IDLE_TTL_IN_MS_KEY, String.valueOf(GRADLE_DAEMON_TTL_MS));
    configureWrapper();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Result(com.intellij.openapi.application.Result)

Aggregations

GradleProjectSettings (org.jetbrains.plugins.gradle.settings.GradleProjectSettings)34 File (java.io.File)9 Project (com.intellij.openapi.project.Project)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 Nullable (org.jetbrains.annotations.Nullable)6 NotNull (org.jetbrains.annotations.NotNull)5 IOException (java.io.IOException)4 DistributionType (org.jetbrains.plugins.gradle.settings.DistributionType)4 GradleSettings (org.jetbrains.plugins.gradle.settings.GradleSettings)4 GradleWrapper (com.android.tools.idea.gradle.util.GradleWrapper)3 Sdk (com.intellij.openapi.projectRoots.Sdk)3 GradleVersion (com.android.ide.common.repository.GradleVersion)2 Result (com.intellij.openapi.application.Result)2 WriteAction (com.intellij.openapi.application.WriteAction)2 ExternalSystemSettingsListenerAdapter (com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter)2 Module (com.intellij.openapi.module.Module)2 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)2 VfsUtil.findFileByIoFile (com.intellij.openapi.vfs.VfsUtil.findFileByIoFile)2 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)2 BuildParticipant (org.jetbrains.plugins.gradle.model.data.BuildParticipant)2