Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve deprecations in main #899

Merged
merged 37 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c6fabb1
Enable deprecation warnings from java compiler
MarkEWaite May 26, 2020
8072caa
Use try/finally in GitChangeLogParser
MarkEWaite May 26, 2020
c4d9d70
Use PerBuildTag instead of deprecated getSkipTag()
MarkEWaite May 26, 2020
0d3590a
Use non-deprecated GitLab constructor
MarkEWaite May 26, 2020
579b59d
Use non-deprecated methods in GitSCM
MarkEWaite May 26, 2020
c5316de
Use non-deprecated checkout in SubmoduleCombinator
MarkEWaite May 26, 2020
d89270a
Use buildEnvironment instead of deprecated buildEnvVars
MarkEWaite May 26, 2020
48e65a7
Suppress deprecation warnings
MarkEWaite May 26, 2020
ecac6eb
Deprecate because overrides deprecated method
MarkEWaite May 26, 2020
70ed0c6
Suppress IGitAPI deprecation warnings
MarkEWaite May 26, 2020
c440e74
Suppress getRepository reference in AbstractGitSCMSource
MarkEWaite May 26, 2020
d3fac2d
Suppress warnings on index triggering
MarkEWaite May 26, 2020
82f345c
Use emptyString in hamcrest assertion
MarkEWaite May 26, 2020
0865e84
Deprecate tests of deprecated methods
MarkEWaite May 26, 2020
b8d7df9
Suppress test deprecation warnings for getRepository
MarkEWaite May 26, 2020
c448d02
Suppress deprecation message on getBuilds.size()
MarkEWaite May 26, 2020
8c6b433
Test with readLines and character set
MarkEWaite May 26, 2020
b805610
Use non-deprecated getLog(n) method
MarkEWaite May 26, 2020
3328cdc
Use getSomeWorkspace in test, not deprecated getWorkspace
MarkEWaite May 26, 2020
0353114
Test with non-deprecated User.get() replacement
MarkEWaite May 26, 2020
2422c7d
Use data bound setter instead of deprecated SCMTrigger constructor
MarkEWaite May 26, 2020
37bd53e
Deprecate test of deprecated method
MarkEWaite May 26, 2020
f0739cd
Use non-deprecated getWorkspace().getRemote()
MarkEWaite May 30, 2020
964a767
Use non-deprecated IOUtils.toString()
MarkEWaite May 30, 2020
6785e52
Mark a UserMergeOptions test method as deprecated
MarkEWaite May 30, 2020
ccc54f6
Deprecate an assert method that depends on a deprecated method
MarkEWaite May 30, 2020
1943cf9
Call non-deprecated repo browser constructor
MarkEWaite May 30, 2020
4626c4a
Mark two methods as Overriden
MarkEWaite May 30, 2020
d685a3f
Fix compile of GitRepositoryBrowserImpl in test
MarkEWaite May 30, 2020
aac2d51
Test with Cause.UserIdCause(), not deprecated Cause.UserCause()
MarkEWaite May 30, 2020
6863f10
Deprecate tests that intentionally test deprecated methods
MarkEWaite May 30, 2020
649049d
Mark tests of deprecated User.get as deprecated
MarkEWaite Jun 4, 2020
ee631bc
Deprecate tests that call deprecated GitSCMSource constructor
MarkEWaite Jun 4, 2020
e3599d5
Deprecate tests of deprecated getExtensions & more
MarkEWaite Jun 4, 2020
944542b
Hide remaining deprecations in tests
MarkEWaite Jun 4, 2020
1966bb7
Remove ATH and PCT from Jenkinsfile
MarkEWaite Jun 4, 2020
b279163
Don't let dirty workspace fail incremental build
MarkEWaite Jun 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 100 additions & 51 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,67 +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
}

buildPlugin(configurations: subsetConfiguration, failFast: false)
Map tasks = [failFast: failFast]
getConfigurations(params).each { config ->
String label = config.platform
String jdk = config.jdk
String jenkinsVersion = config.jenkins
String javaLevel = config.javaLevel

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"
}
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
}
def metadataPath = checkoutGit + "/essentials.yml"
stage("Run ATH") {
def athFolder=pwd(tmp:true) + "/ath"
dir(athFolder) {
runATH metadataFile: metadataPath

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)
}
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"

List<Map<String, String>> 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")
}
stage("Run PCT") {
def pctFolder = pwd(tmp:true) + "/pct"
dir(pctFolder) {
runPCT metadataFile: metadataPath
}

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
}

// Intentionally disabled until tests are more reliable
// parallel branches
// 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)
8 changes: 2 additions & 6 deletions src/main/java/hudson/plugins/git/GitChangeLogParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,8 @@ public List<GitChangeSet> parse(@NonNull List<String> 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));
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/hudson/plugins/git/GitPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand All @@ -196,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());
Expand Down
30 changes: 19 additions & 11 deletions src/main/java/hudson/plugins/git/GitSCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -268,6 +269,7 @@ private void updateFromUserData() throws GitException {
}
}

@SuppressWarnings("deprecation") // `source` field is deprecated but required
public Object readResolve() throws IOException {
// Migrate data

Expand All @@ -276,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<>();
Expand Down Expand Up @@ -415,7 +417,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);
Expand Down Expand Up @@ -469,9 +471,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
Expand Down Expand Up @@ -849,7 +851,7 @@ public GitClient createClient(TaskListener listener, EnvVars environment, Run<?,
StandardUsernameCredentials.class,
project,
project instanceof Queue.Task
? Tasks.getDefaultAuthenticationOf((Queue.Task)project)
? ((Queue.Task) project).getDefaultAuthentication()
: ACL.SYSTEM,
URIRequirementBuilder.fromUri(url).build()
);
Expand All @@ -874,7 +876,9 @@ public GitClient createClient(TaskListener listener, EnvVars environment, Run<?,

@NonNull
private BuildData fixNull(BuildData bd) {
return bd != null ? bd : new BuildData(getScmName(), getUserRemoteConfigs()) /*dummy*/;
ScmName sn = getExtensions().get(ScmName.class);
String scmName = sn == null ? null : sn.getName();
return bd != null ? bd : new BuildData(scmName, getUserRemoteConfigs());
}

/**
Expand Down Expand Up @@ -1340,6 +1344,8 @@ private void computeChangeLog(GitClient git, Revision revToBuild, TaskListener l
}
}

@Override
@Deprecated // Overrides a deprecated implementation, must also be deprecated
public void buildEnvVars(AbstractBuild<?, ?> build, Map<String, String> env) {
buildEnvironment(build, env);
}
Expand Down Expand Up @@ -1741,9 +1747,9 @@ public List<BranchSpec> 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()) {
Expand Down Expand Up @@ -1792,11 +1798,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;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/hudson/plugins/git/GitStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -224,6 +226,7 @@ public void close() {
}
};
try {
@SuppressWarnings("deprecation")
CustomObjectInputStream objectInput = CustomObjectInputStream
.getInstance(context, callback);
proxy.readExternal(objectInput);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hudson/plugins/git/SubmoduleCombinator.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected void makeCombination(Map<IndexEntry, Revision> 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");
Expand All @@ -156,7 +156,7 @@ protected void makeCombination(Map<IndexEntry, Revision> 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());
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/hudson/plugins/git/UserRemoteConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading