You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ra...@apache.org on 2009/04/05 17:43:32 UTC

svn commit: r762110 - /maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java

Author: rafale
Date: Sun Apr  5 15:43:32 2009
New Revision: 762110

URL: http://svn.apache.org/viewvc?rev=762110&view=rev
Log:
Added some traces in order to help creating archetypes by hand.
(ARCHETYPE-236)

Modified:
    maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java

Modified: maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java?rev=762110&r1=762109&r2=762110&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java (original)
+++ maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java Sun Apr  5 15:43:32 2009
@@ -57,9 +57,8 @@
  * @plexus.component
  */
 public class DefaultArchetypeArtifactManager
-extends AbstractLogEnabled
-implements ArchetypeArtifactManager
-{
+    extends AbstractLogEnabled
+    implements ArchetypeArtifactManager {
     /**
      * @plexus.requirement
      */
@@ -77,7 +76,7 @@
 
     private Map archetypeCache = new TreeMap();
 
-    public File getArchetypeFile (
+    public File getArchetypeFile(
         final String groupId,
         final String artifactId,
         final String version,
@@ -85,18 +84,15 @@
         final ArtifactRepository localRepository,
         final List repositories
     )
-    throws UnknownArchetype
-    {
-        try
-        {
+        throws UnknownArchetype {
+        try {
             File archetype = getArchetype(
-                    groupId,
-                    artifactId,
-                    version);
-            if (archetype==null)
-            {
+                groupId,
+                artifactId,
+                version );
+            if( archetype == null ) {
                 archetype =
-                    downloader.download (
+                    downloader.download(
                         groupId,
                         artifactId,
                         version,
@@ -105,142 +101,117 @@
                         repositories
                     );
                 setArchetype(
-                        groupId,
-                        artifactId,
-                        version,
-                        archetype);
+                    groupId,
+                    artifactId,
+                    version,
+                    archetype );
             }
             return archetype;
         }
-        catch ( DownloadNotFoundException ex )
-        {
-            throw new UnknownArchetype ( ex );
+        catch( DownloadNotFoundException ex ) {
+            throw new UnknownArchetype( ex );
         }
-        catch ( DownloadException ex )
-        {
-            throw new UnknownArchetype ( ex );
+        catch( DownloadException ex ) {
+            throw new UnknownArchetype( ex );
         }
     }
 
-    public ClassLoader getArchetypeJarLoader ( File archetypeFile )
-    throws UnknownArchetype
-    {
-        try
-        {
+    public ClassLoader getArchetypeJarLoader( File archetypeFile )
+        throws UnknownArchetype {
+        try {
             URL[] urls = new URL[1];
 
-            urls[0] = archetypeFile.toURI ().toURL ();
+            urls[0] = archetypeFile.toURI().toURL();
 
-            return new URLClassLoader ( urls );
+            return new URLClassLoader( urls );
         }
-        catch ( MalformedURLException e )
-        {
-            throw new UnknownArchetype ( e );
+        catch( MalformedURLException e ) {
+            throw new UnknownArchetype( e );
         }
     }
 
-    public Model getArchetypePom ( File jar )
-    throws XmlPullParserException, UnknownArchetype, IOException
-    {
+    public Model getArchetypePom( File jar )
+        throws XmlPullParserException, UnknownArchetype, IOException {
         String pomFileName = null;
         ZipFile zipFile = null;
-        try
-        {
-            zipFile = getArchetypeZipFile ( jar );
-            Enumeration enumeration = zipFile.entries ();
-            while ( enumeration.hasMoreElements () )
-            {
-                ZipEntry el = (ZipEntry) enumeration.nextElement ();
-
-                String entry = el.getName ();
-                if ( entry.startsWith ( "META-INF" ) && entry.endsWith ( "pom.xml" ) )
-                {
+        try {
+            zipFile = getArchetypeZipFile( jar );
+            Enumeration enumeration = zipFile.entries();
+            while( enumeration.hasMoreElements() ) {
+                ZipEntry el = (ZipEntry) enumeration.nextElement();
+
+                String entry = el.getName();
+                if( entry.startsWith( "META-INF" ) && entry.endsWith( "pom.xml" ) ) {
                     pomFileName = entry;
                 }
             }
 
-            if ( pomFileName == null )
-            {
+            if( pomFileName == null ) {
                 return null;
             }
 
             ZipEntry pom =
-                zipFile.getEntry ( StringUtils.replace ( pomFileName, File.separator, "/" ) );
-            if ( pom == null )
-            {
-                pom = zipFile.getEntry ( StringUtils.replace ( pomFileName, "/", File.separator ) );
+                zipFile.getEntry( StringUtils.replace( pomFileName, File.separator, "/" ) );
+            if( pom == null ) {
+                pom = zipFile.getEntry( StringUtils.replace( pomFileName, "/", File.separator ) );
             }
-            if ( pom == null )
-            {
+            if( pom == null ) {
                 return null;
             }
-            return pomManager.readPom ( zipFile.getInputStream ( pom ) );
+            return pomManager.readPom( zipFile.getInputStream( pom ) );
         }
-        finally
-        {
+        finally {
             closeZipFile( zipFile );
         }
     }
 
-    public ZipFile getArchetypeZipFile ( File archetypeFile )
-    throws UnknownArchetype
-    {
-        try
-        {
-            return new ZipFile ( archetypeFile );
+    public ZipFile getArchetypeZipFile( File archetypeFile )
+        throws UnknownArchetype {
+        try {
+            return new ZipFile( archetypeFile );
         }
-        catch ( ZipException e )
-        {
-            throw new UnknownArchetype ( e );
+        catch( ZipException e ) {
+            throw new UnknownArchetype( e );
         }
-        catch ( IOException e )
-        {
-            throw new UnknownArchetype ( e );
+        catch( IOException e ) {
+            throw new UnknownArchetype( e );
         }
     }
 
-    public boolean isFileSetArchetype ( File archetypeFile )
-    {
+    public boolean isFileSetArchetype( File archetypeFile ) {
         ZipFile zipFile = null;
-        try
-        {
-            zipFile = getArchetypeZipFile ( archetypeFile );
+        try {
+            zipFile = getArchetypeZipFile( archetypeFile );
 
-            return isFileSetArchetype ( zipFile );
+            return isFileSetArchetype( zipFile );
         }
-        catch ( XmlPullParserException e )
-        {
+        catch( XmlPullParserException e ) {
             return false;
         }
-        catch ( IOException e )
-        {
+        catch( IOException e ) {
             return false;
         }
-        catch ( UnknownArchetype e )
-        {
+        catch( UnknownArchetype e ) {
             return false;
         }
-        finally
-        {
+        finally {
             closeZipFile( zipFile );
         }
     }
 
-    public boolean isFileSetArchetype (
+    public boolean isFileSetArchetype(
         String groupId,
         String artifactId,
         String version,
         ArtifactRepository archetypeRepository,
         ArtifactRepository localRepository,
         List repositories
-    )
-    {
+    ) {
         ZipFile zipFile = null;
-        try
-        {
+        try {
             zipFile =
-                getArchetypeZipFile (
-                    getArchetypeFile (
+                getArchetypeZipFile(
+                    getArchetypeFile(
                         groupId,
                         artifactId,
                         version,
@@ -250,68 +221,56 @@
                     )
                 );
 
-            return isFileSetArchetype ( zipFile );
+            return isFileSetArchetype( zipFile );
         }
-        catch ( XmlPullParserException e )
-        {
+        catch( XmlPullParserException e ) {
             return false;
         }
-        catch ( IOException e )
-        {
+        catch( IOException e ) {
             return false;
         }
-        catch ( UnknownArchetype e )
-        {
+        catch( UnknownArchetype e ) {
             return false;
         }
-        finally
-        {
+        finally {
             closeZipFile( zipFile );
         }
     }
 
-    public boolean isOldArchetype ( File archetypeFile )
-    {
+    public boolean isOldArchetype( File archetypeFile ) {
         ZipFile zipFile = null;
-        try
-        {
-            zipFile = getArchetypeZipFile ( archetypeFile );
+        try {
+            zipFile = getArchetypeZipFile( archetypeFile );
 
-            return isOldArchetype ( zipFile );
+            return isOldArchetype( zipFile );
         }
-        catch ( XmlPullParserException e )
-        {
+        catch( XmlPullParserException e ) {
             return false;
         }
-        catch ( IOException e )
-        {
+        catch( IOException e ) {
             return false;
         }
-        catch ( UnknownArchetype e )
-        {
+        catch( UnknownArchetype e ) {
             return false;
         }
-        finally
-        {
+        finally {
             closeZipFile( zipFile );
         }
     }
 
-    public boolean isOldArchetype (
+    public boolean isOldArchetype(
         String groupId,
         String artifactId,
         String version,
         ArtifactRepository archetypeRepository,
         ArtifactRepository localRepository,
         List repositories
-    )
-    {
+    ) {
         ZipFile zipFile = null;
-        try
-        {
+        try {
             zipFile =
-                getArchetypeZipFile (
-                    getArchetypeFile (
+                getArchetypeZipFile(
+                    getArchetypeFile(
                         groupId,
                         artifactId,
                         version,
@@ -321,45 +280,38 @@
                     )
                 );
 
-            return isOldArchetype ( zipFile );
+            return isOldArchetype( zipFile );
         }
-        catch ( XmlPullParserException e )
-        {
+        catch( XmlPullParserException e ) {
             return false;
         }
-        catch ( IOException e )
-        {
+        catch( IOException e ) {
             return false;
         }
-        catch ( UnknownArchetype e )
-        {
+        catch( UnknownArchetype e ) {
             return false;
         }
-        finally
-        {
+        finally {
             closeZipFile( zipFile );
         }
     }
 
-    public boolean exists (
+    public boolean exists(
         String archetypeGroupId,
         String archetypeArtifactId,
         String archetypeVersion,
         ArtifactRepository archetypeRepository,
         ArtifactRepository localRepository,
         List remoteRepositories
-    )
-    {
-        try
-        {
+    ) {
+        try {
             File archetype = getArchetype(
-                    archetypeGroupId,
-                    archetypeArtifactId,
-                    archetypeVersion);
-            if (archetype==null)
-            {
+                archetypeGroupId,
+                archetypeArtifactId,
+                archetypeVersion );
+            if( archetype == null ) {
                 archetype =
-                    downloader.download (
+                    downloader.download(
                         archetypeGroupId,
                         archetypeArtifactId,
                         archetypeVersion,
@@ -368,51 +320,44 @@
                         remoteRepositories
                     );
                 setArchetype(
-                        archetypeGroupId,
-                        archetypeArtifactId,
-                        archetypeVersion,
-                        archetype);
+                    archetypeGroupId,
+                    archetypeArtifactId,
+                    archetypeVersion,
+                    archetype );
             }
 
-            return archetype.exists ();
+            return archetype.exists();
         }
-        catch ( DownloadException e )
-        {
-            getLogger ().debug ( "Archetype don't exist", e );
+        catch( DownloadException e ) {
+            getLogger().debug( "Archetype don't exist", e );
             return false;
         }
-        catch ( DownloadNotFoundException e )
-        {
-            getLogger ().debug ( "Archetype don't exist", e );
+        catch( DownloadNotFoundException e ) {
+            getLogger().debug( "Archetype don't exist", e );
             return false;
         }
     }
 
-    public ArchetypeDescriptor getFileSetArchetypeDescriptor ( File archetypeFile )
-    throws UnknownArchetype
-    {
+    public ArchetypeDescriptor getFileSetArchetypeDescriptor( File archetypeFile )
+        throws UnknownArchetype {
         ZipFile zipFile = null;
-        try
-        {
-            zipFile = getArchetypeZipFile ( archetypeFile );
-
-            return loadFileSetArchetypeDescriptor ( zipFile );
-        }
-        catch ( XmlPullParserException e )
-        {
-            throw new UnknownArchetype ( e );
-        }
-        catch ( IOException e )
-        {
-            throw new UnknownArchetype ( e );
+        try {
+            zipFile = getArchetypeZipFile( archetypeFile );
+
+            return loadFileSetArchetypeDescriptor( zipFile );
         }
-        finally
-        {
+        catch( XmlPullParserException e ) {
+            throw new UnknownArchetype( e );
+        }
+        catch( IOException e ) {
+            throw new UnknownArchetype( e );
+        }
+        finally {
             closeZipFile( zipFile );
         }
     }
 
-    public org.apache.maven.archetype.metadata.ArchetypeDescriptor getFileSetArchetypeDescriptor (
+    public org.apache.maven.archetype.metadata.ArchetypeDescriptor getFileSetArchetypeDescriptor(
         String groupId,
         String artifactId,
         String version,
@@ -420,14 +365,12 @@
         ArtifactRepository localRepository,
         List repositories
     )
-    throws UnknownArchetype
-    {
+        throws UnknownArchetype {
         ZipFile zipFile = null;
-        try
-        {
+        try {
             zipFile =
-                getArchetypeZipFile (
-                    getArchetypeFile (
+                getArchetypeZipFile(
+                    getArchetypeFile(
                         groupId,
                         artifactId,
                         version,
@@ -437,92 +380,77 @@
                     )
                 );
 
-            return loadFileSetArchetypeDescriptor ( zipFile );
+            return loadFileSetArchetypeDescriptor( zipFile );
+        }
+        catch( XmlPullParserException e ) {
+            throw new UnknownArchetype( e );
         }
-        catch ( XmlPullParserException e )
-        {
-            throw new UnknownArchetype ( e );
-        }
-        catch ( IOException e )
-        {
-            throw new UnknownArchetype ( e );
+        catch( IOException e ) {
+            throw new UnknownArchetype( e );
         }
-        finally
-        {
+        finally {
             closeZipFile( zipFile );
         }
     }
 
-    public List getFilesetArchetypeResources ( File archetypeFile )
-    throws UnknownArchetype
-    {
-        List archetypeResources = new ArrayList ();
+    public List getFilesetArchetypeResources( File archetypeFile )
+        throws UnknownArchetype {
+        List archetypeResources = new ArrayList();
 
         ZipFile zipFile = null;
-        try
-        {
-            zipFile = getArchetypeZipFile ( archetypeFile );
-
-            Enumeration enumeration = zipFile.entries ();
-            while ( enumeration.hasMoreElements () )
-            {
-                ZipEntry entry = (ZipEntry) enumeration.nextElement ();
+        try {
+            zipFile = getArchetypeZipFile( archetypeFile );
 
-                if ( !entry.isDirectory ()
-                    && entry.getName ().startsWith ( Constants.ARCHETYPE_RESOURCES )
-                )
-                {
+            Enumeration enumeration = zipFile.entries();
+            while( enumeration.hasMoreElements() ) {
+                ZipEntry entry = (ZipEntry) enumeration.nextElement();
+
+                if( !entry.isDirectory()
+                    && entry.getName().startsWith( Constants.ARCHETYPE_RESOURCES )
+                    ) {
                     // not supposed to be file.seperator
                     String resource =
-                        StringUtils.replace (
-                            entry.getName (),
+                        StringUtils.replace(
+                            entry.getName(),
                             Constants.ARCHETYPE_RESOURCES + "/",
                             ""
                         );
-                    getLogger ().debug ( "Found resource " + resource );
+                    getLogger().debug( "Found resource " + resource );
                     // TODO:FIXME
-                    archetypeResources.add ( resource );
-                }
-                else
-                {
-                    getLogger ().debug ( "Not resource " + entry.getName () );
+                    archetypeResources.add( resource );
+                } else {
+                    getLogger().debug( "Not resource " + entry.getName() );
                 }
             }
             return archetypeResources;
         }
-        finally
-        {
+        finally {
             closeZipFile( zipFile );
         }
     }
 
-    public org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor getOldArchetypeDescriptor (
+    public org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor getOldArchetypeDescriptor(
         File archetypeFile
     )
-    throws UnknownArchetype
-    {
+        throws UnknownArchetype {
         ZipFile zipFile = null;
-        try
-        {
-            zipFile = getArchetypeZipFile ( archetypeFile );
-
-            return loadOldArchetypeDescriptor ( zipFile );
-        }
-        catch ( XmlPullParserException e )
-        {
-            throw new UnknownArchetype ( e );
-        }
-        catch ( IOException e )
-        {
-            throw new UnknownArchetype ( e );
+        try {
+            zipFile = getArchetypeZipFile( archetypeFile );
+
+            return loadOldArchetypeDescriptor( zipFile );
         }
-        finally
-        {
+        catch( XmlPullParserException e ) {
+            throw new UnknownArchetype( e );
+        }
+        catch( IOException e ) {
+            throw new UnknownArchetype( e );
+        }
+        finally {
             closeZipFile( zipFile );
         }
     }
 
-    public org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor getOldArchetypeDescriptor (
+    public org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor getOldArchetypeDescriptor(
         String groupId,
         String artifactId,
         String version,
@@ -530,14 +458,12 @@
         ArtifactRepository localRepository,
         List repositories
     )
-    throws UnknownArchetype
-    {
+        throws UnknownArchetype {
         ZipFile zipFile = null;
-        try
-        {
+        try {
             zipFile =
-                getArchetypeZipFile (
-                    getArchetypeFile (
+                getArchetypeZipFile(
+                    getArchetypeFile(
                         groupId,
                         artifactId,
                         version,
@@ -547,175 +473,167 @@
                     )
                 );
 
-            return loadOldArchetypeDescriptor ( zipFile );
+            return loadOldArchetypeDescriptor( zipFile );
         }
-        catch ( XmlPullParserException e )
-        {
-            throw new UnknownArchetype ( e );
-        }
-        catch ( IOException e )
-        {
-            throw new UnknownArchetype ( e );
+        catch( XmlPullParserException e ) {
+            throw new UnknownArchetype( e );
         }
-        finally
-        {
+        catch( IOException e ) {
+            throw new UnknownArchetype( e );
+        }
+        finally {
             closeZipFile( zipFile );
         }
     }
 
-    private void closeZipFile(ZipFile zipFile)
-    {
-        try
-        {
+    private void closeZipFile( ZipFile zipFile ) {
+        try {
             zipFile.close();
         }
-        catch (Exception e)
-        {
+        catch( Exception e ) {
             getLogger().error( "Fail to close zipFile" );
         }
     }
 
-    private File getArchetype(String archetypeGroupId,
-            String archetypeArtifactId,
-            String archetypeVersion) {
-        String key = archetypeGroupId+":"+archetypeArtifactId+":"+archetypeVersion;
-        if (archetypeCache.containsKey(key))
-        {
-            getLogger().debug("Found archetype "+key+" in cache: "+archetypeCache.get(key));
-            return (File) archetypeCache.get(key);
-        }
-        else
-        {
-            getLogger().debug("Not found archetype "+key+" in cache");
+    private File getArchetype( String archetypeGroupId,
+                               String archetypeArtifactId,
+                               String archetypeVersion ) {
+        String key = archetypeGroupId + ":" + archetypeArtifactId + ":" + archetypeVersion;
+        if( archetypeCache.containsKey( key ) ) {
+            getLogger().debug( "Found archetype " + key + " in cache: " + archetypeCache.get( key ) );
+            return (File) archetypeCache.get( key );
+        } else {
+            getLogger().debug( "Not found archetype " + key + " in cache" );
             return null;
         }
     }
 
-    private void setArchetype(String archetypeGroupId,
-            String archetypeArtifactId,
-            String archetypeVersion,
-            File archetype) {
-        String key = archetypeGroupId+":"+archetypeArtifactId+":"+archetypeVersion;
-        archetypeCache.put(key, archetype);
-    }
-
-    private Reader getArchetypeDescriptorReader ( ZipFile zipFile )
-    throws IOException
-    {
-        ZipEntry entry =
-            zipFile.getEntry (
-                StringUtils.replace ( Constants.ARCHETYPE_DESCRIPTOR, File.separator, "/" )
-            );
-
-        if ( entry == null )
-        {
-            getLogger ().debug (
-                "No found " + Constants.ARCHETYPE_DESCRIPTOR + " retrying with windows path"
-            );
-            entry =
-                zipFile.getEntry (
-                    StringUtils.replace ( Constants.ARCHETYPE_DESCRIPTOR, "/", File.separator )
-                );
+    private void setArchetype( String archetypeGroupId,
+                               String archetypeArtifactId,
+                               String archetypeVersion,
+                               File archetype ) {
+        String key = archetypeGroupId + ":" + archetypeArtifactId + ":" + archetypeVersion;
+        archetypeCache.put( key, archetype );
+    }
+
+    private ZipEntry searchEntry( ZipFile zipFile, String searchString ) {
+        getLogger().debug("Searching for "+searchString+" inside "+zipFile);
+        Enumeration enu = zipFile.entries();
+        while( enu.hasMoreElements() ) {
+            ZipEntry entryfound = (ZipEntry) enu.nextElement();
+            getLogger().debug( "An ENTRY " + entryfound.getName() );
+            if( searchString.equals( entryfound.getName() ) ) {
+                getLogger().error( "Found entry" );
+                return entryfound;
+            }
         }
-        if ( entry == null )
-        {
-            throw new IOException (
+        return null;
+    }
+
+    private Reader getArchetypeDescriptorReader( ZipFile zipFile )
+        throws IOException {
+        ZipEntry entry = searchEntry( zipFile,
+            StringUtils.replace( Constants.ARCHETYPE_DESCRIPTOR, File.separator, "/" ) );
+
+
+        if( entry == null ) {
+            getLogger().debug(
+                "Not found " + Constants.ARCHETYPE_DESCRIPTOR + " retrying with windows path"
+            );
+            entry = searchEntry( zipFile,
+                StringUtils.replace( Constants.ARCHETYPE_DESCRIPTOR, "/", File.separator )
+            );
+        }
+        if( entry == null ) {
+            throw new IOException(
                 "The " + Constants.ARCHETYPE_DESCRIPTOR + " descriptor cannot be found."
             );
         }
 
-        InputStream is = zipFile.getInputStream ( entry );
+        InputStream is = zipFile.getInputStream( entry );
 
-        if ( is == null )
-        {
-            throw new IOException (
+        if( is == null ) {
+            throw new IOException(
                 "The " + Constants.ARCHETYPE_DESCRIPTOR + " descriptor cannot be found."
             );
         }
-        return new InputStreamReader ( is );
+        return new InputStreamReader( is );
     }
 
-    private boolean isFileSetArchetype ( ZipFile zipFile )
-    throws IOException, XmlPullParserException
-    {
+    private boolean isFileSetArchetype( ZipFile zipFile )
+        throws IOException, XmlPullParserException {
         org.apache.maven.archetype.metadata.ArchetypeDescriptor descriptor =
-            loadFileSetArchetypeDescriptor ( zipFile );
+            loadFileSetArchetypeDescriptor( zipFile );
 
-        return descriptor.getName () != null;
+        return descriptor.getName() != null;
     }
 
-    private boolean isOldArchetype ( ZipFile zipFile )
-    throws IOException, XmlPullParserException
-    {
+    private boolean isOldArchetype( ZipFile zipFile )
+        throws IOException, XmlPullParserException {
         org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor descriptor =
-            loadOldArchetypeDescriptor ( zipFile );
+            loadOldArchetypeDescriptor( zipFile );
 
-        return descriptor.getId () != null;
+        return descriptor.getId() != null;
     }
 
-    private org.apache.maven.archetype.metadata.ArchetypeDescriptor loadFileSetArchetypeDescriptor (
+    private org.apache.maven.archetype.metadata.ArchetypeDescriptor loadFileSetArchetypeDescriptor(
         ZipFile zipFile
     )
-    throws IOException, XmlPullParserException
-    {
-        Reader reader = getArchetypeDescriptorReader ( zipFile );
-
-        ArchetypeDescriptorXpp3Reader archetypeReader = new ArchetypeDescriptorXpp3Reader ();
-
-        try
-        {
-            return archetypeReader.read ( reader, true );
-        }
-        finally
-        {
-            reader.close ();
+        throws IOException, XmlPullParserException {
+        Reader reader = getArchetypeDescriptorReader( zipFile );
+
+        ArchetypeDescriptorXpp3Reader archetypeReader = new ArchetypeDescriptorXpp3Reader();
+
+        try {
+            return archetypeReader.read( reader, true );
+        }
+        catch(IOException e){
+            getLogger().debug("Cant not read archetype descriptor", e);
+            throw e;
+        }
+        catch(XmlPullParserException e){
+            getLogger().error("Cant not parse archetype descriptor", e);
+            throw e;
+        }
+        finally {
+            reader.close();
         }
     }
 
     private org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor
-    loadOldArchetypeDescriptor ( ZipFile zipFile )
-    throws IOException, XmlPullParserException
-    {
-        ArchetypeDescriptorBuilder builder = new ArchetypeDescriptorBuilder ();
+    loadOldArchetypeDescriptor( ZipFile zipFile )
+        throws IOException, XmlPullParserException {
+        ArchetypeDescriptorBuilder builder = new ArchetypeDescriptorBuilder();
 
         org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor descriptor = null;
 
         Reader reader = null;
-        try
-        {
-            reader = getOldArchetypeDescriptorReader ( zipFile );
+        try {
+            reader = getOldArchetypeDescriptorReader( zipFile );
 
-            descriptor = builder.build ( reader );
+            descriptor = builder.build( reader );
         }
-        catch ( IOException ex )
-        {
-            getLogger ().debug ( "Can not load old archetype", ex );
+        catch( IOException ex ) {
+            getLogger().debug( "Can not load old archetype", ex );
         }
-        catch ( XmlPullParserException ex )
-        {
-            getLogger ().debug ( "Can not load old archetype", ex );
+        catch( XmlPullParserException ex ) {
+            getLogger().error( "Can not parse old archetype", ex );
         }
-        finally
-        {
-            if ( reader != null )
-            {
-                reader.close ();
+        finally {
+            if( reader != null ) {
+                reader.close();
             }
         }
 
-        if ( descriptor == null )
-        {
-            try
-            {
-                reader = getOlderArchetypeDescriptorReader ( zipFile );
+        if( descriptor == null ) {
+            try {
+                reader = getOlderArchetypeDescriptorReader( zipFile );
 
-                descriptor = builder.build ( reader );
+                descriptor = builder.build( reader );
             }
-            finally
-            {
-                if ( reader != null )
-                {
-                    reader.close ();
+            finally {
+                if( reader != null ) {
+                    reader.close();
                 }
             }
         }
@@ -723,81 +641,69 @@
         return descriptor;
     }
 
-    private Reader getOldArchetypeDescriptorReader ( ZipFile zipFile )
-    throws IOException
-    {
-        ZipEntry entry =
-            zipFile.getEntry (
-                StringUtils.replace ( Constants.OLD_ARCHETYPE_DESCRIPTOR, File.separator, "/" )
-            );
+    private Reader getOldArchetypeDescriptorReader( ZipFile zipFile )
+        throws IOException {
+        ZipEntry entry = searchEntry( zipFile,
+            StringUtils.replace( Constants.OLD_ARCHETYPE_DESCRIPTOR, File.separator, "/" )
+        );
 
-        if ( entry == null )
-        {
-            getLogger ().debug (
+        if( entry == null ) {
+            getLogger().debug(
                 "No found " + Constants.OLD_ARCHETYPE_DESCRIPTOR + " retrying with windows path"
             );
-            entry =
-                zipFile.getEntry (
-                    StringUtils.replace ( Constants.OLD_ARCHETYPE_DESCRIPTOR, "/", File.separator )
-                );
+            entry = searchEntry( zipFile,
+                StringUtils.replace( Constants.OLD_ARCHETYPE_DESCRIPTOR, "/", File.separator )
+            );
         }
 
-        if ( entry == null )
-        {
-            throw new IOException (
+        if( entry == null ) {
+            throw new IOException(
                 "The " + Constants.OLD_ARCHETYPE_DESCRIPTOR + " descriptor cannot be found."
             );
         }
 
-        InputStream is = zipFile.getInputStream ( entry );
+        InputStream is = zipFile.getInputStream( entry );
 
-        if ( is == null )
-        {
-            throw new IOException (
+        if( is == null ) {
+            throw new IOException(
                 "The " + Constants.OLD_ARCHETYPE_DESCRIPTOR + " descriptor cannot be found."
             );
         }
-        return new InputStreamReader ( is );
+        return new InputStreamReader( is );
     }
 
-    private Reader getOlderArchetypeDescriptorReader ( ZipFile zipFile )
-    throws IOException
-    {
-        ZipEntry entry =
-            zipFile.getEntry (
-                StringUtils.replace ( Constants.OLDER_ARCHETYPE_DESCRIPTOR, File.separator, "/" )
-            );
+    private Reader getOlderArchetypeDescriptorReader( ZipFile zipFile )
+        throws IOException {
+        ZipEntry entry = searchEntry( zipFile,
+            StringUtils.replace( Constants.OLDER_ARCHETYPE_DESCRIPTOR, File.separator, "/" )
+        );
 
-        if ( entry == null )
-        {
-            getLogger ().debug (
+        if( entry == null ) {
+            getLogger().debug(
                 "No found " + Constants.OLDER_ARCHETYPE_DESCRIPTOR + " retrying with windows path"
             );
-            entry =
-                zipFile.getEntry (
-                    StringUtils.replace (
-                        Constants.OLDER_ARCHETYPE_DESCRIPTOR,
-                        "/",
-                        File.separator
-                    )
-                );
+            entry = searchEntry( zipFile,
+                StringUtils.replace(
+                    Constants.OLDER_ARCHETYPE_DESCRIPTOR,
+                    "/",
+                    File.separator
+                )
+            );
         }
-        if ( entry == null )
-        {
-            throw new IOException (
+        if( entry == null ) {
+            throw new IOException(
                 "The " + Constants.OLDER_ARCHETYPE_DESCRIPTOR + " descriptor cannot be found."
             );
         }
 
-        InputStream is = zipFile.getInputStream ( entry );
+        InputStream is = zipFile.getInputStream( entry );
 
-        if ( is == null )
-        {
-            throw new IOException (
+        if( is == null ) {
+            throw new IOException(
                 "The " + Constants.OLDER_ARCHETYPE_DESCRIPTOR + " descriptor cannot be found."
             );
         }
 
-        return new InputStreamReader ( is );
+        return new InputStreamReader( is );
     }
 }