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


Java JarArchiver.createArchive方法代码示例

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


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

示例1: process

import org.codehaus.plexus.archiver.jar.JarArchiver; //导入方法依赖的package包/类
private File process() throws IOException, ManifestException {
    getLog().info("Building webjar for " + project.getArtifactId());
    File output = new File(buildDirectory, webjar.getOutputFileName());
    FileUtils.deleteQuietly(output);

    // Compute the set of selected files:
    Collection<File> selected = webjar.getSelectedFiles();
    if (selected.isEmpty()) {
        getLog().warn("No file selected in the webjar - skipping creation");
        return null;
    }
    String root = computeRoot();

    FileUtils.deleteQuietly(output);

    // Web jar are jar file, so use the Plexus Archiver.
    JarArchiver archiver = new JarArchiver();
    archiver.enableLogging(new PlexusLoggerWrapper(getLog()));
    String base = webjar.getFileset().getDirectory();
    for (File file : selected) {
        final String destFileName = root + "/" + file.getAbsolutePath().substring(base.length() + 1);
        getLog().debug(file.getName() + " => " + destFileName);
        archiver.addFile(file, destFileName);
    }

    // Extend the manifest with webjar data - this is not required by the webjar specification
    Manifest manifest = Manifest.getDefaultManifest();
    manifest.getMainSection().addConfiguredAttribute(new Manifest.Attribute("Webjar-Name", webjar.getName()));
    manifest.getMainSection().addConfiguredAttribute(new Manifest.Attribute("Webjar-Version", webjar.getVersion()));
    manifest.getMainSection().addConfiguredAttribute(new Manifest.Attribute("Created-By", "Wisdom Framework " +
            BuildConstants.get("WISDOM_PLUGIN_VERSION")));
    archiver.addConfiguredManifest(manifest);
    archiver.setDestFile(output);
    archiver.createArchive();
    return output;
}
 
开发者ID:wisdom-framework,项目名称:wisdom,代码行数:37,代码来源:WebJarPackager.java

示例2: 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.createArchive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。