mvn.plugin.zsh 13.4 KB
Newer Older
1
# Calls ./mvnw if found, otherwise execute the original mvn
2
mvn-or-mvnw() {
Marc Cornellà's avatar
Marc Cornellà committed
3
4
5
	if [ -x ./mvnw ]; then
		echo "executing mvnw instead of mvn"
		./mvnw "$@"
6
	else
7
		command mvn "$@"
8
9
	fi
}
10

11
# Wrapper function for Maven's mvn command. Based on https://gist.github.com/1027800
12
mvn-color() {
13
14
15
16
17
18
19
	local BOLD=$(echoti bold)
	local TEXT_RED=$(echoti setaf 1)
	local TEXT_GREEN=$(echoti setaf 2)
	local TEXT_YELLOW=$(echoti setaf 3)
	local TEXT_BLUE=$(echoti setaf 4)
	local TEXT_WHITE=$(echoti setaf 7)
	local RESET_FORMATTING=$(echoti sgr0)
Marc Cornellà's avatar
Marc Cornellà committed
20
21
22
23
24
	(
	# Filter mvn output using sed. Before filtering set the locale to C, so invalid characters won't break some sed implementations
	unset LANG
	LC_CTYPE=C mvn "$@" | sed \
		-e "s/\(\[INFO\]\)\(.*\)/${TEXT_BLUE}${BOLD}\1${RESET_FORMATTING}\2/g" \
25
		-e "s/\(\[DEBUG\]\)\(.*\)/${TEXT_WHITE}${BOLD}\1${RESET_FORMATTING}\2/g" \
Marc Cornellà's avatar
Marc Cornellà committed
26
27
28
29
		-e "s/\(\[INFO\]\ BUILD SUCCESSFUL\)/${BOLD}${TEXT_GREEN}\1${RESET_FORMATTING}/g" \
		-e "s/\(\[WARNING\]\)\(.*\)/${BOLD}${TEXT_YELLOW}\1${RESET_FORMATTING}\2/g" \
		-e "s/\(\[ERROR\]\)\(.*\)/${BOLD}${TEXT_RED}\1${RESET_FORMATTING}\2/g" \
		-e "s/Tests run: \([^,]*\), Failures: \([^,]*\), Errors: \([^,]*\), Skipped: \([^,]*\)/${BOLD}${TEXT_GREEN}Tests run: \1${RESET_FORMATTING}, Failures: ${BOLD}${TEXT_RED}\2${RESET_FORMATTING}, Errors: ${BOLD}${TEXT_RED}\3${RESET_FORMATTING}, Skipped: ${BOLD}${TEXT_YELLOW}\4${RESET_FORMATTING}/g"
30

Marc Cornellà's avatar
Marc Cornellà committed
31
32
33
34
	# Make sure formatting is reset
	echo -ne "${RESET_FORMATTING}"
	)
}
35

36
# either use orignal mvn or the mvn wrapper
37
38
alias mvn="mvn-or-mvnw"

39
40
41
# Run mvn against the pom found in a project's root directory (assumes a git repo)
alias 'mvn!'='mvn -f $(git rev-parse --show-toplevel 2>/dev/null || echo ".")/pom.xml'

42
# aliases
43
44
45
46
47
alias mvnag='mvn archetype:generate'
alias mvnboot='mvn spring-boot:run'
alias mvnc='mvn clean'
alias mvncd='mvn clean deploy'
alias mvnce='mvn clean eclipse:clean eclipse:eclipse'
48
alias mvnci='mvn clean install'
49
50
alias mvncie='mvn clean install eclipse:eclipse'
alias mvncini='mvn clean initialize'
Peter Butkovic's avatar
Peter Butkovic committed
51
alias mvncist='mvn clean install -DskipTests'
52
alias mvncisto='mvn clean install -DskipTests --offline'
53
54
55
alias mvncom='mvn compile'
alias mvncp='mvn clean package'
alias mvnct='mvn clean test'
56
alias mvncv='mvn clean verify'
Laurent Vaills's avatar
Laurent Vaills committed
57
alias mvncvst='mvn clean verify -DskipTests'
58
alias mvnd='mvn deploy'
59
alias mvndocs='mvn dependency:resolve -Dclassifier=javadoc'
Peter Butkovic's avatar
Peter Butkovic committed
60
alias mvndt='mvn dependency:tree'
61
62
63
alias mvne='mvn eclipse:eclipse'
alias mvnjetty='mvn jetty:run'
alias mvnp='mvn package'
Peter Butkovic's avatar
Peter Butkovic committed
64
alias mvns='mvn site'
65
alias mvnsrc='mvn dependency:sources'
66
67
68
69
alias mvnt='mvn test'
alias mvntc='mvn tomcat:run'
alias mvntc7='mvn tomcat7:run'
alias mvn-updates='mvn versions:display-dependency-updates'
70

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#realpath replacement for iOS - not always present
function _realpath {
	if [[ -f "$1" ]]
	then
		# file *must* exist
		if cd "$(echo "${1%/*}")" &>/dev/null
		then
			# file *may* not be local
			# exception is ./file.ext
			# try 'cd .; cd -;' *works!*
			local tmppwd="$PWD"
			cd - &>/dev/null
		else
			# file *must* be local
			local tmppwd="$PWD"
		fi
	else
		# file *cannot* exist
		return 1 # failure
	fi

	# reassemble realpath
	echo "$tmppwd"/"${1##*/}"
	return 1 #success
}

function __pom_hierarchy {
	local file=`_realpath "pom.xml"`
	POM_HIERARCHY+=("~/.m2/settings.xml")
	POM_HIERARCHY+=("$file")
	while [ -n "$file" ] && grep -q "<parent>" $file; do
		##look for a new relativePath for parent pom.xml
		local new_file=`grep -e "<relativePath>.*</relativePath>" $file | sed 's/.*<relativePath>//' | sed 's/<\/relativePath>.*//g'`

		## <parent> is present but not defined. Asume ../pom.xml
		if [ -z "$new_file" ]; then
			new_file="../pom.xml"
		fi

		## if file exists continue else break
		new_pom=`_realpath "${file%/*}/$new_file"`
		if [ -n "$new_pom" ]; then
			file=$new_pom
		else
			break
		fi
		POM_HIERARCHY+=("$file")
	done
}
120

Marc Cornellà's avatar
Marc Cornellà committed
121
function listMavenCompletions {
122
123
124
125
126
127
128
129
130
	POM_HIERARCHY=()
	__pom_hierarchy

	profiles=()
	#current pom profiles
	for item in ${POM_HIERARCHY[*]}; do
		profiles=($profiles `[ -e $item ] && cat $item | sed 's/<!--.*-->//' | sed '/<!--/,/-->/d' | grep -e "<profile>" -A 1 | grep -e "<id>.*</id>" | sed 's?.*<id>\(.*\)<\/id>.*?-P\1?'`)
	done

Marc Cornellà's avatar
Marc Cornellà committed
131
132
133
	reply=(
		# common lifecycle
		clean initialize process-resources compile process-test-resources test-compile test package verify install deploy site
134

Marc Cornellà's avatar
Marc Cornellà committed
135
136
		# integration testing
		pre-integration-test integration-test
137

Marc Cornellà's avatar
Marc Cornellà committed
138
139
		# common plugins
		deploy failsafe install site surefire checkstyle javadoc jxr pmd ant antrun archetype assembly dependency enforcer gpg help release repository source eclipse idea jetty cargo jboss tomcat tomcat6 tomcat7 exec versions war ear ejb android scm buildnumber nexus repository sonar license hibernate3 liquibase flyway gwt
140

Marc Cornellà's avatar
Marc Cornellà committed
141
142
143
144
145
146
147
148
149
150
		# deploy
		deploy:deploy-file
		# failsafe
		failsafe:integration-test failsafe:verify
		# install
		install:install-file install:help
		# site
		site:site site:deploy site:run site:stage site:stage-deploy site:attach-descriptor site:jar site:effective-site
		# surefire
		surefire:test
151

Marc Cornellà's avatar
Marc Cornellà committed
152
153
154
155
156
157
158
159
		# checkstyle
		checkstyle:checkstyle checkstyle:check checkstyle:checkstyle-aggregate
		# javadoc
		javadoc:javadoc javadoc:test-javadoc javadoc:javadoc-no-fork javadoc:test-javadoc-no-fork javadoc:aggregate javadoc:test-aggregate javadoc:jar javadoc:test-jar javadoc:aggregate-jar javadoc:test-aggregate-jar javadoc:fix javadoc:test-fix javadoc:resource-bundle javadoc:test-resource-bundle
		# jxr
		jxr:jxr jxr:aggregate jxr:test-jxr jxr:test-aggregate
		# pmd
		pmd:pmd pmd:cpd pmd:check pmd:cpd-check
160

Marc Cornellà's avatar
Marc Cornellà committed
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
		# ant
		ant:ant ant:clean
		# antrun
		antrun:run
		# archetype
		archetype:generate archetype:create-from-project archetype:crawl
		# assembly
		assembly:single assembly:assembly
		# dependency
		dependency:analyze dependency:analyze-dep-mgt dependency:analyze-only dependency:analyze-report dependency:analyze-duplicate dependency:build-classpath dependency:copy dependency:copy-dependencies dependency:display-ancestors dependency:get dependency:go-offline dependency:list dependency:list-repositories dependency:properties dependency:purge-local-repository dependency:resolve dependency:resolve-plugins dependency:sources dependency:tree dependency:unpack dependency:unpack-dependencies
		# enforcer
		enforcer:enforce enforcer:display-info
		# gpg
		gpg:sign gpg:sign-and-deploy-file
		# help
		help:active-profiles help:all-profiles help:describe help:effective-pom help:effective-settings help:evaluate help:expressions help:system
		# release
		release:clean release:prepare release:prepare-with-pom release:rollback release:perform release:stage release:branch release:update-versions
		# jgitflow
		jgitflow:feature-start jgitflow:feature-finish jgitflow:release-start jgitflow:release-finish jgitflow:hotfix-start jgitflow:hotfix-finish jgitflow:build-number
		# repository
		repository:bundle-create repository:bundle-pack
		# source
		source:aggregate source:jar source:jar-no-fork source:test-jar source:test-jar-no-fork
185

Marc Cornellà's avatar
Marc Cornellà committed
186
187
188
189
		# eclipse
		eclipse:clean eclipse:eclipse
		# idea
		idea:clean idea:idea
190

Marc Cornellà's avatar
Marc Cornellà committed
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
		# jetty
		jetty:run jetty:run-exploded
		# cargo
		cargo:start cargo:run cargo:stop cargo:deploy cargo:undeploy cargo:help
		# jboss
		jboss:start jboss:stop jboss:deploy jboss:undeploy jboss:redeploy
		# tomcat
		tomcat:start tomcat:stop tomcat:deploy tomcat:undeploy tomcat:redeploy
		# tomcat6
		tomcat6:run tomcat6:run-war tomcat6:run-war-only tomcat6:stop tomcat6:deploy tomcat6:undeploy
		# tomcat7
		tomcat7:run tomcat7:run-war tomcat7:run-war-only tomcat7:deploy
		# tomee
		tomee:run tomee:run-war tomee:run-war-only tomee:stop tomee:deploy tomee:undeploy
		# spring-boot
		spring-boot:run spring-boot:repackage
		# exec
		exec:exec exec:java
		# versions
		versions:display-dependency-updates versions:display-plugin-updates versions:display-property-updates versions:update-parent versions:update-properties versions:update-child-modules versions:lock-snapshots versions:unlock-snapshots versions:resolve-ranges versions:set versions:use-releases versions:use-next-releases versions:use-latest-releases versions:use-next-snapshots versions:use-latest-snapshots versions:use-next-versions versions:use-latest-versions versions:commit versions:revert
		# scm
		scm:add scm:bootstrap scm:branch scm:changelog scm:check-local-modification scm:checkin scm:checkout scm:diff scm:edit scm:export scm:list scm:remove scm:status scm:tag scm:unedit scm:update scm:update-subprojects scm:validate
		# buildnumber
		buildnumber:create buildnumber:create-timestamp buildnumber:help buildnumber:hgchangeset
215

Marc Cornellà's avatar
Marc Cornellà committed
216
217
218
219
220
221
222
223
224
225
226
227
		# war
		war:war war:exploded war:inplace war:manifest
		# ear
		ear:ear ear:generate-application-xml
		# ejb
		ejb:ejb
		# android
		android:apk android:apklib android:deploy android:deploy-dependencies android:dex android:emulator-start android:emulator-stop android:emulator-stop-all android:generate-sources android:help android:instrument android:manifest-update android:pull android:push android:redeploy android:run android:undeploy android:unpack android:version-update android:zipalign android:devices
		# nexus
		nexus:staging-list nexus:staging-close nexus:staging-drop nexus:staging-release nexus:staging-build-promotion nexus:staging-profiles-list nexus:settings-download
		# repository
		repository:bundle-create repository:bundle-pack repository:help
228

Marc Cornellà's avatar
Marc Cornellà committed
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
		# sonar
		sonar:sonar
		# license
		license:format license:check
		# hibernate3
		hibernate3:hbm2ddl hibernate3:help
		# liquibase
		liquibase:changelogSync liquibase:changelogSyncSQL liquibase:clearCheckSums liquibase:dbDoc liquibase:diff liquibase:dropAll liquibase:help liquibase:migrate liquibase:listLocks liquibase:migrateSQL liquibase:releaseLocks liquibase:rollback liquibase:rollbackSQL liquibase:status liquibase:tag liquibase:update liquibase:updateSQL liquibase:updateTestingRollback
		# flyway
		flyway:clean flyway:history flyway:init flyway:migrate flyway:status flyway:validate
		# gwt
		gwt:browser gwt:clean gwt:compile gwt:compile-report gwt:css gwt:debug gwt:eclipse gwt:eclipseTest gwt:generateAsync gwt:help gwt:i18n gwt:mergewebxml gwt:resources gwt:run gwt:sdkInstall gwt:source-jar gwt:soyc gwt:test
		# asciidoctor
		asciidoctor:process-asciidoc asciidoctor:auto-refresh asciidoctor:http asciidoctor:zip
		# compiler
		compiler:compile compiler:testCompile
		# resources
		resources:resources resources:testResources resources:copy-resources
		# verifier
		verifier:verify
		# jar
		jar:jar jar:test-jar
		# rar
		rar:rar
		# acr
		acr:acr
		# shade
		shade:shade
		# changelog
		changelog:changelog changelog:dev-activity changelog:file-activity
		# changes
		changes:announcement-mail changes:announcement-generate changes:changes-check changes:changes-validate changes:changes-report changes:jira-report changes:trac-report changes:github-report
		# doap
		doap:generate
		# docck
		docck:check
		# jdeps
		jdeps:jdkinternals jdeps:test-jdkinternals
		# linkcheck
		linkcheck:linkcheck
		# project-info-reports
		project-info-reports:cim project-info-reports:dependencies project-info-reports:dependency-convergence project-info-reports:dependency-info project-info-reports:dependency-management project-info-reports:distribution-management project-info-reports:help project-info-reports:index project-info-reports:issue-tracking project-info-reports:license project-info-reports:mailing-list project-info-reports:modules project-info-reports:plugin-management project-info-reports:plugins project-info-reports:project-team project-info-reports:scm project-info-reports:summary
		# surefire-report
		surefire-report:failsafe-report-only surefire-report:report surefire-report:report-only
		# invoker
		invoker:install invoker:integration-test invoker:verify invoker:run
		# jarsigner
		jarsigner:sign jarsigner:verify
		# patch
		patch:apply
		# pdf
		pdf:pdf
		# plugin
		plugin:descriptor plugin:report plugin:updateRegistry plugin:addPluginArtifactMetadata plugin:helpmojo
		# remote-resources
		remote-resources:bundle remote-resources:process
		# scm-publish
		scm-publish:help scm-publish:publish-scm scm-publish:scmpublish
		# stage
		stage:copy
		# toolchain
		toolchain:toolchain
291

Marc Cornellà's avatar
Marc Cornellà committed
292
293
		# options
		"-Dmaven.test.skip=true" -DskipTests -DskipITs -Dmaven.surefire.debug -DenableCiProfile "-Dpmd.skip=true" "-Dcheckstyle.skip=true" "-Dtycho.mode=maven" "-Dmaven.test.failure.ignore=true" "-DgroupId=" "-DartifactId=" "-Dversion=" "-Dpackaging=jar" "-Dfile="
294

Marc Cornellà's avatar
Marc Cornellà committed
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
		# arguments
		-am --also-make
		-amd --also-make-dependents-am
		-B --batch-mode
		-b --builder
		-C --strict-checksums
		-c --lax-checksums
		-cpu --check-plugin-updates
		-D --define
		-e --errors
		-emp --encrypt-master-password
		-ep --encrypt-password
		-f --file
		-fae --fail-at-end
		-ff --fail-fast
		-fn --fail-never
		-gs --global-settings
		-gt --global-toolchains
		-h --help
		-l --log-file
		-llr --legacy-local-repository
		-N --non-recursive
		-npr --no-plugin-registry
		-npu --no-plugin-updates
		-nsu --no-snapshot-updates
		-o --offline
		-P --activate-profiles
		-pl --projects
		-q --quiet
		-rf --resume-from
		-s --settings
		-t --toolchains
		-T --threads
		-U --update-snapshots
		-up --update-plugins
		-v --version
		-V --show-version
		-X --debug

		cli:execute cli:execute-phase
		archetype:generate generate-sources
		cobertura:cobertura
		-Dtest=$(if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dtest=\1?' ; fi)
		-Dit.test=$(if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dit.test=\1?' ; fi)
339
340

		$profiles
Marc Cornellà's avatar
Marc Cornellà committed
341
	)
342
343
344

	unset POM_HIERARCHY
	unset profiles
Fredrik Appelberg's avatar
Fredrik Appelberg committed
345
346
}

Neil Green's avatar
Neil Green committed
347
compctl -K listMavenCompletions mvn mvnw
348
compctl -K listMavenCompletions mvn-color
349
compctl -K listMavenCompletions mvn-or-mvnw