Skip to content

Commit

Permalink
Merge branch 'dev_core'
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeSchumacherCapgemini committed Jul 31, 2020
2 parents 91c3bb9 + 4ca5ae5 commit e2b3919
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;

}
Expand All @@ -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
Expand All @@ -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 + ".");
Expand Down Expand Up @@ -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...");
Expand Down
2 changes: 1 addition & 1 deletion cobigen/cobigen-core-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</parent>

<properties>
<cobigencore.version>6.1.1</cobigencore.version>
<cobigencore.version>6.1.2</cobigencore.version>
</properties>

<modules>
Expand Down
2 changes: 1 addition & 1 deletion documentation/master-cobigen.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e2b3919

Please sign in to comment.