Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * The MIT License
   *
   * Copyright (c) 2009, Manufacture Fran├žaise des Pneumatiques Michelin, Romain Seguy
   *
   * Permission is hereby granted, free of charge, to any person obtaining a copy
   * of this software and associated documentation files (the "Software"), to deal
   * in the Software without restriction, including without limitation the rights
   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  * copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
  *
  * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
 
 package com.michelin.cio.hudson.plugins.clearcaseucmbaseline;
 
Defines a new hudson.model.ParameterDefinition to be displayed at the top of the configuration page of hudson.model.AbstractProjects.

For this parameter to actually work, it is mandatory for the hudson.model.AbstractProjects using it to set their SCM to be ClearCaseUcmBaselineSCM. If not set, the build will be aborted (see ClearCaseUcmBaselineParameterValue.createBuildWrapper(hudson.model.AbstractBuild) which does this check).

When used, this parameter will request the user to select a ClearCase UCM baseline at run-time by displaying a drop-down list. See ClearCaseUcmBaselineParameterValue.

This parameter consists in a set of attributes to be set at config-time:

  • The ClearCase UCM PVOB name;
  • The ClearCase UCM VOB name;
  • The ClearCase UCM component name;
  • The ClearCase UCM promotion level (e.g. RELEASED);
  • The ClearCase UCM view to create name.

The following attribute is then asked at run-time:

  • The ClearCase UCM baseline.

Author(s):
Romain Seguy (http://davadoc.deviantart.com)
Version:
1.0
 
 
     public final static String PARAMETER_NAME = "ClearCase UCM baseline";
 
     private final String component;
     private final String pvob;
     private final String viewName;
     private final String vob;
    
The promotion level is optional: If not is set, then the user will be offered with all the baselines of the ClearCase UCM component.
 
     private final String promotionLevel;
 
     public ClearCaseUcmBaselineParameterDefinition(String pvobString vobString componentString promotionLevelString viewName) {
         super(); // we keep the name of the parameter not
                                          // internationalized, it will save many
                                          // issues when updating system settings
         this. = pvob;
         this. = vob;
         this. = component;
         this. = promotionLevel;
         this. = viewName;
     }
 
     // This method is invoked from a GET or POST HTTP request
     @Override
     public ParameterValue createValue(StaplerRequest req) {
        String[] values = req.getParameterValues(getName());
        if(values == null || values.length != 1) {
            // the "ClearCase UCM baseline" parameter is mandatory, the build
            // has to fail if it's not there (we can't assume a default value)
            return null;
        }
        else {
            return new ClearCaseUcmBaselineParameterValue(
                    getName(), getPvob(), getVob(), getComponent(), getPromotionLevel(), getViewName(), values[0]);
        }
    }
    // This method is invoked when the user clicks on the "Build" button of Hudon's GUI
    @Override
    public ParameterValue createValue(StaplerRequest reqJSONObject formData) {
        value.setPvob();
        value.setVob();
        value.setComponent();
        value.setPromotionLevel();
        value.setViewName();
        return value;
    }

    
Returns an array of ClearCase UCM baselines to be displayed in ClearCaseUcmBaselineParameterDefinition/index.jelly (or null if something wrong happens).
    public String[] getBaselines() throws IOExceptionInterruptedException {
        // cleartool lsbl -fmt "%[name]p " -level <promotion level> -component <component>@<vob>
        ArgumentListBuilder cmd = new ArgumentListBuilder();
        cmd.add(PluginImpl.getDescriptor().getCleartoolExe());
        cmd.add("lsbl");
        cmd.add("-fmt");
        cmd.add("%[name]p ");
        if( != null && .length() > 0) {
            cmd.add("-level");
            cmd.add();
        }
        cmd.add("-component");
        cmd.add( + '@' + );
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Hudson.getInstance().createLauncher(.).launch().cmds(cmd).stdout(baos).join();
        String cleartoolOutput = ClearCaseUcmBaselineUtils.processCleartoolOuput(baos);
        baos.close();
        if(cleartoolOutput.toString().contains("cleartool: Error")) {
            return null;
        }
        else {
            return cleartoolOutput.toString().split(" ");
        }
    }
    public String getComponent() {
        return ;
    }
    public String getPromotionLevel() {
        return ;
    }
    public String getPvob() {
        return ;
    }
    public String getViewName() {
        return ;
    }
    public String getVob() {
        return ;
    }
    @Extension
    public static class DescriptorImpl extends ParameterDescriptor {
        public FormValidation doCheckComponent(@QueryParameter String value) {
            if(value == null || value.length() == 0) {
                return FormValidation.error(ResourceBundleHolder.get(ClearCaseUcmBaselineParameterDefinition.class).format("ComponentMustBeSet"));
            }
            return FormValidation.ok();
        }
        public FormValidation doCheckPromotionLevel(@QueryParameter String value) {
            if(value == null || value.length() == 0) {
                return FormValidation.warning(ResourceBundleHolder.get(ClearCaseUcmBaselineParameterDefinition.class).format("PromotionLevelShouldBeSet"));
            }
            return FormValidation.ok();
        }
        public FormValidation doCheckPvob(@QueryParameter String value) {
            if(value == null || value.length() == 0) {
                return FormValidation.error(ResourceBundleHolder.get(ClearCaseUcmBaselineParameterDefinition.class).format("PVOBMustBeSet"));
            }
            return FormValidation.ok();
        }
        public FormValidation doCheckViewName(@QueryParameter String value) {
            if(value == null || value.length() == 0) {
                return FormValidation.error(ResourceBundleHolder.get(ClearCaseUcmBaselineParameterDefinition.class).format("ViewNameMustBeSet"));
            }
            return FormValidation.ok();
        }
        public FormValidation doCheckVob(@QueryParameter String value) {
            if(value == null || value.length() == 0) {
                return FormValidation.error(ResourceBundleHolder.get(ClearCaseUcmBaselineParameterDefinition.class).format("VOBMustBeSet"));
            }
            return FormValidation.ok();
        }
        @Override
        public String getDisplayName() {
            return ResourceBundleHolder.get(ClearCaseUcmBaselineParameterDefinition.class).format("DisplayName");
        }
    }
New to GrepCode? Check out our FAQ X