Skip to content

Commit

Permalink
JENKINS-9093 : the context path can now also be specified
Browse files Browse the repository at this point in the history
  • Loading branch information
Willem Verstraeten committed Jul 28, 2011
1 parent ed541aa commit 9d8dd85
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
16 changes: 10 additions & 6 deletions src/main/java/hudson/plugins/deploy/CargoContainerAdapter.java
Expand Up @@ -6,11 +6,11 @@
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.remoting.VirtualChannel;
import org.apache.commons.lang.StringUtils;
import org.codehaus.cargo.container.Container;
import org.codehaus.cargo.container.ContainerType;
import org.codehaus.cargo.container.configuration.Configuration;
import org.codehaus.cargo.container.configuration.ConfigurationType;
import org.codehaus.cargo.container.deployable.Deployable;
import org.codehaus.cargo.container.deployable.WAR;
import org.codehaus.cargo.container.deployer.Deployer;
import org.codehaus.cargo.generic.ContainerFactory;
Expand Down Expand Up @@ -51,25 +51,29 @@ protected Container getContainer(ConfigurationFactory configFactory, ContainerFa
return containerFactory.createContainer(id, ContainerType.REMOTE, config);
}

protected void deploy(DeployerFactory deployerFactory, final BuildListener listener, Container container, File f) {
protected void deploy( DeployerFactory deployerFactory, final BuildListener listener, Container container, File f, String contextPath ) {
Deployer deployer = deployerFactory.createDeployer(container);

listener.getLogger().println("Deploying "+f+" to container "+container.getName());

deployer.setLogger(new LoggerImpl(listener.getLogger()));
deployer.redeploy(createDeployable(f));
WAR war = createWAR( f );
if ( !StringUtils.isEmpty(contextPath)) {
war.setContext( contextPath );
}
deployer.redeploy(war);
}

/**
* Creates a Deployable object from the given file object.
* @param deployableFile The deployable file to create the Deployable from.
* @return A Deployable object.
*/
protected Deployable createDeployable(File deployableFile) {
protected WAR createWAR(File deployableFile) {
return new WAR(deployableFile.getAbsolutePath());
}

public boolean redeploy(FilePath war, AbstractBuild<?, ?> build, Launcher launcher, final BuildListener listener) throws IOException, InterruptedException {
public boolean redeploy(FilePath war, final String contextPath, AbstractBuild<?, ?> build, Launcher launcher, final BuildListener listener) throws IOException, InterruptedException {
return war.act(new FileCallable<Boolean>() {
public Boolean invoke(File f, VirtualChannel channel) throws IOException {
if(!f.exists()) {
Expand All @@ -83,7 +87,7 @@ public Boolean invoke(File f, VirtualChannel channel) throws IOException {

Container container = getContainer(configFactory, containerFactory, getContainerId());

deploy(deployerFactory, listener, container, f);
deploy(deployerFactory, listener, container, f, contextPath);
return true;
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/deploy/ContainerAdapter.java
Expand Up @@ -27,7 +27,7 @@ public abstract class ContainerAdapter implements Describable<ContainerAdapter>,
*
* If failed, return false.
*/
public abstract boolean redeploy(FilePath war, AbstractBuild<?,?> build, Launcher launcher, final BuildListener listener) throws IOException, InterruptedException;
public abstract boolean redeploy(FilePath war, String aContextPath, AbstractBuild<?,?> build, Launcher launcher, final BuildListener listener) throws IOException, InterruptedException;

public ContainerAdapterDescriptor getDescriptor() {
return (ContainerAdapterDescriptor)Hudson.getInstance().getDescriptor(getClass());
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/hudson/plugins/deploy/DeployPublisher.java
Expand Up @@ -27,22 +27,24 @@
*/
public class DeployPublisher extends Notifier implements Serializable {
public final ContainerAdapter adapter;
public final String contextPath;

public final String war;
public final boolean onFailure;

@DataBoundConstructor
public DeployPublisher(ContainerAdapter adapter, String war, boolean onFailure) {
public DeployPublisher(ContainerAdapter adapter, String war, String contextPath, boolean onFailure) {
this.adapter = adapter;
this.war = war;
this.onFailure = onFailure;
this.contextPath = contextPath;
}

@Override
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
if (build.getResult().equals(Result.SUCCESS) || onFailure) {
for (FilePath warFile : build.getWorkspace().list(this.war)) {
if(!adapter.redeploy(warFile,build,launcher,listener))
if(!adapter.redeploy(warFile,contextPath,build,launcher,listener))
build.setResult(Result.FAILURE);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/hudson/plugins/deploy/tomcat/TomcatAdapter.java
Expand Up @@ -2,7 +2,7 @@

import hudson.plugins.deploy.PasswordProtectedAdapterCargo;
import org.codehaus.cargo.container.configuration.Configuration;
import org.codehaus.cargo.container.deployable.Deployable;
import org.codehaus.cargo.container.deployable.WAR;
import org.codehaus.cargo.container.tomcat.TomcatPropertySet;
import org.codehaus.cargo.container.tomcat.TomcatWAR;

Expand Down Expand Up @@ -40,10 +40,10 @@ public void configure(Configuration config) {
* Create a Tomcat-specific Deployable object from the given file object.
* @param deployableFile The file to deploy.
* @return A Tomcat-specific Deployable object.
* @see hudson.plugins.deploy.CargoContainerAdapter#createDeployable(java.io.File)
* @see hudson.plugins.deploy.CargoContainerAdapter#createWAR(java.io.File)
*/
@Override
protected Deployable createDeployable(File deployableFile) {
protected WAR createWAR(File deployableFile) {
return new TomcatWAR(deployableFile.getAbsolutePath());
}
}
Expand Up @@ -3,6 +3,9 @@
<f:entry title="${%WAR/EAR files}" field="war">
<f:textbox />
</f:entry>
<f:entry title="${%Context path}" field="contextPath">
<f:textbox />
</f:entry>

<f:dropdownList name="adapter" title="${%Container}">
<j:forEach var="d" items="${descriptor.containerAdapters}" varStatus="loop">
Expand Down
@@ -0,0 +1,4 @@
<div>
The context path that the container should use to publish the WAR/EAR. Note that this may get overridden
if the WAR/EAR to deploy has container-specific configuration embedded inside.
</div>
Expand Up @@ -77,13 +77,13 @@ public void testConfigureRemote() {
//@Test
public void testDeploy() throws IOException, InterruptedException {

adapter.redeploy(new FilePath(new File("D:/workspace/hudson/deploy-plugin/src/test/simple.war")), null, null, new StreamBuildListener(System.out));
adapter.redeploy(new FilePath(new File("src/test/simple.war")), "contextPath", null, null, new StreamBuildListener(System.out));
}

//@Test
public void testRemoteDeploy() throws IOException, InterruptedException {


remoteAdapter.redeploy(new FilePath(new File("/Users/meikelbode/NetBeansProjects/gitprojects/deploy-plugin/src/test/simple.war")), null, null, new StreamBuildListener(System.out));
remoteAdapter.redeploy(new FilePath(new File("/src/test/simple.war")), "contextPath", null, null, new StreamBuildListener(System.out));
}
}

0 comments on commit 9d8dd85

Please sign in to comment.