FELIX-6375 : Require Java 8 as minimum version
diff --git a/inventory/changelog.txt b/inventory/changelog.txt
index 918448f..191a312 100644
--- a/inventory/changelog.txt
+++ b/inventory/changelog.txt
@@ -1,5 +1,7 @@
Changes in 1.1.0
----------------
+** Improvement
+ * [FELIX-6375] - Require Java 8 as minimum version
** Bug
* [FELIX-6371] - JSONConfigurationWriter does not escape backslash and other chars
diff --git a/inventory/pom.xml b/inventory/pom.xml
index 162f2fc..3fc303f 100644
--- a/inventory/pom.xml
+++ b/inventory/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.felix</groupId>
<artifactId>felix-parent</artifactId>
- <version>4</version>
+ <version>7</version>
<relativePath>../pom/pom.xml</relativePath>
</parent>
@@ -45,14 +45,14 @@
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<excludePackageNames>
- *.impl
+ org.apache.felix.inventory.impl:org.apache.felix.inventory.impl.helper:org.apache.felix.inventory.impl.webconsole
</excludePackageNames>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
- <version>3.3.0</version>
+ <version>5.1.1</version>
<extensions>true</extensions>
<configuration>
<instructions>
@@ -68,9 +68,6 @@
javax.servlet.http;resolution:=optional,
*
</Import-Package>
- <Export-Package>
- org.apache.felix.inventory
- </Export-Package>
<DynamicImport-Package>
javax.servlet, javax.servlet.http
</DynamicImport-Package>
@@ -108,6 +105,8 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
+ <version>4.13.1</version>
+ <scope>test</scope>
</dependency>
</dependencies>
</project>
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 6d53789..419b601 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
@@ -37,18 +37,19 @@
*
* The adapter simplifies accessing and working with the inventory printer.
*/
-public class InventoryPrinterAdapter implements InventoryPrinterHandler, Comparable
+public class InventoryPrinterAdapter implements InventoryPrinterHandler, Comparable<InventoryPrinterAdapter>
{
/**
* Comparator for adapters based on the service ranking.
*/
- public static final Comparator RANKING_COMPARATOR = new Comparator()
+ public static final Comparator<InventoryPrinterAdapter> RANKING_COMPARATOR = new Comparator<InventoryPrinterAdapter>()
{
- public int compare(final Object o1, final Object o2)
+ @Override
+ public int compare(final InventoryPrinterAdapter o1, final InventoryPrinterAdapter o2)
{
- return ((InventoryPrinterAdapter) o1).description.compareTo(((InventoryPrinterAdapter) o2).description);
+ return o1.description.compareTo(o2.description);
}
};
@@ -77,18 +78,20 @@
final Object value = this.description.getServiceReference().getProperty(InventoryPrinter.WEBCONSOLE);
if (value == null || !"false".equalsIgnoreCase(value.toString()))
{
- final Dictionary props = new Hashtable();
+ final Dictionary<String, Object> props = new Hashtable<>();
props.put(ConsoleConstants.PLUGIN_LABEL, "status-" + this.description.getName());
props.put(ConsoleConstants.PLUGIN_TITLE, this.description.getTitle());
props.put(ConsoleConstants.PLUGIN_CATEGORY, ConsoleConstants.WEB_CONSOLE_CATEGORY);
this.registration = context.registerService(ConsoleConstants.INTERFACE_SERVLET, new ServiceFactory()
{
+ @Override
public void ungetService(final Bundle bundle, final ServiceRegistration registration, final Object service)
{
// nothing to do
}
+ @Override
public Object getService(final Bundle bundle, final ServiceRegistration registration)
{
return new WebConsolePlugin(manager, description.getName());
@@ -111,6 +114,7 @@
/**
* The human readable title for the inventory printer.
*/
+ @Override
public String getTitle()
{
return this.description.getTitle();
@@ -119,6 +123,7 @@
/**
* The unique name of the printer.
*/
+ @Override
public String getName()
{
return this.description.getName();
@@ -127,6 +132,7 @@
/**
* All supported formats.
*/
+ @Override
public Format[] getFormats()
{
return this.description.getFormats();
@@ -136,6 +142,7 @@
* @see org.apache.felix.inventory.ZipAttachmentProvider#addAttachments(java.util.zip.ZipOutputStream,
* java.lang.String)
*/
+ @Override
public void addAttachments(final ZipOutputStream zos, final String namePrefix) throws IOException
{
if (printer instanceof ZipAttachmentProvider)
@@ -147,6 +154,7 @@
/**
* Whether the printer supports this format.
*/
+ @Override
public boolean supports(final Format format)
{
for (int i = 0; i < this.description.getFormats().length; i++)
@@ -163,6 +171,7 @@
* @see org.apache.felix.inventory.InventoryPrinter#print(org.apache.felix.inventory.Format,
* java.io.PrintWriter)
*/
+ @Override
public void print(final PrintWriter printWriter, final Format format, final boolean isZip)
{
if (this.supports(format))
@@ -176,21 +185,28 @@
return this.description;
}
- public int compareTo(final Object spa)
+ @Override
+ public int compareTo(final InventoryPrinterAdapter spa)
{
- return this.description.getSortKey().compareTo(((InventoryPrinterAdapter) spa).description.getSortKey());
+ return this.description.getSortKey().compareTo(spa.description.getSortKey());
}
+ @Override
public int hashCode()
{
return this.description.getSortKey().hashCode();
}
+ @Override
public boolean equals(final Object spa)
{
+ if ( !(spa instanceof InventoryPrinterAdapter)) {
+ return false;
+ }
return this.description.getSortKey().equals(((InventoryPrinterAdapter) spa).description.getSortKey());
}
+ @Override
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 c2fe3fa..fc2e4bf 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
@@ -18,15 +18,17 @@
import java.util.ArrayList;
import java.util.Arrays;
-import org.apache.felix.inventory.InventoryPrinter;
+import java.util.List;
+
import org.apache.felix.inventory.Format;
+import org.apache.felix.inventory.InventoryPrinter;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
/**
* Helper class for a configuration printer.
*/
-public class InventoryPrinterDescription implements Comparable
+public class InventoryPrinterDescription implements Comparable<InventoryPrinterDescription>
{
private final ServiceReference reference;
@@ -58,7 +60,7 @@
else if (formatsCfg instanceof String[])
{
final String[] formatsCfgArray = (String[]) formatsCfg;
- final ArrayList formatList = new ArrayList();
+ final List<Format> formatList = new ArrayList<>();
for (int i = 0; i < formatsCfgArray.length; i++)
{
final Format format = Format.valueOf(formatsCfgArray[i]);
@@ -69,7 +71,7 @@
}
if (!formatList.isEmpty())
{
- formats = (Format[]) formatList.toArray(new Format[formatList.size()]);
+ formats = formatList.toArray(new Format[formatList.size()]);
}
}
@@ -146,21 +148,25 @@
/**
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
- public int compareTo(final Object spa)
+ @Override
+ public int compareTo(final InventoryPrinterDescription spa)
{
- return this.reference.compareTo(((InventoryPrinterDescription) spa).reference);
+ return this.reference.compareTo(spa.reference);
}
+ @Override
public boolean equals(final Object obj)
{
return this.reference.equals(obj);
}
+ @Override
public int hashCode()
{
return this.reference.hashCode();
}
+ @Override
public String toString()
{
return "InventoryPrinterDescription [title=" + title + ", name=" + name + ", formats=" + Arrays.asList(formats)
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 327caf6..abd7508 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
@@ -25,7 +25,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
@@ -46,23 +45,22 @@
* based on their name. If more than one printer with the same name
* is registered, the one with highest service ranking is used.
*/
-public class InventoryPrinterManagerImpl implements ServiceTrackerCustomizer
+public class InventoryPrinterManagerImpl implements ServiceTrackerCustomizer<InventoryPrinter, InventoryPrinter>
{
/** Bundle Context . */
private final BundleContext bundleContext;
/** Service tracker for Inventory printers. */
- private final ServiceTracker cfgPrinterTracker;
+ private final ServiceTracker<InventoryPrinter, InventoryPrinter> cfgPrinterTracker;
/**
- * All adapters mapped by their name. Type of the map: String,
- * List<InventoryPrinterAdapter>
+ * All adapters mapped by their name.
*/
- private final Map allAdapters = new HashMap();
+ private final Map<String, List<InventoryPrinterAdapter>> allAdapters = new HashMap<>();
- /** Used adapters. Type of the set: InventoryPrinterAdapter */
- private final Set usedAdapters = new TreeSet();
+ /** Used adapters. */
+ private final Set<InventoryPrinterAdapter> usedAdapters = new TreeSet<>();
/** Registration for the web console. */
private final ServiceRegistration pluginRegistration;
@@ -77,20 +75,22 @@
public InventoryPrinterManagerImpl(final BundleContext btx) throws InvalidSyntaxException
{
this.bundleContext = btx;
- this.cfgPrinterTracker = new ServiceTracker(this.bundleContext, InventoryPrinter.SERVICE, this);
+ this.cfgPrinterTracker = new ServiceTracker<>(this.bundleContext, InventoryPrinter.class, this);
this.cfgPrinterTracker.open();
- final Dictionary props = new Hashtable();
+ final Dictionary<String, Object> props = new Hashtable<>();
props.put(ConsoleConstants.PLUGIN_LABEL, ConsoleConstants.NAME);
props.put(ConsoleConstants.PLUGIN_TITLE, ConsoleConstants.TITLE);
props.put(ConsoleConstants.PLUGIN_CATEGORY, ConsoleConstants.WEB_CONSOLE_CATEGORY);
this.pluginRegistration = btx.registerService(ConsoleConstants.INTERFACE_SERVLET, new ServiceFactory()
{
+ @Override
public void ungetService(final Bundle bundle, final ServiceRegistration registration, final Object service)
{
// nothing to do
}
+ @Override
public Object getService(final Bundle bundle, final ServiceRegistration registration)
{
return new DefaultWebConsolePlugin(InventoryPrinterManagerImpl.this);
@@ -121,12 +121,13 @@
/**
* @see org.osgi.util.tracker.ServiceTrackerCustomizer#addingService(org.osgi.framework.ServiceReference)
*/
- public Object addingService(final ServiceReference reference)
+ @Override
+ public InventoryPrinter addingService(final ServiceReference<InventoryPrinter> reference)
{
- final Object obj = this.bundleContext.getService(reference);
+ final InventoryPrinter obj = this.bundleContext.getService(reference);
if (obj != null)
{
- this.addService(reference, (InventoryPrinter) obj);
+ this.addService(reference, obj);
}
return obj;
@@ -136,23 +137,25 @@
* @see org.osgi.util.tracker.ServiceTrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference,
* java.lang.Object)
*/
- public void modifiedService(final ServiceReference reference, final Object service)
+ @Override
+ public void modifiedService(final ServiceReference<InventoryPrinter> reference, final InventoryPrinter service)
{
this.removeService(reference);
- this.addService(reference, (InventoryPrinter) service);
+ this.addService(reference, service);
}
/**
* @see org.osgi.util.tracker.ServiceTrackerCustomizer#removedService(org.osgi.framework.ServiceReference,
* java.lang.Object)
*/
- public void removedService(final ServiceReference reference, final Object service)
+ @Override
+ public void removedService(final ServiceReference<InventoryPrinter> reference, final InventoryPrinter service)
{
this.removeService(reference);
this.bundleContext.ungetService(reference);
}
- private void addService(final ServiceReference reference, final InventoryPrinter obj)
+ private void addService(final ServiceReference<InventoryPrinter> reference, final InventoryPrinter obj)
{
final InventoryPrinterDescription desc = new InventoryPrinterDescription(reference);
final InventoryPrinterAdapter adapter = new InventoryPrinterAdapter(desc, obj);
@@ -163,17 +166,17 @@
final String key = adapter.getName();
synchronized (this.allAdapters)
{
- List list = (List) this.allAdapters.get(key);
+ List<InventoryPrinterAdapter> list = this.allAdapters.get(key);
final InventoryPrinterAdapter first;
if (list == null)
{
- list = new LinkedList();
+ list = new LinkedList<>();
this.allAdapters.put(key, list);
first = null;
}
else
{
- first = (InventoryPrinterAdapter) list.get(0);
+ first = list.get(0);
}
list.add(adapter);
Collections.sort(list, InventoryPrinterAdapter.RANKING_COMPARATOR);
@@ -210,19 +213,19 @@
}
}
- private void removeService(final ServiceReference reference)
+ private void removeService(final ServiceReference<InventoryPrinter> reference)
{
synchronized (this.allAdapters)
{
- final Iterator i = this.allAdapters.entrySet().iterator();
+ final Iterator<Map.Entry<String, List<InventoryPrinterAdapter>>> i = this.allAdapters.entrySet().iterator();
while (i.hasNext())
{
- final Map.Entry entry = (Entry) i.next();
- final Iterator iter = ((List) entry.getValue()).iterator();
+ final Map.Entry<String, List<InventoryPrinterAdapter>> entry = i.next();
+ final Iterator<InventoryPrinterAdapter> iter = entry.getValue().iterator();
boolean removed = false;
while (iter.hasNext())
{
- final InventoryPrinterAdapter adapter = (InventoryPrinterAdapter) iter.next();
+ final InventoryPrinterAdapter adapter = iter.next();
if (adapter.getDescription().getServiceReference().equals(reference))
{
iter.remove();
@@ -232,7 +235,7 @@
}
if (removed)
{
- if (((List) entry.getValue()).size() == 0)
+ if (entry.getValue().size() == 0)
{
i.remove();
}
@@ -244,10 +247,10 @@
InventoryPrinterAdapter adapterToUnregister = null;
synchronized (this.usedAdapters)
{
- final Iterator iter = this.usedAdapters.iterator();
+ final Iterator<InventoryPrinterAdapter> iter = this.usedAdapters.iterator();
while (iter.hasNext())
{
- final InventoryPrinterAdapter adapter = (InventoryPrinterAdapter) iter.next();
+ final InventoryPrinterAdapter adapter = iter.next();
if (adapter.getDescription().getServiceReference().equals(reference))
{
iter.remove();
@@ -275,20 +278,20 @@
*/
public InventoryPrinterHandler[] getHandlers(final Format format)
{
- final List result = new ArrayList();
+ final List<InventoryPrinterAdapter> result = new ArrayList<>();
synchronized (this.usedAdapters)
{
- final Iterator i = this.usedAdapters.iterator();
+ final Iterator<InventoryPrinterAdapter> i = this.usedAdapters.iterator();
while (i.hasNext())
{
- final InventoryPrinterAdapter printer = (InventoryPrinterAdapter) i.next();
+ final InventoryPrinterAdapter printer = i.next();
if (format == null || printer.supports(format))
{
result.add(printer);
}
}
}
- return (InventoryPrinterHandler[]) result.toArray(new InventoryPrinterHandler[result.size()]);
+ return result.toArray(new InventoryPrinterHandler[result.size()]);
}
/**
@@ -300,10 +303,10 @@
{
synchronized (this.usedAdapters)
{
- final Iterator i = this.usedAdapters.iterator();
+ final Iterator<InventoryPrinterAdapter> i = this.usedAdapters.iterator();
while (i.hasNext())
{
- final InventoryPrinterAdapter printer = (InventoryPrinterAdapter) i.next();
+ final InventoryPrinterAdapter printer = i.next();
if (name.equals(printer.getName()))
{
return printer;
diff --git a/inventory/src/test/java/org/apache/felix/inventory/FormatTest.java b/inventory/src/test/java/org/apache/felix/inventory/FormatTest.java
index 5d3131c..54a00ef 100644
--- a/inventory/src/test/java/org/apache/felix/inventory/FormatTest.java
+++ b/inventory/src/test/java/org/apache/felix/inventory/FormatTest.java
@@ -18,12 +18,14 @@
*/
package org.apache.felix.inventory;
+import org.junit.Test;
+
import junit.framework.TestCase;
-public class FormatTest extends TestCase
+public class FormatTest
{
- public void test_valueOf()
+ @Test public void test_valueOf()
{
TestCase.assertSame(Format.TEXT, Format.valueOf("TEXT"));
TestCase.assertSame(Format.JSON, Format.valueOf("JSON"));
@@ -40,14 +42,14 @@
TestCase.assertNull(Format.valueOf("unsupported_name"));
}
- public void test_toString()
+ @Test public void test_toString()
{
TestCase.assertEquals("TEXT", Format.TEXT.toString());
TestCase.assertEquals("JSON", Format.JSON.toString());
TestCase.assertEquals("HTML", Format.HTML.toString());
}
- public void test_equals()
+ @Test public void test_equals()
{
TestCase.assertTrue(Format.TEXT.equals(Format.TEXT));
TestCase.assertFalse(Format.TEXT.equals(Format.JSON));
diff --git a/inventory/src/test/java/org/apache/felix/inventory/impl/helper/JSONConfigurationWriterTest.java b/inventory/src/test/java/org/apache/felix/inventory/impl/helper/JSONConfigurationWriterTest.java
index 029bd09..8754b2a 100644
--- a/inventory/src/test/java/org/apache/felix/inventory/impl/helper/JSONConfigurationWriterTest.java
+++ b/inventory/src/test/java/org/apache/felix/inventory/impl/helper/JSONConfigurationWriterTest.java
@@ -21,12 +21,11 @@
import java.io.StringWriter;
import org.junit.Assert;
+import org.junit.Test;
-import junit.framework.TestCase;
+public class JSONConfigurationWriterTest {
-public class JSONConfigurationWriterTest extends TestCase {
-
- public void test_escaping() {
+ @Test public void test_escaping() {
final StringWriter out = new StringWriter();
final JSONConfigurationWriter w = new JSONConfigurationWriter(out);
w.startJSONWrapper();