Skip to content

Commit

Permalink
Adapt git browsers for Jetty 12 EE 9 transition (#1620)
Browse files Browse the repository at this point in the history
No need to throw ServletException when checking for URL validity.
IOException is sufficient and avoids including Jakarta EE in the method
signature.

Testing done:

* Confirmed that AssemblaWeb still reports the expected message when an
  invalid URL is provided and that it reports no message when a valid
  URL is provided.  Confirmed that Assembla has changed URLs and broken
  the browsing links that previously worked. Separate bug report

* Confirmed that GitBlit browsing works as expected by installing a
  GitBlit server. https://hub.docker.com/r/gitblit/gitblit

* Confirmed that ViewGit browser provides change links as expected.
  Confirmed that the ViewGit URL check logic no longer works on the
  site used as an example.  Now reports that https://repo.or.cz/ does
  not look like a ViewGit site. Separate bug report

Did not check Gitiles because the Gitiles source repository is archived
on GitHub at https://github.com/google/gitiles .  No further development
is expected.

Did not check TFS2013 because I have no idea where to find a Team
Foundation Server 2013 installation.

Did not check Fisheye because I could not find a Fisheye server on the
public internet.
  • Loading branch information
MarkEWaite committed Aug 3, 2024
1 parent 2f06cfe commit 1c84367
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
9 changes: 7 additions & 2 deletions src/main/java/hudson/plugins/git/browser/AssemblaWeb.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public FormValidation doCheckRepoUrl(@AncestorInPath Item project, @QueryParamet
return FormValidation.error(Messages.invalidUrl());
}
return new URLCheck() {
protected FormValidation check() throws IOException, ServletException {
protected FormValidation check() throws IOException {
String v = cleanUrl;
if (!v.endsWith("/")) {
v += '/';
Expand All @@ -129,7 +129,12 @@ protected FormValidation check() throws IOException, ServletException {
return FormValidation.error("This is a valid URL but it does not look like Assembla");
}
} catch (IOException e) {
return FormValidation.error("Exception reading from Assembla URL " + cleanUrl + " : " + handleIOException(v, e));
String prefix = "Exception reading from Assembla URL " + cleanUrl + " : ";
if (e.getMessage().equals(v)) {

Check warning on line 133 in src/main/java/hudson/plugins/git/browser/AssemblaWeb.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 133 is only partially covered, one branch is missing
return FormValidation.error(prefix + "Unable to connect " + v, e);

Check warning on line 134 in src/main/java/hudson/plugins/git/browser/AssemblaWeb.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 134 is not covered by tests
} else {
return FormValidation.error(prefix + "ERROR: " + e.getMessage(), e);
}
}
}
}.check();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,19 @@ public FormValidation doCheckRepoUrl(@QueryParameter(fixEmpty = true) String val
final String finalValue = value;
return new URLCheck() {
@Override
protected FormValidation check() throws IOException, ServletException {
protected FormValidation check() throws IOException {
try {
if (findText(open(new URL(finalValue)), "FishEye")) {
return FormValidation.ok();
} else {
return FormValidation.error("This is a valid URL but it doesn't look like FishEye");
}
} catch (IOException e) {
return handleIOException(finalValue, e);
if (e.getMessage().equals(finalValue)) {
return FormValidation.error("Unable to connect " + finalValue, e);
} else {
return FormValidation.error(e.getMessage(), e);

Check warning on line 122 in src/main/java/hudson/plugins/git/browser/FisheyeGitRepositoryBrowser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 119-122 are not covered by tests
}
}
}
}.check();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public FormValidation doCheckRepoUrl(@AncestorInPath Item project, @QueryParamet
return FormValidation.error(Messages.invalidUrl());
}
return new URLCheck() {
protected FormValidation check() throws IOException, ServletException {
protected FormValidation check() throws IOException {
String v = cleanUrl;
if (!v.endsWith("/")) {
v += '/';
Expand All @@ -115,7 +115,11 @@ protected FormValidation check() throws IOException, ServletException {
return FormValidation.error("This is a valid URL but it doesn't look like Gitblit");
}
} catch (IOException e) {
return handleIOException(v, e);
if (e.getMessage().equals(v)) {
return FormValidation.error("Unable to connect " + v, e);
} else {
return FormValidation.error(e.getMessage(), e);

Check warning on line 121 in src/main/java/hudson/plugins/git/browser/GitBlitRepositoryBrowser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 118-121 are not covered by tests
}
}
}
}.check();
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/hudson/plugins/git/browser/Gitiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public FormValidation doCheckRepoUrl(@AncestorInPath Item project, @QueryParamet
return FormValidation.error(Messages.invalidUrl());
}
return new URLCheck() {
protected FormValidation check() throws IOException, ServletException {
protected FormValidation check() throws IOException {
String v = cleanUrl;
if (!v.endsWith("/"))
v += '/';
Expand All @@ -101,7 +101,11 @@ protected FormValidation check() throws IOException, ServletException {
return FormValidation.error("This is a valid URL but it doesn't look like Gitiles");
}
} catch (IOException e) {
return handleIOException(v, e);
if (e.getMessage().equals(v)) {
return FormValidation.error("Unable to connect " + v, e);
} else {
return FormValidation.error(e.getMessage(), e);

Check warning on line 107 in src/main/java/hudson/plugins/git/browser/Gitiles.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 104-107 are not covered by tests
}
}
}
}.check();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,19 @@ public FormValidation doCheckRepoUrl(@QueryParameter(fixEmpty = true) String val
final String finalValue = value;
return new FormValidation.URLCheck() {
@Override
protected FormValidation check() throws IOException, ServletException {
protected FormValidation check() throws IOException {
try {
if (findText(open(new URL(finalValue)), "icrosoft")) {
return FormValidation.ok();
} else {
return FormValidation.error("This is a valid URL but it doesn't look like a Microsoft server");
}
} catch (IOException e) {
return handleIOException(finalValue, e);
if (e.getMessage().equals(finalValue)) {
return FormValidation.error("Unable to connect " + finalValue, e);
} else {
return FormValidation.error(e.getMessage(), e);

Check warning on line 154 in src/main/java/hudson/plugins/git/browser/TFS2013GitRepositoryBrowser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 151-154 are not covered by tests
}
}
}
}.check();
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/hudson/plugins/git/browser/ViewGitWeb.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public FormValidation doCheckRepoUrl(@AncestorInPath Item project, @QueryParamet
return FormValidation.error(Messages.invalidUrl());
}
return new URLCheck() {
protected FormValidation check() throws IOException, ServletException {
protected FormValidation check() throws IOException {
String v = cleanUrl;
if (!v.endsWith("/"))
v += '/';
Expand All @@ -119,7 +119,11 @@ protected FormValidation check() throws IOException, ServletException {
return FormValidation.error("This is a valid URL but it doesn't look like ViewGit");
}
} catch (IOException e) {
return handleIOException(v, e);
if (e.getMessage().equals(v)) {
return FormValidation.error("Unable to connect " + v, e);
} else {
return FormValidation.error(e.getMessage(), e);

Check warning on line 125 in src/main/java/hudson/plugins/git/browser/ViewGitWeb.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 122-125 are not covered by tests
}
}
}
}.check();
Expand Down

0 comments on commit 1c84367

Please sign in to comment.