use of hudson.model.Hudson in project hudson-2.x by hudson.
the class CascadingUtilTest method testBuildExternalProperties.
@Test
@PrepareForTest({ Hudson.class, StaplerRequest.class })
public void testBuildExternalProperties() throws Exception {
Job job = new FreeStyleProjectMock("job");
StaplerRequest req = createMock(StaplerRequest.class);
String javadocArchiverKey = "hudson-tasks-JavadocArchiver";
JSONObject archiver = new JSONObject();
archiver.put("javadoc_dir", "dir");
archiver.put("keep_all", true);
JSONObject json = new JSONObject();
json.put(javadocArchiverKey, archiver);
Hudson hudson = createMock(Hudson.class);
Descriptor<Publisher> javadocDescriptor = new JavadocArchiver.DescriptorImpl();
expect(hudson.getDescriptorOrDie(JavadocArchiver.class)).andReturn(javadocDescriptor);
JavadocArchiver javadocArchiver = new JavadocArchiver("dir", true);
expect(req.bindJSON(JavadocArchiver.class, archiver)).andReturn(javadocArchiver).anyTimes();
List<Descriptor<Publisher>> descriptors = new ArrayList<Descriptor<Publisher>>();
descriptors.add(javadocDescriptor);
mockStatic(Hudson.class);
expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
replay(Hudson.class, hudson, req);
assertNull(CascadingUtil.getExternalProjectProperty(job, javadocArchiverKey).getValue());
CascadingUtil.buildExternalProperties(req, archiver, descriptors, job);
assertNull(CascadingUtil.getExternalProjectProperty(job, javadocArchiverKey).getValue());
CascadingUtil.buildExternalProperties(req, json, descriptors, job);
assertNotNull(CascadingUtil.getExternalProjectProperty(job, javadocArchiverKey).getValue());
verifyAll();
}
use of hudson.model.Hudson in project hudson-2.x by hudson.
the class CascadingUtilTest method testUnlinkProjectFromCascadingParents2.
@Test
@PrepareForTest(Hudson.class)
public void testUnlinkProjectFromCascadingParents2() throws Exception {
FreeStyleProject project1 = new FreeStyleProjectMock("p1");
FreeStyleProjectMock project2 = new FreeStyleProjectMock("p2");
FreeStyleProjectMock project3 = new FreeStyleProjectMock("p3");
project2.setCascadingProject(project1);
CascadingUtil.linkCascadingProjectsToChild(project1, "p2");
project3.setCascadingProject(project2);
CascadingUtil.linkCascadingProjectsToChild(project2, "p3");
List<Job> jobs = new ArrayList<Job>();
jobs.add(project1);
jobs.add(project2);
jobs.add(project3);
Hudson hudson = createMock(Hudson.class);
mockStatic(Hudson.class);
expect(hudson.getAllItems(Job.class)).andReturn(jobs);
expect(Hudson.getInstance()).andReturn(hudson);
replay(Hudson.class, hudson);
CascadingUtil.unlinkProjectFromCascadingParents(project1, "p2");
//Project3 should disappear from project1's children.
assertTrue(project1.getCascadingChildrenNames().isEmpty());
}
use of hudson.model.Hudson in project hudson-2.x by hudson.
the class PluginManager method doProxyConfigure.
public HttpResponse doProxyConfigure(@QueryParameter("proxy.server") String server, @QueryParameter("proxy.port") String port, @QueryParameter("proxy.noProxyFor") String noProxyFor, @QueryParameter("proxy.userName") String userName, @QueryParameter("proxy.password") String password, @QueryParameter("proxy.authNeeded") String authNeeded) throws IOException {
Hudson hudson = Hudson.getInstance();
hudson.checkPermission(Hudson.ADMINISTER);
server = Util.fixEmptyAndTrim(server);
if ((server != null) && !"".equals(server)) {
// If port is not specified assume it is port 80 (usual default for HTTP port)
int portNumber = 80;
if (!"".equals(Util.fixNull(port))) {
portNumber = Integer.parseInt(Util.fixNull(port));
}
boolean proxyAuthNeeded = "on".equals(Util.fixNull(authNeeded));
if (!proxyAuthNeeded) {
userName = "";
password = "";
}
hudson.proxy = new ProxyConfiguration(server, portNumber, Util.fixEmptyAndTrim(noProxyFor), Util.fixEmptyAndTrim(userName), Util.fixEmptyAndTrim(password), "on".equals(Util.fixNull(authNeeded)));
hudson.proxy.save();
} else {
hudson.proxy = null;
ProxyConfiguration.getXmlFile().delete();
}
return new HttpRedirect("advanced");
}
use of hudson.model.Hudson in project hudson-2.x by hudson.
the class Functions method getCrumb.
public static String getCrumb(StaplerRequest req) {
Hudson h = Hudson.getInstance();
CrumbIssuer issuer = h != null ? h.getCrumbIssuer() : null;
return issuer != null ? issuer.getCrumb(req) : "";
}
use of hudson.model.Hudson in project hudson-2.x by hudson.
the class ZFSInstaller method doStart.
/**
* Called from the confirmation screen to actually initiate the migration.
*/
public void doStart(StaplerRequest req, StaplerResponse rsp, @QueryParameter String username, @QueryParameter String password) throws ServletException, IOException {
requirePOST();
Hudson hudson = Hudson.getInstance();
hudson.checkPermission(Hudson.ADMINISTER);
final String datasetName;
ByteArrayOutputStream log = new ByteArrayOutputStream();
StreamTaskListener listener = new StreamTaskListener(log);
try {
datasetName = createZfsFileSystem(listener, username, password);
} catch (Exception e) {
e.printStackTrace(listener.error(e.getMessage()));
if (e instanceof ZFSException) {
ZFSException ze = (ZFSException) e;
if (ze.getCode() == ErrorCode.EZFS_PERM) {
// permission problem. ask the user to give us the root password
req.setAttribute("message", log.toString());
rsp.forward(this, "askRootPassword", req);
return;
}
}
// for other kinds of problems, report and bail out
req.setAttribute("pre", true);
sendError(log.toString(), req, rsp);
return;
}
// file system creation successful, so restart
WebAppController.get().install(new HudsonIsRestarting());
// redirect the user to the manage page
rsp.sendRedirect2(req.getContextPath() + "/manage");
// asynchronously restart, so that we can give a bit of time to the browser to load "restarting..." screen.
new Thread("restart thread") {
@Override
public void run() {
try {
Thread.sleep(5000);
// close all descriptors on exec except stdin,out,err
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);
}
// re-exec with the system property to indicate where to migrate the data to.
// the 2nd phase is implemented in the migrate method.
JavaVMArguments args = JavaVMArguments.current();
args.setSystemProperty(ZFSInstaller.class.getName() + ".migrate", datasetName);
Daemon.selfExec(args);
} catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, "Restart failed", e);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Restart failed", e);
}
}
}.start();
}
Aggregations