From c6fabb12487aa2d1a98d58717bc47c6e7b545899 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 19:32:20 -0600 Subject: [PATCH 01/37] Enable deprecation warnings from java compiler --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index 380d423bda..e14872baf7 100644 --- a/pom.xml +++ b/pom.xml @@ -43,6 +43,12 @@ + + maven-compiler-plugin + + -Xlint:deprecation + + org.apache.maven.plugins maven-checkstyle-plugin From 8072caa0929791247bcafbc0495b7fd3fe9171d9 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 20:35:21 -0600 Subject: [PATCH 02/37] Use try/finally in GitChangeLogParser --- src/main/java/hudson/plugins/git/GitChangeLogParser.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/hudson/plugins/git/GitChangeLogParser.java b/src/main/java/hudson/plugins/git/GitChangeLogParser.java index 1e7e720d79..43f5f6c2e7 100644 --- a/src/main/java/hudson/plugins/git/GitChangeLogParser.java +++ b/src/main/java/hudson/plugins/git/GitChangeLogParser.java @@ -79,12 +79,8 @@ public List parse(@NonNull List changelog) { @Override public GitChangeSetList parse(Run build, RepositoryBrowser browser, File changelogFile) throws IOException, SAXException { // Parse the log file into GitChangeSet items - each one is a commit - LineIterator lineIterator = null; - try { - lineIterator = FileUtils.lineIterator(changelogFile,"UTF-8"); - return new GitChangeSetList(build, browser, parse(lineIterator)); - } finally { - LineIterator.closeQuietly(lineIterator); + try (LineIterator lineIterator = FileUtils.lineIterator(changelogFile, "UTF-8")) { + return new GitChangeSetList(build, browser, parse(lineIterator)); } } From c4d9d70d16780ae78a620b29003b271b01382bf7 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 20:36:12 -0600 Subject: [PATCH 03/37] Use PerBuildTag instead of deprecated getSkipTag() --- src/main/java/hudson/plugins/git/GitPublisher.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/hudson/plugins/git/GitPublisher.java b/src/main/java/hudson/plugins/git/GitPublisher.java index a13d8dc742..f5e35c7203 100644 --- a/src/main/java/hudson/plugins/git/GitPublisher.java +++ b/src/main/java/hudson/plugins/git/GitPublisher.java @@ -13,6 +13,7 @@ import hudson.model.Descriptor; import hudson.model.Descriptor.FormException; import hudson.model.Result; +import hudson.plugins.git.extensions.impl.PerBuildTag; import hudson.plugins.git.opt.PreBuildMergeOptions; import hudson.scm.SCM; import hudson.tasks.BuildStepDescriptor; @@ -184,7 +185,8 @@ public boolean perform(AbstractBuild build, // If we're pushing the merge back... if (pushMerge) { try { - if (!gitSCM.getSkipTag()) { + if (gitSCM.getExtensions().get(PerBuildTag.class) != null) { + // if PerBuildTag, then tag every build // We delete the old tag generated by the SCM plugin String buildnumber = "jenkins-" + projectName.replace(" ", "_") + "-" + buildNumber; if (git.tagExists(buildnumber)) From 0d3590a196272affc43d1a52ca388489142e5c79 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 20:38:49 -0600 Subject: [PATCH 04/37] Use non-deprecated GitLab constructor --- src/main/java/hudson/plugins/git/GitSCM.java | 2 +- .../plugins/git/browser/casc/GitLabConfigurator.java | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/hudson/plugins/git/GitSCM.java b/src/main/java/hudson/plugins/git/GitSCM.java index d2046b96ba..d94fdfa70b 100644 --- a/src/main/java/hudson/plugins/git/GitSCM.java +++ b/src/main/java/hudson/plugins/git/GitSCM.java @@ -415,7 +415,7 @@ public void setBrowser(GitRepositoryBrowser browser) { return new BitbucketWeb(url); } if (url.startsWith("https://gitlab.com/")) { - return new GitLab(url, ""); + return new GitLab(url); } if (url.startsWith("https://github.com/")) { return new GithubWeb(url); diff --git a/src/main/java/hudson/plugins/git/browser/casc/GitLabConfigurator.java b/src/main/java/hudson/plugins/git/browser/casc/GitLabConfigurator.java index 5db0dfab57..caa113847e 100644 --- a/src/main/java/hudson/plugins/git/browser/casc/GitLabConfigurator.java +++ b/src/main/java/hudson/plugins/git/browser/casc/GitLabConfigurator.java @@ -21,11 +21,17 @@ public class GitLabConfigurator extends BaseConfigurator { @Override protected GitLab instance(Mapping mapping, ConfigurationContext context) throws ConfiguratorException { if (mapping == null) { - return new GitLab("", ""); + return new GitLab(""); } final String url = (mapping.get("repoUrl") != null ? mapping.getScalarValue("repoUrl") : ""); final String version = (mapping.get("version") != null ? mapping.getScalarValue("version") : ""); - return new GitLab(url, version); + if (version.isEmpty()) { + return new GitLab(url); + } + // Only use the deprecated constructor for a non-empty version + @SuppressWarnings("deprecation") + GitLab gitlab = new GitLab(url, version); + return gitlab; } @CheckForNull From 579b59d53a4b1f6b2965135d2f4a838872c7a735 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 20:41:19 -0600 Subject: [PATCH 05/37] Use non-deprecated methods in GitSCM --- src/main/java/hudson/plugins/git/GitSCM.java | 25 +++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/hudson/plugins/git/GitSCM.java b/src/main/java/hudson/plugins/git/GitSCM.java index d94fdfa70b..f239e21c93 100644 --- a/src/main/java/hudson/plugins/git/GitSCM.java +++ b/src/main/java/hudson/plugins/git/GitSCM.java @@ -110,6 +110,7 @@ import hudson.plugins.git.browser.GithubWeb; import static hudson.scm.PollingResult.*; import hudson.Util; +import hudson.plugins.git.extensions.impl.ScmName; import hudson.util.LogTaskListener; import hudson.util.ReflectionUtils; import java.util.Map.Entry; @@ -469,9 +470,9 @@ public String getParamLocalBranch(Run build) throws IOException, Interrupt * @return parameter-expanded local branch name in build. */ public String getParamLocalBranch(Run build, TaskListener listener) throws IOException, InterruptedException { - String branch = getLocalBranch(); + LocalBranch localBranch = getExtensions().get(LocalBranch.class); // substitute build parameters if available - return getParameterString(branch != null ? branch : null, build.getEnvironment(listener)); + return getParameterString(localBranch == null ? null : localBranch.getLocalBranch(), build.getEnvironment(listener)); } @Deprecated @@ -849,7 +850,7 @@ public GitClient createClient(TaskListener listener, EnvVars environment, Run build, Map env) { buildEnvironment(build, env); } @@ -1741,9 +1746,9 @@ public List getBranches() { } @Override public String getKey() { - String name = getScmName(); - if (name != null) { - return name; + ScmName scmName = getExtensions().get(ScmName.class); + if (scmName != null) { + return scmName.getName(); } StringBuilder b = new StringBuilder("git"); for (RemoteConfig cfg : getRepositories()) { @@ -1792,11 +1797,13 @@ public BuildData getBuildData(Run build, boolean clone) { */ public BuildData copyBuildData(Run build) { BuildData base = getBuildData(build); + ScmName sn = getExtensions().get(ScmName.class); + String scmName = sn == null ? null : sn.getName(); if (base==null) - return new BuildData(getScmName(), getUserRemoteConfigs()); + return new BuildData(scmName, getUserRemoteConfigs()); else { BuildData buildData = base.clone(); - buildData.setScmName(getScmName()); + buildData.setScmName(scmName); return buildData; } } From c5316def2a76c2a527b3b164ae470e9310559beb Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 20:43:31 -0600 Subject: [PATCH 06/37] Use non-deprecated checkout in SubmoduleCombinator --- src/main/java/hudson/plugins/git/SubmoduleCombinator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/hudson/plugins/git/SubmoduleCombinator.java b/src/main/java/hudson/plugins/git/SubmoduleCombinator.java index 83f22237ec..8a0ad8bc1f 100644 --- a/src/main/java/hudson/plugins/git/SubmoduleCombinator.java +++ b/src/main/java/hudson/plugins/git/SubmoduleCombinator.java @@ -137,7 +137,7 @@ protected void makeCombination(Map settings) throws Interr // Assume we are checked out String name = "combine-" + tid + "-" + (idx++); git.branch(name); - git.checkout(name); + git.checkout().ref(name).execute(); StringBuilder commit = new StringBuilder( "Jenkins generated combination of:\n"); @@ -156,7 +156,7 @@ protected void makeCombination(Map settings) throws Interr IndexEntry submodule = setting.getKey(); Revision branch = setting.getValue(); GitClient subGit = git.subGit(submodule.getFile()); - subGit.checkout(branch.getSha1().name()); + subGit.checkout().ref(branch.getSha1().name()).execute(); git.add(submodule.getFile()); } From d89270a4efe9cf88bb2342f831774884a66ca2c0 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 20:46:02 -0600 Subject: [PATCH 07/37] Use buildEnvironment instead of deprecated buildEnvVars --- src/main/java/hudson/plugins/git/util/GitUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/hudson/plugins/git/util/GitUtils.java b/src/main/java/hudson/plugins/git/util/GitUtils.java index 58be3ae6a8..38afa046a1 100644 --- a/src/main/java/hudson/plugins/git/util/GitUtils.java +++ b/src/main/java/hudson/plugins/git/util/GitUtils.java @@ -320,7 +320,7 @@ public static EnvVars getPollEnvironment(AbstractProject p, FilePath ws, Launche env = p.getEnvironment(workspaceToNode(ws), listener); } - p.getScm().buildEnvVars(b,env); + p.getScm().buildEnvironment(b,env); } else { env = p.getEnvironment(workspaceToNode(ws), listener); } @@ -367,7 +367,7 @@ private static void addEnvironmentContributingActionsValues(EnvVars env, Abstrac // most importantly, ParametersAction will be processed here (for parameterized builds) if (action instanceof ParametersAction) { ParametersAction envAction = (ParametersAction) action; - envAction.buildEnvVars(b, env); + envAction.buildEnvironment(b, env); } } From 48e65a722338cf41808906ca2196a4aeaa8bd696 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 20:37:17 -0600 Subject: [PATCH 08/37] Suppress deprecation warnings --- src/main/java/hudson/plugins/git/GitPublisher.java | 1 + src/main/java/hudson/plugins/git/GitSCM.java | 3 ++- src/main/java/hudson/plugins/git/GitStatus.java | 6 ++++++ .../java/hudson/plugins/git/RemoteConfigConverter.java | 5 ++++- src/main/java/hudson/plugins/git/UserRemoteConfig.java | 7 +++++-- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/hudson/plugins/git/GitPublisher.java b/src/main/java/hudson/plugins/git/GitPublisher.java index f5e35c7203..9c4376de3e 100644 --- a/src/main/java/hudson/plugins/git/GitPublisher.java +++ b/src/main/java/hudson/plugins/git/GitPublisher.java @@ -198,6 +198,7 @@ public boolean perform(AbstractBuild build, git.tag(buildnumber, "Jenkins Build #" + buildNumber); } + @SuppressWarnings("deprecation") // Too much work to replace with non-deprecated PreBuildMergeOptions mergeOptions = gitSCM.getMergeOptions(); String mergeTarget = environment.expand(mergeOptions.getMergeTarget()); diff --git a/src/main/java/hudson/plugins/git/GitSCM.java b/src/main/java/hudson/plugins/git/GitSCM.java index f239e21c93..d10ee3c34c 100644 --- a/src/main/java/hudson/plugins/git/GitSCM.java +++ b/src/main/java/hudson/plugins/git/GitSCM.java @@ -269,6 +269,7 @@ private void updateFromUserData() throws GitException { } } + @SuppressWarnings("deprecation") // `source` field is deprecated but required public Object readResolve() throws IOException { // Migrate data @@ -277,7 +278,7 @@ public Object readResolve() throws IOException { configVersion = 0L; } - + // Deprecated field needed to retain compatibility if (source != null) { remoteRepositories = new ArrayList<>(); branches = new ArrayList<>(); diff --git a/src/main/java/hudson/plugins/git/GitStatus.java b/src/main/java/hudson/plugins/git/GitStatus.java index 126530b558..66f33a9015 100644 --- a/src/main/java/hudson/plugins/git/GitStatus.java +++ b/src/main/java/hudson/plugins/git/GitStatus.java @@ -508,7 +508,10 @@ public PollingScheduledResponseContributor(Item project) { * {@inheritDoc} */ @Override + @SuppressWarnings("deprecation") public void addHeaders(StaplerRequest req, StaplerResponse rsp) { + // Calls a deprecated getAbsoluteUrl() method because this is a remote API case + // as described in the Javadoc of the deprecated getAbsoluteUrl() method. rsp.addHeader("Triggered", project.getAbsoluteUrl()); } @@ -540,7 +543,10 @@ public ScheduledResponseContributor(Item project) { * {@inheritDoc} */ @Override + @SuppressWarnings("deprecation") public void addHeaders(StaplerRequest req, StaplerResponse rsp) { + // Calls a deprecated getAbsoluteUrl() method because this is a remote API case + // as described in the Javadoc of the deprecated getAbsoluteUrl() method. rsp.addHeader("Triggered", project.getAbsoluteUrl()); } diff --git a/src/main/java/hudson/plugins/git/RemoteConfigConverter.java b/src/main/java/hudson/plugins/git/RemoteConfigConverter.java index e1446f9af1..3cb3511961 100644 --- a/src/main/java/hudson/plugins/git/RemoteConfigConverter.java +++ b/src/main/java/hudson/plugins/git/RemoteConfigConverter.java @@ -160,8 +160,10 @@ public RemoteConfig toRemote() throws URISyntaxException { */ public RemoteConfigConverter(XStream xStream) { mapper = xStream.getMapper(); - converter = new SerializableConverter(mapper, + @SuppressWarnings("deprecation") + SerializableConverter tempConvertor = new SerializableConverter(mapper, xStream.getReflectionProvider()); + converter = tempConvertor; } public boolean canConvert(@SuppressWarnings("rawtypes") Class type) { @@ -224,6 +226,7 @@ public void close() { } }; try { + @SuppressWarnings("deprecation") CustomObjectInputStream objectInput = CustomObjectInputStream .getInstance(context, callback); proxy.readExternal(objectInput); diff --git a/src/main/java/hudson/plugins/git/UserRemoteConfig.java b/src/main/java/hudson/plugins/git/UserRemoteConfig.java index ab9abf07fc..3b1ec04a1f 100644 --- a/src/main/java/hudson/plugins/git/UserRemoteConfig.java +++ b/src/main/java/hudson/plugins/git/UserRemoteConfig.java @@ -104,8 +104,11 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item project, return new StandardListBoxModel().includeCurrentValue(credentialsId); } if (project == null) { - /* Construct a fake project */ - project = new FreeStyleProject(Jenkins.get(), "fake-" + UUID.randomUUID().toString()); + /* Construct a fake project, suppress the deprecation warning because the + * replacement for the deprecated API isn't accessible in this context. */ + @SuppressWarnings("deprecation") + Item fakeProject = new FreeStyleProject(Jenkins.get(), "fake-" + UUID.randomUUID().toString()); + project = fakeProject; } return new StandardListBoxModel() .includeEmptyValue() From ecac6ebd60bb4a9ba438b91beee34802f9dedeeb Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 20:44:55 -0600 Subject: [PATCH 09/37] Deprecate because overrides deprecated method --- .../plugins/git/extensions/impl/CleanBeforeCheckout.java | 1 + .../java/hudson/plugins/git/extensions/impl/CloneOption.java | 1 + .../hudson/plugins/git/extensions/impl/PruneStaleBranch.java | 1 + src/main/java/jenkins/plugins/git/GitSCMSourceDefaults.java | 1 + .../java/jenkins/plugins/git/MergeWithGitSCMExtension.java | 1 + src/test/java/jenkins/plugins/git/GitSCMTelescopeTest.java | 3 +++ 6 files changed, 8 insertions(+) diff --git a/src/main/java/hudson/plugins/git/extensions/impl/CleanBeforeCheckout.java b/src/main/java/hudson/plugins/git/extensions/impl/CleanBeforeCheckout.java index 4a3ad43b0b..03f1c3b86d 100644 --- a/src/main/java/hudson/plugins/git/extensions/impl/CleanBeforeCheckout.java +++ b/src/main/java/hudson/plugins/git/extensions/impl/CleanBeforeCheckout.java @@ -39,6 +39,7 @@ public void setDeleteUntrackedNestedRepositories(boolean deleteUntrackedNestedRe * {@inheritDoc} */ @Override + @Deprecated public void decorateFetchCommand(GitSCM scm, GitClient git, TaskListener listener, FetchCommand cmd) throws IOException, InterruptedException, GitException { listener.getLogger().println("Cleaning workspace"); git.clean(deleteUntrackedNestedRepositories); diff --git a/src/main/java/hudson/plugins/git/extensions/impl/CloneOption.java b/src/main/java/hudson/plugins/git/extensions/impl/CloneOption.java index be46f4339b..7b0b513ddf 100644 --- a/src/main/java/hudson/plugins/git/extensions/impl/CloneOption.java +++ b/src/main/java/hudson/plugins/git/extensions/impl/CloneOption.java @@ -168,6 +168,7 @@ public void decorateCloneCommand(GitSCM scm, Run build, GitClient git, Tas * {@inheritDoc} */ @Override + @Deprecated // Deprecate because the super implementation is deprecated public void decorateFetchCommand(GitSCM scm, GitClient git, TaskListener listener, FetchCommand cmd) throws IOException, InterruptedException, GitException { cmd.shallow(shallow); if (shallow) { diff --git a/src/main/java/hudson/plugins/git/extensions/impl/PruneStaleBranch.java b/src/main/java/hudson/plugins/git/extensions/impl/PruneStaleBranch.java index 63e9242a63..339f6e8244 100644 --- a/src/main/java/hudson/plugins/git/extensions/impl/PruneStaleBranch.java +++ b/src/main/java/hudson/plugins/git/extensions/impl/PruneStaleBranch.java @@ -26,6 +26,7 @@ public PruneStaleBranch() { * {@inheritDoc} */ @Override + @Deprecated public void decorateFetchCommand(GitSCM scm, GitClient git, TaskListener listener, FetchCommand cmd) throws IOException, InterruptedException, GitException { listener.getLogger().println("Pruning obsolete local branches"); cmd.prune(true); diff --git a/src/main/java/jenkins/plugins/git/GitSCMSourceDefaults.java b/src/main/java/jenkins/plugins/git/GitSCMSourceDefaults.java index fb38946e73..3d03df8ffb 100644 --- a/src/main/java/jenkins/plugins/git/GitSCMSourceDefaults.java +++ b/src/main/java/jenkins/plugins/git/GitSCMSourceDefaults.java @@ -119,6 +119,7 @@ public void decorateCloneCommand(GitSCM scm, Run build, GitClient git, Tas * {@inheritDoc} */ @Override + @Deprecated public void decorateFetchCommand(GitSCM scm, GitClient git, TaskListener listener, FetchCommand cmd) throws IOException, InterruptedException, GitException { listener.getLogger() diff --git a/src/main/java/jenkins/plugins/git/MergeWithGitSCMExtension.java b/src/main/java/jenkins/plugins/git/MergeWithGitSCMExtension.java index 80f52a5ebd..3879d342c5 100644 --- a/src/main/java/jenkins/plugins/git/MergeWithGitSCMExtension.java +++ b/src/main/java/jenkins/plugins/git/MergeWithGitSCMExtension.java @@ -82,6 +82,7 @@ public void decorateCloneCommand(GitSCM scm, Run build, GitClient git, Tas } @Override + @Deprecated public void decorateFetchCommand(GitSCM scm, GitClient git, TaskListener listener, FetchCommand cmd) throws IOException, InterruptedException, GitException { // we are doing a merge, so cannot permit a shallow clone diff --git a/src/test/java/jenkins/plugins/git/GitSCMTelescopeTest.java b/src/test/java/jenkins/plugins/git/GitSCMTelescopeTest.java index 160a739fae..d5d81408f1 100644 --- a/src/test/java/jenkins/plugins/git/GitSCMTelescopeTest.java +++ b/src/test/java/jenkins/plugins/git/GitSCMTelescopeTest.java @@ -382,6 +382,7 @@ public String getShortUrl() { } @Override + @Deprecated public String getAbsoluteUrl() { throw new UnsupportedOperationException("Not called."); } @@ -601,6 +602,7 @@ public SCMSource getSCMSource(String string) { } @Override + @Deprecated public void onSCMSourceUpdated(SCMSource scms) { throw new UnsupportedOperationException("Not called."); } @@ -661,6 +663,7 @@ public String getShortUrl() { } @Override + @Deprecated public String getAbsoluteUrl() { throw new UnsupportedOperationException("Not called."); } From 70ed0c654debd5be23ae076692c2d01170522be4 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 20:45:31 -0600 Subject: [PATCH 10/37] Suppress IGitAPI deprecation warnings --- .../hudson/plugins/git/util/BuildChooser.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/hudson/plugins/git/util/BuildChooser.java b/src/main/java/hudson/plugins/git/util/BuildChooser.java index efdd21cd54..1dda8e73ff 100644 --- a/src/main/java/hudson/plugins/git/util/BuildChooser.java +++ b/src/main/java/hudson/plugins/git/util/BuildChooser.java @@ -12,7 +12,6 @@ import hudson.model.TaskListener; import hudson.plugins.git.GitException; import hudson.plugins.git.GitSCM; -import hudson.plugins.git.IGitAPI; import hudson.plugins.git.Revision; import org.jenkinsci.plugins.gitclient.GitClient; @@ -85,7 +84,9 @@ public Collection getCandidateRevisions(boolean isPollCall, @CheckForN @NonNull BuildData buildData, @NonNull BuildChooserContext context) throws GitException, IOException, InterruptedException { // fallback to the previous signature - return getCandidateRevisions(isPollCall, singleBranch, (IGitAPI) git, listener, buildData, context); + @SuppressWarnings("deprecation") + hudson.plugins.git.IGitAPI iGit = (hudson.plugins.git.IGitAPI) git; + return getCandidateRevisions(isPollCall, singleBranch, iGit, listener, buildData, context); } /** @@ -116,8 +117,9 @@ public Collection getCandidateRevisions(boolean isPollCall, @CheckForN * @throws GitException on git error * @throws InterruptedException when interrupted */ + @Deprecated public Collection getCandidateRevisions(boolean isPollCall, String singleBranch, - IGitAPI git, TaskListener listener, BuildData buildData, BuildChooserContext context) throws GitException, IOException, InterruptedException { + hudson.plugins.git.IGitAPI git, TaskListener listener, BuildData buildData, BuildChooserContext context) throws GitException, IOException, InterruptedException { // fallback to the previous signature return getCandidateRevisions(isPollCall,singleBranch,git,listener,buildData); } @@ -125,7 +127,7 @@ public Collection getCandidateRevisions(boolean isPollCall, String sin /** * @deprecated as of 1.1.17 - * Use and override {@link #getCandidateRevisions(boolean, String, IGitAPI, TaskListener, BuildData, BuildChooserContext)} + * Use and override {@link #getCandidateRevisions(boolean, String, hudson.plugins.git.IGitAPI, TaskListener, BuildData, BuildChooserContext)} * @param isPollCall true if this method is called from pollChanges. * @param singleBranch contains the name of a single branch to be built * this will be non-null only in the simple case, in advanced @@ -140,14 +142,15 @@ public Collection getCandidateRevisions(boolean isPollCall, String sin * @throws IOException on input or output error * @throws GitException on git error */ + @Deprecated public Collection getCandidateRevisions(boolean isPollCall, String singleBranch, - IGitAPI git, TaskListener listener, BuildData buildData) throws GitException, IOException { + hudson.plugins.git.IGitAPI git, TaskListener listener, BuildData buildData) throws GitException, IOException { throw new UnsupportedOperationException("getCandidateRevisions method must be overridden"); } /** * @deprecated as of 1.1.25 - * Use and override {@link #prevBuildForChangelog(String, BuildData, IGitAPI, BuildChooserContext)} + * Use and override {@link #prevBuildForChangelog(String, BuildData, hudson.plugins.git.IGitAPI, BuildChooserContext)} * @param branch contains the name of branch to be built * this will be non-null only in the simple case, in advanced * cases with multiple repositories and/or branches specified @@ -158,7 +161,8 @@ public Collection getCandidateRevisions(boolean isPollCall, String sin * Used for invoking Git * @return * the candidate revision. Can be an empty set to indicate that there's nothi */ - public Build prevBuildForChangelog(String branch, @Nullable BuildData buildData, IGitAPI git) { + @Deprecated + public Build prevBuildForChangelog(String branch, @Nullable BuildData buildData, hudson.plugins.git.IGitAPI git) { return buildData == null ? null : buildData.getLastBuildOfBranch(branch); } @@ -166,7 +170,7 @@ public Build prevBuildForChangelog(String branch, @Nullable BuildData buildData, * Determines the baseline to compute the changelog against. * *

- * {@link #getCandidateRevisions(boolean, String, IGitAPI, TaskListener, BuildData, BuildChooserContext)} determine + * {@link #getCandidateRevisions(boolean, String, hudson.plugins.git.IGitAPI, TaskListener, BuildData, BuildChooserContext)} determine * what commits can be subject for a build, and for each commit it determines the branches that contribute to them. * *

@@ -188,7 +192,9 @@ public Build prevBuildForChangelog(String branch, @Nullable BuildData buildData, * @return candidate revision. Can be an empty set to indicate that there's nothing to build. */ public Build prevBuildForChangelog(String branch, @Nullable BuildData data, GitClient git, BuildChooserContext context) throws IOException,InterruptedException { - return prevBuildForChangelog(branch,data, (IGitAPI) git, context); + @SuppressWarnings("deprecation") + hudson.plugins.git.IGitAPI iGit = (hudson.plugins.git.IGitAPI) git; + return prevBuildForChangelog(branch, data, iGit, context); } /** @@ -216,7 +222,8 @@ public Build prevBuildForChangelog(String branch, @Nullable BuildData data, GitC * @throws GitException on git error * @throws InterruptedException if interrupted */ - public Build prevBuildForChangelog(String branch, @Nullable BuildData data, IGitAPI git, BuildChooserContext context) throws IOException,InterruptedException { + @Deprecated + public Build prevBuildForChangelog(String branch, @Nullable BuildData data, hudson.plugins.git.IGitAPI git, BuildChooserContext context) throws IOException,InterruptedException { return prevBuildForChangelog(branch,data,git); } From c440e74458490dd2224742bdf441544b628527f2 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 20:48:50 -0600 Subject: [PATCH 11/37] Suppress getRepository reference in AbstractGitSCMSource --- src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java b/src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java index bfa83cfb54..cddf5a23d7 100644 --- a/src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java +++ b/src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java @@ -578,7 +578,8 @@ public Void run(GitClient client, String remoteName, FetchCommand fetch) throws remoteReferences = Collections.emptyMap(); } fetch.execute(); - try (Repository repository = client.getRepository(); + try (@SuppressWarnings("deprecation") // Local repository reference + Repository repository = client.getRepository(); RevWalk walk = new RevWalk(repository); GitSCMSourceRequest request = context.newRequest(AbstractGitSCMSource.this, listener)) { @@ -956,7 +957,8 @@ protected SCMRevision retrieve(@NonNull final String revision, @NonNull final Ta @Override public SCMRevision run(GitClient client, String remoteName) throws IOException, InterruptedException { - try (final Repository repository = client.getRepository(); + try (@SuppressWarnings("deprecation") // Local repo reference + final Repository repository = client.getRepository(); RevWalk walk = new RevWalk(repository)) { ObjectId ref = client.revParse(tagRef); RevCommit commit = walk.parseCommit(ref); From d3fac2d3e6148f54fef42a178cbd11a7105c1796 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 20:50:56 -0600 Subject: [PATCH 12/37] Suppress warnings on index triggering --- src/main/java/jenkins/plugins/git/GitSCMSource.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/jenkins/plugins/git/GitSCMSource.java b/src/main/java/jenkins/plugins/git/GitSCMSource.java index 86a25c6bb4..9d37b9c65f 100644 --- a/src/main/java/jenkins/plugins/git/GitSCMSource.java +++ b/src/main/java/jenkins/plugins/git/GitSCMSource.java @@ -659,10 +659,13 @@ public boolean isMatch(@NonNull SCM scm) { if (GitStatus.looselyMatches(uri, remote)) { LOGGER.info("Triggering the indexing of " + owner.getFullDisplayName() + " as a result of event from " + origin); - owner.onSCMSourceUpdated(source); + triggerIndexing(owner, source); result.add(new GitStatus.ResponseContributor() { @Override + @SuppressWarnings("deprecation") public void addHeaders(StaplerRequest req, StaplerResponse rsp) { + // Calls a deprecated getAbsoluteUrl() method because this is a remote API case + // as described in the Javadoc of the deprecated getAbsoluteUrl() method. rsp.addHeader("Triggered", owner.getAbsoluteUrl()); } @@ -683,5 +686,10 @@ public void writeBody(PrintWriter w) { } return result; } + + @SuppressWarnings("deprecation") + private void triggerIndexing(SCMSourceOwner owner, SCMSource source) { + owner.onSCMSourceUpdated(source); + } } } From 82f345c0cd7f9991f19924aac0f1f1a1d5f640ba Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 21:10:56 -0600 Subject: [PATCH 13/37] Use emptyString in hamcrest assertion --- src/test/java/hudson/plugins/git/GitPublisherTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/hudson/plugins/git/GitPublisherTest.java b/src/test/java/hudson/plugins/git/GitPublisherTest.java index 2e49dda39e..525761fc63 100644 --- a/src/test/java/hudson/plugins/git/GitPublisherTest.java +++ b/src/test/java/hudson/plugins/git/GitPublisherTest.java @@ -672,7 +672,7 @@ public void testMergeAndPushWithSystemEnvVar() throws Exception { String envName = isWindows() ? "COMPUTERNAME" : "LOGNAME"; String envValue = System.getenv().get(envName); assumeThat(envValue, notNullValue()); - assumeThat(envValue, not(isEmptyString())); + assumeThat(envValue, is(not(emptyString()))); FreeStyleProject project = setupSimpleProject("master"); @@ -809,4 +809,4 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListen return true; } -} \ No newline at end of file +} From 0865e84645297ed528bcdd8bb101cdf4695c53c9 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 21:03:55 -0600 Subject: [PATCH 14/37] Deprecate tests of deprecated methods Silence deprecation warnings --- src/test/java/hudson/plugins/git/browser/GitLabTest.java | 1 + .../plugins/git/browser/casc/GitLabConfiguratorTest.java | 8 ++++++++ .../plugins/git/AbstractGitSCMSourceTrivialTest.java | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/test/java/hudson/plugins/git/browser/GitLabTest.java b/src/test/java/hudson/plugins/git/browser/GitLabTest.java index 5028bd8327..f5880e736d 100644 --- a/src/test/java/hudson/plugins/git/browser/GitLabTest.java +++ b/src/test/java/hudson/plugins/git/browser/GitLabTest.java @@ -17,6 +17,7 @@ import static org.junit.Assert.*; import org.junit.Test; +@Deprecated public class GitLabTest { private static final String GITLAB_URL = "https://SERVER/USER/REPO/"; diff --git a/src/test/java/hudson/plugins/git/browser/casc/GitLabConfiguratorTest.java b/src/test/java/hudson/plugins/git/browser/casc/GitLabConfiguratorTest.java index d29329d174..4392ac9ad8 100644 --- a/src/test/java/hudson/plugins/git/browser/casc/GitLabConfiguratorTest.java +++ b/src/test/java/hudson/plugins/git/browser/casc/GitLabConfiguratorTest.java @@ -45,6 +45,7 @@ public void testGetConfigurators() { } @Test + @Deprecated public void testDescribe() throws Exception { final Mapping expectedMapping = new Mapping(); expectedMapping.put("repoUrl", "http://fake"); @@ -57,6 +58,7 @@ public void testDescribe() throws Exception { } @Test + @Deprecated public void testInstance() throws Exception { final GitLab expectedConfiguration = new GitLab("http://fake", "2.0"); final Mapping mapping = new Mapping(); @@ -69,6 +71,7 @@ public void testInstance() throws Exception { } @Test + @Deprecated public void testInstanceWithEmptyRepo() throws Exception { final GitLab expectedConfiguration = new GitLab("", "2.0"); final Mapping mapping = new Mapping(); @@ -82,6 +85,7 @@ public void testInstanceWithEmptyRepo() throws Exception { } @Test + @Deprecated public void testInstanceWithNullRepo() throws Exception { final GitLab expectedConfiguration = new GitLab(null, "2.0"); final Mapping mapping = new Mapping(); @@ -94,6 +98,7 @@ public void testInstanceWithNullRepo() throws Exception { @Test + @Deprecated public void testInstanceWithEmptyVersion() throws Exception { final GitLab expectedConfiguration = new GitLab("http://fake", ""); final Mapping mapping = new Mapping(); @@ -106,6 +111,7 @@ public void testInstanceWithEmptyVersion() throws Exception { } @Test + @Deprecated public void testInstanceWithNullVersion() throws Exception { // If passing a null, GitLab throws an exception final GitLab expectedConfiguration = new GitLab("http://fake", ""); @@ -118,6 +124,7 @@ public void testInstanceWithNullVersion() throws Exception { } @Test + @Deprecated public void testInstanceWithNullMapping() throws Exception { // A null mapping should create an instance with empty arguments final GitLab expectedConfiguration = new GitLab("", ""); @@ -128,6 +135,7 @@ public void testInstanceWithNullMapping() throws Exception { } @Test + @Deprecated public void testInstanceWithNaNVersion() throws Exception { final Mapping mapping = new Mapping(); mapping.put("repoUrl", "http://fake"); diff --git a/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTrivialTest.java b/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTrivialTest.java index aa9793d1a4..c16597bdb9 100644 --- a/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTrivialTest.java +++ b/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTrivialTest.java @@ -41,6 +41,7 @@ public void setUp() throws Exception { } @Test + @Deprecated public void basicTestIsExcluded() { AbstractGitSCMSource abstractGitSCMSource = mock(AbstractGitSCMSource.class); @@ -98,6 +99,7 @@ public void testGetRefSpecs() { } @Test + @Deprecated public void testIsExcluded() { assertFalse(gitSCMSource.isExcluded("master")); assertFalse(gitSCMSource.isExcluded("remote/master")); From b8d7df95b623185aba014860e582536d26b17855 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 21:35:51 -0600 Subject: [PATCH 15/37] Suppress test deprecation warnings for getRepository --- src/test/java/hudson/plugins/git/AbstractGitProject.java | 3 ++- src/test/java/hudson/plugins/git/AbstractGitTestCase.java | 4 +++- .../hudson/plugins/git/util/AncestryBuildChooserTest.java | 3 ++- .../hudson/plugins/git/util/CommitTimeComparatorTest.java | 4 +++- src/test/java/jenkins/plugins/git/CliGitCommand.java | 3 ++- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/test/java/hudson/plugins/git/AbstractGitProject.java b/src/test/java/hudson/plugins/git/AbstractGitProject.java index f57c35b0b6..c35f44be22 100644 --- a/src/test/java/hudson/plugins/git/AbstractGitProject.java +++ b/src/test/java/hudson/plugins/git/AbstractGitProject.java @@ -240,7 +240,8 @@ protected MatrixBuild build(final MatrixProject project, final Result expectedRe protected String getHeadRevision(AbstractBuild build, final String branch) throws IOException, InterruptedException { return build.getWorkspace().act(new MasterToSlaveFileCallable() { public String invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { - try (Repository repo = Git.with(null, null).in(f).getClient().getRepository()) { + try (@SuppressWarnings("deprecation") // Local repository reference + Repository repo = Git.with(null, null).in(f).getClient().getRepository()) { return repo.resolve("refs/heads/" + branch).name(); } catch (GitException e) { throw new RuntimeException(e); diff --git a/src/test/java/hudson/plugins/git/AbstractGitTestCase.java b/src/test/java/hudson/plugins/git/AbstractGitTestCase.java index 50c5d96141..bd5038167a 100644 --- a/src/test/java/hudson/plugins/git/AbstractGitTestCase.java +++ b/src/test/java/hudson/plugins/git/AbstractGitTestCase.java @@ -299,7 +299,9 @@ protected String getHeadRevision(AbstractBuild build, final String branch) throw return build.getWorkspace().act(new MasterToSlaveFileCallable() { public String invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { try { - ObjectId oid = Git.with(null, null).in(f).getClient().getRepository().resolve("refs/heads/" + branch); + @SuppressWarnings("deprecation") // Local repository reference + org.eclipse.jgit.lib.Repository repo = Git.with(null, null).in(f).getClient().getRepository(); + ObjectId oid = repo.resolve("refs/heads/" + branch); return oid.name(); } catch (GitException e) { throw new RuntimeException(e); diff --git a/src/test/java/hudson/plugins/git/util/AncestryBuildChooserTest.java b/src/test/java/hudson/plugins/git/util/AncestryBuildChooserTest.java index d84c8f7ddc..3cc10e3435 100644 --- a/src/test/java/hudson/plugins/git/util/AncestryBuildChooserTest.java +++ b/src/test/java/hudson/plugins/git/util/AncestryBuildChooserTest.java @@ -119,7 +119,8 @@ private String getLastCommitSha1(Set prevBranches) throws Exception { // Git Client implementation throws away committer date info so we have to do this manually.. // Copied from JGitAPIImpl.commit(String message) private void commit(String message, PersonIdent author, PersonIdent committer) { - try (Repository repo = testGitClient.getRepository()) { + try (@SuppressWarnings("deprecation") // Local repository reference + Repository repo = testGitClient.getRepository()) { CommitCommand cmd = Git.wrap(repo).commit().setMessage(message); if (author != null) cmd.setAuthor(author); diff --git a/src/test/java/hudson/plugins/git/util/CommitTimeComparatorTest.java b/src/test/java/hudson/plugins/git/util/CommitTimeComparatorTest.java index 153d42c8ea..b104e638c0 100644 --- a/src/test/java/hudson/plugins/git/util/CommitTimeComparatorTest.java +++ b/src/test/java/hudson/plugins/git/util/CommitTimeComparatorTest.java @@ -40,10 +40,12 @@ public void testSort_OrderIsOldToNew() throws Exception { } assertEquals(3,revs.size()); + @SuppressWarnings("deprecation") // Local repository reference + org.eclipse.jgit.lib.Repository testRepo = testGitClient.getRepository(); for (int i=0; i<16; i++) { // shuffle, then sort. Collections.shuffle(revs); - Collections.sort(revs, new CommitTimeComparator(testGitClient.getRepository())); + Collections.sort(revs, new CommitTimeComparator(testRepo)); // it should be always branch1, branch2, branch3 for (int j=0; j<3; j++) diff --git a/src/test/java/jenkins/plugins/git/CliGitCommand.java b/src/test/java/jenkins/plugins/git/CliGitCommand.java index d62232badb..9774c571d8 100644 --- a/src/test/java/jenkins/plugins/git/CliGitCommand.java +++ b/src/test/java/jenkins/plugins/git/CliGitCommand.java @@ -66,7 +66,8 @@ public CliGitCommand(GitClient client, String... arguments) { launcher = new Launcher.LocalLauncher(listener); env = new EnvVars(); if (client != null) { - try (Repository repo = client.getRepository()) { + try (@SuppressWarnings("deprecation") // Local repository reference + Repository repo = client.getRepository()) { dir = repo.getWorkTree(); } } else { From c448d027dfc690d2fd43e342f7b3d87fb1969bba Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 21:49:19 -0600 Subject: [PATCH 16/37] Suppress deprecation message on getBuilds.size() --- src/test/java/jenkins/plugins/git/GitBranchSCMHeadTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/jenkins/plugins/git/GitBranchSCMHeadTest.java b/src/test/java/jenkins/plugins/git/GitBranchSCMHeadTest.java index 8ea7fd3471..4b43647ecd 100644 --- a/src/test/java/jenkins/plugins/git/GitBranchSCMHeadTest.java +++ b/src/test/java/jenkins/plugins/git/GitBranchSCMHeadTest.java @@ -56,6 +56,7 @@ public void removeRepos() throws IOException { @Issue("JENKINS-48061") @Test @LocalData + @Deprecated // getBuilds.size() public void testMigrationNoBuildStorm() throws Exception { assumeFalse(Functions.isWindows()); final WorkflowMultiBranchProject job = j.jenkins.getItemByFullName("job", WorkflowMultiBranchProject.class); @@ -81,4 +82,4 @@ public void testMigrationNoBuildStorm() throws Exception { assertEquals(0, v4.getBuilds().size()); } -} \ No newline at end of file +} From 8c6b433f25a02ce3a2261842ab1882c68645bbe9 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 21:54:50 -0600 Subject: [PATCH 17/37] Test with readLines and character set --- src/test/java/hudson/plugins/git/SCMTriggerTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/hudson/plugins/git/SCMTriggerTest.java b/src/test/java/hudson/plugins/git/SCMTriggerTest.java index ea667f20c3..de89c5c796 100644 --- a/src/test/java/hudson/plugins/git/SCMTriggerTest.java +++ b/src/test/java/hudson/plugins/git/SCMTriggerTest.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Enumeration; import java.util.Properties; @@ -304,7 +305,7 @@ private Properties parseLsRemote(File file) throws IOException { Properties properties = new Properties(); Pattern pattern = Pattern.compile("([a-f0-9]{40})\\s*(.*)"); - for(Object lineO : FileUtils.readLines(file)) { + for(Object lineO : FileUtils.readLines(file, StandardCharsets.UTF_8)) { String line = ((String)lineO).trim(); Matcher matcher = pattern.matcher(line); if(matcher.matches()) { From b8056109da9fdb37d32407d7e286515c3bb1a65f Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 25 May 2020 21:55:12 -0600 Subject: [PATCH 18/37] Use non-deprecated getLog(n) method --- .../java/hudson/plugins/git/GitSCMTest.java | 20 +++++++++---------- .../extensions/impl/WipeWorkspaceTest.java | 6 ++++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/test/java/hudson/plugins/git/GitSCMTest.java b/src/test/java/hudson/plugins/git/GitSCMTest.java index fc32d1954e..1448492f9e 100644 --- a/src/test/java/hudson/plugins/git/GitSCMTest.java +++ b/src/test/java/hudson/plugins/git/GitSCMTest.java @@ -381,11 +381,11 @@ public void testAddFirstRepositoryWithNullRepoURL() throws Exception{ FreeStyleProject project = setupProject(repos, Collections.singletonList(new BranchSpec("master")), null, false, null); FreeStyleBuild build = build(project, Result.FAILURE); // Before JENKINS-38608 fix - assertFalse("Build log reports 'Null value not allowed'", - build.getLog().contains("Null value not allowed as an environment variable: GIT_URL")); + assertThat("Build log reports 'Null value not allowed'", + build.getLog(175), not(hasItem("Null value not allowed as an environment variable: GIT_URL"))); // After JENKINS-38608 fix - assertTrue("Build log did not report empty string in job definition", - build.getLog().contains("Git repository URL 1 is an empty string in job definition. Checkout requires a valid repository URL")); + assertThat("Build log did not report empty string in job definition", + build.getLog(175), hasItem("FATAL: Git repository URL 1 is an empty string in job definition. Checkout requires a valid repository URL")); } /** @@ -405,11 +405,11 @@ public void testAddSecondRepositoryWithNullRepoURL() throws Exception{ FreeStyleProject project = setupProject(repos, Collections.singletonList(new BranchSpec("master")), null, false, null); FreeStyleBuild build = build(project, Result.FAILURE); // Before JENKINS-38608 fix - assertFalse("Build log reports 'Null value not allowed'", - build.getLog().contains("Null value not allowed as an environment variable: GIT_URL_2")); + assertThat("Build log reports 'Null value not allowed'", + build.getLog(175), not(hasItem("Null value not allowed as an environment variable: GIT_URL_2"))); // After JENKINS-38608 fix - assertTrue("Build log did not report empty string in job definition for URL 2", - build.getLog().contains("Git repository URL 2 is an empty string in job definition. Checkout requires a valid repository URL")); + assertThat("Build log did not report empty string in job definition for URL 2", + build.getLog(175), hasItem("FATAL: Git repository URL 2 is an empty string in job definition. Checkout requires a valid repository URL")); } @Test @@ -855,14 +855,14 @@ public void testCleanBeforeCheckout() throws Exception { git.branch(branch1); git.checkout(branch1); p.poll(listener).hasChanges(); - assertTrue(firstBuild.getLog().contains("Cleaning")); + assertThat(firstBuild.getLog(175), hasItem("Cleaning workspace")); assertTrue(firstBuild.getLog().indexOf("Cleaning") > firstBuild.getLog().indexOf("Cloning")); //clean should be after clone assertTrue(firstBuild.getLog().indexOf("Cleaning") < firstBuild.getLog().indexOf("Checking out")); //clean before checkout assertTrue(firstBuild.getWorkspace().child(commitFile1).exists()); git.checkout(branch1); final FreeStyleBuild secondBuild = build(p, Result.SUCCESS, commitFile2); p.poll(listener).hasChanges(); - assertTrue(secondBuild.getLog().contains("Cleaning")); + assertThat(secondBuild.getLog(175), hasItem("Cleaning workspace")); assertTrue(secondBuild.getLog().indexOf("Cleaning") < secondBuild.getLog().indexOf("Fetching upstream changes")); assertTrue(secondBuild.getWorkspace().child(commitFile2).exists()); diff --git a/src/test/java/hudson/plugins/git/extensions/impl/WipeWorkspaceTest.java b/src/test/java/hudson/plugins/git/extensions/impl/WipeWorkspaceTest.java index 345d88c22d..1fcd0f252b 100644 --- a/src/test/java/hudson/plugins/git/extensions/impl/WipeWorkspaceTest.java +++ b/src/test/java/hudson/plugins/git/extensions/impl/WipeWorkspaceTest.java @@ -7,6 +7,7 @@ import hudson.plugins.git.TestGitRepo; import hudson.plugins.git.extensions.GitSCMExtension; import hudson.plugins.git.extensions.GitSCMExtensionTest; +import java.util.List; import nl.jqno.equalsverifier.EqualsVerifier; import org.jenkinsci.plugins.gitclient.Git; import org.jenkinsci.plugins.gitclient.GitClient; @@ -14,6 +15,7 @@ import org.jvnet.hudson.test.WithoutJenkins; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.is; public class WipeWorkspaceTest extends GitSCMExtensionTest { @@ -43,8 +45,8 @@ public void testWipeWorkspace() throws Exception { git.commit("First commit"); FreeStyleBuild build = build(projectWithMaster, Result.SUCCESS); - String buildLog = build.getLog(); - assertThat("Workspace not cleaned before checkout",true, is(buildLog.contains("Wiping out workspace first."))); + List buildLog = build.getLog(175); + assertThat(buildLog, hasItem("Wiping out workspace first.")); } @Test From 3328cdc92e5aaa42a518a60797eac713f6caaa77 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Tue, 26 May 2020 05:37:11 -0600 Subject: [PATCH 19/37] Use getSomeWorkspace in test, not deprecated getWorkspace The caller has only built one time in the workspace so "some" workspace can only be the single build that was run. --- .../plugins/git/extensions/impl/CloneOptionNoTagsTest.java | 2 +- .../git/extensions/impl/CloneOptionShallowDefaultTagsTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/hudson/plugins/git/extensions/impl/CloneOptionNoTagsTest.java b/src/test/java/hudson/plugins/git/extensions/impl/CloneOptionNoTagsTest.java index d16faaa3d0..675a3b0818 100644 --- a/src/test/java/hudson/plugins/git/extensions/impl/CloneOptionNoTagsTest.java +++ b/src/test/java/hudson/plugins/git/extensions/impl/CloneOptionNoTagsTest.java @@ -71,7 +71,7 @@ public void detectNoChangeAfterCreatingATag() throws Exception { } private Set allTagsInProjectWorkspace() throws IOException, InterruptedException { - GitClient git = Git.with(listener, null).in(project.getWorkspace()).getClient(); + GitClient git = Git.with(listener, null).in(project.getSomeWorkspace()).getClient(); return git.getTagNames("*"); } } diff --git a/src/test/java/hudson/plugins/git/extensions/impl/CloneOptionShallowDefaultTagsTest.java b/src/test/java/hudson/plugins/git/extensions/impl/CloneOptionShallowDefaultTagsTest.java index f23d808b2d..4778c9e8c7 100644 --- a/src/test/java/hudson/plugins/git/extensions/impl/CloneOptionShallowDefaultTagsTest.java +++ b/src/test/java/hudson/plugins/git/extensions/impl/CloneOptionShallowDefaultTagsTest.java @@ -52,7 +52,7 @@ public void evenShallowCloningFetchesTagsByDefault() throws Exception { } private Set tagsInProjectWorkspaceWithName(String tagPattern) throws IOException, InterruptedException { - GitClient git = Git.with(listener, null).in(project.getWorkspace()).getClient(); + GitClient git = Git.with(listener, null).in(project.getSomeWorkspace()).getClient(); return git.getTagNames(tagPattern); } } From 035311459e0990101de7a5ad6f82fac2e3b12548 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Tue, 26 May 2020 05:42:31 -0600 Subject: [PATCH 20/37] Test with non-deprecated User.get() replacement --- src/test/java/hudson/plugins/git/TestGitRepo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/hudson/plugins/git/TestGitRepo.java b/src/test/java/hudson/plugins/git/TestGitRepo.java index 647d163d9e..fcf404350b 100644 --- a/src/test/java/hudson/plugins/git/TestGitRepo.java +++ b/src/test/java/hudson/plugins/git/TestGitRepo.java @@ -38,11 +38,11 @@ public TestGitRepo(String name, File tmpDir, TaskListener listener) throws IOExc EnvVars envVars = new EnvVars(); gitDir = tmpDir; - User john = User.get(johnDoe.getName(), true); + User john = User.getOrCreateByIdOrFullName(johnDoe.getName()); UserProperty johnsMailerProperty = new Mailer.UserProperty(johnDoe.getEmailAddress()); john.addProperty(johnsMailerProperty); - User jane = User.get(janeDoe.getName(), true); + User jane = User.getOrCreateByIdOrFullName(janeDoe.getName()); UserProperty janesMailerProperty = new Mailer.UserProperty(janeDoe.getEmailAddress()); jane.addProperty(janesMailerProperty); From 2422c7dcdef4799319a580f4b0a54581b7dab232 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Tue, 26 May 2020 05:57:44 -0600 Subject: [PATCH 21/37] Use data bound setter instead of deprecated SCMTrigger constructor --- src/test/java/hudson/plugins/git/GitStatusMultipleSCMTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/hudson/plugins/git/GitStatusMultipleSCMTest.java b/src/test/java/hudson/plugins/git/GitStatusMultipleSCMTest.java index cc458cf18e..3c77d3c059 100644 --- a/src/test/java/hudson/plugins/git/GitStatusMultipleSCMTest.java +++ b/src/test/java/hudson/plugins/git/GitStatusMultipleSCMTest.java @@ -77,7 +77,8 @@ private HttpServletRequest requestWithoutParameters() { } private SCMTrigger setupProject(String branchString, boolean ignoreNotifyCommit) throws Exception { - SCMTrigger trigger = new SCMTrigger("", ignoreNotifyCommit); + SCMTrigger trigger = new SCMTrigger(""); + trigger.setIgnorePostCommitHooks(ignoreNotifyCommit); setupProject(branchString, trigger); return trigger; } From 37bd53edf6463bd5ca833a7f6519151f7f0b4521 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Tue, 26 May 2020 05:58:07 -0600 Subject: [PATCH 22/37] Deprecate test of deprecated method --- .../java/hudson/plugins/git/GitChangeSetTest.java | 2 ++ .../java/hudson/plugins/git/UserMergeOptionsTest.java | 1 + .../hudson/plugins/git/browser/GithubWebTest.java | 3 +++ .../git/extensions/impl/CloneOptionDepthTest.java | 1 + .../jenkins/plugins/git/AbstractGitSCMSourceTest.java | 7 +++++++ .../plugins/git/AbstractGitSCMSourceTrivialTest.java | 11 +++++++++++ .../jenkins/plugins/git/GitSCMFileSystemTest.java | 6 ++++++ .../java/jenkins/plugins/git/GitSCMSourceTest.java | 1 + .../jenkins/plugins/git/GitSCMSourceTraitsTest.java | 7 +++++++ 9 files changed, 39 insertions(+) diff --git a/src/test/java/hudson/plugins/git/GitChangeSetTest.java b/src/test/java/hudson/plugins/git/GitChangeSetTest.java index d1ae260f6d..519f5c3193 100644 --- a/src/test/java/hudson/plugins/git/GitChangeSetTest.java +++ b/src/test/java/hudson/plugins/git/GitChangeSetTest.java @@ -37,6 +37,7 @@ public void testFindOrCreateUser() { } @Test + @Deprecated public void testFindOrCreateUserBasedOnExistingUsersEmail() throws IOException { final GitChangeSet committerCS = GitChangeSetUtil.genChangeSet(true, false); final String existingUserId = "An existing user"; @@ -68,6 +69,7 @@ public void testFindOrCreateUserBasedOnExistingUsersEmail() throws IOException { } @Test + @Deprecated public void findOrCreateByFullName() throws Exception { GitChangeSet cs = GitChangeSetUtil.genChangeSet(false, false); User user = User.get("john"); diff --git a/src/test/java/hudson/plugins/git/UserMergeOptionsTest.java b/src/test/java/hudson/plugins/git/UserMergeOptionsTest.java index 1a5759cd8d..f8da0291eb 100644 --- a/src/test/java/hudson/plugins/git/UserMergeOptionsTest.java +++ b/src/test/java/hudson/plugins/git/UserMergeOptionsTest.java @@ -206,6 +206,7 @@ public void equalsContract() { @Issue({"JENKINS-51638", "JENKINS-34070"}) @Test + @Deprecated // Testing deprecated method instantiate public void mergeStrategyCase() throws Exception { Map args = new HashMap<>(); if (expectedMergeTarget != null) { diff --git a/src/test/java/hudson/plugins/git/browser/GithubWebTest.java b/src/test/java/hudson/plugins/git/browser/GithubWebTest.java index 8c8a21e721..181b530b88 100644 --- a/src/test/java/hudson/plugins/git/browser/GithubWebTest.java +++ b/src/test/java/hudson/plugins/git/browser/GithubWebTest.java @@ -184,14 +184,17 @@ public String getRemote() { return remote; } @Override + @Deprecated public String getIncludes() { return "*"; } @Override + @Deprecated public String getExcludes() { return ""; } @Override + @Deprecated protected List getRefSpecs() { List result = new ArrayList<>(); for (String refSpec : refSpecs) { diff --git a/src/test/java/hudson/plugins/git/extensions/impl/CloneOptionDepthTest.java b/src/test/java/hudson/plugins/git/extensions/impl/CloneOptionDepthTest.java index 13c1e58a39..920f643072 100644 --- a/src/test/java/hudson/plugins/git/extensions/impl/CloneOptionDepthTest.java +++ b/src/test/java/hudson/plugins/git/extensions/impl/CloneOptionDepthTest.java @@ -81,6 +81,7 @@ public void decorateCloneCommandShouldUseValidShallowDepth() throws Exception { @Issue("JENKINS-53050") @Test + @Deprecated public void decorateFetchCommandShouldUseValidShallowDepth() throws Exception { FetchCommand fetchCommand = mock(FetchCommand.class, Mockito.RETURNS_SELF); diff --git a/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java b/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java index 1744df5ed0..fe374516ab 100644 --- a/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java +++ b/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java @@ -89,6 +89,7 @@ public class AbstractGitSCMSourceTest { // TODO AbstractGitSCMSourceRetrieveHeadsTest *sounds* like it would be the right place, but it does not in fact retrieve any heads! @Issue("JENKINS-37482") @Test + @Deprecated public void retrieveHeads() throws Exception { sampleRepo.init(); sampleRepo.git("checkout", "-b", "dev"); @@ -372,6 +373,7 @@ public void retrievePrimaryHead_Duplicated() throws Exception { retrievePrimaryHead(true); } + @Deprecated public void retrievePrimaryHead(boolean duplicatePrimary) throws Exception { sampleRepo.init(); sampleRepo.write("file.txt", ""); @@ -767,6 +769,7 @@ public void fetchOtherRevisions() throws Exception { @Issue("JENKINS-37727") @Test + @Deprecated public void pruneRemovesDeletedBranches() throws Exception { sampleRepo.init(); @@ -806,6 +809,7 @@ public void pruneRemovesDeletedBranches() throws Exception { } @Test + @Deprecated public void testSpecificRevisionBuildChooser() throws Exception { sampleRepo.init(); @@ -865,6 +869,7 @@ public void testSpecificRevisionBuildChooser() throws Exception { @Test + @Deprecated public void testCustomRemoteName() throws Exception { sampleRepo.init(); @@ -879,6 +884,7 @@ public void testCustomRemoteName() throws Exception { } @Test + @Deprecated public void testCustomRefSpecs() throws Exception { sampleRepo.init(); @@ -1054,6 +1060,7 @@ public FetchCommand from(URIish urIish, List list) { } @Override + @Deprecated public FetchCommand prune() { fetchCommand.prune(true); return this; diff --git a/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTrivialTest.java b/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTrivialTest.java index c16597bdb9..6500a699d8 100644 --- a/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTrivialTest.java +++ b/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTrivialTest.java @@ -79,21 +79,25 @@ public void testGetRemote() { } @Test + @Deprecated public void testGetIncludes() { assertEquals(expectedIncludes, gitSCMSource.getIncludes()); } @Test + @Deprecated public void testGetExcludes() { assertEquals(expectedExcludes, gitSCMSource.getExcludes()); } @Test + @Deprecated public void testGetRemoteName() { assertEquals(expectedRemote, gitSCMSource.getRemoteName()); } @Test + @Deprecated public void testGetRefSpecs() { assertEquals(expectedRefSpecs, gitSCMSource.getRefSpecs()); } @@ -124,6 +128,7 @@ public void testIsExcluded() { } @Test + @Deprecated public void testGetRemoteConfigs() { List remoteConfigs = gitSCMSource.getRemoteConfigs(); assertEquals(expectedRemote, remoteConfigs.get(0).getName()); @@ -169,14 +174,20 @@ public String getRemote() { return expectedRemote; } + @Override + @Deprecated public String getIncludes() { return expectedIncludes; } + @Override + @Deprecated public String getExcludes() { return expectedExcludes; } + @Override + @Deprecated public List getRefSpecs() { return expectedRefSpecs; } diff --git a/src/test/java/jenkins/plugins/git/GitSCMFileSystemTest.java b/src/test/java/jenkins/plugins/git/GitSCMFileSystemTest.java index 13326d39dd..14271ed400 100644 --- a/src/test/java/jenkins/plugins/git/GitSCMFileSystemTest.java +++ b/src/test/java/jenkins/plugins/git/GitSCMFileSystemTest.java @@ -110,6 +110,7 @@ public static void confirmTagsAvailable() throws Exception { } @Test + @Deprecated // Testing deprecated GitSCMSource constructor public void ofSource_Smokes() throws Exception { sampleRepo.init(); sampleRepo.git("checkout", "-b", "dev"); @@ -134,6 +135,7 @@ public void ofSource_Smokes() throws Exception { } @Test + @Deprecated // Testing deprecated GitSCMSource constructor public void ofSourceRevision() throws Exception { sampleRepo.init(); sampleRepo.git("checkout", "-b", "dev"); @@ -154,6 +156,7 @@ public void ofSourceRevision() throws Exception { } @Test + @Deprecated // Testing deprecated GitSCMSource constructor public void ofSourceRevision_GitBranchSCMHead() throws Exception { sampleRepo.init(); sampleRepo.git("checkout", "-b", "dev"); @@ -195,6 +198,7 @@ public void slashyBranches() throws Exception { } @Test + @Deprecated // Testing deprecated GitSCMSource constructor public void lastModified_Smokes() throws Exception { Assume.assumeTrue("Windows file system last modify dates not trustworthy", !isWindows()); sampleRepo.init(); @@ -217,6 +221,7 @@ public void lastModified_Smokes() throws Exception { } @Test + @Deprecated // Testing deprecated GitSCMSource constructor public void directoryTraversal() throws Exception { sampleRepo.init(); sampleRepo.git("checkout", "-b", "dev"); @@ -252,6 +257,7 @@ public void directoryTraversal() throws Exception { } @Test + @Deprecated // Testing deprecated GitSCMSource constructor public void mixedContent() throws Exception { sampleRepo.init(); sampleRepo.git("checkout", "-b", "dev"); diff --git a/src/test/java/jenkins/plugins/git/GitSCMSourceTest.java b/src/test/java/jenkins/plugins/git/GitSCMSourceTest.java index e6d7e3be2a..305b632c62 100644 --- a/src/test/java/jenkins/plugins/git/GitSCMSourceTest.java +++ b/src/test/java/jenkins/plugins/git/GitSCMSourceTest.java @@ -91,6 +91,7 @@ public void setup() { } @Test + @Deprecated public void testSourceOwnerTriggeredByDoNotifyCommit() throws Exception { GitSCMSource gitSCMSource = new GitSCMSource("id", REMOTE, "", "*", "", false); GitSCMSourceOwner scmSourceOwner = setupGitSCMSourceOwner(gitSCMSource); diff --git a/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java b/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java index c12fe37b74..a2c9fa309a 100644 --- a/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java +++ b/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java @@ -135,6 +135,7 @@ private void verifyCleanCheckoutTraits(boolean deleteUntrackedNestedRepositories } @Test + @Deprecated // Testing deprecated methods on GitSCMSource public void pimpped_out() throws Exception { GitSCMSource instance = load(); assertThat(instance.getId(), is("fd2380f8-d34f-48d5-8006-c34542bc4a89")); @@ -297,6 +298,7 @@ public void given__modernCode__when__constructor__then__traitsEmpty() throws Exc } @Test + @Deprecated public void given__legacyCode__when__constructor__then__traitsContainLegacyDefaults1() throws Exception { GitSCMSource instance = new GitSCMSource("id", "git://git.test/example.git", null, "*", "", false); assertThat(instance.getTraits(), contains( @@ -310,6 +312,7 @@ public void given__legacyCode__when__constructor__then__traitsContainLegacyDefau } @Test + @Deprecated // Testing deprecated GitSCMSource constructor public void given__legacyCode__when__constructor__then__traitsContainLegacyDefaults2() throws Exception { GitSCMSource instance = new GitSCMSource("id", "git://git.test/example.git", null, "*", "", true); assertThat(instance.getTraits(), containsInAnyOrder( @@ -320,6 +323,7 @@ public void given__legacyCode__when__constructor__then__traitsContainLegacyDefau } @Test + @Deprecated // Testing deprecated GitSCMSource constructor public void given__legacyCode__when__constructor__then__traitsContainLegacyDefaults3() throws Exception { GitSCMSource instance = new GitSCMSource("id", "git://git.test/example.git", null, "foo/*", "", false); assertThat(instance.getTraits(), contains( @@ -335,6 +339,7 @@ public void given__legacyCode__when__constructor__then__traitsContainLegacyDefau } @Test + @Deprecated // Testing deprecated GitSCMSource constructor public void given__legacyCode__when__constructor__then__traitsContainLegacyDefaults4() throws Exception { GitSCMSource instance = new GitSCMSource("id", "git://git.test/example.git", null, "", "foo/*", false); assertThat(instance.getTraits(), contains( @@ -350,6 +355,7 @@ public void given__legacyCode__when__constructor__then__traitsContainLegacyDefau } @Test + @Deprecated // Testing deprecated GitSCMSource constructor public void given__legacyCode__when__constructor__then__traitsContainLegacyDefaults5() throws Exception { GitSCMSource instance = new GitSCMSource("id", "git://git.test/example.git", null, "upstream", null, "*", "", false); @@ -364,6 +370,7 @@ public void given__legacyCode__when__constructor__then__traitsContainLegacyDefau } @Test + @Deprecated // Testing deprecated GitSCMSource constructor public void given__legacyCode__when__constructor__then__traitsContainLegacyDefaults6() throws Exception { GitSCMSource instance = new GitSCMSource("id", "git://git.test/example.git", null, null, "refs/pulls/*:refs/upstream/*", "*", From f0739cd0c3e23e686b2a2abcd3cfcbf2ef44216d Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 30 May 2020 05:53:10 -0600 Subject: [PATCH 23/37] Use non-deprecated getWorkspace().getRemote() --- src/test/java/hudson/plugins/git/GitSCMTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/hudson/plugins/git/GitSCMTest.java b/src/test/java/hudson/plugins/git/GitSCMTest.java index 1448492f9e..ec5a30e190 100644 --- a/src/test/java/hudson/plugins/git/GitSCMTest.java +++ b/src/test/java/hudson/plugins/git/GitSCMTest.java @@ -2189,7 +2189,7 @@ public void testCheckoutFailureIsRetryable() throws Exception { commit(commitFile2, janeDoe, "Commit number 2"); // create lock file to simulate lock collision - File lock = new File(build1.getWorkspace().toString(), ".git/index.lock"); + File lock = new File(build1.getWorkspace().getRemote(), ".git/index.lock"); try { FileUtils.touch(lock); final FreeStyleBuild build2 = build(project, Result.FAILURE); From 964a767900e7eeeef977e321ecfd9a08efd3ea8f Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 30 May 2020 05:53:34 -0600 Subject: [PATCH 24/37] Use non-deprecated IOUtils.toString() --- src/test/java/hudson/plugins/git/GitSCMTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/hudson/plugins/git/GitSCMTest.java b/src/test/java/hudson/plugins/git/GitSCMTest.java index ec5a30e190..0abd395f45 100644 --- a/src/test/java/hudson/plugins/git/GitSCMTest.java +++ b/src/test/java/hudson/plugins/git/GitSCMTest.java @@ -2879,7 +2879,7 @@ private boolean notifyCommit(FreeStyleProject project, ObjectId commitId) throws final URL notifyUrl = new URL(notificationPath); String notifyContent = null; try (final InputStream is = notifyUrl.openStream()) { - notifyContent = IOUtils.toString(is); + notifyContent = IOUtils.toString(is, "UTF-8"); } assertThat(notifyContent, containsString("No Git consumers using SCM API plugin for: " + testRepo.gitDir.toString())); From 6785e528b2e549acaf1cd5b8e2160764a2c2bc89 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 30 May 2020 05:54:17 -0600 Subject: [PATCH 25/37] Mark a UserMergeOptions test method as deprecated --- .../hudson/plugins/git/UserMergeOptionsTest.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/test/java/hudson/plugins/git/UserMergeOptionsTest.java b/src/test/java/hudson/plugins/git/UserMergeOptionsTest.java index f8da0291eb..ad1a230859 100644 --- a/src/test/java/hudson/plugins/git/UserMergeOptionsTest.java +++ b/src/test/java/hudson/plugins/git/UserMergeOptionsTest.java @@ -30,6 +30,14 @@ public class UserMergeOptionsTest { private final MergeCommand.Strategy expectedMergeStrategy; private final MergeCommand.GitPluginFastForwardMode expectedFastForwardMode; + @Deprecated + private UserMergeOptions defineDeprecatedOptions(String mergeRemote, String mergeTarget, MergeCommand.Strategy mergeStrategy) { + return new UserMergeOptions( + mergeRemote, + mergeTarget, + mergeStrategy == null ? null : mergeStrategy.toString()); + } + public UserMergeOptionsTest( String mergeRemote, String mergeTarget, @@ -44,10 +52,7 @@ public UserMergeOptionsTest( mergeTarget, mergeStrategy == null ? null : mergeStrategy.toString(), fastForwardMode); - deprecatedOptions = new UserMergeOptions( - mergeRemote, - mergeTarget, - mergeStrategy == null ? null : mergeStrategy.toString()); + deprecatedOptions = defineDeprecatedOptions(mergeRemote, mergeTarget, mergeStrategy); } @Parameterized.Parameters(name = "{0}+{1}+{2}+{3}") From ccc54f6370b3e55f8d97a73993ed5084a15617af Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 30 May 2020 05:54:51 -0600 Subject: [PATCH 26/37] Deprecate an assert method that depends on a deprecated method --- src/test/java/hudson/plugins/git/UserRemoteConfigTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/hudson/plugins/git/UserRemoteConfigTest.java b/src/test/java/hudson/plugins/git/UserRemoteConfigTest.java index 0092c01a59..11bc3245aa 100644 --- a/src/test/java/hudson/plugins/git/UserRemoteConfigTest.java +++ b/src/test/java/hudson/plugins/git/UserRemoteConfigTest.java @@ -48,7 +48,8 @@ public void credentialsDropdown() throws Exception { assertCredentials(null, null, "admin", "", "mycreds"); assertCredentials(null, "othercreds", "admin", "", "mycreds", "othercreds"); } - + + @Deprecated private void assertCredentials(@CheckForNull final Item project, @CheckForNull final String currentCredentialsId, @NonNull String user, @NonNull String... expectedCredentialsIds) { final Set actual = new TreeSet<>(); // for purposes of this test we do not care about order (though StandardListBoxModel does define some) ACL.impersonate(User.get(user).impersonate(), () -> { From 1943cf977f6d561134e55fc31615c9b6d0dfd19e Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 30 May 2020 05:57:06 -0600 Subject: [PATCH 27/37] Call non-deprecated repo browser constructor --- .../hudson/plugins/git/browser/GitRepositoryBrowserTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/hudson/plugins/git/browser/GitRepositoryBrowserTest.java b/src/test/java/hudson/plugins/git/browser/GitRepositoryBrowserTest.java index 0f0fe5c752..00f618c15e 100644 --- a/src/test/java/hudson/plugins/git/browser/GitRepositoryBrowserTest.java +++ b/src/test/java/hudson/plugins/git/browser/GitRepositoryBrowserTest.java @@ -66,7 +66,7 @@ public static Collection permuteAuthorNameAndGitImplementationAndObjectId() { @Before public void setUp() throws IOException, InterruptedException { - browser = new GitRepositoryBrowserImpl(); + browser = new GitRepositoryBrowserImpl(null); changeSet = GitChangeSetUtil.genChangeSet(sha1, gitImplementation, useAuthorName); paths = changeSet.getPaths(); } From 4626c4a91ac957720dd9dcb21f987ae8286700f5 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 30 May 2020 05:57:25 -0600 Subject: [PATCH 28/37] Mark two methods as Overriden --- .../hudson/plugins/git/browser/GitRepositoryBrowserTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/hudson/plugins/git/browser/GitRepositoryBrowserTest.java b/src/test/java/hudson/plugins/git/browser/GitRepositoryBrowserTest.java index 00f618c15e..262c2fe1f1 100644 --- a/src/test/java/hudson/plugins/git/browser/GitRepositoryBrowserTest.java +++ b/src/test/java/hudson/plugins/git/browser/GitRepositoryBrowserTest.java @@ -120,10 +120,12 @@ private URL getURL(GitChangeSet.Path path, boolean isDiffLink) throws MalformedU public class GitRepositoryBrowserImpl extends GitRepositoryBrowser { + @Override public URL getDiffLink(GitChangeSet.Path path) throws IOException { return getURL(path, true); } + @Override public URL getFileLink(GitChangeSet.Path path) throws IOException { return getURL(path, false); } From d685a3f53c4f1f8d48d6fd57a2f0722bf2d236e1 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 30 May 2020 06:08:46 -0600 Subject: [PATCH 29/37] Fix compile of GitRepositoryBrowserImpl in test --- .../hudson/plugins/git/browser/GitRepositoryBrowserTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/java/hudson/plugins/git/browser/GitRepositoryBrowserTest.java b/src/test/java/hudson/plugins/git/browser/GitRepositoryBrowserTest.java index 262c2fe1f1..d38dca9fab 100644 --- a/src/test/java/hudson/plugins/git/browser/GitRepositoryBrowserTest.java +++ b/src/test/java/hudson/plugins/git/browser/GitRepositoryBrowserTest.java @@ -120,6 +120,10 @@ private URL getURL(GitChangeSet.Path path, boolean isDiffLink) throws MalformedU public class GitRepositoryBrowserImpl extends GitRepositoryBrowser { + protected GitRepositoryBrowserImpl(String repourl) { + super(repourl); + } + @Override public URL getDiffLink(GitChangeSet.Path path) throws IOException { return getURL(path, true); From aac2d51a8a63634f82899e32ad4e2a13a29716b7 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 30 May 2020 14:26:58 -0600 Subject: [PATCH 30/37] Test with Cause.UserIdCause(), not deprecated Cause.UserCause() Deprecation happened in 1.427, a very long time ago. --- src/test/java/hudson/plugins/git/GitSCMTest.java | 6 +++--- src/test/java/hudson/plugins/git/GitStatusTest.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/hudson/plugins/git/GitSCMTest.java b/src/test/java/hudson/plugins/git/GitSCMTest.java index 0abd395f45..d6e53ad982 100644 --- a/src/test/java/hudson/plugins/git/GitSCMTest.java +++ b/src/test/java/hudson/plugins/git/GitSCMTest.java @@ -2409,7 +2409,7 @@ public void testPollingAfterManualBuildWithParametrizedBranchSpec() throws Excep final StringParameterValue branchParam = new StringParameterValue("MY_BRANCH", "manualbranch"); final Action[] actions = {new ParametersAction(branchParam)}; - FreeStyleBuild build = project.scheduleBuild2(0, new Cause.UserCause(), actions).get(); + FreeStyleBuild build = project.scheduleBuild2(0, new Cause.UserIdCause(), actions).get(); rule.assertBuildStatus(Result.SUCCESS, build); assertFalse("No changes to git since last build", project.poll(listener).hasChanges()); @@ -2475,7 +2475,7 @@ Collections. emptyList(), null, null, project.setScm(scm); commit("commitFile1", johnDoe, "Commit number 1"); - FreeStyleBuild first_build = project.scheduleBuild2(0, new Cause.UserCause()).get(); + FreeStyleBuild first_build = project.scheduleBuild2(0, new Cause.UserIdCause()).get(); rule.assertBuildStatus(Result.SUCCESS, first_build); first_build.getWorkspace().deleteContents(); @@ -2515,7 +2515,7 @@ public void testPolling_environmentValueAsEnvironmentContributingAction() throws // SECURITY-170 - have to use ParametersDefinitionProperty project.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("MY_BRANCH", "master"))); - FreeStyleBuild first_build = project.scheduleBuild2(0, new Cause.UserCause(), actions).get(); + FreeStyleBuild first_build = project.scheduleBuild2(0, new Cause.UserIdCause(), actions).get(); rule.assertBuildStatus(Result.SUCCESS, first_build); Launcher launcher = workspace.createLauncher(listener); diff --git a/src/test/java/hudson/plugins/git/GitStatusTest.java b/src/test/java/hudson/plugins/git/GitStatusTest.java index ce654af0e7..c959152a92 100644 --- a/src/test/java/hudson/plugins/git/GitStatusTest.java +++ b/src/test/java/hudson/plugins/git/GitStatusTest.java @@ -603,7 +603,7 @@ private void doNotifyCommitWithDefaultParameter(final boolean allowed, String sa : new Shell("echo $A $B $C"); project.getBuildersList().add(script); - FreeStyleBuild build = project.scheduleBuild2(0, new Cause.UserCause()).get(); + FreeStyleBuild build = project.scheduleBuild2(0, new Cause.UserIdCause()).get(); jenkins.waitForMessage("aaa aaaccc ccc", build); From 6863f105a388e1d65bb35efe6be60831e7234631 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 30 May 2020 14:28:48 -0600 Subject: [PATCH 31/37] Deprecate tests that intentionally test deprecated methods --- src/test/java/hudson/plugins/git/GitSCMTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/java/hudson/plugins/git/GitSCMTest.java b/src/test/java/hudson/plugins/git/GitSCMTest.java index d6e53ad982..f7e43d653a 100644 --- a/src/test/java/hudson/plugins/git/GitSCMTest.java +++ b/src/test/java/hudson/plugins/git/GitSCMTest.java @@ -2432,6 +2432,7 @@ public FakeParametersAction(StringParameterValue params) { this.m_forwardingAction = new ParametersAction(params); } + @Deprecated public void buildEnvVars(AbstractBuild ab, EnvVars ev) { this.m_forwardingAction.buildEnvVars(ab, ev); } @@ -2660,6 +2661,7 @@ public void testSha1NotificationBranches() throws Exception { * in the build data, but no branch name. */ @Test + @Deprecated // Testing deprecated buildEnvVars public void testNoNullPointerExceptionWithNullBranch() throws Exception { ObjectId sha1 = ObjectId.fromString("2cec153f34767f7638378735dc2b907ed251a67d"); @@ -2695,6 +2697,7 @@ public void testNoNullPointerExceptionWithNullBranch() throws Exception { } @Test + @Deprecated // Testing deprecated buildEnvVars public void testBuildEnvVarsLocalBranchStarStar() throws Exception { ObjectId sha1 = ObjectId.fromString("2cec153f34767f7638378735dc2b907ed251a67d"); @@ -2736,6 +2739,7 @@ public void testBuildEnvVarsLocalBranchStarStar() throws Exception { } @Test + @Deprecated // Testing deprecated buildEnvVars public void testBuildEnvVarsLocalBranchNull() throws Exception { ObjectId sha1 = ObjectId.fromString("2cec153f34767f7638378735dc2b907ed251a67d"); @@ -2777,6 +2781,7 @@ public void testBuildEnvVarsLocalBranchNull() throws Exception { } @Test + @Deprecated // testing deprecated buildEnvVars public void testBuildEnvVarsLocalBranchNotSet() throws Exception { ObjectId sha1 = ObjectId.fromString("2cec153f34767f7638378735dc2b907ed251a67d"); From 649049dfc252e736e09aa1afd5e81a1eb043101c Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Wed, 3 Jun 2020 20:37:44 -0600 Subject: [PATCH 32/37] Mark tests of deprecated User.get as deprecated --- src/test/java/hudson/plugins/git/GitChangeSetTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/hudson/plugins/git/GitChangeSetTest.java b/src/test/java/hudson/plugins/git/GitChangeSetTest.java index 519f5c3193..b08d7bae0e 100644 --- a/src/test/java/hudson/plugins/git/GitChangeSetTest.java +++ b/src/test/java/hudson/plugins/git/GitChangeSetTest.java @@ -37,7 +37,7 @@ public void testFindOrCreateUser() { } @Test - @Deprecated + @Deprecated // Test deprecated User.get() public void testFindOrCreateUserBasedOnExistingUsersEmail() throws IOException { final GitChangeSet committerCS = GitChangeSetUtil.genChangeSet(true, false); final String existingUserId = "An existing user"; @@ -69,7 +69,7 @@ public void testFindOrCreateUserBasedOnExistingUsersEmail() throws IOException { } @Test - @Deprecated + @Deprecated // Testing deprecated User.get public void findOrCreateByFullName() throws Exception { GitChangeSet cs = GitChangeSetUtil.genChangeSet(false, false); User user = User.get("john"); From ee631bc5fd10f4cb65729f24f4eb99207a15a0e5 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Wed, 3 Jun 2020 20:44:58 -0600 Subject: [PATCH 33/37] Deprecate tests that call deprecated GitSCMSource constructor --- .../plugins/git/AbstractGitSCMSourceTest.java | 14 ++++++++------ .../plugins/git/GitSCMSourceTraitsTest.java | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java b/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java index fe374516ab..be269e5e49 100644 --- a/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java +++ b/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java @@ -89,7 +89,7 @@ public class AbstractGitSCMSourceTest { // TODO AbstractGitSCMSourceRetrieveHeadsTest *sounds* like it would be the right place, but it does not in fact retrieve any heads! @Issue("JENKINS-37482") @Test - @Deprecated + @Deprecated // Tests deprecated GitSCMSource constructor public void retrieveHeads() throws Exception { sampleRepo.init(); sampleRepo.git("checkout", "-b", "dev"); @@ -364,17 +364,19 @@ public static abstract class ActionableSCMSourceOwner extends Actionable impleme } @Test + @Deprecated public void retrievePrimaryHead_NotDuplicated() throws Exception { retrievePrimaryHead(false); } @Test + @Deprecated public void retrievePrimaryHead_Duplicated() throws Exception { retrievePrimaryHead(true); } - @Deprecated - public void retrievePrimaryHead(boolean duplicatePrimary) throws Exception { + @Deprecated // Calls deprecated GitSCMSource constructor + private void retrievePrimaryHead(boolean duplicatePrimary) throws Exception { sampleRepo.init(); sampleRepo.write("file.txt", ""); sampleRepo.git("add", "file.txt"); @@ -769,7 +771,7 @@ public void fetchOtherRevisions() throws Exception { @Issue("JENKINS-37727") @Test - @Deprecated + @Deprecated // Check GitSCMSource deprecated constructor public void pruneRemovesDeletedBranches() throws Exception { sampleRepo.init(); @@ -869,7 +871,7 @@ public void testSpecificRevisionBuildChooser() throws Exception { @Test - @Deprecated + @Deprecated // Tests deprecated GitSCMSource constructor public void testCustomRemoteName() throws Exception { sampleRepo.init(); @@ -884,7 +886,7 @@ public void testCustomRemoteName() throws Exception { } @Test - @Deprecated + @Deprecated // Tests deprecated GitSCMSource constructor public void testCustomRefSpecs() throws Exception { sampleRepo.init(); diff --git a/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java b/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java index a2c9fa309a..337333df70 100644 --- a/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java +++ b/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java @@ -298,7 +298,7 @@ public void given__modernCode__when__constructor__then__traitsEmpty() throws Exc } @Test - @Deprecated + @Deprecated // Testing deprecated GitSCMSource constructor public void given__legacyCode__when__constructor__then__traitsContainLegacyDefaults1() throws Exception { GitSCMSource instance = new GitSCMSource("id", "git://git.test/example.git", null, "*", "", false); assertThat(instance.getTraits(), contains( From e3599d50ca9bbf208f7cb61932891f427823fdcd Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Wed, 3 Jun 2020 20:45:46 -0600 Subject: [PATCH 34/37] Deprecate tests of deprecated getExtensions & more --- src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java | 2 +- src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java b/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java index be269e5e49..a2c274af5d 100644 --- a/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java +++ b/src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java @@ -811,7 +811,7 @@ public void pruneRemovesDeletedBranches() throws Exception { } @Test - @Deprecated + @Deprecated // Tests deprecated getExtensions() and setExtensions() public void testSpecificRevisionBuildChooser() throws Exception { sampleRepo.init(); diff --git a/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java b/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java index 337333df70..13cafe35b3 100644 --- a/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java +++ b/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java @@ -135,7 +135,7 @@ private void verifyCleanCheckoutTraits(boolean deleteUntrackedNestedRepositories } @Test - @Deprecated // Testing deprecated methods on GitSCMSource + @Deprecated // Includes tests of deprecated methods getIncludes, getExcludes, & getRawRefSpecs public void pimpped_out() throws Exception { GitSCMSource instance = load(); assertThat(instance.getId(), is("fd2380f8-d34f-48d5-8006-c34542bc4a89")); From 944542bb2b505ff9719d3ec6b65613a0eb3990a6 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Wed, 3 Jun 2020 21:02:32 -0600 Subject: [PATCH 35/37] Hide remaining deprecations in tests --- pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pom.xml b/pom.xml index e14872baf7..380d423bda 100644 --- a/pom.xml +++ b/pom.xml @@ -43,12 +43,6 @@ - - maven-compiler-plugin - - -Xlint:deprecation - - org.apache.maven.plugins maven-checkstyle-plugin From 1966bb7e8a9eae0efc70fc4eec61adf02103d7e7 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Thu, 4 Jun 2020 03:45:03 -0600 Subject: [PATCH 36/37] Remove ATH and PCT from Jenkinsfile --- Jenkinsfile | 53 ----------------------------------------------------- 1 file changed, 53 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3beb29e3d4..ff78c5baf5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,56 +12,3 @@ subsetConfiguration = [ [ jdk: '8', platform: 'windows', jenkins: null ] buildPlugin(configurations: subsetConfiguration, failFast: false) - -def branches = [:] - -branches["ATH"] = { - node("docker && highmem") { - def checkoutGit - stage("ATH: Checkout") { - checkoutGit = pwd(tmp:true) + "/athgit" - dir(checkoutGit) { - checkout scm - infra.runMaven(["clean", "package", "-DskipTests"]) - // Include experimental git-client in target dir for ATH - // This Git plugin requires experimental git-client - infra.runMaven(["dependency:copy", "-Dartifact=org.jenkins-ci.plugins:git-client:3.0.0-beta3:hpi", "-DoutputDirectory=target", "-Dmdep.stripVersion=true"]) - dir("target") { - stash name: "localPlugins", includes: "*.hpi" - } - } - } - def metadataPath = checkoutGit + "/essentials.yml" - stage("Run ATH") { - def athFolder=pwd(tmp:true) + "/ath" - dir(athFolder) { - runATH metadataFile: metadataPath - } - } - } -} -branches["PCT"] = { - node("docker && highmem") { - def metadataPath - env.RUN_PCT_LOCAL_PLUGIN_SOURCES_STASH_NAME = "localPluginsPCT" - stage("PCT: Checkout") { - def checkoutGit = pwd(tmp:true) + "/pctgit" - dir(checkoutGit) { - dir("git") { - checkout scm - } - stash name: "localPluginsPCT", useDefaultExcludes: false - } - metadataPath = checkoutGit + "/git/essentials.yml" - } - stage("Run PCT") { - def pctFolder = pwd(tmp:true) + "/pct" - dir(pctFolder) { - runPCT metadataFile: metadataPath - } - } - } -} - -// Intentionally disabled until tests are more reliable -// parallel branches From b27916388a9dbe9aafa1ad0cf62be5d44b3cd6f2 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Thu, 4 Jun 2020 04:31:53 -0600 Subject: [PATCH 37/37] Don't let dirty workspace fail incremental build Once https://github.com/jenkins-infra/pipeline-library/pull/141 is merged, the calls to `clean` can be removed. --- Jenkinsfile | 120 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 111 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ff78c5baf5..e53451d109 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,14 +1,116 @@ -#!groovy +#!/usr/bin/env groovy -Random random = new Random() // Randomize which Jenkins version is selected for more testing -def use_newer_jenkins = random.nextBoolean() // Use newer Jenkins on one build but slightly older on other +import java.util.Collections -// Test plugin compatibility to recommended configurations -subsetConfiguration = [ [ jdk: '8', platform: 'windows', jenkins: null ], - // Compile with Java 8, test 2.204.6 or 2.222.1 depending on random use_newer_jenkins - [ jdk: '8', platform: 'linux', jenkins: !use_newer_jenkins ? '2.204.6' : '2.222.1', javaLevel: '8' ], - // Compile with Java 11, test the Jenkins version that Java 8 did *not* test - [ jdk: '11', platform: 'linux', jenkins: use_newer_jenkins ? '2.204.6' : '2.222.1', javaLevel: '8' ] +// Clean the agents used for the build +// Remove when https://github.com/jenkins-infra/pipeline-library/pull/141 is merged +def temporary_clean(Map params = [:]) { + def failFast = params.containsKey('failFast') ? params.failFast : true + def timeoutValue = params.containsKey('timeout') ? params.timeout : 60 + def forceAci = params.containsKey('forceAci') ? params.forceAci : false + def useAci = params.containsKey('useAci') ? params.useAci : forceAci + if(timeoutValue > 180) { + echo "Timeout value requested was $timeoutValue, lowering to 180 to avoid Jenkins project's resource abusive consumption" + timeoutValue = 180 + } + + Map tasks = [failFast: failFast] + getConfigurations(params).each { config -> + String label = config.platform + String jdk = config.jdk + String jenkinsVersion = config.jenkins + String javaLevel = config.javaLevel + + String stageIdentifier = "${label}-${jdk}${jenkinsVersion ? '-' + jenkinsVersion : ''}" + boolean first = tasks.size() == 1 + boolean runFindbugs = first && params?.findbugs?.run + boolean runCheckstyle = first && params?.checkstyle?.run + boolean archiveFindbugs = first && params?.findbugs?.archive + boolean archiveCheckstyle = first && params?.checkstyle?.archive + boolean skipTests = params?.tests?.skip + boolean addToolEnv = !useAci + + if(useAci && (label == 'linux' || label == 'windows')) { + String aciLabel = jdk == '8' ? 'maven' : 'maven-11' + if(label == 'windows') { + aciLabel += "-windows" + } + label = aciLabel + } + + tasks[stageIdentifier] = { + node(label) { + timeout(timeoutValue) { + stage("TmpClean (${stageIdentifier})") { + if (isUnix()) { + sh(script: 'git clean -xffd > /dev/null 2>&1', + label:'Clean for incrementals', + returnStatus: true) // Ignore failure if CLI git is not available or this is not a git repository + } else { + bat(script: 'git clean -xffd 1> nul 2>&1', + label:'Clean for incrementals', + returnStatus: true) // Ignore failure if CLI git is not available or this is not a git repository + } + } + } + } + } + } + parallel(tasks) +} + +List> getConfigurations(Map params) { + boolean explicit = params.containsKey("configurations") + boolean implicit = params.containsKey('platforms') || params.containsKey('jdkVersions') || params.containsKey('jenkinsVersions') + + if (explicit && implicit) { + error '"configurations" option can not be used with either "platforms", "jdkVersions" or "jenkinsVersions"' + } + + def configs = params.configurations + configs.each { c -> + if (!c.platform) { + error("Configuration field \"platform\" must be specified: $c") + } + if (!c.jdk) { + error("Configuration field \"jdk\" must be specified: $c") + } + } + + if (explicit) return params.configurations + + def platforms = params.containsKey('platforms') ? params.platforms : ['linux', 'windows'] + def jdkVersions = params.containsKey('jdkVersions') ? params.jdkVersions : [8] + def jenkinsVersions = params.containsKey('jenkinsVersions') ? params.jenkinsVersions : [null] + + def ret = [] + for (p in platforms) { + for (jdk in jdkVersions) { + for (jenkins in jenkinsVersions) { + ret << [ + "platform": p, + "jdk": jdk, + "jenkins": jenkins, + "javaLevel": null // not supported in the old format + ] + } + } + } + return ret +} + +// Valid Jenkins versions for test +def testJenkinsVersions = [ '2.204.1', '2.204.6', '2.222.1', '2.222.4', '2.235', '2.238' ] +Collections.shuffle(testJenkinsVersions) + +// Test plugin compatibility to subset of Jenkins versions +subsetConfiguration = [ [ jdk: '8', platform: 'windows', jenkins: testJenkinsVersions[0], javaLevel: '8' ], + [ jdk: '8', platform: 'linux', jenkins: testJenkinsVersions[1], javaLevel: '8' ], + [ jdk: '11', platform: 'linux', jenkins: testJenkinsVersions[2], javaLevel: '8' ] ] +// Clean before build so that `git status -s` will have empty output for incrementals +// Remove when https://github.com/jenkins-infra/pipeline-library/pull/141 is merged +temporary_clean(configurations: subsetConfiguration, failFast: false) + buildPlugin(configurations: subsetConfiguration, failFast: false)