Package hudson.model

Examples of hudson.model.Hudson


     * 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));
        }
View Full Code Here


* @author Kohsuke Kawaguchi
*/
@Extension
public class TooManyJobsButNoView extends AdministrativeMonitor {
    public boolean isActivated() {
        Hudson h = Hudson.getInstance();
        return h.getViews().size()==1 && h.getItemMap().size()> THRESHOLD;
    }
View Full Code Here

        }
    }

    @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);
View Full Code Here

    /**
     * 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);
    }
View Full Code Here

     * Gets the persisted authentication for this Hudson.
     *
     * @return {@link Hudson#ANONYMOUS} if no such credential is found, or if the stored credential is invalid.
     */
    public Authentication get() {
        Hudson h = Hudson.getInstance();
        Secret userName = Secret.decrypt(props.getProperty(getPropertyKey()));
        if (userName==null) return Hudson.ANONYMOUS; // failed to decrypt
        try {
            UserDetails u = h.getSecurityRealm().loadUserByUsername(userName.toString());
            return new UsernamePasswordAuthenticationToken(u.getUsername(), u.getPassword(), u.getAuthorities());
        } catch (AuthenticationException e) {
            return Hudson.ANONYMOUS;
        } catch (DataAccessException e) {
            return Hudson.ANONYMOUS;
View Full Code Here

    /**
     * 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();
    }
View Full Code Here

    @Option(name="-restart",usage="Restart Hudson upon successful installation")
    public boolean restart;

    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>0name = 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();
        return 0; // all success
    }
View Full Code Here

        super(parser, option, setter);
    }

    @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;
    }
View Full Code Here

        super(parser, option, setter);
    }

    @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;
    }
View Full Code Here

    public String name;
    @Argument(metaVar = "CREATE", usage = "Create the job if needed", index = 1, required = true)
    public Boolean create;

    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;
View Full Code Here

TOP

Related Classes of hudson.model.Hudson

Copyright © 2018 www.massapicom. 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.