You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2022/01/08 15:36:51 UTC
[maven-surefire] 01/01: [SUREFIRE-1869] Replace deprecated File.toURL() by File.toURI().toURL()
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch fix/SUREFIRE-1869
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
commit bd5c6304a2382d2804f1afe7dd1fbb5bbce2af83
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Sat Jan 8 16:36:23 2022 +0100
[SUREFIRE-1869] Replace deprecated File.toURL() by File.toURI().toURL()
File.toURL() - does not automatically escape illegal characters
---
.../apache/maven/surefire/booter/Classpath.java | 2 +-
.../maven/surefire/booter/ClasspathTest.java | 23 +++++++++++-----------
.../surefire/booter/IsolatedClassLoaderTest.java | 2 +-
.../surefire/booter/NewClassLoaderRunner.java | 11 +++++++----
.../surefire-946-self-destruct-plugin/pom.xml | 2 +-
.../resources/test-helper-dump-pid-plugin/pom.xml | 2 +-
6 files changed, 22 insertions(+), 20 deletions(-)
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
index b2ed4e6..ef5265c 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
@@ -146,7 +146,7 @@ public final class Classpath implements Iterable<String>, Cloneable
IsolatedClassLoader classLoader = new IsolatedClassLoader( parent, childDelegation, roleName );
for ( String classPathElement : unmodifiableElements )
{
- classLoader.addURL( new File( classPathElement ).toURL() );
+ classLoader.addURL( new File( classPathElement ).toURI().toURL() );
}
if ( parent != null )
{
diff --git a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java
index 38387d5..023e836 100644
--- a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java
+++ b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java
@@ -20,6 +20,7 @@ package org.apache.maven.surefire.booter;
*/
import java.io.File;
+import java.net.URI;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
@@ -201,8 +202,8 @@ public class ClasspathTest
URL url = target.getResource( thisPath );
assertTrue( url.toString().endsWith( thisPath ) );
String s = url.toString().replace( thisPath, "" ).replace( "!", "" ).replace( "jar:file:", "file:" );
- String oneClasspath = new URL( s ).getFile();
- assertTrue( new File( oneClasspath ).exists() );
+ URI oneClasspath = new URI( s );
+ assertTrue( "File: '" + oneClasspath + "' should exist", new File( oneClasspath ).exists() );
Classpath classpath = Classpath.emptyClasspath();
ClassLoader classLoader = classpath.addClassPathElementUrl( new File( oneClasspath ).getCanonicalPath() )
.createClassLoader( false, true, "" );
@@ -212,22 +213,20 @@ public class ClasspathTest
assertNotSame( cls, target );
}
- public void testDontLoadInNewClassLoader()
+ public void testDontLoadInNewClassLoader() throws SurefireExecutionException
{
Class<?> target = ConsoleLogger.class;
- String thisPath = "/" + target.getName().replace( '.', '/' ) + ".class";
- URL url = target.getResource( thisPath );
- assertTrue( url.toString().endsWith( thisPath ) );
+
+ ClassLoader classLoader = emptyClasspath().createClassLoader( false, true, "" );
+
try
{
- Classpath.emptyClasspath()
- .addClassPathElementUrl( "\u0000" )
- .createClassLoader( false, true, "" );
- fail();
+ classLoader.loadClass( target.getName() );
+ fail( "Class should not be loaded" );
}
- catch ( SurefireExecutionException e )
+ catch ( ClassNotFoundException e )
{
- // expected
+ assertEquals( target.getName(), e.getMessage() );
}
}
}
diff --git a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/IsolatedClassLoaderTest.java b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/IsolatedClassLoaderTest.java
index 9b93e52..2e00290 100644
--- a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/IsolatedClassLoaderTest.java
+++ b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/IsolatedClassLoaderTest.java
@@ -50,7 +50,7 @@ public class IsolatedClassLoaderTest
for ( String file : files )
{
- URL fileUrl = new File( file ).toURL();
+ URL fileUrl = new File( file ).toURI().toURL();
classLoader.addURL( fileUrl );
}
}
diff --git a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/NewClassLoaderRunner.java b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/NewClassLoaderRunner.java
index 8fd653b..154a87e 100644
--- a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/NewClassLoaderRunner.java
+++ b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/NewClassLoaderRunner.java
@@ -216,6 +216,7 @@ public class NewClassLoaderRunner
}
catch ( IOException e )
{
+ e.printStackTrace();
return new URL[0];
}
}
@@ -225,7 +226,7 @@ public class NewClassLoaderRunner
Collection<URL> classPath = new HashSet<>();
for ( String file : path.split( pathSeparator ) )
{
- classPath.add( new File( file ).toURL() );
+ classPath.add( new File( file ).toURI().toURL() );
}
return classPath;
}
@@ -241,13 +242,15 @@ public class NewClassLoaderRunner
{
File f = new File( file );
File dir = f.getParentFile();
- classPath.add( ( dir.getName().equals( "target" ) ? new File( dir, "classes" ) : f ).toURL() );
+ classPath.add(
+ ( dir.getName().equals( "target" ) ? new File( dir, "classes" ) : f ).toURI().toURL() );
}
- classPath.add( new File( "target/classes" ).toURL() );
- classPath.add( new File( "target/test-classes" ).toURL() );
+ classPath.add( new File( "target/classes" ).toURI().toURL() );
+ classPath.add( new File( "target/test-classes" ).toURI().toURL() );
}
catch ( IOException e )
{
+ e.printStackTrace();
// turn to java.class.path
classPath.clear();
}
diff --git a/surefire-its/src/test/resources/surefire-946-self-destruct-plugin/pom.xml b/surefire-its/src/test/resources/surefire-946-self-destruct-plugin/pom.xml
index 5abb052..ddad27e 100644
--- a/surefire-its/src/test/resources/surefire-946-self-destruct-plugin/pom.xml
+++ b/surefire-its/src/test/resources/surefire-946-self-destruct-plugin/pom.xml
@@ -29,7 +29,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
- <version>2.9</version>
+ <version>3.6.1</version>
<configuration>
<goalPrefix>maven-selfdestruct-plugin</goalPrefix>
</configuration>
diff --git a/surefire-its/src/test/resources/test-helper-dump-pid-plugin/pom.xml b/surefire-its/src/test/resources/test-helper-dump-pid-plugin/pom.xml
index f6bfa7c..4cc41d4 100644
--- a/surefire-its/src/test/resources/test-helper-dump-pid-plugin/pom.xml
+++ b/surefire-its/src/test/resources/test-helper-dump-pid-plugin/pom.xml
@@ -40,7 +40,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
- <version>3.2</version>
+ <version>3.6.1</version>
<configuration>
<!-- see https://issues.apache.org/jira/browse/MNG-5346 -->
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>