maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject svn commit: r570611 [2/14] - in /maven/sandbox/trunk/archetypeng: ./ archetype-common/ archetype-common/src/ archetype-common/src/main/ archetype-common/src/main/java/ archetype-common/src/main/java/org/ archetype-common/src/main/java/org/apache/ arche...
Date Wed, 29 Aug 2007 02:33:12 GMT
Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypeFilesResolver.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypeFilesResolver.java?rev=570611&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypeFilesResolver.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypeFilesResolver.java Tue Aug 28 19:32:45 2007
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.maven.archetype.common;
+
+import org.apache.maven.archetype.metadata.FileSet;
+
+import java.io.File;
+import java.io.IOException;
+
+import java.util.List;
+
+/**
+ * @author  rafale
+ */
+public interface ArchetypeFilesResolver
+{
+    String ROLE = ArchetypeFilesResolver.class.getName ();
+
+    /**
+     */
+    List getFilesWithExtension ( List files, String extension );
+
+    /**
+     */
+    List getFilteredFiles ( List files, String filtered );
+
+    /**
+     */
+    List filterFiles ( FileSet fileSet, List archetypeResources );
+
+    /**
+     */
+    List filterFiles ( String moduleOffset, FileSet fileSet, List archetypeResources );
+
+    /**
+     */
+    List findOtherResources ( int level, List files, String languages );
+
+    /**
+     */
+    List findOtherResources ( int level, List files, List sourcesFiles, String languages );
+
+    /**
+     */
+    List findOtherSources ( int level, List files, String languages );
+
+    /**
+     */
+    List findResourcesMainFiles ( List files, String languages );
+
+    /**
+     */
+    List findResourcesTestFiles ( List files, String languages );
+
+    /**
+     */
+    List findSiteFiles ( List files, String languages );
+
+    /**
+     */
+    List findSourcesMainFiles ( List files, String languages );
+
+    /**
+     */
+    List findSourcesTestFiles ( List files, String languages );
+
+    /**
+     */
+    List getPackagedFiles ( List files, String packageName );
+
+    /**
+     */
+    String resolvePackage ( File file, List languages )
+    throws IOException;
+
+    /**
+     */
+    List getUnfilteredFiles ( List files, String filtered );
+
+    /**
+     */
+    List getUnpackagedFiles ( List files, String packageName );
+
+    /**
+     */
+}

Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypePropertiesManager.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypePropertiesManager.java?rev=570611&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypePropertiesManager.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypePropertiesManager.java Tue Aug 28 19:32:45 2007
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.maven.archetype.common;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import java.util.Properties;
+
+public interface ArchetypePropertiesManager
+{
+    String ROLE = ArchetypePropertiesManager.class.getName ();
+
+    /**
+     */
+    void readProperties ( Properties properties, File propertyFile )
+    throws FileNotFoundException, IOException;
+
+    /**
+     */
+    void writeProperties ( Properties properties, File propertyFile )
+    throws IOException;
+}

Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypeRegistryManager.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypeRegistryManager.java?rev=570611&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypeRegistryManager.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypeRegistryManager.java Tue Aug 28 19:32:45 2007
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.maven.archetype.common;
+
+import org.apache.maven.archetype.registry.ArchetypeRegistry;
+
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import java.util.List;
+
+public interface ArchetypeRegistryManager
+{
+    String ROLE = ArchetypeRegistryManager.class.getName ();
+
+    public void addGroup ( String group, File archetypeRegistryFile )
+    throws IOException, XmlPullParserException;
+
+    /**
+     */
+    List getArchetypeGroups ( File archetypeRegistryFile );
+
+    /**
+     */
+    List getFilteredExtensions ( String archetypeFilteredExtentions, File archetypeRegistryFile )
+    throws IOException;
+
+    /**
+     */
+    List getLanguages ( String archetypeLanguages, File archetypeRegistryFile )
+    throws IOException;
+
+    /**
+     */
+    ArchetypeRegistry readArchetypeRegistry ( File archetypeRegistryFile )
+    throws IOException, FileNotFoundException, XmlPullParserException;
+
+    /**
+     */
+    List getRepositories (
+        List pomRemoteRepositories,
+        String remoteRepositories,
+        File archetypeRegistryFile
+    )
+    throws IOException, XmlPullParserException;
+
+    /**
+     */
+    void writeArchetypeRegistry ( File archetypeRegistryFile, ArchetypeRegistry archetypeRegistry )
+    throws IOException;
+
+    public ArchetypeRegistry getDefaultArchetypeRegistry();
+}

Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/Constants.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/Constants.java?rev=570611&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/Constants.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/Constants.java Tue Aug 28 19:32:45 2007
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.maven.archetype.common;
+
+import java.util.Arrays;
+import java.util.List;
+
+public interface Constants
+{
+    String ARCHETYPE_ARTIFACT_ID = "archetype.artifactId";
+
+    String ARCHETYPE_DESCRIPTOR = "META-INF/maven/archetype-metadata.xml";
+
+    String ARCHETYPE_GROUP_ID = "archetype.groupId";
+
+    String ARCHETYPE_POM = "pom.xml";
+
+    String ARCHETYPE_RESOURCES = "archetype-resources";
+
+    String ARCHETYPE_SUFFIX = "-archetype";
+
+    String ARCHETYPE_VERSION = "archetype.version";
+
+    String ARTIFACT_ID = "artifactId";
+
+    List DEFAULT_FILTERED_EXTENSIONS =
+        Arrays.asList (
+            new String[]
+            {
+                "java", "xml", "txt", "groovy", "cs", "mdo", "aj", "jsp", "gsp", "vm", "html",
+                "xhtml", "properties", ".classpath", ".project"
+            }
+        );
+
+    List DEFAULT_LANGUAGES =
+        Arrays.asList ( new String[] { "java", "groovy", "csharp", "aspectj" } );
+
+    String GROUP_ID = "groupId";
+
+    String MAIN = "main";
+
+    String OLD_ARCHETYPE_DESCRIPTOR = "META-INF/maven/archetype.xml";
+
+    String OLDER_ARCHETYPE_DESCRIPTOR = "META-INF/archetype.xml";
+
+    String PACKAGE = "package";
+
+    String PACKAGE_NAME = "packageName";
+
+    String PARENT_ARTIFACT_ID = "parentArtifactId";
+
+    String POM_PATH = Constants.ARCHETYPE_RESOURCES + "/" + Constants.ARCHETYPE_POM;
+
+    String RESOURCES = "resources";
+
+    String SITE = "site";
+
+    String SRC = "src";
+
+    String TEST = "test";
+
+    String TMP = ".tmp";
+
+    String VERSION = "version";
+}

Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java?rev=570611&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java Tue Aug 28 19:32:45 2007
@@ -0,0 +1,657 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.maven.archetype.common;
+
+import org.apache.maven.archetype.descriptor.ArchetypeDescriptorBuilder;
+import org.apache.maven.archetype.exception.UnknownArchetype;
+import org.apache.maven.archetype.exception.UnknownGroup;
+import org.apache.maven.archetype.metadata.ArchetypeDescriptor;
+import org.apache.maven.archetype.metadata.io.xpp3.ArchetypeDescriptorXpp3Reader;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.Plugin;
+import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
+import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
+import org.apache.maven.shared.downloader.DownloadException;
+import org.apache.maven.shared.downloader.DownloadNotFoundException;
+import org.apache.maven.shared.downloader.Downloader;
+
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+
+/**
+ * @plexus.component
+ */
+public class DefaultArchetypeArtifactManager
+extends AbstractLogEnabled
+implements ArchetypeArtifactManager
+{
+    /**
+     * @plexus.requirement
+     */
+    private Downloader downloader;
+
+    /**
+     * @plexus.requirement
+     */
+    private RepositoryMetadataManager repositoryMetadataManager;
+
+    public File getArchetypeFile (
+        final String groupId,
+        final String artifactId,
+        final String version,
+        final ArtifactRepository localRepository,
+        final List repositories
+    )
+    throws UnknownArchetype
+    {
+        try
+        {
+            return
+                downloader.download ( groupId, artifactId, version, localRepository, repositories );
+        }
+        catch ( DownloadNotFoundException ex )
+        {
+            throw new UnknownArchetype ( ex );
+        }
+        catch ( DownloadException ex )
+        {
+            throw new UnknownArchetype ( ex );
+        }
+    }
+
+    public ClassLoader getArchetypeJarLoader ( File archetypeFile )
+    throws UnknownArchetype
+    {
+        try
+        {
+            URL[] urls = new URL[1];
+
+            urls[0] = archetypeFile.toURI ().toURL ();
+
+            return new URLClassLoader ( urls );
+        }
+        catch ( MalformedURLException e )
+        {
+            throw new UnknownArchetype ( e );
+        }
+    }
+
+    public ClassLoader getArchetypeJarLoader (
+        String groupId,
+        String artifactId,
+        String version,
+        ArtifactRepository localRepository,
+        List repositories
+    )
+    throws UnknownArchetype
+    {
+        try
+        {
+            File archetypeFile =
+                getArchetypeFile ( groupId, artifactId, version, localRepository, repositories );
+            URL[] urls = new URL[1];
+
+            urls[0] = archetypeFile.toURI ().toURL ();
+
+            return new URLClassLoader ( urls );
+        }
+        catch ( MalformedURLException e )
+        {
+            throw new UnknownArchetype ( e );
+        }
+    }
+
+    public List getArchetypes (
+        String groupId,
+        ArtifactRepository localRepository,
+        List repositories
+    )
+    throws UnknownGroup
+    {
+        try
+        {
+            List archetypes = new ArrayList ();
+
+            RepositoryMetadata metadata = new GroupRepositoryMetadata ( groupId );
+
+            repositoryMetadataManager.resolve ( metadata, repositories, localRepository );
+
+            for (
+                Iterator iter = metadata.getMetadata ().getPlugins ().iterator ();
+                iter.hasNext ();
+            )
+            {
+                Plugin plugin = (Plugin) iter.next ();
+
+                Archetype archetype = new Archetype ();
+
+                archetype.setGroupId ( groupId );
+                archetype.setArtifactId ( plugin.getArtifactId () );
+                archetype.setName ( plugin.getName () );
+                archetype.setPrefix ( plugin.getPrefix () );
+
+                if ( getLogger ().isDebugEnabled () )
+                {
+                    getLogger ().debug ( "plugin=" + groupId + ":" + plugin.getArtifactId () );
+                }
+
+                if ( !archetypes.contains ( archetype ) )
+                {
+                    archetypes.add ( archetype );
+                }
+            } // end for
+
+            return archetypes;
+        }
+        catch ( RepositoryMetadataResolutionException e )
+        {
+            throw new UnknownGroup ( e );
+        }
+    }
+
+    public ZipFile getArchetypeZipFile ( File archetypeFile )
+    throws UnknownArchetype
+    {
+        try
+        {
+            return new ZipFile ( archetypeFile );
+        }
+        catch ( ZipException e )
+        {
+            throw new UnknownArchetype ( e );
+        }
+        catch ( IOException e )
+        {
+            throw new UnknownArchetype ( e );
+        }
+    }
+
+    public ZipFile getArchetypeZipFile (
+        String groupId,
+        String artifactId,
+        String version,
+        ArtifactRepository localRepository,
+        List repositories
+    )
+    throws UnknownArchetype
+    {
+        try
+        {
+            File archetypeFile =
+                getArchetypeFile ( groupId, artifactId, version, localRepository, repositories );
+
+            return new ZipFile ( archetypeFile );
+        }
+        catch ( ZipException e )
+        {
+            throw new UnknownArchetype ( e );
+        }
+        catch ( IOException e )
+        {
+            throw new UnknownArchetype ( e );
+        }
+    }
+
+    public boolean exists (
+        String groupId,
+        String artifactId,
+        String version,
+        ArtifactRepository localRepository,
+        List repositories
+    )
+    {
+        try
+        {
+            File archetypeFile =
+                downloader.download ( groupId, artifactId, version, localRepository, repositories );
+
+            return archetypeFile.exists ();
+        }
+        catch ( DownloadException e )
+        {
+            return false;
+        }
+        catch ( DownloadNotFoundException e )
+        {
+            return false;
+        }
+    }
+
+    public boolean isFileSetArchetype (
+        String groupId,
+        String artifactId,
+        String version,
+        ArtifactRepository localRepository,
+        List repositories
+    )
+    {
+        try
+        {
+            ClassLoader archetypeJarLoader =
+                getArchetypeJarLoader (
+                    groupId,
+                    artifactId,
+                    version,
+                    localRepository,
+                    repositories
+                );
+
+            org.apache.maven.archetype.metadata.ArchetypeDescriptor descriptor =
+                loadFileSetArchetypeDescriptor ( archetypeJarLoader );
+
+            return descriptor.getId () != null;
+        }
+        catch ( XmlPullParserException e )
+        {
+            return false;
+        }
+        catch ( IOException e )
+        {
+            return false;
+        }
+        catch ( UnknownArchetype e )
+        {
+            return false;
+        }
+    }
+
+    public ArchetypeDescriptor getFileSetArchetypeDescriptor ( File archetypeFile )
+    throws UnknownArchetype
+    {
+        try
+        {
+            ClassLoader archetypeJarLoader = getArchetypeJarLoader ( archetypeFile );
+
+            return loadFileSetArchetypeDescriptor ( archetypeJarLoader );
+        }
+        catch ( XmlPullParserException e )
+        {
+            throw new UnknownArchetype ( e );
+        }
+        catch ( IOException e )
+        {
+            throw new UnknownArchetype ( e );
+        }
+    }
+
+    public org.apache.maven.archetype.metadata.ArchetypeDescriptor getFileSetArchetypeDescriptor (
+        String groupId,
+        String artifactId,
+        String version,
+        ArtifactRepository localRepository,
+        List repositories
+    )
+    throws UnknownArchetype
+    {
+        try
+        {
+            ClassLoader archetypeJarLoader =
+                getArchetypeJarLoader (
+                    groupId,
+                    artifactId,
+                    version,
+                    localRepository,
+                    repositories
+                );
+
+            return loadFileSetArchetypeDescriptor ( archetypeJarLoader );
+        }
+        catch ( XmlPullParserException e )
+        {
+            throw new UnknownArchetype ( e );
+        }
+        catch ( IOException e )
+        {
+            throw new UnknownArchetype ( e );
+        }
+    }
+
+    public List getFilesetArchetypeResources ( File archetypeFile )
+    throws UnknownArchetype
+    {
+        List archetypeResources = new ArrayList ();
+
+        ZipFile zipFile = getArchetypeZipFile ( archetypeFile );
+
+        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 (),
+                        Constants.ARCHETYPE_RESOURCES + "/",
+                        ""
+                    );
+                getLogger ().debug ( "Found resource " + resource );
+                // TODO:FIXME
+                archetypeResources.add ( resource );
+            }
+            else
+            {
+                getLogger ().debug ( "Not resource " + entry.getName () );
+            }
+        }
+        return archetypeResources;
+    }
+
+    public List getFilesetArchetypeResources (
+        String groupId,
+        String artifactId,
+        String version,
+        ArtifactRepository localRepository,
+        List repositories
+    )
+    throws UnknownArchetype
+    {
+        List archetypeResources = new ArrayList ();
+
+        ZipFile zipFile =
+            getArchetypeZipFile ( groupId, artifactId, version, localRepository, repositories );
+
+        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
+                archetypeResources.add (
+                    StringUtils.replace (
+                        entry.getName (),
+                        Constants.ARCHETYPE_RESOURCES + "/",
+                        ""
+                    )
+                );
+            }
+        }
+        return archetypeResources;
+    }
+
+    public boolean isOldArchetype (
+        String groupId,
+        String artifactId,
+        String version,
+        ArtifactRepository localRepository,
+        List repositories
+    )
+    {
+        try
+        {
+            ClassLoader archetypeJarLoader =
+                getArchetypeJarLoader (
+                    groupId,
+                    artifactId,
+                    version,
+                    localRepository,
+                    repositories
+                );
+
+            org.apache.maven.archetype.descriptor.ArchetypeDescriptor descriptor =
+                loadOldArchetypeDescriptor ( archetypeJarLoader );
+
+            return descriptor.getId () != null;
+        }
+        catch ( XmlPullParserException e )
+        {
+            return false;
+        }
+        catch ( IOException e )
+        {
+            return false;
+        }
+        catch ( UnknownArchetype ex )
+        {
+            return false;
+        }
+    }
+
+    public org.apache.maven.archetype.descriptor.ArchetypeDescriptor getOldArchetypeDescriptor (
+        String groupId,
+        String artifactId,
+        String version,
+        ArtifactRepository localRepository,
+        List repositories
+    )
+    throws UnknownArchetype
+    {
+        try
+        {
+            ClassLoader archetypeJarLoader =
+                getArchetypeJarLoader (
+                    groupId,
+                    artifactId,
+                    version,
+                    localRepository,
+                    repositories
+                );
+
+            return loadOldArchetypeDescriptor ( archetypeJarLoader );
+        }
+        catch ( XmlPullParserException e )
+        {
+            throw new UnknownArchetype ( e );
+        }
+        catch ( IOException e )
+        {
+            throw new UnknownArchetype ( e );
+        }
+    }
+
+    public String getReleaseVersion (
+        String groupId,
+        String artifactId,
+        ArtifactRepository localRepository,
+        List repositories
+    )
+    throws UnknownArchetype
+    {
+        try
+        {
+            RepositoryMetadata metadata =
+                new GroupRepositoryMetadata ( groupId + "." + artifactId );
+
+            repositoryMetadataManager.resolve ( metadata, repositories, localRepository );
+
+            return metadata.getMetadata ().getVersioning ().getRelease ();
+        }
+        catch ( RepositoryMetadataResolutionException e )
+        {
+            throw new UnknownArchetype ( e );
+        }
+    }
+
+    public List getVersions (
+        String groupId,
+        String artifactId,
+        ArtifactRepository localRepository,
+        List repositories
+    )
+    throws UnknownArchetype
+    {
+        try
+        {
+            RepositoryMetadata metadata =
+                new GroupRepositoryMetadata ( groupId + "." + artifactId );
+
+            repositoryMetadataManager.resolve ( metadata, repositories, localRepository );
+
+            return metadata.getMetadata ().getVersioning ().getVersions ();
+        }
+        catch ( RepositoryMetadataResolutionException e )
+        {
+            throw new UnknownArchetype ( e );
+        }
+    }
+
+    private Reader getArchetypeDescriptorReader ( ClassLoader archetypeJarLoader )
+    throws IOException
+    {
+        InputStream is = getStream ( Constants.ARCHETYPE_DESCRIPTOR, archetypeJarLoader );
+
+        if ( is == null )
+        {
+            throw new IOException (
+                "The " + Constants.ARCHETYPE_DESCRIPTOR + " descriptor cannot be found."
+            );
+        }
+
+        return new InputStreamReader ( is );
+    }
+
+    private org.apache.maven.archetype.metadata.ArchetypeDescriptor loadFileSetArchetypeDescriptor (
+        ClassLoader archetypeJarLoader
+    )
+    throws XmlPullParserException, IOException
+    {
+        Reader reader = getArchetypeDescriptorReader ( archetypeJarLoader );
+
+        ArchetypeDescriptorXpp3Reader archetypeReader = new ArchetypeDescriptorXpp3Reader ();
+
+        try
+        {
+            return archetypeReader.read ( reader, true );
+        }
+        finally
+        {
+            reader.close ();
+        }
+    }
+
+    private org.apache.maven.archetype.descriptor.ArchetypeDescriptor loadOldArchetypeDescriptor (
+        ClassLoader archetypeJarLoader
+    )
+    throws IOException, XmlPullParserException
+    {
+        ArchetypeDescriptorBuilder builder = new ArchetypeDescriptorBuilder ();
+
+        org.apache.maven.archetype.descriptor.ArchetypeDescriptor descriptor = null;
+
+        Reader reader = null;
+        try
+        {
+            reader = getOldArchetypeDescriptorReader ( archetypeJarLoader );
+
+            descriptor = builder.build ( reader );
+        }
+        catch ( IOException ex )
+        {
+            getLogger ().debug ( "Can not load old archetype", ex );
+        }
+        catch ( XmlPullParserException ex )
+        {
+            getLogger ().debug ( "Can not load old archetype", ex );
+        }
+        finally
+        {
+            if ( reader != null )
+            {
+                reader.close ();
+            }
+        }
+
+        if ( descriptor == null )
+        {
+            try
+            {
+                reader = getOlderArchetypeDescriptorReader ( archetypeJarLoader );
+
+                descriptor = builder.build ( reader );
+            }
+            finally
+            {
+                if ( reader != null )
+                {
+                    reader.close ();
+                }
+            }
+        }
+
+        return descriptor;
+    }
+
+    private Reader getOldArchetypeDescriptorReader ( ClassLoader archetypeJarLoader )
+    throws IOException
+    {
+        InputStream is = getStream ( Constants.OLD_ARCHETYPE_DESCRIPTOR, archetypeJarLoader );
+
+        if ( is == null )
+        {
+            throw new IOException (
+                "The " + Constants.OLD_ARCHETYPE_DESCRIPTOR + " descriptor cannot be found."
+            );
+        }
+
+        return new InputStreamReader ( is );
+    }
+
+    private Reader getOlderArchetypeDescriptorReader ( ClassLoader archetypeJarLoader )
+    throws IOException
+    {
+        InputStream is = getStream ( Constants.OLDER_ARCHETYPE_DESCRIPTOR, archetypeJarLoader );
+
+        if ( is == null )
+        {
+            throw new IOException (
+                "The " + Constants.OLDER_ARCHETYPE_DESCRIPTOR + " descriptor cannot be found."
+            );
+        }
+
+        return new InputStreamReader ( is );
+    }
+
+    private InputStream getStream ( String name, ClassLoader loader )
+    {
+        return
+            ( loader == null )
+            ? Thread.currentThread ().getContextClassLoader ().getResourceAsStream ( name )
+            : loader.getResourceAsStream ( name );
+    }
+}

Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeFactory.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeFactory.java?rev=570611&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeFactory.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeFactory.java Tue Aug 28 19:32:45 2007
@@ -0,0 +1,404 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.maven.archetype.common;
+
+import org.apache.maven.project.MavenProject;
+
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+import java.util.Iterator;
+import java.util.Properties;
+
+/**
+ * @plexus.component
+ */
+public class DefaultArchetypeFactory
+extends AbstractLogEnabled
+implements ArchetypeFactory
+{
+    public ArchetypeConfiguration createArchetypeConfiguration (
+        ArchetypeDefinition archetypeDefinition,
+        Properties properties
+    )
+    {
+        ArchetypeConfiguration configuration = new ArchetypeConfiguration ();
+        getLogger ().debug (
+            "Creating ArchetypeConfiguration from ArchetypeDefinition and Properties"
+        );
+
+        configuration.setGroupId ( archetypeDefinition.getGroupId () );
+        configuration.setArtifactId ( archetypeDefinition.getArtifactId () );
+        configuration.setVersion ( archetypeDefinition.getVersion () );
+
+        Iterator propertiesIterator = properties.keySet ().iterator ();
+        while ( propertiesIterator.hasNext () )
+        {
+            String property = (String) propertiesIterator.next ();
+            if ( !Constants.ARCHETYPE_GROUP_ID.equals ( property )
+                && !Constants.ARCHETYPE_ARTIFACT_ID.equals ( property )
+                && !Constants.ARCHETYPE_VERSION.equals ( property )
+            )
+            {
+                configuration.addRequiredProperty ( property );
+
+                getLogger ().debug ( "Adding requiredProperty " + property );
+
+                configuration.setProperty ( property, properties.getProperty ( property ) );
+
+                getLogger ().debug (
+                    "Adding property " + property + "=" + properties.getProperty ( property )
+                );
+            }
+        }
+
+        return configuration;
+    }
+
+    public ArchetypeConfiguration createArchetypeConfiguration (
+        org.apache.maven.archetype.descriptor.ArchetypeDescriptor archetypeDescriptor,
+        Properties properties
+    )
+    {
+        ArchetypeConfiguration configuration = new ArchetypeConfiguration ();
+        getLogger ().debug (
+            "Creating ArchetypeConfiguration from legacy descriptor and Properties"
+        );
+
+        configuration.setGroupId ( properties.getProperty ( Constants.ARCHETYPE_GROUP_ID, null ) );
+        configuration.setArtifactId (
+            properties.getProperty ( Constants.ARCHETYPE_ARTIFACT_ID, null )
+        );
+        configuration.setVersion ( properties.getProperty ( Constants.ARCHETYPE_VERSION, null ) );
+
+        configuration.setName ( archetypeDescriptor.getId () );
+
+        configuration.addRequiredProperty ( Constants.GROUP_ID );
+        getLogger ().debug ( "Adding requiredProperty " + Constants.GROUP_ID );
+        if ( null != properties.getProperty ( Constants.GROUP_ID, null ) )
+        {
+            configuration.setProperty (
+                Constants.GROUP_ID,
+                properties.getProperty ( Constants.GROUP_ID )
+            );
+            getLogger ().debug (
+                "Setting property " + Constants.GROUP_ID + "="
+                + configuration.getProperty ( Constants.GROUP_ID )
+            );
+        }
+        configuration.addRequiredProperty ( Constants.ARTIFACT_ID );
+        getLogger ().debug ( "Adding requiredProperty " + Constants.ARTIFACT_ID );
+        if ( null != properties.getProperty ( Constants.ARTIFACT_ID, null ) )
+        {
+            configuration.setProperty (
+                Constants.ARTIFACT_ID,
+                properties.getProperty ( Constants.ARTIFACT_ID )
+            );
+            getLogger ().debug (
+                "Setting property " + Constants.ARTIFACT_ID + "="
+                + configuration.getProperty ( Constants.ARTIFACT_ID )
+            );
+        }
+        configuration.addRequiredProperty ( Constants.VERSION );
+        getLogger ().debug ( "Adding requiredProperty " + Constants.VERSION );
+        if ( null != properties.getProperty ( Constants.VERSION, null ) )
+        {
+            configuration.setProperty (
+                Constants.VERSION,
+                properties.getProperty ( Constants.VERSION )
+            );
+            getLogger ().debug (
+                "Setting property " + Constants.VERSION + "="
+                + configuration.getProperty ( Constants.VERSION )
+            );
+        }
+        configuration.addRequiredProperty ( Constants.PACKAGE );
+        getLogger ().debug ( "Adding requiredProperty " + Constants.PACKAGE );
+        if ( null
+            != properties.getProperty (
+                Constants.PACKAGE,
+                properties.getProperty ( Constants.PACKAGE_NAME, null )
+            )
+        )
+        {
+            configuration.setProperty (
+                Constants.PACKAGE,
+                properties.getProperty (
+                    Constants.PACKAGE,
+                    properties.getProperty ( Constants.PACKAGE_NAME )
+                )
+            );
+            getLogger ().debug (
+                "Setting property " + Constants.PACKAGE_NAME + "="
+                + configuration.getProperty ( Constants.PACKAGE_NAME )
+            );
+        }
+
+        return configuration;
+    }
+
+    public ArchetypeConfiguration createArchetypeConfiguration (
+        org.apache.maven.archetype.metadata.ArchetypeDescriptor archetypeDescriptor,
+        Properties properties
+    )
+    {
+        ArchetypeConfiguration configuration = new ArchetypeConfiguration ();
+        getLogger ().debug (
+            "Creating ArchetypeConfiguration from fileset descriptor and Properties"
+        );
+
+        configuration.setGroupId ( properties.getProperty ( Constants.ARCHETYPE_GROUP_ID, null ) );
+        configuration.setArtifactId (
+            properties.getProperty ( Constants.ARCHETYPE_ARTIFACT_ID, null )
+        );
+        configuration.setVersion ( properties.getProperty ( Constants.ARCHETYPE_VERSION, null ) );
+
+        configuration.setName ( archetypeDescriptor.getId () );
+
+        Iterator requiredProperties = archetypeDescriptor.getRequiredProperties ().iterator ();
+        while ( requiredProperties.hasNext () )
+        {
+            org.apache.maven.archetype.metadata.RequiredProperty requiredProperty =
+                (org.apache.maven.archetype.metadata.RequiredProperty) requiredProperties.next ();
+
+            configuration.addRequiredProperty ( requiredProperty.getKey () );
+            getLogger ().debug ( "Adding requiredProperty " + requiredProperty.getKey () );
+
+            if ( null
+                != properties.getProperty (
+                    requiredProperty.getKey (),
+                    requiredProperty.getDefaultValue ()
+                )
+            )
+            {
+                configuration.setProperty (
+                    requiredProperty.getKey (),
+                    properties.getProperty (
+                        requiredProperty.getKey (),
+                        requiredProperty.getDefaultValue ()
+                    )
+                );
+                getLogger ().debug (
+                    "Setting property " + requiredProperty.getKey () + "="
+                    + configuration.getProperty ( requiredProperty.getKey () )
+                );
+            }
+            if ( null != requiredProperty.getDefaultValue () )
+            {
+                configuration.setDefaultProperty (
+                    requiredProperty.getKey (),
+                    requiredProperty.getDefaultValue ()
+                );
+                getLogger ().debug (
+                    "Setting defaultProperty " + requiredProperty.getKey () + "="
+                    + configuration.getDefaultValue ( requiredProperty.getKey () )
+                );
+            }
+        } // end while
+
+        if (!configuration.isConfigured(Constants.GROUP_ID))
+        {
+            configuration.addRequiredProperty ( Constants.GROUP_ID );
+            getLogger ().debug ( "Adding requiredProperty " + Constants.GROUP_ID );
+            if ( null != properties.getProperty ( Constants.GROUP_ID, configuration.getDefaultValue ( Constants.GROUP_ID ) ) )
+            {
+                configuration.setProperty (
+                    Constants.GROUP_ID,
+                    properties.getProperty ( Constants.GROUP_ID, configuration.getDefaultValue ( Constants.GROUP_ID ) )
+                );
+                getLogger ().debug (
+                    "Setting property " + Constants.GROUP_ID + "="
+                    + configuration.getProperty ( Constants.GROUP_ID )
+                );
+            }
+        }
+        if (!configuration.isConfigured(Constants.ARTIFACT_ID))
+        {
+            configuration.addRequiredProperty ( Constants.ARTIFACT_ID );
+            getLogger ().debug ( "Adding requiredProperty " + Constants.ARTIFACT_ID );
+            if ( null != properties.getProperty ( Constants.ARTIFACT_ID, configuration.getDefaultValue ( Constants.ARTIFACT_ID ) ) )
+            {
+                configuration.setProperty (
+                    Constants.ARTIFACT_ID,
+                    properties.getProperty ( Constants.ARTIFACT_ID )
+                );
+                getLogger ().debug (
+                    "Setting property " + Constants.ARTIFACT_ID + "="
+                    + configuration.getProperty ( Constants.ARTIFACT_ID )
+                );
+            }
+        }
+        if (!configuration.isConfigured(Constants.VERSION))
+        {
+            configuration.addRequiredProperty ( Constants.VERSION );
+            getLogger ().debug ( "Adding requiredProperty " + Constants.VERSION );
+            if ( null != properties.getProperty ( Constants.VERSION, configuration.getDefaultValue ( Constants.VERSION ) ) )
+            {
+                configuration.setProperty (
+                    Constants.VERSION,
+                    properties.getProperty ( Constants.VERSION, configuration.getDefaultValue ( Constants.VERSION ) )
+                );
+                getLogger ().debug (
+                    "Setting property " + Constants.VERSION + "="
+                    + configuration.getProperty ( Constants.VERSION )
+                );
+            }
+        }
+        if (!configuration.isConfigured(Constants.PACKAGE))
+        {
+            configuration.addRequiredProperty ( Constants.PACKAGE );
+            getLogger ().debug ( "Adding requiredProperty " + Constants.PACKAGE );
+            if ( null
+                != properties.getProperty (
+                    Constants.PACKAGE,
+                    properties.getProperty ( Constants.PACKAGE_NAME, configuration.getDefaultValue ( Constants.PACKAGE_NAME ) )
+                )
+            )
+            {
+                configuration.setProperty (
+                    Constants.PACKAGE,
+                    properties.getProperty (
+                        Constants.PACKAGE,
+                        properties.getProperty ( Constants.PACKAGE_NAME, configuration.getDefaultValue ( Constants.PACKAGE_NAME ) )
+                    )
+                );
+                getLogger ().debug (
+                    "Setting property " + Constants.PACKAGE + "="
+                    + configuration.getProperty ( Constants.PACKAGE )
+                );
+            }
+        }
+
+        return configuration;
+    }
+
+    public ArchetypeConfiguration createArchetypeConfiguration (
+        MavenProject project,
+        ArchetypeDefinition archetypeDefinition,
+        Properties properties
+    )
+    {
+        ArchetypeConfiguration configuration = new ArchetypeConfiguration ();
+        getLogger ().debug (
+            "Creating ArchetypeConfiguration from ArchetypeDefinition, MavenProject and Properties"
+        );
+
+        configuration.setGroupId ( archetypeDefinition.getGroupId () );
+        configuration.setArtifactId ( archetypeDefinition.getArtifactId () );
+        configuration.setVersion ( archetypeDefinition.getVersion () );
+
+        configuration.addRequiredProperty ( Constants.GROUP_ID );
+        getLogger ().debug ( "Adding requiredProperty " + Constants.GROUP_ID );
+        configuration.setDefaultProperty ( Constants.GROUP_ID, project.getGroupId () );
+        if ( null != properties.getProperty ( Constants.GROUP_ID, null ) )
+        {
+            configuration.setProperty (
+                Constants.GROUP_ID,
+                properties.getProperty ( Constants.GROUP_ID )
+            );
+            getLogger ().debug (
+                "Setting property " + Constants.GROUP_ID + "="
+                + configuration.getProperty ( Constants.GROUP_ID )
+            );
+        }
+
+        configuration.addRequiredProperty ( Constants.ARTIFACT_ID );
+        getLogger ().debug ( "Adding requiredProperty " + Constants.ARTIFACT_ID );
+        configuration.setDefaultProperty ( Constants.ARTIFACT_ID, project.getArtifactId () );
+        if ( null != properties.getProperty ( Constants.ARTIFACT_ID, null ) )
+        {
+            configuration.setProperty (
+                Constants.ARTIFACT_ID,
+                properties.getProperty ( Constants.ARTIFACT_ID )
+            );
+            getLogger ().debug (
+                "Setting property " + Constants.ARTIFACT_ID + "="
+                + configuration.getProperty ( Constants.ARTIFACT_ID )
+            );
+        }
+
+        configuration.addRequiredProperty ( Constants.VERSION );
+        getLogger ().debug ( "Adding requiredProperty " + Constants.VERSION );
+        configuration.setDefaultProperty ( Constants.VERSION, project.getVersion () );
+        if ( null != properties.getProperty ( Constants.VERSION, null ) )
+        {
+            configuration.setProperty (
+                Constants.VERSION,
+                properties.getProperty ( Constants.VERSION )
+            );
+            getLogger ().debug (
+                "Setting property " + Constants.VERSION + "="
+                + configuration.getProperty ( Constants.VERSION )
+            );
+        }
+
+        configuration.addRequiredProperty ( Constants.PACKAGE );
+        getLogger ().debug ( "Adding requiredProperty " + Constants.PACKAGE );
+        if ( null
+            != properties.getProperty (
+                Constants.PACKAGE,
+                properties.getProperty ( Constants.PACKAGE_NAME, null )
+            )
+        )
+        {
+            configuration.setProperty (
+                Constants.PACKAGE,
+                properties.getProperty (
+                    Constants.PACKAGE,
+                    properties.getProperty ( Constants.PACKAGE_NAME )
+                )
+            );
+            getLogger ().debug (
+                "Setting property " + Constants.PACKAGE + "="
+                + configuration.getProperty ( Constants.PACKAGE )
+            );
+        }
+
+        return configuration;
+    }
+
+    public ArchetypeDefinition createArchetypeDefinition ( Properties properties )
+    {
+        ArchetypeDefinition definition = new ArchetypeDefinition ();
+        getLogger ().debug (
+            "Creating ArchetypeDefinition ("
+            + properties.getProperty ( Constants.ARCHETYPE_GROUP_ID, null ) + ":"
+            + properties.getProperty ( Constants.ARCHETYPE_ARTIFACT_ID, null ) + ":"
+            + properties.getProperty ( Constants.ARCHETYPE_VERSION, null ) + ")"
+        );
+
+        definition.setGroupId ( properties.getProperty ( Constants.ARCHETYPE_GROUP_ID, null ) );
+        definition.setArtifactId (
+            properties.getProperty ( Constants.ARCHETYPE_ARTIFACT_ID, null )
+        );
+        definition.setVersion ( properties.getProperty ( Constants.ARCHETYPE_VERSION, null ) );
+
+        return definition;
+    }
+
+    public void updateArchetypeConfiguration (
+        ArchetypeConfiguration archetypeConfiguration,
+        ArchetypeDefinition archetypeDefinition
+    )
+    {
+        archetypeConfiguration.setGroupId ( archetypeDefinition.getGroupId () );
+        archetypeConfiguration.setArtifactId ( archetypeDefinition.getArtifactId () );
+        archetypeConfiguration.setVersion ( archetypeDefinition.getVersion () );
+    }
+}

Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeFilesResolver.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeFilesResolver.java?rev=570611&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeFilesResolver.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeFilesResolver.java Tue Aug 28 19:32:45 2007
@@ -0,0 +1,465 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.maven.archetype.common;
+
+import org.apache.maven.archetype.metadata.FileSet;
+
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.io.File;
+import java.io.IOException;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @plexus.component
+ */
+public class DefaultArchetypeFilesResolver
+extends AbstractLogEnabled
+implements ArchetypeFilesResolver
+{
+    public List getFilesWithExtension ( List files, String extension )
+    {
+        ListScanner scanner = new ListScanner ();
+        scanner.setBasedir ( "" );
+
+        scanner.setIncludes ( "**/*." + extension );
+        scanner.setExcludes ( "" );
+
+        return scanner.scan ( files );
+    }
+
+    public List getFilteredFiles ( List files, String filtered )
+    {
+        ListScanner scanner = new ListScanner ();
+        scanner.setBasedir ( "" );
+
+        scanner.setIncludes ( filtered );
+        scanner.setExcludes ( "" );
+
+        List result = scanner.scan ( files );
+        getLogger ().debug (
+            "Scanned " + result.size () + " filtered files in " + files.size () + " files"
+        );
+
+        return result;
+    }
+
+    public List filterFiles ( FileSet fileSet, List archetypeResources )
+    {
+        return filterFiles ( "", fileSet, archetypeResources );
+    }
+
+    public List filterFiles ( String moduleOffset, FileSet fileSet, List archetypeResources )
+    {
+        ListScanner scanner = new ListScanner ();
+        scanner.setBasedir (
+            ( StringUtils.isEmpty ( moduleOffset ) ? "" : ( moduleOffset + File.separatorChar ) )
+            + fileSet.getDirectory ()
+        );
+        scanner.setIncludes ( fileSet.getIncludes () );
+        scanner.setExcludes ( fileSet.getExcludes () );
+        scanner.setCaseSensitive ( true );
+
+        return scanner.scan ( archetypeResources );
+    }
+
+    public List findOtherResources ( int level, List files, String languages )
+    {
+        ListScanner scanner = new ListScanner ();
+
+        scanner.setBasedir ( "" );
+
+        String includes = "";
+        for ( int i = 0; i < level; i++ )
+        {
+            includes += "*/";
+        }
+
+        scanner.setIncludes ( includes + "**" );
+        scanner.setExcludes ( languages );
+
+        List result = scanner.scan ( files );
+        getLogger ().debug (
+            "Scanned " + result.size () + " other resources in " + files.size ()
+            + " files at level " + level
+        );
+
+        return result;
+    }
+
+    public List findOtherResources ( int level, List files, List sourcesFiles, String languages )
+    {
+        ListScanner scanner = new ListScanner ();
+
+        scanner.setBasedir ( "" );
+
+        Set selectedDirectories = new HashSet ();
+
+        List includes = new ArrayList ();
+
+        Iterator sourcesFilesIterator = sourcesFiles.iterator ();
+        while ( sourcesFilesIterator.hasNext () )
+        {
+            String sourcesFile = (String) sourcesFilesIterator.next ();
+
+            String directory = PathUtils.getDirectory ( sourcesFile, level - 1 );
+            if ( !selectedDirectories.contains ( directory ) )
+            {
+                includes.add ( directory + "/**" );
+            }
+
+            selectedDirectories.add ( directory );
+        }
+
+        scanner.setExcludes ( languages );
+
+        List result = scanner.scan ( files );
+        getLogger ().debug (
+            "Scanned " + result.size () + " other resources in " + files.size ()
+            + " files at level " + level
+        );
+
+        return result;
+    }
+
+    public List findOtherSources ( int level, List files, String languages )
+    {
+        ListScanner scanner = new ListScanner ();
+        scanner.setBasedir ( "" );
+
+        String levelDirectory = "";
+        for ( int i = 0; i < ( level - 1 ); i++ )
+        {
+            levelDirectory += "*/";
+        }
+
+        String includes = "";
+        String[] languagesAsArray = StringUtils.split ( languages );
+        for ( int i = 0; i < languagesAsArray.length; i++ )
+        {
+            includes += levelDirectory + languagesAsArray[i];
+        }
+
+        scanner.setIncludes ( includes );
+
+        List result = scanner.scan ( files );
+        getLogger ().debug (
+            "Scanned " + result.size () + " other sources in " + files.size () + " files at level "
+            + level
+        );
+
+        return result;
+    }
+
+    public List findResourcesMainFiles ( List files, String languages )
+    {
+        ListScanner scanner = new ListScanner ();
+        scanner.setBasedir ( "src/main" );
+
+        scanner.setIncludes ( "**" );
+        scanner.setExcludes ( languages );
+
+        List result = scanner.scan ( files );
+        getLogger ().debug (
+            "Scanned " + result.size () + " resources in " + files.size () + " files"
+        );
+
+        return result;
+    }
+
+    public List findResourcesTestFiles ( List files, String languages )
+    {
+        ListScanner scanner = new ListScanner ();
+        scanner.setBasedir ( "src/test" );
+
+        scanner.setIncludes ( "**" );
+        scanner.setExcludes ( languages );
+
+        List result = scanner.scan ( files );
+        getLogger ().debug (
+            "Scanned " + result.size () + " test resources in " + files.size () + " files"
+        );
+
+        return result;
+    }
+
+    public List findSiteFiles ( List files, String languages )
+    {
+        ListScanner scanner = new ListScanner ();
+        scanner.setBasedir ( "src/site" );
+
+        scanner.setIncludes ( "**" );
+        scanner.setExcludes ( languages );
+
+        List result = scanner.scan ( files );
+        getLogger ().debug (
+            "Scanned " + result.size () + " site resources in " + files.size () + " files"
+        );
+
+        return result;
+    }
+
+    public List findSourcesMainFiles ( List files, String languages )
+    {
+        ListScanner scanner = new ListScanner ();
+        scanner.setBasedir ( "src/main" );
+
+        scanner.setIncludes ( languages );
+
+        List result = scanner.scan ( files );
+        getLogger ().debug (
+            "Scanned " + result.size () + " sources in " + files.size () + " files"
+        );
+
+        return result;
+    }
+
+    public List findSourcesTestFiles ( List files, String languages )
+    {
+        ListScanner scanner = new ListScanner ();
+        scanner.setBasedir ( "src/test" );
+
+        scanner.setIncludes ( languages );
+
+        List result = scanner.scan ( files );
+        getLogger ().debug (
+            "Scanned " + result.size () + " test sources in " + files.size () + " files"
+        );
+
+        return result;
+    }
+
+    public List getPackagedFiles ( List files, String packageName )
+    {
+        List packagedFiles = new ArrayList ();
+        Iterator filesIterator = files.iterator ();
+        while ( filesIterator.hasNext () )
+        {
+            String file = (String) filesIterator.next ();
+
+            if ( file.startsWith ( packageName ) )
+            {
+                packagedFiles.add ( file.substring ( packageName.length () + 1 ) );
+            }
+        }
+        getLogger ().debug (
+            "Scanned " + packagedFiles.size () + " packaged files in " + files.size () + " files"
+        );
+        return packagedFiles;
+    }
+
+    public String resolvePackage ( File basedir, List languages )
+    throws IOException
+    {
+        getLogger ().debug ( "Resolving package in " + basedir + " using languages " + languages );
+
+        List files = resolveFiles ( basedir, languages );
+
+        return resolvePackage ( files );
+    }
+
+    public List getUnfilteredFiles ( List files, String filtered )
+    {
+        ListScanner scanner = new ListScanner ();
+        scanner.setBasedir ( "" );
+
+        scanner.setIncludes ( "**" );
+        scanner.setExcludes ( filtered );
+
+        List result = scanner.scan ( files );
+        getLogger ().debug (
+            "Scanned " + result.size () + " unfiltered files in " + files.size () + " files"
+        );
+
+        return result;
+    }
+
+    public List getUnpackagedFiles ( List files, String packageName )
+    {
+        List unpackagedFiles = new ArrayList ();
+        Iterator filesIterator = files.iterator ();
+        while ( filesIterator.hasNext () )
+        {
+            String file = (String) filesIterator.next ();
+
+            if ( !file.startsWith ( packageName ) )
+            {
+                unpackagedFiles.add ( file );
+            }
+        }
+        getLogger ().debug (
+            "Scanned " + unpackagedFiles.size () + " unpackaged files in " + files.size ()
+            + " files"
+        );
+        return unpackagedFiles;
+    }
+
+    private String getCommonPackage ( String packageName, String templatePackage )
+    {
+        String common = "";
+
+        String difference = StringUtils.difference ( packageName, templatePackage );
+        if ( StringUtils.isNotEmpty ( difference ) )
+        {
+            String temporaryCommon =
+                StringUtils.substring (
+                    templatePackage,
+                    0,
+                    templatePackage.lastIndexOf ( difference )
+                );
+            if ( !difference.startsWith ( "." ) )
+            {
+                common =
+                    StringUtils.substring (
+                        temporaryCommon,
+                        0,
+                        temporaryCommon.lastIndexOf ( "." )
+                    );
+            }
+            else
+            {
+                common = temporaryCommon;
+            }
+        }
+        else
+        {
+            common = packageName;
+        }
+
+        return common;
+    }
+
+    private List resolveFiles ( File basedir, List languages )
+    throws IOException
+    {
+        String[] languagesArray = (String[]) languages.toArray ( new String[languages.size ()] );
+        String[] languagesPathesArray = new String[languagesArray.length];
+        for ( int i = 0; i < languagesArray.length; i++ )
+        {
+            languagesPathesArray[i] = "**/src/**/" + languagesArray[i] + "/**";
+        }
+
+        String excludes = "target";
+        Iterator defaultExcludes = Arrays.asList ( ListScanner.DEFAULTEXCLUDES ).iterator ();
+        while ( defaultExcludes.hasNext () )
+        {
+            excludes += "," + (String) defaultExcludes.next () + "/**";
+        }
+
+        List absoluteFiles =
+            FileUtils.getFiles (
+                basedir,
+                StringUtils.join ( languagesPathesArray, "," ),
+                excludes
+            );
+
+        getLogger ().debug ( "Found " + absoluteFiles.size () + " potential archetype files" );
+
+        List files = new ArrayList ( absoluteFiles.size () );
+
+        Iterator filesIterator = absoluteFiles.iterator ();
+        while ( filesIterator.hasNext () )
+        {
+            File file = (File) filesIterator.next ();
+            String filePath =
+                StringUtils.prechomp (
+                    file.getAbsolutePath (),
+                    basedir.getAbsolutePath () + File.separator
+                );
+
+            String minusSrc = StringUtils.prechomp ( filePath, "src" + File.separator );
+
+            for ( int i = 0; i < languagesArray.length; i++ )
+            {
+                String language = languagesArray[i];
+
+                if ( StringUtils.countMatches (
+                        minusSrc,
+                        File.separator + language + File.separator
+                    )
+                    > 0
+                )
+                {
+                    String minusLanguage =
+                        StringUtils.prechomp ( minusSrc, language + File.separator );
+
+                    files.add ( toUnixPath ( minusLanguage ) );
+                }
+            }
+        }
+
+        getLogger ().debug (
+            "Found " + files.size () + " archetype files for package resolution "
+        );
+
+        return files;
+    }
+
+    private String resolvePackage ( List files )
+    {
+        String packageName = null;
+        Iterator minusLanguageIterator = files.iterator ();
+        while ( minusLanguageIterator.hasNext () )
+        {
+            String minusLanguage = (String) minusLanguageIterator.next ();
+
+            String filePackage;
+            if ( minusLanguage.indexOf ( "/" ) >= 0 )
+            {
+                filePackage =
+                    StringUtils.replace (
+                        minusLanguage.substring ( 0, minusLanguage.lastIndexOf ( "/" ) ),
+                        "/",
+                        "."
+                    );
+            }
+            else
+            {
+                filePackage = "";
+            }
+
+            if ( packageName == null )
+            {
+                packageName = filePackage;
+            }
+            else
+            {
+                packageName = getCommonPackage ( packageName, filePackage );
+            }
+        }
+
+        getLogger ().debug ( "Package resolved to " + packageName );
+
+        return packageName;
+    }
+
+    private String toUnixPath ( String path )
+    {
+        return path.replace ( File.separatorChar, '/' );
+    }
+}

Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypePropertiesManager.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypePropertiesManager.java?rev=570611&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypePropertiesManager.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypePropertiesManager.java Tue Aug 28 19:32:45 2007
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.maven.archetype.common;
+
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.IOUtil;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import java.util.Iterator;
+import java.util.Properties;
+
+/**
+ * @plexus.component
+ */
+public class DefaultArchetypePropertiesManager
+extends AbstractLogEnabled
+implements ArchetypePropertiesManager
+{
+    public void readProperties ( Properties properties, File propertyFile )
+    throws FileNotFoundException, IOException
+    {
+        getLogger ().debug ( "Reading property file " + propertyFile );
+
+        InputStream is = new FileInputStream ( propertyFile );
+
+        try
+        {
+            properties.load ( is );
+
+            getLogger ().debug ( "Read " + properties.size () + " properties" );
+        }
+        finally
+        {
+            IOUtil.close ( is );
+        }
+    }
+
+    public void writeProperties ( Properties properties, File propertyFile )
+    throws IOException
+    {
+        Properties storedProperties = new Properties ();
+        try
+        {
+            readProperties ( storedProperties, propertyFile );
+        }
+        catch ( FileNotFoundException ex )
+        {
+            getLogger ().debug ( "Property file not found. Creating a new one" );
+        }
+
+        getLogger ().debug ( "Adding " + properties.size () + " properties" );
+
+        Iterator propertiesIterator = properties.keySet ().iterator ();
+        while ( propertiesIterator.hasNext () )
+        {
+            String propertyKey = (String) propertiesIterator.next ();
+            storedProperties.setProperty ( propertyKey, properties.getProperty ( propertyKey ) );
+        }
+
+        OutputStream os = new FileOutputStream ( propertyFile );
+
+        try
+        {
+            storedProperties.store ( os, "" );
+
+            getLogger ().debug ( "Stored " + storedProperties.size () + " properties" );
+        }
+        finally
+        {
+            IOUtil.close ( os );
+        }
+    }
+}

Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeRegistryManager.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeRegistryManager.java?rev=570611&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeRegistryManager.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeRegistryManager.java Tue Aug 28 19:32:45 2007
@@ -0,0 +1,314 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.maven.archetype.common;
+
+import org.apache.maven.archetype.registry.ArchetypeRegistry;
+import org.apache.maven.archetype.registry.ArchetypeRepository;
+import org.apache.maven.archetype.registry.io.xpp3.ArchetypeRegistryXpp3Reader;
+import org.apache.maven.archetype.registry.io.xpp3.ArchetypeRegistryXpp3Writer;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @plexus.component
+ */
+public class DefaultArchetypeRegistryManager
+extends AbstractLogEnabled
+implements ArchetypeRegistryManager
+{
+    /**
+     * Used to create ArtifactRepository objects given the urls of the remote repositories.
+     *
+     * @plexus.requirement
+     */
+    private ArtifactRepositoryFactory artifactRepositoryFactory;
+
+    /**
+     * Determines whether the layout is legacy or not.
+     *
+     * @plexus.requirement  roleHint="default"
+     */
+    private ArtifactRepositoryLayout defaultArtifactRepositoryLayout;
+
+    public List getArchetypeGroups ( File archetypeRegistryFile )
+    {
+        try
+        {
+            ArchetypeRegistry registry = readArchetypeRegistry ( archetypeRegistryFile );
+            return registry.getArchetypeGroups ();
+        }
+        catch ( IOException e )
+        {
+            getLogger ().warn ( "Can not read ~/m2/archetype.xml" );
+            return
+                Arrays.asList (
+                    new String[] { "org.apache.maven.archetypes", "org.codehaus.mojo.archetypes" }
+                );
+        }
+        catch ( XmlPullParserException e )
+        {
+            getLogger ().warn ( "Can not read ~/m2/archetype.xml" );
+            return
+                Arrays.asList (
+                    new String[] { "org.apache.maven.archetypes", "org.codehaus.mojo.archetypes" }
+                );
+        }
+    }
+
+    public List getFilteredExtensions (
+        String archetypeFilteredExtentions,
+        File archetypeRegistryFile
+    )
+    throws IOException
+    {
+        List filteredExtensions = new ArrayList ();
+
+        if ( StringUtils.isNotEmpty ( archetypeFilteredExtentions ) )
+        {
+            filteredExtensions.addAll (
+                Arrays.asList ( StringUtils.split ( archetypeFilteredExtentions, "," ) )
+            );
+        }
+
+        try
+        {
+            ArchetypeRegistry registry = readArchetypeRegistry ( archetypeRegistryFile );
+
+            filteredExtensions.addAll ( registry.getFilteredExtensions () );
+        }
+        catch ( IOException e )
+        {
+            getLogger ().warn ( "Can not read ~/m2/archetype.xml" );
+        }
+        catch ( XmlPullParserException e )
+        {
+            getLogger ().warn ( "Can not read ~/m2/archetype.xml" );
+        }
+
+        if ( filteredExtensions.isEmpty () )
+        {
+            filteredExtensions.addAll ( Constants.DEFAULT_FILTERED_EXTENSIONS );
+        }
+
+        return filteredExtensions;
+    }
+
+    public List getLanguages ( String archetypeLanguages, File archetypeRegistryFile )
+    throws IOException
+    {
+        List languages = new ArrayList ();
+
+        if ( StringUtils.isNotEmpty ( archetypeLanguages ) )
+        {
+            languages.addAll ( Arrays.asList ( StringUtils.split ( archetypeLanguages, "," ) ) );
+        }
+
+        try
+        {
+            ArchetypeRegistry registry = readArchetypeRegistry ( archetypeRegistryFile );
+
+            languages.addAll ( registry.getLanguages () );
+        }
+        catch ( IOException e )
+        {
+            getLogger ().warn ( "Can not read ~/m2/archetype.xml" );
+        }
+        catch ( XmlPullParserException e )
+        {
+            getLogger ().warn ( "Can not read ~/m2/archetype.xml" );
+        }
+
+        if ( languages.isEmpty () )
+        {
+            languages.addAll ( Constants.DEFAULT_LANGUAGES );
+        }
+
+        return languages;
+    }
+
+    public ArchetypeRegistry readArchetypeRegistry ( File archetypeRegistryFile )
+    throws IOException, FileNotFoundException, XmlPullParserException
+    {
+        ArchetypeRegistryXpp3Reader reader = new ArchetypeRegistryXpp3Reader ();
+        FileReader fileReader = new FileReader ( archetypeRegistryFile );
+
+        try
+        {
+            return reader.read ( fileReader );
+        }
+        finally
+        {
+            IOUtil.close ( fileReader );
+        }
+    }
+
+    public List getRepositories (
+        List pomRemoteRepositories,
+        String remoteRepositories,
+        File archetypeRegistryFile
+    )
+    throws IOException, XmlPullParserException
+    {
+        List archetypeRemoteRepositories = new ArrayList ( pomRemoteRepositories );
+
+        ArchetypeRegistry registry = readArchetypeRegistry ( archetypeRegistryFile );
+        if ( !registry.getArchetypeRepositories ().isEmpty () )
+        {
+            archetypeRemoteRepositories = new ArrayList ();
+
+            Iterator repositories = registry.getArchetypeRepositories ().iterator ();
+            while ( repositories.hasNext () )
+            {
+                ArchetypeRepository repository = (ArchetypeRepository) repositories.next ();
+
+                archetypeRemoteRepositories.add (
+                    createRepository ( repository.getUrl (), repository.getId () )
+                );
+            }
+        }
+
+        if ( remoteRepositories != null )
+        {
+            archetypeRemoteRepositories = new ArrayList ();
+
+            String[] s = StringUtils.split ( remoteRepositories, "," );
+
+            for ( int i = 0; i < s.length; i++ )
+            {
+                archetypeRemoteRepositories.add ( createRepository ( s[i], "id" + i ) );
+            }
+        }
+
+        return archetypeRemoteRepositories;
+    }
+
+    public void writeArchetypeRegistry (
+        File archetypeRegistryFile,
+        ArchetypeRegistry archetypeRegistry
+    )
+    throws IOException
+    {
+        ArchetypeRegistryXpp3Writer writer = new ArchetypeRegistryXpp3Writer ();
+        FileWriter fileWriter = new FileWriter ( archetypeRegistryFile );
+
+        try
+        {
+            writer.write ( fileWriter, archetypeRegistry );
+        }
+        finally
+        {
+            IOUtil.close ( fileWriter );
+        }
+    }
+
+    /**
+     * Code stealed from MavenArchetypeMojo
+     * (org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha4).
+     */
+    private ArtifactRepository createRepository ( String url, String repositoryId )
+    {
+        // snapshots vs releases
+        // offline = to turning the update policy off
+
+        // TODO: we'll need to allow finer grained creation of repositories but this will do for now
+
+        String updatePolicyFlag = ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS;
+
+        String checksumPolicyFlag = ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN;
+
+        ArtifactRepositoryPolicy snapshotsPolicy =
+            new ArtifactRepositoryPolicy ( true, updatePolicyFlag, checksumPolicyFlag );
+
+        ArtifactRepositoryPolicy releasesPolicy =
+            new ArtifactRepositoryPolicy ( true, updatePolicyFlag, checksumPolicyFlag );
+
+        return
+            artifactRepositoryFactory.createArtifactRepository (
+                repositoryId,
+                url,
+                defaultArtifactRepositoryLayout,
+                snapshotsPolicy,
+                releasesPolicy
+            );
+    }
+
+    public void addGroup(String group, File archetypeRegistryFile)
+    throws IOException, XmlPullParserException
+    {
+        ArchetypeRegistry registry;
+        try
+        {
+            registry = readArchetypeRegistry(archetypeRegistryFile);
+        }
+        catch (FileNotFoundException ex)
+        {
+            registry = getDefaultArchetypeRegistry();
+        }
+
+        if (registry.getArchetypeGroups().contains(group))
+        {
+            getLogger().debug("Group " + group + " already exists");
+        }
+        else
+        {
+            registry.addArchetypeGroup(group.trim());
+            getLogger().info("New group " + group + " added to registry");
+        }
+
+        writeArchetypeRegistry(archetypeRegistryFile, registry);
+    }
+
+    public ArchetypeRegistry getDefaultArchetypeRegistry()
+    {
+        ArchetypeRegistry registry = new ArchetypeRegistry ();
+
+        registry.addArchetypeGroup ( "org.apache.maven.archetypes" );
+        registry.addArchetypeGroup ( "org.codehaus.mojo.archetypes" );
+
+        registry.getLanguages ().addAll ( Constants.DEFAULT_LANGUAGES );
+        registry.getFilteredExtensions ().addAll ( Constants.DEFAULT_FILTERED_EXTENSIONS );
+
+        ArchetypeRepository archetypeRepository = new ArchetypeRepository ();
+        archetypeRepository.setId ( "central" );
+        archetypeRepository.setUrl ( "http://repo1.maven.org/maven2" );
+
+        registry.addArchetypeRepository(archetypeRepository);
+
+        return registry;
+    }
+}



Mime
View raw message