Search in sources :

Example 26 with Hudson

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

the class InstallToolCommand method run.

protected int run() throws Exception {
    Hudson h = Hudson.getInstance();
    h.checkPermission(Hudson.READ);
    // where is this build running?
    BuildIDs id = channel.call(new BuildIDs());
    if (!id.isComplete())
        throw new AbortException("This command can be only invoked from a build executing inside Hudson");
    AbstractProject p = Hudson.getInstance().getItemByFullName(id.job, AbstractProject.class);
    if (p == null)
        throw new AbortException("No such job found: " + id.job);
    p.checkPermission(Item.CONFIGURE);
    List<String> toolTypes = new ArrayList<String>();
    for (ToolDescriptor<?> d : ToolInstallation.all()) {
        toolTypes.add(d.getDisplayName());
        if (d.getDisplayName().equals(toolType)) {
            List<String> toolNames = new ArrayList<String>();
            for (ToolInstallation t : d.getInstallations()) {
                toolNames.add(t.getName());
                if (t.getName().equals(toolName))
                    return install(t, id, p);
            }
            // didn't find the right tool name
            error(toolNames, toolName, "name");
        }
    }
    // didn't find the tool type
    error(toolTypes, toolType, "type");
    // will never be here
    throw new AssertionError();
}
Also used : Hudson(hudson.model.Hudson) ArrayList(java.util.ArrayList) ToolInstallation(hudson.tools.ToolInstallation) AbstractProject(hudson.model.AbstractProject) AbortException(hudson.AbortException)

Example 27 with Hudson

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

the class SolarisSMFLifecycle method restart.

/**
     * In SMF managed environment, just commit a suicide and the service will be restarted by SMF.
     */
@Override
public void restart() throws IOException, InterruptedException {
    Hudson h = Hudson.getInstance();
    if (h != null)
        h.cleanUp();
    System.exit(0);
}
Also used : Hudson(hudson.model.Hudson)

Example 28 with Hudson

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

the class UnixLifecycle method restart.

@Override
public void restart() throws IOException, InterruptedException {
    Hudson h = Hudson.getInstance();
    if (h != null)
        h.cleanUp();
    // close all files upon exec, except stdin, stdout, and stderr
    int sz = LIBC.getdtablesize();
    for (int i = 3; i < sz; i++) {
        int flags = LIBC.fcntl(i, F_GETFD);
        if (flags < 0)
            continue;
        LIBC.fcntl(i, F_SETFD, flags | FD_CLOEXEC);
    }
    // exec to self
    LIBC.execv(Daemon.getCurrentExecutable(), new StringArray(args.toArray(new String[args.size()])));
    throw new IOException("Failed to exec " + LIBC.strerror(Native.getLastError()));
}
Also used : StringArray(com.sun.jna.StringArray) Hudson(hudson.model.Hudson) IOException(java.io.IOException)

Example 29 with Hudson

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

the class WorkspaceSnapshotSCM method resolve.

/**
     * Obtains the {@link WorkspaceSnapshot} object that this {@link SCM} points to,
     * or throws {@link ResolvedFailedException} upon failing.
     *
     * @return never null.
     */
public Snapshot resolve() throws ResolvedFailedException {
    Hudson h = Hudson.getInstance();
    AbstractProject<?, ?> job = h.getItemByFullName(jobName, AbstractProject.class);
    if (job == null) {
        if (h.getItemByFullName(jobName) == null) {
            AbstractProject nearest = AbstractProject.findNearest(jobName);
            throw new ResolvedFailedException(Messages.WorkspaceSnapshotSCM_NoSuchJob(jobName, nearest.getFullName()));
        } else
            throw new ResolvedFailedException(Messages.WorkspaceSnapshotSCM_IncorrectJobType(jobName));
    }
    PermalinkList permalinks = job.getPermalinks();
    Permalink p = permalinks.get(permalink);
    if (p == null)
        throw new ResolvedFailedException(Messages.WorkspaceSnapshotSCM_NoSuchPermalink(permalink, jobName));
    AbstractBuild<?, ?> b = (AbstractBuild<?, ?>) p.resolve(job);
    if (b == null)
        throw new ResolvedFailedException(Messages.WorkspaceSnapshotSCM_NoBuild(permalink, jobName));
    WorkspaceSnapshot snapshot = b.getAction(WorkspaceSnapshot.class);
    if (snapshot == null)
        throw new ResolvedFailedException(Messages.WorkspaceSnapshotSCM_NoWorkspace(jobName, permalink));
    return new Snapshot(snapshot, b);
}
Also used : WorkspaceSnapshot(hudson.WorkspaceSnapshot) Permalink(hudson.model.PermalinkProjectAction.Permalink) WorkspaceSnapshot(hudson.WorkspaceSnapshot) PermalinkList(hudson.PermalinkList) AbstractBuild(hudson.model.AbstractBuild) Hudson(hudson.model.Hudson) AbstractProject(hudson.model.AbstractProject)

Example 30 with Hudson

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

the class Trigger method checkTriggers.

public static void checkTriggers(final Calendar cal) {
    Hudson inst = Hudson.getInstance();
    // Are we using synchronous polling?
    SCMTrigger.DescriptorImpl scmd = inst.getDescriptorByType(SCMTrigger.DescriptorImpl.class);
    if (scmd.synchronousPolling) {
        LOGGER.fine("using synchronous polling");
        // Check that previous synchronous polling job is done to prevent piling up too many jobs
        if (previousSynchronousPolling == null || previousSynchronousPolling.isDone()) {
            // Process SCMTriggers in the order of dependencies. Note that the crontab spec expressed per-project is
            // ignored, only the global setting is honored. The polling job is submitted only if the previous job has
            // terminated.
            // FIXME allow to set a global crontab spec
            previousSynchronousPolling = scmd.getExecutor().submit(new DependencyRunner(new ProjectRunnable() {

                public void run(AbstractProject p) {
                    for (Trigger t : (Collection<Trigger>) p.getTriggers().values()) {
                        if (t instanceof SCMTrigger) {
                            LOGGER.fine("synchronously triggering SCMTrigger for project " + t.job.getName());
                            t.run();
                        }
                    }
                }
            }));
        } else {
            LOGGER.fine("synchronous polling has detected unfinished jobs, will not trigger additional jobs.");
        }
    }
    // Process all triggers, except SCMTriggers when synchronousPolling is set
    for (AbstractProject<?, ?> p : inst.getAllItems(AbstractProject.class)) {
        for (Trigger t : p.getTriggers().values()) {
            if (!(t instanceof SCMTrigger && scmd.synchronousPolling)) {
                LOGGER.fine("cron checking " + p.getName());
                if (t.tabs.check(cal)) {
                    LOGGER.config("cron triggered " + p.getName());
                    try {
                        t.run();
                    } catch (Throwable e) {
                        // t.run() is a plugin, and some of them throw RuntimeException and other things.
                        // don't let that cancel the polling activity. report and move on.
                        LOGGER.log(Level.WARNING, t.getClass().getName() + ".run() failed for " + p.getName(), e);
                    }
                }
            }
        }
    }
}
Also used : DependencyRunner(hudson.DependencyRunner) Hudson(hudson.model.Hudson) ProjectRunnable(hudson.DependencyRunner.ProjectRunnable) AbstractProject(hudson.model.AbstractProject)

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