Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-50626] - Refactoring: Move duplicated Config property retrie…
…val logic to the Config Class
  • Loading branch information
oleg-nenashev committed Apr 6, 2018
1 parent ff72d15 commit 7f1ebce
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
Expand Up @@ -25,10 +25,17 @@
*/
package org.jenkins.tools.test.model;

import org.apache.commons.lang.StringUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
* POJO used to configure PluginCompatTester execution
Expand Down Expand Up @@ -206,6 +213,33 @@ public void setMavenPropertiesFiles( String mavenPropertiesFile ) {
this.mavenPropertiesFile = mavenPropertiesFile;
}

/**
* Retrieves Maven Properties from available sources like {@link #mavenPropertiesFile}.
* @return Map of properties
* @throws IOException Property read failure
* @since TODO
*/
public Map<String, String> retrieveMavenProperties() throws IOException {
Map<String, String> res = new HashMap<>();

// Read properties from File
if ( StringUtils.isNotBlank( mavenPropertiesFile )) {
File file = new File (mavenPropertiesFile);
if (file.exists() && file.isFile()) {
try(FileInputStream fileInputStream = new FileInputStream(file)) {
Properties properties = new Properties( );
properties.load( fileInputStream );
for (Map.Entry<Object,Object> entry : properties.entrySet()) {
res.put((String) entry.getKey(), (String) entry.getValue());
}
}
} else {
throw new IOException("Extra Maven Properties File " + mavenPropertiesFile + " does not exist or not a File" );
}
}
return res;
}

public TestStatus getCacheThresholStatus() {
return cacheThresholStatus;
}
Expand Down
Expand Up @@ -211,21 +211,7 @@ public PluginCompatReport testPlugins()
// TODO REMOVE
mconfig.userProperties.put( "failIfNoTests", "false" );
mconfig.userProperties.put( "argLine", "-XX:MaxPermSize=128m" );
String mavenPropertiesFilePath = this.config.getMavenPropertiesFile();
if ( StringUtils.isNotBlank( mavenPropertiesFilePath )) {
File file = new File (mavenPropertiesFilePath);
if (file.exists() && file.isFile()) {
try(FileInputStream fileInputStream = new FileInputStream(file)) {
Properties properties = new Properties( );
properties.load( fileInputStream );
for (Map.Entry<Object,Object> entry : properties.entrySet()) {
mconfig.userProperties.put((String) entry.getKey(), (String) entry.getValue());
}
}
} else {
throw new IOException("Extra Maven Properties File " + mavenPropertiesFilePath + " does not exist" );
}
}
mconfig.userProperties.putAll(this.config.retrieveMavenProperties());

SCMManagerFactory.getInstance().start();
for(MavenCoordinates coreCoordinates : testedCores){
Expand Down
Expand Up @@ -106,25 +106,8 @@ private MavenRunner.Config getMavenConfig(PluginCompatTesterConfig config) throw
// TODO REMOVE
mconfig.userProperties.put("failIfNoTests", "false");
mconfig.userProperties.put("argLine", "-XX:MaxPermSize=128m");
String mavenPropertiesFilePath = config.getMavenPropertiesFile();
if (StringUtils.isNotBlank(mavenPropertiesFilePath)) {
File file = new File(mavenPropertiesFilePath);
if (file.exists()) {
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(file);
Properties properties = new Properties();
properties.load(fileInputStream);
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
mconfig.userProperties.put((String) entry.getKey(), (String) entry.getValue());
}
} finally {
IOUtils.closeQuietly(fileInputStream);
}
} else {
System.out.println("File " + mavenPropertiesFilePath + " not exists");
}
}
mconfig.userProperties.putAll(config.retrieveMavenProperties());

return mconfig;
}

Expand Down

0 comments on commit 7f1ebce

Please sign in to comment.