You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by kr...@apache.org on 2019/06/24 02:02:19 UTC
[knox] branch master updated: KNOX-1905 - Upgrade maven-pmd-plugin
to 3.12.0
This is an automated email from the ASF dual-hosted git repository.
krisden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git
The following commit(s) were added to refs/heads/master by this push:
new c08c11c KNOX-1905 - Upgrade maven-pmd-plugin to 3.12.0
c08c11c is described below
commit c08c11c17d97467b38022addd77dafe99ff65b99
Author: Kevin Risden <kr...@apache.org>
AuthorDate: Sun Jun 23 12:10:27 2019 -0400
KNOX-1905 - Upgrade maven-pmd-plugin to 3.12.0
Signed-off-by: Kevin Risden <kr...@apache.org>
---
.../main/resources/build-tools/pmd/pmd-ruleset.xml | 5 +-
.../topology/discovery/ambari/RESTInvoker.java | 23 ++-----
.../discovery/ambari/YarnUIV2URLCreatorTest.java | 7 +-
.../federation/JWTFederationFilterTest.java | 69 ++++++++++---------
.../sandbox-with-knox-inside/HiveJDBCSample.java | 74 ++++++++------------
.../hive/java/jdbc/sandbox/HiveJDBCSample.java | 2 +-
.../org/apache/knox/gateway/shell/KnoxSession.java | 78 ++++++++++------------
.../apache/knox/gateway/GatewayBasicFuncTest.java | 7 +-
.../apache/knox/gateway/GatewayDeployFuncTest.java | 5 --
pom.xml | 2 +-
10 files changed, 117 insertions(+), 155 deletions(-)
diff --git a/build-tools/src/main/resources/build-tools/pmd/pmd-ruleset.xml b/build-tools/src/main/resources/build-tools/pmd/pmd-ruleset.xml
index 2e24c8f..e20db56 100644
--- a/build-tools/src/main/resources/build-tools/pmd/pmd-ruleset.xml
+++ b/build-tools/src/main/resources/build-tools/pmd/pmd-ruleset.xml
@@ -25,10 +25,12 @@ limitations under the License.
<exclude name="AccessorMethodGeneration" />
<exclude name="ArrayIsStoredDirectly" />
<exclude name="AvoidPrintStackTrace" />
+ <exclude name="AvoidReassigningLoopVariables" />
<exclude name="AvoidReassigningParameters" />
<exclude name="AvoidStringBufferField" />
<exclude name="AvoidUsingHardCodedIP" />
<exclude name="ConstantsInInterface" />
+ <exclude name="ForLoopVariableCount" />
<exclude name="GuardLogStatement" />
<exclude name="JUnitAssertionsShouldIncludeMessage" />
<exclude name="JUnitTestContainsTooManyAsserts" />
@@ -40,6 +42,7 @@ limitations under the License.
<exclude name="ReplaceHashtableWithMap" />
<exclude name="SwitchStmtsShouldHaveDefault" />
<exclude name="SystemPrintln" />
+ <exclude name="UseTryWithResources" />
<exclude name="UseVarargs" />
</rule>
@@ -93,4 +96,4 @@ limitations under the License.
<exclude name="UseStringBufferForStringAppends" />
</rule>
<rule ref="category/java/security.xml" />
-</ruleset>
\ No newline at end of file
+</ruleset>
diff --git a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/RESTInvoker.java b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/RESTInvoker.java
index 8eba839..24a3eec 100644
--- a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/RESTInvoker.java
+++ b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/RESTInvoker.java
@@ -83,7 +83,6 @@ class RESTInvoker {
JSONObject invoke(String url, String username, String passwordAlias) {
JSONObject result = null;
- CloseableHttpResponse response = null;
try {
HttpGet request = new HttpGet(url);
@@ -138,31 +137,23 @@ class RESTInvoker {
// Ambari CSRF protection
request.addHeader("X-Requested-By", "Knox");
- response = httpClient.execute(request);
-
- if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) {
+ try(CloseableHttpResponse response = httpClient.execute(request)){
+ if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) {
HttpEntity entity = response.getEntity();
if (entity != null) {
- result = (JSONObject) JSONValue.parse((EntityUtils.toString(entity)));
- log.debugJSON(result.toJSONString());
+ result = (JSONObject) JSONValue.parse((EntityUtils.toString(entity)));
+ log.debugJSON(result.toJSONString());
} else {
- log.noJSON(url);
+ log.noJSON(url);
}
- } else {
+ } else {
log.unexpectedRestResponseStatusCode(url, response.getStatusLine().getStatusCode());
+ }
}
} catch (ConnectTimeoutException e) {
log.restInvocationTimedOut(url, e);
} catch (IOException e) {
log.restInvocationError(url, e);
- } finally {
- if(response != null) {
- try {
- response.close();
- } catch (IOException e) {
- // Ignore
- }
- }
}
return result;
}
diff --git a/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIV2URLCreatorTest.java b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIV2URLCreatorTest.java
index 8db53c1..640f49b 100644
--- a/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIV2URLCreatorTest.java
+++ b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIV2URLCreatorTest.java
@@ -16,15 +16,14 @@
*/
package org.apache.knox.gateway.topology.discovery.ambari;
+import org.junit.Test;
public class YarnUIV2URLCreatorTest extends YarnUIURLCreatorTest {
-
@Override
String getTargetService() {
return "YARNUIV2";
}
-
@Override
ServiceURLCreator getServiceURLCreator(AmbariCluster cluster) {
ServiceURLCreator creator = new YarnUIV2URLCreator();
@@ -32,4 +31,8 @@ public class YarnUIV2URLCreatorTest extends YarnUIURLCreatorTest {
return creator;
}
+ @Test
+ public void doTest() {
+ // TODO
+ }
}
diff --git a/gateway-provider-security-jwt/src/test/java/org/apache/knox/gateway/provider/federation/JWTFederationFilterTest.java b/gateway-provider-security-jwt/src/test/java/org/apache/knox/gateway/provider/federation/JWTFederationFilterTest.java
index 28d7129..aa73160 100644
--- a/gateway-provider-security-jwt/src/test/java/org/apache/knox/gateway/provider/federation/JWTFederationFilterTest.java
+++ b/gateway-provider-security-jwt/src/test/java/org/apache/knox/gateway/provider/federation/JWTFederationFilterTest.java
@@ -17,53 +17,52 @@
*/
package org.apache.knox.gateway.provider.federation;
-import java.security.NoSuchAlgorithmException;
-
-import javax.servlet.http.HttpServletRequest;
-
+import com.nimbusds.jwt.SignedJWT;
import org.apache.knox.gateway.provider.federation.jwt.filter.JWTFederationFilter;
import org.apache.knox.gateway.services.security.token.JWTokenAuthority;
import org.easymock.EasyMock;
import org.junit.Before;
+import org.junit.Test;
-import com.nimbusds.jwt.SignedJWT;
+import javax.servlet.http.HttpServletRequest;
public class JWTFederationFilterTest extends AbstractJWTFilterTest {
+ @Before
+ public void setUp() {
+ handler = new TestJWTFederationFilter();
+ ((TestJWTFederationFilter) handler).setTokenService(new TestJWTokenAuthority(publicKey));
+ }
- @Before
- public void setup() throws Exception, NoSuchAlgorithmException {
- handler = new TestJWTFederationFilter();
- ((TestJWTFederationFilter) handler).setTokenService(new TestJWTokenAuthority(publicKey));
- }
-
- @Override
- protected void setTokenOnRequest(HttpServletRequest request, SignedJWT jwt) {
- String token = "Bearer " + jwt.serialize();
- EasyMock.expect(request.getHeader("Authorization")).andReturn(token);
- }
+ @Override
+ protected void setTokenOnRequest(HttpServletRequest request, SignedJWT jwt) {
+ String token = "Bearer " + jwt.serialize();
+ EasyMock.expect(request.getHeader("Authorization")).andReturn(token);
+ }
- @Override
- protected void setGarbledTokenOnRequest(HttpServletRequest request, SignedJWT jwt) {
- String token = "Bearer " + "ljm" + jwt.serialize();
- EasyMock.expect(request.getHeader("Authorization")).andReturn(token);
- }
+ @Override
+ protected void setGarbledTokenOnRequest(HttpServletRequest request, SignedJWT jwt) {
+ String token = "Bearer " + "ljm" + jwt.serialize();
+ EasyMock.expect(request.getHeader("Authorization")).andReturn(token);
+ }
- @Override
- protected String getAudienceProperty() {
- return TestJWTFederationFilter.KNOX_TOKEN_AUDIENCES;
- }
-
- private static class TestJWTFederationFilter extends JWTFederationFilter {
-
- public void setTokenService(JWTokenAuthority ts) {
- authority = ts;
- }
+ @Override
+ protected String getAudienceProperty() {
+ return TestJWTFederationFilter.KNOX_TOKEN_AUDIENCES;
+ }
+ private static class TestJWTFederationFilter extends JWTFederationFilter {
+ void setTokenService(JWTokenAuthority ts) {
+ authority = ts;
}
+ }
- @Override
- protected String getVerificationPemProperty() {
- return TestJWTFederationFilter.TOKEN_VERIFICATION_PEM;
- }
+ @Override
+ protected String getVerificationPemProperty() {
+ return TestJWTFederationFilter.TOKEN_VERIFICATION_PEM;
+ }
+ @Test
+ public void doTest() {
+ // TODO
+ }
}
diff --git a/gateway-shell-samples/src/main/resources/samples/hive/java/jdbc/sandbox-with-knox-inside/HiveJDBCSample.java b/gateway-shell-samples/src/main/resources/samples/hive/java/jdbc/sandbox-with-knox-inside/HiveJDBCSample.java
index 58e0c8b..3072dee 100644
--- a/gateway-shell-samples/src/main/resources/samples/hive/java/jdbc/sandbox-with-knox-inside/HiveJDBCSample.java
+++ b/gateway-shell-samples/src/main/resources/samples/hive/java/jdbc/sandbox-with-knox-inside/HiveJDBCSample.java
@@ -15,6 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.apache.knox.gateway.shell.hive
import java.sql.Connection;
import java.sql.DriverManager;
@@ -28,12 +29,7 @@ import java.util.logging.Logger;
import org.apache.knox.gateway.shell.Credentials;
public class HiveJDBCSample {
-
public static void main( String[] args ) {
- Connection connection = null;
- Statement statement = null;
- ResultSet resultSet = null;
-
try {
String gatewayHost = "localhost";
int gatewayPort = 8443;
@@ -54,53 +50,37 @@ public class HiveJDBCSample {
Class.forName( "org.apache.hive.jdbc.HiveDriver" );
// Configure JDBC connection
- connection = DriverManager.getConnection( connectionString, user, password );
-
- statement = connection.createStatement();
-
- // Disable Hive authorization - This can be ommited if Hive authorization is configured properly
- statement.execute( "set hive.security.authorization.enabled=false" );
-
- // Drop sample table to ensure repeatability
- statement.execute( "DROP TABLE logs" );
-
- // Create sample table
- statement.execute( "CREATE TABLE logs(column1 string, column2 string, column3 string, column4 string, column5 string, column6 string, column7 string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ' '" );
-
- // Load data into Hive from file /tmp/log.txt which is placed on the local file system
- statement.execute( "LOAD DATA LOCAL INPATH '/tmp/sample.log' OVERWRITE INTO TABLE logs" );
-
- resultSet = statement.executeQuery( "SELECT * FROM logs" );
-
- while ( resultSet.next() ) {
- System.out.println( resultSet.getString( 1 ) + " --- " + resultSet.getString( 2 ) );
+ try(Connection connection = DriverManager.getConnection(connectionString, username, pass)) {
+ try (Statement statement = connection.createStatement()) {
+ // Disable Hive authorization - This can be ommited if Hive authorization is configured properly
+ statement.execute("set hive.security.authorization.enabled=false");
+
+ // Drop sample table to ensure repeatability
+ statement.execute("DROP TABLE logs");
+
+ // Create sample table
+ statement.execute("CREATE TABLE logs(column1 string, column2 string, column3 string, column4 string, column5 string, column6 string, column7 string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ' '");
+
+ // Load data into Hive from file /tmp/log.txt which is placed on the local file system
+ statement.execute("LOAD DATA LOCAL INPATH '/tmp/sample.log' OVERWRITE INTO TABLE logs");
+
+ try (ResultSet resultSet = statement.executeQuery("SELECT * FROM logs")) {
+ while (resultSet.next()) {
+ System.out.println(resultSet.getString(1) + " --- " + resultSet.getString(2));
+ }
+ } catch (SQLException ex) {
+ Logger.getLogger(HiveJDBCSample.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ } catch (SQLException ex) {
+ Logger.getLogger(HiveJDBCSample.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ } catch ( SQLException ex ) {
+ Logger.getLogger( HiveJDBCSample.class.getName() ).log( Level.SEVERE, null, ex );
}
} catch ( ClassNotFoundException ex ) {
Logger.getLogger( HiveJDBCSample.class.getName() ).log( Level.SEVERE, null, ex );
} catch ( SQLException ex ) {
Logger.getLogger( HiveJDBCSample.class.getName() ).log( Level.SEVERE, null, ex );
- } finally {
- if ( resultSet != null ) {
- try {
- resultSet.close();
- } catch ( SQLException ex ) {
- Logger.getLogger( HiveJDBCSample.class.getName() ).log( Level.SEVERE, null, ex );
- }
- }
- if ( statement != null ) {
- try {
- statement.close();
- } catch ( SQLException ex ) {
- Logger.getLogger( HiveJDBCSample.class.getName() ).log( Level.SEVERE, null, ex );
- }
- }
- if ( connection != null ) {
- try {
- connection.close();
- } catch ( SQLException ex ) {
- Logger.getLogger( HiveJDBCSample.class.getName() ).log( Level.SEVERE, null, ex );
- }
- }
}
}
}
diff --git a/gateway-shell-samples/src/main/resources/samples/hive/java/jdbc/sandbox/HiveJDBCSample.java b/gateway-shell-samples/src/main/resources/samples/hive/java/jdbc/sandbox/HiveJDBCSample.java
index 51db7a4..9a5f4a9 100644
--- a/gateway-shell-samples/src/main/resources/samples/hive/java/jdbc/sandbox/HiveJDBCSample.java
+++ b/gateway-shell-samples/src/main/resources/samples/hive/java/jdbc/sandbox/HiveJDBCSample.java
@@ -57,7 +57,7 @@ public class HiveJDBCSample {
Class.forName( "org.apache.hive.jdbc.HiveDriver" );
// Configure JDBC connection
- connection = DriverManager.getConnection( connectionString, user, pass );
+ connection = DriverManager.getConnection( connectionString, username, pass );
statement = connection.createStatement();
diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSession.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSession.java
index 7671b7b..00f5ffd 100644
--- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSession.java
+++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSession.java
@@ -20,7 +20,6 @@ package org.apache.knox.gateway.shell;
import com.sun.security.auth.callback.TextCallbackHandler;
import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
@@ -392,51 +391,46 @@ public class KnoxSession implements Closeable {
discoverTruststoreDetails(clientContext);
- InputStream is = null;
- try {
- ks = KeyStore.getInstance("JKS");
- File file = new File(clientContext.connection().truststoreLocation());
- if (file.exists()) {
- truststorePass = clientContext.connection().truststorePass();
- } else {
- String truststore = System.getProperty("javax.net.ssl.trustStore");
- truststorePass = System.getProperty("javax.net.ssl.trustStorePassword", "changeit");
- if (truststore == null) {
- String truststoreDir = System.getProperty("java.home");
- truststore = truststoreDir + File.separator + "lib" + File.separator
- + "security" + File.separator + "cacerts";
- }
- file = new File(truststore);
+ File file = new File(clientContext.connection().truststoreLocation());
+ if (file.exists()) {
+ truststorePass = clientContext.connection().truststorePass();
+ } else {
+ String truststore = System.getProperty("javax.net.ssl.trustStore");
+ truststorePass = System.getProperty("javax.net.ssl.trustStorePassword", "changeit");
+ if (truststore == null) {
+ String truststoreDir = System.getProperty("java.home");
+ truststore = truststoreDir + File.separator + "lib" + File.separator
+ + "security" + File.separator + "cacerts";
}
+ file = new File(truststore);
+ }
- if (file.exists()) {
- is = Files.newInputStream(file.toPath());
+ if (file.exists()) {
+ try (InputStream is = Files.newInputStream(file.toPath())) {
+ ks = KeyStore.getInstance("JKS");
ks.load(is, truststorePass.toCharArray());
+ } catch (KeyStoreException e) {
+ throw new KnoxShellException("Unable to create keystore of expected type.", e);
+ } catch (FileNotFoundException e) {
+ throw new KnoxShellException("Unable to read truststore."
+ + " Please import the gateway-identity certificate into the JVM"
+ + " truststore or set the truststore location ENV variables.", e);
+ } catch (NoSuchAlgorithmException e) {
+ throw new KnoxShellException("Unable to load the truststore."
+ + " Please import the gateway-identity certificate into the JVM"
+ + " truststore or set the truststore location ENV variables.", e);
+ } catch (CertificateException e) {
+ throw new KnoxShellException("Certificate cannot be found in the truststore."
+ + " Please import the gateway-identity certificate into the JVM"
+ + " truststore or set the truststore location ENV variables.", e);
+ } catch (IOException e) {
+ throw new KnoxShellException("Unable to load truststore."
+ + " May be related to password setting or truststore format.", e);
}
- else {
- throw new KnoxShellException("Unable to find a truststore for secure login."
- + "Please import the gateway-identity certificate into the JVM"
- + " truststore or set the truststore location ENV variables.");
- }
- } catch (KeyStoreException e) {
- throw new KnoxShellException("Unable to create keystore of expected type.", e);
- } catch (FileNotFoundException e) {
- throw new KnoxShellException("Unable to read truststore."
- + " Please import the gateway-identity certificate into the JVM"
- + " truststore or set the truststore location ENV variables.", e);
- } catch (NoSuchAlgorithmException e) {
- throw new KnoxShellException("Unable to load the truststore."
- + " Please import the gateway-identity certificate into the JVM"
- + " truststore or set the truststore location ENV variables.", e);
- } catch (CertificateException e) {
- throw new KnoxShellException("Certificate cannot be found in the truststore."
- + " Please import the gateway-identity certificate into the JVM"
- + " truststore or set the truststore location ENV variables.", e);
- } catch (IOException e) {
- throw new KnoxShellException("Unable to load truststore."
- + " May be related to password setting or truststore format.", e);
- } finally {
- IOUtils.closeQuietly(is);
+ } else {
+ throw new KnoxShellException("Unable to find a truststore for secure login."
+ + "Please import the gateway-identity certificate into the JVM"
+ + " truststore or set the truststore location ENV variables.");
}
return ks;
diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java
index 47c151e..e79b827 100644
--- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java
@@ -3578,8 +3578,6 @@ public class GatewayBasicFuncTest {
// .prettyPrint();
driver.assertComplete();
-
-
// Authorize as a different (invalid) user
setupResources();
given()
@@ -3745,7 +3743,7 @@ public class GatewayBasicFuncTest {
LOG_EXIT();
}
- void setupResource(String serviceRole, String path){
+ private void setupResource(String serviceRole, String path){
driver.getMock(serviceRole)
.expect().method("GET")
.pathInfo(path)
@@ -3757,8 +3755,7 @@ public class GatewayBasicFuncTest {
// .contentType(type.toString());
}
- void setupResources() {
-
+ private void setupResources() {
driver.setResourceBase(GatewayBasicFuncTest.class);
try {
diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayDeployFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayDeployFuncTest.java
index 50eac3c..339295e 100644
--- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayDeployFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayDeployFuncTest.java
@@ -157,11 +157,6 @@ public class GatewayDeployFuncTest {
.gotoRoot();
}
- //@Test
- public void waitForManualTesting() throws IOException {
- System.in.read();
- }
-
@Test( timeout = TestUtils.LONG_TIMEOUT )
public void testDeployRedeployUndeploy() throws InterruptedException, IOException {
LOG_ENTER();
diff --git a/pom.xml b/pom.xml
index ca25409..f6346e8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -208,7 +208,7 @@
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-dependency-plugin.version>3.1.1</maven-dependency-plugin.version>
<maven-enforcer-plugin.version>3.0.0-M2</maven-enforcer-plugin.version>
- <maven-pmd-plugin.version>3.11.0</maven-pmd-plugin.version>
+ <maven-pmd-plugin.version>3.12.0</maven-pmd-plugin.version>
<metrics.version>4.1.0</metrics.version>
<mina.version>2.0.20</mina.version>
<nimbus-jose-jwt.version>7.3</nimbus-jose-jwt.version>