Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SUREFIRE-1869] Replace deprecated File.toURL() by File.toURI().toURL() #435

Merged
merged 1 commit into from Jan 9, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -146,7 +146,7 @@ public ClassLoader createClassLoader( boolean childDelegation, boolean enableAss
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 )
{
Expand Down
Expand Up @@ -20,6 +20,7 @@
*/

import java.io.File;
import java.net.URI;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -201,8 +202,8 @@ public void testLoadInNewClassLoader() throws Exception
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, "" );
Expand All @@ -212,22 +213,20 @@ public void testLoadInNewClassLoader() throws Exception
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() );
}
}
}
Expand Up @@ -50,7 +50,7 @@ public void prepareClassLoader() throws Exception

for ( String file : files )
{
URL fileUrl = new File( file ).toURL();
URL fileUrl = new File( file ).toURI().toURL();
classLoader.addURL( fileUrl );
}
}
Expand Down
Expand Up @@ -216,6 +216,7 @@ private static URL[] toClassPath()
}
catch ( IOException e )
{
e.printStackTrace();
return new URL[0];
}
}
Expand All @@ -225,7 +226,7 @@ private static Collection<URL> toPathList( String path ) throws MalformedURLExce
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;
}
Expand All @@ -241,13 +242,15 @@ private static Collection<URL> toPathList()
{
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();
}
Expand Down
Expand Up @@ -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>
Expand Down
Expand Up @@ -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>
Expand Down