Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit 80b681c

Browse files
keithchongsghung
authored andcommitted
[63] For Codewind projects, use a subset of all server generators (#68)
Signed-off-by: Keith Chong <kchong@ca.ibm.com>
1 parent 64479a7 commit 80b681c

5 files changed

Lines changed: 81 additions & 10 deletions

File tree

dev/org.eclipse.codewind.openapi.core/src/org/eclipse/codewind/openapi/core/IOpenApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public interface IOpenApiConstants {
1919

2020
public static final String CODEWIND_LANGUAGE = "language"; //$NON-NLS-1$
2121
public static final String CODEWIND_PROJECT_NAME = "name"; //$NON-NLS-1$
22+
public static final String CODEWIND_PROJECT_TYPE = "projectType"; //$NON-NLS-1$
2223
public static final String CODEWIND_PROJECT_FULL_LOCAL_PATH = "fullLocalPath"; //$NON-NLS-1$
2324
public static final String CODEWIND_PROJECT_LANGUAGE = "projectLanguage"; //$NON-NLS-1$
2425
public static final String CODEWIND_GET_ID_METHOD = "getId"; //$NON-NLS-1$

dev/org.eclipse.codewind.openapi.core/src/org/eclipse/codewind/openapi/core/util/Util.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
public class Util {
3131

32-
private static String UNKNOWN_LANGUAGE = "unknown"; //$NON-NLS-1$
32+
private static String UNKNOWN_VALUE = "unknown"; //$NON-NLS-1$
3333

3434
public Util() {
3535
}
@@ -52,7 +52,7 @@ public static String getProjectLanguage(IProject project) {
5252
Object object = jobj.get(IOpenApiConstants.CODEWIND_LANGUAGE);
5353
if (object != null) {
5454
String lang = object.toString();
55-
if (UNKNOWN_LANGUAGE.equals(lang)) {
55+
if (UNKNOWN_VALUE.equals(lang)) {
5656
lang = ""; //$NON-NLS-1$
5757
}
5858
return lang;
@@ -78,7 +78,7 @@ public static String getProjectLanguage(IProject project) {
7878
Object object = jobj.get(IOpenApiConstants.CODEWIND_LANGUAGE);
7979
if (object != null) {
8080
String lang = object.toString();
81-
if (UNKNOWN_LANGUAGE.equals(lang)) {
81+
if (UNKNOWN_VALUE.equals(lang)) {
8282
lang = ""; //$NON-NLS-1$
8383
}
8484
return lang;
@@ -133,7 +133,7 @@ public static String getProjectLanguage(Object obj) {
133133

134134
if (languageObject instanceof String) {
135135
String language = (String)languageObject;
136-
if (UNKNOWN_LANGUAGE.equals(language)) { //$NON-NLS-1$
136+
if (UNKNOWN_VALUE.equals(language)) { //$NON-NLS-1$
137137
language = ""; //$NON-NLS-1$
138138
}
139139
return language;
@@ -144,6 +144,33 @@ public static String getProjectLanguage(Object obj) {
144144
return ""; //$NON-NLS-1$
145145
}
146146

147+
/**
148+
*
149+
* @param obj
150+
* @return a non-null string
151+
*/
152+
public static String getProjectTypeId(Object obj) {
153+
Class<?> clazz = obj.getClass();
154+
try {
155+
Field field = clazz.getField(IOpenApiConstants.CODEWIND_PROJECT_TYPE);
156+
Object projectTypeObject = field.get(obj);
157+
Class<?> projectTypeClass = projectTypeObject.getClass();
158+
Method getIdMethod = projectTypeClass.getMethod(IOpenApiConstants.CODEWIND_GET_ID_METHOD); //$NON-NLS-1$
159+
Object typeObject = getIdMethod.invoke(projectTypeObject);
160+
161+
if (typeObject instanceof String) {
162+
String typeId = (String)typeObject;
163+
if (UNKNOWN_VALUE.equals(typeId)) { //$NON-NLS-1$
164+
typeId = ""; //$NON-NLS-1$
165+
}
166+
return typeId;
167+
}
168+
} catch (Exception e) {
169+
Activator.log(IStatus.ERROR, e);
170+
}
171+
return ""; //$NON-NLS-1$
172+
}
173+
147174
public static IProject getProject(Object obj) {
148175
Class<?> clazz = obj.getClass();
149176
String projectName = null;

dev/org.eclipse.codewind.openapi.ui/src/org/eclipse/codewind/openapi/ui/Constants.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,15 @@ public static enum PROJECT_TYPE { MAVEN, NODEJS, GO, NOT_ASSESSED, UNKNOWN};
108108
{"Rust", "rust-server"},
109109
{"Scala", "scala-finch","scala-lagom-server", "scalatra"}
110110
};
111+
112+
public static String SPRING_SERVER = "spring";
113+
public static String LIBERTY_AND_DOCKER_SERVER_GENERATORS[] = { // The supported/tested server generators for Liberty
114+
"jaxrs-spec",
115+
"jaxrs-cxf"
116+
};
117+
118+
public static String SPRING_PROJECT_TYPE_ID = "spring";
119+
public static String LIBERTY_PROJECT_TYPE_ID = "liberty";
120+
public static String JAVA_DOCKER_PROJECT_TYPE_ID = "docker";
121+
111122
}

dev/org.eclipse.codewind.openapi.ui/src/org/eclipse/codewind/openapi/ui/wizard/AbstractGenerateWizardPage.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public abstract class AbstractGenerateWizardPage extends WizardPage {
7979

8080
protected boolean isCodewindProject = false;
8181
protected String codewindProjectLanguage = ""; //$NON-NLS-1$
82+
protected String codewindProjectTypeId = ""; //$NON-NLS-1$
8283
protected String initialOutputFolder = null;
8384

8485
public AbstractGenerateWizardPage(String pageName) {
@@ -191,7 +192,6 @@ public void widgetSelected(SelectionEvent e) {
191192
gd = new GridData(GridData.FILL_HORIZONTAL);
192193
gd.horizontalSpan = 2;
193194
languages.setLayoutData(gd);
194-
languages.addModifyListener(e -> dialogChanged(e));
195195

196196
label = new Label(container, SWT.NULL);
197197
label.setText(Messages.WIZARD_PAGE_GENERATOR_TYPE);
@@ -202,10 +202,11 @@ public void widgetSelected(SelectionEvent e) {
202202
gd.horizontalSpan = 2;
203203
generatorTypes.setToolTipText(Messages.WIZARD_PAGE_GENERATOR_TYPE_TOOLTIP);
204204
generatorTypes.setLayoutData(gd);
205-
generatorTypes.addModifyListener(e -> dialogChanged(e));
206205

207206
initialize();
208207
dialogChanged(null);
208+
languages.addModifyListener(e -> dialogChanged(e));
209+
generatorTypes.addModifyListener(e -> dialogChanged(e));
209210
setControl(container);
210211
}
211212

@@ -233,6 +234,11 @@ protected void determineProjectType() {
233234
codewindProjectLanguage = possibleLanguage;
234235
}
235236
project = Util.getProject(obj);
237+
238+
String possibleProjectTypeId = Util.getProjectTypeId(obj);
239+
if (possibleProjectTypeId.length() > 0) {
240+
this.codewindProjectTypeId = possibleProjectTypeId;
241+
}
236242
}
237243
}
238244

dev/org.eclipse.codewind.openapi.ui/src/org/eclipse/codewind/openapi/ui/wizard/GenerateServerWizardPage.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,43 @@ public GenerateServerWizardPage(ISelection selection) {
2828
@Override
2929
protected void populateGeneratorTypesCombo(String language) {
3030
generatorTypes.removeAll();
31+
// For specific Codewind overrides, populate the combo here.
32+
33+
// Populate with all known generators
3134
for (int i = 0; i < Constants.ALL_SERVER_LANGUAGES.length; i++) {
3235
if (Constants.ALL_SERVER_LANGUAGES[i][0].equals(language)) {
3336
for (int j = 1; j < Constants.ALL_SERVER_LANGUAGES[i].length; j++) {
3437
generatorTypes.add(Constants.ALL_SERVER_LANGUAGES[i][j]);
3538
}
36-
if (generatorTypes.getItemCount() > 0) {
37-
generatorTypes.select(0);
38-
}
3939
break;
4040
}
41-
}
41+
}
42+
43+
if (language == "Java") {
44+
// Spring
45+
if (isCodewindProject && this.codewindProjectTypeId.equals(Constants.SPRING_PROJECT_TYPE_ID)) {
46+
if (generatorTypes.indexOf(Constants.SPRING_SERVER) >= 0) {
47+
generatorTypes.remove(Constants.SPRING_SERVER);
48+
}
49+
generatorTypes.add(Constants.SPRING_SERVER, 0); // Put it first
50+
}
51+
52+
// For Liberty
53+
if (isCodewindProject && this.codewindProjectTypeId.equals(Constants.LIBERTY_PROJECT_TYPE_ID) || this.codewindProjectTypeId.equals(Constants.JAVA_DOCKER_PROJECT_TYPE_ID)) {
54+
int length = Constants.LIBERTY_AND_DOCKER_SERVER_GENERATORS.length;
55+
for (int i = 0; i < length; i++) {
56+
if (generatorTypes.indexOf(Constants.LIBERTY_AND_DOCKER_SERVER_GENERATORS[i]) >= 0) {
57+
generatorTypes.remove(Constants.LIBERTY_AND_DOCKER_SERVER_GENERATORS[i]);
58+
}
59+
}
60+
for (int i = length - 1; i >= 0; i--) {
61+
generatorTypes.add(Constants.LIBERTY_AND_DOCKER_SERVER_GENERATORS[i], 0); // Put them at the top of the list
62+
}
63+
}
64+
}
65+
if (generatorTypes.getItemCount() > 0) {
66+
generatorTypes.select(0);
67+
}
4268
}
4369

4470
@Override

0 commit comments

Comments
 (0)