Skip to content
Permalink
Browse files

Update Repository Browser for use with Pipeline.

May fix the following: JENKINS-43069 JENKINS-37094
  • Loading branch information...
p4paul committed Jun 13, 2017
1 parent 61bcb3d commit dc460806d1b78d5766aefb2b7514f981c0a43a03
@@ -70,7 +70,6 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -246,9 +245,6 @@ public String getKey() {
try {
ConnectionHelper connection = new ConnectionHelper(credentials, null);
return new SwarmBrowser(connection.getSwarm());
} catch (MalformedURLException e) {
logger.info("Unable to guess repository browser.");
return null;
} catch (P4JavaException e) {
logger.info("Unable to access Perforce Property.");
return null;
@@ -15,7 +15,6 @@

import javax.servlet.ServletException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Pattern;

@@ -32,17 +31,23 @@
* This is the root 'module' of the FishEye repository. It is a path that is
* trimmed from the beginning of depot paths for files.
*/
public final String rootModule;
private final String rootModule;

public String getRootModule() {
if (rootModule == null)
return "";
return rootModule;
}

@DataBoundConstructor
public FishEyeBrowser(String url, String rootModule) throws MalformedURLException {
public FishEyeBrowser(String url, String rootModule) {
super(url);
this.rootModule = trimHeadSlash(trimHeadSlash(rootModule));
}

@Override
public URL getChangeSetLink(P4ChangeEntry changeSet) throws IOException {
return new URL(getUrl(), "../../changelog/" + getProjectName() + "/?cs="
return new URL(getSafeUrl(), "../../changelog/" + getProjectName() + "/?cs="
+ changeSet.getId());
}

@@ -54,15 +59,15 @@ public URL getDiffLink(P4AffectedFile file, String change) throws Exception {
if (change == null || change.isEmpty()) {
return null;
}
return new URL(getUrl(), getRelativeFilename(file)
+ new QueryBuilder(getUrl().getQuery()).add("r1=").add(
return new URL(getSafeUrl(), getRelativeFilename(file)
+ new QueryBuilder(getSafeUrl().getQuery()).add("r1=").add(
"r2=" + change));
}

@Override
public URL getFileLink(P4AffectedFile file) throws Exception {
return new URL(getUrl(), getRelativeFilename(file)
+ new QueryBuilder(getUrl().getQuery()));
return new URL(getSafeUrl(), getRelativeFilename(file)
+ new QueryBuilder(getSafeUrl().getQuery()));
}

@Override
@@ -83,20 +88,14 @@ private String getRelativeFilename(P4AffectedFile file) {
* Pick up "FOOBAR" from "http://site/browse/FOOBAR/"
*/
private String getProjectName() {
String p = getUrl().getPath();
String p = getSafeUrl().getPath();
if (p.endsWith("/"))
p = p.substring(0, p.length() - 1);

int idx = p.lastIndexOf('/');
return p.substring(idx + 1);
}

private String getRootModule() {
if (rootModule == null)
return "";
return rootModule;
}

@Extension
public static class DescriptorImpl extends Descriptor<RepositoryBrowser<?>> {

@@ -126,13 +125,8 @@ public FormValidation doCheck(@QueryParameter final String value)
}

@Override
public FishEyeBrowser newInstance(StaplerRequest req, JSONObject formData)
throws FormException {
FishEyeBrowser browser = null;
if (req != null) {
browser = req.bindParameters(FishEyeBrowser.class, "fisheye.");
}
return browser;
public FishEyeBrowser newInstance(StaplerRequest req, JSONObject jsonObject) throws FormException {
return req.bindJSON(FishEyeBrowser.class, jsonObject);
}
}
}
@@ -5,13 +5,14 @@
import hudson.model.Descriptor;
import hudson.scm.RepositoryBrowser;
import hudson.util.FormValidation;
import net.sf.json.JSONObject;
import org.jenkinsci.plugins.p4.changes.P4AffectedFile;
import org.jenkinsci.plugins.p4.changes.P4ChangeEntry;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

@@ -28,15 +29,23 @@
* The Perforce depot path for the 'project', e.g.
* <tt>//depot/core/main</tt>
*/
public final String depotPath;
private final String depotPath;

public String getDepotPath() {
return depotPath;
}

/**
* The name of the 'project' in OpenGrok, e.g. <tt>core</tt>
*/
public final String projectName;
private final String projectName;

public String getProjectName() {
return projectName;
}

@DataBoundConstructor
public OpenGrokBrowser(String url, String depotPath, String projectName) throws MalformedURLException {
public OpenGrokBrowser(String url, String depotPath, String projectName) {
super(url);
this.depotPath = depotPath;
this.projectName = projectName;
@@ -54,13 +63,13 @@ public URL getDiffLink(P4AffectedFile file, String change) throws Exception {
String r1 = "r1=" + URLEncoder.encode(path + "#" + (rev - 1), "UTF-8");
String r2 = "r2=" + URLEncoder.encode(path + "#" + rev, "UTF-8");

return new URL(getUrl(), "source/diff/" + projectName + "/build.properties?"
return new URL(getSafeUrl(), "source/diff/" + projectName + "/build.properties?"
+ r2 + "&" + r1 + getRelativeFilename(file));
}

@Override
public URL getFileLink(P4AffectedFile file) throws Exception {
return new URL(getUrl(), "source/xref/" + projectName + "/"
return new URL(getSafeUrl(), "source/xref/" + projectName + "/"
+ getRelativeFilename(file));
}

@@ -103,5 +112,10 @@ public FormValidation doCheck(@QueryParameter final String value) {
}
return FormValidation.ok();
}

@Override
public OpenGrokBrowser newInstance(StaplerRequest req, JSONObject jsonObject) throws FormException {
return req.bindJSON(OpenGrokBrowser.class, jsonObject);
}
}
}
@@ -11,16 +11,25 @@

private static final long serialVersionUID = 1L;

private final URL url;
private String url;

P4Browser(String url) throws MalformedURLException {
this.url = normalizeToEndWithSlash(new URL(url));
public P4Browser(String url) {
this.url = url;
}

public URL getUrl() {
public final String getUrl() {
return url;
}

public URL getSafeUrl() {
try {
URL safe = normalizeToEndWithSlash(new URL(url));
return safe;
} catch (MalformedURLException e) {
return null;
}
}

/**
* Determines the link to the diff between the version.
*
@@ -14,7 +14,6 @@

import javax.servlet.ServletException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

public class P4WebBrowser extends P4Browser {
@@ -29,17 +28,17 @@
public final String p4LabelEnd = "?ac=16"; // label content screen

@DataBoundConstructor
public P4WebBrowser(String url) throws MalformedURLException {
public P4WebBrowser(String url) {
super(url);
}

@Override
public URL getChangeSetLink(P4ChangeEntry changeSet) throws IOException {
return new URL(getUrl().toString() + changeSet.getId() + p4ChangeEnd);
return new URL(getSafeUrl().toString() + changeSet.getId() + p4ChangeEnd);
}

public URL getLabelSetLink(P4ChangeEntry changeSet) throws IOException {
return new URL(getUrl().toString() + changeSet.getId() + p4LabelEnd);
return new URL(getSafeUrl().toString() + changeSet.getId() + p4LabelEnd);
}

@Override
@@ -54,18 +53,18 @@ public URL getDiffLink(P4AffectedFile file, String change) throws Exception {
return null;
}

return new URL(getUrl().toString() + file.getPath() + p4DiffEnd
return new URL(getSafeUrl().toString() + file.getPath() + p4DiffEnd
+ "&rev1=" + (rev - 1) + "&rev2=" + (rev));
}

@Override
public URL getFileLink(P4AffectedFile file) throws Exception {
return new URL(getUrl().toString() + file.getPath() + p4FileEnd);
return new URL(getSafeUrl().toString() + file.getPath() + p4FileEnd);
}

@Override
public URL getJobLink(String job) throws Exception {
return new URL(getUrl().toString() + job + p4JobEnd);
return new URL(getSafeUrl().toString() + job + p4JobEnd);
}

@Extension
@@ -91,13 +90,8 @@ public FormValidation doCheck(@QueryParameter final String value)
}

@Override
public P4WebBrowser newInstance(StaplerRequest req, JSONObject formData)
throws FormException {
P4WebBrowser browser = null;
if (req != null) {
browser = req.bindParameters(P4WebBrowser.class, "p4web.");
}
return browser;
public P4WebBrowser newInstance(StaplerRequest req, JSONObject jsonObject) throws FormException {
return req.bindJSON(P4WebBrowser.class, jsonObject);
}
}
}
@@ -14,25 +14,24 @@

import javax.servlet.ServletException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

public class SwarmBrowser extends P4Browser {

private static final long serialVersionUID = 1L;

@DataBoundConstructor
public SwarmBrowser(String url) throws MalformedURLException {
public SwarmBrowser(String url) {
super(url);
}

@Override
public URL getChangeSetLink(P4ChangeEntry changeSet) throws IOException {
return new URL(getUrl() + "change/" + changeSet.getId());
return new URL(getSafeUrl() + "change/" + changeSet.getId());
}

public URL getLabelSetLink(P4ChangeEntry changeSet) throws IOException {
return new URL(getUrl() + "label/" + changeSet.getId());
return new URL(getSafeUrl() + "label/" + changeSet.getId());
}

@Override
@@ -47,12 +46,12 @@ public URL getFileLink(P4AffectedFile file) throws Exception {
String path = file.getPath();
path = path.replace("//", "files/");
String rev = "?v=" + r;
return new URL(getUrl() + path + rev);
return new URL(getSafeUrl() + path + rev);
}

@Override
public URL getJobLink(String job) throws Exception {
return new URL(getUrl() + "jobs/" + job);
return new URL(getSafeUrl() + "jobs/" + job);
}

@Extension
@@ -76,12 +75,8 @@ public FormValidation doCheck(@QueryParameter final String value) throws IOExcep
}

@Override
public SwarmBrowser newInstance(StaplerRequest req, JSONObject formData) throws FormException {
SwarmBrowser browser = null;
if (req != null) {
browser = req.bindParameters(SwarmBrowser.class, "swarm.");
}
return browser;
public SwarmBrowser newInstance(StaplerRequest req, JSONObject jsonObject) throws FormException {
return req.bindJSON(SwarmBrowser.class, jsonObject);
}
}
}
@@ -1,7 +1,7 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<f:entry title="URL" field="url">
<f:entry title="${%URL}" field="url">
<f:textbox />
</f:entry>

@@ -1,7 +1,7 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<f:entry title="URL" field="url">
<f:entry title="${%URL}" field="url">
<f:textbox />
</f:entry>

@@ -1,8 +1,8 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<f:entry title="URL" field="url">
<f:textbox />
</f:entry>
<f:entry title="${%URL}" field="url">
<f:textbox />
</f:entry>

</j:jelly>
@@ -1,7 +1,7 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<f:entry title="URL" field="url">
<f:entry title="${%URL}" field="url">
<f:textbox />
</f:entry>

@@ -1,6 +1,6 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<j:set var="browser" value="${it.build.parent.scm.effectiveBrowser}"/>
<j:set var="browser" value="${it.browser}"/>
<j:choose>
<j:when test="${it.emptySet}">
No changes from last build.

0 comments on commit dc46080

Please sign in to comment.
You can’t perform that action at this time.