Skip to content
This repository was archived by the owner on Jan 10, 2020. It is now read-only.

Commit 6a6d924

Browse files
author
Pablo Parra
committed
Externalized configuration (Teamforge file IDs and oasp4j template version) and minor fixes
1 parent d2b012b commit 6a6d924

6 files changed

Lines changed: 53 additions & 35 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
<artifactId>javafx</artifactId>
2424
<version>2.2</version>
2525
<!-- For Java 7 -->
26-
<!-- <systemPath>${java.home}/lib/jfxrt.jar</systemPath> -->
27-
<systemPath>${java.home}/lib/ext/jfxrt.jar</systemPath>
26+
<systemPath>${java.home}/lib/jfxrt.jar</systemPath>
27+
<!-- <systemPath>${java.home}/lib/ext/jfxrt.jar</systemPath>-->
2828
<scope>system</scope>
2929
</dependency>
3030

src/main/java/com/devonfw/devcon/common/utils/Constants.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ public final class Constants {
9494
/**
9595
* OASP TEMPLATE VERSION
9696
*/
97-
public final static String OASP_TEMPLATE_VERSION = /* "2.1.2" */ "2.1.0";
97+
public final static String OASP_TEMPLATE_VERSION = "oasp_template_version";
98+
99+
/**
100+
* OASP TEMPLATE LAST STABLE VERSION
101+
*/
102+
public final static String OASP_TEMPLATE_LAST_STABLE_VERSION = "2.1.0";
98103

99104
/**
100105
* OASP TEMPLATE GROUP ID

src/main/java/com/devonfw/devcon/common/utils/Downloader.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,22 +204,22 @@ public void downloadFile(String source, String path, String tempFileName) throws
204204
}
205205

206206
/**
207-
* Method to obtain the ID of a file stored in the Teamforge site. The fileId is read from the devonfw.github.io
208-
* repository, from the "version.json" file
207+
* Method to obtain the Devcon's configuration properties from the devonfw.github.io repository, from the
208+
* "version.json" file
209209
*
210-
* @param fileReference the reference of the file in Teamforge
210+
* @param property the reference of the file in Teamforge
211211
* @return the file ID
212212
*/
213-
public static Optional<String> getFileID(String fileReference) {
213+
public static Optional<String> getDevconConfigProperty(String property) {
214214

215215
try {
216-
String fileId = null;
216+
String propertyValue = null;
217217
JSONObject json = null;
218218

219219
json = new JSONObject(IOUtils.toString(new URL(Devcon.VERSION_URL), Charset.forName("UTF-8")));
220220

221-
fileId = (String) json.get(fileReference);
222-
return Optional.of(fileId);
221+
propertyValue = (String) json.get(property);
222+
return Optional.of(propertyValue);
223223
} catch (Exception e) {
224224
return Optional.absent();
225225
}

src/main/java/com/devonfw/devcon/modules/dist/Dist.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ public void install(String path, String type, String user, String password) thro
5858
try {
5959

6060
if (type.toLowerCase().equals(DistConstants.OASP_IDE)) {
61-
teamforgeFileId = Downloader.getFileID(DistConstants.OASP_FILE_ID);
61+
teamforgeFileId = Downloader.getDevconConfigProperty(DistConstants.OASP_FILE_ID);
6262
if (!teamforgeFileId.isPresent())
6363
throw new Exception("Property " + DistConstants.OASP_FILE_ID + " not found.");
6464
} else if (type.toLowerCase().equals(DistConstants.DEVON_DIST)) {
65-
teamforgeFileId = Downloader.getFileID(DistConstants.DEVON_FILE_ID);
65+
teamforgeFileId = Downloader.getDevconConfigProperty(DistConstants.DEVON_FILE_ID);
6666
if (!teamforgeFileId.isPresent())
6767
throw new Exception("Property " + DistConstants.DEVON_FILE_ID + " not found.");
6868
} else {

src/main/java/com/devonfw/devcon/modules/oasp4j/Oasp4j.java

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.devonfw.devcon.common.api.data.ProjectType;
3939
import com.devonfw.devcon.common.impl.AbstractCommandModule;
4040
import com.devonfw.devcon.common.utils.Constants;
41+
import com.devonfw.devcon.common.utils.Downloader;
4142
import com.devonfw.devcon.common.utils.Utils;
4243
import com.google.common.base.Optional;
4344

@@ -63,7 +64,7 @@ public Oasp4j() {
6364
* @param packagename Package Name of Server Project
6465
* @param groupid Group Id of the Server Project
6566
* @param version Version of the Server Project
66-
* @throws IOException
67+
* @throws Exception
6768
*/
6869
@Command(name = "create", description = "This creates a new server project based on OASP template")
6970
@Parameters(values = {
@@ -73,15 +74,22 @@ public Oasp4j() {
7374
@Parameter(name = "groupid", description = "groupid for server project"),
7475
@Parameter(name = "version", description = "version of server project") })
7576
public void create(String serverpath, String servername, String packagename, String groupid, String version)
76-
throws IOException {
77+
throws Exception {
7778

78-
String command =
79-
new StringBuffer("cmd /c mvn -DarchetypeVersion=").append(Constants.OASP_TEMPLATE_VERSION)
80-
.append(" -DarchetypeGroupId=").append(Constants.OASP_TEMPLATE_GROUP_ID).append(" -DarchetypeArtifactId=")
81-
.append(Constants.OASP_TEMPLATE_GROUP_ID).append(" -DarchetypeArtifactId=")
82-
.append(Constants.OASP_ARTIFACT_ID).append(" archetype:generate -DgroupId=").append(groupid)
83-
.append(" -DartifactId=").append(servername).append(" -Dversion=").append(version).append(" -Dpackage=")
84-
.append(packagename).append(" -DinteractiveMode=false").toString();
79+
Optional<String> oaspTemplateVersion_op = Downloader.getDevconConfigProperty(Constants.OASP_TEMPLATE_VERSION);
80+
String oaspTemplateVersion =
81+
oaspTemplateVersion_op.isPresent() ? oaspTemplateVersion_op.get() : Constants.OASP_TEMPLATE_LAST_STABLE_VERSION;
82+
if (!oaspTemplateVersion_op.isPresent())
83+
this.output.showError("Oasp template version not found in config file.");
84+
85+
this.output.showMessage("Using the oasp template version: " + oaspTemplateVersion);
86+
87+
String command = new StringBuffer("cmd /c mvn -DarchetypeVersion=").append(oaspTemplateVersion)
88+
.append(" -DarchetypeGroupId=").append(Constants.OASP_TEMPLATE_GROUP_ID).append(" -DarchetypeArtifactId=")
89+
.append(Constants.OASP_TEMPLATE_GROUP_ID).append(" -DarchetypeArtifactId=").append(Constants.OASP_ARTIFACT_ID)
90+
.append(" archetype:generate -DgroupId=").append(groupid).append(" -DartifactId=").append(servername)
91+
.append(" -Dversion=").append(version).append(" -Dpackage=").append(packagename)
92+
.append(" -DinteractiveMode=false").toString();
8593

8694
if (!SystemUtils.IS_OS_WINDOWS) {
8795
getOutput().showMessage("This task is currently only supported on Windows");
@@ -129,10 +137,13 @@ public void create(String serverpath, String servername, String packagename, Str
129137
getOutput().showMessage("Adding devon.json file...");
130138
Utils.addDevonJsonFile(project.toPath(), ProjectType.OASP4J);
131139

132-
if (Integer.parseInt(Constants.OASP_TEMPLATE_VERSION.replaceAll("\\.", "")) <= new Integer("211")) {
140+
if (Integer.parseInt(
141+
/* Constants.OASP_TEMPLATE_VERSION */oaspTemplateVersion.replaceAll("\\.", "")) <= new Integer("211")) {
133142
modifyPom(serverpath + "\\" + servername + "\\server\\pom.xml", packagename);
134143
}
135144

145+
getOutput().showMessage("Oasp4j project created successfully");
146+
136147
} else {
137148
throw new Exception("Project creation failed");
138149
}
@@ -158,7 +169,8 @@ public void create(String serverpath, String servername, String packagename, Str
158169
* @param port Server will be started at this port
159170
*/
160171
@Command(name = "run", description = "This command runs the application from spring boot embedded tomcat", context = ContextType.PROJECT)
161-
@Parameters(values = { @Parameter(name = "port", description = "Port to start Spring boot app (port 8081 by default)", optional = true) })
172+
@Parameters(values = {
173+
@Parameter(name = "port", description = "Port to start Spring boot app (port 8081 by default)", optional = true) })
162174
public void run(String port) {
163175

164176
if (!this.projectInfo.isPresent()) {
@@ -246,7 +258,8 @@ public void build() {
246258
* @param path server project path
247259
*/
248260
@Command(name = "deploy", description = "This command will deploy the server project on tomcat", context = ContextType.PROJECT)
249-
@Parameters(values = { @Parameter(name = "tomcatpath", description = "Path to tomcat folder (if not provided and the project is in a Devonfw distribution the default software/tomcat folder will be used)", optional = true, inputType = @InputType(name = InputTypeNames.PATH)) })
261+
@Parameters(values = {
262+
@Parameter(name = "tomcatpath", description = "Path to tomcat folder (if not provided and the project is in a Devonfw distribution the default software/tomcat folder will be used)", optional = true, inputType = @InputType(name = InputTypeNames.PATH)) })
250263
public void deploy(String tomcatpath) {
251264

252265
String path;
@@ -272,9 +285,9 @@ public void deploy(String tomcatpath) {
272285

273286
if (appName.isPresent()) {
274287

275-
tomcatpath =
276-
tomcatpath.isEmpty() ? distInfo.get().getPath().toFile().toString() + File.separator + "software"
277-
+ File.separator + "tomcat" : tomcatpath;
288+
tomcatpath = tomcatpath.isEmpty()
289+
? distInfo.get().getPath().toFile().toString() + File.separator + "software" + File.separator + "tomcat"
290+
: tomcatpath;
278291

279292
File tomcatDir = new File(tomcatpath);
280293

@@ -343,13 +356,13 @@ public void deploy(String tomcatpath) {
343356
int tomcatResult = tomcatProcess.waitFor();
344357

345358
if (tomcatResult == 0) {
346-
getOutput().showMessage(
347-
"##########################################################################");
348-
getOutput().showMessage(
349-
"After Tomcat finishes the loading process the app should be available in: ");
359+
getOutput()
360+
.showMessage("##########################################################################");
361+
getOutput()
362+
.showMessage("After Tomcat finishes the loading process the app should be available in: ");
350363
getOutput().showMessage("localhost:8080/" + warFile.getName().replace(".war", ""));
351-
getOutput().showMessage(
352-
"##########################################################################");
364+
getOutput()
365+
.showMessage("##########################################################################");
353366
}
354367

355368
} else {

src/main/java/com/devonfw/devcon/modules/oasp4js/Oasp4js.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ public void jumpstart(String path, String angularVersion, String user, String pa
189189

190190
if (angularVersion.equals("1")) {
191191
// frsFileId = OASP4JS_ang1;
192-
frsFileId = Downloader.getFileID(OASP4JS_ang1_ID);
192+
frsFileId = Downloader.getDevconConfigProperty(OASP4JS_ang1_ID);
193193
if (!frsFileId.isPresent())
194194
throw new Exception("Property " + OASP4JS_ang1_ID + " not found.");
195195
} else if (angularVersion.equals("2")) {
196196
// frsFileId = OASP4JS_ang2;
197-
frsFileId = Downloader.getFileID(OASP4JS_ang2_ID);
197+
frsFileId = Downloader.getDevconConfigProperty(OASP4JS_ang2_ID);
198198
if (!frsFileId.isPresent())
199199
throw new Exception("Property " + OASP4JS_ang2_ID + " not found.");
200200
} else {

0 commit comments

Comments
 (0)