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

hudson.plugins.jobConfigHistory.JobConfigHistoryProjectAction Maven / Gradle / Ivy

There is a newer version: 1.9
Show newest version
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 getConfigs() throws IOException {
        checkConfigurePermission();
        final ArrayList configs = new ArrayList();
        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);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy