Search in sources :

Example 11 with Hudson

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

the class PluginManager method doSiteConfigure.

/**
     * Bare-minimum configuration mechanism to change the update center.
     */
public HttpResponse doSiteConfigure(@QueryParameter String site) throws IOException {
    Hudson hudson = Hudson.getInstance();
    hudson.checkPermission(Hudson.ADMINISTER);
    UpdateCenter uc = hudson.getUpdateCenter();
    PersistedList<UpdateSite> sites = uc.getSites();
    for (UpdateSite s : sites) {
        if (s.getId().equals("default"))
            sites.remove(s);
    }
    sites.add(new UpdateSite("default", site));
    return HttpResponses.redirectToContextRoot();
}
Also used : UpdateCenter(hudson.model.UpdateCenter) Hudson(hudson.model.Hudson) UpdateSite(hudson.model.UpdateSite)

Example 12 with Hudson

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

the class CopyJobCommand method run.

protected int run() throws Exception {
    Hudson h = Hudson.getInstance();
    h.checkPermission(Item.CREATE);
    if (h.getItem(dst) != null) {
        stderr.println("Job '" + dst + "' already exists");
        return -1;
    }
    h.copy(src, dst);
    Job newJob = (Job) Hudson.getInstance().getItem(dst);
    if (forceSave && null != newJob) {
        newJob.save();
    }
    return 0;
}
Also used : Hudson(hudson.model.Hudson) Job(hudson.model.Job)

Example 13 with Hudson

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

the class CreateJobCommand method run.

protected int run() throws Exception {
    Hudson h = Hudson.getInstance();
    h.checkPermission(Item.CREATE);
    if (h.getItem(name) != null) {
        stderr.println("Job '" + name + "' already exists");
        return -1;
    }
    h.createProjectFromXML(name, stdin);
    return 0;
}
Also used : Hudson(hudson.model.Hudson)

Example 14 with Hudson

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

the class InstallPluginCommand method run.

protected int run() throws Exception {
    Hudson h = Hudson.getInstance();
    h.checkPermission(Hudson.ADMINISTER);
    for (String source : sources) {
        // is this a file?
        FilePath f = new FilePath(channel, source);
        if (f.exists()) {
            stdout.println(Messages.InstallPluginCommand_InstallingPluginFromLocalFile(f));
            if (name == null)
                name = f.getBaseName();
            f.copyTo(getTargetFile());
            continue;
        }
        // is this an URL?
        try {
            URL u = new URL(source);
            stdout.println(Messages.InstallPluginCommand_InstallingPluginFromUrl(u));
            if (name == null) {
                name = u.getPath();
                name = name.substring(name.indexOf('/') + 1);
                name = name.substring(name.indexOf('\\') + 1);
                int idx = name.lastIndexOf('.');
                if (idx > 0)
                    name = name.substring(0, idx);
            }
            getTargetFile().copyFrom(u);
            continue;
        } catch (MalformedURLException e) {
        // not an URL
        }
        // is this a plugin the update center?
        UpdateSite.Plugin p = h.getUpdateCenter().getPlugin(source);
        if (p != null) {
            stdout.println(Messages.InstallPluginCommand_InstallingFromUpdateCenter(source));
            p.deploy().get();
            continue;
        }
        stdout.println(Messages.InstallPluginCommand_NotAValidSourceName(source));
        if (!source.contains(".") && !source.contains(":") && !source.contains("/") && !source.contains("\\")) {
            // looks like a short plugin name. Why did we fail to find it in the update center?
            if (h.getUpdateCenter().getSites().isEmpty()) {
                stdout.println(Messages.InstallPluginCommand_NoUpdateCenterDefined());
            } else {
                Set<String> candidates = new HashSet<String>();
                for (UpdateSite s : h.getUpdateCenter().getSites()) {
                    Data dt = s.getData();
                    if (dt == null) {
                        stdout.println(Messages.InstallPluginCommand_NoUpdateDataRetrieved(s.getUrl()));
                    } else {
                        candidates.addAll(dt.plugins.keySet());
                    }
                }
                stdout.println(Messages.InstallPluginCommand_DidYouMean(source, EditDistance.findNearest(source, candidates)));
            }
        }
        return 1;
    }
    if (restart)
        h.restart();
    // all success
    return 0;
}
Also used : FilePath(hudson.FilePath) MalformedURLException(java.net.MalformedURLException) Hudson(hudson.model.Hudson) Data(hudson.model.UpdateSite.Data) UpdateSite(hudson.model.UpdateSite) URL(java.net.URL) HashSet(java.util.HashSet)

Example 15 with Hudson

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

the class DescribableListUtilTest method testConvertToProjectProperties3.

@Test
public void testConvertToProjectProperties3() throws IOException {
    Hudson hudson = createMock(Hudson.class);
    Mailer.DescriptorImpl descriptor = createMock(Mailer.DescriptorImpl.class);
    String mailerName = "hudson-tasks-Mailer";
    expect(descriptor.getJsonSafeClassName()).andReturn(mailerName);
    expect(hudson.getDescriptorOrDie(Mailer.class)).andReturn(descriptor);
    mockStatic(Hudson.class);
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    prepareJob();
    DescribableList<Publisher, Descriptor<Publisher>> list = new DescribableList<Publisher, Descriptor<Publisher>>();
    list.add(new Mailer());
    Map<String, ExternalProjectProperty<Publisher>> map = DescribableListUtil.convertToProjectProperties(list, job);
    assertNotNull(map);
    assertEquals(map.size(), 1);
    assertNotNull(map.get(mailerName));
    assertEquals(map.get(mailerName).getValue().getClass(), Mailer.class);
}
Also used : Hudson(hudson.model.Hudson) ExternalProjectProperty(org.hudsonci.model.project.property.ExternalProjectProperty) Mailer(hudson.tasks.Mailer) Descriptor(hudson.model.Descriptor) Publisher(hudson.tasks.Publisher) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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