Search in sources :

Example 6 with AbstractProject

use of hudson.model.AbstractProject 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 7 with AbstractProject

use of hudson.model.AbstractProject 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 8 with AbstractProject

use of hudson.model.AbstractProject 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)

Example 9 with AbstractProject

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

the class MetaProject method find.

public static MetaProject find(final UUID id) {
    checkNotNull(id);
    Job job = JobUuid.find(id);
    if (job instanceof AbstractProject) {
        return new MetaProject((AbstractProject) job);
    }
    return null;
}
Also used : Job(hudson.model.Job) AbstractProject(hudson.model.AbstractProject)

Example 10 with AbstractProject

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

the class FilePath method validateRelativePath.

/**
     * Validates a relative file path from this {@link FilePath}.
     * Requires configure permission on ancestor AbstractProject object in request.
     *
     * @param value
     *      The relative path being validated.
     * @param errorIfNotExist
     *      If true, report an error if the given relative path doesn't exist. Otherwise it's a warning.
     * @param expectingFile
     *      If true, we expect the relative path to point to a file.
     *      Otherwise, the relative path is expected to be pointing to a directory.
     */
public FormValidation validateRelativePath(String value, boolean errorIfNotExist, boolean expectingFile) throws IOException {
    AbstractProject subject = Stapler.getCurrentRequest().findAncestorObject(AbstractProject.class);
    subject.checkPermission(Item.CONFIGURE);
    value = fixEmpty(value);
    // none entered yet, or something is seriously wrong
    if (value == null || (AbstractProject<?, ?>) subject == null)
        return FormValidation.ok();
    // a common mistake is to use wildcard
    if (value.contains("*"))
        return FormValidation.error(Messages.FilePath_validateRelativePath_wildcardNotAllowed());
    try {
        if (// no base directory. can't check
        !exists())
            return FormValidation.ok();
        FilePath path = child(value);
        if (path.exists()) {
            if (expectingFile) {
                if (!path.isDirectory())
                    return FormValidation.ok();
                else
                    return FormValidation.error(Messages.FilePath_validateRelativePath_notFile(value));
            } else {
                if (path.isDirectory())
                    return FormValidation.ok();
                else
                    return FormValidation.error(Messages.FilePath_validateRelativePath_notDirectory(value));
            }
        }
        String msg = expectingFile ? Messages.FilePath_validateRelativePath_noSuchFile(value) : Messages.FilePath_validateRelativePath_noSuchDirectory(value);
        if (errorIfNotExist)
            return FormValidation.error(msg);
        else
            return FormValidation.warning(msg);
    } catch (InterruptedException e) {
        return FormValidation.ok();
    }
}
Also used : AbstractProject(hudson.model.AbstractProject)

Aggregations

AbstractProject (hudson.model.AbstractProject)14 Hudson (hudson.model.Hudson)4 ArrayList (java.util.ArrayList)3 AbstractBuild (hudson.model.AbstractBuild)2 Run (hudson.model.Run)2 Binding (groovy.lang.Binding)1 GroovyShell (groovy.lang.GroovyShell)1 AbortException (hudson.AbortException)1 DependencyRunner (hudson.DependencyRunner)1 ProjectRunnable (hudson.DependencyRunner.ProjectRunnable)1 EnvVars (hudson.EnvVars)1 PermalinkList (hudson.PermalinkList)1 WorkspaceSnapshot (hudson.WorkspaceSnapshot)1 Action (hudson.model.Action)1 UpstreamCause (hudson.model.Cause.UpstreamCause)1 DependencyGraph (hudson.model.DependencyGraph)1 Dependency (hudson.model.DependencyGraph.Dependency)1 Item (hudson.model.Item)1 Job (hudson.model.Job)1 Permalink (hudson.model.PermalinkProjectAction.Permalink)1