org.codehaus.mojo.webstart.Utils Maven / Gradle / Ivy
package org.codehaus.mojo.webstart;
/*
* Copyright 2001-2007 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License" );
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.maven.plugin.MojoExecutionException;
import java.io.File;
class Utils
{
/**
* Delete a directory
*
* @param d the directory to delete
*/
public static void removeDir( File d )
throws MojoExecutionException
{
String[] list = d.list();
if ( list == null )
{
list = new String[0];
}
for ( int i = 0; i < list.length; i++ )
{
String s = list[i];
File f = new File( d, s );
if ( f.isDirectory() )
{
removeDir( f );
}
else
{
if ( !delete( f ) )
{
String message = "Unable to delete file " + f.getAbsolutePath();
throw new MojoExecutionException( message );
}
}
}
if ( !delete( d ) )
{
String message = "Unable to delete directory " + d.getAbsolutePath();
throw new MojoExecutionException( message );
}
}
/**
* Accommodate Windows bug encountered in both Sun and IBM JDKs.
* Others possible. If the delete does not work, call System.gc(),
* wait a little and try again.
*/
public static boolean delete( File f )
{
if ( !f.delete() )
{
if ( System.getProperty( "os.name" ).toLowerCase().indexOf( "windows" ) > -1 )
{
System.gc();
}
try
{
Thread.sleep( 10 );
return f.delete();
}
catch ( InterruptedException ex )
{
return f.delete();
}
}
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy