diff --git a/cola-components/dev-util-archetypes/README.md b/cola-components/dev-util-archetypes/README.md index 0fcbba85c..751260ecc 100644 --- a/cola-components/dev-util-archetypes/README.md +++ b/cola-components/dev-util-archetypes/README.md @@ -1,5 +1,10 @@ -# COLA Dev Helper Archetypes +# COLA Dev Util Archetypes 用于开发时快速生成`COLA Components`工程的Archetypes。 即方便COLA开发的工具工程。 + +提供了脚本,调用`Util Archetypes`生成`COLA Components`工程: + +- [`new-cola-normal-component.sh`](new-cola-normal-component.sh) +- [`new-cola-starter-component.sh`](new-cola-starter-component.sh) diff --git a/cola-components/dev-util-archetypes/new-cola-normal-component.sh b/cola-components/dev-util-archetypes/new-cola-normal-component.sh new file mode 100755 index 000000000..35fe87211 --- /dev/null +++ b/cola-components/dev-util-archetypes/new-cola-normal-component.sh @@ -0,0 +1,37 @@ +#!/bin/bash +set -eEuo pipefail +# adjust current dir to script dir +cd "$(dirname "$(readlink -f "$0")")" + +source ../../scripts/common.sh +source ../../scripts/common_build.sh + +# shellcheck disable=SC2154 +[ $# -ne 1 ] && die "need only 1 argument for component name!$nl${nl}usage:$nl $0 hello" +readonly component_name="$1" +readonly archetype_dir=cola-normal-component-archetype + +( + cd "$archetype_dir" + MVN_WITH_BASIC_OPTIONS install +) + +groupId=$(extractFirstElementValueFromPom groupId ../pom.xml) +component_version=$(extractFirstElementValueFromPom version ../pom.xml) + +archetypeGroupId=$(extractFirstElementValueFromPom groupId "$archetype_dir/pom.xml") +archetypeArtifactId=$(extractFirstElementValueFromPom artifactId "$archetype_dir/pom.xml") +archetypeVersion=$(extractFirstElementValueFromPom version "$archetype_dir/pom.xml") + +cd .. + +MVN_WITH_BASIC_OPTIONS archetype:generate \ + -DgroupId="$groupId" \ + -DartifactId="cola-component-$component_name" \ + -Dversion="$component_version" \ + -Dpackage="com.alibaba.cola.$component_name" \ + -DarchetypeGroupId="$archetypeGroupId" \ + -DarchetypeArtifactId="$archetypeArtifactId" \ + -DarchetypeVersion="$archetypeVersion" \ + -DinteractiveMode=false \ + -DarchetypeCatalog=local diff --git a/cola-components/dev-util-archetypes/new-cola-starter-component.sh b/cola-components/dev-util-archetypes/new-cola-starter-component.sh new file mode 100755 index 000000000..ee8e97c7d --- /dev/null +++ b/cola-components/dev-util-archetypes/new-cola-starter-component.sh @@ -0,0 +1,36 @@ +#!/bin/bash +set -eEuo pipefail +# adjust current dir to script dir +cd "$(dirname "$(readlink -f "$0")")" + +source ../../scripts/common.sh +source ../../scripts/common_build.sh + +# shellcheck disable=SC2154 +[ $# -ne 1 ] && die "need only 1 argument for component name!$nl${nl}usage:$nl $0 hello" +readonly component_name="$1" +readonly archetype_dir=cola-starter-component-archetype + +( + cd "$archetype_dir" + MVN_WITH_BASIC_OPTIONS install +) + +groupId=$(extractFirstElementValueFromPom groupId ../pom.xml) +component_version=$(extractFirstElementValueFromPom version ../pom.xml) + +archetypeGroupId=$(extractFirstElementValueFromPom groupId "$archetype_dir/pom.xml") +archetypeArtifactId=$(extractFirstElementValueFromPom artifactId "$archetype_dir/pom.xml") +archetypeVersion=$(extractFirstElementValueFromPom version "$archetype_dir/pom.xml") + +cd .. +MVN_WITH_BASIC_OPTIONS archetype:generate \ + -DgroupId="$groupId" \ + -DartifactId="cola-component-$component_name-starter" \ + -Dversion="$component_version" \ + -Dpackage="com.alibaba.cola.$component_name" \ + -DarchetypeGroupId="$archetypeGroupId" \ + -DarchetypeArtifactId="$archetypeArtifactId" \ + -DarchetypeVersion="$archetypeVersion" \ + -DinteractiveMode=false \ + -DarchetypeCatalog=local diff --git a/scripts/common.sh b/scripts/common.sh index e6c74d135..e2e6eb4f2 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -47,6 +47,7 @@ headInfo() { # https://unix.stackexchange.com/questions/285924 versionLessThan() { (($# == 2)) || die "${FUNCNAME[0]} need only 2 arguments, actual arguments: $*" + local ver=$1 local destVer=$2 diff --git a/scripts/common_build.sh b/scripts/common_build.sh index 5652072f5..bce2c582f 100644 --- a/scripts/common_build.sh +++ b/scripts/common_build.sh @@ -52,6 +52,14 @@ MVN_WITH_BASIC_OPTIONS() { logAndRun "$(__getMvnwExe)" "${_MVN_BASIC_OPTIONS[@]}" "$@" } +extractFirstElementValueFromPom() { + (($# == 2)) || die "${FUNCNAME[0]} need only 2 arguments, actual arguments: $*" + + local element=$1 + local pom_file=$2 + grep \<"$element"'>.* "$pom_file" | awk -F' 'NR==1 {print $2}' +} + # Where is Maven local repository? # https://mkyong.com/maven/where-is-maven-local-repository/ diff --git a/scripts/integration-test.sh b/scripts/integration-test.sh index 854b86d06..6b3285e55 100755 --- a/scripts/integration-test.sh +++ b/scripts/integration-test.sh @@ -42,10 +42,7 @@ cleanMavenInstallOfColaInMavenLocalRepository headInfo "CI: archetype:generate by cola-framework-archetype-service" # NOTE: DO NOT declare archetypeVersion var as readonly, its value is supplied by subshell. - archetypeVersion=$( - grep '.*' cola-archetypes/cola-archetype-service/pom.xml | - awk -F'' 'NR==1 {print $2}' - ) + archetypeVersion=$(extractFirstElementValueFromPom version cola-archetypes/cola-archetype-service/pom.xml) # shellcheck disable=SC2030 readonly demo_dir="cola-archetypes/target/cola-framework-archetype-service-demo" @@ -74,10 +71,7 @@ cleanMavenInstallOfColaInMavenLocalRepository headInfo "CI: archetype:generate by cola-framework-archetype-web" # NOTE: DO NOT declare archetypeVersion var as readonly, its value is supplied by subshell. - archetypeVersion=$( - grep '.*' cola-archetypes/cola-archetype-web/pom.xml | - awk -F'' 'NR==1 {print $2}' - ) + archetypeVersion=$(extractFirstElementValueFromPom version cola-archetypes/cola-archetype-web/pom.xml) # shellcheck disable=SC2031 readonly demo_dir="cola-archetypes/target/cola-framework-archetype-web-demo"