You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2007/08/29 04:43:59 UTC
svn commit: r570618 [5/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...
Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/PathUtils.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/PathUtils.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/PathUtils.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/PathUtils.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,65 @@
+/*
+ * 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.util.StringUtils;
+
+import java.io.File;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author rafale
+ */
+public class PathUtils
+{
+ /**
+ * This method converts all \ or / chars to File.separatorChar.
+ *
+ * @param path
+ *
+ * @return
+ */
+ public static String convertPathForOS ( String path )
+ {
+ path = StringUtils.replace ( path, "/", File.separator );
+ return StringUtils.replace ( path, "\\", File.separator );
+ }
+
+ public static String getDirectory ( String file, int level )
+ {
+ file = convertPathForOS ( file );
+
+ String[] fileAsArray = StringUtils.split ( file, File.separator );
+ List directoryAsArray = new ArrayList ();
+
+ for ( int i = 0; ( i < level ) && ( i < ( fileAsArray.length - 1 ) ); i++ )
+ {
+ directoryAsArray.add ( fileAsArray[i] );
+ }
+
+ return
+ StringUtils.join (
+ directoryAsArray.toArray ( new String[directoryAsArray.size ()] ),
+ File.separator
+ );
+ }
+}
Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/PomManager.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/PomManager.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/PomManager.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/common/PomManager.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,65 @@
+/*
+ * 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.exception.InvalidPackaging;
+import org.apache.maven.model.Model;
+
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import org.dom4j.DocumentException;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+public interface PomManager
+{
+ String ROLE = PomManager.class.getName ();
+
+ /**
+ */
+ void addModule ( File basedirPom, String artifactId )
+ throws FileNotFoundException,
+ IOException,
+ XmlPullParserException,
+ DocumentException,
+ InvalidPackaging;
+
+ /**
+ */
+ void addParent ( File pom, File basedirPom )
+ throws FileNotFoundException, IOException, XmlPullParserException;
+
+ /**
+ */
+ void mergePoms ( File pom, File temporaryPom )
+ throws FileNotFoundException, IOException, XmlPullParserException;
+
+ /**
+ */
+ Model readPom ( File pomFile )
+ throws FileNotFoundException, IOException, XmlPullParserException;
+
+ /**
+ */
+ void writePom ( Model model, File pomFile )
+ throws IOException;
+}
Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeGenerationConfigurationFailure.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeGenerationConfigurationFailure.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeGenerationConfigurationFailure.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeGenerationConfigurationFailure.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,42 @@
+/*
+ * 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.exception;
+
+public class ArchetypeGenerationConfigurationFailure
+extends Exception
+{
+ public ArchetypeGenerationConfigurationFailure ()
+ { }
+
+ public ArchetypeGenerationConfigurationFailure ( String msg )
+ {
+ super ( msg );
+ }
+
+ public ArchetypeGenerationConfigurationFailure ( Throwable cause )
+ {
+ super ( cause );
+ }
+
+ public ArchetypeGenerationConfigurationFailure ( String msg, Throwable cause )
+ {
+ super ( msg, cause );
+ }
+}
Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeGenerationFailure.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeGenerationFailure.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeGenerationFailure.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeGenerationFailure.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,42 @@
+/*
+ * 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.exception;
+
+public class ArchetypeGenerationFailure
+extends Exception
+{
+ public ArchetypeGenerationFailure ()
+ { }
+
+ public ArchetypeGenerationFailure ( String msg )
+ {
+ super ( msg );
+ }
+
+ public ArchetypeGenerationFailure ( Throwable cause )
+ {
+ super ( cause );
+ }
+
+ public ArchetypeGenerationFailure ( String msg, Throwable cause )
+ {
+ super ( msg, cause );
+ }
+}
Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeNotConfigured.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeNotConfigured.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeNotConfigured.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeNotConfigured.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,42 @@
+/*
+ * 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.exception;
+
+public class ArchetypeNotConfigured
+extends Exception
+{
+ public ArchetypeNotConfigured ()
+ { }
+
+ public ArchetypeNotConfigured ( String msg )
+ {
+ super ( msg );
+ }
+
+ public ArchetypeNotConfigured ( Throwable cause )
+ {
+ super ( cause );
+ }
+
+ public ArchetypeNotConfigured ( String msg, Throwable cause )
+ {
+ super ( msg, cause );
+ }
+}
Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeNotDefined.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeNotDefined.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeNotDefined.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeNotDefined.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,42 @@
+/*
+ * 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.exception;
+
+public class ArchetypeNotDefined
+extends Exception
+{
+ public ArchetypeNotDefined ()
+ { }
+
+ public ArchetypeNotDefined ( String msg )
+ {
+ super ( msg );
+ }
+
+ public ArchetypeNotDefined ( Throwable cause )
+ {
+ super ( cause );
+ }
+
+ public ArchetypeNotDefined ( String msg, Throwable cause )
+ {
+ super ( msg, cause );
+ }
+}
Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeSelectionFailure.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeSelectionFailure.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeSelectionFailure.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeSelectionFailure.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,42 @@
+/*
+ * 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.exception;
+
+public class ArchetypeSelectionFailure
+extends Exception
+{
+ public ArchetypeSelectionFailure ()
+ { }
+
+ public ArchetypeSelectionFailure ( String msg )
+ {
+ super ( msg );
+ }
+
+ public ArchetypeSelectionFailure ( Throwable cause )
+ {
+ super ( cause );
+ }
+
+ public ArchetypeSelectionFailure ( String msg, Throwable cause )
+ {
+ super ( msg, cause );
+ }
+}
Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/InvalidPackaging.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/InvalidPackaging.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/InvalidPackaging.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/InvalidPackaging.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,42 @@
+/*
+ * 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.exception;
+
+public class InvalidPackaging
+extends Exception
+{
+ public InvalidPackaging ()
+ { }
+
+ public InvalidPackaging ( String msg )
+ {
+ super ( msg );
+ }
+
+ public InvalidPackaging ( Throwable cause )
+ {
+ super ( cause );
+ }
+
+ public InvalidPackaging ( String msg, Throwable cause )
+ {
+ super ( msg, cause );
+ }
+}
Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/OutputFileExists.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/OutputFileExists.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/OutputFileExists.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/OutputFileExists.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,42 @@
+/*
+ * 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.exception;
+
+public class OutputFileExists
+extends Exception
+{
+ public OutputFileExists ()
+ { }
+
+ public OutputFileExists ( String msg )
+ {
+ super ( msg );
+ }
+
+ public OutputFileExists ( Throwable cause )
+ {
+ super ( cause );
+ }
+
+ public OutputFileExists ( String msg, Throwable cause )
+ {
+ super ( msg, cause );
+ }
+}
Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/PomFileExists.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/PomFileExists.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/PomFileExists.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/PomFileExists.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,42 @@
+/*
+ * 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.exception;
+
+public class PomFileExists
+extends Exception
+{
+ public PomFileExists ()
+ { }
+
+ public PomFileExists ( String msg )
+ {
+ super ( msg );
+ }
+
+ public PomFileExists ( Throwable cause )
+ {
+ super ( cause );
+ }
+
+ public PomFileExists ( String msg, Throwable cause )
+ {
+ super ( msg, cause );
+ }
+}
Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ProjectDirectoryExists.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ProjectDirectoryExists.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ProjectDirectoryExists.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/ProjectDirectoryExists.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,42 @@
+/*
+ * 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.exception;
+
+public class ProjectDirectoryExists
+extends Exception
+{
+ public ProjectDirectoryExists ()
+ { }
+
+ public ProjectDirectoryExists ( String msg )
+ {
+ super ( msg );
+ }
+
+ public ProjectDirectoryExists ( Throwable cause )
+ {
+ super ( cause );
+ }
+
+ public ProjectDirectoryExists ( String msg, Throwable cause )
+ {
+ super ( msg, cause );
+ }
+}
Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/TemplateCreationException.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/TemplateCreationException.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/TemplateCreationException.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/TemplateCreationException.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,42 @@
+/*
+ * 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.exception;
+
+public class TemplateCreationException
+extends Exception
+{
+ public TemplateCreationException ()
+ { }
+
+ public TemplateCreationException ( String msg )
+ {
+ super ( msg );
+ }
+
+ public TemplateCreationException ( Throwable cause )
+ {
+ super ( cause );
+ }
+
+ public TemplateCreationException ( String msg, Throwable cause )
+ {
+ super ( msg, cause );
+ }
+}
Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/UnknownArchetype.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/UnknownArchetype.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/UnknownArchetype.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/UnknownArchetype.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,42 @@
+/*
+ * 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.exception;
+
+public class UnknownArchetype
+extends Exception
+{
+ public UnknownArchetype ()
+ { }
+
+ public UnknownArchetype ( String msg )
+ {
+ super ( msg );
+ }
+
+ public UnknownArchetype ( Throwable cause )
+ {
+ super ( cause );
+ }
+
+ public UnknownArchetype ( String msg, Throwable cause )
+ {
+ super ( msg, cause );
+ }
+}
Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/UnknownGroup.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/UnknownGroup.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/UnknownGroup.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/java/org/apache/maven/archetype/exception/UnknownGroup.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,42 @@
+/*
+ * 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.exception;
+
+public class UnknownGroup
+extends Exception
+{
+ public UnknownGroup ()
+ { }
+
+ public UnknownGroup ( String msg )
+ {
+ super ( msg );
+ }
+
+ public UnknownGroup ( Throwable cause )
+ {
+ super ( cause );
+ }
+
+ public UnknownGroup ( String msg, Throwable cause )
+ {
+ super ( msg, cause );
+ }
+}
Added: maven/sandbox/trunk/archetypeng/archetype-common/src/main/mdo/archetype-common.mdo
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/main/mdo/archetype-common.mdo?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/main/mdo/archetype-common.mdo (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/main/mdo/archetype-common.mdo Tue Aug 28 19:43:33 2007
@@ -0,0 +1,483 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<model>
+ <id>archetype-common</id>
+ <name>ArchetypeCommon</name>
+
+ <defaults>
+ <default>
+ <key>package</key>
+ <value>org.apache.maven.archetype.common</value>
+ </default>
+ </defaults>
+
+ <classes>
+
+ <class rootElement="true">
+ <name>Archetype</name>
+ <fields>
+ <field>
+ <name>GroupId</name>
+ <type>String</type>
+ </field>
+ <field>
+ <name>ArtifactId</name>
+ <type>String</type>
+ </field>
+ <field>
+ <name>Version</name>
+ <type>String</type>
+ </field>
+ <field>
+ <name>Name</name>
+ <type>String</type>
+ </field>
+ <field>
+ <name>Prefix</name>
+ <type>String</type>
+ </field>
+ </fields>
+ <codeSegments>
+ <codeSegment>
+ <code><![CDATA[
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+
+ if ( !( o instanceof Archetype ) )
+ {
+ return false;
+ }
+
+ Archetype a = (Archetype) o;
+
+ if ( !a.getArtifactId().equals( getArtifactId() ) )
+ {
+ return false;
+ }
+ else if ( !a.getGroupId().equals( getGroupId() ) )
+ {
+ return false;
+ }
+ /*
+ else if ( !a.getPrefix().equals( getPrefix() ) )
+ {
+ return false;
+ }
+ else if ( !a.getName().equals( getName() ) )
+ {
+ return false;
+ }*/
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result = 17;
+ result = 37 * result + getArtifactId().hashCode();
+ result = 37 * result + getGroupId().hashCode();
+ return result;
+ }
+ ]]></code>
+ </codeSegment>
+ </codeSegments>
+ </class>
+
+ <class>
+ <name>ArchetypeDefinition</name>
+ <fields>
+ <field>
+ <name>GroupId</name>
+ <type>String</type>
+ </field>
+ <field>
+ <name>ArtifactId</name>
+ <type>String</type>
+ </field>
+ <field>
+ <name>Version</name>
+ <type>String</type>
+ </field>
+ <field>
+ <name>Name</name>
+ <type>String</type>
+ </field>
+ </fields>
+ <codeSegments>
+ <codeSegment>
+ <code><![CDATA[
+ public void reset ()
+ {
+ setGroupId ( null );
+ setArtifactId ( null );
+ setVersion ( null );
+ }
+
+ public java.util.Properties toProperties ()
+ {
+ java.util.Properties properties = new java.util.Properties ();
+ properties.setProperty (
+ Constants.ARCHETYPE_GROUP_ID,
+ (org.codehaus.plexus.util.StringUtils.isNotEmpty( getGroupId () ) ? getGroupId () : "" )
+ );
+ properties.setProperty (
+ Constants.ARCHETYPE_ARTIFACT_ID,
+ (org.codehaus.plexus.util.StringUtils.isNotEmpty( getArtifactId () ) ? getArtifactId () : "" )
+ );
+ properties.setProperty (
+ Constants.ARCHETYPE_VERSION,
+ (org.codehaus.plexus.util.StringUtils.isNotEmpty( getVersion () ) ? getVersion () : "" )
+ );
+ return properties;
+ }
+
+ public boolean isArtifactDefined ()
+ {
+ return org.codehaus.plexus.util.StringUtils.isNotEmpty( getArtifactId () );
+ }
+
+ public boolean isDefined ()
+ {
+ return isPartiallyDefined () && isVersionDefined ();
+ }
+
+ public boolean isGroupDefined ()
+ {
+ return org.codehaus.plexus.util.StringUtils.isNotEmpty( getGroupId () );
+ }
+
+ public boolean isPartiallyDefined ()
+ {
+ return isGroupDefined () && isArtifactDefined ();
+ }
+
+ public boolean isVersionDefined ()
+ {
+ return org.codehaus.plexus.util.StringUtils.isNotEmpty( getVersion () );
+ }
+ ]]></code>
+ </codeSegment>
+ </codeSegments>
+ </class>
+
+ <class>
+ <name>ArchetypeConfiguration</name>
+ <fields>
+ <field>
+ <name>GroupId</name>
+ <type>String</type>
+ </field>
+ <field>
+ <name>ArtifactId</name>
+ <type>String</type>
+ </field>
+ <field>
+ <name>Version</name>
+ <type>String</type>
+ </field>
+ <field>
+ <name>Name</name>
+ <type>String</type>
+ </field>
+ <field>
+ <name>RequiredProperties</name>
+ <association>
+ <type>String</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ </fields>
+ <codeSegments>
+ <codeSegment>
+ <code><![CDATA[
+ public void reset ()
+ {
+ properties.clear ();
+ }
+
+ private java.util.Properties properties = new java.util.Properties ();
+
+ public void setProperty ( String requiredProperty, String propertyValue )
+ {
+ properties.setProperty ( requiredProperty, propertyValue );
+ }
+
+ public String getProperty (String property)
+ {
+ return properties.getProperty ( property, null );
+ }
+
+ public java.util.Properties getProperties ()
+ {
+ return properties;
+ }
+
+ public java.util.Properties toProperties ()
+ {
+ java.util.Properties result = new java.util.Properties ();
+ result.putAll ( properties );
+ result.setProperty (
+ Constants.ARCHETYPE_GROUP_ID,
+ (org.codehaus.plexus.util.StringUtils.isNotEmpty( getGroupId () ) ? getGroupId () : "" )
+ );
+ result.setProperty (
+ Constants.ARCHETYPE_ARTIFACT_ID,
+ (org.codehaus.plexus.util.StringUtils.isNotEmpty( getArtifactId () ) ? getArtifactId () : "" )
+ );
+ result.setProperty (
+ Constants.ARCHETYPE_VERSION,
+ (org.codehaus.plexus.util.StringUtils.isNotEmpty( getVersion () ) ? getVersion () : "" )
+ );
+ return result;
+ }
+
+ public boolean isConfigured ()
+ {
+ boolean configured = true;
+
+ java.util.Iterator requiredProperties = getRequiredProperties().iterator();
+ while ( configured && requiredProperties.hasNext () )
+ {
+ String requiredProperty = (String) requiredProperties.next ();
+
+ configured = configured &&
+ org.codehaus.plexus.util.StringUtils.isNotEmpty(
+ properties.getProperty ( requiredProperty )
+ );
+ }
+
+ return configured;
+ }
+
+ public boolean isConfigured ( String requiredProperties )
+ {
+ return org.codehaus.plexus.util.StringUtils.isNotEmpty (
+ properties.getProperty ( requiredProperties )
+ );
+ }
+
+ private java.util.Properties defaultProperties = new java.util.Properties ();
+
+ public void setDefaultProperty ( String requiredProperty, String propertyValue )
+ {
+ defaultProperties.setProperty ( requiredProperty, propertyValue );
+ }
+
+ public String getDefaultValue (String requiredProperty)
+ {
+ return defaultProperties.getProperty ( requiredProperty, null );
+ }
+
+ public java.util.Properties getDefaultValues ()
+ {
+ return defaultProperties;
+ }
+ ]]></code>
+ </codeSegment>
+ </codeSegments>
+ </class>
+ <!--
+ <class>
+ <name>Template</name>
+ <fields>
+ <field>
+ <name>Directory</name>
+ <type>String</type>
+ </field>
+ <field>
+ <name>InnerPath</name>
+ <type>String</type>
+ </field>
+ <field>
+ <name>Language</name>
+ <type>String</type>
+ </field>
+ <field>
+ <name>Main</name>
+ <type>boolean</type>
+ </field>
+ <field>
+ <name>Pom</name>
+ <type>boolean</type>
+ </field>
+ <field>
+ <name>Resource</name>
+ <type>boolean</type>
+ </field>
+ <field>
+ <name>SiteResource</name>
+ <type>boolean</type>
+ </field>
+ <field>
+ <name>Source</name>
+ <type>boolean</type>
+ </field>
+ <field>
+ <name>TemplateName</name>
+ <type>String</type>
+ </field>
+ <field>
+ <name>TemplatePath</name>
+ <type>String</type>
+ </field>
+ <field>
+ <name>Test</name>
+ <type>boolean</type>
+ </field>
+ </fields>
+ <codeSegments>
+ <codeSegment>
+ <code><![CDATA[
+ public Template ( String relativePath )
+ throws org.codehaus.mojo.archetypeng.exception.TemplateCreationException
+ {
+ if ( relativePath.equals ( Constants.ARCHETYPE_POM ) )
+ {
+ setTemplatePath ( relativePath );
+ setPom ( true );
+ }
+ else
+ {
+ setTemplatePath ( relativePath );
+
+ String srcLevel =
+ org.codehaus.plexus.util.StringUtils.prechomp (
+ relativePath,
+ Constants.SRC + "/"
+ );
+
+ String firstLevel =
+ org.codehaus.plexus.util.StringUtils.getPrechomp (
+ srcLevel,
+ "/"
+ ).replace (
+ "/",
+ ""
+ );
+ String afterFirstLevel = org.codehaus.plexus.util.StringUtils.prechomp (
+ srcLevel,
+ "/"
+ );
+ String secondLevel =
+ org.codehaus.plexus.util.StringUtils.getPrechomp (
+ afterFirstLevel,
+ "/"
+ ).replace (
+ "/",
+ ""
+ );
+ String aftersecondLevel = org.codehaus.plexus.util.StringUtils.prechomp (
+ afterFirstLevel,
+ "/"
+ );
+ String afterLevel;
+
+ if ( Constants.MAIN.equals ( firstLevel ) )
+ {
+ setMain ( true );
+ }
+ else if ( Constants.TEST.equals ( firstLevel ) )
+ {
+ setTest ( true );
+ }
+ else if ( Constants.SITE.equals ( firstLevel ) )
+ {
+ setSiteResource ( true );
+ }
+ else
+ {
+ throw new org.codehaus.mojo.archetypeng.exception.TemplateCreationException (
+ "Unknown directory " + firstLevel
+ );
+ }
+
+ if ( isMain () || isTest () )
+ {
+ if ( Constants.LANGUAGES.contains ( secondLevel ) )
+ {
+ setSource ( true );
+ setLanguage ( secondLevel );
+ }
+ else
+ {
+ setResource ( true );
+ setDirectory ( secondLevel );
+ }
+ afterLevel = aftersecondLevel;
+ }
+ else
+ { // isSiteResource
+ afterLevel = afterFirstLevel;
+ }
+
+ if ( org.codehaus.plexus.util.StringUtils.countMatches ( afterLevel, "/" ) > 0 )
+ {
+ setInnerPath (
+ org.codehaus.plexus.util.StringUtils.chomp ( afterLevel, "/" )
+ );
+ setTemplateName (
+ org.codehaus.plexus.util.StringUtils.getChomp (
+ afterLevel,
+ "/"
+ ).replace (
+ "/",
+ ""
+ )
+ );
+ }
+ else
+ {
+ setInnerPath ( "" );
+ setTemplateName ( afterLevel );
+ }
+ } // end if
+ }
+
+ public String toString ()
+ {
+ return
+ ( isPom ()
+ ? "POM"
+ : ( isMain ()
+ ? ( "MAIN"
+ + ( isSource () ? ( "-SOURCE(" + getLanguage () + ")" )
+ : ( "-RESOURCE(" + getDirectory () + ")" ) )
+ + ( "".equals ( getInnerPath () ) ? "" : ( "-" + getInnerPath () ) )
+ + "-" + getTemplateName () )
+ : ( isTest ()
+ ? ( "TEST"
+ + ( isSource () ? ( "-SOURCE(" + getLanguage () + ")" )
+ : ( "-RESOURCE(" + getDirectory () + ")" ) )
+ + ( "".equals ( getInnerPath () ) ? "" : ( "-" + getInnerPath () ) )
+ + "-" + getTemplateName () )
+ : ( "SITE"
+ + ( "".equals ( getInnerPath () ) ? "" : ( "-" + getInnerPath () ) )
+ + "-" + getTemplateName () ) ) ) );
+ }
+ ]]></code>
+ </codeSegment>
+ </codeSegments>
+ </class>
+-->
+ </classes>
+</model>
Added: maven/sandbox/trunk/archetypeng/archetype-common/src/test/java/org/apache/maven/archetype/TestListScanner.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-common/src/test/java/org/apache/maven/archetype/TestListScanner.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-common/src/test/java/org/apache/maven/archetype/TestListScanner.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-common/src/test/java/org/apache/maven/archetype/TestListScanner.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,92 @@
+/*
+ * 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;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.archetype.common.ListScanner;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
+ */
+public class TestListScanner
+extends TestCase
+{
+ public void testUnixPaths ()
+ {
+ List archetypeResources = new ArrayList ();
+
+ archetypeResources.add ( "pom.xml" );
+ archetypeResources.add ( "App.java" );
+ archetypeResources.add ( "src/main/c/App.c" );
+ archetypeResources.add ( "src/main/java/App.java" );
+ archetypeResources.add ( "src/main/java/inner/package/App2.java" );
+ archetypeResources.add ( "src/main/mdo/App.mdo" );
+ archetypeResources.add ( "src/main/resources/App.properties" );
+ archetypeResources.add ( "src/main/resources/inner/dir/App2.properties" );
+ archetypeResources.add ( "src/test/c/AppTest.c" );
+ archetypeResources.add ( "src/test/java/AppTest.java" );
+ archetypeResources.add ( "src/test/mdo/AppTest.mdo" );
+ archetypeResources.add ( "src/test/resources/AppTest.properties" );
+
+ ListScanner scanner = new ListScanner ();
+ scanner.setBasedir ( "src/main/java" );
+ scanner.setIncludes ( "**/*.java" );
+ scanner.setCaseSensitive ( true );
+
+ List result = scanner.scan ( archetypeResources );
+
+ assertEquals ( 2, result.size () );
+ assertTrue ( result.contains ( "src/main/java/App.java" ) );
+ assertTrue ( result.contains ( "src/main/java/inner/package/App2.java" ) );
+ }
+
+ public void testWindowsPaths ()
+ {
+ List archetypeResources = new ArrayList ();
+
+ archetypeResources.add ( "pom.xml" );
+ archetypeResources.add ( "App.java" );
+ archetypeResources.add ( "src\\main\\c\\App.c" );
+ archetypeResources.add ( "src\\main\\java\\App.java" );
+ archetypeResources.add ( "src\\main\\java\\inner\\package\\App2.java" );
+ archetypeResources.add ( "src\\main\\mdo\\App.mdo" );
+ archetypeResources.add ( "src\\main\\resources\\App.properties" );
+ archetypeResources.add ( "src\\main\\resources\\inner\\dir\\App2.properties" );
+ archetypeResources.add ( "src\\test\\c\\AppTest.c" );
+ archetypeResources.add ( "src\\test\\java\\AppTest.java" );
+ archetypeResources.add ( "src\\test\\mdo\\AppTest.mdo" );
+ archetypeResources.add ( "src\\test\\resources\\AppTest.properties" );
+
+ ListScanner scanner = new ListScanner ();
+ scanner.setBasedir ( "src\\main\\java" );
+ scanner.setIncludes ( "**\\*.java" );
+ scanner.setCaseSensitive ( true );
+
+ List result = scanner.scan ( archetypeResources );
+
+ assertEquals ( 2, result.size () );
+ assertTrue ( result.contains ( "src\\main\\java\\App.java" ) );
+ assertTrue ( result.contains ( "src\\main\\java\\inner\\package\\App2.java" ) );
+ }
+}
Added: maven/sandbox/trunk/archetypeng/archetype-creator/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-creator/pom.xml?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-creator/pom.xml (added)
+++ maven/sandbox/trunk/archetypeng/archetype-creator/pom.xml Tue Aug 28 19:43:33 2007
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.archetype</groupId>
+ <artifactId>maven-archetype</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>archetype-creator</artifactId>
+
+ <name>Maven ArchetypeNG Creator</name>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.archetype</groupId>
+ <artifactId>archetype-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.archetype</groupId>
+ <artifactId>archetype-descriptor</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-plugin-testing-harness</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-interactivity-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-model</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact-manager</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Added: maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/ArchetypeCreationConfigurator.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/ArchetypeCreationConfigurator.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/ArchetypeCreationConfigurator.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/ArchetypeCreationConfigurator.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.creator;
+
+import org.apache.maven.archetype.exception.ArchetypeNotConfigured;
+import org.apache.maven.archetype.exception.ArchetypeNotDefined;
+import org.apache.maven.archetype.exception.TemplateCreationException;
+import org.apache.maven.project.MavenProject;
+
+import org.codehaus.plexus.components.interactivity.PrompterException;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import java.util.List;
+import java.util.Properties;
+
+public interface ArchetypeCreationConfigurator
+{
+ String ROLE = ArchetypeCreationConfigurator.class.getName ();
+
+ void configureArchetypeCreation (
+ MavenProject project,
+ Boolean interactiveMode,
+ Properties commandLineProperties,
+ File propertyFile,
+ List languages
+ )
+ throws FileNotFoundException,
+ IOException,
+ ArchetypeNotDefined,
+ ArchetypeNotConfigured,
+ PrompterException,
+ TemplateCreationException;
+}
Added: maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/ArchetypeCreationQueryer.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/ArchetypeCreationQueryer.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/ArchetypeCreationQueryer.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/ArchetypeCreationQueryer.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,84 @@
+/*
+ * 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.creator;
+
+import org.apache.maven.archetype.common.ArchetypeConfiguration;
+
+import org.codehaus.plexus.components.interactivity.PrompterException;
+
+public interface ArchetypeCreationQueryer
+{
+ String ROLE = ArchetypeCreationQueryer.class.getName ();
+
+ /**
+ */
+ String getArchetypeArtifactId ( String defaultValue )
+ throws PrompterException;
+
+ /**
+ */
+ String getArchetypeGroupId ( String defaultValue )
+ throws PrompterException;
+
+ /**
+ */
+ String getArchetypeVersion ( String defaultValue )
+ throws PrompterException;
+
+ /**
+ */
+ String getArtifactId ( String defaultValue )
+ throws PrompterException;
+
+ /**
+ */
+ boolean askAddAnotherProperty ()
+ throws PrompterException;
+
+ /**
+ */
+ String askNewPropertyKey ()
+ throws PrompterException;
+
+ /**
+ */
+ String askReplacementValue ( String propertyKey, String defaultValue )
+ throws PrompterException;
+
+ /**
+ */
+ boolean confirmConfiguration ( ArchetypeConfiguration archetypeConfiguration )
+ throws PrompterException;
+
+ /**
+ */
+ String getGroupId ( String defaultValue )
+ throws PrompterException;
+
+ /**
+ */
+ String getPackage ( String defaultValue )
+ throws PrompterException;
+
+ /**
+ */
+ String getVersion ( String defaultValue )
+ throws PrompterException;
+}
Added: maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/ArchetypeCreator.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/ArchetypeCreator.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/ArchetypeCreator.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/ArchetypeCreator.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,52 @@
+/*
+ * 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.creator;
+
+import org.apache.maven.archetype.exception.ArchetypeNotConfigured;
+import org.apache.maven.archetype.exception.ArchetypeNotDefined;
+import org.apache.maven.archetype.exception.TemplateCreationException;
+import org.apache.maven.project.MavenProject;
+
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+
+import java.util.List;
+
+public interface ArchetypeCreator
+{
+ String ROLE = ArchetypeCreator.class.getName ();
+
+ void createArchetype (
+ MavenProject project,
+ File propertyFile,
+ List languages,
+ List filtereds,
+ String defaultEncoding,
+ boolean ignoreReplica,
+ File archetypeRegistryFile
+ )
+ throws IOException,
+ ArchetypeNotDefined,
+ ArchetypeNotConfigured,
+ TemplateCreationException,
+ XmlPullParserException;
+}
Added: maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/DefaultArchetypeCreationConfigurator.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/DefaultArchetypeCreationConfigurator.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/DefaultArchetypeCreationConfigurator.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/DefaultArchetypeCreationConfigurator.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,371 @@
+/*
+ * 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.creator;
+
+import org.apache.maven.archetype.common.ArchetypeConfiguration;
+import org.apache.maven.archetype.common.ArchetypeDefinition;
+import org.apache.maven.archetype.common.ArchetypeFactory;
+import org.apache.maven.archetype.common.ArchetypeFilesResolver;
+import org.apache.maven.archetype.common.ArchetypePropertiesManager;
+import org.apache.maven.archetype.common.Constants;
+import org.apache.maven.archetype.exception.ArchetypeNotConfigured;
+import org.apache.maven.archetype.exception.ArchetypeNotDefined;
+import org.apache.maven.archetype.exception.TemplateCreationException;
+import org.apache.maven.project.MavenProject;
+
+import org.codehaus.plexus.components.interactivity.PrompterException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * @plexus.component
+ */
+public class DefaultArchetypeCreationConfigurator
+extends AbstractLogEnabled
+implements ArchetypeCreationConfigurator
+{
+ /**
+ * @plexus.requirement
+ */
+ private ArchetypeCreationQueryer archetypeCreationQueryer;
+
+ /**
+ * @plexus.requirement
+ */
+ private ArchetypeFactory archetypeFactory;
+
+ /**
+ * @plexus.requirement
+ */
+ private ArchetypeFilesResolver archetypeFilesResolver;
+
+ /**
+ * @plexus.requirement
+ */
+ private ArchetypePropertiesManager archetypePropertiesManager;
+
+ public void configureArchetypeCreation (
+ MavenProject project,
+ Boolean interactiveMode,
+ Properties commandLineProperties,
+ File propertyFile,
+ List languages
+ )
+ throws FileNotFoundException,
+ IOException,
+ ArchetypeNotDefined,
+ ArchetypeNotConfigured,
+ PrompterException,
+ TemplateCreationException
+ {
+ Properties properties =
+ initialiseArchetypeProperties ( commandLineProperties, propertyFile );
+
+ ArchetypeDefinition archetypeDefinition =
+ archetypeFactory.createArchetypeDefinition ( properties );
+
+ if ( !archetypeDefinition.isDefined () )
+ {
+ archetypeDefinition = defineDefaultArchetype ( project, properties );
+ }
+
+ ArchetypeConfiguration archetypeConfiguration =
+ archetypeFactory.createArchetypeConfiguration (
+ project,
+ archetypeDefinition,
+ properties
+ );
+
+ String resolvedPackage =
+ archetypeFilesResolver.resolvePackage ( project.getBasedir (), languages );
+
+ if ( !archetypeConfiguration.isConfigured () )
+ {
+ archetypeConfiguration =
+ defineDefaultConfiguration (
+ project,
+ archetypeDefinition,
+ resolvedPackage,
+ properties
+ );
+ }
+
+ if ( interactiveMode.booleanValue () )
+ {
+ getLogger ().debug ( "Entering interactive mode" );
+
+ boolean confirmed = false;
+ while ( !confirmed )
+ {
+ if ( !archetypeDefinition.isDefined () )
+ {
+ getLogger ().debug ( "Archetype is not defined" );
+ if ( !archetypeDefinition.isGroupDefined () )
+ {
+ getLogger ().debug ( "Asking for archetype's groupId" );
+ archetypeDefinition.setGroupId (
+ archetypeCreationQueryer.getArchetypeGroupId ( project.getGroupId () )
+ );
+ }
+ if ( !archetypeDefinition.isArtifactDefined () )
+ {
+ getLogger ().debug ( "Asking for archetype's artifactId" );
+ archetypeDefinition.setArtifactId (
+ archetypeCreationQueryer.getArchetypeArtifactId (
+ project.getArtifactId () + Constants.ARCHETYPE_SUFFIX
+ )
+ );
+ }
+ if ( !archetypeDefinition.isVersionDefined () )
+ {
+ getLogger ().debug ( "Asking for archetype's version" );
+ archetypeDefinition.setVersion (
+ archetypeCreationQueryer.getArchetypeVersion ( project.getVersion () )
+ );
+ }
+
+ archetypeFactory.updateArchetypeConfiguration (
+ archetypeConfiguration,
+ archetypeDefinition
+ );
+ }
+
+ if ( !archetypeConfiguration.isConfigured () )
+ {
+ getLogger ().debug ( "Archetype is not configured" );
+ if ( !archetypeConfiguration.isConfigured ( Constants.GROUP_ID ) )
+ {
+ getLogger ().debug ( "Asking for project's groupId" );
+ archetypeConfiguration.setProperty (
+ Constants.GROUP_ID,
+ archetypeCreationQueryer.getGroupId (
+ archetypeConfiguration.getDefaultValue ( Constants.GROUP_ID )
+ )
+ );
+ }
+ if ( !archetypeConfiguration.isConfigured ( Constants.ARTIFACT_ID ) )
+ {
+ getLogger ().debug ( "Asking for project's artifactId" );
+ archetypeConfiguration.setProperty (
+ Constants.ARTIFACT_ID,
+ archetypeCreationQueryer.getArtifactId (
+ archetypeConfiguration.getDefaultValue ( Constants.ARTIFACT_ID )
+ )
+ );
+ }
+ if ( !archetypeConfiguration.isConfigured ( Constants.VERSION ) )
+ {
+ getLogger ().debug ( "Asking for project's version" );
+ archetypeConfiguration.setProperty (
+ Constants.VERSION,
+ archetypeCreationQueryer.getVersion (
+ archetypeConfiguration.getDefaultValue ( Constants.VERSION )
+ )
+ );
+ }
+ if ( !archetypeConfiguration.isConfigured ( Constants.PACKAGE ) )
+ {
+ getLogger ().debug ( "Asking for project's package" );
+ archetypeConfiguration.setProperty (
+ Constants.PACKAGE,
+ archetypeCreationQueryer.getPackage (
+ StringUtils.isEmpty ( resolvedPackage )
+ ? archetypeConfiguration.getDefaultValue ( Constants.PACKAGE )
+ : resolvedPackage
+ )
+ );
+ }
+ } // end if
+
+ boolean stopAddingProperties = false;
+ while ( !stopAddingProperties )
+ {
+ getLogger ().debug ( "Asking for another required property" );
+ stopAddingProperties = !archetypeCreationQueryer.askAddAnotherProperty ();
+
+ if ( !stopAddingProperties )
+ {
+ getLogger ().debug ( "Asking for required property key" );
+
+ String propertyKey = archetypeCreationQueryer.askNewPropertyKey ();
+ getLogger ().debug ( "Asking for required property value" );
+
+ String replacementValue =
+ archetypeCreationQueryer.askReplacementValue (
+ propertyKey,
+ archetypeConfiguration.getDefaultValue ( propertyKey )
+ );
+ archetypeConfiguration.setDefaultProperty ( propertyKey, replacementValue );
+ archetypeConfiguration.setProperty ( propertyKey, replacementValue );
+ }
+ }
+
+ getLogger ().debug ( "Asking for configuration confirmation" );
+ if ( archetypeCreationQueryer.confirmConfiguration ( archetypeConfiguration ) )
+ {
+ confirmed = true;
+ }
+ else
+ {
+ getLogger ().debug ( "Reseting archetype's definition and configuration" );
+ archetypeConfiguration.reset ();
+ archetypeDefinition.reset ();
+ }
+ } // end while
+ }
+ else
+ {
+ getLogger ().debug ( "Entering batch mode" );
+ if ( !archetypeDefinition.isDefined () )
+ {
+ throw new ArchetypeNotDefined ( "The archetype is not defined" );
+ }
+ else if ( !archetypeConfiguration.isConfigured () )
+ {
+ throw new ArchetypeNotConfigured ( "The archetype is not configured" );
+ }
+ } // end if
+
+ archetypePropertiesManager.writeProperties (
+ archetypeConfiguration.toProperties (),
+ propertyFile
+ );
+ }
+
+ private ArchetypeDefinition defineDefaultArchetype (
+ MavenProject project,
+ Properties properties
+ )
+ {
+ if ( StringUtils.isEmpty ( properties.getProperty ( Constants.ARCHETYPE_GROUP_ID ) ) )
+ {
+ getLogger ().info ( "Setting default archetype's groupId: " + project.getGroupId () );
+ properties.setProperty ( Constants.ARCHETYPE_GROUP_ID, project.getGroupId () );
+ }
+ if ( StringUtils.isEmpty ( properties.getProperty ( Constants.ARCHETYPE_ARTIFACT_ID ) ) )
+ {
+ getLogger ().info (
+ "Setting default archetype's artifactId: " + project.getArtifactId ()
+ );
+ properties.setProperty (
+ Constants.ARCHETYPE_ARTIFACT_ID,
+ project.getArtifactId () + "-archetype"
+ );
+ }
+ if ( StringUtils.isEmpty ( properties.getProperty ( Constants.ARCHETYPE_VERSION ) ) )
+ {
+ getLogger ().info ( "Setting default archetype's version: " + project.getVersion () );
+ properties.setProperty ( Constants.ARCHETYPE_VERSION, project.getVersion () );
+ }
+
+ return archetypeFactory.createArchetypeDefinition ( properties );
+ }
+
+ private ArchetypeConfiguration defineDefaultConfiguration (
+ MavenProject project,
+ ArchetypeDefinition archetypeDefinition,
+ String resolvedPackage,
+ Properties properties
+ )
+ {
+ if ( StringUtils.isEmpty ( properties.getProperty ( Constants.GROUP_ID ) ) )
+ {
+ getLogger ().info ( "Setting default groupId: " + project.getGroupId () );
+ properties.setProperty ( Constants.GROUP_ID, project.getGroupId () );
+ }
+
+ if ( StringUtils.isEmpty ( properties.getProperty ( Constants.ARTIFACT_ID ) ) )
+ {
+ getLogger ().info ( "Setting default artifactId: " + project.getArtifactId () );
+ properties.setProperty ( Constants.ARTIFACT_ID, project.getArtifactId () );
+ }
+
+ if ( StringUtils.isEmpty ( properties.getProperty ( Constants.VERSION ) ) )
+ {
+ getLogger ().info ( "Setting default version: " + project.getVersion () );
+ properties.setProperty ( Constants.VERSION, project.getVersion () );
+ }
+
+ if ( StringUtils.isEmpty (
+ properties.getProperty (
+ Constants.PACKAGE,
+ properties.getProperty ( Constants.PACKAGE_NAME )
+ )
+ )
+ )
+ {
+ if ( StringUtils.isEmpty ( resolvedPackage ) )
+ {
+ resolvedPackage = project.getGroupId ();
+ }
+ getLogger ().info ( "Setting default package: " + resolvedPackage );
+ properties.setProperty ( Constants.PACKAGE_NAME, resolvedPackage );
+ properties.setProperty ( Constants.PACKAGE, resolvedPackage );
+ }
+
+ return
+ archetypeFactory.createArchetypeConfiguration (
+ project,
+ archetypeDefinition,
+ properties
+ );
+ }
+
+ private Properties initialiseArchetypeProperties (
+ Properties commandLineProperties,
+ File propertyFile
+ )
+ throws IOException
+ {
+ Properties properties = new Properties ();
+
+ try
+ {
+ archetypePropertiesManager.readProperties ( properties, propertyFile );
+ }
+ catch ( FileNotFoundException ex )
+ {
+ getLogger ().debug ( "archetype.properties does not exist" );
+ }
+
+ Iterator commandLinePropertiesIterator =
+ new ArrayList ( commandLineProperties.keySet () ).iterator ();
+ while ( commandLinePropertiesIterator.hasNext () )
+ {
+ String propertyKey = (String) commandLinePropertiesIterator.next ();
+
+ properties.setProperty (
+ propertyKey,
+ commandLineProperties.getProperty ( propertyKey )
+ );
+ }
+
+ return properties;
+ }
+}
Added: maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/DefaultArchetypeCreationQueryer.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/DefaultArchetypeCreationQueryer.java?rev=570618&view=auto
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/DefaultArchetypeCreationQueryer.java (added)
+++ maven/sandbox/trunk/archetypeng/archetype-creator/src/main/java/org/apache/maven/archetype/creator/DefaultArchetypeCreationQueryer.java Tue Aug 28 19:43:33 2007
@@ -0,0 +1,149 @@
+/*
+ * 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.creator;
+
+import org.apache.maven.archetype.common.ArchetypeConfiguration;
+import org.apache.maven.archetype.common.Constants;
+
+import org.codehaus.plexus.components.interactivity.Prompter;
+import org.codehaus.plexus.components.interactivity.PrompterException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+import java.util.Iterator;
+
+/**
+ * @plexus.component
+ */
+public class DefaultArchetypeCreationQueryer
+extends AbstractLogEnabled
+implements ArchetypeCreationQueryer
+{
+ /**
+ * @plexus.requirement
+ */
+ private Prompter prompter;
+
+ public String getArchetypeArtifactId ( String defaultValue )
+ throws PrompterException
+ {
+ return getValue ( Constants.ARCHETYPE_ARTIFACT_ID, defaultValue );
+ }
+
+ public String getArchetypeGroupId ( String defaultValue )
+ throws PrompterException
+ {
+ return getValue ( Constants.ARCHETYPE_GROUP_ID, defaultValue );
+ }
+
+ public String getArchetypeVersion ( String defaultValue )
+ throws PrompterException
+ {
+ return getValue ( Constants.ARCHETYPE_VERSION, defaultValue );
+ }
+
+ public String getArtifactId ( String defaultValue )
+ throws PrompterException
+ {
+ return getValue ( Constants.ARTIFACT_ID, defaultValue );
+ }
+
+ public boolean askAddAnotherProperty ()
+ throws PrompterException
+ {
+ String query = "Add a new custom property";
+
+ String answer = prompter.prompt ( query, "Y" );
+
+ return "Y".equalsIgnoreCase ( answer );
+ }
+
+ public String askNewPropertyKey ()
+ throws PrompterException
+ {
+ String query = "Define property key";
+
+ String answer = prompter.prompt ( query );
+
+ return answer;
+ }
+
+ public String askReplacementValue ( String propertyKey, String defaultValue )
+ throws PrompterException
+ {
+ return getValue ( propertyKey, defaultValue );
+ }
+
+ public boolean confirmConfiguration ( ArchetypeConfiguration archetypeConfiguration )
+ throws PrompterException
+ {
+ String query = "Confirm archetype configuration:\n";
+ query += Constants.ARCHETYPE_GROUP_ID + "=" + archetypeConfiguration.getGroupId () + "\n";
+ query +=
+ Constants.ARCHETYPE_ARTIFACT_ID + "=" + archetypeConfiguration.getArtifactId () + "\n";
+ query += Constants.ARCHETYPE_VERSION + "=" + archetypeConfiguration.getVersion () + "\n";
+
+ Iterator propertiesIter = archetypeConfiguration.getProperties ().keySet ().iterator ();
+
+ while ( propertiesIter.hasNext () )
+ {
+ String property = (String) propertiesIter.next ();
+ query += property + "=" + archetypeConfiguration.getProperty ( property ) + "\n";
+ }
+
+ String answer = prompter.prompt ( query, "Y" );
+
+ return "Y".equalsIgnoreCase ( answer );
+ }
+
+ public String getGroupId ( String defaultValue )
+ throws PrompterException
+ {
+ return getValue ( Constants.GROUP_ID, defaultValue );
+ }
+
+ public String getPackage ( String defaultValue )
+ throws PrompterException
+ {
+ return getValue ( Constants.PACKAGE, defaultValue );
+ }
+
+ public String getVersion ( String defaultValue )
+ throws PrompterException
+ {
+ return getValue ( Constants.VERSION, defaultValue );
+ }
+
+ private String getValue ( String requiredProperty, String defaultValue )
+ throws PrompterException
+ {
+ String query = "Define value for " + requiredProperty + ": ";
+ String answer;
+
+ if ( ( defaultValue != null ) && !defaultValue.equals ( "null" ) )
+ {
+ answer = prompter.prompt ( query, defaultValue );
+ }
+ else
+ {
+ answer = prompter.prompt ( query );
+ }
+ return answer;
+ }
+}