Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 c1c458c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 59 deletions.
26 changes: 2 additions & 24 deletions src/main/java/jenkins/plugins/svnmerge/FeatureBranchProperty.java
Expand Up @@ -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;
Expand Down
@@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);

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

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

}
56 changes: 56 additions & 0 deletions src/main/java/jenkins/plugins/svnmerge/Utility.java
@@ -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.