Package org.jenkinsci.plugins.workflow.cps.global

Source Code of org.jenkinsci.plugins.workflow.cps.global.WorkflowLibRepository

package org.jenkinsci.plugins.workflow.cps.global;

import hudson.Extension;
import hudson.model.RootAction;
import jenkins.model.Jenkins;
import org.eclipse.jgit.lib.Repository;
import org.jenkinsci.plugins.gitserver.FileBackedHttpGitRepository;

import java.io.File;
import java.io.IOException;

/**
* Exposes the workflow libs as a git repository over HTTP.
*
* @author Kohsuke Kawaguchi
*/
@Extension
public class WorkflowLibRepository extends FileBackedHttpGitRepository implements RootAction {
    public WorkflowLibRepository() {
        super(workspace());
    }

    private static File workspace() {
        Jenkins j = Jenkins.getInstance();
        if (j == null) {
            throw new IllegalStateException("Jenkins is not running");
        }
        return new File(j.root, "workflow-libs");
    }

    @Override
    protected void checkPushPermission() {
        Jenkins j = Jenkins.getInstance();
        if (j == null) {
            throw new IllegalStateException("Jenkins is not running");
        }
        j.checkPermission(Jenkins.RUN_SCRIPTS);
    }

    public String getIconFileName() {
        return null;
    }

    public String getDisplayName() {
        return null;
    }

    public String getUrlName() {
        return "workflowLibs.git";
    }

    /**
     * Starts a new repository without initial import, since this directory
     * was never unmanaged. This will create a nice empty repo that people
     * can push into, as opposed to one they have to pull from.
     *
     * This prevents a user mistake like JENKINS-25632.
     */
    @Override
    protected void createInitialRepository(Repository r) throws IOException {
        r.create();
    }
}
TOP

Related Classes of org.jenkinsci.plugins.workflow.cps.global.WorkflowLibRepository

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.