All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hudson.plugins.git.Revision Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 *
 * Copyright (c) 2011 Oracle Corporation.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *
 * Andrew Bayer, Anton Kozak, Nikita Levyankov
 *
 *******************************************************************************/

package hudson.plugins.git;

import java.util.ArrayList;
import java.util.Collection;
import org.eclipse.jgit.lib.ObjectId;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

/**
 * A Revision is a SHA1 in the object tree, and the collection of branches
 * that share this ID. Unlike other SCMs, git can have >1 branches point
 * at the _same_ commit.
 *
 * @author magnayn
 */
@ExportedBean(defaultVisibility = 999)
public class Revision implements java.io.Serializable, Cloneable {
    private static final long serialVersionUID = -7203898556389073882L;

    ObjectId sha1;
    Collection branches;

    public Revision(ObjectId sha1) {
        this.sha1 = sha1;
        this.branches = new ArrayList();
    }

    public Revision(ObjectId sha1, Collection branches) {
        this.sha1 = sha1;
        this.branches = branches;
    }

    public ObjectId getSha1() {
        return sha1;
    }

    @Exported(name = "SHA1")
    public String getSha1String() {
        return sha1 == null ? "" : sha1.name();
    }

    public void setSha1(ObjectId sha1) {
        this.sha1 = sha1;
    }

    @Exported(name = "branch")
    public Collection getBranches() {
        return branches;
    }

    public void setBranches(Collection branches) {
        this.branches = branches;
    }

    public boolean containsBranchName(String name) {
        for (Branch b : branches) {
            if (b.getName().equals(name)) {
                return true;
            }
        }
        return false;
    }

    public String toString() {
        String s = "Revision " + sha1.name() + " (";
        for (Branch br : branches) {
            s += br.getName() + ", ";
        }
        if (s.endsWith(", ")) {
            s = s.substring(0, s.length() - 2);
        }
        s += ")";

        return s;
    }

    @Override
    public Revision clone() {
        Revision clone;
        try {
            clone = (Revision) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException("Error cloning Revision", e);
        }
        clone.branches = new ArrayList(branches);
        return clone;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy