diff --git a/pom.xml b/pom.xml index 508ebbe..de4cc75 100644 --- a/pom.xml +++ b/pom.xml @@ -3,23 +3,37 @@ 4.0.0 org.jvnet.hudson.plugins maven-deployment-linker - 1.6-SNAPSHOT + 2.0-SNAPSHOT hpi Maven Deployment Linker - http://wiki.hudson-ci.org/display/HUDSON/Maven+Deployment+Linker + https://plugins.jenkins.io/${project.artifactId} - scm:git:https://github.com/jenkinsci/maven-deployment-linker-plugin.git - scm:git:https://github.com/jenkinsci/maven-deployment-linker-plugin.git - https://github.com/jenkinsci/favorite-plugin + scm:git:https://github.com/jenkinsci/${project.artifactId}-plugin.git + scm:git:https://github.com/jenkinsci/${project.artifactId}-plugin.git + https://github.com/jenkinsci/${project.artifactId}-plugin org.jenkins-ci.plugins plugin - 1.420 + 2.4 + UTF-8 + + 1.642.3 + + 7 + + + + + 1.15 + lshatzer @@ -67,15 +81,89 @@ org.jenkins-ci.plugins token-macro 1.5.1 - + + + + + org.jenkins-ci.plugins.workflow + workflow-step-api + ${workflow-plugins.version} + + + + org.jenkins-ci.plugins.workflow + workflow-job + ${workflow-plugins.version} + test + + + org.jenkins-ci.plugins.workflow + workflow-cps + ${workflow-plugins.version} + test + + + org.jenkins-ci.plugins.workflow + workflow-basic-steps + ${workflow-plugins.version} + test + + + org.jenkins-ci.plugins.workflow + workflow-durable-task-step + ${workflow-plugins.version} + test + + + org.jenkins-ci.plugins.workflow + workflow-support + ${workflow-plugins.version} + tests + test + + + + org.jenkins-ci.plugins + git + 2.4.1 + test + + + org.apache.httpcomponents + httpclient + + + + org.jenkins-ci.tools maven-hpi-plugin - 1.90 true + + + FINE + FINE + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + + false + diff --git a/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentDownloader.java b/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentDownloader.java index 51eb68a..a3d9361 100644 --- a/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentDownloader.java +++ b/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentDownloader.java @@ -5,22 +5,17 @@ import hudson.Launcher; import hudson.Util; import hudson.console.HyperlinkNote; -import hudson.model.AutoCompletionCandidates; -import hudson.model.BuildListener; -import hudson.model.AbstractBuild; -import hudson.model.AbstractProject; -import hudson.model.Hudson; -import hudson.model.Job; +import hudson.model.*; import hudson.model.PermalinkProjectAction.Permalink; -import hudson.model.Run; import hudson.plugins.mavendeploymentlinker.MavenDeploymentLinkerAction.ArtifactVersion; import hudson.tasks.BuildStepDescriptor; import hudson.tasks.Builder; import hudson.util.FormValidation; -import hudson.util.IOUtils; import hudson.util.ListBoxModel; import hudson.util.ListBoxModel.Option; +import jenkins.model.Jenkins; +import javax.servlet.ServletException; import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; @@ -31,17 +26,11 @@ import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; -import javax.servlet.ServletException; - +import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException; import org.jenkinsci.plugins.tokenmacro.TokenMacro; -import org.kohsuke.stapler.AncestorInPath; -import org.kohsuke.stapler.DataBoundConstructor; -import org.kohsuke.stapler.QueryParameter; -import org.kohsuke.stapler.Stapler; -import org.kohsuke.stapler.StaplerRequest; - +import org.kohsuke.stapler.*; import com.ning.http.client.AsyncHttpClient; import com.ning.http.client.Response; @@ -92,7 +81,7 @@ public MavenDeploymentDownloader(String projectName, String filePattern, String if (req != null) { // Prevents both invalid values and access to artifacts of projects which this user cannot see. // If value is parameterized, it will be checked when build runs. - if (Hudson.getInstance().getItemByFullName(projectName, Job.class) == null) { + if (Jenkins.getInstance().getItemByFullName(projectName, Job.class) == null) { projectName = ""; // Ignore/clear bad value to avoid ugly 500 page } } @@ -164,7 +153,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListen return false; } - final Job job = Hudson.getInstance().getItemByFullName(resolvedProjectName, Job.class); + final Job job = Jenkins.getInstance().getItemByFullName(resolvedProjectName, Job.class); FilePath targetDirFp = new FilePath(build.getWorkspace(), targetDir); if (cleanTargetDir) { @@ -179,7 +168,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListen { // do some hyper linked logging - final String jobUrl = Hudson.getInstance().getRootUrl() + "job/" + resolvedProjectName; + final String jobUrl = Jenkins.getInstance().getRootUrl() + "job/" + resolvedProjectName; final String linkBuildNr = HyperlinkNote.encodeTo(jobUrl + "/" + resolvedJob.number, "#" + resolvedJob.number); final String linkPerma = HyperlinkNote.encodeTo(jobUrl + "/" + link.getId(), link.getDisplayName()); final String linkJob = HyperlinkNote.encodeTo(jobUrl, resolvedProjectName); @@ -256,7 +245,7 @@ public DescriptorImpl getDescriptor() { public static final class DescriptorImpl extends BuildStepDescriptor { public AutoCompletionCandidates doAutoCompleteProjectName(@QueryParameter String value) { - final List jobs = Hudson.getInstance().getItems(Job.class); + final List jobs = Jenkins.getInstance().getItems(Job.class); AutoCompletionCandidates c = new AutoCompletionCandidates(); for (Job job : jobs) if (job.getName().toLowerCase().startsWith(value.toLowerCase())) @@ -268,7 +257,7 @@ public ListBoxModel doFillPermaLinkItems(@AncestorInPath Job defaultJob, @ // gracefully fall back to some job, if none is given Job j = null; if (projectName != null) - j = Hudson.getInstance().getItem(projectName, defaultJob, Job.class); + j = Jenkins.getInstance().getItem(projectName, defaultJob, Job.class); if (j == null) j = defaultJob; diff --git a/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerAction.java b/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerAction.java index 055f5c2..6d415bc 100644 --- a/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerAction.java +++ b/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerAction.java @@ -1,39 +1,61 @@ package hudson.plugins.mavendeploymentlinker; import hudson.model.Action; - -import org.apache.commons.lang.StringUtils; -import org.kohsuke.stapler.export.Exported; +import hudson.model.Run; +import jenkins.tasks.SimpleBuildStep; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.regex.Pattern; -public class MavenDeploymentLinkerAction implements Action { - - /*package*/ static class ArtifactVersion { +import org.apache.commons.lang.StringUtils; +import org.kohsuke.stapler.export.Exported; + +public class MavenDeploymentLinkerAction implements Action, SimpleBuildStep.LastBuildAction { + + private List projectActions; + + public MavenDeploymentLinkerAction(Run build) { + List projectActions = new ArrayList<>(); + projectActions.add(new MavenDeploymentProjectLinkerAction(build.getParent())); + this.projectActions = projectActions; + } + + public static class ArtifactVersion { private static final String SNAPSHOT_PATTERN = ".*-SNAPSHOT.*"; private static final Pattern p = Pattern.compile(SNAPSHOT_PATTERN); - + private ArtifactVersion(String url) { this.url = normalize(url); snapshot = p.matcher(url).matches(); } - + private final String url; private boolean snapshot; - + private String normalize(String url) { // JENKINS-9114 : Remove "dav:" when Maven uses webdav deployment return StringUtils.removeStart(url, "dav:"); } - + public boolean isSnapshot() { return snapshot; } + public String getUrl() { return url; } + + + public String getArtifactName() { + return url.substring(url.lastIndexOf('/') + 1, url.length()); + } + + /** + * @deprecated use {@link #getUrl} and {@link #getArtifactName()} instead. + */ + @Deprecated public String getText() { StringBuilder textBuilder = new StringBuilder(); textBuilder.append("\n
  • "); @@ -44,14 +66,14 @@ public String getText() { return textBuilder.toString(); } } - + private List deployments = new ArrayList(); - + private transient String text; - + @Deprecated private transient boolean snapshot; - + public boolean isRelease() { for (ArtifactVersion artifactVersion : deployments) { if (!artifactVersion.isSnapshot()) return true; @@ -71,6 +93,10 @@ public String getUrlName() { return ""; } + /** + * @deprecated use {@link #getDeployments()} instead. + */ + @Deprecated @Exported public String getText() { if (text == null) { @@ -91,9 +117,14 @@ public void addDeployment(String url) { } /** - * @return list of all linked deployments + * @return list of all linked deployments. */ - /*package*/ List getDeployments() { + public List getDeployments() { return deployments; } + + @Override + public Collection getProjectActions() { + return this.projectActions; + } } diff --git a/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerRecorder.java b/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerRecorder.java index 1347566..f879b82 100644 --- a/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerRecorder.java +++ b/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerRecorder.java @@ -1,21 +1,19 @@ package hudson.plugins.mavendeploymentlinker; import hudson.Extension; +import hudson.FilePath; import hudson.Launcher; -import hudson.model.Action; -import hudson.model.BuildListener; -import hudson.model.AbstractBuild; import hudson.model.AbstractProject; -import hudson.model.Project; +import hudson.model.Run; +import hudson.model.TaskListener; import hudson.tasks.BuildStepDescriptor; import hudson.tasks.BuildStepMonitor; import hudson.tasks.Publisher; import hudson.tasks.Recorder; +import jenkins.tasks.SimpleBuildStep; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; +import javax.annotation.Nonnull; +import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; @@ -24,15 +22,18 @@ import org.apache.commons.lang.StringUtils; import org.kohsuke.stapler.DataBoundConstructor; -public class MavenDeploymentLinkerRecorder extends Recorder { +public class MavenDeploymentLinkerRecorder extends Recorder implements SimpleBuildStep { private static final String IGNORED_RESOURCES="^.*maven-metadata.xml$"; private String regexp; + + private PrintStream logger; @DataBoundConstructor - public MavenDeploymentLinkerRecorder(final String regexp) { + public MavenDeploymentLinkerRecorder(final String regexp, TaskListener listener) { this.regexp = StringUtils.trimToEmpty(regexp); + this.logger = listener.getLogger(); } public String getRegexp() { @@ -48,9 +49,10 @@ public BuildStepMonitor getRequiredMonitorService() { } @Override - public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { - File logFile = build.getLogFile(); - BufferedReader in = new BufferedReader(new FileReader(logFile)); + public void perform(@Nonnull Run build, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull + TaskListener listener) throws InterruptedException, IOException { + Reader logReader = build.getLogReader(); + BufferedReader in = new BufferedReader(logReader); Pattern pattern = Pattern.compile("^.*?Uploading: (.*?)$"); Pattern filterPattern = Pattern.compile(StringUtils.isNotBlank(regexp) ? regexp : ".*"); Pattern ignoredPattern = Pattern.compile(IGNORED_RESOURCES); @@ -68,21 +70,19 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListen } } if (matches.size() > 0) { - MavenDeploymentLinkerAction action = new MavenDeploymentLinkerAction(); + MavenDeploymentLinkerAction action = new MavenDeploymentLinkerAction(build); + logger.println(matches.size() + " Maven Deployment Links where found."); for (String url : matches) { action.addDeployment(url); } - build.getActions().add(action); + build.addAction(action); build.save(); + } else { + logger.println("No Maven Deployment Links where found."); } - return true; + return; } - @Override - public Action getProjectAction(AbstractProject project) { - return new MavenDeploymentProjectLinkerAction(project); - } - @Extension public static class DescriptorImpl extends BuildStepDescriptor { diff --git a/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStep.java b/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStep.java new file mode 100644 index 0000000..c60139e --- /dev/null +++ b/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStep.java @@ -0,0 +1,55 @@ +package hudson.plugins.mavendeploymentlinker; + +import hudson.Extension; +import hudson.Util; + +import javax.annotation.Nonnull; + +import java.io.Serializable; + +import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl; +import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl; +import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.DataBoundSetter; + +/** + * @author Matthias Balke + */ +public class MavenDeploymentLinkerStep extends AbstractStepImpl implements Serializable { + + private static final long serialVersionUID = 1L; + + private String regexp; + + @DataBoundConstructor + public MavenDeploymentLinkerStep() { + } + + public String getRegexp() { + return regexp; + } + + @DataBoundSetter + public void setRegexp(String regexp) { + this.regexp = Util.fixEmptyAndTrim(regexp); + } + + @Extension + public static class DescriptorImpl extends AbstractStepDescriptorImpl { + + public DescriptorImpl() { + super(MavenDeploymentLinkerStepExecution.class); + } + + @Override + public String getFunctionName() { + return "deploymentLinker"; + } + + @Nonnull + @Override + public String getDisplayName() { + return "Link Maven Deployments"; + } + } +} diff --git a/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStepExecution.java b/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStepExecution.java new file mode 100644 index 0000000..d78b664 --- /dev/null +++ b/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStepExecution.java @@ -0,0 +1,44 @@ +package hudson.plugins.mavendeploymentlinker; + +import hudson.FilePath; +import hudson.Launcher; +import hudson.model.Run; +import hudson.model.TaskListener; + +import javax.inject.Inject; + +import org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution; +import org.jenkinsci.plugins.workflow.steps.StepContextParameter; + +/** + * @author Matthias Balke + */ +public class MavenDeploymentLinkerStepExecution extends AbstractSynchronousNonBlockingStepExecution { + + private static final long serialVersionUID = 1L; + + @StepContextParameter + private transient TaskListener listener; + + @StepContextParameter + private transient FilePath ws; + + @StepContextParameter + private transient Run build; + + @StepContextParameter + private transient Launcher launcher; + + @Inject + MavenDeploymentLinkerStep mavenDeploymentLinkerStep; + + @Override + protected Void run() throws Exception { + listener.getLogger().println("Recording Maven Deployment Links ..."); + + MavenDeploymentLinkerRecorder recorder = new MavenDeploymentLinkerRecorder(mavenDeploymentLinkerStep.getRegexp(), listener); + recorder.perform(build, ws, launcher, listener); + + return null; + } +} diff --git a/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentProjectLinkerAction.java b/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentProjectLinkerAction.java index faba3cb..488a453 100644 --- a/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentProjectLinkerAction.java +++ b/src/main/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentProjectLinkerAction.java @@ -1,7 +1,7 @@ package hudson.plugins.mavendeploymentlinker; import hudson.model.Action; -import hudson.model.AbstractProject; +import hudson.model.Job; import hudson.model.Result; import hudson.model.Run; import hudson.util.RunList; @@ -9,9 +9,10 @@ import org.kohsuke.stapler.export.Exported; public class MavenDeploymentProjectLinkerAction implements Action { - private final AbstractProject project; - public MavenDeploymentProjectLinkerAction(AbstractProject project) { + private final Job project; + + public MavenDeploymentProjectLinkerAction(Job project) { this.project = project; } @@ -26,12 +27,12 @@ public String getDisplayName() { public String getUrlName() { return ""; } - + @Exported public boolean hasLatestDeployments() { return getLatestDeployments() != null; } - + @Exported public Action getLatestDeployments() { Run lastSuccessfulBuild = project.getLastSuccessfulBuild(); @@ -40,7 +41,7 @@ public Action getLatestDeployments() { } return lastSuccessfulBuild.getAction(MavenDeploymentLinkerAction.class); } - + @Exported public boolean hasLatestReleaseDeployments() { return getLatestReleaseDeployments() != null; diff --git a/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentDownloader/config.jelly b/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentDownloader/config.jelly index b93ddea..6d2decd 100644 --- a/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentDownloader/config.jelly +++ b/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentDownloader/config.jelly @@ -1,3 +1,4 @@ + diff --git a/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerAction/summary.jelly b/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerAction/summary.jelly index 14c99fc..24c23d2 100644 --- a/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerAction/summary.jelly +++ b/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerAction/summary.jelly @@ -1,6 +1,11 @@ + ${%deployments} - ${it.text} + - \ No newline at end of file + diff --git a/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerRecorder/config.jelly b/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerRecorder/config.jelly index 31a5017..9ba6129 100644 --- a/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerRecorder/config.jelly +++ b/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerRecorder/config.jelly @@ -1,3 +1,4 @@ + diff --git a/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStep/config.jelly b/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStep/config.jelly new file mode 100644 index 0000000..4cafc89 --- /dev/null +++ b/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStep/config.jelly @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStep/config.properties b/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStep/config.properties new file mode 100644 index 0000000..4db7768 --- /dev/null +++ b/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStep/config.properties @@ -0,0 +1 @@ +linkRegexp=Matching this regular expression \ No newline at end of file diff --git a/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStep/config_fr.properties b/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStep/config_fr.properties new file mode 100644 index 0000000..9e6c4a5 --- /dev/null +++ b/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStep/config_fr.properties @@ -0,0 +1 @@ +linkRegexp=qui vérifient cette expression régulière \ No newline at end of file diff --git a/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentProjectLinkerAction/jobMain.jelly b/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentProjectLinkerAction/jobMain.jelly index ff65942..9cf3cea 100644 --- a/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentProjectLinkerAction/jobMain.jelly +++ b/src/main/resources/hudson/plugins/mavendeploymentlinker/MavenDeploymentProjectLinkerAction/jobMain.jelly @@ -1,16 +1,25 @@ + ${%latestDeployments} - ${it.latestDeployments.text} + ${%latestReleaseDeployments} - ${it.latestReleaseDeployments.text} +
    -
    \ No newline at end of file +
    diff --git a/src/test/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStepTest.java b/src/test/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStepTest.java new file mode 100644 index 0000000..4838e7b --- /dev/null +++ b/src/test/java/hudson/plugins/mavendeploymentlinker/MavenDeploymentLinkerStepTest.java @@ -0,0 +1,132 @@ +package hudson.plugins.mavendeploymentlinker; + +import java.util.Arrays; + +import org.apache.commons.lang.StringUtils; +import org.hamcrest.CoreMatchers; +import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; +import org.jenkinsci.plugins.workflow.job.WorkflowJob; +import org.jenkinsci.plugins.workflow.job.WorkflowRun; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsRule; + +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertThat; + +public class MavenDeploymentLinkerStepTest { + + @Rule + public JenkinsRule j = new JenkinsRule(); + + /** + * Test collecting maven deployment links. + */ + @Test + public void deploymentLinkerFoundNoDeployments() + throws Exception { + // job setup + WorkflowJob foo = j.jenkins.createProject(WorkflowJob.class, "foo"); + foo.setDefinition(new CpsFlowDefinition(StringUtils.join(Arrays.asList( + "node {", + " echo 'test'", + " deploymentLinker regexp: '.*'", + "}"), "\n"))); + + // get the build going, and wait until workflow pauses + WorkflowRun b = j.assertBuildStatusSuccess(foo.scheduleBuild2(0).get()); + + j.assertLogContains("Recording Maven Deployment Links ...", b); + j.assertLogContains("No Maven Deployment Links where found.", b); + } + + /** + * Test collecting maven deployment links. + */ + @Test + public void deploymentLinkerFoundOneDeployment() + throws Exception { + // job setup + String artifactName = "maven-deployment-linker-1.6-20171026.194553-11.pom"; + String url = "http://localhost:8081/nexus/content/repositories/snapshots/org/" + + "jvnet/hudson/plugins/maven-deployment-linker/1.6-SNAPSHOT/" + artifactName; + + WorkflowJob foo = j.jenkins.createProject(WorkflowJob.class, "foo"); + foo.setDefinition(new CpsFlowDefinition(StringUtils.join(Arrays.asList( + "node {", + " echo 'test'", + " echo '''" + getSampleDeploymentLog() + "'''", + " deploymentLinker regexp: '.*'", + "}"), "\n"))); + + // get the build going, and wait until workflow pauses + WorkflowRun b = j.assertBuildStatusSuccess(foo.scheduleBuild2(0).get()); + j.assertLogContains("Recording Maven Deployment Links ...", b); + + + MavenDeploymentLinkerAction deploymentLinkerAction = b.getAction(MavenDeploymentLinkerAction.class); + String log = j.getLog(b); + System.out.println(log); + + + assertThat(deploymentLinkerAction, notNullValue()); + j.assertLogContains("2 Maven Deployment Links where found.", b); + } + + + private String getSampleDeploymentLog() { + return "Uploading: http://localhost:8081/nexus/content/repositories/snapshots/org/jvnet/hudson/plugins/maven-deployment-linker/1.6-SNAPSHOT/maven-deployment-linker-1.6-20171026.194553-11.hpi\n" + + "2/32 KB\n" + + "4/32 KB\n" + + "6/32 KB\n" + + "8/32 KB\n" + + "10/32 KB\n" + + "12/32 KB\n" + + "14/32 KB\n" + + "16/32 KB\n" + + "18/32 KB\n" + + "20/32 KB\n" + + "22/32 KB\n" + + "24/32 KB\n" + + "26/32 KB\n" + + "28/32 KB\n" + + "30/32 KB\n" + + "32/32 KB\n" + + "\n" + + "Uploaded: http://localhost:8081/nexus/content/repositories/snapshots/org/jvnet/hudson/plugins/maven-deployment-linker/1.6-SNAPSHOT/maven-deployment-linker-1.6-20171026.194553-11.hpi (32 KB at 702.6 KB/sec)\n" + + "Uploading: http://localhost:8081/nexus/content/repositories/snapshots/org/jvnet/hudson/plugins/maven-deployment-linker/1.6-SNAPSHOT/maven-deployment-linker-1.6-20171026.194553-11.pom\n" + + "2/6 KB\n" + + "4/6 KB\n" + + "6/6 KB\n" + + "\n" + + "Uploaded: http://localhost:8081/nexus/content/repositories/snapshots/org/jvnet/hudson/plugins/maven-deployment-linker/1.6-SNAPSHOT/maven-deployment-linker-1.6-20171026.194553-11.pom (6 KB at 148.0 KB/sec)\n" + + "Downloading: http://localhost:8081/nexus/content/repositories/snapshots/org/jvnet/hudson/plugins/maven-deployment-linker/maven-metadata.xml\n" + + "305/305 B\n" + + "\n" + + "Downloaded: http://localhost:8081/nexus/content/repositories/snapshots/org/jvnet/hudson/plugins/maven-deployment-linker/maven-metadata.xml (305 B at 10.6 KB/sec)\n" + + "Uploading: http://localhost:8081/nexus/content/repositories/snapshots/org/jvnet/hudson/plugins/maven-deployment-linker/1.6-SNAPSHOT/maven-metadata.xml\n" + + "966/966 B\n" + + "\n" + + "Uploaded: http://localhost:8081/nexus/content/repositories/snapshots/org/jvnet/hudson/plugins/maven-deployment-linker/1.6-SNAPSHOT/maven-metadata.xml (966 B at 32.5 KB/sec)\n" + + "Uploading: http://localhost:8081/nexus/content/repositories/snapshots/org/jvnet/hudson/plugins/maven-deployment-linker/maven-metadata.xml\n" + + "305/305 B\n" + + "\n" + + "Uploaded: http://localhost:8081/nexus/content/repositories/snapshots/org/jvnet/hudson/plugins/maven-deployment-linker/maven-metadata.xml (305 B at 9.0 KB/sec)\n"; + } + + // List foundActions = new ArrayList<>(); + // for (Action action : b.getAllActions()) { + // if (action instanceof MavenDeploymentLinkerAction) { + // foundActions.add((MavenDeploymentLinkerAction)action); + // } + // } + // + // assertThat("Should have found one MavenDeploymentLinkerAction", foundActions, hasSize(1)); + // + // List deployments = foundActions.get(0).getDeployments(); + // + // assertThat("Should have recorded one Deployment", deployments, hasSize(1)); + // assertThat("Should match the artifact name", deployments.get(0).getArtifactName(), equalTo(artifactName)); + // assertThat("Should match the artifact url", deployments.get(0).getUrl(), equalTo(url)); +}