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
   * Copyright (c) 2007-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Erik Ramfelt,
   *                          Henrik Lynggaard, Peter Liljenberg, Andrew Bayer
   *
   * 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;
 
 import hudson.Util;
 import java.io.File;
 import java.util.Map;
This class represents the actual hudson.model.ParameterValue for the ClearCaseUcmBaselineParameterDefinition parameter.

This value holds the following information:

  • The ClearCase UCM PVOB name (which is actually defined at config-time — cf. ClearCaseUcmBaselineParameterDefinition);
  • The ClearCase UCM VOB name (which is actually defined at config-time — cf. ClearCaseUcmBaselineParameterDefinition);
  • The ClearCase UCM component name (which is actually defined at config-time — cf. ClearCaseUcmBaselineParameterDefinition);
  • The ClearCase UCM promotion level (which is actually defined at config-time — cf. ClearCaseUcmBaselineParameterDefinition);
  • The ClearCase UCM view to create name (which is actually defined at config-time — cf. ClearCaseUcmBaselineParameterDefinition);
  • The ClearCase UCM baseline (this is the only one information which is asked at build-time)
  • Author(s):
    Romain Seguy (http://davadoc.deviantart.com)
    Version:
    1.0
     
     
         @Exported(visibility=3) private String baseline;        // this att is set by the user once the build takes place
         @Exported(visibility=3) private String component;       // this att comes from ClearCaseUcmBaselineParameterDefinition
         @Exported(visibility=3) private String promotionLevel;  // this att comes from ClearCaseUcmBaselineParameterDefinition
         @Exported(visibility=3) private String pvob;            // this att comes from ClearCaseUcmBaselineParameterDefinition
         @Exported(visibility=3) private String viewName;        // this att comes from ClearCaseUcmBaselineParameterDefinition
         @Exported(visibility=3) private String vob;             // this att comes from ClearCaseUcmBaselineParameterDefinition
         private String normalizedViewName;
     
         public ClearCaseUcmBaselineParameterValue(String nameString pvobString vobString componentString promotionLevelString viewNameString baseline) {
             super(name);
             this. = pvob;
             this. = vob;
             this. = component;
             this. = promotionLevel;
             this. = viewName;
             this. = baseline;
         }

        
    Returns the hudson.tasks.BuildWrapper (defined as an inner class) which does the "checkout" from the ClearCase UCM baseline selected by the user.

    If a ClearCaseUcmBaselineParameterDefinition is added for the build but the SCM is not ClearCaseUcmBaselineSCM, then the hudson.tasks.BuildWrapper which is returned will make the build fail.

        @Override
        public BuildWrapper createBuildWrapper(AbstractBuild<?, ?> build) {
            // let's ensure that a baseline has been really provided
            if( == null || .length() == 0) {
                return new BuildWrapper() {
                    
    This method makes the build fail when baseline value is null or empty.
                    @Override
                    public Environment setUp(AbstractBuild buildLauncher launcherBuildListener listenerthrows IOExceptionInterruptedException {
                        listener.fatalError("The value '" +  + "' is not a valid ClearCase UCM baseline.");
                        return null;
                    }
                };
            }
            if(build.getProject().getScm() instanceof ClearCaseUcmBaselineSCM) {
                // the job is apparently set-up in a clean way, the build can take place
                return new BuildWrapper() {
                    private ClearToolLauncher createClearToolLauncher(TaskListener listenerFilePath workspaceLauncher launcher) {
                        return new HudsonClearToolLauncher(
                                PluginImpl.getDescriptor().getCleartoolExe(),
                                Hudson.getInstance().getDescriptor(ClearCaseUcmBaselineSCM.class).getDisplayName(),
                                listener,
                                workspace,
                                launcher);
                    }

                    
                    private String generateNormalizedViewName(VariableResolver variableResolverString viewName) {
                        String normalizedViewName = Util.replaceMacro(viewNamevariableResolver);
                        normalizedViewName = normalizedViewName.replaceAll("[\\s\\\\\\/:\\?\\*\\|]+""_");
                        return normalizedViewName;
                    }

                    
    This method is the one which actually does the ClearCase stuff (creating the view, setting the config spec, downloading the view, etc.).

    This method is invoked when the user clicks on the 'Build' button appearing on the parameters page.

                    @Override
                    public Environment setUp(AbstractBuild buildLauncher launcherBuildListener listenerthrows IOExceptionInterruptedException {
                        VariableResolver variableResolver = new BuildVariableResolver(buildlauncher);
                        ClearToolLauncher clearToolLauncher = createClearToolLauncher(listenerbuild.getProject().getWorkspace(), launcher);
                        ClearToolUcmBaseline cleartool = new ClearToolUcmBaseline(variableResolverclearToolLauncher);
                         = generateNormalizedViewName(variableResolver);
                        FilePath workspace = build.getProject().getWorkspace();
                        FilePath viewPath = workspace.child();
                        String rootDir = '/' +  + '/' + ;
                        StringBuilder configSpec = new StringBuilder();
                        // TODO Don't create the view if it already exists
                        // --- 1. We remove the view if it already exists ---
                        if(viewPath.exists()) {
                            cleartool.rmview();
                        }
                        // --- 2. We first create the view to be loaded ---
                        // cleartool mkview -tag <tag> <view path>
                        cleartool.mkview(null);
                        // --- 3. We create the configspec ---
                        configSpec.append("element * CHECKEDOUT\n");
                        configSpec.append("element ").append(rootDir).append("/... ").append().append('\n');
                        // cleartool lsbl -fmt "%[depends_on_closure]p" <baseline>@<vob>
                        String[] dependentBaselines = cleartool.getDependentBaselines();
                        for(String dependentBaselineSelectordependentBaselines) {
                            String dependentBaseline = dependentBaselineSelector.split("@")[0];
                            String component = cleartool.getComponentFromBaseline(dependentBaseline);
                            rootDir = cleartool.getComponentRootDir(component);
                            configSpec.append("element ").append(rootDir).append("/... ").append(dependentBaseline).append('\n');
                        }
                        configSpec.append("element * /main/0\n");
                        configSpec.append("load ").append(rootDir).append('\n');
                        for(String dependentBaselineSelectordependentBaselines) {
                            String dependentBaseline = dependentBaselineSelector.split("@")[0];
                            String component = cleartool.getComponentFromBaseline(dependentBaseline);
                            rootDir = cleartool.getComponentRootDir(component);
                            configSpec.append("load ").append(rootDir).append('\n');
                        }
                        listener.getLogger().println("The view will be created based on the following config spec:");
                        listener.getLogger().println("--- config spec start ---");
                        listener.getLogger().print(configSpec.toString());
                        listener.getLogger().println("---  config spec end  ---");
                        // --- 4. We actually load the view based on the configspec ---
                        //cleartool setcs <configspec>
                        cleartool.setcs(configSpec.toString());
                        // --- 5. Create the environment variables ---
                        return new Environment() {
                            @Override
                            public void buildEnvVars(Map<StringStringenv) {
                                env.put(.,
                                        );
                                env.put(.,
                                        env.get("WORKSPACE") + . + );
                            }
                        };
                    }
                };
            }
            else {
                return new BuildWrapper() {
                    
    This method makes the build fail when a ClearCaseUcmBaselineParameterDefinition parameter is defined for the job, but the SCM is not an instance of ClearCaseUcmBaselineSCM.
                    @Override
                    public Environment setUp(AbstractBuild buildLauncher launcherBuildListener listenerthrows IOExceptionInterruptedException {
                        String ccUcmBaselineSCMDisplayName = Hudson.getInstance().getDescriptor(ClearCaseUcmBaselineSCM.class).getDisplayName();
                        listener.fatalError(
                                "This job is not set up to use a '"
                                + ccUcmBaselineSCMDisplayName
                                + "' SCM while it has a '"
                                + Hudson.getInstance().getDescriptor(ClearCaseUcmBaselineParameterDefinition.class).getDisplayName()
                                + "' parameter: Either remove the parameter or set the SCM to be '"
                                + ccUcmBaselineSCMDisplayName
                                + "'; In the meantime: Aborting!");
                        return null;
                    } 
                };
            }
        }
        public String getBaseline() {
            return ;
        }
        public void setBaseline(String baseline) {
            this. = baseline;
        }
        public String getComponent() {
            return ;
        }
        public void setComponent(String component) {
            this. = component;
        }
        public String getPromotionLevel() {
            return ;
        }
        public void setPromotionLevel(String promotionLevel) {
            this. = promotionLevel;
        }
        public String getPvob() {
            return ;
        }
        public void setPvob(String pvob) {
            this. = pvob;
        }
        public String getViewName() {
            return ;
        }
        public void setViewName(String viewName) {
            this. = viewName;
        }
        public String getVob() {
            return ;
        }
        public void setVob(String vob) {
            this. = vob;
        }
    New to GrepCode? Check out our FAQ X