summaryrefslogtreecommitdiffstats
path: root/common/common-scripts/src/main/groovy/io/fd/honeycomb/common/scripts/ModulesListGenerator.groovy
diff options
context:
space:
mode:
authorMaros Marsalek <mmarsale@cisco.com>2016-10-12 14:48:17 +0200
committerMarek Gradzki <mgradzki@cisco.com>2016-10-17 09:11:21 +0000
commit7236617f71a2090aa1aebac37e2b7b51330cdc73 (patch)
tree97011e0210a589adfb48c00b761d8ec59d631f8b /common/common-scripts/src/main/groovy/io/fd/honeycomb/common/scripts/ModulesListGenerator.groovy
parent957461dcfd741fc3290e4317c2297c5618b593b5 (diff)
HONEYCOMB-157 Extract groovy scripts from poms
And put all of them into a dedicated module Change-Id: Id04c66806a89af68d821a43ef92f0a59220e04e9 Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'common/common-scripts/src/main/groovy/io/fd/honeycomb/common/scripts/ModulesListGenerator.groovy')
-rw-r--r--common/common-scripts/src/main/groovy/io/fd/honeycomb/common/scripts/ModulesListGenerator.groovy69
1 files changed, 69 insertions, 0 deletions
diff --git a/common/common-scripts/src/main/groovy/io/fd/honeycomb/common/scripts/ModulesListGenerator.groovy b/common/common-scripts/src/main/groovy/io/fd/honeycomb/common/scripts/ModulesListGenerator.groovy
new file mode 100644
index 000000000..c7a74d20e
--- /dev/null
+++ b/common/common-scripts/src/main/groovy/io/fd/honeycomb/common/scripts/ModulesListGenerator.groovy
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.common.scripts
+
+import groovy.text.SimpleTemplateEngine
+
+import java.nio.file.Paths
+
+/**
+ * Generate modules-list file a honeycomb distribution.
+ */
+class ModulesListGenerator {
+
+ static final def DEFAULT_MODULES_LIST = ModulesListGenerator.getResource("/modules/modulesListDefaultContent").text
+
+ static final def MODULES_LIST_CONTENT_PROPERTY = "distribution.modules"
+ static final def MODULES_FOLDER = "modules"
+ static final def MODULE_LIST_FILE_SUFFIX = "-module-config"
+ static final def SEPARATOR = ","
+
+ public static void generate(project, properties, log) {
+ // module configuration file extraction
+ // builds project name from group,artifact and version to prevent overwriting
+ // while building multiple distribution project
+ def artifact = project.artifact
+ def projectName = "${artifact.getGroupId()}_${artifact.getArtifactId()}_${artifact.getVersion()}".replace(".","-")
+
+ log.info "Generating list of modules started by distribution ${projectName}"
+
+ def activeModules = properties.getProperty(MODULES_LIST_CONTENT_PROPERTY, DEFAULT_MODULES_LIST)
+ .tokenize(SEPARATOR)
+ .collect { module -> module.trim() }
+
+ log.info "Project ${projectName} : Found modules ${activeModules}"
+ //creates folder modules
+
+ def outputPath = Paths.get(project.build.outputDirectory, StartupScriptGenerator.MINIMAL_RESOURCES_FOLDER, MODULES_FOLDER)
+ //creates module folder
+ outputPath.toFile().mkdirs()
+
+ def outputFile = Paths.get(outputPath.toString(), "${projectName}${MODULE_LIST_FILE_SUFFIX}").toFile()
+ outputFile.createNewFile();
+ log.info("Writing module configuration for distribution ${projectName} to ${outputPath}")
+
+ if (activeModules.isEmpty()) {
+ outputFile.text = new SimpleTemplateEngine().createTemplate(DEFAULT_MODULES_LIST).make(
+ ["groupId" : project.groupId,
+ "artifactId": project.artifactId,
+ "version" : project.version]).toString()
+ } else {
+ activeModules.add(0, "// Generated from ${project.groupId}/${project.artifactId}/${project.version}")
+ outputFile.text = activeModules.join(System.lineSeparator)
+ }
+ }
+}