Gson gson = new Gson(); Revision revision = new Revision(); HashMap<String, List<HashMap<String, String>>> HM = new HashMap<String, List<HashMap<String, String>>>(); List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>(); HashMap<String, String> HMin = new HashMap<String, String>(); HMin.put("id", "12"); HMin.put("type", "toster"); list.add(HMin); HM.put("mark", list); revision.setRev(HM); revision.setAuth("ololo"); String json = gson.toJson(revision); Revision test = new Gson().fromJson(json, Revision.class); System.out.println(json); System.out.println(revision); System.out.println(test);
private Revision objectId2Revision(String singleBranch, ObjectId sha1) { Revision revision = new Revision(sha1); revision.getBranches().add(new Branch(singleBranch, sha1)); return revision; }
public Revision sortBranchesForRevision(Revision revision, List<BranchSpec> branchOrder, EnvVars env) { ArrayList<Branch> orderedBranches = new ArrayList<>(revision.getBranches().size()); ArrayList<Branch> revisionBranches = new ArrayList<>(revision.getBranches()); for(BranchSpec branchSpec : branchOrder) { for (Iterator<Branch> i = revisionBranches.iterator(); i.hasNext();) { Branch b = i.next(); if (branchSpec.matches(b.getName(), env)) { i.remove(); orderedBranches.add(b); } } } orderedBranches.addAll(revisionBranches); return new Revision(revision.getSha1(), orderedBranches); }
public Revision toRevision(IGitAPI git) { ObjectId sha1 = git.revParse(commit); Revision revision = new Revision(sha1); revision.getBranches().add(new Branch("detached", sha1)); return revision; }
public Revision toRevision(IGitAPI git) { ObjectId sha1 = git.revParse(commit); Revision revision = new Revision(sha1); revision.getBranches().add(new Branch("detached", sha1)); return revision; }
/** * Return a list of "Revisions" - where a revision knows about all the branch names that refer to * a SHA1. * * @return * @throws IOException * @throws GitException */ public Collection<Revision> getAllBranchRevisions() throws GitException, IOException { Map<ObjectId, Revision> revisions = new HashMap<ObjectId, Revision>(); List<Branch> branches = git.getRemoteBranches(); for (Branch b : branches) { Revision r = revisions.get(b.getSHA1()); if (r == null) { r = new Revision(b.getSHA1()); revisions.put(b.getSHA1(), r); } r.getBranches().add(b); } return revisions.values(); }
public Revision getRevisionForSHA1(ObjectId sha1) throws GitException, IOException, InterruptedException { for(Revision revision : getAllBranchRevisions()) { if(revision.getSha1().equals(sha1)) return revision; } return new Revision(sha1); }
/** * Return a list of "Revisions" - where a revision knows about all the branch names that refer to * a SHA1. * * @return * @throws IOException * @throws GitException */ public Collection<Revision> getAllBranchRevisions() throws GitException, IOException { Map<ObjectId, Revision> revisions = new HashMap<ObjectId, Revision>(); List<Branch> branches = git.getRemoteBranches(); for (Branch b : branches) { Revision r = revisions.get(b.getSHA1()); if (r == null) { r = new Revision(b.getSHA1()); revisions.put(b.getSHA1(), r); } r.getBranches().add(b); } return revisions.values(); }
/** * Return a list of "Revisions" - where a revision knows about all the branch names that refer to * a SHA1. * @return list of revisions * @throws IOException on input or output error * @throws GitException on git error * @throws InterruptedException when interrupted */ public Collection<Revision> getAllBranchRevisions() throws GitException, IOException, InterruptedException { Map<ObjectId, Revision> revisions = new HashMap<>(); for (Branch b : git.getRemoteBranches()) { Revision r = revisions.get(b.getSHA1()); if (r == null) { r = new Revision(b.getSHA1()); revisions.put(b.getSHA1(), r); } r.getBranches().add(b); } for (String tag : git.getTagNames(null)) { String tagRef = Constants.R_TAGS + tag; ObjectId objectId = git.revParse(tagRef); Revision r = revisions.get(objectId); if (r == null) { r = new Revision(objectId); revisions.put(objectId, r); } r.getBranches().add(new Branch(tagRef, objectId)); } return revisions.values(); }
public Revision toRevision(GitClient git) throws InterruptedException { if (revision != null) { return revision; } ObjectId sha1 = git.revParse(commit); Revision revision = new Revision(sha1); // Here we do not have any local branches, containing the commit. So... // we are to get all the remote branches, and show them to users, as // they are local final List<Branch> branches = normalizeBranches(git.getBranchesContaining( ObjectId.toString(sha1), true)); revision.getBranches().addAll(branches); return revision; }
public SpecificRevisionBuildChooser(SCMRevisionImpl revision) { ObjectId sha1 = ObjectId.fromString(revision.getHash()); String name = revision.getHead().getName(); this.revision = new Revision(sha1, Collections.singleton(new Branch(name, sha1))); }
Revision revision = new Revision(sha1); revision.getBranches().add(new Branch(refspec, sha1));
Revision revision = new Revision(sha1); revision.getBranches().add(new Branch(singleBranch, sha1)); return Collections.singletonList(revision);
try { ObjectId sha1 = git.revParse(branchSpec); Revision revision = new Revision(sha1); revision.getBranches().add(new Branch("detached", sha1)); verbose(listener,"Will build the detached SHA1 {0}",sha1);
try { ObjectId sha1 = git.revParse(singleBranch); Revision revision = new Revision(sha1); revision.getBranches().add(new Branch("detached", sha1)); verbose(listener, "Will build the detached SHA1 {0}", sha1); Revision revision = new Revision(sha1); revision.getBranches().add(new Branch(singleBranch, sha1)); return Collections.singletonList(revision);
try { ObjectId sha1 = git.revParse(singleBranch); Revision revision = new Revision(sha1); revision.getBranches().add(new Branch("detached", sha1)); verbose(listener, "Will build the detached SHA1 {0}", sha1); Revision revision = new Revision(sha1); revision.getBranches().add(new Branch(singleBranch, sha1)); return Collections.singletonList(revision);
@Override public Build prevBuildForChangelog(String singleBranch, BuildData data, GitClient git, BuildChooserContext context) throws InterruptedException, IOException { if (data != null) { ObjectId sha1 = git.revParse("FETCH_HEAD"); // Now we cheat and add the parent as the last build on the branch, so we can // get the changelog working properly-ish. ObjectId parentSha1 = getFirstParent(sha1, git); Revision parentRev = new Revision(parentSha1); parentRev.getBranches().add(new Branch(singleBranch, parentSha1)); int prevBuildNum = 0; Result r = null; Build lastBuild = data.getLastBuildOfBranch(singleBranch); if (lastBuild != null) { prevBuildNum = lastBuild.getBuildNumber(); r = lastBuild.getBuildResult(); } return new Build(parentRev, prevBuildNum, r); } else { //Hmm no sure what to do here, but the git plugin can handle us returning null here return null; } }
ObjectId mergeRev = git.revParse(Constants.HEAD); listener.getLogger().println("Merge succeeded, producing " + mergeRev.name()); return new Revision(mergeRev, rev.getBranches()); // note that this ensures Build.revision != Build.marked
@Override public Revision decorateRevisionToBuild(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, Revision marked, Revision rev) throws IOException, InterruptedException, GitException { listener.getLogger().println("Merging " + targetBranch.getName() + " commit " + targetBranch.getRevision().getHash() + " into merge-request head commit " + rev.getSha1String()); checkout(scm, build, git, listener, rev); try { git.setAuthor("Jenkins", /* could parse out of JenkinsLocationConfiguration.get().getAdminAddress() but seems overkill */"nobody@nowhere"); git.setCommitter("Jenkins", "nobody@nowhere"); MergeCommand cmd = git.merge().setRevisionToMerge(ObjectId.fromString(targetBranch.getRevision().getHash())); for (GitSCMExtension ext : scm.getExtensions()) { // By default we do a regular merge, allowing it to fast-forward. ext.decorateMergeCommand(scm, build, git, listener, cmd); } cmd.execute(); } catch (GitException e) { // Try to revert merge conflict markers. checkout(scm, build, git, listener, rev); throw e; } build.addAction(new MergeRecord(targetBranch.getRefSpec().destinationRef(targetBranch.getName()), targetBranch.getRevision().getHash())); // does not seem to be used, but just in case ObjectId mergeRev = git.revParse(Constants.HEAD); listener.getLogger().println("Merge succeeded, producing " + mergeRev.name()); return new Revision(mergeRev, rev.getBranches()); // note that this ensures Build.revision != Build.marked }