1 package org.codehaus.mojo.webstart.util; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.io.File; 23 import java.io.FileFilter; 24 import java.net.URI; 25 import java.util.zip.ZipFile; 26 27 import org.apache.maven.plugin.MojoExecutionException; 28 29 /** 30 * Helper for all IO operations. 31 * 32 * @author tchemit <chemit@codelutin.com> 33 * @since 1.0-beta-4 34 */ 35 public interface IOUtil 36 { 37 38 /** 39 * Plexus component role. 40 */ 41 String ROLE = IOUtil.class.getName(); 42 43 /** 44 * Copy the content of a directory to another one recursively. 45 * 46 * @param sourceDirectory directory to copy 47 * @param targetDirectory where to copy 48 * @throws MojoExecutionException if could not perform operation 49 */ 50 void copyResources( File sourceDirectory, File targetDirectory ) 51 throws MojoExecutionException; 52 53 /** 54 * Copy directory structure from {@code sourceDirectory} to {@code targetDirectory}. 55 * 56 * @param sourceDirectory source of copy 57 * @param targetDirectory target of copy 58 * @throws MojoExecutionException if could not perform operation 59 */ 60 void copyDirectoryStructure( File sourceDirectory, File targetDirectory ) 61 throws MojoExecutionException; 62 63 /** 64 * @param sourceFile source file 65 * @param targetFile target file 66 * @return {@code true} if source file should be copy to target location 67 */ 68 boolean shouldCopyFile( File sourceFile, File targetFile ); 69 70 /** 71 * Conditionally copy the file into the target directory. 72 * The operation is not performed when the target file exists and is up to date. 73 * The target file name is taken from the <code>sourceFile</code> name. 74 * 75 * @param sourceFile source file to copy 76 * @param targetDirectory location of the target directory where to copy file 77 * @return <code>true</code> when the file was copied, <code>false</code> otherwise. 78 * @throws MojoExecutionException if an error occurs attempting to copy the file. 79 */ 80 boolean copyFileToDirectoryIfNecessary( File sourceFile, File targetDirectory ) 81 throws MojoExecutionException; 82 83 void copyFile( File sourceFile, File targetFile ) 84 throws MojoExecutionException; 85 86 /** 87 * Delete the specified directory. 88 * 89 * @param dir the directory to delete 90 * @throws MojoExecutionException if could not delete directory 91 */ 92 void removeDirectory( File dir ) 93 throws MojoExecutionException; 94 95 /** 96 * Create the given directory if it does not exist. 97 * <p/> 98 * will throw an exception if could not perform the operation. 99 * 100 * @param dir the dir to create if it does not exist 101 * @throws MojoExecutionException if could not create directory 102 */ 103 void makeDirectoryIfNecessary( File dir ) 104 throws MojoExecutionException; 105 106 /** 107 * @param directory location of directory where to delete some files 108 * @param fileFilter filter to select files to delete 109 * @return the number of deleted files 110 * @throws MojoExecutionException if could not delete files 111 */ 112 int deleteFiles( File directory, FileFilter fileFilter ) 113 throws MojoExecutionException; 114 115 /** 116 * Delete a file. 117 * <p/> 118 * will throw an exception if could not perform the operation. 119 * 120 * @param file the file to delete 121 * @throws MojoExecutionException if could not delete file 122 */ 123 void deleteFile( File file ) 124 throws MojoExecutionException; 125 126 /** 127 * Rename a file. 128 * <p/> 129 * will throw an exception if could not perform the operation. 130 * 131 * @param source original file to renmae 132 * @param target target file 133 * @throws MojoExecutionException if could not rename file 134 */ 135 void renameTo( File source, File target ) 136 throws MojoExecutionException; 137 138 /** 139 * Copy a resource from the given uri to {@code target} file. 140 * <p/> 141 * The resource can come from class-path is the scheme is {@code classpath}, otherwise will try to get incoming 142 * resource from the url obtained from the uri. 143 * 144 * @param uri uri to copy 145 * @param classLoader classloader used to find resource in from classpaht 146 * @param target where to copy 147 * @throws MojoExecutionException if something wrong happen 148 */ 149 void copyResources( URI uri, ClassLoader classLoader, File target ) 150 throws MojoExecutionException; 151 152 /** 153 * Silently closes the resource 154 * 155 * @param closeable 156 */ 157 void close( ZipFile closeable ); 158 159 void createArchive(File directory, File archive) 160 throws MojoExecutionException; 161 }