Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@

<properties>
<projectOwner>Red Hat, Inc.</projectOwner>
<javaVersion>1.8</javaVersion>
<enforceStandards>false</enforceStandards>
<enforceBestPractices>false</enforceBestPractices>
<plugin.jacoco.skip>false</plugin.jacoco.skip>
<maven.compiler.release>${javaVersion}</maven.compiler.release>
</properties>

<modules>
Expand All @@ -52,7 +52,7 @@
<dependency>
<groupId>org.commonjava.boms</groupId>
<artifactId>web-commons-bom</artifactId>
<version>31</version>
<version>34</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -81,11 +81,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
Expand Down
25 changes: 10 additions & 15 deletions rwx-test/src/test/java/org/commonjava/rwx/test/AbstractTest.java
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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;
Expand All @@ -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.
Expand All @@ -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 version=\"1.0\"?>" );
xml = xml.replaceAll( "<nil/>", "<nil></nil>" );
xml = xml.replace( "<nil/>", "<nil></nil>" );
return xml;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,7 +53,7 @@ public void requestWithOneParamTest() throws Exception
public void roundTrip_RequestWithOneArrayParamTest() throws Exception
{
RequestWithOneArrayParam requst = new RequestWithOneArrayParam();
List<String> array = Arrays.asList( "test1", "test2" );
List<String> array = List.of( "test1", "test2" );
requst.setArray( array );
String request = new RWXMapper().render( requst );
String expected = getXMLStringIgnoreFormat( "requestWithOneArrayParam" );
Expand Down
12 changes: 0 additions & 12 deletions rwx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,9 @@
<name>RWX</name>

<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-templates</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
</dependencies>
</project>
12 changes: 2 additions & 10 deletions rwx/src/main/java/org/commonjava/rwx/core/AnnoProcessor.java
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -456,11 +455,8 @@ private void generateOutput( Template template, Map<String, Object> 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 )
Expand All @@ -470,10 +466,6 @@ private void generateOutput( Template template, Map<String, Object> templatePara
"While generating sources for class: '" + className + "', error: "
+ e.getMessage() );
}
finally
{
IOUtils.closeQuietly( sourceWriter );
}
}

static class Item
Expand Down
7 changes: 3 additions & 4 deletions rwx/src/main/java/org/commonjava/rwx/core/XmlRpcParser.java
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -311,7 +310,7 @@ else if ( localName.equals( NIL ) )
else if ( event == XMLStreamConstants.CHARACTERS ) // default string value, takes form of <value>str</value>
{
String text = reader.getText();
if ( StringUtils.isNotBlank( text ) )
if ( text != null && !text.isBlank() )
{
ret = text.trim();
logger.trace( "Read value: " + text );
Expand Down
8 changes: 3 additions & 5 deletions rwx/src/main/java/org/commonjava/rwx/util/ProcessorUtils.java
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -99,7 +97,7 @@ public static String getRegistryClassName( Set<String> packageNames )

if ( packageNames.size() == 1 )
{
commonPkgName = packageNames.toArray( new String[0] )[0];
commonPkgName = packageNames.iterator().next();
}
else
{
Expand Down Expand Up @@ -142,7 +140,7 @@ public static String getRegistryClassName( Set<String> packageNames )
}

commonPkgName = sb.toString();
if ( StringUtils.isBlank( commonPkgName ) )
if ( commonPkgName.isBlank() )
{
return "generated._Registry"; // default
}
Expand Down
5 changes: 2 additions & 3 deletions rwx/src/main/java/org/commonjava/rwx/util/RenderUtils.java
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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.*;

/**
Expand Down Expand Up @@ -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 );
}
Expand Down
23 changes: 16 additions & 7 deletions rwx/src/main/java/org/commonjava/rwx/vocab/ValueType.java
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -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 );
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<String> set = new HashSet<>( );
Expand Down
Loading