Search in sources :

Example 21 with Hudson

use of hudson.model.Hudson in project hudson-2.x by hudson.

the class QueueServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    // static methods
    mockStatic(Hudson.class);
    // final and native
    hudson = mock(Hudson.class);
    MockitoAnnotations.initMocks(this);
    queueService = new QueueServiceImpl(security);
    queueService.setHudson(hudson);
}
Also used : Hudson(hudson.model.Hudson) QueueServiceImpl(org.hudsonci.service.internal.QueueServiceImpl) Before(org.junit.Before)

Example 22 with Hudson

use of hudson.model.Hudson in project hudson-2.x by hudson.

the class UpdateJobCommand method run.

protected int run() throws Exception {
    Hudson h = Hudson.getInstance();
    TopLevelItem item = h.getItem(name);
    if (item == null && !create) {
        stderr.println("Job '" + name + "' does not exist and create is set to false");
        return -1;
    }
    if (item == null) {
        h.checkPermission(Item.CREATE);
        h.createProjectFromXML(name, stdin);
    } else {
        try {
            h.checkPermission(Job.CONFIGURE);
            File rootDirOfJob = new File(new File(h.getRootDir(), "jobs"), name);
            // place it as config.xml
            File configXml = Items.getConfigFile(rootDirOfJob).getFile();
            IOUtils.copy(stdin, configXml);
            item = h.reloadProjectFromDisk(configXml.getParentFile());
        } catch (IOException e) {
            throw e;
        }
    }
    return 0;
}
Also used : Hudson(hudson.model.Hudson) TopLevelItem(hudson.model.TopLevelItem) IOException(java.io.IOException) File(java.io.File)

Example 23 with Hudson

use of hudson.model.Hudson in project hudson-2.x by hudson.

the class AbstractProjectOptionHandler method parseArguments.

@Override
public int parseArguments(Parameters params) throws CmdLineException {
    Hudson h = Hudson.getInstance();
    String src = params.getParameter(0);
    AbstractProject s = h.getItemByFullName(src, AbstractProject.class);
    if (s == null)
        throw new CmdLineException(owner, "No such job '" + src + "' perhaps you meant " + AbstractProject.findNearest(src) + "?");
    setter.addValue(s);
    return 1;
}
Also used : Hudson(hudson.model.Hudson) AbstractProject(hudson.model.AbstractProject) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 24 with Hudson

use of hudson.model.Hudson in project hudson-2.x by hudson.

the class TopLevelItemOptionHandler method parseArguments.

@Override
public int parseArguments(Parameters params) throws CmdLineException {
    Hudson h = Hudson.getInstance();
    String src = params.getParameter(0);
    TopLevelItem s = h.getItem(src);
    if (s == null)
        throw new CmdLineException(owner, "No such job '" + src + "' perhaps you meant " + AbstractProject.findNearest(src) + "?");
    setter.addValue(s);
    return 1;
}
Also used : Hudson(hudson.model.Hudson) TopLevelItem(hudson.model.TopLevelItem) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 25 with Hudson

use of hudson.model.Hudson in project hudson-2.x by hudson.

the class ClientAuthenticationCache method set.

/**
     * Persists the specified authentication.
     */
public void set(Authentication a) throws IOException, InterruptedException {
    Hudson h = Hudson.getInstance();
    // make sure that this security realm is capable of retrieving the authentication by name,
    // as it's not required.
    UserDetails u = h.getSecurityRealm().loadUserByUsername(a.getName());
    props.setProperty(getPropertyKey(), Secret.fromString(u.getUsername()).getEncryptedValue());
    save();
}
Also used : UserDetails(org.acegisecurity.userdetails.UserDetails) Hudson(hudson.model.Hudson)

Aggregations

Hudson (hudson.model.Hudson)43 FreeStyleProjectMock (hudson.model.FreeStyleProjectMock)8 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 Job (hudson.model.Job)7 IOException (java.io.IOException)7 Before (org.junit.Before)7 FreeStyleProject (hudson.model.FreeStyleProject)5 AbstractProject (hudson.model.AbstractProject)4 File (java.io.File)3 Descriptor (hudson.model.Descriptor)2 TopLevelItem (hudson.model.TopLevelItem)2 UpdateSite (hudson.model.UpdateSite)2 CrumbIssuer (hudson.security.csrf.CrumbIssuer)2 Publisher (hudson.tasks.Publisher)2 JSONObject (net.sf.json.JSONObject)2 CmdLineException (org.kohsuke.args4j.CmdLineException)2 StaplerRequest (org.kohsuke.stapler.StaplerRequest)2 Provides (com.google.inject.Provides)1