From 8d1b9fc0af9174d68ed23058d78ea37a6b0a30f4 Mon Sep 17 00:00:00 2001 From: "Francois @fanf42 Armand" Date: Tue, 10 Apr 2018 00:53:22 +0200 Subject: [PATCH] Fixes #12391: Make maven faster and correct MAVEN_OPS --- .gitignore | 1 + Makefile | 4 ++++ makefiles/common-scala-plugin.mk | 4 ++-- makefiles/find_m2_repo.sh | 27 +++++++++++++++++++++++++++ makefiles/global-vars.mk | 5 ++--- makefiles/make-plugins-common.mk | 6 +++--- 6 files changed, 39 insertions(+), 8 deletions(-) create mode 100755 makefiles/find_m2_repo.sh diff --git a/.gitignore b/.gitignore index 9adb95189..9254926ce 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ license.sign *.pubkey *.privkey pom.xml +makefiles/m2_location.cache diff --git a/Makefile b/Makefile index b86eb972b..cb207b9e0 100644 --- a/Makefile +++ b/Makefile @@ -37,4 +37,8 @@ clean: rm -f pom.xml for i in $(ALL); do cd $$i; $(MAKE) clean; cd ..; done +very-clean: clean + ./makefiles/find_m2_repo.sh clean + + .PHONY: $(LIBS) $(PLUGINS) diff --git a/makefiles/common-scala-plugin.mk b/makefiles/common-scala-plugin.mk index 56d72fa3b..5c5712297 100644 --- a/makefiles/common-scala-plugin.mk +++ b/makefiles/common-scala-plugin.mk @@ -18,12 +18,12 @@ TARGET_KEY_CLASSPATH = license.pubkey # PUBLIC_KEY_PATH: path towards the public key to embed std-files: - mvn $(MAVEN_OPTS) package + $(MVN_CMD) package mkdir -p target/$(NAME) mv target/$(NAME)-*-jar-with-dependencies.jar target/$(NAME)/$(NAME).jar licensed-files: check-license - mvn $(MAVEN_OPTS) -Dlimited -Dplugin-resource-publickey=$(TARGET_KEY_CLASSPATH) -Dplugin-resource-license=$(TARGET_LICENSE_PATH) -Dplugin-declared-version=$(VERSION) package + $(MVN_CMD) -Dlimited -Dplugin-resource-publickey=$(TARGET_KEY_CLASSPATH) -Dplugin-resource-license=$(TARGET_LICENSE_PATH) -Dplugin-declared-version=$(VERSION) package mkdir -p target/$(NAME) mv target/$(NAME)-*-jar-with-dependencies.jar target/$(NAME)/$(NAME).jar cp $(PUBLIC_KEY_PATH) target/$(TARGET_KEY_CLASSPATH) diff --git a/makefiles/find_m2_repo.sh b/makefiles/find_m2_repo.sh new file mode 100755 index 000000000..994e98417 --- /dev/null +++ b/makefiles/find_m2_repo.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +# +# This file help find M2_REPO. +# This is not trivial as M2_REPO can be defined in a multitude of +# place, so the safe solution is to ask mvn directly. +# But even that is not easy, because mvn doesn't reply simply. +# And as it is very long, we want to cache the result +# + +SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" +M2_REPO_LOC_CACHE=${SCRIPT_DIR}/m2_location.cache + +case $1 in + + "clean") + rm -f ${M2_REPO_LOC_CACHE} + ;; + + *) + if [ ! -f ${M2_REPO_LOC_CACHE} ]; then + mvn ${MVN_PARAMS} help:evaluate -Dexpression="localRepository" | grep basedir | sed -e "s/.*>\(.*\)<.*/\1/" > ${M2_REPO_LOC_CACHE} + fi + cat ${M2_REPO_LOC_CACHE} + +esac + diff --git a/makefiles/global-vars.mk b/makefiles/global-vars.mk index 06d1ddc8b..f4aca905e 100644 --- a/makefiles/global-vars.mk +++ b/makefiles/global-vars.mk @@ -20,9 +20,8 @@ endif LIB_COMMON_NAME = plugins-common LIB_PRIVATE_NAME = plugins-common-private -# if you want to add maven option, add them with MVN_OPS -MAVEN_OPTS = $(MVN_OPS) --batch-mode - +# if you want to add maven command line parameter, add them with MVN_PARAMS +MVN_CMD = mvn $(MVN_PARAMS) --batch-mode generate-pom: cp pom-template.xml pom.xml diff --git a/makefiles/make-plugins-common.mk b/makefiles/make-plugins-common.mk index feadc6de6..38b324d8d 100644 --- a/makefiles/make-plugins-common.mk +++ b/makefiles/make-plugins-common.mk @@ -8,7 +8,7 @@ include ../makefiles/global-vars.mk # maven local repo -MAVEN_LOCAL_REPO = $(shell mvn help:evaluate -Dexpression="localRepository" | grep basedir | sed -e "s/.*>\(.*\)<.*/\1/") +MAVEN_LOCAL_REPO = $(shell $(MVN_PARAMS) ../makefiles/find_m2_repo.sh) NAME = $(LIB_$(LIB_TYPE)_NAME) VERSION = $(RUDDER_BRANCH)-$(LIB_$(LIB_TYPE)_VERSION) @@ -23,11 +23,11 @@ PARENT_POM = $(MAVEN_LOCAL_REPO)/com/normation/plugins/plugins-parent/$(PARENT_V # hand. Yep, most beautiful tool. $(PLUGINS_JAR_PATH): $(PARENT_POM) test -n "$(LIB_TYPE)" # $$LIB_TYPE must be defined to COMMON or PRIVATE - mvn $(MAVEN_OPTS) clean install + $(MVN_CMD) clean install $(PARENT_POM): echo $(PARENT_POM) - cd .. && mvn $(MAVEN_OPTS) -pl com.normation.plugins:plugins-parent install + cd .. && $(MVN_CMD) -pl com.normation.plugins:plugins-parent install clean: rm -f pom.xml rm -rf target