Skip to content

Commit

Permalink
Merge pull request #6 from MicroFocus/bug_fix
Browse files Browse the repository at this point in the history
Bug fix
  • Loading branch information
XtraSonic authored Oct 29, 2019
2 parents f6ce043 + fbd13e7 commit 364d103
Show file tree
Hide file tree
Showing 20 changed files with 242 additions and 91 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ To generate the war please execute the ```mvn package``` goal on the root module
server you are free to do so.

After generating the war you can read the Deployment section from the user guide, which you find in the
[documentation](docs/Git_Integration_For_Octane_Installation_Guide-v1.1.1.pdf).
[documentation](docs/Git_Integration_For_Octane_Installation_Guide-v1.1.2.pdf).

### Documentation

In case of any troubles, please read the user guide, found in the
[documentation](/docs/Git_Integration_For_Octane_User_Guide-v1.1.1.pdf).
[documentation](/docs/Git_Integration_For_Octane_User_Guide-v1.1.2.pdf).

### What's New
* v1.1.2
* The configuration file is loaded at startup. Some of the flaws can be detected at startup resulting in an error which can be found in Tomcat/Jetty logs file.
* Bug fixes:
* Application was failing at startup in case the path to the .war file contained spaces.
* If two instances of the application were running in parallel in the same environment the log files wold be merged.
* If multiple entities were selected at the first use for the `Get Pull Requests/Get Branch Information` features, a race condition could occur. In this case some of the UDFs would be created but not necessarily updated.
* v1.1.1
* Branches are created with a name having the following pattern: <octane_entity_id>-<octane_entity_name>
* Created the "logs.location" property to the configuration file. This allows the user to configure the location for the log files.
Expand Down
4 changes: 2 additions & 2 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<version>2.1.7.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<version>1.1.1</version>
<version>1.1.2</version>
<packaging>war</packaging>

<artifactId>api</artifactId>
Expand All @@ -23,7 +23,7 @@

<properties>
<javax.servlet.version>3.1.0</javax.servlet.version>
<git-integration-for-octane.project.version>1.1.1</git-integration-for-octane.project.version>
<git-integration-for-octane.project.version>1.1.2</git-integration-for-octane.project.version>
<git-integration-for-octane.war.name>git-integration-for-octane-</git-integration-for-octane.war.name>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@
package com.microfocus.adm.almoctane.integration.git.api;

import com.microfocus.adm.almoctane.integration.git.config.CommonUtils;
import com.microfocus.adm.almoctane.integration.git.config.Factory;
import com.microfocus.adm.almoctane.integration.git.config.OctanePool;
import com.microfocus.adm.almoctane.integration.git.config.OctanePoolException;
import org.apache.log4j.PropertyConfigurator;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
import java.util.Properties;

@SpringBootApplication
Expand All @@ -32,12 +40,13 @@ public class MainApplication extends SpringBootServletInitializer {
Properties configurationFileProperties;

try {
configurationFileProperties = CommonUtils.loadProperties("configuration.properties");
} catch (IOException e) {
throw new RuntimeException("Please provide a configuration file in the conf folder!");
configurationFileProperties = CommonUtils.loadPropertiesFromConfFolder("configuration.properties");
initLogs(configurationFileProperties);
Factory.getInstance();
OctanePool.getPool();
} catch (IOException | OctanePoolException e) {
throw new RuntimeException("Please provide a correct configuration file in the conf folder!", e);
}

initLogs(configurationFileProperties);
}

public static void main(String[] args) {
Expand All @@ -50,20 +59,74 @@ protected SpringApplicationBuilder configure(SpringApplicationBuilder applicatio
}

private static void initLogs(Properties configurationFileProperties) {
String logsLocation = configurationFileProperties.getProperty("logs.location");
String pathToLogs = configurationFileProperties.getProperty("logs.location");

//logs.location not set in the configuration file -> default
if (pathToLogs == null) {
setDefaultLogsLocation();
return;
}

pathToLogs = pathToLogs.trim().replace("\\", "/");
File logsFolder = new File(pathToLogs);


if (!logsFolder.exists() || !logsFolder.isDirectory()) {
System.out.println("The path provided for the log files in the configuration file does not " +
"represent a path to an existing folder. The logs will be placed in the default location.");
setDefaultLogsLocation();
return;
}

try {
setLog4jFileLocation(pathToLogs);
LoggerFactory.getLogger(MainApplication.class)
.info(String.format("Logs location: %s/octane_utility_logs folder", pathToLogs));

} catch (IOException | URISyntaxException e) {
System.err.println("Could not initialize the logs: " + e.getMessage());
System.err.println(Arrays.toString(e.getStackTrace()));
}

if (logsLocation != null) {
System.setProperty("git-integration-for-octane-log-folder", logsLocation);
LoggerFactory.getLogger(MainApplication.class).info(String.format("Logs location: %s\\octane_utility_logs folder", logsLocation));
}

private static void setLog4jFileLocation(String pathToLogs) throws IOException, URISyntaxException {
URL log4jPropertyUrl = MainApplication.class.getResource("/log4j.properties");
if (log4jPropertyUrl == null)
throw new FileNotFoundException("Could not find Log4j property file");
Properties logsProperty = CommonUtils.loadPropertyFile(new File(log4jPropertyUrl.toURI()));

pathToLogs = pathToLogs.replace("\\", "/");

//make sure path ends with "/"
if (!pathToLogs.endsWith("/"))
pathToLogs = pathToLogs + "/";

String logFileLocation = logsProperty.getProperty("log4j.appender.file.File");

if (logFileLocation != null) {
//replace "${...}/" with actual folder path
logFileLocation = logFileLocation.replaceAll("\\$\\{(.*)}/", pathToLogs);
} else {
logFileLocation = pathToLogs + "octane_utility_logs/octane_git_integration_logs.log";
}
logsProperty.setProperty("log4j.appender.file.File", logFileLocation);
PropertyConfigurator.configure(logsProperty);
}

private static void setDefaultLogsLocation() {
try {
File jarFile = new File(MainApplication.class.getProtectionDomain().getCodeSource().getLocation().toURI());

String logFolderPath = jarFile.getParentFile().getParentFile().toPath().toString();

String installationFolder = new File(MainApplication.class
.getProtectionDomain().getCodeSource().getLocation().getPath())
.getParentFile()
.getParent();
setLog4jFileLocation(logFolderPath);

System.setProperty("git-integration-for-octane-log-folder", "logs");
LoggerFactory.getLogger(MainApplication.class).info(String.format("Installation folder: %s. The logs can be found in the octane_utility_logs folder", installationFolder));
LoggerFactory.getLogger(MainApplication.class)
.info(String.format("Installation folder: %s. The logs can be found in the octane_utility_logs folder", logFolderPath));
} catch (URISyntaxException | IOException e) {
System.err.println("Default logs folder could not be initialized:" + e.getMessage());
System.err.println(Arrays.toString(e.getStackTrace()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public ModelAndView fetchBranchInformationIntoOctane(ModelMap model,
return new ModelAndView("OctaneResponse", model);
}


private static void setModelAttributes(ModelMap model,
List<String> ids,
String dialogId,
Expand Down
8 changes: 4 additions & 4 deletions api/src/main/webapp/conf/configuration.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ octane.password=
# The name of the field. This is what users will see in the entities.
octane.pullRequestsInformationUDFLabel=

# The name of the field must have “_udf” at the end.
# The name of the field must have “_udf” at the end. The name cannot contain spaces.
octane.pullRequestsInformationUDFName=


# In order to display the branch information, the utility will have to create a memo field using a label and a name.
# The name of the field. This is what users will see in the entities.
octane.branchInformationUDFLabel=

# The name of the field must have “_udf” at the end.
# The name of the field must have “_udf” at the end. The name cannot contain spaces.
octane.branchInformationUDFName=


Expand All @@ -46,7 +46,6 @@ octane.branchInformationUDFName=
repo.host=



# BITBUCKET
# The Bitbucket URL.
bitbucketserver.url=
Expand All @@ -64,6 +63,7 @@ bitbucketserver.access=


# LOGS LOCATION
# This can be set in order to place the logs in a custom location. Please provide the fill path (C:/example/folder/for/logs)
# This can be set in order to place the logs in a custom location. Please provide the full existing path (C:/example/folder/for/logs or C:\\example\\folder\\for\\logs)
# If this field is not present, the logs will be placed by default in the <git-integration-for-octane>/octane_utility_logs.
#
# logs.location=
4 changes: 2 additions & 2 deletions bitbucket-endpoint/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>git-integration-for-octane</artifactId>
<groupId>com.microfocus.adm.almoctane.integration.git</groupId>
<version>1.1.1</version>
<version>1.1.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -23,7 +23,7 @@
<dependency>
<groupId>com.microfocus.adm.almoctane.integration.git</groupId>
<artifactId>common</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>git-integration-for-octane</artifactId>
<groupId>com.microfocus.adm.almoctane.integration.git</groupId>
<version>1.1.1</version>
<version>1.1.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
8 changes: 4 additions & 4 deletions config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>git-integration-for-octane</artifactId>
<groupId>com.microfocus.adm.almoctane.integration.git</groupId>
<version>1.1.1</version>
<version>1.1.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -26,21 +26,21 @@
<dependency>
<groupId>com.microfocus.adm.almoctane.integration.git</groupId>
<artifactId>common</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.microfocus.adm.almoctane.integration.git</groupId>
<artifactId>bitbucket-endpoint</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.microfocus.adm.almoctane.integration.git</groupId>
<artifactId>octane-endpoint</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.Properties;

/**
Expand All @@ -32,20 +33,29 @@ public class CommonUtils {
* @return - The properties.
* @throws IOException - In case the configuration file is named differently or does not exist.
*/
public static Properties loadProperties(String propertyFileName) throws IOException {
Properties properties = new Properties();

File file = new File(Factory.class.getProtectionDomain().getCodeSource().getLocation().getPath());

String inputFilePath = String.format("%s%s%s%s%s",
file.getParentFile().getParentFile().getParent(),
File.separator, "conf",
File.separator,
propertyFileName);
public static Properties loadPropertiesFromConfFolder(String propertyFileName) throws IOException {

try {
File jarFile = new File(CommonUtils.class.getProtectionDomain().getCodeSource().getLocation().toURI());
File configurationFile = jarFile.getParentFile()
.getParentFile()
.getParentFile()
.toPath().resolve("conf").resolve(propertyFileName)
.toFile();
return loadPropertyFile(configurationFile);
} catch (URISyntaxException e) {
throw new RuntimeException("Error getting the configuration file", e);
}
}

InputStream input = new FileInputStream(inputFilePath);
properties.load(input);

public static Properties loadPropertyFile(File file) throws IOException {
Properties properties = new Properties();
try (FileInputStream fileInputStream = new FileInputStream(file)) {
properties.load(fileInputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,32 @@ public class Factory {
* @throws IOException - In case the configuration file is named differently or does not exist.
*/
private Factory() throws IOException {
properties = CommonUtils.loadProperties(propertyFileName);
properties = CommonUtils.loadPropertiesFromConfFolder(propertyFileName);

userDefinedFields = new HashMap<>();

userDefinedFields.put(OctaneUDF.Type.PULL_REQUEST, new OctaneUDF(properties.getProperty(PropertiesFileKeys.PULL_REQUESTS_INFORMATION_UDF_NAME),
properties.getProperty(PropertiesFileKeys.PULL_REQUESTS_INFORMATION_UDF_LABEL), OctaneUDF.Type.PULL_REQUEST));
userDefinedFields.put(OctaneUDF.Type.PULL_REQUEST, new OctaneUDF(properties.getProperty(PropertiesFileKeys.PULL_REQUESTS_INFORMATION_UDF_NAME).trim(),
properties.getProperty(PropertiesFileKeys.PULL_REQUESTS_INFORMATION_UDF_LABEL).trim(), OctaneUDF.Type.PULL_REQUEST));

userDefinedFields.put(OctaneUDF.Type.BRANCH, new OctaneUDF(properties.getProperty(PropertiesFileKeys.BRANCH_INFORMATION_UDF_NAME),
properties.getProperty(PropertiesFileKeys.BRANCH_INFORMATION_UDF_LABEL), OctaneUDF.Type.BRANCH));
userDefinedFields.put(OctaneUDF.Type.BRANCH, new OctaneUDF(properties.getProperty(PropertiesFileKeys.BRANCH_INFORMATION_UDF_NAME).trim(),
properties.getProperty(PropertiesFileKeys.BRANCH_INFORMATION_UDF_LABEL).trim(), OctaneUDF.Type.BRANCH));

String repoHost, server, access;
repoHost = properties.getProperty(PropertiesFileKeys.REPOSITORY_HOST);
repoHost = properties.getProperty(PropertiesFileKeys.REPOSITORY_HOST).trim();

switch (repoHost) {
case PropertiesFileKeys.BITBUCKET_SERVER:
String urlKey = repoHost + PropertiesFileKeys._URL;
String accessKey = repoHost + PropertiesFileKeys._ACCESS;
server = properties.getProperty(urlKey);
access = properties.getProperty(accessKey);
server = properties.getProperty(urlKey).trim();
access = properties.getProperty(accessKey).trim();
if (server.equals("") || access.equals(""))
throw new FactoryException(repoHost, urlKey, accessKey);
HttpTransport httpTransport = HttpTransporter.getInstance().getHttpTransport();
implementation = new BitbucketRepositoryConnectionAdapter(server, access, httpTransport);
break;
default:
throw new IOException("Configuration file contains an unknown host name");
throw new IOException("Configuration file contains an unknown " + PropertiesFileKeys.REPOSITORY_HOST + " name. Actual value: " + repoHost);
}

setProxy();
Expand Down Expand Up @@ -121,11 +121,11 @@ public OctaneService getOctaneService(String id, long sharedSpace, long workspac
*/
private static void setProxy() {
if (properties.containsKey(PropertiesFileKeys.PROXY_HOST) && properties.containsKey(PropertiesFileKeys.PROXY_PORT)) {
System.setProperty("http.proxyHost", properties.getProperty(PropertiesFileKeys.PROXY_HOST));
System.setProperty("http.proxyPort", properties.getProperty(PropertiesFileKeys.PROXY_PORT));
System.setProperty("http.proxyHost", properties.getProperty(PropertiesFileKeys.PROXY_HOST).trim());
System.setProperty("http.proxyPort", properties.getProperty(PropertiesFileKeys.PROXY_PORT).trim());

System.setProperty("https.proxyHost", properties.getProperty(PropertiesFileKeys.PROXY_HOST));
System.setProperty("https.proxyPort", properties.getProperty(PropertiesFileKeys.PROXY_PORT));
System.setProperty("https.proxyHost", properties.getProperty(PropertiesFileKeys.PROXY_HOST).trim());
System.setProperty("https.proxyPort", properties.getProperty(PropertiesFileKeys.PROXY_PORT).trim());
}
}
}
Loading

0 comments on commit 364d103

Please sign in to comment.