FELIX-4026 Ensure Java 1.4 API use and class files
- generate 1.4 class files
- check Java 1.4 API use
- Resolve current non-Java 1.4 API use
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1468913 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/inventory/pom.xml b/inventory/pom.xml
index a421d49..306e407 100644
--- a/inventory/pom.xml
+++ b/inventory/pom.xml
@@ -41,6 +41,44 @@
<build>
<plugins>
+ <!-- Make sure to not use non Java 1.4 API -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.4</source>
+ <target>1.4</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>animal-sniffer-maven-plugin</artifactId>
+ <version>1.7</version>
+ <configuration>
+ <signature>
+ <groupId>org.codehaus.mojo.signature</groupId>
+ <artifactId>java14</artifactId>
+ <version>1.0</version>
+ </signature>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>test</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <excludePackageNames>
+ *.impl
+ </excludePackageNames>
+ </configuration>
+ </plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
diff --git a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterAdapter.java b/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterAdapter.java
index b57c55f..a5a5a6a 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterAdapter.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterAdapter.java
@@ -157,24 +157,28 @@
}
}
- /**
- * @see java.lang.Object#toString()
- */
- public String toString()
+ public InventoryPrinterDescription getDescription()
{
- return printer.getClass() + "(" + super.toString() + ")";
+ return this.description;
}
- /**
- * @see java.lang.Comparable#compareTo(java.lang.Object)
- */
public int compareTo(final Object spa)
{
return this.description.getSortKey().compareTo(((InventoryPrinterAdapter) spa).description.getSortKey());
}
- public InventoryPrinterDescription getDescription()
+ public int hashCode()
{
- return this.description;
+ return this.description.getSortKey().hashCode();
+ }
+
+ public boolean equals(final Object spa)
+ {
+ return this.description.getSortKey().equals(((InventoryPrinterAdapter) spa).description.getSortKey());
+ }
+
+ public String toString()
+ {
+ return printer.getClass() + "(" + super.toString() + ")";
}
}
diff --git a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterDescription.java b/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterDescription.java
index 3952c43..c2fe3fa 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterDescription.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterDescription.java
@@ -163,7 +163,7 @@
public String toString()
{
- return "InventoryPrinterDescription [title=" + title + ", name=" + name + ", formats=" + Arrays.toString(formats)
+ return "InventoryPrinterDescription [title=" + title + ", name=" + name + ", formats=" + Arrays.asList(formats)
+ ", sortKey=" + sortKey + "]";
}
}
diff --git a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterManagerImpl.java b/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterManagerImpl.java
index 0d564b4..7b8d007 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterManagerImpl.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterManagerImpl.java
@@ -27,8 +27,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import java.util.concurrent.ConcurrentSkipListSet;
-
+import java.util.TreeSet;
import org.apache.felix.inventory.InventoryPrinter;
import org.apache.felix.inventory.Format;
import org.apache.felix.inventory.impl.webconsole.ConsoleConstants;
@@ -62,7 +61,7 @@
private final Map allAdapters = new HashMap();
/** Used adapters. Type of the set: InventoryPrinterAdapter */
- private final Set usedAdapters = new ConcurrentSkipListSet();
+ private final Set usedAdapters = new TreeSet();
/** Registration for the web console. */
private final ServiceRegistration pluginRegistration;
@@ -112,7 +111,10 @@
{
this.allAdapters.clear();
}
- this.usedAdapters.clear();
+ synchronized (this.usedAdapters)
+ {
+ this.usedAdapters.clear();
+ }
}
/**
@@ -191,20 +193,18 @@
}
if (removeAdapter != null)
{
- final Iterator i = this.usedAdapters.iterator();
- while (i.hasNext())
- {
- if (i.next() == removeAdapter)
- {
- i.remove();
- break;
- }
- }
removeAdapter.unregisterConsole();
+ synchronized (this.usedAdapters)
+ {
+ this.usedAdapters.remove(removeAdapter);
+ }
}
if (addAdapter != null)
{
- this.usedAdapters.add(addAdapter);
+ synchronized (this.usedAdapters)
+ {
+ this.usedAdapters.add(addAdapter);
+ }
addAdapter.registerConsole(this.bundleContext, this);
}
}
@@ -222,7 +222,7 @@
while (iter.hasNext())
{
final InventoryPrinterAdapter adapter = (InventoryPrinterAdapter) iter.next();
- if (adapter.getDescription().getServiceReference().compareTo(reference) == 0)
+ if (adapter.getDescription().getServiceReference().equals(reference))
{
iter.remove();
removed = true;
@@ -239,17 +239,26 @@
}
}
}
- final Iterator iter = this.usedAdapters.iterator();
- while (iter.hasNext())
+
+ InventoryPrinterAdapter adapterToUnregister = null;
+ synchronized (this.usedAdapters)
{
- final InventoryPrinterAdapter adapter = (InventoryPrinterAdapter) iter.next();
- if (adapter.getDescription().getServiceReference().compareTo(reference) == 0)
+ final Iterator iter = this.usedAdapters.iterator();
+ while (iter.hasNext())
{
- iter.remove();
- adapter.unregisterConsole();
- break;
+ final InventoryPrinterAdapter adapter = (InventoryPrinterAdapter) iter.next();
+ if (adapter.getDescription().getServiceReference().equals(reference))
+ {
+ iter.remove();
+ adapterToUnregister = adapter;
+ break;
+ }
}
}
+ if (adapterToUnregister != null)
+ {
+ adapterToUnregister.unregisterConsole();
+ }
}
/**
@@ -259,8 +268,11 @@
*/
public InventoryPrinterHandler[] getAllHandlers()
{
- return (InventoryPrinterHandler[]) this.usedAdapters.toArray(new InventoryPrinterHandler[this.usedAdapters
- .size()]);
+ synchronized (this.usedAdapters)
+ {
+ return (InventoryPrinterHandler[]) this.usedAdapters.toArray(new InventoryPrinterHandler[this.usedAdapters
+ .size()]);
+ }
}
/**
@@ -271,13 +283,16 @@
public InventoryPrinterHandler[] getHandlers(final Format format)
{
final List result = new ArrayList();
- final Iterator i = this.usedAdapters.iterator();
- while (i.hasNext())
+ synchronized (this.usedAdapters)
{
- final InventoryPrinterAdapter printer = (InventoryPrinterAdapter) i.next();
- if (printer.supports(format))
+ final Iterator i = this.usedAdapters.iterator();
+ while (i.hasNext())
{
- result.add(printer);
+ final InventoryPrinterAdapter printer = (InventoryPrinterAdapter) i.next();
+ if (printer.supports(format))
+ {
+ result.add(printer);
+ }
}
}
return (InventoryPrinterHandler[]) result.toArray(new InventoryPrinterHandler[result.size()]);
@@ -290,13 +305,16 @@
*/
public InventoryPrinterHandler getHandler(final String name)
{
- final Iterator i = this.usedAdapters.iterator();
- while (i.hasNext())
+ synchronized (this.usedAdapters)
{
- final InventoryPrinterAdapter printer = (InventoryPrinterAdapter) i.next();
- if (name.equals(printer.getName()))
+ final Iterator i = this.usedAdapters.iterator();
+ while (i.hasNext())
{
- return printer;
+ final InventoryPrinterAdapter printer = (InventoryPrinterAdapter) i.next();
+ if (name.equals(printer.getName()))
+ {
+ return printer;
+ }
}
}
return null;
diff --git a/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/WebConsoleAdapter.java b/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/WebConsoleAdapter.java
index 24a57dc..6b79cb1 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/WebConsoleAdapter.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/WebConsoleAdapter.java
@@ -96,16 +96,22 @@
{
if (cpa.title.startsWith("%"))
{
- final String key = cpa.title.substring(1);
+ String title = cpa.title.substring(1);
+
final ResourceBundle rb = this.rbManager.getResourceBundle(reference.getBundle());
- if (rb == null || !rb.containsKey(key))
+ if (rb != null)
{
- cpa.title = key;
+ try
+ {
+ title = rb.getString(title);
+ }
+ catch (Exception e)
+ {
+ // ClassCastException, MissingResourceException
+ // ignore
+ }
}
- else
- {
- cpa.title = rb.getString(key);
- }
+ cpa.title = title;
}
if (cpa.label == null)
{