[ https://jira.codehaus.org/browse/MEAR-187?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=348315#comment-348315 ]
Martin Gainty commented on MEAR-187: ------------------------------------ plexus-archiver does not currently implement ZipOutpuStream or ZipEntry so the un-archive functions for EAR Here is what I propose for the new EarUnArchiver.java package org.codehaus.plexus.archiver; /** * * Copyright 2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.archiver.util.FilterSupport; import org.codehaus.plexus.components.io.fileselectors.FileSelector; import org.codehaus.plexus.components.io.resources.PlexusIoResource; import org.codehaus.plexus.logging.AbstractLogEnabled; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** * @author <a href="http://blog.soebes.de">Karl Heinz Marbaise</a> * @version $Revision$ $Date$ * @description UnPack an ear */ public class EarUnArchiver extends AbstractLogEnabled implements UnArchiver, FinalizerEnabled, FilterEnabled { private File destDirectory; private File destFile; private File sourceFile; private boolean overwrite = true; public FilterSupport filterSupport; public FilterSupport getFilterSupport() { return this.filterSupport; } private List finalizers; private FileSelector[] fileSelectors; /** * since 2.3 is on by default * @since 1.1 */ private boolean useJvmChmod = true; /** * @since 1.1 */ private boolean ignorePermissions = false; public EarArchiver() { // no op } public EarArchiver( final File sourceFile ) { this.sourceFile = sourceFile; } public File getDestDirectory() { return destDirectory; } public void setDestDirectory( final File destDirectory ) { this.destDirectory = destDirectory; } public File getDestFile() { return destFile; } public void setDestFile( final File destFile ) { this.destFile = destFile; } public File getSourceFile() { return sourceFile; } public void setSourceFile( final File sourceFile ) { this.sourceFile = sourceFile; } public boolean isOverwrite() { return overwrite; } public void setOverwrite( final boolean b ) { overwrite = b; } public final void extract() throws ArchiverException { //System.out.println("EarArchiver::extract LINE 120 before validate()"); // validate(); System.out.println("EarArchiver::extract LINE 122 before execute()"); try { execute(); } catch(Exception excp) { System.out.println("EarArchiver::extract LINE 129 threw Exception message="+excp.getMessage()); } System.out.println("EarArchiver::extract LINE 124 before runArchiveFinalizers()"); runArchiveFinalizers(); } public final void extract( final String path, final File outputDirectory ) throws ArchiverException { System.out.println("AbstractInArchiver:;extract path="+path); System.out.println("EarArchiver:;extract outputDirectory="+outputDirectory); System.out.println("EarArchiver::extract before validate(path, outputDirectory)"); validate( path, outputDirectory ); System.out.println("EarArchiver::extract before execute(path,outputDirectory)"); execute( path, outputDirectory ); System.out.println("EarArchiver::extract before runArchiveFinalizers"); runArchiveFinalizers(); } public void setArchiveFilters( final List filters ) { filterSupport = new FilterSupport( filters, getLogger() ); } public void addArchiveFinalizer( final ArchiveFinalizer finalizer ) { if ( finalizers == null ) { finalizers = new ArrayList(); } finalizers.add( finalizer ); } public void setArchiveFinalizers( final List archiveFinalizers ) { finalizers = archiveFinalizers; } private final void runArchiveFinalizers() throws ArchiverException { System.out.println("EarArchiver::unArchiveFinalizers() where finalizers="+finalizers); if ( finalizers != null ) { System.out.println("EarArchiver::unArchiveFinalizers() before for ( final Iterator it = finalizers.iterator(); it.hasNext(); )" for ( final Iterator it = finalizers.iterator(); it.hasNext(); ) { System.out.println("EarArchiver::unArchiverFinalizers() before for ( final Iterator it = finalizers.iterator(); it.hasNext( final ArchiveFinalizer finalizer = (ArchiveFinalizer) it.next(); System.out.println("EarArchiver::unArchiverFinalizers() before finalizer.finalizeArchiveExtraction( this )"); finalizer.finalizeArchiveExtraction( this ); } } else { System.out.println("EarArchiver::unArchiveFinalizers before unZipIt(sourceFile="+sourceFile); System.out.println("EarArchiver::unArchiveFinalizers befoe unZipIt(destDirectory="+destDirectory); try { unZipIt((String)sourceFile.getCanonicalPath(), (String)destDirectory.getCanonicalPath()); } catch(java.io.IOException ioe) { System.out.println("AbstractUnArchiveFinalizers LINE 193 throws IOException has been caught message="+ioe. } } } public synchronized void MakeTheDirs(File newFile) { System.out.println("EarArchiver::MakeTheDirs before new File(newFile.getParent()).mkdirs()) newFile="+newFi new java.io.File(newFile.getParent()).mkdirs(); } public synchronized void setArchiveBit(java.io.File newFile) { StringBuffer sb=new StringBuffer(); sb.append("attrib +a "); try { sb.append(newFile.getCanonicalPath()); } catch(java.io.IOException io) { System.out.println("sb.append(newFile.getCanonicalPath returns IOException message="+io.getMessage()); } System.out.println("EarArchiver::unZipIt About to "+sb.toString()); try { Runtime.getRuntime().exec(sb.toString()); } catch(java.io.IOException io2) { System.out.println("Runtime.getRuntime().exec() has thrown IOException message="+io2.getMessage()); } } public synchronized void setReadModeOff(java.io.File newFile) { StringBuffer sb = new StringBuffer(); sb.append("attrib -r "); try { sb.append(newFile.getCanonicalPath()); } catch(java.io.IOException io) { System.out.println("EarArchiver::setReadModeOff sb.append(newFile.getCanonicalPath returns IOException messag } System.out.println("EarArchiver::setReadModeOff About to "+sb.toString()); try { Runtime.getRuntime().exec(sb.toString()); } catch(java.io.IOException io2) { System.out.println("EarArchiver::setReadModelOff Runtime.getRuntime().exec has thrown IOException message="+io } } public synchronized java.io.FileOutputStream getFileOutputStream(java.io.File newFile) { System.out.println("EarArchiver::getFileOutputStream(newFile) before fos = new FileOutputStream(newFile) newFile=" // set writable to true newFile.setExecutable(true); System.out.println("EarArchiver::getFileOutputStream is Executable allow : "+newFile.canExecute() ); newFile.setReadable(true); System.out.println("EarArchiver::getFileOutputStream is Readable allow : "+newFile. canRead() ); newFile.setWritable(true); System.out.println("EarArchiver::getFileOutputStream is Writable allow : "+newFile.canWrite() ); System.out.println("EarArchiver::getFileOutputStream will call setArchiveBit()"); setArchiveBit(newFile); setReadModeOff(newFile); java.io.FileOutputStream fos = null; System.out.println("test for existence of newFile="+newFile+" newFile.exists()="+newFile.exists()); if(newFile.isDirectory()==false) { try { fos = new java.io.FileOutputStream(newFile); } catch(java.io.FileNotFoundException fnfe) { System.out.println("EarArchiver::unZipIt FileNotFoundException has been thrown in getFileOutputStream newFile } } System.out.println("EarArchiver::getFileOutputStream returns FileOutputStream fos="+fos); return fos; } public synchronized java.io.File getTheFile( java.io.File outputFolder, java.io.File fileName) { System.out.println("EarArchiver::getTheFile before new java.io.File(outputFolder + File.separator + fileName) outputFo return new java.io.File(outputFolder + File.separator + fileName); } public synchronized java.util.zip.ZipInputStream getZipInputStream(String zipFile) { System.out.println("EarArchiver::getZipInputStream(zipFile) where zipFile="+zipFile); java.util.zip.ZipInputStream zip=null; try { java.io.FileInputStream fis=new java.io.FileInputStream(zipFile); System.out.println("EarArchiver::getZipInputStream(zipFile="+zipFile); zip= new java.util.zip.ZipInputStream(fis); } catch(java.io.FileNotFoundException fne) { System.out.println("EarArchiver::getZipInputStream LINE 289 throws FileNotFoundException message="+fne.getMe } System.out.println("EarArchiver::getZipInpuitStream(zipFile) returns zip="+zip); return zip; } public synchronized java.io.File makeOutputFolder(String outputFolder) { System.out.println("EarArchiver::makeOutputFolder(outputFolder) outputFolder="+outputFolder); return new java.io.File(outputFolder); } public synchronized void ReadAndWrite(java.util.zip.ZipInputStream zis,java.io.FileOutputStream fos, byte []buffer) { int len=0; if(zis!=null) { try { while( (len = zis.read(buffer) ) > 0) { System.out.println("EarArchiver::ReadAndWrite before fos.write(buffer="+buffer); System.out.println("EarArchiver::ReadAndWrite len="+len); fos.write(buffer, 0, len); } //end while } catch(java.io.IOException ioe) { System.out.println("EarArchiver::ReadAndWrite throws IOException mssage="+ioe.getMessage()); } } } public synchronized java.util.zip.ZipEntry getNextEntry(java.util.zip.ZipInputStream zis) { System.out.println("AbstractUnArchive::getNextEntry zis="+zis); java.util.zip.ZipEntry zipEntry = null; if(zis!=null) { try { zipEntry = zis.getNextEntry(); } catch(java.io.IOException ioe) { System.out.println("AbstractUnArchivr::getNextEntry throws java.io.IOException mssage="+ioe.getMessage()); } } System.out.println("AbstractUnArchiveEntry::getNextEntry LINE 327 returns zipEntry="+zipEntry); return zipEntry; } public synchronized String getName(java.util.zip.ZipEntry ze) { String name=null; if (ze!=null) { name = ze.getName(); } System.out.println("AbstractUnArchiveEntry::getName LINE 312 returns "+name); return name; } public java.io.File getOutputFile(String outputFolder, String fileName) { StringBuffer sb=new StringBuffer(); sb.append(outputFolder); sb.append("\\"); sb.append(fileName); System.out.println("EarArchiver::getOutputFile will create file:"+sb.toString()); return new java.io.File(sb.toString()); } /** * Unzip it * @param zipFile input zip file * @param output zip file output folder */ public synchronized void unZipIt(String zipFile, String outputFolder) { byte[] buffer = new byte[1024]; try { //create output directory is not exists System.out.println("EarArchiver::unZipIt zipFile="+zipFile+" outputFolder="+outputFolder+" before folder = new File(out java.io.File folder =makeOutputFolder(outputFolder); System.out.println("EarArchiver::unZipIt folder = "+folder); if(folder.exists()==false) { synchronized(folder) { MakeTheDirs(folder); } } //get the zip file content java.util.zip.ZipInputStream zis =null; if(zipFile!=null) { synchronized(zipFile) { zis = getZipInputStream(zipFile); } } System.out.println("EarArchiver::unZipIt zis = "+zis); //get the zipped file list entry java.util.zip.ZipEntry ze=null; synchronized(zis) { ze = getNextEntry(zis); //zis.getNextEntry(); } System.out.println("EarArchiver::unZipIt ze="+ze); java.io.File newFile = null; while(ze!=null) { System.out.println("EarArchiver::unZipIt before fileName = ze.getName()"); String fileName=null; synchronized(ze) { fileName = getName(ze); } System.out.println("EarArchiver::unZipIt filename="+fileName); synchronized(outputFolder) { newFile =getOutputFile((String)outputFolder, (String)fileName); } System.out.println("EarArchiver::unZipIt file unzip : "+ newFile.getAbsoluteFile()); //create all non exists folders //else you will hit FileNotFoundException for compressed folder synchronized( newFile ) { MakeTheDirs(newFile); } java.io.FileOutputStream fos = null; synchronized( newFile ) { fos = getFileOutputStream(newFile); } System.out.println("AbstarctUnArchiver::unZipIt fos="+fos); int len; if(fos!=null) { synchronized(fos) { ReadAndWrite(zis, fos,buffer); } System.out.println("EarArchiver::unZIpIt before fos.close()"); synchronized(fos) { fos.close(); } } System.out.println("EarArchiver::unZipIt before ze=zis.getNextEntry()"); synchronized(zis) { ze = getNextEntry(zis); } } System.out.println("EarArchiver::unZipIt before zis.closeEntry()"); synchronized(zis) { zis.closeEntry(); } System.out.println("EarArchiver::unZipIt before zis.close()"); synchronized(zis) { zis.close(); } System.out.println("EarArchiver::unZipIt LINE 410 Done"); } catch(IOException ex) { System.out.println("EarArchiver::unZipIt throws IOexception LINE 415 message="+ex.getMessage()); //ex.printStackTrace(); } } //end unZipIt protected boolean include( final InputStream inputStream, final String name ) throws ArchiveFilterException { return filterSupport == null || filterSupport.include( inputStream, name ); } protected void validate( final String path, final File outputDirectory ) { System.out.println("EarArchiver::validate path="+path); System.out.println("EarArchiver::validate outputDirectory="+outputDirectory); } protected void validate() throws ArchiverException { System.out.println("EarArchiver::validate() sourceFile="+sourceFile); if ( sourceFile == null ) { throw new ArchiverException( "The source file isn't defined." ); } if ( sourceFile.isDirectory() ) { throw new ArchiverException( "The source must not be a directory." ); } if ( !sourceFile.exists() ) { throw new ArchiverException( "The source file " + sourceFile + " doesn't exist." ); } System.out.println("EarArchiver::validate destDirectory="+destDirectory); System.out.println("EarArchiver::validate destFile = "+destFile); if ( destDirectory == null) // && destFile == null ) { throw new ArchiverException( "The destination isn't defined." ); } if ( destDirectory != null) // && destFile != null ) { throw new ArchiverException( "You must choose between a destination directory and a destination file." ); } if ( destDirectory != null) // && !destDirectory.isDirectory() ) { destFile = destDirectory; destDirectory = null; } if ( destFile != null) // && destFile.isDirectory() ) { destDirectory = destFile; destFile = null; } System.out.println("EarArchiver::validate exitting"); } public void setFileSelectors( final FileSelector[] fileSelectors ) { this.fileSelectors = fileSelectors; } public FileSelector[] getFileSelectors() { return fileSelectors; } protected boolean isSelected( final String fileName, final PlexusIoResource fileInfo ) throws ArchiverException { if ( fileSelectors != null ) { for ( int i = 0; i < fileSelectors.length; i++ ) { try { if ( !fileSelectors[i].isSelected( fileInfo ) ) { return false; } } catch ( final IOException e ) { throw new ArchiverException( "Failed to check, whether " + fileInfo.getName() + " is selected: " + e.getMessage(), e ); } } } return true; } protected void execute() throws ArchiverException { System.out.println("EarArchiver::execute() LINE 270 throws ArchiverException doesnt do anything at the moment..exitt } protected void execute( String path, File outputDirectory ) throws ArchiverException { System.out.println("EarArchiver::execute(path, outputDirectory) LINE 276 path="+path); try { System.out.println("EarArchiver::execute(path, outputDirectory) LINE 279 outputDirectory="+outputDirectory.getCanoni } catch(java.io.IOException ioe) { System.out.println("EarArchiver::execute(path, outputDirectory) LINE 283 throws IOException mesage="+ioe.getMe } } /** * @since 1.1 */ public boolean isUseJvmChmod() { return useJvmChmod; } /** * <b>jvm chmod won't set group level permissions !</b> * @since 1.1 */ public void setUseJvmChmod( final boolean useJvmChmod ) { this.useJvmChmod = useJvmChmod; } /** * @since 1.1 */ public boolean isIgnorePermissions() { return ignorePermissions; } /** * @since 1.1 */ public void setIgnorePermissions( final boolean ignorePermissions ) { this.ignorePermissions = ignorePermissions; } } attaching file EarUnArchiver.java > No unpack capability for ear > ---------------------------- > > Key: MEAR-187 > URL: https://jira.codehaus.org/browse/MEAR-187 > Project: Maven Ear Plugin > Issue Type: Bug > Affects Versions: 2.9 > Environment: maven 3.0.2 > jdk 1.7.0.45 > Reporter: Martin Gainty > > EarModuleFactory.standardArtifactTypes.contains( type ) ) type=ear > AbstractEarTest::createArtifactsTest ear.execute() has thrown > MojoExecutionException message=Invalid type [ear] supported types are [jar, > ejb, ejb3, par, ejb-client, app-client, rar, war, sar, wsr, har] > Therefore the ear type is NEVER unpacked/unzipped (and consequently > repacked/zipped) for type ear > Whatever was in the previous ear remains (with no ability to upgrade versions) > Originally reported by Martin Holler > Martin -- This message was sent by Atlassian JIRA (v6.1.6#6162)