From 9a33f84d8c3a5fd81d5432c457e40da8e4c88f3b Mon Sep 17 00:00:00 2001 From: "Ricardo M. Augusto" Date: Wed, 25 May 2016 16:46:31 -0300 Subject: [PATCH 1/3] Added support for remote files over HTTP(s) --- pom.xml | 9 ++++++ .../plugins/envfile/EnvFileBuildWrapper.java | 10 +++---- .../plugins/envfile/InputStreamFactory.java | 30 +++++++++++++++++++ 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 src/main/java/hudson/plugins/envfile/InputStreamFactory.java diff --git a/pom.xml b/pom.xml index 3984937..d3c0159 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,15 @@ + + Ricardo M. Augusto + rmaugusto@gmail.com + + + Developer + + + diff --git a/src/main/java/hudson/plugins/envfile/EnvFileBuildWrapper.java b/src/main/java/hudson/plugins/envfile/EnvFileBuildWrapper.java index 323bd82..28527f2 100755 --- a/src/main/java/hudson/plugins/envfile/EnvFileBuildWrapper.java +++ b/src/main/java/hudson/plugins/envfile/EnvFileBuildWrapper.java @@ -10,7 +10,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; @@ -82,7 +82,7 @@ private Properties readPropsFromFile(String path, Map 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); @@ -90,7 +90,7 @@ private Properties readPropsFromFile(String path, Map currentMap { if(path != null) { - fis = new FileInputStream(resolvedPath); + fis = InputStreamFactory.createInputStream(resolvedPath); props.load(fis); } else @@ -119,9 +119,9 @@ private Properties readPropsFromFile(String path, Map 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 { diff --git a/src/main/java/hudson/plugins/envfile/InputStreamFactory.java b/src/main/java/hudson/plugins/envfile/InputStreamFactory.java new file mode 100644 index 0000000..2c463f2 --- /dev/null +++ b/src/main/java/hudson/plugins/envfile/InputStreamFactory.java @@ -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; + } + +} From 4521c9034171fe04ce51497d45676490e542e501 Mon Sep 17 00:00:00 2001 From: "Ricardo M. Augusto" Date: Wed, 25 May 2016 16:48:47 -0300 Subject: [PATCH 2/3] Create README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..1eeae45 --- /dev/null +++ b/README.md @@ -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. From 606f46e7c3043acccf7d9065315fa6036bb258c9 Mon Sep 17 00:00:00 2001 From: "Ricardo M. Augusto" Date: Fri, 27 May 2016 18:19:56 -0300 Subject: [PATCH 3/3] Accept multiples files --- .gitignore | 1 + pom.xml | 2 +- pom.xml.releaseBackup | 68 +++++++++++++++++++ release.properties | 16 +++++ .../plugins/envfile/EnvFileBuildWrapper.java | 57 +++++++++------- .../envfile/EnvFileBuildWrapper/config.jelly | 2 +- 6 files changed, 120 insertions(+), 26 deletions(-) create mode 100644 pom.xml.releaseBackup create mode 100644 release.properties diff --git a/.gitignore b/.gitignore index 5b7b1e4..b9d3ea1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ target .settings .project work +/bin/ diff --git a/pom.xml b/pom.xml index d3c0159..a60aa75 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ org.hudsonci.plugins envfile - 1.3-h-2-SNAPSHOT + 1.3-h-2 hpi Hudson Environment File Plugin https://wiki.hudson-ci.org/display/HUDSON/Envfile+Plugin diff --git a/pom.xml.releaseBackup b/pom.xml.releaseBackup new file mode 100644 index 0000000..d3c0159 --- /dev/null +++ b/pom.xml.releaseBackup @@ -0,0 +1,68 @@ + + 4.0.0 + + org.eclipse.hudson.plugins + hudson-plugin-parent + 3.0.0 + + + org.hudsonci.plugins + envfile + 1.3-h-2-SNAPSHOT + hpi + Hudson Environment File Plugin + https://wiki.hudson-ci.org/display/HUDSON/Envfile+Plugin + + + + buildwrapper + + + + + schristou88 + Steven Christou + schristou88@gmail.com + + + Maintainer + + + + + + + + Anders Johansson + ajoajoajo@gmail.com + + + Original Developer + + + + + Ricardo M. Augusto + rmaugusto@gmail.com + + + Developer + + + + + + + + The MIT license + http://www.opensource.org/licenses/mit-license.php + repo + + + + + scm:git:git://github.com/hudson3-plugins/envfile-plugin.git + scm:git:git@github.com:hudson3-plugins/envfile-plugin.git + https://github.com/hudson3-plugins/envfile-plugin + + diff --git a/release.properties b/release.properties new file mode 100644 index 0000000..97c599b --- /dev/null +++ b/release.properties @@ -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 diff --git a/src/main/java/hudson/plugins/envfile/EnvFileBuildWrapper.java b/src/main/java/hudson/plugins/envfile/EnvFileBuildWrapper.java index 28527f2..3fd6e4c 100755 --- a/src/main/java/hudson/plugins/envfile/EnvFileBuildWrapper.java +++ b/src/main/java/hudson/plugins/envfile/EnvFileBuildWrapper.java @@ -1,5 +1,6 @@ package hudson.plugins.envfile; +import java.util.StringTokenizer; import hudson.EnvVars; import hudson.Extension; import hudson.Launcher; @@ -143,33 +144,41 @@ private Map getEnvFileMap(Map currentMap) Map newFileEnvMap = new HashMap(); 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 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 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; } diff --git a/src/main/resources/hudson/plugins/envfile/EnvFileBuildWrapper/config.jelly b/src/main/resources/hudson/plugins/envfile/EnvFileBuildWrapper/config.jelly index 7d7c5c0..cd02388 100755 --- a/src/main/resources/hudson/plugins/envfile/EnvFileBuildWrapper/config.jelly +++ b/src/main/resources/hudson/plugins/envfile/EnvFileBuildWrapper/config.jelly @@ -1,6 +1,6 @@ - +