Skip to content

Commit

Permalink
Merge pull request #384 from MarkEWaite/use-JGit-5.2
Browse files Browse the repository at this point in the history
Use JGit 5.2.0 & adapt one test
  • Loading branch information
MarkEWaite committed Dec 11, 2018
2 parents c72d9b8 + c1c3110 commit 69e00ad
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
<jenkins.version>2.60.3</jenkins.version>
<java.level>8</java.level>
<jgit.version>5.1.3.201810200350-r</jgit.version>
<jgit.version>5.2.0.201812061821-r</jgit.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
* A {@link HttpConnection} which uses {@link HttpClient} and attempts to
Expand Down Expand Up @@ -331,14 +333,19 @@ private void execute() throws IOException, ClientProtocolException {
}

public Map<String, List<String>> getHeaderFields() {
Map<String, List<String>> ret = new HashMap<>();
Map<String, List<String>> ret = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
for (Header hdr : resp.getAllHeaders()) {
List<String> list = new LinkedList<>();
for (HeaderElement hdrElem : hdr.getElements())
list.add(hdrElem.toString());
ret.put(hdr.getName(), list);
ret.put(hdr.getName(), Collections.unmodifiableList(list));
}
return ret;
return Collections.unmodifiableMap(ret);
}

public List<String> getHeaderFields(@org.eclipse.jgit.annotations.NonNull String name) {
Map<String, List<String>> allHeaders = getHeaderFields();
return allHeaders.get(name);
}

public void setRequestProperty(String name, String value) {
Expand Down
25 changes: 22 additions & 3 deletions src/test/java/org/jenkinsci/plugins/gitclient/GitAPITestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2124,15 +2124,34 @@ public void test_submodule_checkout_and_clean_transitions() throws Exception {
*/
// w.git.checkout().ref(notSubRefName).execute();
w.git.checkout().ref(notSubRefName).branch(notSubBranchName).deleteBranchIfExist(true).execute();
assertDirExists(ntpDir);
assertFileExists(ntpContributingFile);
assertFileContains(ntpContributingFile, contributingFileContentFromNonsubmoduleBranch);
if (w.git instanceof CliGitAPIImpl) {
/*
* Transition from "with submodule" to "without submodule"
* where the "without submodule" case includes the file
* ntpContributingFile and the directory ntpDir.
*/
assertDirExists(ntpDir);
assertFileExists(ntpContributingFile);
assertFileContains(ntpContributingFile, contributingFileContentFromNonsubmoduleBranch);
/* submodule dirs exist because git.clean() won't remove untracked submodules */
assertDirExists(firewallDir);
assertDirExists(sshkeysDir);
assertFileExists(sshkeysModuleFile);
} else {
/*
* Transition from "with submodule" to "without submodule"
* where the "without submodule" case includes the file
* ntpContributingFile and the directory ntpDir.
*
* JGit 5.2.0 handles the transition from "with submodule"
* to "without submodule" differently than CLI git and
* differently than JGit versions prior to JGit 5.2.0.
* It does not checkout ntpDir or the ntpContributingFile.
*
* Prior to JGit 5.2.0 and the CheckoutCommand bug fix,
* the ntpDir would remain along with ntpContributingFile.
*/
assertDirNotFound(ntpDir);
/* firewallDir and sshKeysDir don't exist because JGit submodule update never created them */
assertDirNotFound(firewallDir);
assertDirNotFound(sshkeysDir);
Expand Down

0 comments on commit 69e00ad

Please sign in to comment.