/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenImportingSettings.java

https://bitbucket.org/nbargnesi/idea · Java · 271 lines · 203 code · 53 blank · 15 comment · 44 complexity · bd4ba74978eac95918c9e705f40c8b95 MD5 · raw file

  1. /*
  2. * Copyright 2000-2009 JetBrains s.r.o.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.jetbrains.idea.maven.project;
  17. import com.intellij.util.containers.ContainerUtil;
  18. import com.intellij.util.xmlb.annotations.Property;
  19. import org.jetbrains.annotations.NotNull;
  20. import java.util.List;
  21. public class MavenImportingSettings implements Cloneable {
  22. private static final String PROCESS_RESOURCES_PHASE = "process-resources";
  23. public static final String[] UPDATE_FOLDERS_PHASES = new String[]{
  24. "generate-sources",
  25. "process-sources",
  26. "generate-resources",
  27. PROCESS_RESOURCES_PHASE,
  28. "generate-test-sources",
  29. "process-test-sources",
  30. "generate-test-resources",
  31. "process-test-resources"};
  32. public static final String UPDATE_FOLDERS_DEFAULT_PHASE = PROCESS_RESOURCES_PHASE;
  33. @NotNull private String dedicatedModuleDir = "";
  34. private boolean lookForNested = false;
  35. private boolean importAutomatically = false;
  36. private boolean createModulesForAggregators = true;
  37. private boolean createModuleGroups = false;
  38. private boolean excludeTargetFolder = true;
  39. private boolean keepSourceFolders = true;
  40. private boolean useMavenOutput = true;
  41. private String updateFoldersOnImportPhase = UPDATE_FOLDERS_DEFAULT_PHASE;
  42. private boolean downloadSourcesAutomatically = false;
  43. private boolean downloadDocsAutomatically = false;
  44. private GeneratedSourcesFolder generatedSourcesFolder = GeneratedSourcesFolder.AUTODETECT;
  45. private List<Listener> myListeners = ContainerUtil.createEmptyCOWList();
  46. public enum GeneratedSourcesFolder {
  47. AUTODETECT("Detect automatically"),
  48. GENERATED_SOURCE_FOLDER("target/generated-sources"),
  49. SUBFOLDER("subdirectories of \"target/generated-sources\"");
  50. public final String title;
  51. private GeneratedSourcesFolder(String title) {
  52. this.title = title;
  53. }
  54. }
  55. @NotNull
  56. public String getDedicatedModuleDir() {
  57. return dedicatedModuleDir;
  58. }
  59. public void setDedicatedModuleDir(@NotNull String dedicatedModuleDir) {
  60. this.dedicatedModuleDir = dedicatedModuleDir;
  61. }
  62. public boolean isLookForNested() {
  63. return lookForNested;
  64. }
  65. public void setLookForNested(boolean lookForNested) {
  66. this.lookForNested = lookForNested;
  67. }
  68. public boolean isImportAutomatically() {
  69. return importAutomatically;
  70. }
  71. public void setImportAutomatically(boolean importAutomatically) {
  72. this.importAutomatically = importAutomatically;
  73. fireAutoImportChanged();
  74. }
  75. public boolean isCreateModuleGroups() {
  76. return createModuleGroups;
  77. }
  78. public void setCreateModuleGroups(boolean createModuleGroups) {
  79. this.createModuleGroups = createModuleGroups;
  80. fireCreateModuleGroupsChanged();
  81. }
  82. public boolean isCreateModulesForAggregators() {
  83. return createModulesForAggregators;
  84. }
  85. public void setCreateModulesForAggregators(boolean createModulesForAggregators) {
  86. this.createModulesForAggregators = createModulesForAggregators;
  87. fireCreateModuleForAggregatorsChanged();
  88. }
  89. public boolean isKeepSourceFolders() {
  90. return keepSourceFolders;
  91. }
  92. public void setKeepSourceFolders(boolean keepSourceFolders) {
  93. this.keepSourceFolders = keepSourceFolders;
  94. }
  95. public boolean isExcludeTargetFolder() {
  96. return excludeTargetFolder;
  97. }
  98. public void setExcludeTargetFolder(boolean excludeTargetFolder) {
  99. this.excludeTargetFolder = excludeTargetFolder;
  100. }
  101. public boolean isUseMavenOutput() {
  102. return useMavenOutput;
  103. }
  104. public void setUseMavenOutput(boolean useMavenOutput) {
  105. this.useMavenOutput = useMavenOutput;
  106. }
  107. public String getUpdateFoldersOnImportPhase() {
  108. return updateFoldersOnImportPhase;
  109. }
  110. public void setUpdateFoldersOnImportPhase(String updateFoldersOnImportPhase) {
  111. this.updateFoldersOnImportPhase = updateFoldersOnImportPhase;
  112. }
  113. public boolean isDownloadSourcesAutomatically() {
  114. return downloadSourcesAutomatically;
  115. }
  116. public void setDownloadSourcesAutomatically(boolean Value) {
  117. this.downloadSourcesAutomatically = Value;
  118. }
  119. public boolean isDownloadDocsAutomatically() {
  120. return downloadDocsAutomatically;
  121. }
  122. public void setDownloadDocsAutomatically(boolean value) {
  123. this.downloadDocsAutomatically = value;
  124. }
  125. @Property
  126. @NotNull
  127. public GeneratedSourcesFolder getGeneratedSourcesFolder() {
  128. return generatedSourcesFolder;
  129. }
  130. public void setGeneratedSourcesFolder(GeneratedSourcesFolder generatedSourcesFolder) {
  131. if (generatedSourcesFolder == null) return; // null may come from deserializator
  132. this.generatedSourcesFolder = generatedSourcesFolder;
  133. }
  134. @Override
  135. public boolean equals(Object o) {
  136. if (this == o) return true;
  137. if (o == null || getClass() != o.getClass()) return false;
  138. MavenImportingSettings that = (MavenImportingSettings)o;
  139. if (createModuleGroups != that.createModuleGroups) return false;
  140. if (createModulesForAggregators != that.createModulesForAggregators) return false;
  141. if (importAutomatically != that.importAutomatically) return false;
  142. if (downloadDocsAutomatically != that.downloadDocsAutomatically) return false;
  143. if (downloadSourcesAutomatically != that.downloadSourcesAutomatically) return false;
  144. if (lookForNested != that.lookForNested) return false;
  145. if (keepSourceFolders != that.keepSourceFolders) return false;
  146. if (excludeTargetFolder != that.excludeTargetFolder) return false;
  147. if (useMavenOutput != that.useMavenOutput) return false;
  148. if (generatedSourcesFolder != that.generatedSourcesFolder) return false;
  149. if (!dedicatedModuleDir.equals(that.dedicatedModuleDir)) return false;
  150. if (updateFoldersOnImportPhase != null
  151. ? !updateFoldersOnImportPhase.equals(that.updateFoldersOnImportPhase)
  152. : that.updateFoldersOnImportPhase != null) {
  153. return false;
  154. }
  155. return true;
  156. }
  157. @Override
  158. public int hashCode() {
  159. int result = 0;
  160. if (lookForNested) result++;
  161. result <<= 1;
  162. if (importAutomatically) result++;
  163. result <<= 1;
  164. if (createModulesForAggregators) result++;
  165. result <<= 1;
  166. if (createModuleGroups) result++;
  167. result <<= 1;
  168. if (keepSourceFolders) result++;
  169. result <<= 1;
  170. if (useMavenOutput) result++;
  171. result <<= 1;
  172. if (downloadSourcesAutomatically) result++;
  173. result <<= 1;
  174. if (downloadDocsAutomatically) result++;
  175. result <<= 1;
  176. result = 31 * result + (updateFoldersOnImportPhase != null ? updateFoldersOnImportPhase.hashCode() : 0);
  177. result = 31 * result + dedicatedModuleDir.hashCode();
  178. result = 31 * result + generatedSourcesFolder.hashCode();
  179. return result;
  180. }
  181. @Override
  182. public MavenImportingSettings clone() {
  183. try {
  184. MavenImportingSettings result = (MavenImportingSettings)super.clone();
  185. result.myListeners = ContainerUtil.createEmptyCOWList();
  186. return result;
  187. }
  188. catch (CloneNotSupportedException e) {
  189. throw new Error(e);
  190. }
  191. }
  192. public void addListener(Listener l) {
  193. myListeners.add(l);
  194. }
  195. public void removeListener(Listener l) {
  196. myListeners.remove(l);
  197. }
  198. private void fireAutoImportChanged() {
  199. for (Listener each : myListeners) {
  200. each.autoImportChanged();
  201. }
  202. }
  203. private void fireCreateModuleGroupsChanged() {
  204. for (Listener each : myListeners) {
  205. each.createModuleGroupsChanged();
  206. }
  207. }
  208. private void fireCreateModuleForAggregatorsChanged() {
  209. for (Listener each : myListeners) {
  210. each.createModuleForAggregatorsChanged();
  211. }
  212. }
  213. public interface Listener {
  214. void autoImportChanged();
  215. void createModuleGroupsChanged();
  216. void createModuleForAggregatorsChanged();
  217. }
  218. }