diff --git a/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/externalprocess/ExternalProcessHandler.java b/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/externalprocess/ExternalProcessHandler.java
index 74be328374..96cdd62a77 100644
--- a/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/externalprocess/ExternalProcessHandler.java
+++ b/cobigen/cobigen-core-parent/cobigen-core/src/main/java/com/devonfw/cobigen/impl/externalprocess/ExternalProcessHandler.java
@@ -1,10 +1,12 @@
package com.devonfw.cobigen.impl.externalprocess;
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
@@ -251,6 +253,8 @@ public boolean startServer() {
LOG.error("Unable to start the exe/server", e);
}
+ LOG.info("Try to start server at port " + port);
+
return true;
}
@@ -266,17 +270,6 @@ private boolean exeIsNotValid(String filePath) {
return true;
}
- try {
- if (removeOldVersions(exeName, exeFile.getName())) {
- LOG.info(
- "Cleaning up the external servers folder because something strange was found. Server: " + exeName);
- Files.deleteIfExists(Paths.get(filePath));
- return true;
- }
- } catch (IOException e) {
- LOG.error(
- "Not able to clean externalservers folder, but we will keep the execution as this is not a blocker", e);
- }
return false;
}
@@ -386,8 +379,6 @@ private String downloadExe(String downloadURL, String filePath, String fileName)
// Remove tar file
Files.deleteIfExists(tarPath);
- // Now we remove old versions of this file
- removeOldVersions(fileName, currentFileName);
return filePath;
}
@@ -403,33 +394,6 @@ private String getLastPartOfTarPath(String path) {
return path.substring(path.lastIndexOf("/") + 1);
}
- /**
- * If found, remove all the files that contain this file name. This is used for removing not needed
- * versions of the current external process.
- * @param fileName
- * name of the external server (e.g. "nestserver")
- * @param currentFileName
- * name of the current external server including the version number and its extension (e.g.
- * "nestserver-1.0.7.exe")
- * @return true if any file was removed
- * @throws IOException
- * {@link IOException} occurred while removing the file
- */
- private Boolean removeOldVersions(String fileName, String currentFileName) throws IOException {
- File folder = new File(ExternalProcessConstants.EXTERNAL_PROCESS_FOLDER.toString());
- File[] listOfFiles = folder.listFiles();
- Boolean somethingWasRemoved = false;
-
- for (File currFile : listOfFiles) {
- if (currFile.getName().contains(fileName) && !currFile.getName().equals(currentFileName)) {
- // Remove old version of file
- Files.deleteIfExists(currFile.toPath());
- somethingWasRemoved = true;
- }
- }
- return somethingWasRemoved;
- }
-
/**
* Tries several times to start a new connection to the server. If the port is already in use, tries to
* connect again to another port
@@ -445,6 +409,8 @@ public boolean initializeConnection() {
// Just check correct port acquisition
if (acquirePort()) {
return true;
+ } else {
+ continue;
}
} catch (Exception e) {
LOG.error("Connection to server failed, attempt number " + retry + ".");
@@ -525,7 +491,26 @@ public boolean isNotConnected() {
try {
getConnection("GET", "Content-Type", "text/plain", ExternalProcessConstants.IS_CONNECTION_READY);
if (conn.getResponseCode() < 300) {
- return false;
+
+ // Check if it is the correct server version
+ try (InputStreamReader isr = new InputStreamReader(conn.getInputStream());
+ BufferedReader br = new BufferedReader(isr)) {
+ String response = br.readLine();
+
+ if (response.equals(processProperties.getServerVersion())) {
+ return false;
+ }
+
+ if (response.equals("true")) {
+ LOG.warn(
+ "An old version is currently deployed. Please consider deploying the newest version to get the current bug fixes/features");
+ return false;
+ }
+ } catch (Exception e) {
+ LOG.info("Reading server version failed");
+ }
+
+ return true;
}
} catch (IOException e) {
LOG.error("Connection to server failed, maybe the server is not yet deployed...");
diff --git a/cobigen/cobigen-core-parent/pom.xml b/cobigen/cobigen-core-parent/pom.xml
index dcfeb46ec9..2bf71c0460 100644
--- a/cobigen/cobigen-core-parent/pom.xml
+++ b/cobigen/cobigen-core-parent/pom.xml
@@ -12,7 +12,7 @@
- 6.1.1
+ 6.1.2
diff --git a/documentation/master-cobigen.asciidoc b/documentation/master-cobigen.asciidoc
index 8ae058d37f..716d03f6fb 100644
--- a/documentation/master-cobigen.asciidoc
+++ b/documentation/master-cobigen.asciidoc
@@ -12,7 +12,7 @@ This document contains the documentation of the CobiGen core module as well as a
---
-* CobiGen v6.1.1
+* CobiGen v6.1.2
* CobiGen - Java Plug-in v2.2.2
* CobiGen - XML Plug-in v4.2.0
* CobiGen - TypeScript Plug-in v2.4.3