Skip to content
Merged
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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ under the License.
</parent>

<artifactId>maven-remote-resources-plugin</artifactId>
<version>3.0.1-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>Apache Maven Remote Resources Plugin</name>
Expand Down Expand Up @@ -68,7 +68,7 @@ under the License.
</distributionManagement>

<properties>
<javaVersion>7</javaVersion>
<javaVersion>8</javaVersion>
<mavenVersion>3.2.5</mavenVersion>
<project.build.outputTimestamp>2022-07-17T16:33:17Z</project.build.outputTimestamp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,8 @@ public static void mergeReportPluginDefinitions( ReportPlugin child, ReportPlugi

Map<String, ReportSet> childReportSets = child.getReportSetsAsMap();

for ( Object parentReportSet1 : parentReportSets )
for ( ReportSet parentReportSet : parentReportSets )
{
ReportSet parentReportSet = (ReportSet) parentReportSet1;

if ( !handleAsInheritance || parentIsInherited )
{
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.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
Expand All @@ -38,6 +37,7 @@
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.text.SimpleDateFormat;
import java.util.AbstractMap;
import java.util.ArrayList;
Expand Down Expand Up @@ -493,7 +493,7 @@ public void execute()
catch ( MalformedURLException e )
{
// ignore
getLog().debug( "URL issue with supplemental-models.xml: " + e.toString() );
getLog().debug( "URL issue with supplemental-models.xml: " + e );
}
}
}
Expand Down Expand Up @@ -696,7 +696,7 @@ protected List<MavenProject> getProjects()
getLog().debug( "Adding project with groupId [" + p.getGroupId() + "]" );
}
}
Collections.sort( projects, new ProjectComparator() );
projects.sort( new ProjectComparator( ) );
return projects;
}

Expand All @@ -714,12 +714,7 @@ private Set<Artifact> resolveProjectArtifacts()
return dependencyResolver.resolve( project, Arrays.asList( resolveScopes ), mavenSession );
}
}
catch ( ArtifactResolutionException e )
{
throw new IllegalStateException( "Failed to resolve dependencies for one or more projects in the reactor. "
+ "Reason: " + e.getMessage(), e );
}
catch ( ArtifactNotFoundException e )
catch ( ArtifactResolutionException | ArtifactNotFoundException e )
{
throw new IllegalStateException( "Failed to resolve dependencies for one or more projects in the reactor. "
+ "Reason: " + e.getMessage(), e );
Expand Down Expand Up @@ -873,7 +868,7 @@ private Reader getReader( File source ) throws IOException
{
if ( encoding != null )
{
return new InputStreamReader( new FileInputStream( source ), encoding );
return new InputStreamReader( Files.newInputStream( source.toPath() ), encoding );
}
else
{
Expand Down Expand Up @@ -918,9 +913,9 @@ private void fileWriteIfDiffers( DeferredFileOutputStream outStream )

if ( file.exists() )
{
try ( InputStream is = new FileInputStream( file ) )
try ( InputStream is = Files.newInputStream( file.toPath() );
InputStream newContents = new ByteArrayInputStream( outStream.getData() ) )
{
final InputStream newContents = new ByteArrayInputStream( outStream.getData() );
needOverwrite = !IOUtil.contentEquals( is, newContents );
if ( getLog().isDebugEnabled() )
{
Expand All @@ -937,7 +932,7 @@ private void fileWriteIfDiffers( DeferredFileOutputStream outStream )
}
getLog().debug( "Writing " + file );

try ( OutputStream os = new FileOutputStream( file ) )
try ( OutputStream os = Files.newOutputStream( file.toPath() ) )
{
outStream.writeTo( os );
}
Expand Down Expand Up @@ -1279,7 +1274,7 @@ protected void processResourceBundles( ClassLoader classLoader, VelocityContext
if ( appendedResourceFile.exists() )
{
getLog().info( "Copying appended resource: " + projectResource );
try ( InputStream in = new FileInputStream( appendedResourceFile );
try ( InputStream in = Files.newInputStream( appendedResourceFile.toPath() );
OutputStream out = new FileOutputStream( f, true ) )
{
IOUtil.copy( in, out );
Expand Down Expand Up @@ -1374,7 +1369,7 @@ private static String generateSupplementMapKey( String groupId, String artifactI
return groupId.trim() + ":" + artifactId.trim();
}

private Map<String, Model> loadSupplements( String models[] )
private Map<String, Model> loadSupplements( String[] models )
throws MojoExecutionException
{
if ( models == null )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,38 @@
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.LegacyLocalRepositoryManager;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.plugin.resources.remote.stub.MavenProjectBuildStub;
import org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.logging.console.ConsoleLoggerManager;
import org.codehaus.plexus.util.FileUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Properties;
import java.util.Collections;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;
import org.codehaus.plexus.util.IOUtil;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.internal.impl.EnhancedLocalRepositoryManagerFactory;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.LocalRepositoryManager;


/**
* RemoteResources plugin Test Case
*/

public class RemoteResourcesMojoTest
extends AbstractMojoTestCase
{
Expand Down Expand Up @@ -256,12 +247,12 @@ public void testVelocityUTF8()
file = new File( file, "UTF-8.bin" );
assertTrue( file.exists() );

InputStream in = new FileInputStream( file );
byte[] data = IOUtil.toByteArray( in );
in.close();

byte[] expected = "\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00DF".getBytes( "UTF-8" );
assertTrue( Arrays.equals( expected, data ) );
try (InputStream in = Files.newInputStream( file.toPath( ) ) )
{
byte[] data = IOUtil.toByteArray( in );
byte[] expected = "\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00DF".getBytes( StandardCharsets.UTF_8 );
assertTrue( Arrays.equals( expected, data ) );
}
}

public void testVelocityISO88591()
Expand Down Expand Up @@ -297,12 +288,13 @@ public void testVelocityISO88591()
file = new File( file, "ISO-8859-1.bin" );
assertTrue( file.exists() );

InputStream in = new FileInputStream( file );
byte[] data = IOUtil.toByteArray( in );
in.close();
try (InputStream in = Files.newInputStream( file.toPath() ) )
{
byte[] data = IOUtil.toByteArray( in );
byte[] expected = "\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00DF".getBytes( StandardCharsets.ISO_8859_1 );
assertTrue( Arrays.equals( expected, data ) );
}

byte[] expected = "\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00DF".getBytes( "ISO-8859-1" );
assertTrue( Arrays.equals( expected, data ) );
}

public void testFilteredBundles()
Expand Down Expand Up @@ -386,7 +378,7 @@ public void testFilteredBundlesWithProjectProperties()

protected void buildResourceBundle( String id,
String sourceEncoding,
String resourceNames[],
String[] resourceNames,
File jarName )
throws Exception
{
Expand Down Expand Up @@ -418,21 +410,24 @@ protected void buildResourceBundle( String id,

if ( null != jarName )
{
JarOutputStream jar = new JarOutputStream( new FileOutputStream( jarName ) );
jar.putNextEntry( new ZipEntry( "META-INF/maven/remote-resources.xml" ) );
jar.write( data.getBytes() );
jar.closeEntry();

for ( String resourceName : resourceNames )
try ( OutputStream fos = Files.newOutputStream( jarName.toPath() );
JarOutputStream jar = new JarOutputStream( fos ) )
{
File resource = new File( resourceDir, resourceName );
InputStream in = new FileInputStream( resource );
jar.putNextEntry( new ZipEntry( resourceName ) );
IOUtil.copy( in, jar );
jar.putNextEntry( new ZipEntry( "META-INF/maven/remote-resources.xml" ) );
jar.write( data.getBytes() );
jar.closeEntry();
in.close();

for ( String resourceName : resourceNames )
{
File resource = new File( resourceDir, resourceName );
try ( InputStream in = Files.newInputStream( resource.toPath() ) )
{
jar.putNextEntry( new ZipEntry( resourceName ) );
IOUtil.copy( in, jar );
jar.closeEntry();
}
}
}
jar.close();
}
}

Expand Down Expand Up @@ -500,7 +495,7 @@ protected ProcessRemoteResourcesMojo lookupProcessMojo()


protected ProcessRemoteResourcesMojo lookupProcessMojoWithSettings( final MavenProject project,
String bundles[] )
String[] bundles )
throws Exception
{
return lookupProcessMojoWithSettings( project, new ArrayList<>( Arrays.asList( bundles ) ) );
Expand All @@ -522,11 +517,11 @@ protected ProcessRemoteResourcesMojo lookupProcessMojoWithSettings( final MavenP
request = new DefaultMavenExecutionRequest();
request.setUserProperties( null );
request.setLocalRepository( localRepository );
request.setGoals( Arrays.asList( "install" ) );
request.setGoals(Collections.singletonList( "install" ) );
request.setBaseDirectory( project.getBasedir() );
request.setStartTime( Calendar.getInstance().getTime() );
MavenSession session = new MavenSession( getContainer(), reposession, request, new DefaultMavenExecutionResult() );
session.setProjects( Arrays.asList( project ) );
session.setProjects( Collections.singletonList( project ) );

setVariableValueToObject( mojo, "project", project );
setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild().getOutputDirectory() ) );
Expand All @@ -540,6 +535,6 @@ protected ProcessRemoteResourcesMojo lookupProcessMojoWithSettings( final MavenP
protected ProcessRemoteResourcesMojo lookupProcessMojoWithDefaultSettings( final MavenProject project )
throws Exception
{
return lookupProcessMojoWithSettings( project, new ArrayList<String>() );
return lookupProcessMojoWithSettings( project, new ArrayList<>() );
}
}