buildframework/helium/tools/common/java/src/com/nokia/ant/taskdefs/RebaselineTask.java
changeset 179 d8ac696cc51f
parent 1 be27ed110b50
--- a/buildframework/helium/tools/common/java/src/com/nokia/ant/taskdefs/RebaselineTask.java	Wed Oct 28 14:39:48 2009 +0000
+++ b/buildframework/helium/tools/common/java/src/com/nokia/ant/taskdefs/RebaselineTask.java	Wed Dec 23 19:29:07 2009 +0200
@@ -1,264 +1,109 @@
 /*
-* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of the License "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description: 
-*
-*/
+ * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description: 
+ *
+ */
 
 package com.nokia.ant.taskdefs;
 
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.Execute;
 
 /**
  * ANT wrapper task for the GSCM rebaseline.pl script.
+ * 
  * @ant.task category="SCM"
  */
-public class RebaselineTask extends Task
-{
-    // The attributes of this task
-    private String database;
-    private String projectName;
-    private String password;
-    private String release;   
-    private String baseline;
-    private String version;
-    private Boolean releaseBaseline;
-    private Boolean leaveFolderswritable;   
-    private Boolean disableTaskRebadging;   
-    private Boolean rebadgeObjectVersions;
-    private String baselineName;
-    private Boolean useBranchReleaseMethodology;
-    private Boolean createBaselineForRollingReleaseTag;
-    private Integer verbosity;
-
-    /**
-     * Set Synergy Database name to be used by rebaseline.pl script.
-     * @param database
-     * @ant.required
-     */
-    public void setdatabase(String database) {
-        this.database = database;
-        log("Set database to " + database, Project.MSG_DEBUG); 
-    }
+public class RebaselineTask extends RBTTask {
+  // The attributes of this task
+  private Boolean disableTaskRebadging;
 
-    /**
-     * Set Synergy Project Name to be used by rebaseline.pl script.
-     * @param projectName
-     * @ant.required
-     */
-    public void setprojectName(String projectName) {
-        this.projectName = projectName;
-        log("Set projectName to " + projectName, Project.MSG_DEBUG); 
-    }
-
-    /**
-     * Set Synergy Password to be used by rebaseline.pl script.
-     * @param password
-     * @ant.required
-     */    
-    public void setpassword(String password) {
-        this.password = password;
-        log("Set password to " + password, Project.MSG_DEBUG);
-    }
-
-    /**
-     * Set release tag (Two-part name) for the release project created by reconfigure.pl script.
-     * @param release
-     * @ant.not-required
-     */    
-    public void setrelease(String release) {
-        this.release = release;
-        log("Set release to " + release, Project.MSG_DEBUG);
-    }
+  /**
+   * Return disableTaskRebadging
+   * 
+   * @return the disableTaskRebadging.
+   */
+  public Boolean getDisableTaskRebadging() {
+    return disableTaskRebadging;
+  }
 
-    /**
-     * Set four-part name of existing baseline (incompatible with 'projectName' and 'baselineName' attributes) to be used by rebaseline.pl script.
-     * @param baseline 
-     * @ant.not-required
-     */    
-    public void setbaseline(String baseline) {
-        this.baseline = baseline;
-        log("Set baseline to " + baseline, Project.MSG_DEBUG);
-    }
-
-    /**
-     * Set version of new project created by rebaseline.pl script.
-     * @param version
-     * @ant.not-required
-     */    
-    public void setversion(String version) {
-        this.version = version;
-        log("Set version to " + version, Project.MSG_DEBUG);
-    }
-
-    /**
-     * Set whether to release the baseline project created by rebaseline.pl script.
-     * @param releaseBaseline
-     * @ant.not-required Default is no.
-     */    
-    public void setreleaseBaseline(Boolean releaseBaseline) {
-        this.releaseBaseline = releaseBaseline;
-        log("Set releaseBaseline to " + releaseBaseline, Project.MSG_DEBUG);
-    }
+  /**
+   * Set whether to disable task rebadging (incompatible with
+   * 'rebadgeObjectVersions' attribute) in the rebaseline.pl script.
+   * 
+   * @param disableTaskRebadging
+   * @ant.not-required Default is no.
+   */
+  public void setdisableTaskRebadging(Boolean disableTaskRebadging) {
+    this.disableTaskRebadging = disableTaskRebadging;
+    log("Set disableTaskRebadging to " + disableTaskRebadging);
+  }
 
-    /**
-     * Set whether to leave the folders writable in the baseline project created by rebaseline.pl script.
-     * @param leaveFolderswritable
-     * @ant.not-required  Default is no.
-     */    
-    public void setleaveFolderswritable(Boolean leaveFolderswritable) {
-        this.leaveFolderswritable = leaveFolderswritable;
-        log("Set leaveFolderswritable to " + leaveFolderswritable, Project.MSG_DEBUG);
-    }
-
-    /**
-     * Set whether to disable task rebadging (incompatible with 'rebadgeObjectVersions' attribute) in the rebaseline.pl script.
-     * @param disableTaskRebadging
-     * @ant.not-required  Default is no.
-     */    
-    public void setdisableTaskRebadging(Boolean disableTaskRebadging) {
-        this.disableTaskRebadging = disableTaskRebadging;
-        log("Set disableTaskRebadging to " + disableTaskRebadging, Project.MSG_DEBUG);
-    }
-
-    /**
-     * Set whether to rebadge object versions in the rebaseline.pl script.
-     * @param password Synergy Password
-     * @ant.not-required Default is no.
-     */    
-    public void setrebadgeObjectVersions(Boolean rebadgeObjectVersions) {
-        this.rebadgeObjectVersions = rebadgeObjectVersions;
-        log("Set rebadgeObjectVersions to " + rebadgeObjectVersions, Project.MSG_DEBUG);
-    }
+  /**
+   * Set the execution script.
+   * 
+   */
+  protected void setExecutionScript() {
+    append2CommandString("rebaseline.pl");
+  }
 
-    /**
-     * Set new baseline name to use in rebaseline.pl script.
-     * @param baselineName
-     * @ant.not-required
-     */    
-    public void setbaselineName(String baselineName) {
-        this.baselineName = baselineName;
-        log("Set baselineName to " + baselineName, Project.MSG_DEBUG);
-    }
-
-    /**
-     * Set whether to utilize branch release methodology in the rebaseline.pl script.
-     * @param useBranchReleaseMethodology
-     * @ant.not-required Default is no.
-     */    
-    public void setuseBranchReleaseMethodology(Boolean useBranchReleaseMethodology) {
-        this.useBranchReleaseMethodology = useBranchReleaseMethodology;
-        log("Set useBranchReleaseMethodology to " + useBranchReleaseMethodology, Project.MSG_DEBUG);
-    }
-
-    /**
-     * Set whether to create additional integration baseline for rolling-release tag.
-     * @param createBaselineForRollingReleaseTag
-     * @ant.not-required Default is no.
-     */    
-    public void setcreateBaselineForRollingReleaseTag(Boolean createBaselineForRollingReleaseTag) {
-        this.createBaselineForRollingReleaseTag = createBaselineForRollingReleaseTag;
-        log("Set createBaselineForRollingReleaseTag to " + createBaselineForRollingReleaseTag, Project.MSG_DEBUG);
-    }
-
-   /**
-     * Set verbosity level to be used by rebaseline.pl script. Verbosity level ( 0 - quiet, 1 - verbose). Exception will be raised for any other value.
-     * @param verbosity 
-     * @ant.not-required
-     */     
-    public void setverbosity(Integer verbosity) {
-        this.verbosity = verbosity;
-        log("Set verbosity to " + verbosity, Project.MSG_DEBUG);
-    }
-    
-    public void execute() {
-        String missingArgs = "";
-        String commandArgs = "cmd /c rebaseline.pl ";
-
-        /* Handle mandatory arguments */
-        if (database == null)
-            missingArgs += "database ";
-        else
-            commandArgs += "-d " + database + " "; 
-
-        if (projectName == null)
-            missingArgs += "projectName ";
-        else
-            commandArgs += "-p " + projectName + " "; 
+  /**
+   * Build a command list consisting of all the required and optional command
+   * arguments of the current task.
+   */
+  protected void buildCommandList() {
+    addCommandArg("database", "-d", true, getDatabase());
+    addCommandArg("password", "-P", true, getPassword());
+    addCommandArg("ccmProject", "-p", true, getCcmProject());
+    addCommandArg("release", "-r", getRelease());
+    addCommandArg("baseline", "-B", getBaseline());
+    addCommandArg("version", "-v", getVersion());
+    addCommandArg("newBaselineName", "-n", getNewBaselineName());
+    addCommandArg("releaseBaseline", "-R", getReleaseBaseline());
+    addCommandArg("leaveFolderswritable", "-w", getLeaveFoldersWritable());
+    addCommandArg("disableTaskRebadging", "-x", getDisableTaskRebadging());
+    addCommandArg("rebadgeObjectVersions", "-a", getRebadgeObjectVersions());
+    addCommandArg("useBranchReleaseMethodology", "-b", getUseBranchReleaseMethodology());
+    addCommandArg("createBaselineForRollingReleaseTag", "-i", getCreateBaselineForRollingReleaseTag());
+  }
 
-        if (password == null)
-            missingArgs += "password ";
-        else
-            commandArgs += "-P " + password + " "; 
-
-        if (!missingArgs.equals(""))
-            throw new BuildException("[" + getTaskName() + "] Error: mandatory attributes are not defined - " + missingArgs);
-
-        /* Handle optional arguments */
-        if (release != null)
-             commandArgs += "-r " + release + " "; 
-
-        if (baseline != null)
-             commandArgs += "-B " + baseline + " "; 
-
-        if (version != null)
-             commandArgs += "-v " + version + " "; 
-
-        if (baselineName != null)
-             commandArgs += "-n " + baselineName + " "; 
-
-        if (releaseBaseline != null)
-            if (releaseBaseline)
-                commandArgs += "-R ";
+  /**
+   * Method returns the correct verbosity level for the input choice.
+   * 
+   * @param choice
+   *            is the verbosity choice set by user.
+   * @return the verbosity level to set.
+   */
+  protected String getVerbosity(int choice) {
+    String cmd = "";
+    switch (choice) {
+    case 0:
+      cmd = "-q ";
+      break;
+    case 1:
+      cmd = "-V ";
+      break;
+    default:
+      raiseError("Verbosity level is not recognised. "
+          + "Legal values are: 0 - quiet, 1 - verbose.");
+    }
+    return cmd;
+  }
 
-        if (leaveFolderswritable != null)
-            if (leaveFolderswritable)
-                commandArgs += "-w ";
-                
-        if (disableTaskRebadging != null)
-            if (disableTaskRebadging)
-                commandArgs += "-x ";
-
-        if (rebadgeObjectVersions != null)
-            if (rebadgeObjectVersions)
-                commandArgs += "-a ";
-
-        if (useBranchReleaseMethodology != null)
-            if (useBranchReleaseMethodology)
-                commandArgs += "-b ";
-
-        if (createBaselineForRollingReleaseTag != null)
-            if (createBaselineForRollingReleaseTag)
-                commandArgs += "-i ";
-
-        if (verbosity != null)
-            switch(verbosity) {
-              case 0: commandArgs += "-q ";
-                      break;
-              case 1: commandArgs += "-V ";
-                      break;
-              default: throw new BuildException("[" + getTaskName() + "] Error: Verbosity level is not recognised. Legal values are: 0 - quiet, 1 - verbose.");
-            }
-
-        try {
-            Execute exe = new Execute();
-            exe.runCommand(this, commandArgs.split(" "));
-        } catch (BuildException e) {
-            throw new BuildException("[" + getTaskName() + "] Error: Script execution failure.");
-        }
-        log("Completed successfully.");
-    }
+  /**
+   * Method validates the given arguments.
+   */
+  protected void validateArguments() {
+    // Do nothing
+  }
+  
 }
\ No newline at end of file