Skip to content

Commit

Permalink
replace deprecated code in favor of Java 7 core and apache commons li…
Browse files Browse the repository at this point in the history
…braries (#13)

* replace deprecated code in favor java 7 core and apache commons libraries
* declare dependency
* fix typos
* replace org.codehaus.plexus.util.IOUtil
* simplify logic
* use fixtures
* move setUp code to setUp method
  • Loading branch information
elharo authored Jul 22, 2020
1 parent 1bc58b3 commit 1a097bd
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 204 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
<artifactId>plexus-build-api</artifactId>
<version>0.0.7</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
import java.util.Arrays;
import java.util.List;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.maven.model.Resource;
import org.apache.maven.shared.utils.PathTool;
import org.apache.maven.shared.utils.ReaderFactory;
import org.apache.maven.shared.utils.StringUtils;
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.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.AbstractLogEnabled;
Expand Down Expand Up @@ -88,8 +88,8 @@ public boolean filteredFileExtension( String fileName, List<String> userNonFilte
{
nonFilteredFileExtensions.addAll( userNonFilteredFileExtensions );
}
boolean filteredFileExtension =
!nonFilteredFileExtensions.contains( StringUtils.lowerCase( FileUtils.extension( fileName ) ) );
String extension = StringUtils.lowerCase( FilenameUtils.getExtension( fileName ) );
boolean filteredFileExtension = !nonFilteredFileExtensions.contains( extension );
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "file " + fileName + " has a" + ( filteredFileExtension ? " " : " non " )
Expand Down Expand Up @@ -359,13 +359,14 @@ static String getEncoding( File file, String encoding, String propertiesEncoding
*/
static boolean isPropertiesFile( File file )
{
return "properties".equals( StringUtils.lowerCase( FileUtils.extension( file.getName() ) ) );
String extension = StringUtils.lowerCase( FilenameUtils.getExtension( ( file.getName() ) ) );
return "properties".equals( extension );
}

private void handleDefaultFilterWrappers( MavenResourcesExecution mavenResourcesExecution )
throws MavenFilteringException
{
List<FileUtils.FilterWrapper> filterWrappers = new ArrayList<>();
List<FilterWrapper> filterWrappers = new ArrayList<>();
if ( mavenResourcesExecution.getFilterWrappers() != null )
{
filterWrappers.addAll( mavenResourcesExecution.getFilterWrappers() );
Expand Down Expand Up @@ -505,7 +506,7 @@ private String filterFileName( String name, List<FilterWrapper> wrappers )

try ( StringWriter writer = new StringWriter() )
{
IOUtil.copy( reader, writer );
IOUtils.copy( reader, writer );
String filteredFilename = writer.toString();

if ( getLogger().isDebugEnabled() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.codehaus.plexus.interpolation.multi.DelimiterSpecification;

/**
* A FilterReader implementation, that works with Interpolator interface instead of it's own interpolation
* A FilterReader implementation, that works with Interpolator interface instead of its own interpolation
* implementation. This implementation is heavily based on org.codehaus.plexus.util.InterpolationFilterReader.
*
* @author cstamas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private static String getPropertyValue( String k, Properties p, Logger logger )

/**
* Logs the detected cycle in properties resolution
* @param valueChain the secuence of properties resolved so fa
* @param valueChain the sequence of properties resolved so far
* @param nk the key the closes the cycle
* @param logger Logger instance
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public void setDelimitersShouldAddDefaultDelimitersIfUseDefaultDelimitersIfNotNu
@Test
public void setDelimitersShouldAddDefaultDelimitersIfUseDefaultDelimitersIfSingleElementIsGiven()
{
LinkedHashSet<String> delimiters = new LinkedHashSet<>();
delimiters.add( "test" );
request.setDelimiters( delimiters, true );
assertThat( request.getDelimiters(), Matchers.contains( "${*}", "@", "test" ) );
Expand All @@ -95,7 +94,6 @@ public void setDelimitersShouldAddDefaultDelimitersIfUseDefaultDelimitersIfSingl
@Test
public void setDelimitersShouldAddDefaultDelimitersForNullElement()
{
LinkedHashSet<String> delimiters = new LinkedHashSet<>();
delimiters.add( "test" );
delimiters.add( null );
delimiters.add( "second" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.File;
import java.io.Reader;
import java.io.StringReader;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -31,7 +32,6 @@

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.codehaus.plexus.PlexusTestCase;

Expand All @@ -50,10 +50,7 @@ protected void setUp()
throws Exception
{
super.setUp();
if ( to.exists() )
{
FileUtils.forceDelete( to );
}
Files.deleteIfExists( to.toPath() );
}

public void testNotOverwriteFile()
Expand Down
Loading

0 comments on commit 1a097bd

Please sign in to comment.