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());
}
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;
}
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);
}
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));
}
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;
}
Aggregations