Skip to content

Commit

Permalink
Merge pull request #12 from apache/warn
Browse files Browse the repository at this point in the history
replace deprecated methods
  • Loading branch information
elharo authored Jul 16, 2020
2 parents 36d2e6e + 4fcb717 commit ced9ce5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;

import org.apache.commons.io.IOUtils;
import org.codehaus.plexus.interpolation.Interpolator;
import org.codehaus.plexus.interpolation.RecursionInterceptor;
import org.codehaus.plexus.util.IOUtil;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
Expand All @@ -55,39 +56,39 @@ public void testDefaults()

Reader in = new StringReader( "text without expression" );
Reader reader = getDollarBracesReader( in, interpolator, "\\" );
assertEquals( "text without expression", IOUtil.toString( reader ) );
assertEquals( "text without expression", IOUtils.toString( reader ) );

in = new StringReader( "valid expression ${a}" );
reader = getDollarBracesReader( in, interpolator, null );
assertEquals( "valid expression DONE_A", IOUtil.toString( reader ) );
assertEquals( "valid expression DONE_A", IOUtils.toString( reader ) );

in = new StringReader( "empty expression ${}" );
reader = getDollarBracesReader( in, interpolator, null );
assertEquals( "empty expression ${}", IOUtil.toString( reader ) );
assertEquals( "empty expression ${}", IOUtils.toString( reader ) );

in = new StringReader( "dollar space expression $ {a}" );
reader = getDollarBracesReader( in, interpolator, "\\" );
assertEquals( "dollar space expression $ {a}", IOUtil.toString( reader ) );
assertEquals( "dollar space expression $ {a}", IOUtils.toString( reader ) );

in = new StringReader( "space in expression ${ a}" );
reader = getDollarBracesReader( in, interpolator, "\\" );
assertEquals( "space in expression ${ a}", IOUtil.toString( reader ) );
assertEquals( "space in expression ${ a}", IOUtils.toString( reader ) );

in = new StringReader( "escape dollar with expression \\${a}" );
reader = getDollarBracesReader( in, interpolator, "\\" );
assertEquals( "escape dollar with expression ${a}", IOUtil.toString( reader ) );
assertEquals( "escape dollar with expression ${a}", IOUtils.toString( reader ) );

// in = new StringReader( "escape escape string before expression \\\\${a}" );
// reader = getDollarBracesReader( in, interpolator, "\\" );
// assertEquals( "escape escape string before expression \\DONE_A", IOUtil.toString( reader ) );
// assertEquals( "escape escape string before expression \\DONE_A", IOUtils.toString( reader ) );
//
// in = new StringReader( "escape escape string and expression \\\\\\${a}" );
// reader = getDollarBracesReader( in, interpolator, "\\" );
// assertEquals( "escape escape string before expression \\${a}", IOUtil.toString( reader ) );
// assertEquals( "escape escape string before expression \\${a}", IOUtils.toString( reader ) );

in = new StringReader( "unknown expression ${unknown}" );
reader = getDollarBracesReader( in, interpolator, "\\" );
assertEquals( "unknown expression ${unknown}", IOUtil.toString( reader ) );
assertEquals( "unknown expression ${unknown}", IOUtils.toString( reader ) );
}

// MSHARED-198: custom delimiters doesn't work as expected
Expand All @@ -101,22 +102,22 @@ public void testCustomDelimiters()
Reader in = new StringReader( "aaaFILTER.a.MEaaa" );
Reader reader = getAaa_AaaReader( in, interpolator );

assertEquals( "DONE", IOUtil.toString( reader ) );
assertEquals( "DONE", IOUtils.toString( reader ) );

in = new StringReader( "abcFILTER.a.MEabc" );
reader = getAbc_AbcReader( in, interpolator );
assertEquals( "DONE", IOUtil.toString( reader ) );
assertEquals( "DONE", IOUtils.toString( reader ) );
}

// MSHARED-235: reader exceeds readAheadLimit
@Test
public void testMarkInvalid()
throws Exception
public void testMarkInvalid() throws IOException
{
Reader in = new StringReader( "@\").replace(p,\"]\").replace(q,\"" );
Reader reader = getAtReader( in, interpolator, "\\" );

assertEquals( "@\").replace(p,\"]\").replace(q,\"", IOUtil.toString( reader ) );
try ( Reader reader =
getAtReader( new StringReader( "@\").replace(p,\"]\").replace(q,\"" ), interpolator, "\\" ) )
{
assertEquals( "@\").replace(p,\"]\").replace(q,\"", IOUtils.toString( reader ) );
}
}

protected abstract Reader getAbc_AbcReader( Reader in, Interpolator interpolator );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import java.util.List;
import java.util.Properties;

import org.apache.commons.io.IOUtils;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.utils.io.FileUtils;
import org.apache.maven.shared.utils.io.FileUtils.FilterWrapper;
import org.apache.maven.shared.utils.io.IOUtil;
import org.codehaus.plexus.PlexusTestCase;

/**
Expand Down Expand Up @@ -149,9 +149,10 @@ public void testMavenBasedir()

List<FilterWrapper> wrappers = mavenFileFilter.getDefaultFilterWrappers( req );

Reader reader = wrappers.get( 0 ).getReader( new StringReader( "${filefilter} ${buildfilter}" ) );

assertEquals( "true true", IOUtil.toString( reader ) );
try ( Reader reader = wrappers.get( 0 ).getReader( new StringReader( "${filefilter} ${buildfilter}" ) ) )
{
assertEquals( "true true", IOUtils.toString( reader ) );
}
}

// MSHARED-198: custom delimiters doesn't work as expected
Expand All @@ -169,10 +170,10 @@ public void testCustomDelimiters()
List<FilterWrapper> wrappers = mavenFileFilter.getDefaultFilterWrappers( req );

Reader reader = wrappers.get( 0 ).getReader( new StringReader( "aaaFILTER.a.MEaaa" ) );
assertEquals( "DONE", IOUtil.toString( reader ) );
assertEquals( "DONE", IOUtils.toString( reader ) );

reader = wrappers.get( 0 ).getReader( new StringReader( "abcFILTER.a.MEabc" ) );
assertEquals( "DONE", IOUtil.toString( reader ) );
assertEquals( "DONE", IOUtils.toString( reader ) );
}

// MSHARED-199: Filtering doesn't work if 2 delimiters are used on the same line, the first one being left open
Expand All @@ -188,7 +189,9 @@ public void testLineWithSingleAtAndExpression()

List<FilterWrapper> wrappers = mavenFileFilter.getDefaultFilterWrappers( req );

Reader reader = wrappers.get( 0 ).getReader( new StringReader( "[email protected] ${foo}" ) );
assertEquals( "[email protected] bar", IOUtil.toString( reader ) );
try ( Reader reader = wrappers.get( 0 ).getReader( new StringReader( "[email protected] ${foo}" ) ) )
{
assertEquals( "[email protected] bar", IOUtils.toString( reader ) );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.io.StringReader;
import java.util.Properties;

import org.apache.maven.shared.utils.io.IOUtil;
import org.apache.commons.io.IOUtils;
import org.codehaus.plexus.PlexusTestCase;

/**
Expand All @@ -35,7 +35,6 @@ public class DefaultMavenReaderFilterTest
public void testJustDoSomeFiltering()
throws Exception
{
assertNotNull( DefaultMavenReaderFilter.class );
MavenReaderFilter readerFilter = lookup( MavenReaderFilter.class );

StringReader src = new StringReader( "[email protected] ${foo}" );
Expand All @@ -46,8 +45,9 @@ public void testJustDoSomeFiltering()
req.setFiltering( true );
req.setAdditionalProperties( additionalProperties );

final Reader filter = readerFilter.filter( req );

assertEquals( "[email protected] bar", IOUtil.toString( filter ) );
try ( Reader filter = readerFilter.filter( req ) )
{
assertEquals( "[email protected] bar", IOUtils.toString( filter ) );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
import java.util.List;
import java.util.Properties;

import org.apache.commons.io.IOUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Resource;
import org.apache.maven.settings.Settings;
import org.apache.maven.shared.utils.io.FileUtils;
import org.apache.maven.shared.utils.io.IOUtil;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.interpolation.PrefixedObjectValueSource;
import org.codehaus.plexus.interpolation.ValueSource;
Expand Down Expand Up @@ -395,9 +395,9 @@ public static boolean filesAreIdentical( File expected, File current )
FileInputStream currentIn = new FileInputStream( current ) )
{

byte[] expectedBuffer = IOUtil.toByteArray( expectedIn );
byte[] expectedBuffer = IOUtils.toByteArray( expectedIn );

byte[] currentBuffer = IOUtil.toByteArray( currentIn );
byte[] currentBuffer = IOUtils.toByteArray( currentIn );
if ( expectedBuffer.length != currentBuffer.length )
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@

import java.io.File;
import java.io.FileInputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

import org.apache.commons.io.IOUtils;
import org.apache.maven.model.Resource;
import org.apache.maven.shared.utils.io.FileUtils;
import org.apache.maven.shared.utils.io.IOUtil;
import org.codehaus.plexus.PlexusTestCase;

/**
Expand Down Expand Up @@ -91,7 +92,7 @@ public void testEscape()

try ( FileInputStream in = new FileInputStream( new File( outputDirectory, "content.xml" ) ) )
{
String content = IOUtil.toString( in );
String content = IOUtils.toString( in, StandardCharsets.UTF_8 );
assertTrue( content.contains( "<broken-tag>Content with replacement: I am the replacement !</broken-tag>" ) );
assertTrue( content.contains( "<broken-tag>Content with escaped replacement: Do not ${replaceThis} !</broken-tag>" ) );
}
Expand Down

0 comments on commit ced9ce5

Please sign in to comment.