Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ target
.settings
.project
work
/bin/
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# envfile-plugin
Hudson envfile plugin

This project is a fork to add a new feature.
It supports remote files over HTTP(s) and local filesystem.
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>org.hudsonci.plugins</groupId>
<artifactId>envfile</artifactId>
<version>1.3-h-2-SNAPSHOT</version>
<version>1.3-h-2</version>
<packaging>hpi</packaging>
<name>Hudson Environment File Plugin</name>
<url>https://wiki.hudson-ci.org/display/HUDSON/Envfile+Plugin</url>
Expand Down Expand Up @@ -41,6 +41,15 @@
</role>
</roles>
</contributor>
<contributor>
<name>Ricardo M. Augusto</name>
<email>rmaugusto@gmail.com</email>
<roles>
<role>
Developer
</role>
</roles>
</contributor>
</contributors>

<licenses>
Expand Down
68 changes: 68 additions & 0 deletions pom.xml.releaseBackup
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.hudson.plugins</groupId>
<artifactId>hudson-plugin-parent</artifactId>
<version>3.0.0</version>
</parent>

<groupId>org.hudsonci.plugins</groupId>
<artifactId>envfile</artifactId>
<version>1.3-h-2-SNAPSHOT</version>
<packaging>hpi</packaging>
<name>Hudson Environment File Plugin</name>
<url>https://wiki.hudson-ci.org/display/HUDSON/Envfile+Plugin</url>


<properties>
<hudsonTags>buildwrapper</hudsonTags>
</properties>

<developers>
<developer>
<id>schristou88</id>
<name>Steven Christou</name>
<email>schristou88@gmail.com</email>
<roles>
<role>
Maintainer
</role>
</roles>
</developer>
</developers>

<contributors>
<contributor>
<name>Anders Johansson</name>
<email>ajoajoajo@gmail.com</email>
<roles>
<role>
Original Developer
</role>
</roles>
</contributor>
<contributor>
<name>Ricardo M. Augusto</name>
<email>rmaugusto@gmail.com</email>
<roles>
<role>
Developer
</role>
</roles>
</contributor>
</contributors>

<licenses>
<license>
<name>The MIT license</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>

<scm>
<connection>scm:git:git://github.com/hudson3-plugins/envfile-plugin.git</connection>
<developerConnection>scm:git:git@github.com:hudson3-plugins/envfile-plugin.git</developerConnection>
<url>https://github.com/hudson3-plugins/envfile-plugin</url>
</scm>
</project>
16 changes: 16 additions & 0 deletions release.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#release configuration
#Wed May 25 16:59:04 BRT 2016
project.scm.org.hudsonci.plugins\:envfile.tag=HEAD
project.scm.org.hudsonci.plugins\:envfile.url=https\://github.com/hudson3-plugins/envfile-plugin
project.scm.org.hudsonci.plugins\:envfile.connection=scm\:git\:git\://github.com/hudson3-plugins/envfile-plugin.git
scm.tag=envfile-1.3-h-2
scm.url=scm\:git\:git@github.com\:hudson3-plugins/envfile-plugin.git
pushChanges=false
preparationGoals=clean verify
project.scm.org.hudsonci.plugins\:envfile.developerConnection=scm\:git\:git@github.com\:hudson3-plugins/envfile-plugin.git
project.dev.org.hudsonci.plugins\:envfile=1.3-h-3-SNAPSHOT
remoteTagging=true
scm.commentPrefix=[maven-release-plugin]
project.rel.org.hudsonci.plugins\:envfile=1.3-h-2
exec.additionalArguments=-Psonatype-oss-release
completedPhase=generate-release-poms
67 changes: 38 additions & 29 deletions src/main/java/hudson/plugins/envfile/EnvFileBuildWrapper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hudson.plugins.envfile;

import java.util.StringTokenizer;
import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher;
Expand All @@ -10,7 +11,7 @@
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrapperDescriptor;

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
Expand Down Expand Up @@ -82,15 +83,15 @@ private Properties readPropsFromFile(String path, Map<String, String> currentMap
console(Messages.EnvFileBuildWrapper_Console_ReadingFile());

Properties props = new Properties();
FileInputStream fis = null;
InputStream fis = null;
String resolvedPath = Util.replaceMacro(path, currentMap);
console(Messages.EnvFileBuildWrapper_Console_PathToFile() + ": " + resolvedPath);

try
{
if(path != null)
{
fis = new FileInputStream(resolvedPath);
fis = InputStreamFactory.createInputStream(resolvedPath);
props.load(fis);
}
else
Expand Down Expand Up @@ -119,9 +120,9 @@ private Properties readPropsFromFile(String path, Map<String, String> currentMap

/**
* Helper to close environment file.
* @param fis {@link FileInputStream} for environment file.
* @param fis {@link InputStream} for environment file.
*/
private void close(FileInputStream fis)
private void close(InputStream fis)
{
try
{
Expand All @@ -143,33 +144,41 @@ private Map<String, String> getEnvFileMap(Map<String, String> currentMap)
Map<String, String> newFileEnvMap = new HashMap<String, String>();

tmpFileEnvMap.putAll(currentMap);

//Fetch env variables from fil as properties
Properties envProps = readPropsFromFile(filePath, currentMap);

if(envProps != null || envProps.size() < 1)
{

//Add env variables to temporary env map and file map containing new variables.
for (Entry<Object, Object> prop : envProps.entrySet())

StringTokenizer st = new StringTokenizer(filePath, "\r\n|\n|\r");
while (st.hasMoreElements()) {

String uniqFile = Util.fixEmpty((String)st.nextElement());

//Fetch env variables from fil as properties
Properties envProps = readPropsFromFile(uniqFile, currentMap);

if(envProps != null || envProps.size() < 1)
{
String key = prop.getKey().toString();
String value = prop.getValue().toString();
newFileEnvMap.put(key, value);
tmpFileEnvMap.put(key, value);

//Add env variables to temporary env map and file map containing new variables.
for (Entry<Object, Object> prop : envProps.entrySet())
{
String key = prop.getKey().toString();
String value = prop.getValue().toString();
newFileEnvMap.put(key, value);
tmpFileEnvMap.put(key, value);
}

// Resolve all variables against each other.
EnvVars.resolve(tmpFileEnvMap);

//Print resolved variables and copy resolved value to return map.
for(String key : newFileEnvMap.keySet())
{
newFileEnvMap.put(key, tmpFileEnvMap.get(key));
console(key + "=" + newFileEnvMap.get(key));
}

}

// Resolve all variables against each other.
EnvVars.resolve(tmpFileEnvMap);

//Print resolved variables and copy resolved value to return map.
for(String key : newFileEnvMap.keySet())
{
newFileEnvMap.put(key, tmpFileEnvMap.get(key));
console(key + "=" + newFileEnvMap.get(key));
}


}

return newFileEnvMap;
}

Expand Down
30 changes: 30 additions & 0 deletions src/main/java/hudson/plugins/envfile/InputStreamFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package hudson.plugins.envfile;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

/**
* This class is responsible to create appropriate InputStream instance
* according to path
*
* @author Ricardo M. Augusto
*
*/
public final class InputStreamFactory {

public static InputStream createInputStream(String path)
throws IOException {
InputStream is = null;

if (path.toLowerCase().startsWith("http")) {
is = new URL(path).openStream();
} else {
is = new FileInputStream(path);
}

return is;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<f:entry title="${%Title}" help="/plugin/envfile/help-projectConfig.html" description="${%Description}">
<f:textbox name="filePath" field="filePath"/>
<f:expandableTextbox name="filePath" field="filePath"/>
</f:entry>
</j:jelly>