Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JobsApi.create gained param 'optionalFolderPath' to create the job at… #11

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/cdancy/jenkins/rest/JenkinsConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class JenkinsConstants {

public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_";
public static final String JENKINS_REST_VARIABLE_ID = "JENKINS_REST_" + JCLOUDS_VARIABLE_ID;

public static final String OPTIONAL_FOLDER_PATH_PARAM = "optionalFolderPath";

protected JenkinsConstants() {
throw new UnsupportedOperationException("Purposefully not implemented");
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/cdancy/jenkins/rest/features/JobsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.cdancy.jenkins.rest.features;

import static com.cdancy.jenkins.rest.JenkinsConstants.OPTIONAL_FOLDER_PATH_PARAM;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -46,10 +47,12 @@
import com.cdancy.jenkins.rest.domain.job.ProgressiveText;
import com.cdancy.jenkins.rest.fallbacks.JenkinsFallbacks;
import com.cdancy.jenkins.rest.filters.JenkinsAuthenticationFilter;
import com.cdancy.jenkins.rest.filters.ScrubNullFolderParam;
import com.cdancy.jenkins.rest.parsers.BuildNumberToInteger;
import com.cdancy.jenkins.rest.parsers.LocationToQueueId;
import com.cdancy.jenkins.rest.parsers.OutputToProgressiveText;
import com.cdancy.jenkins.rest.parsers.RequestStatusParser;
import org.jclouds.javax.annotation.Nullable;

@RequestFilters(JenkinsAuthenticationFilter.class)
@Path("/")
Expand All @@ -71,14 +74,16 @@ BuildInfo buildInfo(@PathParam("name") String jobName,
@PathParam("number") int buildNumber);

@Named("jobs:create")
@Path("/createItem")
@Path("{" + OPTIONAL_FOLDER_PATH_PARAM + "}/createItem")
@Fallback(JenkinsFallbacks.RequestStatusOnError.class)
@RequestFilters(ScrubNullFolderParam.class)
@ResponseParser(RequestStatusParser.class)
@Produces(MediaType.APPLICATION_XML)
@Consumes(MediaType.WILDCARD)
@Payload("{configXML}")
@POST
RequestStatus create(@QueryParam("name") String jobName,
RequestStatus create(@Nullable @PathParam(OPTIONAL_FOLDER_PATH_PARAM) String optionalFolderPath,
@QueryParam("name") String jobName,
@PayloadParam(value = "configXML") String configXML);

@Named("jobs:get-config")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.cdancy.jenkins.rest.filters;

import static com.cdancy.jenkins.rest.JenkinsConstants.OPTIONAL_FOLDER_PATH_PARAM;

import javax.inject.Singleton;

import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter;

@Singleton
public class ScrubNullFolderParam implements HttpRequestFilter {

private static final String SCRUB_NULL_PARAM = "/%7B" + OPTIONAL_FOLDER_PATH_PARAM + "%7D";
private static final String EMPTY_STRING = "";

@Override
public HttpRequest filter(final HttpRequest request) throws HttpException {
final String requestPath = request.getEndpoint().getRawPath().replaceAll(SCRUB_NULL_PARAM, EMPTY_STRING);
return request.toBuilder().fromHttpRequest(request).replacePath(requestPath).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class JobsApiLiveTest extends BaseJenkinsApiLiveTest {
@Test
public void testCreateJob() {
String config = payloadFromResource("/freestyle-project-no-params.xml");
RequestStatus success = api().create("DevTest", config);
RequestStatus success = api().create(null, "DevTest", config);
assertTrue(success.value());
}

Expand Down Expand Up @@ -114,7 +114,7 @@ public void testGetBuildInfo() {
@Test(dependsOnMethods = "testGetBuildInfo")
public void testCreateJobThatAlreadyExists() {
String config = payloadFromResource("/freestyle-project.xml");
RequestStatus success = api().create("DevTest", config);
RequestStatus success = api().create(null, "DevTest", config);
assertFalse(success.value());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void testCreateJob() throws Exception {
JenkinsApi jenkinsApi = api(server.getUrl("/"));
JobsApi api = jenkinsApi.jobsApi();
try {
RequestStatus success = api.create("DevTest", configXML);
RequestStatus success = api.create(null, "DevTest", configXML);
assertNotNull(success);
assertTrue(success.value());
assertTrue(success.errors().isEmpty());
Expand All @@ -145,7 +145,7 @@ public void testCreateJobAlreadyExists() throws Exception {
JenkinsApi jenkinsApi = api(server.getUrl("/"));
JobsApi api = jenkinsApi.jobsApi();
try {
RequestStatus success = api.create("DevTest", configXML);
RequestStatus success = api.create(null, "DevTest", configXML);
assertNotNull(success);
assertFalse(success.value());
assertFalse(success.errors().isEmpty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public class QueueApiLiveTest extends BaseJenkinsApiLiveTest {
@BeforeClass
public void init() {
String config = payloadFromResource("/freestyle-project-sleep-task.xml");
RequestStatus success = api.jobsApi().create("QueueTest", config);
RequestStatus success = api.jobsApi().create(null, "QueueTest", config);
assertTrue(success.value());

config = payloadFromResource("/freestyle-project.xml");
success = api.jobsApi().create("QueueTestSingleParam", config);
success = api.jobsApi().create(null, "QueueTestSingleParam", config);
assertTrue(success.value());

config = payloadFromResource("/freestyle-project-sleep-task-multiple-params.xml");
success = api.jobsApi().create("QueueTestMultipleParams", config);
success = api.jobsApi().create(null, "QueueTestMultipleParams", config);
assertTrue(success.value());
}

Expand Down