From a681d5e7501c1dfa65dade5db9322e30a62a9361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Mon, 21 Dec 2015 22:54:28 +0200 Subject: [PATCH 1/5] Specify javac source and target via maven.compiler.* properties --- pom.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index bbe50345cb..35d90eb0a9 100644 --- a/pom.xml +++ b/pom.xml @@ -99,6 +99,9 @@ UTF-8 UTF-8 + 1.7 + 1.7 + true - 1.7 - 1.7 true ${javac-compiler-id} From 8fbb9b638551baa4bd118e2b8b4e7691c074cf47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Mon, 21 Dec 2015 22:56:06 +0200 Subject: [PATCH 2/5] Upgrade maven-pmd-plugin to 3.6, remove redundant config Recent versions default to project.build.sourceEncoding and maven.compiler.target. --- pom.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 35d90eb0a9..c7e27b5c68 100644 --- a/pom.xml +++ b/pom.xml @@ -893,12 +893,10 @@ org.apache.maven.plugins maven-pmd-plugin - 3.0.1 + 3.6 true - utf-8 100 - 1.5 From 93a53e1cda23ae3a186cd8956ebb0b1908673a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Mon, 21 Dec 2015 23:24:28 +0200 Subject: [PATCH 3/5] Fix UUIDGenerator.getHardwareAddress on recent Java versions Enable related tests on all Java versions and drop < 1.7 support code. --- .../activemq/artemis/utils/UUIDGenerator.java | 32 ++++++------------- .../tests/unit/util/UUIDGeneratorTest.java | 12 ++----- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/UUIDGenerator.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/UUIDGenerator.java index e9878d1f60..116a6482ba 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/UUIDGenerator.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/UUIDGenerator.java @@ -16,7 +16,6 @@ */ package org.apache.activemq.artemis.utils; -import java.lang.reflect.Method; import java.net.NetworkInterface; import java.net.SocketException; import java.security.SecureRandom; @@ -134,21 +133,13 @@ public final class UUIDGenerator { * @return A byte array containing the hardware address. */ public static byte[] getHardwareAddress() { - Method getHardwareAddressMethod; - Method isUpMethod; - Method isLoopbackMethod; - Method isVirtualMethod; try { - getHardwareAddressMethod = NetworkInterface.class.getMethod("getHardwareAddress"); - isUpMethod = NetworkInterface.class.getMethod("isUp"); - isLoopbackMethod = NetworkInterface.class.getMethod("isLoopback"); - isVirtualMethod = NetworkInterface.class.getMethod("isVirtual"); // check if we have enough security permissions to create and shutdown an executor - ExecutorService executor = Executors.newFixedThreadPool(0); + ExecutorService executor = Executors.newFixedThreadPool(1); executor.shutdownNow(); } catch (Throwable t) { - // not on Java 6 or not enough security permission + // not enough security permission return null; } @@ -159,7 +150,7 @@ public final class UUIDGenerator { return null; } - byte[] address = findFirstMatchingHardwareAddress(ifaces, getHardwareAddressMethod, isUpMethod, isLoopbackMethod, isVirtualMethod); + byte[] address = findFirstMatchingHardwareAddress(ifaces); if (address != null) { if (ActiveMQUtilLogger.LOGGER.isDebugEnabled()) { ActiveMQUtilLogger.LOGGER.debug("using hardware address " + UUIDGenerator.asString(address)); @@ -269,11 +260,7 @@ public final class UUIDGenerator { } } - private static byte[] findFirstMatchingHardwareAddress(List ifaces, - final Method getHardwareAddressMethod, - final Method isUpMethod, - final Method isLoopbackMethod, - final Method isVirtualMethod) { + private static byte[] findFirstMatchingHardwareAddress(List ifaces) { ExecutorService executor = Executors.newFixedThreadPool(ifaces.size()); Collection> tasks = new ArrayList<>(ifaces.size()); @@ -281,18 +268,17 @@ public final class UUIDGenerator { tasks.add(new Callable() { @Override public byte[] call() throws Exception { - boolean up = (Boolean) isUpMethod.invoke(networkInterface); - boolean loopback = (Boolean) isLoopbackMethod.invoke(networkInterface); - boolean virtual = (Boolean) isVirtualMethod.invoke(networkInterface); + boolean up = networkInterface.isUp(); + boolean loopback = networkInterface.isLoopback(); + boolean virtual = networkInterface.isVirtual(); if (loopback || virtual || !up) { throw new Exception("not suitable interface"); } - Object res = getHardwareAddressMethod.invoke(networkInterface); - if (res != null && res instanceof byte[]) { + byte[] address = networkInterface.getHardwareAddress(); + if (address != null) { - byte[] address = (byte[]) res; byte[] paddedAddress = UUIDGenerator.getZeroPaddedSixBytes(address); if (UUIDGenerator.isBlackList(address)) { diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/util/UUIDGeneratorTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/util/UUIDGeneratorTest.java index 48282e32de..46a906506f 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/util/UUIDGeneratorTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/util/UUIDGeneratorTest.java @@ -34,15 +34,9 @@ public class UUIDGeneratorTest extends ActiveMQTestBase { @Test public void testGetHardwareAddress() throws Exception { - String javaVersion = System.getProperty("java.vm.version"); - if (javaVersion.startsWith("1.5")) { - Assert.assertNull(UUIDGenerator.getHardwareAddress()); - } - else if (javaVersion.startsWith("1.6")) { - byte[] bytes = UUIDGenerator.getHardwareAddress(); - Assert.assertNotNull(bytes); - Assert.assertTrue(bytes.length == 6); - } + byte[] bytes = UUIDGenerator.getHardwareAddress(); + Assert.assertNotNull(bytes); + Assert.assertTrue(bytes.length == 6); } @Test From a5eb04a2baddae2c047e36dc5575088c784e5b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Mon, 21 Dec 2015 23:31:49 +0200 Subject: [PATCH 4/5] Remove Java < 1.5 support from XMLUtil.getTextContent --- .../core/client/ActiveMQClientLogger.java | 1 + .../activemq/artemis/utils/XMLUtil.java | 58 +------------------ 2 files changed, 2 insertions(+), 57 deletions(-) diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/ActiveMQClientLogger.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/ActiveMQClientLogger.java index f881191796..e67891d513 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/ActiveMQClientLogger.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/ActiveMQClientLogger.java @@ -386,6 +386,7 @@ public interface ActiveMQClientLogger extends BasicLogger { @Message(id = 214017, value = "Caught unexpected Throwable", format = Message.Format.MESSAGE_FORMAT) void caughtunexpectedThrowable(@Cause Throwable t); + @Deprecated @LogMessage(level = Logger.Level.ERROR) @Message(id = 214018, value = "Failed to invoke getTextContent() on node {0}", format = Message.Format.MESSAGE_FORMAT) void errorOnXMLTransform(@Cause Throwable t, Node n); diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java index 5634207132..bd96a71977 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java @@ -26,7 +26,6 @@ import javax.xml.validation.Validator; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; -import java.lang.reflect.Method; import java.net.URL; import java.security.AccessController; import java.security.PrivilegedAction; @@ -145,16 +144,9 @@ public final class XMLUtil { return sb.toString(); } - private static final Object[] EMPTY_ARRAY = new Object[0]; - /** - * This metod is here because Node.getTextContent() is not available in JDK 1.4 and I would like - * to have an uniform access to this functionality. - *

* Note: if the content is another element or set of elements, it returns a string representation * of the hierarchy. - *

- * TODO implementation of this method is a hack. Implement it properly. */ public static String getTextContent(final Node n) { if (n.hasChildNodes()) { @@ -173,55 +165,7 @@ public final class XMLUtil { } } - Method[] methods = Node.class.getMethods(); - - for (Method getTextContext : methods) { - if ("getTextContent".equals(getTextContext.getName())) { - try { - return (String) getTextContext.invoke(n, XMLUtil.EMPTY_ARRAY); - } - catch (Exception e) { - ActiveMQClientLogger.LOGGER.errorOnXMLTransform(e, n); - return null; - } - } - } - - String textContent = null; - - if (n.hasChildNodes()) { - NodeList nl = n.getChildNodes(); - for (int i = 0; i < nl.getLength(); i++) { - Node c = nl.item(i); - if (c.getNodeType() == Node.TEXT_NODE) { - textContent = n.getNodeValue(); - if (textContent == null) { - // TODO This is a hack. Get rid of it and implement this properly - String s = c.toString(); - int idx = s.indexOf("#text:"); - if (idx != -1) { - textContent = s.substring(idx + 6).trim(); - if (textContent.endsWith("]")) { - textContent = textContent.substring(0, textContent.length() - 1); - } - } - } - if (textContent == null) { - break; - } - } - } - - // TODO This is a hack. Get rid of it and implement this properly - String s = n.toString(); - int i = s.indexOf('>'); - int i2 = s.indexOf(" Date: Mon, 21 Dec 2015 23:35:40 +0200 Subject: [PATCH 5/5] Update Java version in example Eclipse config --- etc/org.eclipse.jdt.core.prefs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/etc/org.eclipse.jdt.core.prefs b/etc/org.eclipse.jdt.core.prefs index eb99f0b1d9..d1b8d712fd 100644 --- a/etc/org.eclipse.jdt.core.prefs +++ b/etc/org.eclipse.jdt.core.prefs @@ -10,9 +10,9 @@ org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes= org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes= org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.unusedLocal=optimize out -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -20,7 +20,7 @@ org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.processAnnotations=enabled -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.7 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=18 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=16