// Path: src/main/java/com/versionone/integration/ciCommon/BuildInfo.java
// public interface BuildInfo {
// 
//     String getProjectName();
//     long getBuildId();
//     Date getStartTime();
//     long getElapsedTime();
// 
//     /**
//      * Defines success of build.
//      *
//      * @return true if build is successful; otherwise - false.
//      */
//     boolean isSuccessful();
// 
//     /**
//      * Defines whether build was manualy forced.
//      *
//      * @return true if build was forced; otherwise - false.
//      */
//     boolean isForced();
// 
//     /**
//      * Check whether build have any VCS changes.
//      *
//      * @return
//      */
//     boolean hasChanges();
// 
//     /**
//      * Gets list of VCS changes included in the build.
//      *
//      * @return Iterable of VCS changes.
//      */
//     Iterable<VcsModification> getChanges();
// 
//     /**
//      * @return url of build results web page.
//      */
//     String getUrl();
// 
//     /**
//      * @return name of build. (may be equals to {@link #getBuildId()})
//      */
//     String getBuildName();
// }
// 
// Path: src/main/java/com/versionone/integration/ciCommon/VcsModification.java
// public interface VcsModification {
// 
//     String getUserName();
// 
//     String getComment();
// 
//     /**
//      * Get modification date.
//      *
//      * @return Date and time the modification occur. Or null.
//      */
//     Date getDate();
// 
//     String getId();
// }


import hudson.model.Action;
import hudson.model.Result;
import hudson.model.AbstractBuild;
import hudson.model.Cause;
import hudson.model.CauseAction;
import hudson.model.Hudson;
import hudson.scm.ChangeLogSet;
import java.io.PrintStream;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.LinkedList;
import java.util.List;
import com.versionone.integration.ciCommon.BuildInfo;
import com.versionone.integration.ciCommon.VcsModification;
package com.versionone.jenkins;




public class JenkinsBuildInfo implements BuildInfo {

    private final AbstractBuild build;
    private final long elapsedTime;
    private final PrintStream logger;

    public JenkinsBuildInfo(AbstractBuild build, PrintStream logger) {
        this.build = build;
        this.logger = logger;
        GregorianCalendar now = new GregorianCalendar();
        elapsedTime = now.getTime().getTime() - build.getTimestamp().getTime().getTime();
    }

    public String getProjectName() {
        return build.getProject().getName();
    }

    public long getBuildId() {
        return build.getProject().getLastBuild().getNumber();
    }

    public Date getStartTime() {
        return build.getTimestamp().getTime();
    }

    public long getElapsedTime() {
        return elapsedTime;
    }

    public boolean isSuccessful() {
        return build.getResult() == Result.SUCCESS;
    }

    public boolean isForced() {
        for (Action action : build.getActions()) {
            if (action instanceof CauseAction) {
                for (Object cause : ((CauseAction) action).getCauses()) {
// Path: src/main/java/com/versionone/integration/ciCommon/BuildInfo.java
// public interface BuildInfo {
// 
//     String getProjectName();
//     long getBuildId();
//     Date getStartTime();
//     long getElapsedTime();
// 
//     /**
//      * Defines success of build.
//      *
//      * @return true if build is successful; otherwise - false.
//      */
//     boolean isSuccessful();
// 
//     /**
//      * Defines whether build was manualy forced.
//      *
//      * @return true if build was forced; otherwise - false.
//      */
//     boolean isForced();
// 
//     /**
//      * Check whether build have any VCS changes.
//      *
//      * @return
//      */
//     boolean hasChanges();
// 
//     /**
//      * Gets list of VCS changes included in the build.
//      *
//      * @return Iterable of VCS changes.
//      */
//     Iterable<VcsModification> getChanges();
// 
//     /**
//      * @return url of build results web page.
//      */
//     String getUrl();
// 
//     /**
//      * @return name of build. (may be equals to {@link #getBuildId()})
//      */
//     String getBuildName();
// }
// 
// Path: src/main/java/com/versionone/integration/ciCommon/VcsModification.java
// public interface VcsModification {
// 
//     String getUserName();
// 
//     String getComment();
// 
//     /**
//      * Get modification date.
//      *
//      * @return Date and time the modification occur. Or null.
//      */
//     Date getDate();
// 
//     String getId();
// }


// Path: src/main/java/com/versionone/jenkins/JenkinsBuildInfo.java
import hudson.model.Action;
import hudson.model.Result;
import hudson.model.AbstractBuild;
import hudson.model.Cause;
import hudson.model.CauseAction;
import hudson.model.Hudson;
import hudson.scm.ChangeLogSet;
import java.io.PrintStream;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.LinkedList;
import java.util.List;
import com.versionone.integration.ciCommon.BuildInfo;
import com.versionone.integration.ciCommon.VcsModification;

package com.versionone.jenkins;




public class JenkinsBuildInfo implements BuildInfo {

    private final AbstractBuild build;
    private final long elapsedTime;
    private final PrintStream logger;

    public JenkinsBuildInfo(AbstractBuild build, PrintStream logger) {
        this.build = build;
        this.logger = logger;
        GregorianCalendar now = new GregorianCalendar();
        elapsedTime = now.getTime().getTime() - build.getTimestamp().getTime().getTime();
    }

    public String getProjectName() {
        return build.getProject().getName();
    }

    public long getBuildId() {
        return build.getProject().getLastBuild().getNumber();
    }

    public Date getStartTime() {
        return build.getTimestamp().getTime();
    }

    public long getElapsedTime() {
        return elapsedTime;
    }

    public boolean isSuccessful() {
        return build.getResult() == Result.SUCCESS;
    }

    public boolean isForced() {
        for (Action action : build.getActions()) {
            if (action instanceof CauseAction) {
                for (Object cause : ((CauseAction) action).getCauses()) {
                    if (cause instanceof Cause.UserCause) {