当前位置: 首页>>代码示例>>Java>>正文


Java JarArchiver.addDirectory方法代码示例

本文整理汇总了Java中org.codehaus.plexus.archiver.jar.JarArchiver.addDirectory方法的典型用法代码示例。如果您正苦于以下问题:Java JarArchiver.addDirectory方法的具体用法?Java JarArchiver.addDirectory怎么用?Java JarArchiver.addDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.plexus.archiver.jar.JarArchiver的用法示例。


在下文中一共展示了JarArchiver.addDirectory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: copyFile

import org.codehaus.plexus.archiver.jar.JarArchiver; //导入方法依赖的package包/类
/**
 * Copy file from source to destination. The directories up to <code>destination</code> will be created if they
 * don't already exist. if the <code>onlyIfModified</code> flag is <tt>false</tt>, <code>destination</code> will be
 * overwritten if it already exists. If the flag is <tt>true</tt> destination will be overwritten if it's not up to
 * date.
 * <p/>
 *
 * @param context the packaging context
 * @param source an existing non-directory <code>File</code> to copy bytes from
 * @param destination a non-directory <code>File</code> to write bytes to (possibly overwriting).
 * @param targetFilename the relative path of the file from the webapp root directory
 * @param onlyIfModified if true, copy the file only if the source has changed, always copy otherwise
 * @return true if the file has been copied/updated, false otherwise
 * @throws IOException if <code>source</code> does not exist, <code>destination</code> cannot be written to, or an
 *             IO error occurs during copying
 */
protected boolean copyFile( WarPackagingContext context, File source, File destination, String targetFilename,
                            boolean onlyIfModified )
    throws IOException
{
    if ( onlyIfModified && destination.lastModified() >= source.lastModified() )
    {
        context.getLog().debug( " * " + targetFilename + " is up to date." );
        return false;
    }
    else
    {
        if ( source.isDirectory() )
        {
            context.getLog().warn( " + " + targetFilename + " is packaged from the source folder" );

            try
            {
                JarArchiver archiver = context.getJarArchiver();
                archiver.addDirectory( source );
                archiver.setDestFile( destination );
                archiver.createArchive();
            }
            catch ( ArchiverException e )
            {
                String msg = "Failed to create " + targetFilename;
                context.getLog().error( msg, e );
                IOException ioe = new IOException( msg );
                ioe.initCause( e );
                throw ioe;
            }
        }
        else
        {
            FileUtils.copyFile( source.getCanonicalFile(), destination );
            // preserve timestamp
            destination.setLastModified( source.lastModified() );
            context.getLog().debug( " + " + targetFilename + " has been copied." );
        }
        return true;
    }
}
 
开发者ID:zhegexiaohuozi,项目名称:maven-seimicrawler-plugin,代码行数:58,代码来源:AbstractWarPackagingTask.java


注:本文中的org.codehaus.plexus.archiver.jar.JarArchiver.addDirectory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。