-
Notifications
You must be signed in to change notification settings - Fork 316
/
StandardProjectConfig.java
223 lines (198 loc) · 6.14 KB
/
StandardProjectConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/**
* Copyright (c) 2015, 2020 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.xtext.generator.model.project;
import java.util.Objects;
import org.eclipse.emf.mwe2.runtime.Mandatory;
import org.eclipse.xtext.xtext.generator.Issues;
/**
* Specialized project configuration that uses standard names and paths. Usually
* it is sufficient to set the {@code baseName} and {@code rootPath} properties
* and to enable the required subprojects.
*
* @noextend This class should not be extended by clients.
*/
public class StandardProjectConfig extends XtextProjectConfig {
/**
* set to {@code true} by the project wizard(s) in case "Maven/Gradle"
* source layout is selected.
*/
private boolean mavenLayout;
private boolean createEclipseMetaData;
private String rootPath;
private String baseName;
/**
* The base name of the project, which is usually equal to the runtime
* subproject.
*/
@Mandatory
public String setBaseName(String baseName) {
return this.baseName = baseName;
}
/**
* The root path, usually {@code ".."}.
*/
@Mandatory
public String setRootPath(String rootPath) {
return this.rootPath = rootPath;
}
@Override
public void checkConfiguration(Issues issues) {
super.checkConfiguration(issues);
if (rootPath == null) {
issues.addError("The property 'rootPath' must be set", this);
}
if (baseName == null) {
issues.addError("The property 'baseName' must be set", this);
}
}
@Override
public void setDefaults() {
super.setDefaults();
for(SubProjectConfig it : getEnabledProjects()) {
if (it.getName() == null) {
it.setName(computeName(it));
}
if (it.getRootPath() == null) {
it.setRoot(computeRoot(it));
}
if (it.getMetaInfPath() == null) {
it.setMetaInf(computeMetaInf(it));
}
if (it.getSrcPath() == null) {
it.setSrc(computeSrc(it));
}
if (it.getSrcGenPath() == null) {
it.setSrcGen(computeSrcGen(it));
}
if (it.getIconsPath() == null) {
it.setIcons(computeIcons(it));
}
if (it instanceof BundleProjectConfig) {
if (createEclipseMetaData) {
BundleProjectConfig bundleProjectConfig = (BundleProjectConfig) it;
if (bundleProjectConfig.getManifest() == null) {
bundleProjectConfig.setManifest(newManifestAccess());
}
if (bundleProjectConfig.getPluginXml() == null) {
bundleProjectConfig.setPluginXml(newPluginXmlAccess());
}
}
}
if (it instanceof RuntimeProjectConfig) {
RuntimeProjectConfig runtimeProjectConfig = (RuntimeProjectConfig) it;
if (!(runtimeProjectConfig.getEcoreModelPath() != null)) {
runtimeProjectConfig.setEcoreModel(computeEcoreModel(runtimeProjectConfig));
}
}
if (it instanceof WebProjectConfig) {
WebProjectConfig webProjectConfig = (WebProjectConfig) it;
if (webProjectConfig.getAssetsPath() == null) {
webProjectConfig.setAssets(computeAssets(webProjectConfig));
}
}
};
}
protected String computeName(SubProjectConfig project) {
if (Objects.equals(project, getRuntime())) {
return baseName;
} else if (Objects.equals(project, getRuntimeTest())) {
if (!mavenLayout) {
return baseName + ".tests";
} else {
return baseName;
}
} else if (Objects.equals(project, getGenericIde())) {
return baseName + ".ide";
} else if (Objects.equals(project, getEclipsePlugin())) {
return baseName + ".ui";
} else if (Objects.equals(project, getEclipsePluginTest())) {
if (!mavenLayout) {
return baseName + ".ui.tests";
} else {
return baseName + ".ui";
}
} else if (Objects.equals(project, getWeb())) {
return baseName + ".web";
}
return null;
}
protected String computeRoot(SubProjectConfig project) {
return rootPath + "/"+ project.getName();
}
/**
* In case of "Maven/Gradle" source layout the src outlet is named
* 'src/main/java', test classes go into 'src/test/java' instead of any
* dedicated '...tests' project.
*/
protected String computeSrc(SubProjectConfig project) {
if (mavenLayout) {
return project.getRootPath() + "/" + "src/"+ computeSourceSet(project) + "/java";
} else {
return project.getRootPath() + "/" + "src";
}
}
/**
* In case of "Maven/Gradle" source layout the srcGen outlet is named
* 'src/main/xtext-gen', test-related srcGen classes go into
* 'src/test/xtext-gen' instead of any dedicated '...tests' project. Don't
* confuse it with 'src/main/xtend-gen'!
*/
protected String computeSrcGen(SubProjectConfig project) {
if (mavenLayout) {
return project.getRootPath() + "/" + "src/"+ computeSourceSet(project) + "/xtext-gen";
} else {
return project.getRootPath() + "/" + "src-gen";
}
}
protected String computeMetaInf(SubProjectConfig project) {
if (mavenLayout) {
return project.getRootPath() + "/" + "src/"+ computeSourceSet(project) + "/resources/META-INF";
} else {
return project.getRootPath() + "/" + "META-INF";
}
}
protected String computeEcoreModel(RuntimeProjectConfig project) {
return project.getRootPath() + "/" + "model/generated";
}
protected String computeAssets(WebProjectConfig project) {
if (mavenLayout) {
return project.getRootPath() + "/" + "src/"+ computeSourceSet(project) + "/webapp";
} else {
return project.getRootPath() + "/" + "WebRoot";
}
}
protected String computeSourceSet(SubProjectConfig project) {
if (getTestProjects().contains(project)) {
return "test";
} else {
return "main";
}
}
protected String computeIcons(SubProjectConfig project) {
return project.getRootPath() + "/" + "icons";
}
public boolean isMavenLayout() {
return mavenLayout;
}
public void setMavenLayout(boolean mavenLayout) {
this.mavenLayout = mavenLayout;
}
public boolean isCreateEclipseMetaData() {
return createEclipseMetaData;
}
public void setCreateEclipseMetaData(boolean createEclipseMetaData) {
this.createEclipseMetaData = createEclipseMetaData;
}
public String getRootPath() {
return rootPath;
}
public String getBaseName() {
return baseName;
}
}