forked from jenkinsci/git-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GitRepositoryBrowser.java
69 lines (58 loc) · 2.04 KB
/
GitRepositoryBrowser.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package hudson.plugins.git.browser;
import hudson.EnvVars;
import hudson.model.Job;
import hudson.model.TaskListener;
import hudson.plugins.git.GitChangeSet;
import hudson.scm.RepositoryBrowser;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import java.io.IOException;
import java.net.URL;
public abstract class GitRepositoryBrowser extends RepositoryBrowser<GitChangeSet> {
private final String url;
@Deprecated
protected GitRepositoryBrowser() {
this(null);
}
protected GitRepositoryBrowser(String url) {
this.url = url;
}
public final URL getUrl() throws IOException {
String u = url;
StaplerRequest req = Stapler.getCurrentRequest();
if (req != null) {
Job job = req.findAncestorObject(Job.class);
if (job != null) {
EnvVars env = null;
try {
env = job.getEnvironment(null, TaskListener.NULL);
} catch (InterruptedException e) {
throw new IOException("Failed to retrieve job environment", e);
}
u = env.expand(url);
}
}
return normalizeToEndWithSlash(new URL(u));
}
/**
* Determines the link to the diff between the version
* in the specified revision of {@link GitChangeSet.Path} to its previous version.
*
* @param path affected file path
* @return
* null if the browser doesn't have any URL for diff.
* @throws IOException
*/
public abstract URL getDiffLink(GitChangeSet.Path path) throws IOException;
/**
* Determines the link to a single file under Git.
* This page should display all the past revisions of this file, etc.
*
* @param path affected file path
* @return
* null if the browser doesn't have any suitable URL.
* @throws IOException
*/
public abstract URL getFileLink(GitChangeSet.Path path) throws IOException;
private static final long serialVersionUID = 1L;
}