加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
add_smart-doc.sh 3.89 KB
一键复制 编辑 原始数据 按行查看 历史
#!/bin/bash
# Define constants
GROUP_ID="com.ly.smart-doc"
ARTIFACT_ID="smart-doc-maven-plugin"
VERSION="3.0.3"
CONFIG_FILE="./src/main/resources/smart-doc.json"
INCLUDES=("com.baomidou:mybatis-plus-extension" "com.baomidou:mybatis-plus-core" "org.springframework.data:spring-data-commons")
# Define the command to add smart-doc-maven-plugin
ADD_PLUGIN_COMMAND="xmlstarlet ed --inplace -N x=http://maven.apache.org/POM/4.0.0 \
--subnode \"/x:project/x:build/x:plugins\" --type elem -n plugin -v \"\" \
--subnode \"/x:project/x:build/x:plugins/plugin[last()]\" --type elem -n groupId -v \"$GROUP_ID\" \
--subnode \"/x:project/x:build/x:plugins/plugin[last()]\" --type elem -n artifactId -v \"$ARTIFACT_ID\" \
--subnode \"/x:project/x:build/x:plugins/plugin[last()]\" --type elem -n version -v \"$VERSION\""
# Delete version element while add to submodule pom.xml
SUBMODULE_ADD_PLUGIN_COMMAND="xmlstarlet ed --inplace -N x=http://maven.apache.org/POM/4.0.0 \
--subnode \"/x:project/x:build/x:plugins\" --type elem -n plugin -v \"\" \
--subnode \"/x:project/x:build/x:plugins/plugin[last()]\" --type elem -n groupId -v \"$GROUP_ID\" \
--subnode \"/x:project/x:build/x:plugins/plugin[last()]\" --type elem -n artifactId -v \"$ARTIFACT_ID\""
ADD_PLUGIN_MANAGEMENT_COMMAND="xmlstarlet ed --inplace -N x=http://maven.apache.org/POM/4.0.0 \
--subnode \"/x:project/x:build/x:pluginManagement/x:plugins\" --type elem -n plugin -v \"\" \
--subnode \"/x:project/x:build/x:pluginManagement/x:plugins/plugin[last()]\" --type elem -n groupId -v \"$GROUP_ID\" \
--subnode \"/x:project/x:build/x:pluginManagement/x:plugins/plugin[last()]\" --type elem -n artifactId -v \"$ARTIFACT_ID\" \
--subnode \"/x:project/x:build/x:pluginManagement/x:plugins/plugin[last()]\" --type elem -n version -v \"$VERSION\""
# Check if it is a multi-module Maven project
MODULES=$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -c "/x:project/x:modules" pom.xml)
if [ -z "$MODULES" ]; then
echo "This is a single module project."
PLUGIN=$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -c "/x:project/x:build/x:plugins/x:plugin[x:groupId='$GROUP_ID' and x:artifactId='$ARTIFACT_ID']" pom.xml)
if [ -z "$PLUGIN" ]; then
eval "$ADD_PLUGIN_COMMAND pom.xml"
eval "xmlstarlet fo -s 4 pom.xml > pom.xml.tmp && mv pom.xml.tmp pom.xml"
echo "The plugin has been added to the XML document."
else
echo "The plugin is already present in the XML document."
fi
else
echo "This is a multi-module project."
PLUGIN=$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -c "/x:project/x:build/x:pluginManagement/x:plugins/x:plugin[x:groupId='$GROUP_ID' and x:artifactId='$ARTIFACT_ID']" pom.xml)
if [ -z "$PLUGIN" ]; then
eval "$ADD_PLUGIN_MANAGEMENT_COMMAND pom.xml"
eval "xmlstarlet fo -s 4 pom.xml > pom.xml.tmp && mv pom.xml.tmp pom.xml"
echo "The plugin has been added to the pluginManagement section."
else
echo "The plugin is already present in the pluginManagement section."
fi
SUBMODULES_POM=$(find . -mindepth 1 -path "./pom.xml" -prune -o -name "pom.xml" -print | sort)
# shellcheck disable=SC2145
for SUBMODULE_POM in $SUBMODULES_POM; do
MODULE_NAME=$(xmlstarlet sel -N x="http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:artifactId" "$SUBMODULE_POM")
PLUGIN=$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -c "/x:project/x:build/x:plugins/x:plugin[x:groupId='$GROUP_ID' and x:artifactId='$ARTIFACT_ID']" "$SUBMODULE_POM")
if [ -z "$PLUGIN" ]; then
eval "$SUBMODULE_ADD_PLUGIN_COMMAND $SUBMODULE_POM"
eval "xmlstarlet fo -s 4 $SUBMODULE_POM > $SUBMODULE_POM.tmp && mv $SUBMODULE_POM.tmp $SUBMODULE_POM"
echo "The plugin has been added to the $MODULE_NAME module."
else
echo "The plugin is already present in the $MODULE_NAME module."
fi
done
fi
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化