Eclipseplugins
FeatureBranchSettings.java
1 package com.proalpha.pds.gitutils.mylyn;
2 
3 import java.util.List;
4 
5 import org.eclipse.jgit.lib.Repository;
6 import org.eclipse.mylyn.tasks.core.ITask;
7 
8 import com.proalpha.git.util.PaBranchName;
9 import com.proalpha.git.util.PaRepository;
10 
17 public class FeatureBranchSettings {
18 
19  private ITask task;
20  private Repository repository;
21  private String taskEpic = "";
22  private String taskSprint = "";
23  private String taskParent = "";
24  private String targetBranch;
25  private String sourceBranch;
26  private String dbCommit = "";
27  private String artifactsCommit = "";
28  private boolean updateTargetBranch = true;
29  private boolean updateSourceBranch = true;
30  private CheckoutAction checkoutAction = CheckoutAction.LOAD_XML;
31 
32  public CheckoutAction getCheckoutAction() {
33  return checkoutAction;
34  }
35 
36  public void setCheckoutAction(CheckoutAction checkoutAction) {
37  this.checkoutAction = checkoutAction;
38  }
39 
40  public Repository getRepository() {
41  return repository;
42  }
43 
44  public void setRepository(Repository repository) {
45  this.repository = repository;
46  }
47 
48  public boolean isUpdateTargetBranch() {
49  return updateTargetBranch;
50  }
51 
52  public void setUpdateTargetBranch(boolean updateTargetBranch) {
53  this.updateTargetBranch = updateTargetBranch;
54  }
55 
56  public boolean isUpdateSourceBranch() {
57  return updateSourceBranch;
58  }
59 
60  public void setUpdateSourceBranch(boolean updateSourceBranch) {
61  this.updateSourceBranch = updateSourceBranch;
62  }
63 
64  public String getTargetBranch() {
65  return targetBranch;
66  }
67 
68  public void setTargetBranch(String targetBranch) {
69  this.targetBranch = targetBranch;
70  }
71 
72  public String getSourceBranch() {
73  return sourceBranch;
74  }
75 
76  public void setSourceBranch(String sourceBranch) {
77  this.sourceBranch = sourceBranch;
78  }
79 
80  public ITask getTask() {
81  return task;
82  }
83 
84  public void setTask(ITask task) {
85  this.task = task;
86  }
87 
88  public String getTaskEpic() {
89  return taskEpic;
90  }
91 
92  public void setTaskEpic(String taskEpic) {
93  this.taskEpic = taskEpic;
94  }
95 
96  public String getTaskSprint() {
97  return taskSprint;
98  }
99 
100  public void setTaskSprint(String taskSprint) {
101  this.taskSprint = taskSprint;
102  }
103 
104  public String getTaskParent() {
105  return taskParent;
106  }
107 
108  public void setTaskParent(String taskParent) {
109  this.taskParent = taskParent;
110  }
111 
112  public String getDbCommit() {
113  return dbCommit;
114  }
115 
116  public void setDbCommit(String dbCommit) {
117  this.dbCommit = dbCommit;
118  }
119 
120  public String getArtifactsCommit() {
121  return artifactsCommit;
122  }
123 
124  public void setArtifactsCommit(String artifactsCommit) {
125  this.artifactsCommit = artifactsCommit;
126  }
127 
132  public void deriveDefaults() {
135  }
136 
144  List<String> branches = PaRepository.getMasterBranches(this.getRepository());
145 
146  if (!branches.isEmpty()) {
147  // Just load the first found master branch.
148  // We expect that each local repository only has one master branch
149  String version = PaBranchName.getVersion(branches.get(0), this.getRepository());
150  if (version != null) {
151  this.setSourceBranch(version + ".master");
152  return;
153  }
154 
155  } else {
156 
157  // Determine source branch by a code-freeze branch
158  branches = PaRepository.getCodeFreezeBranches(this.getRepository());
159  if (!branches.isEmpty()) {
160  String version = PaBranchName.getVersion(branches.get(0), this.getRepository());
161  if (version != null) {
162  this.setSourceBranch(version);
163  return;
164  }
165  }
166  }
167 
168  // Fallback: Just set name to master
169  this.setSourceBranch("master");
170 
171  }
172 
179  public void deriveTargetBranch(String branchSuffix) {
180  String version = "";
181 
182  List<String> branches = PaRepository.getMasterBranches(this.getRepository());
183  if (branches.isEmpty())
184  // No master available? But possibly a code-freeze branch
185  branches = PaRepository.getCodeFreezeBranches(this.getRepository());
186 
187  if (!branches.isEmpty()) {
188  version = PaBranchName.getVersion(branches.get(0), this.getRepository());
189  if (version != null) {
190  this.setTargetBranch(version + "." + branchSuffix);
191  return;
192  }
193  }
194 
195  // Fallback - just the key of the task
196  this.setTargetBranch(branchSuffix);
197  }
198 
205  this.deriveTargetBranch(task.getTaskKey());
206  }
207 
208 }