1 /* 2 * Copyright 2012 smartics, Kronseder & Reiner GmbH 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package de.smartics.ci.maven; 17 18 import de.smartics.ci.comm.CiController; 19 import de.smartics.ci.comm.command.CommandException; 20 import de.smartics.ci.comm.command.CommandResult; 21 import de.smartics.ci.comm.command.CommandResult.HttpStatus; 22 23 /** 24 * Apply (create or update) job hudson ci mojo. 25 * 26 * @goal applyJobs 27 * @requiresProject 28 * @description Applies (create or update) a job within a running hudson server 29 * by uploading a config.xml. 30 */ 31 public class ApplyJobHudsonCiMojo extends AbstractConfigChoiceHudsonCiMojo 32 { 33 // ********************************* Fields ********************************* 34 35 // --- constants ------------------------------------------------------------ 36 37 // --- members -------------------------------------------------------------- 38 39 // ****************************** Initializer ******************************* 40 41 // ****************************** Constructors ****************************** 42 43 // ****************************** Inner Classes ***************************** 44 45 // ********************************* Methods ******************************** 46 47 // --- init ----------------------------------------------------------------- 48 49 // --- get&set -------------------------------------------------------------- 50 51 // --- business ------------------------------------------------------------- 52 53 /** 54 * {@inheritDoc} 55 * 56 * @throws CommandException 57 */ 58 public final void executeCommand(final String jobName, 59 final String jobConfigString, final CiController controller) 60 throws CommandException 61 { 62 applyJob(jobConfigString, controller, jobName); 63 } 64 65 private void applyJob(final String configString, 66 final CiController controller, final String jobName) 67 throws CommandException 68 { 69 logInfo("Starting to apply job: " + jobName); 70 final CommandResult<?> result = 71 controller.checkStatusJob(jobName, null, null); 72 73 if (HttpStatus.OK == result.getCode()) 74 { 75 controller.updateJob(jobName, configString); 76 } 77 else 78 { 79 controller.createJob(jobName, configString); 80 } 81 82 logInfo("Job: " + jobName + " applied"); 83 84 } 85 // --- object basics -------------------------------------------------------- 86 87 }