diff --git a/pom.xml b/pom.xml index 6c543bb..a43ca02 100644 --- a/pom.xml +++ b/pom.xml @@ -36,10 +36,10 @@ Red Hat, Inc. - 1.8 false false false + ${javaVersion} @@ -52,7 +52,7 @@ org.commonjava.boms web-commons-bom - 31 + 34 pom import @@ -81,11 +81,6 @@ org.slf4j slf4j-api - - org.slf4j - log4j-over-slf4j - runtime - ch.qos.logback logback-core diff --git a/rwx-test/src/test/java/org/commonjava/rwx/test/AbstractTest.java b/rwx-test/src/test/java/org/commonjava/rwx/test/AbstractTest.java index b3b586a..6961096 100644 --- a/rwx-test/src/test/java/org/commonjava/rwx/test/AbstractTest.java +++ b/rwx-test/src/test/java/org/commonjava/rwx/test/AbstractTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2010 Red Hat, Inc. (http://github.com/Commonjava/commonjava) * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +15,6 @@ */ package org.commonjava.rwx.test; -import org.apache.commons.io.IOUtils; import org.commonjava.rwx.core.Registry; import org.commonjava.rwx.test.generated.Test_Registry; import org.junit.BeforeClass; @@ -24,8 +23,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.PrintWriter; -import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.util.stream.Collectors; /** * Created by ruhan on 8/2/17. @@ -47,30 +46,26 @@ protected InputStream getXMLStream( final String name ) protected String getXMLString( final String name ) throws IOException { - return IOUtils.toString( new InputStreamReader( getXMLStream( name ) )); + try ( InputStream stream = getXMLStream( name ) ) + { + return new String( stream.readAllBytes(), StandardCharsets.UTF_8 ); + } } // Comparing XML string is a bad idea. But we need it in some cases, e.g., kojiListBuildsResponseNIL protected String getXMLStringIgnoreFormat( final String name ) throws IOException { - final BufferedReader reader = new BufferedReader( new InputStreamReader( getXMLStream( name ) ) ); - final StringWriter writer = new StringWriter(); - final PrintWriter pWriter = new PrintWriter( writer ); - - String line; - while ( ( line = reader.readLine() ) != null ) + try ( BufferedReader reader = new BufferedReader(new InputStreamReader( getXMLStream( name ), StandardCharsets.UTF_8 ) ) ) { - pWriter.print( line.trim() ); + return reader.lines().map( String::trim ).collect( Collectors.joining() ).trim(); } - - return writer.toString().trim(); } protected String formalizeXMLString( String xml ) { xml = xml.replaceFirst( "<\\?.*\\?>", "" ); - xml = xml.replaceAll( "", "" ); + xml = xml.replace( "", "" ); return xml; } diff --git a/rwx-test/src/test/java/org/commonjava/rwx/test/simple/SimpleRWXMapperTest.java b/rwx-test/src/test/java/org/commonjava/rwx/test/simple/SimpleRWXMapperTest.java index 37cb4f1..166ac67 100644 --- a/rwx-test/src/test/java/org/commonjava/rwx/test/simple/SimpleRWXMapperTest.java +++ b/rwx-test/src/test/java/org/commonjava/rwx/test/simple/SimpleRWXMapperTest.java @@ -21,7 +21,6 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; -import java.util.Arrays; import java.util.List; import static junit.framework.TestCase.assertEquals; @@ -54,7 +53,7 @@ public void requestWithOneParamTest() throws Exception public void roundTrip_RequestWithOneArrayParamTest() throws Exception { RequestWithOneArrayParam requst = new RequestWithOneArrayParam(); - List array = Arrays.asList( "test1", "test2" ); + List array = List.of( "test1", "test2" ); requst.setArray( array ); String request = new RWXMapper().render( requst ); String expected = getXMLStringIgnoreFormat( "requestWithOneArrayParam" ); diff --git a/rwx/pom.xml b/rwx/pom.xml index e75cf06..b0cde91 100644 --- a/rwx/pom.xml +++ b/rwx/pom.xml @@ -30,21 +30,9 @@ RWX - - org.apache.commons - commons-lang3 - org.codehaus.groovy groovy-templates - - commons-io - commons-io - - - commons-codec - commons-codec - diff --git a/rwx/src/main/java/org/commonjava/rwx/core/AnnoProcessor.java b/rwx/src/main/java/org/commonjava/rwx/core/AnnoProcessor.java index c6920f1..b3fb6b8 100644 --- a/rwx/src/main/java/org/commonjava/rwx/core/AnnoProcessor.java +++ b/rwx/src/main/java/org/commonjava/rwx/core/AnnoProcessor.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2010 Red Hat, Inc. (http://github.com/Commonjava/commonjava) * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,6 @@ import groovy.lang.Writable; import groovy.text.GStringTemplateEngine; import groovy.text.Template; -import org.apache.commons.io.IOUtils; import org.commonjava.rwx.anno.ArrayPart; import org.commonjava.rwx.anno.Converter; import org.commonjava.rwx.anno.DataIndex; @@ -456,11 +455,8 @@ private void generateOutput( Template template, Map templatePara { Filer filer = processingEnv.getFiler(); Writable output = template.make( templateParams ); - Writer sourceWriter = null; - try + try ( Writer sourceWriter = filer.createSourceFile( className ).openWriter() ) { - FileObject file = filer.createSourceFile( className ); - sourceWriter = file.openWriter(); output.writeTo( sourceWriter ); } catch ( final IOException e ) @@ -470,10 +466,6 @@ private void generateOutput( Template template, Map templatePara "While generating sources for class: '" + className + "', error: " + e.getMessage() ); } - finally - { - IOUtils.closeQuietly( sourceWriter ); - } } static class Item diff --git a/rwx/src/main/java/org/commonjava/rwx/core/XmlRpcParser.java b/rwx/src/main/java/org/commonjava/rwx/core/XmlRpcParser.java index 3cb1e73..7bb0d3c 100644 --- a/rwx/src/main/java/org/commonjava/rwx/core/XmlRpcParser.java +++ b/rwx/src/main/java/org/commonjava/rwx/core/XmlRpcParser.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2010 Red Hat, Inc. (http://github.com/Commonjava/commonjava) * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +15,6 @@ */ package org.commonjava.rwx.core; -import org.apache.commons.lang3.StringUtils; import org.commonjava.rwx.error.CoercionException; import org.commonjava.rwx.error.XmlRpcException; import org.commonjava.rwx.vocab.ValueType; @@ -140,7 +139,7 @@ else if ( localName.equals( METHOD_NAME ) ) if ( event == XMLStreamConstants.CHARACTERS ) { String text = reader.getText(); - if ( StringUtils.isNotBlank( text ) ) + if ( text != null && !text.isBlank() ) { ret.setMethodName( text.trim() ); logger.trace( "Read methodName: " + text ); @@ -311,7 +310,7 @@ else if ( localName.equals( NIL ) ) else if ( event == XMLStreamConstants.CHARACTERS ) // default string value, takes form of str { String text = reader.getText(); - if ( StringUtils.isNotBlank( text ) ) + if ( text != null && !text.isBlank() ) { ret = text.trim(); logger.trace( "Read value: " + text ); diff --git a/rwx/src/main/java/org/commonjava/rwx/util/ProcessorUtils.java b/rwx/src/main/java/org/commonjava/rwx/util/ProcessorUtils.java index 621d4fb..1c6b29d 100644 --- a/rwx/src/main/java/org/commonjava/rwx/util/ProcessorUtils.java +++ b/rwx/src/main/java/org/commonjava/rwx/util/ProcessorUtils.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2010 Red Hat, Inc. (http://github.com/Commonjava/commonjava) * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,8 +15,6 @@ */ package org.commonjava.rwx.util; -import org.apache.commons.lang3.StringUtils; - import javax.lang.model.element.Element; import java.util.ArrayList; import java.util.HashSet; @@ -99,7 +97,7 @@ public static String getRegistryClassName( Set packageNames ) if ( packageNames.size() == 1 ) { - commonPkgName = packageNames.toArray( new String[0] )[0]; + commonPkgName = packageNames.iterator().next(); } else { @@ -142,7 +140,7 @@ public static String getRegistryClassName( Set packageNames ) } commonPkgName = sb.toString(); - if ( StringUtils.isBlank( commonPkgName ) ) + if ( commonPkgName.isBlank() ) { return "generated._Registry"; // default } diff --git a/rwx/src/main/java/org/commonjava/rwx/util/RenderUtils.java b/rwx/src/main/java/org/commonjava/rwx/util/RenderUtils.java index 3092b4f..38910a8 100644 --- a/rwx/src/main/java/org/commonjava/rwx/util/RenderUtils.java +++ b/rwx/src/main/java/org/commonjava/rwx/util/RenderUtils.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2010 Red Hat, Inc. (http://github.com/Commonjava/commonjava) * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,7 +28,6 @@ import java.util.List; import java.util.Map; -import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.commonjava.rwx.vocab.XmlRpcConstants.*; /** @@ -223,7 +222,7 @@ private static void writePrimitive( XMLStreamWriter w, Object object ) throws XM w.writeStartElement( type.getPrimaryTag() ); String chars = type.coercion().toString( object ); - if ( isNotBlank( chars ) ) + if ( chars != null && !chars.isBlank() ) { w.writeCharacters( chars ); } diff --git a/rwx/src/main/java/org/commonjava/rwx/vocab/ValueType.java b/rwx/src/main/java/org/commonjava/rwx/vocab/ValueType.java index 9f7b702..f766998 100644 --- a/rwx/src/main/java/org/commonjava/rwx/vocab/ValueType.java +++ b/rwx/src/main/java/org/commonjava/rwx/vocab/ValueType.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2010 Red Hat, Inc. (http://github.com/Commonjava/commonjava) * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,15 +15,16 @@ */ package org.commonjava.rwx.vocab; -import org.apache.commons.codec.binary.Base64; import org.commonjava.rwx.error.CoercionException; import org.commonjava.rwx.util.ValueCoercion; +import java.nio.charset.StandardCharsets; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Arrays; +import java.util.Base64; import java.util.Date; import java.util.List; import java.util.Locale; @@ -260,7 +261,15 @@ public Object fromString( final String value ) throws CoercionException return null; } - final byte[] result = Base64.decodeBase64( value.trim() ); + byte[] result; + try + { + result = Base64.getMimeDecoder().decode( value.trim() ); + } + catch ( final IllegalArgumentException e ) + { + result = new byte[0]; + } if ( result.length < 1 && !value.isEmpty() && !value.equals( "==" ) && !value.equals( "=" ) ) { throw new CoercionException( "Invalid Base64 input: " + value ); @@ -279,9 +288,9 @@ public String toString( final Object value ) throws CoercionException return null; } - return new String( Base64.encodeBase64( value instanceof String ? - ( (String) value ).getBytes() : - ( byte[]) value ) ); + return Base64.getEncoder().encodeToString( value instanceof String ? + ( (String) value ).getBytes( StandardCharsets.UTF_8 ) : + ( byte[]) value ); } catch ( final ClassCastException e ) { @@ -360,7 +369,7 @@ public static ValueType typeFor( final Object value ) public static ValueType typeOf( final String tag ) { - if ( tag == null || tag.trim().isEmpty() ) + if ( tag == null || tag.isBlank() ) { return STRING; } diff --git a/rwx/src/test/java/org/commonjava/rwx/core/util/ProcessorUtilsTest.java b/rwx/src/test/java/org/commonjava/rwx/core/util/ProcessorUtilsTest.java index 19640c1..e0ad8ed 100644 --- a/rwx/src/test/java/org/commonjava/rwx/core/util/ProcessorUtilsTest.java +++ b/rwx/src/test/java/org/commonjava/rwx/core/util/ProcessorUtilsTest.java @@ -19,7 +19,6 @@ import static org.commonjava.rwx.util.ProcessorUtils.getRegistryClassName; import org.junit.Test; -import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -34,7 +33,7 @@ public class ProcessorUtilsTest @Test public void getRegistryNameTest() { - String reg = getRegistryClassName( Collections.emptySet() ); + String reg = getRegistryClassName( Set.of() ); assertEquals( "generated._Registry", reg ); Set set = new HashSet<>( );