[izpack-users] A small contribution

Rich Stephens rstephens at pathfire.com
Thu Apr 6 17:18:33 CEST 2006


I have a small contribution I would like to make to the izPack project.
I have never contributed to an open-source project before, so I'm not
exactly sure how to go about it.  I have added copyDir functions to the
IoHelper class that will copy an entire directory structure from one
directory to another, using the current CopyFile function, with the same
function signature(s).  That is to say, all the features of the CopyFile
function are available when copying directories (permissions, variable
substitution, etc).  The source directory named will be copied along
with all of its contents to the target directory.  The target directory
will be created if it does not exist.

Thanks,
Rich Stephens
Pathfire, Inc.
http://www.pathfire.com

The source for this feature should be added to IoHelper.java, and is
pasted below:

/**
     * Copies the contents of inDir into outDir.
     * 
     * @param inFile path of directory which should be copied
     * @param outFile path of directory to create and copy indir and its
contents into
     */
    public static void copyDir(String inDir, String outDir) throws
IOException
    {
        copyDir(new File(inDir), new File(outDir));
    }

    /**
     * Creates an in- and output stream for the given File objects (that
represent directories)
     * and copies the directory and all its files from the specified
input to the specified output.
     * 
     * @param inDir File object for input
     * @param outDir File object for output
     * @exception IOException if an I/O error occurs
     */
    public static void copyDir(File inDir, File outDir) throws
IOException
    {
        copyDir(inDir, outDir, null, null);
    }

    /**
     * Creates an in- and output stream for the given File objects (that
represent directories)
     * and copies the directory and all its files from the specified
input to the specified output.
     * If permissions is not null, a chmod will be done on the output
directory.
     * 
     * @param inDir File object for input
     * @param outDir File object for output
     * @param permissions permissions for the output file(s) &
directories.
     * @exception IOException if an I/O error occurs
     */
    public static void copyDir(File inDir, File outDir, String
permissions) throws IOException
    {
        copyDir(inDir, outDir, permissions, null);
    }

    /**
     * Recursively a directory and its contents of a directory from the
specified input
     * to the specified output. If the VariableSubstitutor is not null,
a substition will
     * be done during copy.
     * 
     * @param inDir File object for input
     * @param outDir File object for output
     * @param vss substitutor which is used during copying
     * @exception IOException if an I/O error occurs
     */
    public static void copyDir(File inDir, File outDir,
VariableSubstitutor vss)
            throws IOException
    {
        copyDir(inDir, outDir, null, vss);
    }

    /**
     * Recursively copy a directory and its contents from the specified
input to the
     * specified output. If the VariableSubstitutor is not null, a
substition
     * will be done during copy. If permissions is not null, a chmod
will be done on
     * the output directory.
     * 
     * @param inDir File object for input
     * @param outDir File object for output
     * @param permissions permissions for the output file(s) &
directories.
     * @param vs substitutor which is used during copying
     * @exception IOException if an I/O error occurs
     */
    public static void copyDir(File inDir, File outDir, String
permissions,
            VariableSubstitutor vs) throws IOException
    {
        copyDir(inDir, outDir, permissions, vs, null);
    }
    
    /**
     * Recursively copy contents of a directory using copyFile:
     * 
     * @param inDir
     * @param outDir
     * @param permissions permissions for the output file
     * @param vs substitutor which is used during copying
     * @param type file type for the substitutor
     */
    public static void copyDir(File inDir, File outDir, String
permissions,
    	VariableSubstitutor vs, String type) throws IOException
    {
    	// Make the output directory
    	outDir.mkdirs();
    	if (permissions != null && IoHelper.supported("chmod"))
        {
            chmod(outDir.getAbsolutePath(), permissions);
        }
    	
    	File [] inlist = inDir.listFiles();
    	for (int i = 0; i < inlist.length; i++)
    	{
    		String inPath = inDir.getCanonicalPath();
    		String filePath = inlist[i].getCanonicalPath();
    		String relativePath =
filePath.substring(inPath.length());
    		File newOutPath = new File(outDir, relativePath);
	
    		if (inlist[i].equals(outDir))
    			continue;
    		if (inlist[i].isFile())
    			copyFile(inlist[i], newOutPath, permissions, vs,
type);
    		else
    			copyDir(inlist[i], newOutPath, permissions, vs,
type);
    	}
    }




More information about the izpack-users mailing list