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;
37 private boolean myInheritProjectCompileOutputPath = true;
39 public ModuleData(@NotNull String id,
40 @NotNull ProjectSystemId owner,
41 @NotNull String typeId,
43 @NotNull String moduleFileDirectoryPath,
44 @NotNull String externalConfigPath) {
45 super(owner, name, name.replaceAll("(/|\\\\)", "_"));
47 myModuleTypeId = typeId;
48 myExternalConfigPath = externalConfigPath;
49 myArtifacts = Collections.emptyList();
50 myModuleFileDirectoryPath = moduleFileDirectoryPath;
53 protected ModuleData(@NotNull String id,
54 @NotNull ProjectSystemId owner,
55 @NotNull String typeId,
56 @NotNull String externalName,
57 @NotNull String internalName,
58 @NotNull String moduleFileDirectoryPath,
59 @NotNull String externalConfigPath) {
60 super(owner, externalName, FileUtil.sanitizeFileName(internalName));
62 myModuleTypeId = typeId;
63 myExternalConfigPath = externalConfigPath;
64 myArtifacts = Collections.emptyList();
65 myModuleFileDirectoryPath = moduleFileDirectoryPath;
70 public String getId() {
75 public String getModuleTypeId() {
76 return myModuleTypeId;
81 public String getLinkedExternalProjectPath() {
82 return myExternalConfigPath;
86 public String getModuleFilePath() {
87 return ExternalSystemApiUtil
88 .toCanonicalPath(myModuleFileDirectoryPath + "/" + getInternalName() + ModuleFileType.DOT_DEFAULT_EXTENSION);
92 public String getModuleFileDirectoryPath() {
93 return myModuleFileDirectoryPath;
96 public void setModuleFileDirectoryPath(@NotNull String path) {
97 myModuleFileDirectoryPath = path;
100 public boolean isInheritProjectCompileOutputPath() {
101 return myInheritProjectCompileOutputPath;
104 public void setInheritProjectCompileOutputPath(boolean inheritProjectCompileOutputPath) {
105 myInheritProjectCompileOutputPath = inheritProjectCompileOutputPath;
109 * Allows to get file system path of the compile output of the source of the target type.
111 * @param type target source type
112 * @return file system path to use for compile output for the target source type;
113 * {@link JavaProjectData#getCompileOutputPath() project compile output path} should be used if current module
114 * doesn't provide specific compile output path
117 public String getCompileOutputPath(@NotNull ExternalSystemSourceType type) {
118 return myCompileOutputPaths.get(type);
121 public void setCompileOutputPath(@NotNull ExternalSystemSourceType type, @Nullable String path) {
123 myCompileOutputPaths.remove(type);
126 myCompileOutputPaths.put(type, ExternalSystemApiUtil.toCanonicalPath(path));
130 public String getGroup() {
134 public void setGroup(@Nullable String group) {
135 this.myGroup = group;
139 public String getVersion() {
143 public void setVersion(@Nullable String version) {
144 this.myVersion = version;
148 public String getDescription() {
149 return myDescription;
152 public void setDescription(@Nullable String description) {
153 this.myDescription = description;
157 public List<File> getArtifacts() {
161 public void setArtifacts(@NotNull List<File> artifacts) {
162 myArtifacts = artifacts;
166 public String[] getIdeModuleGroup() {
167 return myIdeModuleGroup;
170 public void setIdeModuleGroup(@Nullable String[] ideModuleGroup) {
171 this.myIdeModuleGroup = ideModuleGroup;
175 public String getSourceCompatibility() {
176 return mySourceCompatibility;
179 public void setSourceCompatibility(@Nullable String sourceCompatibility) {
180 mySourceCompatibility = sourceCompatibility;
184 public String getTargetCompatibility() {
185 return myTargetCompatibility;
188 public void setTargetCompatibility(@Nullable String targetCompatibility) {
189 myTargetCompatibility = targetCompatibility;
193 public boolean equals(Object o) {
194 if (!(o instanceof ModuleData)) return false;
195 if (!super.equals(o)) return false;
197 ModuleData that = (ModuleData)o;
199 if (myGroup != null ? !myGroup.equals(that.myGroup) : that.myGroup != null) return false;
200 if (!myModuleTypeId.equals(that.myModuleTypeId)) return false;
201 if (myVersion != null ? !myVersion.equals(that.myVersion) : that.myVersion != null) return false;
202 if (myDescription != null ? !myDescription.equals(that.myDescription) : that.myDescription != null) return false;
208 public int hashCode() {
209 int result = super.hashCode();
210 result = 31 * result + myModuleTypeId.hashCode();
211 result = 31 * result + (myGroup != null ? myGroup.hashCode() : 0);
212 result = 31 * result + (myVersion != null ? myVersion.hashCode() : 0);
213 result = 31 * result + (myDescription != null ? myDescription.hashCode() : 0);
218 public String toString() {
219 return String.format("module '%s:%s:%s'",
220 myGroup == null ? "" : myGroup,
222 myVersion == null ? "" : myVersion);