类hudson.model.Hudson源码实例Demo

下面列出了怎么用hudson.model.Hudson的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: blueocean-plugin   文件: ProfileApiTest.java
@Test
public void shouldFailForAnonymousRead() throws IOException {
    HudsonPrivateSecurityRealm realm = new HudsonPrivateSecurityRealm(false);
    realm.createAccount("alice","alice");
    j.jenkins.setSecurityRealm(realm);

    GlobalMatrixAuthorizationStrategy as = new GlobalMatrixAuthorizationStrategy();
    j.jenkins.setAuthorizationStrategy(as);
    as.add(Hudson.READ,"alice");

    Map resp = new RequestBuilder(baseUrl)
            .status(403)
            .get("/users/")
            .build(Map.class);
    assertEquals(403, resp.get("code"));
}
 
源代码2 项目: blueocean-plugin   文件: ProfileApiTest.java
@Test
public void shouldSucceedForAnonymousRead() throws IOException {
    HudsonPrivateSecurityRealm realm = new HudsonPrivateSecurityRealm(false);
    realm.createAccount("alice","alice");
    j.jenkins.setSecurityRealm(realm);

    GlobalMatrixAuthorizationStrategy as = new GlobalMatrixAuthorizationStrategy();
    j.jenkins.setAuthorizationStrategy(as);
    as.add(Hudson.READ,"anonymous");

    List resp = new RequestBuilder(baseUrl)
            .status(200)
            .get("/users/")
            .build(List.class);
    assertEquals(1, resp.size());
}
 
源代码3 项目: blueocean-plugin   文件: ProfileApiTest.java
@Test
public void shouldFailForUnauthorizedUser() throws IOException, UnirestException {
    HudsonPrivateSecurityRealm realm = new HudsonPrivateSecurityRealm(false);
    realm.createAccount("alice","alice");
    realm.createAccount("bob","bob");
    j.jenkins.setSecurityRealm(realm);

    GlobalMatrixAuthorizationStrategy as = new GlobalMatrixAuthorizationStrategy();
    j.jenkins.setAuthorizationStrategy(as);
    as.add(Hudson.READ,"alice");

    Map resp = new RequestBuilder(baseUrl)
            .status(403)
            .auth("bob", "bob")
            .get("/users/")
            .build(Map.class);
    assertEquals(403, resp.get("code"));
}
 
源代码4 项目: jenkins-test-harness   文件: JmhBenchmarkState.java
private void launchInstance() throws Exception {
    ImmutablePair<Server, ServletContext> results = JenkinsRule._createWebServer(contextPath, localPort::setValue,
            getClass().getClassLoader(), localPort.getValue(), JenkinsRule::_configureUserRealm);

    server = results.left;
    ServletContext webServer = results.right;

    jenkins = new Hudson(temporaryDirectoryAllocator.allocate(), webServer);
    JenkinsRule._configureJenkinsForTest(jenkins);
    JenkinsRule._configureUpdateCenter(jenkins);
    jenkins.getActions().add(this);

    String url = Objects.requireNonNull(getJenkinsURL()).toString();
    Objects.requireNonNull(JenkinsLocationConfiguration.get()).setUrl(url);
    LOGGER.log(Level.INFO, "Running on {0}", url);
}
 
/**
 * {@inheritDoc}
 */
@Override
public String getAvatarImageOf(String size) {
    if (avatar == null) {
        // fall back to the generic github org icon
        String image = avatarIconClassNameImageOf(getAvatarIconClassName(), size);
        return image != null
                ? image
                : (Stapler.getCurrentRequest().getContextPath() + Hudson.RESOURCE_PATH
                        + "/plugin/github-branch-source/images/" + size + "/github-logo.png");
    } else {
        String[] xy = size.split("x");
        if (xy.length == 0) return avatar;
        if (avatar.contains("?")) return avatar + "&s=" + xy[0];
        else return avatar + "?s=" + xy[0];
    }
}
 
@Nonnull
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // used by index.jelly
public Set<Permission> getFolderPermissions() {
    HashSet<PermissionGroup> groups = new HashSet<>(PermissionGroup.getAll());
    groups.remove(PermissionGroup.get(Hudson.class));
    groups.remove(PermissionGroup.get(Computer.class));
    groups.remove(PermissionGroup.get(Permission.class));
    return getSafePermissions(groups);
}
 
@Nonnull
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // used by index.jelly
public Set<Permission> getAgentPermissions() {
    HashSet<PermissionGroup> groups = new HashSet<>(PermissionGroup.getAll());
    groups.remove(PermissionGroup.get(Run.class));
    groups.remove(PermissionGroup.get(SCM.class));
    groups.remove(PermissionGroup.get(View.class));
    groups.remove(PermissionGroup.get(Item.class));
    groups.remove(PermissionGroup.get(Hudson.class));
    groups.remove(PermissionGroup.get(Permission.class));
    return getSafePermissions(groups);
}
 
源代码8 项目: blueocean-plugin   文件: ArtifactsSecurity564.java
/**
 * Uses matrix-auth to provide artifacts permission.
 *
 * If hudson.security.ArtifactsPermission is set then the user must have Run.ARTIFACTS set.
 *
 * @throws Exception
 */
@Issue("SECURITY-564")
@Test
public void testArtifactsWithPermissions() throws Exception {
    String JOB_NAME = "artifactPermissions";
    String artifactPath = "a/b/c";
    HudsonPrivateSecurityRealm realm = new HudsonPrivateSecurityRealm(false);
    realm.createAccount("alice","alice");
    realm.createAccount("bob","bob");
    j.jenkins.setSecurityRealm(realm);

    GlobalMatrixAuthorizationStrategy as = new GlobalMatrixAuthorizationStrategy();
    j.jenkins.setAuthorizationStrategy(as);
    as.add(Hudson.READ,"alice");
    as.add(Item.READ,"alice");
    as.add(Run.ARTIFACTS,"alice");
    as.add(Hudson.READ,"bob");
    as.add(Item.READ,"bob");

    FreeStyleProject p = j.createFreeStyleProject(JOB_NAME);
    p.getBuildersList().add(new ArtifactBuilder(artifactPath, 100));
    p.getPublishersList().add(new ArtifactArchiver("**/*"));
    Run r = p.scheduleBuild2(0).waitForStart();

    r = j.waitForCompletion(r);

    List artifacts = request().authAlice().get("/organizations/jenkins/pipelines/"+JOB_NAME+"/runs/"+r.getId()+"/artifacts").build(List.class);

    Assert.assertEquals(100, artifacts.size());
    Assert.assertEquals(0, ((Map) artifacts.get(0)).get("size"));
    Assert.assertEquals(artifactPath + "/0.txt", ((Map) artifacts.get(0)).get("path"));
    Assert.assertEquals("/job/artifactPermissions/1/artifact/"+ artifactPath +"/0.txt", ((Map) artifacts.get(0)).get("url"));

    List artifactsBob = request().auth("bob", "bob").get("/organizations/jenkins/pipelines/"+JOB_NAME+"/runs/"+r.getId()+"/artifacts").build(List.class);

    Assert.assertEquals(0, artifactsBob.size());
}
 
源代码9 项目: jenkins-test-harness   文件: JenkinsRule.java
/**
 * Creates a new instance of {@link jenkins.model.Jenkins}. If the derived class wants to create it in a different way,
 * you can override it.
 */
protected Hudson newHudson() throws Exception {
    jettyLevel(Level.WARNING);
    ServletContext webServer = createWebServer();
    File home = homeLoader.allocate();
    for (JenkinsRecipe.Runner r : recipes)
        r.decorateHome(this,home);
    try {
        return new Hudson(home, webServer, getPluginManager());
    } catch (InterruptedException x) {
        throw new AssumptionViolatedException("Jenkins startup interrupted", x);
    } finally {
        jettyLevel(Level.INFO);
    }
}
 
@DataBoundConstructor
public EnvDashboardView(final String name, final String envOrder, final String compOrder,
		final String deployHistory) {
	super(name, Hudson.getInstance());
	this.envOrder = envOrder;
	this.compOrder = compOrder;
	this.deployHistory = deployHistory;
}
 
@Override
public Item doCreateItem(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
	return Hudson.getInstance().doCreateItem(req, rsp);
}
 
源代码12 项目: DotCi   文件: OrganizationGravatarIcon.java
public String getImageOf(final String size) {
    return Stapler.getCurrentRequest().getContextPath() + Hudson.RESOURCE_PATH + "/images/" + size + "/folder.png";
}
 
源代码13 项目: DotCi   文件: OrganizationGravatarIcon.java
public Descriptor<OrganizationGravatarIcon> getDescriptor() {
    return Hudson.getInstance().getDescriptorOrDie(getClass());
}
 
源代码14 项目: DotCi   文件: OrganizationGravatarIcon.java
public static DescriptorExtensionList<OrganizationGravatarIcon, DescriptorImpl> all() {
    return Hudson.getInstance().<OrganizationGravatarIcon, DescriptorImpl>getDescriptorList(OrganizationGravatarIcon.class);
}
 
源代码15 项目: DotCi   文件: OrganizationContainer.java
@Override
public TopLevelItemDescriptor getDescriptor() {
    return (DescriptorImpl) Hudson.getInstance().getDescriptorOrDie(getClass());
}
 
源代码16 项目: DotCi   文件: OrganizationContainer.java
public DynamicProject createProject(final Class<DynamicProject> type, final String projectName) throws IOException {
    return type.cast(createProject((TopLevelItemDescriptor) Hudson.getInstance().getDescriptor(type), projectName));
}
 
 类所在包
 同包方法