Skip to content

Commit 8eab741

Browse files
authored
0 parents  commit 8eab741

File tree

4 files changed

+283
-0
lines changed

4 files changed

+283
-0
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
The [PlantUML Standard Library](http://plantuml.com/stdlib) makes it possible to use popular icons in PlantUML with zero effort.
2+
3+
The [plantuml-stdlib](https://github.com/plantuml/plantuml-stdlib) code as based on other projects.
4+
5+
As there were changes in some of those repos that were not (yet) in plantuml-stdlib, I decided to open some merge-requests to update things.
6+
7+
Because I don't like to do thnings manually that could be automated, I spend some time creating two BASH scripts:
8+
9+
- [`check-sources-for-update.sh`](./check-sources-for-update.sh)
10+
- [`update_sources.sh`](./update_sources.sh)
11+
12+
The first script checks if there are updates for the libraries in the plantuml-stdlib codebase.
13+
The second updates all the libraries in the plantuml-stdlib codebase.
14+
15+
## `check-sources-for-update.sh`
16+
17+
To use this script, make sure there is an up-to-date version of the `plantuml-stdlib` git repository locally.
18+
19+
Then point the script to the `plantuml-stdlib` code base:
20+
21+
```bash
22+
bash ./check-sources-for-update.sh /path/to/plantuml-stdlib/
23+
```
24+
This will then output whether each project has an update available or not.
25+
26+
## `update_sources.sh`
27+
28+
To use this script, make sure there is an up-to-date version of the `plantuml-stdlib` git repository locally.
29+
30+
The `sources.config` file is also needed.
31+
32+
Next point the script to the `plantuml-stdlib` code base:
33+
34+
```bash
35+
bash ./update_sources.sh . /path/to/repos/ /path/to/sources.config
36+
```
37+
38+
This will then checkout or update all the other project git repositories and copy all the relevant files from those projects into the `plantuml-stdlib` code base.
39+
It does this based on information from the config file.
40+
41+
The changes in `plantuml-stdlib` can then be seen using `git status`, added using `git add`. comitted with `git commit`, etc.
42+

check-sources-for-update.sh

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit -o errtrace -o nounset -o pipefail
4+
5+
# ==============================================================================
6+
: readonly "${RESET_TEXT:=$(tput sgr0)}" # turn off all attributes
7+
# ------------------------------------------------------------------------------
8+
# Foreground colors
9+
# ------------------------------------------------------------------------------
10+
: readonly "${COLOR_BLUE:=$(tput setaf 4)}"
11+
: readonly "${COLOR_GREEN:=$(tput setaf 2)}"
12+
: readonly "${COLOR_RED:=$(tput setaf 1)}"
13+
: readonly "${COLOR_WHITE:=$(tput setaf 7)}"
14+
: readonly "${COLOR_YELLOW:=$(tput setaf 3)}"
15+
# ------------------------------------------------------------------------------
16+
# Text attributes
17+
# ------------------------------------------------------------------------------
18+
: readonly "${TEXT_BOLD:=$(tput bold)}" # turn on bold (extra bright) mode
19+
: readonly "${TEXT_INVERSE:=$(tput rev)}" # turn on color inverse mode
20+
# ------------------------------------------------------------------------------
21+
# Text output channels
22+
# ------------------------------------------------------------------------------
23+
: "${ERROR_OUTPUT:=/dev/stderr}"
24+
: "${NORMAL_OUTPUT:=/dev/stdout}"
25+
: "${SILENCE_OUTPUT:=/dev/null}"
26+
# ==============================================================================
27+
28+
: "${GIT:=git}"
29+
30+
check_sources_for_update() {
31+
32+
get_local_version() {
33+
local sContent sLocalVersion
34+
35+
readonly sContent="${1?One parameter required: <content>}"
36+
37+
sLocalVersion=$(echo "${sContent}" | grep -oE '([0-9]+\.?){3}')
38+
39+
if echo "${sLocalVersion}" | grep --quiet '\.0[0-9]';then
40+
# Remove unneeded leading zero
41+
sLocalVersion="$(echo "${sLocalVersion}" | tr '.' "\n" | bc | tr "\n" '.')"
42+
sLocalVersion="${sLocalVersion:0:-1}"
43+
fi
44+
45+
echo "${sLocalVersion}"
46+
}
47+
48+
get_version_from_remote_git() {
49+
local sProject sRemoteVersion
50+
51+
readonly sProject="${1?One parameter required: <github-project>}"
52+
53+
readonly sRemoteVersion="$("${GIT}" ls-remote --tags "git://github.com/${sProject}.git" \
54+
| cut -d'/' -f3 \
55+
| grep -E '^v?[0-9.]+$' \
56+
| grep -oE '[0-9.]+' \
57+
| sort -V \
58+
| tail -n1)" || true
59+
60+
echo "${sRemoteVersion}"
61+
}
62+
63+
compare_versions() {
64+
local sLocalVersion sRemoteVersion sResponse
65+
66+
readonly sLocalVersion="${1?Two parameters required: <local-version> <remote-version>}"
67+
sRemoteVersion="${2?Two parameters required: <local-version> <remote-version>}"
68+
69+
if [[ "${sLocalVersion}" == "" ]] || [[ "${sRemoteVersion}" == "" ]];then
70+
readonly sResponse="${COLOR_RED}No version infromation available${RESET_TEXT}"
71+
else
72+
if echo "${sRemoteVersion}" | grep --quiet -E '^[0-9]+\.[0-9]+$';then
73+
# Pad "x.y" format to "x.y.z" format
74+
sRemoteVersion="${sRemoteVersion}.0"
75+
fi
76+
77+
if [[ "$(echo -e "${sRemoteVersion}\n${sLocalVersion}" | sort -V | tail -n 1)" == "${sLocalVersion}" ]];then
78+
readonly sResponse="${COLOR_GREEN}Up To Date${RESET_TEXT}"
79+
else
80+
readonly sResponse="${COLOR_YELLOW}Newer version available ${TEXT_INVERSE} ${sRemoteVersion} ${RESET_TEXT}"
81+
fi
82+
fi
83+
84+
echo "${sResponse}"
85+
}
86+
87+
get_project_name_from_github_url() {
88+
local sContent sProject sUrl
89+
90+
readonly sContent="${1?One parameter required: <content>}"
91+
92+
readonly sUrl=$(echo "${sContent}" | grep -oE 'https?://.*')
93+
readonly sProject="$(echo "${sUrl}" | rev | grep -oE '[^/]+/[^/]+' | rev)"
94+
95+
echo "${sProject}"
96+
}
97+
98+
check_source_for_update() {
99+
local sContent sLocalVersion sProject sRemoteVersion
100+
101+
readonly sContent="${1?One parameter required: <content>}"
102+
readonly sLocalVersion="$(get_local_version "${sContent}")"
103+
readonly sProject="$(get_project_name_from_github_url "${sContent}")"
104+
105+
echo -n "${RESET_TEXT} =====> ${TEXT_BOLD}${sProject}${RESET_TEXT} (${COLOR_BLUE}${sLocalVersion}${RESET_TEXT})"
106+
107+
readonly sRemoteVersion="$(get_version_from_remote_git "${sProject}")"
108+
109+
echo " $(compare_versions "${sLocalVersion}" "${sRemoteVersion}")"
110+
}
111+
112+
run() {
113+
local sSourcesFile sSourcePaths
114+
115+
sSourcePaths="${1?One parameter required: <sources-path>}"
116+
117+
for sSourcesFile in "${sSourcePaths}/"*'/INFO';do
118+
check_source_for_update "$(cat "${sSourcesFile}")"
119+
done;
120+
121+
# @TODO: Move this to an exit trap, so we don't fuck up the terminal when a user aborts
122+
echo -n "${RESET_TEXT}"
123+
}
124+
125+
run "${@}"
126+
}
127+
128+
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
129+
export -f check_sources_for_update
130+
else
131+
check_sources_for_update "${@}"
132+
exit $?
133+
fi

sources.config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
aws /dist/
2+
awslib /dist/
3+
azure /dist/
4+
C4 /
5+
cloudinsight /sprites/
6+
cloudogu /
7+
office /office2014/
8+
tupadr3 /

update_sources.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit -o errtrace -o nounset -o pipefail
4+
5+
update_sources() {
6+
7+
get_project_name_from_github_url() {
8+
local sContent sProject sUrl
9+
10+
readonly sContent="${1?One parameter required: <content>}"
11+
12+
readonly sUrl=$(echo "${sContent}" | grep -oE 'https?://.*')
13+
readonly sProject="$(echo "${sUrl}" | rev | grep -oE '[^/]+/[^/]+' | rev)"
14+
15+
echo "${sProject}"
16+
}
17+
18+
update_source() {
19+
local iLength sConfig sPath sProject sSourceFile sSourcePath sTargetFile sTargetPath
20+
21+
readonly sProject="${1?Five parameters required: <project> <target-path> <source-path> <path> <config>}"
22+
readonly sTargetPath="${2?Five parameters required: <project> <target-path> <source-path> <path> <config>}"
23+
readonly sSourcePath="${3?Five parameters required: <project> <target-path> <source-path> <path> <config>}"
24+
readonly sPath="${4?Five parameters required: <project> <target-path> <source-path> <path> <config>}"
25+
readonly sConfig="${5?Five parameters required: <project> <target-path> <source-path> <path> <config>}"
26+
27+
echo -e "\n =====> Updating ${sProject} (${sPath})"
28+
29+
if [[ ! -d "${sSourcePath}/${sPath}" ]];then
30+
echo ' -----> Creating git clone'
31+
git clone "git://github.com/${sProject}.git" "${sSourcePath}/${sPath}"
32+
else
33+
echo ' -----> Git clone exists, pull latest changes'
34+
git --git-dir="${sSourcePath}/${sPath}/.git" --work-tree="${sSourcePath}/${sPath}" pull
35+
fi
36+
37+
38+
echo ' -----> Looking up config'
39+
40+
sSource="$(echo "${sConfig}" | grep "\b${sPath}\b" | tr -d ' ')" || true
41+
42+
if [[ "${sSource}" == '' ]];then
43+
echo -e "\tNo config vailable. Skipping"
44+
else
45+
readonly iLength=$(( "${#sSourcePath} + ${#sSource}" + 1))
46+
echo ' -----> Copying "*.puml" files'
47+
48+
find "${sSourcePath}/${sSource}" -name '*.puml' -print0 |
49+
while read -r -d $'\0' sFilePath; do
50+
sSourceFile="${sSourcePath}/${sSource}${sFilePath:${iLength}}"
51+
sTargetFile="${sTargetPath}/${sPath}/${sFilePath:${iLength}}"
52+
53+
sTargetFolder="$(dirname "${sTargetFile}")"
54+
55+
if [[ ! -d "${sTargetFolder}" ]];then
56+
mkdir -p "${sTargetFolder}"
57+
fi
58+
59+
cp "${sSourceFile}" "${sTargetFile}"
60+
done
61+
fi
62+
}
63+
64+
run() {
65+
local sConfigFile sContent sFolder sPath sProject sSourcesFile sSourcePath sTargetPath
66+
67+
readonly sTargetPath="${1?Three parameters required: <target-path> <source-path> <config-file>}"
68+
readonly sSourcePath="${2?Three parameters required: <target-path> <source-path> <config-file>}"
69+
readonly sConfigFile="${3?Three parameters required: <target-path> <source-path> <config-file>}"
70+
71+
for sSourcesFile in "${sTargetPath}/"*'/INFO';do
72+
sPath="$(dirname "${sSourcesFile}")"
73+
74+
sFolder="$(basename "${sPath}")"
75+
76+
sContent="$(cat "${sSourcesFile}")"
77+
78+
sProject="$(get_project_name_from_github_url "${sContent}")"
79+
80+
update_source \
81+
"${sProject}" \
82+
"$(realpath "${sTargetPath}")" \
83+
"$(realpath "${sSourcePath}")" \
84+
"${sFolder}" \
85+
"$(cat "${sConfigFile}")"
86+
done;
87+
88+
# Cleanup
89+
rm -rf "${sTargetPath}/C4/samples/" "${sTargetPath}/tupadr3/examples/"
90+
}
91+
92+
run "${@}"
93+
}
94+
95+
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
96+
export -f update_sources
97+
else
98+
update_sources "${@}"
99+
exit $?
100+
fi

0 commit comments

Comments
 (0)