forked from Praqma/config-rotator-plugin
/
GitConfigurationComponent.java
107 lines (83 loc) · 2.83 KB
/
GitConfigurationComponent.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package net.praqma.jenkins.configrotator.scm.git;
import hudson.FilePath;
import hudson.model.TaskListener;
import net.praqma.jenkins.configrotator.AbstractConfigurationComponent;
import org.eclipse.jgit.revwalk.RevCommit;
import java.io.IOException;
import java.util.logging.Logger;
public class GitConfigurationComponent extends AbstractConfigurationComponent {
private static Logger logger = Logger.getLogger( GitConfigurationComponent.class.getName() );
private transient RevCommit commit;
private String commitId;
private String name;
private String branch;
private String repository;
private GitConfigurationComponent( String name, String repository, String branch, String commitId, boolean fixed ) {
super( fixed );
this.name = name;
this.repository = repository;
this.branch = branch;
this.commitId = commitId;
}
public GitConfigurationComponent( String name, String repository, String branch, RevCommit commit, boolean fixed ) {
super( fixed );
this.commit = commit;
if( commit != null ) {
this.commitId = commit.getName();
}
this.name = name;
this.branch = branch;
this.repository = repository;
}
public void checkout( FilePath workspace, TaskListener listener ) throws IOException, InterruptedException {
workspace.act( new Checkout( name, branch, commitId ) );
}
public String getBranch() {
return branch;
}
public String getRepository() {
return repository;
}
public String getName() {
return name;
}
public RevCommit getCommit() {
return commit;
}
public void setCommitId( String commitId ) {
this.commitId = commitId;
}
public String getCommitId() {
return commitId;
}
@Override
public String getComponentName() {
return repository;
}
@Override
protected Object clone() {
GitConfigurationComponent gcc = new GitConfigurationComponent( name, repository, branch, commitId, fixed );
return gcc;
}
@Override
public String getFeedId() {
return repository;
}
@Override
public String getFeedName() {
return repository;
}
@Override
public String toString() {
return "GitComponent[" + name + ": " + repository + ", " + branch + ", " + commitId + "]";
}
@Override
public String prettyPrint() {
return name + ": " + repository + ", " + branch + ", " + commitId;
}
@Override
public String toHtml() {
StringBuilder builder = new StringBuilder();
return getBasicHtml( builder, new Element( repository, isChangedLast() ), new Element( branch, isChangedLast() ), new Element( commitId, isChangedLast() ), new Element( fixed+"", isChangedLast() ) );
}
}