1 package com.intellij.openapi.externalSystem.model.project;
3 import com.intellij.ide.highlighter.ModuleFileType;
4 import com.intellij.openapi.externalSystem.model.ProjectSystemId;
5 import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
6 import com.intellij.openapi.util.io.FileUtil;
7 import com.intellij.util.containers.ContainerUtil;
8 import org.jetbrains.annotations.NotNull;
9 import org.jetbrains.annotations.Nullable;
12 import java.util.Collections;
13 import java.util.List;
17 * @author Denis Zhdanov
18 * @since 8/8/11 12:11 PM
20 public class ModuleData extends AbstractNamedData implements Named, ExternalConfigPathAware, Identifiable {
22 private static final long serialVersionUID = 1L;
24 @NotNull private final Map<ExternalSystemSourceType, String> myCompileOutputPaths = ContainerUtil.newHashMap();
25 @NotNull private final String myId;
26 @NotNull private final String myModuleTypeId;
27 @NotNull private final String myExternalConfigPath;
28 @NotNull private String myModuleFileDirectoryPath;
29 @Nullable private String myGroup;
30 @Nullable private String myVersion;
31 @Nullable private String myDescription;
32 @NotNull private List<File> myArtifacts;
33 @Nullable private String[] myIdeModuleGroup;
34 @Nullable private String mySourceCompatibility;
35 @Nullable private String myTargetCompatibility;
36 @Nullable private String myProductionModuleId;
38 private boolean myInheritProjectCompileOutputPath = true;
40 public ModuleData(@NotNull String id,
41 @NotNull ProjectSystemId owner,
42 @NotNull String typeId,
44 @NotNull String moduleFileDirectoryPath,
45 @NotNull String externalConfigPath) {
46 super(owner, name, name.replaceAll("(/|\\\\)", "_"));
48 myModuleTypeId = typeId;
49 myExternalConfigPath = externalConfigPath;
50 myArtifacts = Collections.emptyList();
51 myModuleFileDirectoryPath = moduleFileDirectoryPath;
54 protected ModuleData(@NotNull String id,
55 @NotNull ProjectSystemId owner,
56 @NotNull String typeId,
57 @NotNull String externalName,
58 @NotNull String internalName,
59 @NotNull String moduleFileDirectoryPath,
60 @NotNull String externalConfigPath) {
61 super(owner, externalName, FileUtil.sanitizeFileName(internalName));
63 myModuleTypeId = typeId;
64 myExternalConfigPath = externalConfigPath;
65 myArtifacts = Collections.emptyList();
66 myModuleFileDirectoryPath = moduleFileDirectoryPath;
71 public String getId() {
76 public String getModuleTypeId() {
77 return myModuleTypeId;
82 public String getLinkedExternalProjectPath() {
83 return myExternalConfigPath;
87 public String getModuleFilePath() {
88 return ExternalSystemApiUtil
89 .toCanonicalPath(myModuleFileDirectoryPath + "/" + getInternalName() + ModuleFileType.DOT_DEFAULT_EXTENSION);
93 public String getModuleFileDirectoryPath() {
94 return myModuleFileDirectoryPath;
97 public void setModuleFileDirectoryPath(@NotNull String path) {
98 myModuleFileDirectoryPath = path;
102 * @return an internal id of production module corresponding to a test-only module, this information is used to populate
103 * {@link com.intellij.openapi.roots.TestModuleProperties}
106 public String getProductionModuleId() {
107 return myProductionModuleId;
110 public void setProductionModuleId(@Nullable String productionModuleId) {
111 myProductionModuleId = productionModuleId;
114 public boolean isInheritProjectCompileOutputPath() {
115 return myInheritProjectCompileOutputPath;
118 public void setInheritProjectCompileOutputPath(boolean inheritProjectCompileOutputPath) {
119 myInheritProjectCompileOutputPath = inheritProjectCompileOutputPath;
123 * Allows to get file system path of the compile output of the source of the target type.
125 * @param type target source type
126 * @return file system path to use for compile output for the target source type;
127 * {@link JavaProjectData#getCompileOutputPath() project compile output path} should be used if current module
128 * doesn't provide specific compile output path
131 public String getCompileOutputPath(@NotNull ExternalSystemSourceType type) {
132 return myCompileOutputPaths.get(type);
135 public void setCompileOutputPath(@NotNull ExternalSystemSourceType type, @Nullable String path) {
137 myCompileOutputPaths.remove(type);
140 myCompileOutputPaths.put(type, ExternalSystemApiUtil.toCanonicalPath(path));
144 public String getGroup() {
148 public void setGroup(@Nullable String group) {
149 this.myGroup = group;
153 public String getVersion() {
157 public void setVersion(@Nullable String version) {
158 this.myVersion = version;
162 public String getDescription() {
163 return myDescription;
166 public void setDescription(@Nullable String description) {
167 this.myDescription = description;
171 public List<File> getArtifacts() {
175 public void setArtifacts(@NotNull List<File> artifacts) {
176 myArtifacts = artifacts;
180 public String[] getIdeModuleGroup() {
181 return myIdeModuleGroup;
184 public void setIdeModuleGroup(@Nullable String[] ideModuleGroup) {
185 this.myIdeModuleGroup = ideModuleGroup;
189 public String getSourceCompatibility() {
190 return mySourceCompatibility;
193 public void setSourceCompatibility(@Nullable String sourceCompatibility) {
194 mySourceCompatibility = sourceCompatibility;
198 public String getTargetCompatibility() {
199 return myTargetCompatibility;
202 public void setTargetCompatibility(@Nullable String targetCompatibility) {
203 myTargetCompatibility = targetCompatibility;
207 public boolean equals(Object o) {
208 if (!(o instanceof ModuleData)) return false;
209 if (!super.equals(o)) return false;
211 ModuleData that = (ModuleData)o;
213 if (myGroup != null ? !myGroup.equals(that.myGroup) : that.myGroup != null) return false;
214 if (!myModuleTypeId.equals(that.myModuleTypeId)) return false;
215 if (myVersion != null ? !myVersion.equals(that.myVersion) : that.myVersion != null) return false;
216 if (myDescription != null ? !myDescription.equals(that.myDescription) : that.myDescription != null) return false;
222 public int hashCode() {
223 int result = super.hashCode();
224 result = 31 * result + myModuleTypeId.hashCode();
225 result = 31 * result + (myGroup != null ? myGroup.hashCode() : 0);
226 result = 31 * result + (myVersion != null ? myVersion.hashCode() : 0);
227 result = 31 * result + (myDescription != null ? myDescription.hashCode() : 0);
232 public String toString() {
233 return String.format("module '%s:%s:%s'",
234 myGroup == null ? "" : myGroup,
236 myVersion == null ? "" : myVersion);