From 4e894cc3f88120c75828a6ca5874670c1816b50d Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Thu, 14 Aug 2014 19:45:42 +0400 Subject: [PATCH] Gradle: use application level for gradle system setting related issue: IDEA-128535 Global Gradle Settings aren't global --- plugins/gradle/src/META-INF/plugin.xml | 1 + .../gradle/settings/GradleSettings.java | 62 +++++-------- .../gradle/settings/GradleSystemSettings.java | 92 +++++++++++++++++++ 3 files changed, 117 insertions(+), 38 deletions(-) create mode 100644 plugins/gradle/src/org/jetbrains/plugins/gradle/settings/GradleSystemSettings.java diff --git a/plugins/gradle/src/META-INF/plugin.xml b/plugins/gradle/src/META-INF/plugin.xml index f15f424a10b8..f00346625e81 100644 --- a/plugins/gradle/src/META-INF/plugin.xml +++ b/plugins/gradle/src/META-INF/plugin.xml @@ -106,6 +106,7 @@ + diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/settings/GradleSettings.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/settings/GradleSettings.java index d85e6cf1a742..db1569965d4a 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/settings/GradleSettings.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/settings/GradleSettings.java @@ -30,26 +30,24 @@ import java.util.Set; /** * Holds shared project-level gradle-related settings (should be kept at the '*.ipr' or under '.idea'). - * + * * @author peter */ @State( - name = "GradleSettings", - storages = { - @Storage(file = StoragePathMacros.PROJECT_FILE), - @Storage(file = StoragePathMacros.PROJECT_CONFIG_DIR + "/gradle.xml", scheme = StorageScheme.DIRECTORY_BASED) - } + name = "GradleSettings", + storages = { + @Storage(file = StoragePathMacros.PROJECT_FILE), + @Storage(file = StoragePathMacros.PROJECT_CONFIG_DIR + "/gradle.xml", scheme = StorageScheme.DIRECTORY_BASED) + } ) public class GradleSettings extends AbstractExternalSystemSettings - implements PersistentStateComponent -{ + implements PersistentStateComponent { - @Nullable private String myServiceDirectoryPath; - @Nullable private String myGradleVmOptions; - private boolean myIsOfflineWork; + private final GradleSystemSettings mySystemSettings; public GradleSettings(@NotNull Project project) { super(GradleSettingsListener.TOPIC, project); + mySystemSettings = GradleSystemSettings.getInstance(); } @NotNull @@ -65,9 +63,6 @@ public class GradleSettings extends AbstractExternalSystemSettings { private Set myProjectSettings = ContainerUtilRt.newTreeSet(); - public String serviceDirectoryPath; - public String gradleVmOptions; - public boolean offlineWork; @AbstractCollection(surroundWithTag = false, elementTypes = {GradleProjectSettings.class}) public Set getLinkedExternalProjectsSettings() { diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/settings/GradleSystemSettings.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/settings/GradleSystemSettings.java new file mode 100644 index 000000000000..b24bd24cbf0d --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/settings/GradleSystemSettings.java @@ -0,0 +1,92 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.gradle.settings; + +import com.intellij.openapi.components.*; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Vladislav.Soroka + * @since 14/8/2014 + */ +@State( + name = "GradleSystemSettings", + storages = { + @Storage(file = StoragePathMacros.APP_CONFIG + "/gradle.settings.xml") + } +) +public class GradleSystemSettings implements PersistentStateComponent { + + @Nullable private String myServiceDirectoryPath; + @Nullable private String myGradleVmOptions; + private boolean myIsOfflineWork; + + @NotNull + public static GradleSystemSettings getInstance() { + return ServiceManager.getService(GradleSystemSettings.class); + } + + @SuppressWarnings("unchecked") + @Nullable + @Override + public GradleSystemSettings.MyState getState() { + MyState state = new MyState(); + state.serviceDirectoryPath = myServiceDirectoryPath; + state.gradleVmOptions = myGradleVmOptions; + state.offlineWork = myIsOfflineWork; + return state; + } + + @Override + public void loadState(MyState state) { + myServiceDirectoryPath = state.serviceDirectoryPath; + myGradleVmOptions = state.gradleVmOptions; + myIsOfflineWork = state.offlineWork; + } + + @Nullable + public String getServiceDirectoryPath() { + return myServiceDirectoryPath; + } + + public void setServiceDirectoryPath(@Nullable String newPath) { + myServiceDirectoryPath = newPath; + } + + @Nullable + public String getGradleVmOptions() { + return myGradleVmOptions; + } + + public void setGradleVmOptions(@Nullable String gradleVmOptions) { + myGradleVmOptions = gradleVmOptions; + } + + public boolean isOfflineWork() { + return myIsOfflineWork; + } + + public void setOfflineWork(boolean isOfflineWork) { + myIsOfflineWork = isOfflineWork; + } + + public static class MyState { + public String serviceDirectoryPath; + public String gradleVmOptions; + public boolean offlineWork; + } +} \ No newline at end of file