Skip to content
Permalink
Browse files
JENKINS-24735 - Add support for build parameters in Subversion URLs
 
 * Extract SVNUrl variable expansion into a utility and use that acrosss
all classes that require it.
  • Loading branch information
alexouzounis committed Oct 21, 2014
1 parent 8e84f51 commit c1c458ca705f8ed0c4a324ec56ae5927f0666f93
@@ -102,30 +102,8 @@ public ModuleLocation getUpstreamSubversionLocation() {
if (scm instanceof SubversionSCM) {
SubversionSCM svn = (SubversionSCM) scm;
ModuleLocation ml = svn.getLocations()[0];
// expand system variables
Computer c = Computer.currentComputer();
if (c != null) {
try {
// JVM vars
EnvVars cEnv = c.getEnvironment();
ml = ml.getExpandedLocation(cEnv);
// node vars
for (NodeProperty<?> nodeProp: c.getNode().getNodeProperties()){
if(nodeProp instanceof EnvironmentVariablesNodeProperty){
EnvVars nodeEnvVars = ((EnvironmentVariablesNodeProperty) nodeProp).getEnvVars();
ml = ml.getExpandedLocation(nodeEnvVars);

}
}
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to get computer environment",e);
} catch (InterruptedException e) {
LOGGER.log(Level.WARNING, "Failed to get computer environment",e);

}
}
// expand upstream project variables
ml = ml.getExpandedLocation(p);
// expand system and node environment variables as well as the project parameters
ml = Utility.getExpandedLocation(ml, p);
return ml;
}
return null;
@@ -1,25 +1,19 @@
package jenkins.plugins.svnmerge;

import hudson.BulkChange;
import hudson.EnvVars;
import hudson.Util;
import hudson.model.Action;
import hudson.model.AbstractModelObject;
import hudson.model.AbstractProject;
import hudson.model.Computer;
import hudson.scm.SvnClientManager;
import hudson.scm.SCM;
import hudson.scm.SubversionSCM;
import hudson.scm.SubversionSCM.ModuleLocation;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.slaves.NodeProperty;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.ServletException;

@@ -96,6 +90,8 @@ public RepositoryLayoutInfo getRepositoryLayout() {
//TODO: check for multiple locations ?
SubversionSCM svn = (SubversionSCM) scm;
ModuleLocation firstLocation = svn.getLocations()[0];
// expand system and node environment variables as well as the project parameters
firstLocation = Utility.getExpandedLocation(firstLocation, project);
return getRepositoryLayout(firstLocation);
}

@@ -134,33 +130,8 @@ public void doNewBranch(StaplerRequest req, StaplerResponse rsp,
// TODO: check for multiple locations
SubversionSCM svn = (SubversionSCM) scm;
ModuleLocation firstLocation = svn.getLocations()[0];
// expand system variables
Computer c = Computer.currentComputer();
if (c != null) {
try {
// JVM vars
EnvVars cEnv = c.getEnvironment();
firstLocation = firstLocation.getExpandedLocation(cEnv);
// node vars
for (NodeProperty<?> nodeProp : c.getNode().getNodeProperties()) {
if (nodeProp instanceof EnvironmentVariablesNodeProperty) {
EnvVars nodeEnvVars = ((EnvironmentVariablesNodeProperty) nodeProp)
.getEnvVars();
firstLocation = firstLocation.getExpandedLocation(nodeEnvVars);

}
}
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to get computer environment",
e);
} catch (InterruptedException e) {
LOGGER.log(Level.WARNING, "Failed to get computer environment",
e);

}
}
// expand upstream project variables
firstLocation = firstLocation.getExpandedLocation(project);
// expand system and node environment variables as well as the project parameters
firstLocation = Utility.getExpandedLocation(firstLocation, project);

RepositoryLayoutInfo layoutInfo = getRepositoryLayout(firstLocation);

@@ -299,6 +270,4 @@ private boolean createSVNCopy(SvnClientManager svnMgr, ModuleLocation originalLo
}
}

private static final Logger LOGGER = Logger.getLogger(IntegratableProjectAction.class.getName());

}
@@ -0,0 +1,56 @@
package jenkins.plugins.svnmerge;

import hudson.EnvVars;
import hudson.model.Computer;
import hudson.model.Job;
import hudson.scm.SubversionSCM.ModuleLocation;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.slaves.NodeProperty;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Utility {


/**
* Expands the system variables, the node environment variables and the project parameters
*/
public static ModuleLocation getExpandedLocation(ModuleLocation ml, Job<?,?> project) {
ModuleLocation location= ml.getExpandedLocation(project);
// expand system variables
Computer c = Computer.currentComputer();
if (c != null) {
try {
// JVM vars
EnvVars cEnv = c.getEnvironment();
location = location.getExpandedLocation(cEnv);
// node vars
for (NodeProperty<?> nodeProp : c.getNode().getNodeProperties()) {
if (nodeProp instanceof EnvironmentVariablesNodeProperty) {
EnvVars nodeEnvVars = ((EnvironmentVariablesNodeProperty) nodeProp)
.getEnvVars();
location = location
.getExpandedLocation(nodeEnvVars);

}
}
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to get computer environment",
e);
} catch (InterruptedException e) {
LOGGER.log(Level.WARNING, "Failed to get computer environment",
e);

}
}
// expand project variables
if(project!=null){
location = location.getExpandedLocation(project);
}
return location;
}

private static final Logger LOGGER = Logger.getLogger(Utility.class.getName());
}

0 comments on commit c1c458c

Please sign in to comment.