Search in sources :

Example 6 with GradleSettings

use of org.jetbrains.plugins.gradle.settings.GradleSettings in project android by JetBrains.

the class CachedDependencyNotFoundErrorHandlerTest method testHandleError.

public void testHandleError() throws Exception {
    GradleSettings settings = GradleSettings.getInstance(getProject());
    // Set "offline mode" on to force the IDE to show quick-fix.
    settings.setOfflineWork(true);
    String expectedNotificationMessage = "No cached version of dependency, available for offline mode.";
    String error = expectedNotificationMessage + "\nExtra error message.";
    registerSyncErrorToSimulate(error);
    loadProjectAndExpectSyncError(SIMPLE_APPLICATION);
    SyncMessagesStub.NotificationUpdate notificationUpdate = mySyncMessagesStub.getNotificationUpdate();
    assertNotNull(notificationUpdate);
    assertThat(notificationUpdate.getText()).contains(expectedNotificationMessage);
    List<NotificationHyperlink> quickFixes = notificationUpdate.getFixes();
    assertThat(quickFixes).hasSize(1);
    // Verify hyperlinks are correct.
    NotificationHyperlink quickFix = quickFixes.get(0);
    assertThat(quickFix).isInstanceOf(ToggleOfflineModeHyperlink.class);
    ToggleOfflineModeHyperlink toggleOfflineModeQuickFix = (ToggleOfflineModeHyperlink) quickFix;
    assertFalse(toggleOfflineModeQuickFix.isEnableOfflineMode());
}
Also used : GradleSettings(org.jetbrains.plugins.gradle.settings.GradleSettings) SyncMessagesStub(com.android.tools.idea.gradle.project.sync.messages.SyncMessagesStub) ToggleOfflineModeHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.ToggleOfflineModeHyperlink) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)

Example 7 with GradleSettings

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

the class GradleProjectOpenProcessor method setupGradleProjectSettingsInHeadlessMode.

private boolean setupGradleProjectSettingsInHeadlessMode(GradleProjectImportProvider projectImportProvider, WizardContext wizardContext) {
    final ModuleWizardStep[] wizardSteps = projectImportProvider.createSteps(wizardContext);
    if (wizardSteps.length > 0 && wizardSteps[0] instanceof SelectExternalProjectStep) {
        SelectExternalProjectStep selectExternalProjectStep = (SelectExternalProjectStep) wizardSteps[0];
        wizardContext.setProjectBuilder(getBuilder());
        try {
            selectExternalProjectStep.updateStep();
            final ImportFromGradleControl importFromGradleControl = getBuilder().getControl(wizardContext.getProject());
            GradleProjectSettingsControl gradleProjectSettingsControl = (GradleProjectSettingsControl) importFromGradleControl.getProjectSettingsControl();
            final GradleProjectSettings projectSettings = gradleProjectSettingsControl.getInitialSettings();
            if (GRADLE_DISTRIBUTION_TYPE != null) {
                for (DistributionType type : DistributionType.values()) {
                    if (type.name().equals(GRADLE_DISTRIBUTION_TYPE)) {
                        projectSettings.setDistributionType(type);
                        break;
                    }
                }
            }
            if (GRADLE_HOME != null) {
                projectSettings.setGradleHome(GRADLE_HOME);
            }
            gradleProjectSettingsControl.reset();
            final GradleSystemSettingsControl systemSettingsControl = (GradleSystemSettingsControl) importFromGradleControl.getSystemSettingsControl();
            assert systemSettingsControl != null;
            final GradleSettings gradleSettings = systemSettingsControl.getInitialSettings();
            if (GRADLE_VM_OPTIONS != null) {
                gradleSettings.setGradleVmOptions(GRADLE_VM_OPTIONS);
            }
            if (GRADLE_OFFLINE != null) {
                gradleSettings.setOfflineWork(Boolean.parseBoolean(GRADLE_OFFLINE));
            }
            String serviceDirectory = GRADLE_SERVICE_DIRECTORY;
            if (GRADLE_SERVICE_DIRECTORY != null) {
                gradleSettings.setServiceDirectoryPath(serviceDirectory);
            }
            systemSettingsControl.reset();
            if (!selectExternalProjectStep.validate()) {
                return false;
            }
        } catch (ConfigurationException e) {
            Messages.showErrorDialog(wizardContext.getProject(), e.getMessage(), e.getTitle());
            return false;
        }
        selectExternalProjectStep.updateDataModel();
    }
    return true;
}
Also used : GradleProjectSettingsControl(org.jetbrains.plugins.gradle.service.settings.GradleProjectSettingsControl) GradleSettings(org.jetbrains.plugins.gradle.settings.GradleSettings) ModuleWizardStep(com.intellij.ide.util.projectWizard.ModuleWizardStep) ConfigurationException(com.intellij.openapi.options.ConfigurationException) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) GradleSystemSettingsControl(org.jetbrains.plugins.gradle.service.settings.GradleSystemSettingsControl) ImportFromGradleControl(org.jetbrains.plugins.gradle.service.settings.ImportFromGradleControl) SelectExternalProjectStep(com.intellij.openapi.externalSystem.service.project.wizard.SelectExternalProjectStep) DistributionType(org.jetbrains.plugins.gradle.settings.DistributionType)

Example 8 with GradleSettings

use of org.jetbrains.plugins.gradle.settings.GradleSettings in project android by JetBrains.

the class GradleProjectImporter method openOrImportProject.

private void openOrImportProject(@NotNull String projectName, @NotNull File projectFolderPath, @NotNull Request request, @Nullable GradleSyncListener listener, boolean open) throws IOException, ConfigurationException {
    ProjectFolder projectFolder = myProjectFolderFactory.create(projectFolderPath);
    projectFolder.createTopLevelBuildFile();
    projectFolder.createIdeaProjectFolder();
    Project project = request.getProject();
    Project newProject = project;
    if (newProject == null) {
        newProject = open ? myNewProjectSetup.openProject(projectFolderPath.getPath()) : myNewProjectSetup.createProject(projectName, projectFolderPath.getPath());
    }
    if (project == null) {
        GradleSettings gradleSettings = GradleSettings.getInstance(newProject);
        gradleSettings.setGradleVmOptions("");
    }
    myNewProjectSetup.prepareProjectForImport(newProject, request.getLanguageLevel());
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
        newProject.save();
    }
    myGradleSyncInvoker.requestProjectSync(newProject, createSyncRequestSettings(request), listener);
}
Also used : Project(com.intellij.openapi.project.Project) GradleSettings(org.jetbrains.plugins.gradle.settings.GradleSettings)

Example 9 with GradleSettings

use of org.jetbrains.plugins.gradle.settings.GradleSettings in project android by JetBrains.

the class GradleSettingsCleanUpTask method cleanUp.

@Override
void cleanUp(@NotNull Project project) {
    GradleProjectSettings projectSettings = GradleProjectSettingsFinder.getInstance().findGradleProjectSettings(project);
    if (projectSettings == null) {
        projectSettings = new GradleProjectSettings();
    }
    setUpGradleProjectSettings(project, projectSettings);
    GradleSettings gradleSettings = GradleSettings.getInstance(project);
    gradleSettings.setLinkedProjectsSettings(ImmutableList.of(projectSettings));
}
Also used : GradleSettings(org.jetbrains.plugins.gradle.settings.GradleSettings) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings)

Example 10 with GradleSettings

use of org.jetbrains.plugins.gradle.settings.GradleSettings in project android by JetBrains.

the class GradleLocalCache method getGradleServicePaths.

@NotNull
private static Collection<File> getGradleServicePaths(@Nullable Project project) {
    Set<File> paths = new LinkedHashSet<>();
    if (project != null) {
        // Use the one set in the IDE
        GradleSettings settings = GradleSettings.getInstance(project);
        String path = settings.getServiceDirectoryPath();
        if (isNotEmpty(path)) {
            File file = new File(path);
            if (file.isDirectory()) {
                paths.add(file);
            }
        }
    }
    // The default location: ~/.gradle
    File path = new File(getUserHome(), DOT_GRADLE);
    if (path.isDirectory()) {
        paths.add(path);
    }
    return paths;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) GradleSettings(org.jetbrains.plugins.gradle.settings.GradleSettings) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GradleSettings (org.jetbrains.plugins.gradle.settings.GradleSettings)12 Project (com.intellij.openapi.project.Project)3 File (java.io.File)3 GradleProjectSettings (org.jetbrains.plugins.gradle.settings.GradleProjectSettings)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 NotNull (org.jetbrains.annotations.NotNull)2 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)1 GradleSyncInvoker (com.android.tools.idea.gradle.project.sync.GradleSyncInvoker)1 SdkSync (com.android.tools.idea.gradle.project.sync.SdkSync)1 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)1 ToggleOfflineModeHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.ToggleOfflineModeHyperlink)1 SyncMessagesStub (com.android.tools.idea.gradle.project.sync.messages.SyncMessagesStub)1 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)1 HyperlinkFixture (com.android.tools.idea.tests.gui.framework.fixture.MessagesToolWindowFixture.HyperlinkFixture)1 MessageFixture (com.android.tools.idea.tests.gui.framework.fixture.MessagesToolWindowFixture.MessageFixture)1 ModuleWizardStep (com.intellij.ide.util.projectWizard.ModuleWizardStep)1 SelectExternalProjectStep (com.intellij.openapi.externalSystem.service.project.wizard.SelectExternalProjectStep)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 VfsUtil.findFileByIoFile (com.intellij.openapi.vfs.VfsUtil.findFileByIoFile)1 IOException (java.io.IOException)1