Package org.codehaus.plexus.archiver

Examples of org.codehaus.plexus.archiver.Archiver


        final File file) throws MojoExecutionException
    {
        final String archiveExt = FileUtils.getExtension(file.getAbsolutePath()).toLowerCase();
        try
        {
            final Archiver archiver;
            archiver = this.archiverManager.getArchiver(archiveExt);
            archiver.setDestFile(file);
            archiver.addDirectory(location);
            archiver.createArchive();
        }
        catch (Throwable throwable)
        {
            if (throwable instanceof IOException || throwable instanceof ArchiverException)
            {
View Full Code Here


     * @required
     */
    private File xarDirectory;
   
    public void execute() throws MojoExecutionException {
        Archiver archiver = new DirectoryArchiver();
        archiver.setDestFile(xarDirectory);
        try {
            buildArchive(archiver);
            archiver.createArchive();
        } catch (ArchiverException e) {
            throw new MojoExecutionException("Unable to build archive", e);
        } catch (IOException e) {
            throw new MojoExecutionException("Unable to build archive", e);
        }
View Full Code Here

    public File archive(String sourcePath, String destPath, Artifact artifact) throws ArchiverException, IOException {
        File source = serverInfo.resolve(sourcePath);
        File dest = serverInfo.resolve(destPath);
        String serverName = artifact.getArtifactId() + "-" + artifact.getVersion();
        dest = new File(dest, serverName + "-bin." + artifact.getType());
        Archiver archiver;
        if ("tar.gz".equals(artifact.getType())) {
            archiver = new TarArchiver();
            TarArchiver.TarCompressionMethod tarCompressionMethod = new TarArchiver.TarCompressionMethod();
            tarCompressionMethod.setValue("gzip");
            ((TarArchiver) archiver).setCompression(tarCompressionMethod);
            TarLongFileMode fileMode = new TarLongFileMode();
            fileMode.setValue(TarLongFileMode.GNU);
            ((TarArchiver) archiver).setLongfile(fileMode);
        } else if ("zip".equals(artifact.getType())) {
            archiver = new ZipArchiver();
        } else {
            throw new IllegalArgumentException("Unknown target type: " + artifact.getType());
        }
        archiver.setIncludeEmptyDirs(true);
        archiver.setDestFile(dest);
/* see if using plexus-archiver 1.0-alpha-7 same as maven lets us share code.  Following is for 1.0-alpha-9
        DefaultFileSet all = new DefaultFileSet();
        all.setDirectory(source);
        archiver.addFileSet(all);
*/
       
        // add in all files and mark them with default file permissions
        Map<String, File> all = IOUtil.listAllFileNames(source);
        for (Map.Entry<String, File> entry : all.entrySet()) {
            String destFileName = serverName + "/" + entry.getKey();
            File sourceFile = entry.getValue();
            if (sourceFile.isFile()) {
                archiver.addFile(sourceFile, destFileName, UnixStat.DEFAULT_FILE_PERM);
            }
        }

        // add execute permissions to all non-batch files in the bin/ directory
        File bin = new File(source, "bin");
        if (bin.exists()) {
            Map<String, File> includes = IOUtil.listAllFileNames(bin);
            for (Map.Entry<String, File> entry : includes.entrySet()) {
                String destFileName = serverName + "/bin/" + entry.getKey();
                File sourceFile = entry.getValue();
                if (!destFileName.endsWith(".bat") && sourceFile.isFile()) {
                    archiver.addFile(sourceFile, destFileName, UnixStat.DEFAULT_DIR_PERM);
                }
            }
        }
       
        archiver.createArchive();
        return dest;
    }
View Full Code Here

            // BUILD UBER-ZIP OF ARTIFACT + DEPENDENCIES

            getLog().info( "Processing: " + inputFile );

            final File uberZip = new File( workingDirectory, "uber-" + inputFile.getName() );
            final Archiver archiver = archiverManager.getArchiver( "zip" );

            archiver.setDestFile( uberZip );

            if ( inputFile.isDirectory() )
            {
                archiver.addDirectory( inputFile );
            }
            else
            {
                archiver.addArchivedFileSet( inputFile );
            }

            for ( final Artifact a : (Set<Artifact>) project.getArtifacts() )
            {
                if ( filter.include( a ) )
                {
                    try
                    {
                        archiver.addArchivedFileSet( a.getFile(), null, META_INF_EXCLUDES );
                    }
                    catch ( final Throwable e )
                    {
                        getLog().info( "Ignoring: " + a );
                        getLog().debug( e );
                    }
                }
            }

            if ( !archiver.getResources().hasNext() )
            {
                getLog().info( "Nothing to JarJar" );
                return;
            }

            archiver.createArchive();

            // JARJAR UBER-ZIP

            getLog().info( "JarJar'ing to: " + outputFile );
View Full Code Here

    @Test
    public void addFile_NoPerms_CallAcceptFilesOnlyOnce()
        throws IOException, ArchiverException
    {
        final MockControl delegateControl = MockControl.createControl( Archiver.class );
        final Archiver delegate = (Archiver) delegateControl.getMock();

        delegate.addFile( null, null );
        delegateControl.setMatcher( MockControl.ALWAYS_MATCHER );
        delegateControl.setVoidCallable();

        delegate.setForced( true );
        delegateControl.setVoidCallable( MockControl.ZERO_OR_MORE );

        final CounterSelector counter = new CounterSelector( true );
        final List<FileSelector> selectors = new ArrayList<FileSelector>();
        selectors.add( counter );
View Full Code Here

    @Test
    public void addDirectory_NoPerms_CallAcceptFilesOnlyOnce()
        throws IOException, ArchiverException
    {
        final Archiver delegate = new JarArchiver();

        final File output = fileManager.createTempFile();

        delegate.setDestFile( output );

        final CounterSelector counter = new CounterSelector( true );
        final List<FileSelector> selectors = new ArrayList<FileSelector>();
        selectors.add( counter );
View Full Code Here

            }

            final List<ContainerDescriptorHandler> containerHandlers =
                selectContainerDescriptorHandlers( assembly.getContainerDescriptorHandlers(), configSource );

            final Archiver archiver =
                createArchiver( format, assembly.isIncludeBaseDirectory(), basedir, configSource, containerHandlers );

            archiver.setDestFile( destFile );

            final AssemblyContext context = new DefaultAssemblyContext();

            dependencyResolver.resolve( assembly, configSource, context );

            for ( final Iterator<AssemblyArchiverPhase> phaseIterator = assemblyPhases.iterator(); phaseIterator.hasNext(); )
            {
                final AssemblyArchiverPhase phase = phaseIterator.next();

                phase.execute( assembly, archiver, configSource, context );
            }

            archiver.createArchive();
        }
        catch ( final ArchiverException e )
        {
            throw new ArchiveCreationException( "Error creating assembly archive " + assembly.getId() + ": "
                + e.getMessage(), e );
View Full Code Here

    protected Archiver createArchiver( final String format, final boolean includeBaseDir, final String finalName,
                                       final AssemblerConfigurationSource configSource,
                                       final List<ContainerDescriptorHandler> containerHandlers )
        throws ArchiverException, NoSuchArchiverException
    {
        Archiver archiver;
        if ( format.startsWith( "tar" ) )
        {
            archiver = createTarArchiver( format, configSource.getTarLongFileMode() );
        }
        else if ( "war".equals( format ) )
        {
            archiver = createWarArchiver();
        }
        else
        {
            archiver = archiverManager.getArchiver( format );
        }

        final List<FileSelector> extraSelectors = new ArrayList<FileSelector>();
        final List<ArchiveFinalizer> extraFinalizers = new ArrayList<ArchiveFinalizer>();
        if ( archiver instanceof JarArchiver )
        {
            extraSelectors.add( new JarSecurityFileSelector() );

            extraFinalizers.add( new ManifestCreationFinalizer( configSource.getProject(),
                                                                configSource.getJarArchiveConfiguration() ) );

        }

        if ( configSource.getArchiverConfig() != null )
        {
            configureArchiver( archiver, configSource );
        }

        String prefix = "";
        if ( includeBaseDir )
        {
            prefix = finalName;
        }

        archiver =
            new AssemblyProxyArchiver( prefix, archiver, containerHandlers, extraSelectors, extraFinalizers,
                                       configSource.getWorkingDirectory(), getLogger(), configSource.isDryRun() );

        archiver.setUseJvmChmod( configSource.isUpdateOnly() );
        archiver.setIgnorePermissions( configSource.isIgnorePermissions() );
        archiver.setForced( !configSource.isUpdateOnly() );

        return archiver;
    }
View Full Code Here

    public File archive(String sourcePath, String destPath, Artifact artifact) throws ArchiverException, IOException {
        File source = serverInfo.resolve(sourcePath);
        File dest = serverInfo.resolve(destPath);
        String serverName = artifact.getArtifactId() + "-" + artifact.getVersion();
        dest = new File(dest, serverName + "-bin." + artifact.getType());
        Archiver archiver;
        if ("tar.gz".equals(artifact.getType())) {
            archiver = new TarArchiver();
            TarArchiver.TarCompressionMethod tarCompressionMethod = new TarArchiver.TarCompressionMethod();
            tarCompressionMethod.setValue("gzip");
            ((TarArchiver) archiver).setCompression(tarCompressionMethod);
            TarLongFileMode fileMode = new TarLongFileMode();
            fileMode.setValue(TarLongFileMode.GNU);
            ((TarArchiver) archiver).setLongfile(fileMode);
        } else if ("zip".equals(artifact.getType())) {
            archiver = new ZipArchiver();
        } else {
            throw new IllegalArgumentException("Unknown target type: " + artifact.getType());
        }
        archiver.setIncludeEmptyDirs(true);
        archiver.setDestFile(dest);
/* see if using plexus-archiver 1.0-alpha-7 same as maven lets us share code.  Following is for 1.0-alpha-9
        DefaultFileSet all = new DefaultFileSet();
        all.setDirectory(source);
        archiver.addFileSet(all);
*/
       
        // add in all files and mark them with default file permissions
        Map<String, File> all = IOUtil.listAllFileNames(source);
        removeExcludes(source, all);
        for (Map.Entry<String, File> entry : all.entrySet()) {
            String destFileName = serverName + "/" + entry.getKey();
            File sourceFile = entry.getValue();
            if (sourceFile.isFile()) {
                archiver.addFile(sourceFile, destFileName, UnixStat.DEFAULT_FILE_PERM);
            }
        }

        // add execute permissions to all non-batch files in the bin/ directory
        File bin = new File(source, "bin");
        if (bin.exists()) {
            Map<String, File> includes = IOUtil.listAllFileNames(bin);
            for (Map.Entry<String, File> entry : includes.entrySet()) {
                String destFileName = serverName + "/bin/" + entry.getKey();
                File sourceFile = entry.getValue();
                if (!destFileName.endsWith(".bat") && sourceFile.isFile()) {
                    archiver.addFile(sourceFile, destFileName, UnixStat.DEFAULT_DIR_PERM);
                }
            }
        }
       
        archiver.createArchive();
        return dest;
    }
View Full Code Here

    public File archive(String sourcePath, String destPath, Artifact artifact) throws ArchiverException, IOException {
        File source = serverInfo.resolve(sourcePath);
        File dest = serverInfo.resolve(destPath);
        String serverName = artifact.getArtifactId() + "-" + artifact.getVersion();
        dest = new File(dest, serverName + "-bin." + artifact.getType());
        Archiver archiver;
        if ("tar.gz".equals(artifact.getType())) {
            archiver = new TarArchiver();
            TarArchiver.TarCompressionMethod tarCompressionMethod = new TarArchiver.TarCompressionMethod();
            tarCompressionMethod.setValue("gzip");
            ((TarArchiver) archiver).setCompression(tarCompressionMethod);
            TarLongFileMode fileMode = new TarLongFileMode();
            fileMode.setValue(TarLongFileMode.GNU);
            ((TarArchiver) archiver).setLongfile(fileMode);
        } else if ("zip".equals(artifact.getType())) {
            archiver = new ZipArchiver();
        } else {
            throw new IllegalArgumentException("Unknown target type: " + artifact.getType());
        }
        archiver.setIncludeEmptyDirs(true);
        archiver.setDestFile(dest);
/* see if using plexus-archiver 1.0-alpha-7 same as maven lets us share code.  Following is for 1.0-alpha-9
        DefaultFileSet all = new DefaultFileSet();
        all.setDirectory(source);
        archiver.addFileSet(all);
*/
       
        // add in all files and mark them with default file permissions
        Map<File, Boolean> emptyDirs = new HashMap<File, Boolean>();
        Map<String, File> all = IOUtil.listAllFileNames(source);
        removeExcludes(source, all);
        for (Map.Entry<String, File> entry : all.entrySet()) {
            String destFileName = serverName + "/" + entry.getKey();
            File sourceFile = entry.getValue();
            if (sourceFile.isFile()) {
                archiver.addFile(sourceFile, destFileName, UnixStat.DEFAULT_FILE_PERM);
                // mark parent directories non-empty
                for (File parentDir = sourceFile.getParentFile();
                     parentDir != null && !parentDir.equals(source);
                     parentDir = parentDir.getParentFile()) {              
                    emptyDirs.put(parentDir, Boolean.FALSE);
                }
               
            } else if (sourceFile.isDirectory()) {                          
                Boolean isEmpty = emptyDirs.get(sourceFile);               
                if (isEmpty == null) {      
                    emptyDirs.put(sourceFile, Boolean.TRUE);
                    // mark parent directories non-empty
                    for (File parentDir = sourceFile.getParentFile();
                         parentDir != null && !parentDir.equals(source);
                         parentDir = parentDir.getParentFile()) {              
                        emptyDirs.put(parentDir, Boolean.FALSE);
                    }
                }             
            }
        }
       
        if (!all.isEmpty()) {
            emptyDirs.put(source, Boolean.FALSE);
        }
               
        String sourceDirPath = source.getAbsolutePath();
        for (Map.Entry<File, Boolean> entry : emptyDirs.entrySet()) {
            if (entry.getValue().booleanValue()) {               
                String emptyDirPath = entry.getKey().getAbsolutePath();
                String relativeDir = emptyDirPath.substring(sourceDirPath.length());
                relativeDir = relativeDir.replace('\\', '/');
                archiver.addDirectory(entry.getKey(), serverName + relativeDir);
            }
        }
        emptyDirs.clear();
       
        all.clear();
       
        // add execute permissions to all non-batch files in the bin/ directory
        File bin = new File(source, "bin");
        if (bin.exists()) {
            Map<String, File> includes = IOUtil.listAllFileNames(bin);
            for (Map.Entry<String, File> entry : includes.entrySet()) {
                String destFileName = serverName + "/bin/" + entry.getKey();
                File sourceFile = entry.getValue();
                if (!destFileName.endsWith(".bat") && sourceFile.isFile()) {
                    archiver.addFile(sourceFile, destFileName, UnixStat.DEFAULT_DIR_PERM);
                }
            }
        }
       
        archiver.createArchive();
        return dest;
    }
View Full Code Here

TOP

Related Classes of org.codehaus.plexus.archiver.Archiver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.