Skip to content

Commit

Permalink
+ add new-cola-*-component.sh scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Jan 11, 2021
1 parent 75475c7 commit 0bd608b
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 9 deletions.
7 changes: 6 additions & 1 deletion cola-components/dev-util-archetypes/README.md
Original file line number Diff line number Diff line change
@@ -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)
37 changes: 37 additions & 0 deletions cola-components/dev-util-archetypes/new-cola-normal-component.sh
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions cola-components/dev-util-archetypes/new-cola-starter-component.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions scripts/common_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"'>.*</'"$element"\> "$pom_file" | awk -F'</?'"$element"\> 'NR==1 {print $2}'
}

# Where is Maven local repository?
# https://mkyong.com/maven/where-is-maven-local-repository/

Expand Down
10 changes: 2 additions & 8 deletions scripts/integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<version>.*</version>' cola-archetypes/cola-archetype-service/pom.xml |
awk -F'</?version>' '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"
Expand Down Expand Up @@ -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 '<version>.*</version>' cola-archetypes/cola-archetype-web/pom.xml |
awk -F'</?version>' '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"
Expand Down

0 comments on commit 0bd608b

Please sign in to comment.