~ubuntu-branches/ubuntu/saucy/jenkins/saucy-proposed

« back to all changes in this revision

Viewing changes to core/src/main/java/jenkins/model/JenkinsLocationConfiguration.java

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-13 12:35:19 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20130813123519-tizgfxcr70trl7r0
Tags: 1.509.2+dfsg-1
* New upstream release (Closes: #706725):
  - d/control: Update versioned BD's:
    * jenkins-executable-war >= 1.28.
    * jenkins-instance-identity >= 1.3.
    * libjenkins-remoting-java >= 2.23.
    * libjenkins-winstone-java >= 0.9.10-jenkins-44.
    * libstapler-java >= 1.207.
    * libjenkins-json-java >= 2.4-jenkins-1.
    * libstapler-adjunct-timeline-java >= 1.4.
    * libstapler-adjunct-codemirror-java >= 1.2.
    * libmaven-hpi-plugin-java >= 1.93.
    * libjenkins-xstream-java >= 1.4.4-jenkins-3.
  - d/maven.rules: Map to older version of animal-sniffer-maven-plugin.
  - Add patch for compatibility with guava >= 0.14.
  - Add patch to exclude asm4 dependency via jnr-posix.
  - Fixes the following security vulnerabilities:
    CVE-2013-2034, CVE-2013-2033, CVE-2013-2034, CVE-2013-1808
* d/patches/*: Switch to using git patch-queue for managing patches.
* De-duplicate jars between libjenkins-java and jenkins-external-job-monitor
  (Closes: #701163):
  - d/control: Add dependency between jenkins-external-job-monitor ->
    libjenkins-java.
  - d/rules: 
    Drop installation of jenkins-core in jenkins-external-job-monitor.
  - d/jenkins-external-job-monitor.{links,install}: Link to jenkins-core
    in /usr/share/java instead of included version.
* Wait longer for jenkins to stop during restarts (Closes: #704848):
  - d/jenkins.init: Re-sync init script from upstream codebase.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package jenkins.model;
 
2
 
 
3
import hudson.Extension;
 
4
import hudson.Util;
 
5
import hudson.XmlFile;
 
6
import hudson.util.FormValidation;
 
7
import hudson.util.XStream2;
 
8
import net.sf.json.JSONObject;
 
9
import org.kohsuke.stapler.QueryParameter;
 
10
import org.kohsuke.stapler.StaplerRequest;
 
11
 
 
12
import javax.mail.internet.AddressException;
 
13
import javax.mail.internet.InternetAddress;
 
14
import java.io.File;
 
15
import java.io.IOException;
 
16
import java.util.logging.Level;
 
17
import java.util.logging.Logger;
 
18
 
 
19
/**
 
20
 * Stores the location of Jenkins (e-mail address and the HTTP URL.)
 
21
 *
 
22
 * @author Kohsuke Kawaguchi
 
23
 */
 
24
@Extension
 
25
public class JenkinsLocationConfiguration extends GlobalConfiguration {
 
26
    /**
 
27
     * @deprecated
 
28
     */
 
29
    private transient String hudsonUrl;
 
30
    private String adminAddress;
 
31
    private String jenkinsUrl;
 
32
 
 
33
    // just to suppress warnings
 
34
    private transient String charset,useSsl;
 
35
 
 
36
    public static JenkinsLocationConfiguration get() {
 
37
        return GlobalConfiguration.all().get(JenkinsLocationConfiguration.class);
 
38
    }
 
39
 
 
40
    public JenkinsLocationConfiguration() {
 
41
        load();
 
42
    }
 
43
 
 
44
    @Override
 
45
    public synchronized void load() {
 
46
        // for backward compatibility, if we don't have our own data yet, then
 
47
        // load from Mailer.
 
48
        XmlFile file = getConfigFile();
 
49
        if(!file.exists()) {
 
50
            XStream2 xs = new XStream2();
 
51
            xs.addCompatibilityAlias("hudson.tasks.Mailer$DescriptorImpl",JenkinsLocationConfiguration.class);
 
52
            file = new XmlFile(xs,new File(Jenkins.getInstance().getRootDir(),"hudson.tasks.Mailer.xml"));
 
53
            if (file.exists()) {
 
54
                try {
 
55
                    file.unmarshal(this);
 
56
                    if (jenkinsUrl==null)
 
57
                        jenkinsUrl = hudsonUrl;
 
58
                } catch (IOException e) {
 
59
                    LOGGER.log(Level.WARNING, "Failed to load "+file, e);
 
60
                }
 
61
            }
 
62
        } else {
 
63
            super.load();
 
64
        }
 
65
    }
 
66
 
 
67
    public String getAdminAddress() {
 
68
        String v = adminAddress;
 
69
        if(v==null)     v = Messages.Mailer_Address_Not_Configured();
 
70
        return v;
 
71
    }
 
72
 
 
73
    public void setAdminAddress(String adminAddress) {
 
74
        if(adminAddress.startsWith("\"") && adminAddress.endsWith("\"")) {
 
75
            // some users apparently quote the whole thing. Don't konw why
 
76
            // anyone does this, but it's a machine's job to forgive human mistake
 
77
            adminAddress = adminAddress.substring(1,adminAddress.length()-1);
 
78
        }
 
79
        this.adminAddress = adminAddress;
 
80
        save();
 
81
    }
 
82
 
 
83
    public String getUrl() {
 
84
        return jenkinsUrl;
 
85
    }
 
86
 
 
87
    public void setUrl(String hudsonUrl) {
 
88
        String url = Util.nullify(hudsonUrl);
 
89
        if(url!=null && !url.endsWith("/"))
 
90
            url += '/';
 
91
        this.jenkinsUrl = url;
 
92
        save();
 
93
    }
 
94
 
 
95
    @Override
 
96
    public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
 
97
        req.bindJSON(this,json);
 
98
        return true;
 
99
    }
 
100
 
 
101
    /**
 
102
     * Checks the URL in <tt>global.jelly</tt>
 
103
     */
 
104
    public FormValidation doCheckUrl(@QueryParameter String value) {
 
105
        if(value.startsWith("http://localhost"))
 
106
            return FormValidation.warning(Messages.Mailer_Localhost_Error());
 
107
        return FormValidation.ok();
 
108
    }
 
109
 
 
110
    public FormValidation doCheckAdminAddress(@QueryParameter String value) {
 
111
        try {
 
112
            new InternetAddress(value);
 
113
            return FormValidation.ok();
 
114
        } catch (AddressException e) {
 
115
            return FormValidation.error(e.getMessage());
 
116
        }
 
117
    }
 
118
 
 
119
    private static final Logger LOGGER = Logger.getLogger(JenkinsLocationConfiguration.class.getName());
 
120
}