Skip to content

Commit

Permalink
[JENKINS-14646] - Replace old name HudsonXXXX by XXXX
Browse files Browse the repository at this point in the history
[JENKINS-14626] - Specify file name generated to deploy

Signed-off-by: Raphael CHAUMIER <rcr@orange.fr>
  • Loading branch information
Raphael CHAUMIER committed Aug 1, 2012
1 parent 84ca5fc commit c1954bd
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 47 deletions.
Expand Up @@ -21,11 +21,12 @@ public interface ArtifactSelector {
*
* @param build
* @param listener
* @param filteredResource
* @return
* @throws IOException
* @throws XmlPullParserException
* @throws InterruptedException
*/
public Artifact selectArtifactRecorded(AbstractBuild<?, ?> build, BuildListener listener) throws IOException, XmlPullParserException, InterruptedException;
public Artifact selectArtifactRecorded(AbstractBuild<?, ?> build, BuildListener listener, String filteredResource) throws IOException, XmlPullParserException, InterruptedException;

}
Expand Up @@ -18,6 +18,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;

import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

/**
Expand All @@ -29,45 +31,50 @@ public class MavenJobArtifactSelectorImpl implements ArtifactSelector {
private static transient final Pattern ARTIFACT_DEPLOYABLE_PATTERN = Pattern.compile(".*\\.(ear|war|jar)", Pattern.CASE_INSENSITIVE);

/* (non-Javadoc)
* @see org.jenkinsci.plugins.deploy.weblogic.TargetGeneratedSelector#getTargetGeneratedFilePath()
* @see org.jenkinsci.plugins.deploy.weblogic.ArtifactSelector#selectArtifactRecorded(hudson.model.AbstractBuild, hudson.model.BuildListener, java.lang.String)
*/
public Artifact selectArtifactRecorded(AbstractBuild<?, ?> build, BuildListener listener) throws IOException, XmlPullParserException, InterruptedException {
public Artifact selectArtifactRecorded(AbstractBuild<?, ?> build, BuildListener listener, String filteredResource) throws IOException, XmlPullParserException, InterruptedException {

Artifact selectedArtifact = null;

List<MavenAbstractArtifactRecord<MavenBuild>> mars = getActions( build, listener);
if(mars==null || mars.isEmpty()) {
listener.getLogger().println("[HudsonWeblogicDeploymentPlugin] - No artifacts are recorded. Is this a Maven project?");
listener.getLogger().println("[WeblogicDeploymentPlugin] - No artifacts are recorded. Is this a Maven project?");
}

listener.getLogger().println("[HudsonWeblogicDeploymentPlugin] - Retrieving artifacts recorded...");
listener.getLogger().println("[WeblogicDeploymentPlugin] - Retrieving artifacts recorded...");
List<Artifact> artifactsRecorded = new ArrayList<Artifact>();
for (MavenAbstractArtifactRecord<MavenBuild> mar : mars) {
listener.getLogger().println("[HudsonWeblogicDeploymentPlugin] - "+mar.getBuild().getArtifacts().size()+ " artifacts recorded in "+mar.getBuild().getArtifactsDir());
listener.getLogger().println("[WeblogicDeploymentPlugin] - "+mar.getBuild().getArtifacts().size()+ " artifacts recorded in "+mar.getBuild().getArtifactsDir());
for(Artifact artifact : mar.getBuild().getArtifacts()){
//On ne conserve que les jar,ear et war
Matcher matcher = ARTIFACT_DEPLOYABLE_PATTERN.matcher(artifact.getFileName());
while (matcher.find()) {
listener.getLogger().println("[HudsonWeblogicDeploymentPlugin] - the following artifact recorded "+artifact.getFileName()+" is eligible.");
//Si une expression reguliere est fournie on filtre en priorité sur la regex
if(StringUtils.isNotEmpty(filteredResource) && Pattern.matches(filteredResource, artifact.getFileName())){
listener.getLogger().println("[WeblogicDeploymentPlugin] - the following artifact recorded "+artifact.getFileName()+" is eligible.");
artifactsRecorded.add(artifact);
}

} else {
//On ne conserve que les jar,ear et war
Matcher matcher = ARTIFACT_DEPLOYABLE_PATTERN.matcher(artifact.getFileName());
while (matcher.find()) {
listener.getLogger().println("[WeblogicDeploymentPlugin] - the following artifact recorded "+artifact.getFileName()+" is eligible.");
artifactsRecorded.add(artifact);
}
}
}
}

if(artifactsRecorded.size() < 1){
throw new RuntimeException("[HudsonWeblogicDeploymentPlugin] - No artifact to deploy found.");
throw new RuntimeException("[WeblogicDeploymentPlugin] - No artifact to deploy found.");
}

if(artifactsRecorded.size() > 1){
listener.getLogger().println("[HudsonWeblogicDeploymentPlugin] - More than 1 artifact found : The first one "+artifactsRecorded.get(0)+ " will be deployed!!!");
listener.getLogger().println("[WeblogicDeploymentPlugin] - More than 1 artifact found : The first one "+artifactsRecorded.get(0)+ " will be deployed!!!");
}

selectedArtifact = artifactsRecorded.get(0);

// Erreur si l'artifact n'existe pas
if(selectedArtifact == null){
throw new RuntimeException("[HudsonWeblogicDeploymentPlugin] - No artifact to deploy found.");
throw new RuntimeException("[WeblogicDeploymentPlugin] - No artifact to deploy found.");
}

return selectedArtifact;
Expand All @@ -87,7 +94,7 @@ protected List<MavenAbstractArtifactRecord<MavenBuild>> getActions(AbstractBuild
for (Entry<MavenModule, MavenBuild> e : ((MavenModuleSetBuild)build).getModuleLastBuilds().entrySet()) {
MavenAbstractArtifactRecord<MavenBuild> a = e.getValue().getAction(MavenAbstractArtifactRecord.class);
if (a == null) {
listener.getLogger().println("[HudsonWeblogicDeploymentPlugin] - No artifacts are recorded for module" + e.getKey().getName() + ". Is this a Maven project?");
listener.getLogger().println("[WeblogicDeploymentPlugin] - No artifacts are recorded for module" + e.getKey().getName() + ". Is this a Maven project?");
} else {
actions.add(a);
}
Expand Down

0 comments on commit c1954bd

Please sign in to comment.