Fixed FELIX-3476 Make package admin to use SimpleWebConsolePlugin
https://issues.apache.org/jira/browse/FELIX-3476

Fixed FELIX-3474 Make package admin work with J9 and other embedded VMs
https://issues.apache.org/jira/browse/FELIX-3474


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1330237 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole-plugins/packageadmin/src/main/resources/OSGI-INF/l10n/bundle.properties b/webconsole-plugins/packageadmin/src/main/resources/OSGI-INF/l10n/bundle.properties
new file mode 100644
index 0000000..91c4163
--- /dev/null
+++ b/webconsole-plugins/packageadmin/src/main/resources/OSGI-INF/l10n/bundle.properties
@@ -0,0 +1,46 @@
+#Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#
+# Web Console strings for reference all strings here are commented.
+# This file may be used to produce a translation of the strings
+#
+# Note that properties files are ISO-8859-1 encoded. To provide translations
+# for languages requiring different character encodings, you may use the
+# native2ascii Maven Plugin from http://mojo.codehaus.org/native2ascii-maven-plugin/
+# to translate the natively encoded files to ISO-8859-1 during bundle build
+#
+# Translations requiring non-ISO-8859-1 encoding are placed in the
+# src/main/native2ascii/OSGI-INF/l10n folder and are converted using said
+# plugin while building the bundle
+#
+pluginTitle=Packages
+find.label=Packages/Classes: 
+find.btn=Find
+find.tip=Enter a list of package or class names
+
+header.package.name=Package
+header.package.ver=Version
+header.exporting.bundle=Exported by
+header.maven.deps=Maven Dependency
+no.exporters.found=No exporting bundle(s) found
+no.maven.found=No maven information available
+status.initial=Please enter a list of package or class names and click the find button
+status.find={0} result(s) found
+
+# duplicates
+find.dups=Find Duplicate Exports
+status.dups={0} duplicate package(s) found
+header.importing.bundle=Used by bundle(s)
diff --git a/webconsole-plugins/packageadmin/src/main/resources/OSGI-INF/l10n/bundle_bg.properties b/webconsole-plugins/packageadmin/src/main/resources/OSGI-INF/l10n/bundle_bg.properties
new file mode 100644
index 0000000..8b96e6a
--- /dev/null
+++ b/webconsole-plugins/packageadmin/src/main/resources/OSGI-INF/l10n/bundle_bg.properties
@@ -0,0 +1,46 @@
+#Licensed to the Apache Software Foundation (ASF) under one or more

+# contributor license agreements.  See the NOTICE file distributed with

+# this work for additional information regarding copyright ownership.

+# The ASF licenses this file to You under the Apache License, Version 2.0

+# (the "License"); you may not use this file except in compliance with

+# the License.  You may obtain a copy of the License at

+#

+#      http://www.apache.org/licenses/LICENSE-2.0

+#

+# Unless required by applicable law or agreed to in writing, software

+# distributed under the License is distributed on an "AS IS" BASIS,

+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+# See the License for the specific language governing permissions and

+# limitations under the License.

+

+#

+# Web Console strings for reference all strings here are commented.

+# This file may be used to produce a translation of the strings

+#

+# Note that properties files are ISO-8859-1 encoded. To provide translations

+# for languages requiring different character encodings, you may use the

+# native2ascii Maven Plugin from http://mojo.codehaus.org/native2ascii-maven-plugin/

+# to translate the natively encoded files to ISO-8859-1 during bundle build

+#

+# Translations requiring non-ISO-8859-1 encoding are placed in the

+# src/main/native2ascii/OSGI-INF/l10n folder and are converted using said

+# plugin while building the bundle

+#

+pluginTitle=Java пакети

+find.label=Пакети/класове: 

+find.btn=Търсене

+find.tip=Въведете списък с пакети или имена на класове

+

+header.package.name=Пакет

+header.package.ver=Версия

+header.exporting.bundle=Предостъпен от

+header.maven.deps=Maven информация

+no.exporters.found=Няма бъндъли предотставящи този пакет

+no.maven.found=Няма достъпна Maven информация

+status.initial=Моля въведете списък с пакети или имена на класове и натиснете бутона "Търсене"

+status.find=Открити са {0} резултата

+

+# duplicates

+find.dups=Търсене на дублирани пакети

+status.dups=Открити са {0} дуплирани пакета

+header.importing.bundle=Използван от бъндъл(и)

diff --git a/webconsole-plugins/packageadmin/src/main/resources/res/plugin.css b/webconsole-plugins/packageadmin/src/main/resources/res/plugin.css
new file mode 100644
index 0000000..474a443
--- /dev/null
+++ b/webconsole-plugins/packageadmin/src/main/resources/res/plugin.css
@@ -0,0 +1,19 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one or more

+ * contributor license agreements.  See the NOTICE file distributed with

+ * this work for additional information regarding copyright ownership.

+ * The ASF licenses this file to You under the Apache License, Version 2.0

+ * (the "License"); you may not use this file except in compliance with

+ * the License.  You may obtain a copy of the License at

+ *

+ *      http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+

+td.mvn { white-space: pre-wrap }

+#findField { width: 50% }

diff --git a/webconsole-plugins/packageadmin/src/main/resources/res/plugin.html b/webconsole-plugins/packageadmin/src/main/resources/res/plugin.html
new file mode 100644
index 0000000..d4fbae3
--- /dev/null
+++ b/webconsole-plugins/packageadmin/src/main/resources/res/plugin.html
@@ -0,0 +1,63 @@
+<script type="text/javascript" src="${pluginRoot}/res/plugin.js"></script>
+<script type="text/javascript">
+// <![CDATA[
+var i18n = {
+	statusFind : '${status.find}',
+	statusDups : '${status.dups}'
+}
+// ]]>
+</script>
+
+<!-- status line -->
+<p class="statline">${status.initial}</p>
+
+<!-- table caption -->
+<form method="post" action="${pluginRoot}">
+	<div class="ui-widget-header ui-corner-top buttonGroup">
+		<span>${find.label}</span>
+		<input type="text" id="findField" title="${find.tip}" />
+		<button id="findButton">${find.btn}</button>
+		<button id="findDups">${find.dups}</button>
+	</div>
+</form>
+
+<!-- table find results -->
+<table class="tablesorter nicetable noauto" id="findTable">
+	<thead>
+		<tr>
+			<th>${header.package.name}</th>
+			<th>${header.package.ver}</th>
+			<th>${header.exporting.bundle}</th>
+			<th>${header.maven.deps}</th>
+		</tr>
+	</thead>
+	<tbody>
+		<tr>
+			<td class="pkg">&nbsp;</td>
+			<td class="ver">-</td>
+			<td class="bnd">${no.exporters.found}</td>
+			<td class="mvn">${no.maven.found}</td>
+		</tr>
+	</tbody>
+</table>
+
+<!-- duplicates -->
+<table class="nicetable noauto ui-helper-hidden" id="dupsTable">
+	<thead>
+		<tr>
+			<th>${header.package.name}</th>
+			<th>${header.package.ver}</th>
+			<th>${header.exporting.bundle}</th>
+			<th>${header.importing.bundle}</th>
+		</tr>
+	</thead>
+	<tbody>
+		<tr>
+			<td class="pkg">-</td>
+			<td class="ver">-</td>
+			<td class="exp">-</td>
+			<td class="imp">&nbsp;</td>
+		</tr>
+	</tbody>
+</table>
+
diff --git a/webconsole-plugins/packageadmin/src/main/resources/res/plugin.js b/webconsole-plugins/packageadmin/src/main/resources/res/plugin.js
new file mode 100644
index 0000000..8468103
--- /dev/null
+++ b/webconsole-plugins/packageadmin/src/main/resources/res/plugin.js
@@ -0,0 +1,120 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one or more

+ * contributor license agreements.  See the NOTICE file distributed with

+ * this work for additional information regarding copyright ownership.

+ * The ASF licenses this file to You under the Apache License, Version 2.0

+ * (the "License"); you may not use this file except in compliance with

+ * the License.  You may obtain a copy of the License at

+ *

+ *      http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+

+var findField = false;

+var findButton = false;

+var findTable = false;

+var findTableBody = false;

+var findTableTemplate = false;

+var dupsTable = false;

+var dupsTableBody = false;

+var dupsTableTemplate = false;

+var statline = false;

+

+function linkBundle(bnd) { return '<a href="{0}/bundles/{1}">{2} ({3})</a>'.msgFormat(appRoot, bnd.bid, bnd.bsn, bnd.bid) }

+

+$(function() {

+	findField = $('#findField');

+	statline = $('.statline');

+

+	findTable = $('#findTable').tablesorter({

+		headers:{

+			1:{sorter: false},

+			3:{sorter: false}

+		},

+		textExtraction:mixedLinksExtraction

+	});

+	findTableBody = findTable.find('tbody');

+	findTableTemplate = findTableBody.find('tr').clone();

+	findTableBody.empty();

+

+	dupsTable = $('#dupsTable');

+	dupsTableBody = dupsTable.find('tbody');

+	dupsTableTemplate = dupsTableBody.find('tr').clone();

+

+	$('#findButton').click(function() {

+		if(!findField.val()) {

+			findField.addClass('ui-state-error');

+		} else {

+			findField.removeClass('ui-state-error');

+

+			$.post(pluginRoot, { 'action': 'deps', 'plugin.find' : findField.val() }, function(response) {

+				dupsTable.addClass('ui-helper-hidden')

+				findTable.removeClass('ui-helper-hidden');

+				findTableBody.empty();

+				if (response.packages) for(var i in response.packages) {

+					var pkg = response.packages[i];

+					if (pkg.exporters) for(var i in pkg.exporters) {

+						var exp = pkg.exporters[i];

+						var tr = findTableTemplate.clone()

+							.find('td.pkg').text(pkg.name).end()

+							.find('td.ver').text(exp.version).end()

+							.find('td.bnd').html(linkBundle(exp)).end()

+							.appendTo(findTableBody);

+						if (response.maven && response.maven[exp.bid]) {

+							var mvn = response.maven[exp.bid];

+							mvn['scope'] = 'provided';

+							var txt = ''; for (var p in mvn) {

+								txt += '\t<' + p + '>' + mvn[p] + '</' + p + '>\n';

+							}

+							tr.find('td.mvn').text('<dependency>\n' + txt + '</dependency>');

+						}

+					} else {

+						var tr = findTableTemplate.clone()

+							.find('td.pkg').text(pkg.name).end()

+							.appendTo(findTableBody);

+					}

+				}

+				statline.text(i18n.statusFind.msgFormat(response.packages ? response.packages.length : 0));

+				findTable.trigger('update').trigger('applyWidgets')

+			}, 'json');

+		}

+		return false;

+	});

+

+	$('#findDups').click(function() {

+		$.post(pluginRoot, { 'action': 'dups' }, function(response) {

+			findTable.addClass('ui-helper-hidden');

+			dupsTable.removeClass('ui-helper-hidden')

+			dupsTableBody.empty();

+			if (response) for(var i in response) {

+				var pkg = response[i];

+				if (pkg.entries) for (var i in pkg.entries) {

+					var exp = pkg.entries[i];

+					var td = dupsTableTemplate.clone()

+						.find('td.pkg').text(pkg.name).end()

+						.find('td.ver').text(exp.version).end()

+						.find('td.exp').html(linkBundle(exp)).end();

+					if (exp.importers) {

+						var txt = ''; for(var j in exp.importers) txt += linkBundle(exp.importers[j]) + '<br/>';

+						td.find('td.imp').html( txt );

+					}

+					if (i==0) {

+						td.find('td.pkg').attr('rowspan', pkg.entries.length);

+					} else {

+						td.find('td.pkg').remove();

+					}

+					td.appendTo(dupsTableBody);

+				}

+			}

+			statline.text(i18n.statusDups.msgFormat(response ? response.length : 0));

+		}, 'json');

+

+		return false;

+	});

+

+})