summaryrefslogtreecommitdiff
blob: 599298d6ff08060faa91d9363762c4f5053e8021 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/eclipse-ext.eclass,v 1.8 2005/02/13 01:22:44 karltk Exp $

# Author: Karl Trygve Kalleberg <karltk@gentoo.org>
# Maintainer: Karl Trygve Kalleberg <karltk@gentoo.org>

inherit base eutils
ECLASS="eclipse-ext"
INHERITED="${INHERITED} ${ECLASS}"
IUSE="${IUSE}"
SLOT="${SLOT}"

# Must be listed in oldest->newest order!
known_eclipse_slots="2 3 3.1"

# These should not be reinitialized if previously set
# (check allows require-slot in pkg_setup)

[ -z "${eclipse_ext_type}" ] && \
	eclipse_ext_type="source"

[ -z "${eclipse_ext_slot}" ] && \
	eclipse_ext_slot="0"

[ -z "${eclipse_ext_basedir}" ] && \
	eclipse_ext_basedir="/usr/$(get_libdir)/eclipse-extensions-${eclipse_ext_slot}/eclipse"

[ -z "${eclipse_ext_platformdir}" ] && \
	eclipse_ext_platformdir="/usr/$(get_libdir)/eclipse-${eclipse_ext_slot}"

# ---------------------------------------------------------------------------
# @private _find-optimum-slot
#
# Look for a given SLOT. If not found return the least highest SLOT
# available.
#
# @param $1 - SLOT of Eclipse SDK that is most desired
# @return 0 - all is well, non-zero otherwise
# ---------------------------------------------------------------------------
function _find-optimum-slot {
	local found=false

	for x in ${known_eclipse_slots} ; do
		if [ "$1" == "$x" ] ; then
			found=true
		fi
		if [ "${found}" == "true" ] && [ -d /usr/$(get_libdir)/eclipse-${x} ] ; then
			echo $x
			return 0
		fi
	done
	echo ""
	return 1
}

# ---------------------------------------------------------------------------
# @public require-slot
#
# Ensure that an Eclipse SDK is actually available for the given slot;
# sets internal state to install for selected slot.
#
# @param $1 - SLOT of Eclipse SDK that required for this ebuild
# alternatively
# @return 0 - all is well, non-zero otherwise
# ---------------------------------------------------------------------------
function eclipse-ext_require-slot {

	local slot=$(_find-optimum-slot $1)

	if [ -z "${slot}" ] ; then
		eerror "Cannot find any Eclipse SDK supporting slot $1"
		return 1
	fi

	if [ "${slot}" != "$1" ] ; then
		ewarn "Slot $1 could not be satisfied, installing for ${slot} instead"
	fi

	eclipse_ext_slot=${slot}
	eclipse_ext_basedir="/usr/$(get_libdir)/eclipse-extensions-${eclipse_ext_slot}/eclipse"
	eclipse_ext_platformdir="/usr/$(get_libdir)/eclipse-${eclipse_ext_slot}"

	return 0
}

# ---------------------------------------------------------------------------
# @public create-plugin-layout
#
# Create directory infrastructure for binary-only plugins so that the installed
# Eclipse SDK will see them. Sets internal state for installing as source or
# binary.
#
# @param $1 - type of ebuild, "source" or "binary"
# @return   - nothing
# ---------------------------------------------------------------------------
function eclipse-ext_create-ext-layout {
	local type=$1
	if [ "${type}" == "binary" ] ; then
		eclipse_ext_basedir="/opt/eclipse-extensions-${eclipse_ext_slot}/eclipse"
		dodir ${eclipse_ext_basedir}/{features,plugins}
		touch ${D}/${eclipse_ext_basedir}/.eclipseextension
	else
		eclipse_ext_basedir="/usr/$(get_libdir)/eclipse-extensions-${eclipse_ext_slot}/eclipse"
		dodir ${eclipse_ext_basedir}/{features,plugins}
		touch ${D}/${eclipse_ext_basedir}/.eclipseextension
	fi
}

# ---------------------------------------------------------------------------
# @public install-features
#
# Installs one or multiple features into the plugin directory for the required
# Eclipse SDK.
#
# Note: You must call require-slot prior to calling install-features. If your
# ebuild is for a binary-only plugin, you must also call create-plugin-layout
# prior to calling install-features.
#
# @param $* - feature directories
# @return 0 - if all is well
#         1 - if require-slot was not called
# ---------------------------------------------------------------------------
function eclipse-ext_install-features {

	if [ ${eclipse_ext_slot} == 0 ] ; then
		eerror "You must call require-slot prior to calling ${FUNCNAME}!"
		return 1
	fi

	for x in $* ; do
		if [ -d "$x" ] && [ -f $x/feature.xml ] ; then
			cp -a $x ${D}/${eclipse_ext_basedir}/features
		else
			eerror "$x not a feature directory!"
		fi
	done
}

# ---------------------------------------------------------------------------
# @public install-plugins
#
# Installs one or multiple plugins into the plugin directory for the required
# Eclipse SDK.
#
# Note: You must call require-slot prior to calling install-features. If your
# ebuild is for a binary-only plugin, you must also call create-plugin-layout
# prior to calling install-features.
#
# @param $* - plugin directories
# @return   - nothing
# ---------------------------------------------------------------------------

function eclipse-ext_install-plugins {

	if [ ${eclipse_ext_slot} == 0 ] ; then
		eerror "You must call require-slot prior to calling ${FUNCNAME}!"
		return 1
	fi

	for x in $* ; do
		if [ -d "$x" ] && ( [ -f "$x/plugin.xml" ] || [ -f "$x/fragment.xml" ] ) ; then
			cp -a $x ${D}/${eclipse_ext_basedir}/plugins
		else
			eerror "$x not a plugin directory!"
		fi
	done
}

function eclipse-ext_pkg_postinst() {
	einfo "For tips, tricks and general info on running Eclipse on Gentoo, go to:"
	einfo "http://gentoo-wiki.com/Eclipse"
}

function pkg_postinst() {
	eclipse-ext_pkg_postinst
}

# ---------------------------------------------------------------------------
# @public get-classpath
#
# Tries to parse out a classpath string from a build.properties file. Is very
# stupid: Assumes it's a one-liner on the form classpath = comma:separated:
#
# @param $1 - name of the file (typically build.properties)
# @param $2 - name of the one-liner env var (default 'classpath')
# @return - echo of space-separated classpath entries.
# ---------------------------------------------------------------------------

eclipse-ext_get-classpath() {

        local file=$1
        local envvar="classpath"

        if [ "$1" == "build.properties" ] ; then
                if [ ! -z "$2" ] ; then
                        envvar="$2"
                fi
        fi

        echo "$(cat ${FILESDIR}/build.properties-${PV} | sed "s/.*=//" | tr ';' ' ')"
}

_path-dissecter() {
        echo $1 | sed -r "s/.*\/([^/]+)_([0-9.]+)\/(.*)/\\${2}/"
}

_get-plugin-name() {
        _path-dissecter $1 1
}

_get-plugin-version() {
        _path-dissecter $1 2
}

_get-plugin-content() {
        _path-dissecter $1 3
}

# ---------------------------------------------------------------------------
# @public resolve-jars
#
# Takes a space-separated list of plugin_version/subdirs/file.jar entries and
# tries to resolve the version for the plugin against the chosen eclipse version
# (set by require-slot).
#
# Note: You must call require-slot prior to calling resolve-jars.
#
# @param $1 - string with space-separated plugin/jarfile
# @return - echo of :-separated resolved files
# ---------------------------------------------------------------------------
eclipse-ext_resolve-jars() {

        local resolved=""

        for x in $1 ; do
                local jarfile=$(_get-plugin-content $x)
                local name="$(_get-plugin-name $x)"
                local x=$(echo ${eclipse_ext_platformdir}/plugins/${name}_*/${jarfile})
                if [ -f ${x} ] ; then
                        resolved="${resolved}:$x"
                else
                        :
                        #echo "Warning: did not find ${name}"
                fi
        done
        echo ${resolved}
}