Search in sources :

Example 1 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)

Example 2 with GradleProjectSettings

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

the class GradleImportingTestCase method importProject.

@Override
protected void importProject() {
    ExternalSystemApiUtil.subscribe(myProject, GradleConstants.SYSTEM_ID, new ExternalSystemSettingsListenerAdapter() {

        @Override
        public void onProjectsLinked(@NotNull Collection settings) {
            Object item = ContainerUtil.getFirstItem(settings);
            if (item instanceof GradleProjectSettings) {
                ((GradleProjectSettings) item).setGradleJvm(GRADLE_JDK_NAME);
            }
        }
    });
    super.importProject();
}
Also used : ExternalSystemSettingsListenerAdapter(com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) Collection(java.util.Collection)

Example 3 with GradleProjectSettings

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

the class GradleInstallationManager method doGetGradleJdk.

@Nullable
private Sdk doGetGradleJdk(@Nullable Project project, String linkedProjectPath) {
    if (project == null) {
        return null;
    }
    final GradleProjectSettings settings = GradleSettings.getInstance(project).getLinkedProjectSettings(linkedProjectPath);
    if (settings == null) {
        return null;
    }
    final String gradleJvm = settings.getGradleJvm();
    final Sdk sdk;
    try {
        sdk = ExternalSystemJdkUtil.getJdk(project, gradleJvm);
    } catch (ExternalSystemJdkException e) {
        throw new ExternalSystemJdkException(String.format("Invalid Gradle JDK configuration found. <a href='%s'>Open Gradle Settings</a> \n", OpenExternalSystemSettingsCallback.ID), linkedProjectPath, e, OpenExternalSystemSettingsCallback.ID);
    }
    if (sdk == null && gradleJvm != null) {
        throw new ExternalSystemJdkException(String.format("Invalid Gradle JDK configuration found. <a href='%s'>Open Gradle Settings</a> \n", OpenExternalSystemSettingsCallback.ID), linkedProjectPath, null, OpenExternalSystemSettingsCallback.ID);
    }
    final File sdkHomePath = sdk != null && sdk.getHomePath() != null ? new File(sdk.getHomePath()) : null;
    if (sdkHomePath != null && JdkUtil.checkForJre(sdkHomePath.getPath()) && !JdkUtil.checkForJdk(sdkHomePath)) {
        throw new ExternalSystemJdkException(String.format("Please, use JDK instead of JRE for Gradle importer. <a href='%s'>Open Gradle Settings</a> \n", OpenExternalSystemSettingsCallback.ID), linkedProjectPath, null, OpenExternalSystemSettingsCallback.ID);
    }
    return sdk;
}
Also used : GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) ExternalSystemJdkException(com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkException) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with GradleProjectSettings

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

the class CompositeBuildDataService method importData.

public void importData(@NotNull final Collection<DataNode<CompositeBuildData>> toImport, @Nullable ProjectData projectData, @NotNull final Project project, @NotNull IdeModifiableModelsProvider modelsProvider) {
    if (toImport.isEmpty()) {
        if (projectData != null) {
            GradleProjectSettings projectSettings = GradleSettings.getInstance(project).getLinkedProjectSettings(projectData.getLinkedExternalProjectPath());
            if (projectSettings != null && projectSettings.getCompositeBuild() != null && projectSettings.getCompositeBuild().getCompositeDefinitionSource() == CompositeDefinitionSource.SCRIPT) {
                projectSettings.setCompositeBuild(null);
            }
        }
        return;
    }
    if (toImport.size() != 1) {
        throw new IllegalArgumentException(String.format("Expected to get a single composite data node but got %d: %s", toImport.size(), toImport));
    }
    CompositeBuildData compositeBuildData = toImport.iterator().next().getData();
    GradleProjectSettings projectSettings = GradleSettings.getInstance(project).getLinkedProjectSettings(compositeBuildData.getRootProjectPath());
    if (projectSettings != null) {
        GradleProjectSettings.CompositeBuild compositeBuild = new GradleProjectSettings.CompositeBuild();
        compositeBuild.setCompositeDefinitionSource(CompositeDefinitionSource.SCRIPT);
        for (BuildParticipant buildParticipant : compositeBuildData.getCompositeParticipants()) {
            compositeBuild.getCompositeParticipants().add(buildParticipant.copy());
        }
        projectSettings.setCompositeBuild(compositeBuild);
    }
}
Also used : GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) CompositeBuildData(org.jetbrains.plugins.gradle.model.data.CompositeBuildData) BuildParticipant(org.jetbrains.plugins.gradle.model.data.BuildParticipant)

Example 5 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)

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