public static File extractResourceToDestination()

in src/main/java/org/apache/maven/shared/verifier/util/ResourceExtractor.java [74:112]


    public static File extractResourceToDestination( Class<?> cl, String resourcePath, File destination,
                                                     boolean alwaysExtract )
        throws IOException
    {
        URL url = cl.getResource( resourcePath );
        if ( url == null )
        {
            throw new IllegalArgumentException( "Resource not found: " + resourcePath );
        }
        if ( "jar".equalsIgnoreCase( url.getProtocol() ) )
        {
            File jarFile = getJarFileFromUrl( url );
            extractResourcePathFromJar( cl, jarFile, resourcePath, destination );
        }
        else
        {
            try
            {
                File resourceFile = new File( new URI( url.toExternalForm() ) );
                if ( !alwaysExtract )
                {
                    return resourceFile;
                }
                if ( resourceFile.isDirectory() )
                {
                    FileUtils.copyDirectoryStructure( resourceFile, destination );
                }
                else
                {
                    FileUtils.copyFile( resourceFile, destination );
                }
            }
            catch ( URISyntaxException e )
            {
                throw new RuntimeException( "Couldn't convert URL to File:" + url, e );
            }
        }
        return destination;
    }