package hudson.plugins.jobConfigHistory;
import hudson.XmlFile;
import hudson.model.AbstractProject;
import hudson.security.AccessControlled;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
/**
* @author Stefan Brausch
*/
public class JobConfigHistoryProjectAction extends JobConfigHistoryBaseAction {
/** Our logger. */
private static final Logger LOG = Logger.getLogger(JobConfigHistoryProjectAction.class.getName());
/**
* @param project
* for which configurations should be returned.
*/
public JobConfigHistoryProjectAction(AbstractProject<?, ?> project) {
super();
this.project = project;
}
/** The project. */
private final transient AbstractProject<?, ?> project;
/**
* Returns the configuration history entries for one {@link AbstractProject}.
*
* @return history list for one {@link AbstractProject}.
* @throws IOException
* if {@link JobConfigHistoryConsts#HISTORY_FILE} might not be read or the path might not be urlencoded.
*/
public final List<ConfigInfo> getConfigs() throws IOException {
checkConfigurePermission();
final ArrayList<ConfigInfo> configs = new ArrayList<ConfigInfo>();
final File historyRootDir = getPlugin().getHistoryDir(project.getConfigFile());
if (!historyRootDir.isDirectory()) {
LOG.info(historyRootDir + " is not a directory, assuming that no history exists yet.");
return Collections.emptyList();
}
for (final File historyDir : historyRootDir.listFiles(JobConfigHistory.HISTORY_FILTER)) {
final XmlFile historyXml = new XmlFile(new File(historyDir, JobConfigHistoryConsts.HISTORY_FILE));
final HistoryDescr histDescr = (HistoryDescr) historyXml.read();
final ConfigInfo config = ConfigInfo.create(project, historyDir, histDescr);
configs.add(config);
}
Collections.sort(configs, ConfigInfoComparator.INSTANCE);
return configs;
}
/**
* Returns the project for which we want to see the config history, the config files or the diff.
*
* @return project
*/
public final AbstractProject<?, ?> getProject() {
return project;
}
/**
* {@inheritDoc} Returns the project.
*/
@Override
protected AccessControlled getAccessControlledObject() {
return project;
}
@Override
protected void checkConfigurePermission() {
getAccessControlledObject().checkPermission(project.CONFIGURE);
}
@Override
protected boolean hasConfigurePermission() {
return getAccessControlledObject().hasPermission(project.CONFIGURE);
}
}