1 |
grobian 10/02/26 17:17:39 |
2 |
|
3 |
Added: maven.eselect-1 |
4 |
Log: |
5 |
Revbump for Prefix fixes, bug #305359 |
6 |
(Portage version: 2.2.00.15444-prefix/cvs/Darwin powerpc) |
7 |
|
8 |
Revision Changes Path |
9 |
1.1 app-admin/eselect-maven/files/maven.eselect-1 |
10 |
|
11 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-admin/eselect-maven/files/maven.eselect-1?rev=1.1&view=markup |
12 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-admin/eselect-maven/files/maven.eselect-1?rev=1.1&content-type=text/plain |
13 |
|
14 |
Index: maven.eselect-1 |
15 |
=================================================================== |
16 |
# Copyright 1999-2010 Gentoo Foundation |
17 |
# Distributed under the terms of the GNU General Public License v2 |
18 |
# $Id: maven.eselect-1,v 1.1 2010/02/26 17:17:38 grobian Exp $ |
19 |
|
20 |
DESCRIPTION="Manage Maven targets" |
21 |
MAINTAINER="jieryn@×××××.com" |
22 |
VERSION="0.1" |
23 |
|
24 |
MVN="${EROOT}/usr/bin/mvn" |
25 |
|
26 |
# find a list of mvn symlink targets, best first. |
27 |
find_targets() { |
28 |
for f in $(ls -r "${MVN}"-[0-9]* 2> /dev/null) ; do |
29 |
if [[ -f "${f}" ]] ; then |
30 |
echo $(basename "${f}") |
31 |
fi |
32 |
done |
33 |
} |
34 |
|
35 |
# get a named or numbered target. |
36 |
find_target() { |
37 |
local target=${1} |
38 |
|
39 |
if is_number "${target}" && [[ ${target} -ge 1 ]] ; then |
40 |
targets=( $(find_targets ) ) |
41 |
[[ -z "${targets}" ]] && die -q "No targets found!" |
42 |
target=${targets[$(( ${target} - 1 ))]} |
43 |
fi |
44 |
|
45 |
if [[ "${target}" = mvn-[0-9]* ]] && [[ -f "${EROOT}/usr/bin/${target}" ]] ; then |
46 |
echo ${target} |
47 |
else |
48 |
die -q "Target \"${1}\" doesn't appear to be valid!" |
49 |
fi |
50 |
} |
51 |
|
52 |
# try to remove the mvn symlink. |
53 |
remove_symlink() { |
54 |
rm "${MVN}" &>/dev/null |
55 |
} |
56 |
|
57 |
# determine the current target. |
58 |
get_target() { |
59 |
local canonicalised=$(canonicalise "${MVN}") |
60 |
echo $(basename "${canonicalised}") |
61 |
} |
62 |
|
63 |
# set the Maven symlink. |
64 |
set_symlink() { |
65 |
local target=$(find_target "${1}") |
66 |
remove_symlink |
67 |
ln -s "${target}" "${MVN}" || \ |
68 |
die "Couldn't set ${target} symlink." |
69 |
} |
70 |
|
71 |
### show action ### |
72 |
|
73 |
describe_show() { |
74 |
echo "Show current Maven target" |
75 |
} |
76 |
|
77 |
do_show() { |
78 |
if [[ ${#} -gt 0 ]]; then |
79 |
die -q "No parameters allowed." |
80 |
fi |
81 |
|
82 |
if [[ -L "${MVN}" ]] ; then |
83 |
get_target |
84 |
return 0 |
85 |
elif [[ -e "${MVN}" ]] ; then |
86 |
echo "(not a symlink)" >&2 |
87 |
return 1 |
88 |
else |
89 |
echo "(unset)" >&2 |
90 |
return 1 |
91 |
fi |
92 |
} |
93 |
|
94 |
### list action ### |
95 |
|
96 |
describe_list() { |
97 |
echo "List available Maven targets" |
98 |
} |
99 |
|
100 |
do_list() { |
101 |
if [[ ${#} -gt 0 ]]; then |
102 |
die -q "Usage error: no parameters allowed." |
103 |
fi |
104 |
|
105 |
local i targets |
106 |
targets=( $(find_targets) ) |
107 |
|
108 |
if [[ -n ${targets[@]} ]] ; then |
109 |
local canonicalised basename |
110 |
|
111 |
for (( i = 0 ; i < ${#targets[@]} ; i = i + 1 )) ; do |
112 |
canonicalised=$(canonicalise "${MVN}") |
113 |
basename=$(basename "${canonicalised}") |
114 |
|
115 |
if [[ "${targets[${i}]}" = "${basename}" ]] ; then |
116 |
targets[${i}]="${targets[${i}]} $(highlight '*')" |
117 |
fi |
118 |
done |
119 |
|
120 |
write_list_start "Available Maven targets:" |
121 |
write_numbered_list "${targets[@]}" |
122 |
else |
123 |
write_kv_list_entry "(none found)" "" |
124 |
fi |
125 |
} |
126 |
|
127 |
### set action ### |
128 |
|
129 |
describe_set() { |
130 |
echo "Set a new Maven target" |
131 |
} |
132 |
|
133 |
describe_set_options() { |
134 |
echo "target : Target name or number (from 'list' action)" |
135 |
} |
136 |
|
137 |
describe_set_parameters() { |
138 |
echo "<target>" |
139 |
} |
140 |
|
141 |
do_set() { |
142 |
if [[ $# -gt 1 ]]; then |
143 |
die -q "Too many parameters. Expected only one." |
144 |
fi |
145 |
|
146 |
local target=${1} |
147 |
|
148 |
if [[ -z "${target}" ]] ; then |
149 |
die -q "You didn't give me a target name or number." |
150 |
elif [[ -L "${MVN}" ]] ; then |
151 |
if ! remove_symlink ; then |
152 |
die -q "Can't remove existing Maven provider." |
153 |
elif ! set_symlink "${1}" ; then |
154 |
die -q "Can't set new Maven provider." |
155 |
fi |
156 |
elif [[ -e "${MVN}" ]] ; then |
157 |
write_warning_msg "Can't set a new Maven provider. There's a file in the way at ${MVN}. You can try removing it manually, and then re-running this command." |
158 |
else |
159 |
set_symlink "${target}" || die -q "Wasn't able to set a new provider." |
160 |
fi |
161 |
} |
162 |
|
163 |
### update action ### |
164 |
|
165 |
describe_update() { |
166 |
echo "Set the Maven target to the latest if the current target is invalid or if the given target is the latest" |
167 |
} |
168 |
|
169 |
describe_update_options() { |
170 |
echo "target (optional) : Target name (from 'list' action)" |
171 |
} |
172 |
|
173 |
describe_update_parameters() { |
174 |
echo "<target>" |
175 |
} |
176 |
|
177 |
do_update() { |
178 |
if [[ $# -gt 1 ]] ; then |
179 |
die -q "Too many parameters. Expected only one." |
180 |
fi |
181 |
|
182 |
# For pkg_postrm |
183 |
if [[ ! $(find_targets) ]]; then |
184 |
remove_symlink |
185 |
return |
186 |
fi |
187 |
|
188 |
local canonicalised=$(canonicalise "${MVN}") |
189 |
|
190 |
if [[ ! -L "${MVN}" ]] || [[ ! -f "${canonicalised}" ]] ; then |
191 |
do_set 1 |
192 |
elif [[ -n "${1}" ]] ; then |
193 |
# Check whether target name is valid. |
194 |
find_target "${1}" > /dev/null |
195 |
|
196 |
if [[ "${1}" == "$(find_target 1)" ]] ; then |
197 |
do_set 1 |
198 |
fi |
199 |
fi |
200 |
} |
201 |
|
202 |
# vim: set ft=eselect : |