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

de.dagere.peass.vcs.CommitIterator Maven / Gradle / Ivy

The newest version!
/**
 *     This file is part of PerAn.
 *
 *     PerAn is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     PerAn is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with PerAn.  If not, see .
 */
package de.dagere.peass.vcs;

import java.io.File;
import java.util.List;

import de.dagere.peass.config.ExecutionConfig;
import de.dagere.peass.dependency.analysis.data.CommitDiff;

/**
 * Iterator for VCS, moving always the position of the iterator alongside with the version saved in the folder.
 * @author reichelt
 *
 */
public abstract class CommitIterator {

	protected final File projectFolder;
	protected int commitIndex = 0;

	public CommitIterator(final File projectFolder) {
		this.projectFolder = projectFolder;
	}

	/**
	 * Returns the count of commits
	 * 
	 * @return count of commits
	 */
	public abstract int getSize();
	
	public int getRemainingSize() {
	   return -1;
	}
	
	/**
	 * Returns the current tag
	 * 
	 * @return current tag
	 */
	public abstract String getCommitName();
	
	/**
	 * Returns the predecessor tag
	 * @return
	 */
	public abstract String getPredecessor();

	/**
	 * Whether a next commit is present
	 * @return True, if a next commit is present, false otherwise
	 */
	public abstract boolean hasNextCommit();

	/**
	 * Goes to next commit, also checking out next commit in the folder
	 * @return True for success, false otherwise
	 */
	public abstract boolean goToNextCommit();
	
	/**
	 * Goes to first commit, both in the iterator and the folder
	 * @return True for success, false otherwise
	 */
	public abstract boolean goToFirstCommit();

	/**
	 * Checkout the Commit before the start (if no one is given, just move the iterator and do not change folder state)
	 * @return Whether the 0th commit is not equal to the current commit
	 */
	public abstract boolean goTo0thCommit();

   public boolean goToNamedCommit(String name) {
      goToFirstCommit();
      while (!getCommitName().equals(name) && hasNextCommit()) {
         goToNextCommit();
      }
      return getCommitName().equals(name);
   }
	
   public abstract boolean isPredecessor(String lastRunningCommit);

   public abstract boolean goToPreviousCommit();

   public abstract CommitDiff getChangedClasses(File projectFolder, List genericModules, String lastCommit, ExecutionConfig config);

   public abstract List getCommits();

   public boolean hasPreviousCommit() {
      return commitIndex > 0;
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy