1 package com.proalpha.pds.gitutils.checks;
3 import java.io.IOException;
4 import java.util.ArrayList;
7 import org.eclipse.core.runtime.jobs.Job;
8 import org.eclipse.jface.dialogs.MessageDialog;
9 import org.eclipse.jface.wizard.WizardPage;
10 import org.eclipse.jgit.api.Git;
11 import org.eclipse.jgit.api.errors.GitAPIException;
12 import org.eclipse.jgit.lib.Ref;
13 import org.eclipse.jgit.lib.Repository;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.widgets.Combo;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Display;
18 import org.eclipse.swt.widgets.Label;
21 private Repository repository;
23 private Combo cmb_source;
24 private Combo cmb_target;
25 private List<String> localBranches;
29 this.repository = repository;
31 setTitle(
"Select Branches");
32 setDescription(
"Select the source and target branch for Differeces");
37 public void createControl(Composite parent) {
38 Composite container =
new Composite(parent, SWT.NONE);
39 setControl(container);
41 cmb_source =
new Combo(container, SWT.NONE | SWT.READ_ONLY);
42 cmb_source.setBounds(174, 41, 173, 23);
44 Label lblSourceBranch =
new Label(container, SWT.NONE);
45 lblSourceBranch.setBounds(27, 49, 141, 15);
46 lblSourceBranch.setText(
"Source Branch");
48 cmb_target =
new Combo(container, SWT.NONE | SWT.READ_ONLY);
49 cmb_target.setBounds(173, 70, 174, 23);
51 Label lblTargetBranch =
new Label(container, SWT.NONE);
52 lblTargetBranch.setBounds(27, 78, 141, 15);
53 lblTargetBranch.setText(
"Target Branch");
57 String curBranch = repositoryTools.extendBanchName(repositoryTools.getBranch());
58 String masterBranch = repositoryTools.extendBanchName(repositoryTools.getMasterBranch());
60 localBranches = getBranches();
62 Integer itemcount = 0;
64 for (String branch : localBranches) {
66 cmb_source.add(branch);
67 cmb_target.add(branch);
69 if (curBranch.equals(branch)) {
70 cmb_source.select(itemcount);
73 if (masterBranch.equals(branch)) {
74 cmb_target.select(itemcount);
80 }
catch (IOException | GitAPIException e1) {
86 private List<String> getBranches()
throws IOException, GitAPIException {
88 List<String> allBranches =
new ArrayList<String>();
90 try (Git git =
new Git(repository)) {
92 List<Ref> call = git.branchList().call();
94 for (Ref ref : call) {
95 allBranches.add(ref.getName());
103 public boolean selection_done() {
106 if (cmb_source.getText().length() == 0 || cmb_target.getText().length() == 0) {
107 MessageDialog.openError(Display.getDefault().getActiveShell(),
"branch selection error",
108 "not all branches are selected.");
114 String source_branch = getSingleBranchName(cmb_source.getText());
115 String target_branch = getSingleBranchName(cmb_target.getText());
117 String relativeInputFile = source_branch +
'_' + target_branch +
".inp";
121 String titletxt = String.format(
"get compiler listing between %s and %s", source_branch, target_branch);
124 options.type = CompileType.DIFF;
125 options.commit1 = source_branch;
126 options.commit2 = target_branch;
127 options.compilerInputFileName = relativeInputFile;
129 Job branchDeptCollectorJob =
new CompileJob(titletxt, repositoryTools, options);
130 branchDeptCollectorJob.setUser(
true);
131 branchDeptCollectorJob.schedule();
137 private String getSingleBranchName(String branch) {
139 if (branch.contains(
"/")) {
140 String[] refs = branch.split(
"/");
142 branch = refs[refs.length - 1];