Refactor var functions of Pipeline library

Move all named functions under com.mirantis.mcp package

Change-Id: I98002e038173fce2325d069e951b221c61109e69
diff --git a/src/com/mirantis/mcp/Git.groovy b/src/com/mirantis/mcp/Git.groovy
index 0cb9533..4bf2056 100644
--- a/src/com/mirantis/mcp/Git.groovy
+++ b/src/com/mirantis/mcp/Git.groovy
@@ -33,3 +33,119 @@
     }
     return git_commit
 }
+
+/**
+ * Execute git clone+checkout stage for some project,
+ * through SSH
+ *
+ * @param body Closure
+ *        body includes next parameters:
+ *          - credentialsId, id of user which should make checkout
+ *          - branch, branch of project
+ *          - host, gerrit-ci hostname
+ *          - project, name of project
+ *          - targetDir, target directory of cloned repo
+ *          - withMerge, prevent detached mode in repo
+ *
+ * Usage example:
+ *
+ * def gitFunc = new com.mirantis.mcp.Git()
+ * gitFunc.gitSSHCheckout {
+ *   credentialsId = 'mcp-ci-gerrit'
+ *   branch = 'mcp-0.1'
+ *   host = 'ci.mcp-ci.local'
+ *   project = 'project'
+ * }
+ */
+def gitSSHCheckout = { body ->
+  // evaluate the body block, and collect configuration into the object
+  def config = [:]
+  body.resolveStrategy = Closure.DELEGATE_FIRST
+  body.delegate = config
+  body()
+
+  def merge = config.withMerge ?: false
+  def targetDir = config.targetDir ?: "./"
+  def port = config.port ?: "29418"
+
+  // default parameters
+  def scmExtensions = [
+    [$class: 'CleanCheckout'],
+    [$class: 'RelativeTargetDirectory', relativeTargetDir: "${targetDir}"]
+  ]
+
+  // https://issues.jenkins-ci.org/browse/JENKINS-6856
+  if (merge) {
+    scmExtensions.add([$class: 'LocalBranch', localBranch: "${config.branch}"])
+  }
+
+  checkout(
+    scm: [
+      $class: 'GitSCM',
+      branches: [[name: "${config.branch}"]],
+      extensions: scmExtensions,
+      userRemoteConfigs: [[
+        credentialsId: "${config.credentialsId}",
+        name: 'origin',
+        url: "ssh://${config.credentialsId}@${config.host}:${port}/${config.project}.git"
+      ]]
+    ]
+  )
+}
+
+/**
+ * Execute git clone and checkout stage from gerrit review
+ *
+ * @param body Closure
+ *        body includes next parameters:
+ *          - credentialsId, id of user which should make checkout
+ *          - withMerge, prevent detached mode in repo
+ *          - withWipeOut, wipe repository and force clone
+ *
+ * Usage example:
+ *
+ * def gitFunc = new com.mirantis.mcp.Git()
+ * gitFunc.gerritPatchsetCheckout {
+ *   credentialsId = 'mcp-ci-gerrit'
+ *   withMerge = true
+ * }
+ */
+def gerritPatchsetCheckout = { body ->
+  // evaluate the body block, and collect configuration into the object
+  def config = [:]
+  body.resolveStrategy = Closure.DELEGATE_FIRST
+  body.delegate = config
+  body()
+
+
+  def merge = config.withMerge ?: false
+  def wipe = config.withWipeOut ?: false
+
+  // default parameters
+  def scmExtensions = [
+    [$class: 'CleanCheckout'],
+    [$class: 'BuildChooserSetting', buildChooser: [$class: 'GerritTriggerBuildChooser']]
+  ]
+  // if we need to "merge" code from patchset to GERRIT_BRANCH branch
+  if (merge) {
+    scmExtensions.add([$class: 'LocalBranch', localBranch: "${GERRIT_BRANCH}"])
+  }
+  // we need wipe workspace before checkout
+  if (wipe) {
+    scmExtensions.add([$class: 'WipeWorkspace'])
+  }
+
+  checkout(
+    scm: [
+      $class: 'GitSCM',
+      branches: [[name: "${GERRIT_BRANCH}"]],
+      extensions: scmExtensions,
+      userRemoteConfigs: [[
+        credentialsId: "${config.credentialsId}",
+        name: 'gerrit',
+        url: "ssh://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}.git",
+        refspec: "${GERRIT_REFSPEC}"
+      ]]
+    ]
+  )
+}