Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support of additional variables, which can be specified individ…
…ually for labels. Resolves: https://issues.jenkins-ci.org/browse/JENKINS-18774 Signed-off-by: Oleg Nenashev <nenashev@synopsys.com>
- Loading branch information
1 parent
3bada61
commit 8adaaaa
Showing
8 changed files
with
256 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 0 additions & 71 deletions
71
src/main/java/com/synopsys/arc/jenkinsci/plugins/customtools/EnvVariablesConstructor.java
This file was deleted.
Oops, something went wrong.
119 changes: 119 additions & 0 deletions
119
src/main/java/com/synopsys/arc/jenkinsci/plugins/customtools/EnvVariablesInjector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright 2013 Oleg Nenashev <nenashev@synopsys.com>, Synopsys Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.synopsys.arc.jenkinsci.plugins.customtools; | ||
|
||
import hudson.EnvVars; | ||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import java.util.Map.Entry; | ||
import java.util.Properties; | ||
import java.util.TreeMap; | ||
|
||
/** | ||
* Tool-specific environment variables injector. | ||
* Implements additionalVariables for CutomTool. | ||
* @author Oleg Nenashev <nenashev@synopsys.com> | ||
* @since 0.3 | ||
*/ | ||
public class EnvVariablesInjector extends TreeMap<String, EnvVariablesInjector.Entity> | ||
{ | ||
private EnvVariablesInjector(){} | ||
|
||
public static EnvVariablesInjector Create(String props) throws IOException { | ||
Properties prop = new Properties(); | ||
StringReader rdr = new StringReader(props); | ||
prop.load(rdr); | ||
|
||
EnvVariablesInjector vars = new EnvVariablesInjector(); | ||
for (Entry<Object,Object> entry: prop.entrySet()) | ||
{ | ||
String varName = (String)entry.getKey(); | ||
Entity ent = new Entity(varName, (String)entry.getValue()); | ||
vars.put(varName, ent); | ||
} | ||
return vars; | ||
} | ||
|
||
/** | ||
* Inject variables into EnvVars | ||
* @param target Target variables | ||
* @throws IOException Exception during modification of EnvVars | ||
*/ | ||
public void Inject(EnvVars target) throws IOException { | ||
for (Entry<String, EnvVariablesInjector.Entity> entry: entrySet()) { | ||
entry.getValue().Inject(target); | ||
} | ||
} | ||
|
||
/** | ||
* Internal entry, which describes modification of Environment Variables | ||
*/ | ||
//TODO: Handle delimiters | ||
//TODO: Handle modification conflicts | ||
// etc. | ||
public static class Entity { | ||
public String envName; | ||
public String envValue; | ||
public final static String DEFAULT_LIST_DELIMITER=","; | ||
|
||
@Deprecated | ||
public String listDelimiter; | ||
@Deprecated | ||
public boolean isList; | ||
@Deprecated | ||
public boolean isOverrides; | ||
|
||
public Entity(String envName, String envValue) { | ||
this(envName, envValue, DEFAULT_LIST_DELIMITER, false, true); | ||
} | ||
|
||
/** | ||
* @deprecated Not implemented in 0.3 | ||
* @param envName | ||
* @param envValue | ||
* @param listDelimiter | ||
* @param isList | ||
* @param isOverrides | ||
*/ | ||
public Entity(String envName, String envValue, String listDelimiter, | ||
boolean isList, boolean isOverrides) | ||
{ | ||
this.envName = envName; | ||
this.envValue = envValue; | ||
this.listDelimiter = listDelimiter; | ||
this.isList = isList; | ||
this.isOverrides = isOverrides; | ||
} | ||
|
||
/** | ||
* Inject variables into EnvVars | ||
* @param target Target environment | ||
* @throws IOException Exception during modification of EnvVars | ||
*/ | ||
public void Inject(EnvVars target) throws IOException { | ||
//TODO: check overrides | ||
//TODO: check lists | ||
String val = target.get(envName); | ||
|
||
//TODO: substitute, check, etc. | ||
val = envValue; | ||
target.put(envName, val); | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.