Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added groovy refactor experimentation

  • Loading branch information...
commit 58e4dc810067d07fb5a2c0b66347e036e4e38d8d 1 parent 3e9311f
Raphael Pieroni authored
Showing with 9,998 additions and 0 deletions.
  1. +295 −0 grarchetype-common/pom.xml
  2. +172 −0 grarchetype-common/src/main/groovy/groovy/xml/IndentedStreamingMarkupBuilder.groovy
  3. +13 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/Archetype.groovy
  4. +22 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/ArchetypeGenerationRequest.groovy
  5. +10 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/ArchetypeGenerationResult.groovy
  6. +33 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/DefaultArchetype.groovy
  7. +26 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/artifact/ArchetypeArtifactManager.groovy
  8. +153 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/artifact/DefaultArchetypeArtifactManager.groovy
  9. +18 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/catalog/ArchetypeCataloger.groovy
  10. +152 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/catalog/DefaultArchetypeCataloger.groovy
  11. +13 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/file/ArchetypeFileResolver.groovy
  12. +43 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/file/DefaultArchetypeFileResolver.groovy
  13. +359 −0 ...hetype-common/src/main/groovy/org/apache/maven/archetype/generator/AbstractFilesetArchetypeGenerator.groovy
  14. +14 −0 ...chetype-common/src/main/groovy/org/apache/maven/archetype/generator/DefaultFilesetArchetypeGenerator.groovy
  15. +100 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/generator/DefaultProjectGenerator.groovy
  16. +14 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/generator/FilesetArchetypeGenerator.groovy
  17. +85 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/generator/LegacyGenerator.groovy
  18. +14 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/generator/ProjectGenerator.groovy
  19. +265 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/pom/DefaultPomManager.groovy
  20. +16 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/pom/PomManager.groovy
  21. +52 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/util/DefaultRepositoryCreator.groovy
  22. +12 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/util/RepositoryCreator.groovy
  23. +31 −0 grarchetype-common/src/main/groovy/org/apache/maven/archetype/util/Scanner.groovy
  24. +44 −0 grarchetype-common/src/main/groovy/org/gparallelizer/AsyncException.groovy
  25. +253 −0 grarchetype-common/src/main/groovy/org/gparallelizer/AsyncInvokerUtil.groovy
  26. +197 −0 grarchetype-common/src/main/groovy/org/gparallelizer/Asynchronizer.groovy
  27. +2,980 −0 grarchetype-common/src/main/mdo/maven.mdo
  28. +23 −0 grarchetype-common/src/main/resources/archetype-catalog.xml
  29. +44 −0 grarchetype-common/src/test/archetypes/basic-with-parent/META-INF/maven/archetype-metadata.xml
  30. +51 −0 grarchetype-common/src/test/archetypes/basic-with-parent/archetype-resources/pom.xml
  31. +17 −0 grarchetype-common/src/test/archetypes/basic-with-parent/archetype-resources/src/main/java/App.java
  32. +13 −0 grarchetype-common/src/test/archetypes/basic-with-parent/archetype-resources/src/main/resources/images/foo.png
  33. +44 −0 grarchetype-common/src/test/archetypes/basic/META-INF/maven/archetype-metadata.xml
  34. +45 −0 grarchetype-common/src/test/archetypes/basic/archetype-resources/pom.xml
  35. +17 −0 grarchetype-common/src/test/archetypes/basic/archetype-resources/src/main/java/App.java
  36. +13 −0 grarchetype-common/src/test/archetypes/basic/archetype-resources/src/main/resources/images/foo.png
  37. +49 −0 grarchetype-common/src/test/archetypes/multi-with-parent/META-INF/maven/archetype-metadata.xml
  38. +26 −0 grarchetype-common/src/test/archetypes/multi-with-parent/archetype-resources/${ignoredProperty}/pom.xml
  39. +26 −0 grarchetype-common/src/test/archetypes/multi-with-parent/archetype-resources/${rootArtifactId}-a/pom.xml
  40. +34 −0 grarchetype-common/src/test/archetypes/multi-with-parent/archetype-resources/${rootArtifactId}-b/pom.xml
  41. +34 −0 ...n/src/test/archetypes/multi-with-parent/archetype-resources/${rootArtifactId}-c/${rootArtifactId}-d/pom.xml
  42. +34 −0 ...s/multi-with-parent/archetype-resources/${rootArtifactId}-c/${rootArtifactId}-e/${rootArtifactId}-f/pom.xml
  43. +34 −0 ...s/multi-with-parent/archetype-resources/${rootArtifactId}-c/${rootArtifactId}-e/${rootArtifactId}-g/pom.xml
  44. +34 −0 ...pes/multi-with-parent/archetype-resources/${rootArtifactId}-c/${rootArtifactId}-e/${upArtifactId}-h/pom.xml
  45. +32 −0 ...n/src/test/archetypes/multi-with-parent/archetype-resources/${rootArtifactId}-c/${rootArtifactId}-e/pom.xml
  46. +31 −0 grarchetype-common/src/test/archetypes/multi-with-parent/archetype-resources/${rootArtifactId}-c/pom.xml
  47. +33 −0 grarchetype-common/src/test/archetypes/multi-with-parent/archetype-resources/pom.xml
  48. +49 −0 grarchetype-common/src/test/archetypes/multi/META-INF/maven/archetype-metadata.xml
  49. +26 −0 grarchetype-common/src/test/archetypes/multi/archetype-resources/${ignoredProperty}/pom.xml
  50. +26 −0 grarchetype-common/src/test/archetypes/multi/archetype-resources/${rootArtifactId}-a/pom.xml
  51. +34 −0 grarchetype-common/src/test/archetypes/multi/archetype-resources/${rootArtifactId}-b/pom.xml
  52. +34 −0 ...hetype-common/src/test/archetypes/multi/archetype-resources/${rootArtifactId}-c/${rootArtifactId}-d/pom.xml
  53. +34 −0 ...st/archetypes/multi/archetype-resources/${rootArtifactId}-c/${rootArtifactId}-e/${rootArtifactId}-f/pom.xml
  54. +34 −0 ...st/archetypes/multi/archetype-resources/${rootArtifactId}-c/${rootArtifactId}-e/${rootArtifactId}-g/pom.xml
  55. +34 −0 ...test/archetypes/multi/archetype-resources/${rootArtifactId}-c/${rootArtifactId}-e/${upArtifactId}-h/pom.xml
  56. +32 −0 ...hetype-common/src/test/archetypes/multi/archetype-resources/${rootArtifactId}-c/${rootArtifactId}-e/pom.xml
  57. +31 −0 grarchetype-common/src/test/archetypes/multi/archetype-resources/${rootArtifactId}-c/pom.xml
  58. +27 −0 grarchetype-common/src/test/archetypes/multi/archetype-resources/pom.xml
  59. +30 −0 grarchetype-common/src/test/archetypes/nested-complete-inner/META-INF/maven/archetype-metadata.xml
  60. +28 −0 grarchetype-common/src/test/archetypes/nested-complete-innest/META-INF/maven/archetype-metadata.xml
  61. +30 −0 grarchetype-common/src/test/archetypes/nested-complete-main/META-INF/maven/archetype-metadata.xml
  62. +46 −0 grarchetype-common/src/test/archetypes/nested-inner/META-INF/maven/archetype-metadata.xml
  63. +94 −0 ...c/test/archetypes/nested-inner/archetype-resources/${rootArtifactId}-inner/${rootArtifactId}-innest/pom.xml
  64. +26 −0 grarchetype-common/src/test/archetypes/nested-inner/archetype-resources/${rootArtifactId}-inner/pom.xml
  65. +25 −0 grarchetype-common/src/test/archetypes/nested-inner/archetype-resources/pom.xml
  66. +39 −0 grarchetype-common/src/test/archetypes/nested-innest/META-INF/maven/archetype-metadata.xml
  67. +26 −0 .../test/archetypes/nested-innest/archetype-resources/${rootArtifactId}-inner/${rootArtifactId}-innest/pom.xml
  68. +26 −0 grarchetype-common/src/test/archetypes/nested-innest/archetype-resources/${rootArtifactId}-inner/pom.xml
  69. +27 −0 grarchetype-common/src/test/archetypes/nested-innest/archetype-resources/pom.xml
  70. +47 −0 grarchetype-common/src/test/archetypes/nested-main/META-INF/maven/archetype-metadata.xml
  71. +71 −0 ...rc/test/archetypes/nested-main/archetype-resources/${rootArtifactId}-inner/${rootArtifactId}-innest/pom.xml
  72. +26 −0 grarchetype-common/src/test/archetypes/nested-main/archetype-resources/${rootArtifactId}-inner/pom.xml
  73. +25 −0 grarchetype-common/src/test/archetypes/nested-main/archetype-resources/pom.xml
  74. +34 −0 grarchetype-common/src/test/archetypes/nested-missing-inner/META-INF/maven/archetype-metadata.xml
  75. +34 −0 grarchetype-common/src/test/archetypes/nested-missing-main/META-INF/maven/archetype-metadata.xml
  76. +33 −0 grarchetype-common/src/test/archetypes/nested-partial/META-INF/maven/archetype-metadata.xml
  77. +26 −0 grarchetype-common/src/test/archetypes/nested-partial/archetype-resources/${rootArtifactId}-a/pom.xml
  78. +143 −0 grarchetype-common/src/test/archetypes/nested-partial/archetype-resources/pom.xml
  79. +31 −0 grarchetype-common/src/test/archetypes/old/META-INF/archetype.xml
  80. +34 −0 grarchetype-common/src/test/archetypes/old/archetype-resources/pom.xml
  81. +4 −0 grarchetype-common/src/test/archetypes/old/archetype-resources/src/main/java/App.java
  82. +4 −0 grarchetype-common/src/test/archetypes/old/archetype-resources/src/main/resources/App.properties
  83. +4 −0 grarchetype-common/src/test/archetypes/old/archetype-resources/src/site/site.xml
  84. +104 −0 grarchetype-common/src/test/groovy/org/apache/maven/archetype/catalog/DefaultArchetypeCatalogerTest.groovy
  85. +76 −0 grarchetype-common/src/test/groovy/org/apache/maven/archetype/file/DefaultArchetypeFileResolverTest.groovy
  86. +279 −0 ...ype-common/src/test/groovy/org/apache/maven/archetype/generator/DefaultArchetypefilesetGeneratorTest.groovy
  87. +234 −0 grarchetype-common/src/test/groovy/org/apache/maven/archetype/generator/DefaultProjectGeneratorTest.groovy
  88. +65 −0 grarchetype-common/src/test/groovy/org/apache/maven/archetype/util/ScannerTest.groovy
  89. +9 −0 grarchetype-common/src/test/pom.xml
  90. +11 −0 grarchetype-common/src/test/projects/generateMonoModuleProjectParentFromArchetype/pom.xml
  91. +11 −0 grarchetype-common/src/test/projects/generateMonoModuleProjectParentFromDirectory/pom.xml
  92. +8 −0 grarchetype-common/src/test/projects/generateMultiModuleProjectWithParentFromArchetype/pom.xml
  93. +8 −0 grarchetype-common/src/test/projects/generateMultiModuleProjectWithParentFromDirectory/pom.xml
  94. +53 −0 grarchetype-common/src/test/repositories/central/archetype-catalog.xml
  95. 0  grarchetype-common/src/test/repositories/local/dummy
  96. +266 −0 grarchetype-plugin/pom.xml
  97. +125 −0 grarchetype-plugin/src/main/groovy/org/apache/maven/archetype/mojos/CreateProjectFromArchetypeMojo.groovy
  98. +13 −0 grarchetype-plugin/src/main/groovy/org/apache/maven/archetype/ui/ArchetypeGenerationConfigurator.groovy
  99. +135 −0 grarchetype-plugin/src/main/groovy/org/apache/maven/archetype/ui/ArchetypePrompter.groovy
  100. +13 −0 grarchetype-plugin/src/main/groovy/org/apache/maven/archetype/ui/ArchetypeSelector.groovy
  101. +187 −0 grarchetype-plugin/src/main/groovy/org/apache/maven/archetype/ui/DefaultArchetypeGenerationConfigurator.groovy
  102. +146 −0 grarchetype-plugin/src/main/groovy/org/apache/maven/archetype/ui/DefaultArchetypeSelector.groovy
  103. +39 −0 grarchetype-plugin/src/test/archetypes/nested-properties-inner/META-INF/maven/archetype-metadata.xml
  104. +37 −0 grarchetype-plugin/src/test/archetypes/nested-properties-innest/META-INF/maven/archetype-metadata.xml
  105. +43 −0 grarchetype-plugin/src/test/archetypes/nested-properties-main/META-INF/maven/archetype-metadata.xml
  106. +31 −0 grarchetype-plugin/src/test/archetypes/old/META-INF/archetype.xml
  107. +34 −0 grarchetype-plugin/src/test/archetypes/old/archetype-resources/pom.xml
  108. +4 −0 grarchetype-plugin/src/test/archetypes/old/archetype-resources/src/main/java/App.java
  109. +4 −0 grarchetype-plugin/src/test/archetypes/old/archetype-resources/src/main/resources/App.properties
  110. +4 −0 grarchetype-plugin/src/test/archetypes/old/archetype-resources/src/site/site.xml
  111. +88 −0 ...type-plugin/src/test/groovy/org/apache/maven/archetype/ui/DefaultArchetypeGenerationConfiguratorTest.groovy
  112. +38 −0 grarchetype-plugin/src/test/groovy/org/apache/maven/archetype/ui/DefaultArchetypeSelectorTest.groovy
  113. +20 −0 grarchetype-plugin/src/test/repositories/central/archetype-catalog.xml
  114. 0  grarchetype-plugin/src/test/repositories/local/dummy
  115. +72 −0 grarchetype-testing/grarchetype-repository/pom.xml
  116. +257 −0 ...e-testing/grarchetype-repository/src/main/java/org/apache/maven/archetype/repository/RepositoryServlet.java
  117. +12 −0 grarchetype-testing/grarchetype-repository/src/main/webapp/WEB-INF/web.xml
  118. +21 −0 grarchetype-testing/pom.xml
  119. +257 −0 pom.xml
View
295 grarchetype-common/pom.xml
@@ -0,0 +1,295 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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.grarchetype</groupId>
+ <artifactId>maven-grarchetype</artifactId>
+ <version>2.0-alpha-5-SNAPSHOT</version>
+ </parent>
+ <artifactId>grarchetype-common</artifactId>
+ <name>Maven GRArchetype Common</name>
+ <packaging>jar</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-model</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.velocity</groupId>
+ <artifactId>velocity</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-all</artifactId>
+ <version>1.6.0</version>
+ <!--version>1.6-RC-2</version-->
+ </dependency>
+ <dependency>
+ <groupId>jdom</groupId>
+ <artifactId>jdom</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-plugin-testing-harness</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-file</artifactId>
+ <version>1.0-beta-2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-http</artifactId>
+ <version>1.0-beta-2</version><!-- with 1.0-beta-4 some tests fail -->
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.cargo</groupId>
+ <artifactId>cargo-core-api-container</artifactId>
+ <version>1.0-alpha-6</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.cargo</groupId>
+ <artifactId>cargo-core-api-util</artifactId>
+ <version>1.0-alpha-6</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.cargo</groupId>
+ <artifactId>cargo-core-api-generic</artifactId>
+ <version>1.0-alpha-6</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.cargo</groupId>
+ <artifactId>cargo-core-api-module</artifactId>
+ <version>1.0-alpha-6</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.cargo</groupId>
+ <artifactId>cargo-core-container-jetty</artifactId>
+ <version>1.0-alpha-6</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>6.1.11</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>grarchetype-repository</artifactId>
+ <version>${project.version}</version>
+ <type>war</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemProperties>
+ <property>
+ <name>maven.home</name>
+ <value>${maven.home}</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.modello</groupId>
+ <artifactId>modello-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>model</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>jdom-writer</goal>
+ </goals>
+ <configuration>
+ <model>src/main/mdo/maven.mdo</model>
+ <version>4.0.0</version>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.groovy.maven</groupId>
+ <artifactId>gmaven-plugin</artifactId>
+ <version>1.0-rc-5</version>
+ <configuration>
+ <providerSelection>1.6</providerSelection>
+ <!--providerSelection>1.6</providerSelection-->
+ </configuration>
+ <executions>
+ <execution>
+ <id>generate-sources</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>generateStubs</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>compile</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>test-compile</id>
+ <phase>test-compile</phase>
+ <goals>
+ <goal>testCompile</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>prepareRepositories</id>
+ <phase>generate-test-resources</phase>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ <configuration>
+ <source>
+log.info "Preparing Repositories"
+def dir = "${project.basedir}/target/repositories"
+ant.delete dir: dir
+ant.mkdir dir: dir
+ant.copy( toDir: dir ) {
+ fileset dir: "${project.basedir}/src/test/repositories"
+}
+
+def prepareArchetype = { archetype, archetypeVersion ->
+ if( project.packaging != 'pom' ) {
+ log.info "Preparing ${archetype}-${archetypeVersion} archetype..."
+ dir = "${project.basedir}/target/repositories/central/archetypes/${archetype}/${archetypeVersion}"
+ ant.mkdir dir: dir
+ ant.jar destFile: "${dir}/${archetype}-${archetypeVersion}.jar", basedir: "${project.basedir}/src/test/archetypes/${archetype}"
+ }
+}
+prepareArchetype 'nested-complete-main', '1.0'
+prepareArchetype 'nested-complete-inner', '1.0'
+prepareArchetype 'nested-complete-innest', '1.0'
+
+prepareArchetype 'nested-missing-main', '1.0'
+prepareArchetype 'nested-missing-inner', '1.0'
+
+prepareArchetype 'basic', '1.0'
+prepareArchetype 'basic-with-parent', '1.0'
+prepareArchetype 'multi', '1.0'
+prepareArchetype 'multi-with-parent', '1.0'
+
+prepareArchetype 'old', '1.0'
+prepareArchetype 'nested-main', '1.0'
+prepareArchetype 'nested-inner', '1.0'
+prepareArchetype 'nested-innest', '1.0'
+prepareArchetype 'nested-partial', '1.0'
+ </source>
+ </configuration>
+ </execution>
+ <execution>
+ <id>prepareProjects</id>
+ <phase>generate-test-resources</phase>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ <configuration>
+ <source>
+log.info "Preparing projects..."
+def dir = "${project.basedir}/target/projects"
+ant.delete dir: dir
+ant.mkdir dir: dir
+ant.copy( toDir: dir ) {
+ fileset dir: "${project.basedir}/src/test/projects"
+}
+ </source>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-maven-plugin</artifactId>
+ <version>1.3.8</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>descriptor</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy</id>
+ <phase>process-test-resources</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/wars</outputDirectory>
+ <overWriteReleases>true</overWriteReleases>
+ <overWriteSnapshots>true</overWriteSnapshots>
+ <includeTypes>war</includeTypes>
+ <stripVersion>true</stripVersion>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ <version>2.2</version>
+ </plugin>
+ </plugins>
+ </reporting>
+
+ <profiles>
+ <profile>
+ <id>internal-catalog</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>**/InternalCatalogFromWiki.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
View
172 grarchetype-common/src/main/groovy/groovy/xml/IndentedStreamingMarkupBuilder.groovy
@@ -0,0 +1,172 @@
+package groovy.xml
+
+import groovy.xml.streamingmarkupsupport.AbstractStreamingBuilder
+import groovy.xml.streamingmarkupsupport.StreamingMarkupWriter
+import groovy.xml.streamingmarkupsupport.BaseMarkupBuilder
+
+class IndentedStreamingMarkupBuilder extends StreamingMarkupBuilder {
+ def tagIndentOffset = ' '
+ def attributeIndentOffest = ' '
+ private def tagIndentString = ''
+ private def attributeIndentString = attributeIndentOffest
+ private def tagIndentclosed = false
+
+ def pendingStack = []
+ def commentClosure = {doc, pendingNamespaces, namespaces, namespaceSpecificTags, prefix, attrs, body, out ->
+ out.unescaped() << "\n${tagIndentString}<!--"
+ out.escaped() << body
+ out.unescaped() << "${tagIndentString}-->"
+ }
+ def piClosure = {doc, pendingNamespaces, namespaces, namespaceSpecificTags, prefix, attrs, body, out ->
+ attrs.each {target, instruction ->
+ out.unescaped() << "\n${tagIndentString}<?"
+ if (instruction instanceof Map) {
+ out.unescaped() << target
+ instruction.each {name, value ->
+ if (value.toString().contains('"')) {
+ out.unescaped() << " $name='$value'"
+ } else {
+ out.unescaped() << " $name=\"$value\""
+ }
+ }
+ } else {
+ out.unescaped() << "$target $instruction"
+ }
+ out.unescaped() << "?>"
+ }
+ }
+ def declarationClosure = {doc, pendingNamespaces, namespaces, namespaceSpecificTags, prefix, attrs, body, out ->
+ out.unescaped() << '<?xml version="1.0"'
+ if (out.encodingKnown) out.escaped() << " encoding=\"${out.encoding}\""
+ out.unescaped() << '?>'
+ }
+ def noopClosure = {doc, pendingNamespaces, namespaces, namespaceSpecificTags, prefix, attrs, body, out ->
+ body.each {
+ if (it instanceof Closure) {
+ def body1 = it.clone()
+
+ body1.delegate = doc
+ body1(doc)
+ } else if (it instanceof Buildable) {
+ it.build(doc)
+ } else {
+ out.escaped() << it
+ }
+ }
+ }
+ def unescapedClosure = {doc, pendingNamespaces, namespaces, namespaceSpecificTags, prefix, attrs, body, out ->
+ out.unescaped() << body
+ }
+ def tagClosure = {tag, doc, pendingNamespaces, namespaces, namespaceSpecificTags, prefix, attrs, body, out ->
+ if (prefix != "") {
+ if (!(namespaces.containsKey(prefix) || pendingNamespaces.containsKey(prefix))) {
+ throw new GroovyRuntimeException("Namespace prefix: ${prefix} is not bound to a URI")
+ }
+
+ if (prefix != ":") tag = prefix + ":" + tag
+ }
+
+ out = out.unescaped() << "\n${tagIndentString}<${tag}"
+
+ attrs.each {key, value ->
+ if (key.contains('$')) {
+ def parts = key.tokenize('$')
+
+ if (namespaces.containsKey(parts[0]) || pendingNamespaces.containsKey(parts[0])) {
+ key = parts[0] + ":" + parts[1]
+ } else {
+ throw new GroovyRuntimeException("bad attribute namespace tag: ${parts[0]} in ${key}")
+ }
+ }
+
+ out << " ${key}='"
+ out.writingAttribute = true
+ "${value}".build(doc)
+ out.writingAttribute = false
+ out << "'"
+ }
+
+ def hiddenNamespaces = [:]
+
+ pendingNamespaces.each {key, value ->
+ hiddenNamespaces[key] = namespaces[key]
+ namespaces[key] = value
+ out << ((key == ":") ? " xmlns='" : " xmlns:${key}='")
+ out.writingAttribute = true
+ "${value}".build(doc)
+ out.writingAttribute = false
+ out << "'"
+ }
+
+ if (body == null) {
+ out << "/>"
+ } else {
+ out << ">"
+ tagIndentclosed = false
+ tagIndentString = tagIndentString + tagIndentOffset
+ attributeIndentString = tagIndentString + attributeIndentOffest
+
+ pendingStack.add pendingNamespaces.clone()
+ pendingNamespaces.clear()
+
+ body.each {
+ if (it instanceof Closure) {println"CLOSURE"
+ def body1 = it.clone()
+
+ body1.delegate = doc
+ body1(doc)
+ } else if (it instanceof Buildable) {println"BUILDABLE}"
+ it.build(doc)
+ } else {println"ESCAPED}"
+ out.escaped() << it
+ }
+ }
+
+ System.out.println"XXX ${tag} XX${body?.dump()}"
+ pendingNamespaces.clear()
+ pendingNamespaces.putAll pendingStack.pop()
+
+ tagIndentString = tagIndentString - tagIndentOffset
+ attributeIndentString = tagIndentString + attributeIndentOffest
+ out << "${tagIndentclosed?'\n'+tagIndentString:''}</${tag}>"
+ tagIndentclosed = true
+ }
+
+ hiddenNamespaces.each {key, value ->
+ if (value == null) {
+ namespaces.remove key
+ } else {
+ namespaces[key] = value
+ }
+ }
+ }
+
+ def builder = null
+
+ IndentedStreamingMarkupBuilder() {
+ specialTags.putAll(['yield': noopClosure,
+ 'yieldUnescaped': unescapedClosure,
+ 'xmlDeclaration': declarationClosure,
+ 'comment': commentClosure,
+ 'pi': piClosure])
+
+ def nsSpecificTags = [':': [tagClosure, tagClosure, [:]], // the default namespace
+ 'http://www.w3.org/XML/1998/namespace': [tagClosure, tagClosure, [:]],
+ 'http://www.codehaus.org/Groovy/markup/keywords': [badTagClosure, tagClosure, specialTags]]
+
+ this.builder = new BaseMarkupBuilder(nsSpecificTags)
+ }
+
+ def encoding = null
+
+ public bind(closure) {
+ def boundClosure = this.builder.bind(closure);
+ def enc = encoding; // take a snapshot of the encoding when the closure is bound to the builder
+
+ {out ->
+ out = new StreamingMarkupWriter(out, enc)
+ boundClosure.trigger = out
+ out.flush()
+ }.asWritable()
+ }
+}
View
13 grarchetype-common/src/main/groovy/org/apache/maven/archetype/Archetype.groovy
@@ -0,0 +1,13 @@
+package org.apache.maven.archetype
+
+/**
+ *
+ * @author rafale
+ */
+interface Archetype {
+ String ROLE = 'org.apache.maven.archetype.Archetype'
+
+ ArchetypeGenerationResult generateProjectFromArchetype( ArchetypeGenerationRequest request )
+
+}
+
View
22 grarchetype-common/src/main/groovy/org/apache/maven/archetype/ArchetypeGenerationRequest.groovy
@@ -0,0 +1,22 @@
+package org.apache.maven.archetype
+
+/**
+ *
+ * @author rafale
+ */
+class ArchetypeGenerationRequest {
+ //- input properties
+ def repositories
+ def localRepository
+
+ def groupId
+ def artifactId
+ def version
+ def outputDirectory
+ def generationFilterProperties
+
+ //- calculed properties
+ def archetypeFile
+ def archetypes
+}
+
View
10 grarchetype-common/src/main/groovy/org/apache/maven/archetype/ArchetypeGenerationResult.groovy
@@ -0,0 +1,10 @@
+package org.apache.maven.archetype
+
+/**
+ *
+ * @author rafale
+ */
+class ArchetypeGenerationResult {
+ def cause
+}
+
View
33 grarchetype-common/src/main/groovy/org/apache/maven/archetype/DefaultArchetype.groovy
@@ -0,0 +1,33 @@
+package org.apache.maven.archetype
+
+import org.codehaus.plexus.logging.AbstractLogEnabled
+import org.apache.maven.archetype.generator.ProjectGenerator
+
+/**
+ *
+ * @author rafale
+ * @plexus.component
+ */
+class DefaultArchetype
+extends AbstractLogEnabled
+implements Archetype {
+
+ /** @plexus.requirement */
+ private ProjectGenerator generator
+
+ ArchetypeGenerationResult generateProjectFromArchetype( ArchetypeGenerationRequest request ) {
+ logger.error "generateProjectFromArchetype $request"
+
+ ArchetypeGenerationResult result = new ArchetypeGenerationResult()
+
+ try {
+ generator.generateProject request
+ } catch( exception ) {
+ result.cause = exception
+ }
+
+ return result
+ }
+
+}
+
View
26 grarchetype-common/src/main/groovy/org/apache/maven/archetype/artifact/ArchetypeArtifactManager.groovy
@@ -0,0 +1,26 @@
+package org.apache.maven.archetype.artifact
+import org.apache.maven.artifact.repository.ArtifactRepository
+import org.apache.maven.artifact.repository.ArtifactRepository
+
+/**
+ *
+ * @author rafale
+ */
+interface ArchetypeArtifactManager {
+ static String ROLE = 'org.apache.maven.archetype.artifact.ArchetypeArtifactManager'
+
+ static String ARCHETYPE_DESCRIPTOR = 'META-INF/maven/archetype-metadata.xml'
+ static String LEGACY_ARCHETYPE_DESCRIPTOR = 'META-INF/maven/archetype.xml'
+ static String OLD_LEGACY_ARCHETYPE_DESCRIPTOR = 'META-INF/archetype.xml'
+
+ def getFilesetArchetypeDescriptor( File archetypeFile )
+ def getFilesetArchetypeResources( File archetypeFile )
+ def getArchetypeZipFile( File archetypeFile )
+
+ def getArchetypeFile( String groupId, String artifactId, String version,
+ ArtifactRepository localRepository, List<ArtifactRepository> remoteRepository )
+ def isLegacyArchetype( File archetypeFile )
+
+ def getLegacyArchetypeDescriptor( File archetypeFile )
+}
+
View
153 ...hetype-common/src/main/groovy/org/apache/maven/archetype/artifact/DefaultArchetypeArtifactManager.groovy
@@ -0,0 +1,153 @@
+package org.apache.maven.archetype.artifact
+import java.util.zip.ZipFile
+import java.util.zip.ZipEntry
+import org.codehaus.plexus.logging.AbstractLogEnabled
+import org.apache.maven.artifact.factory.ArtifactFactory
+import org.apache.maven.artifact.resolver.ArtifactResolver
+import org.apache.maven.artifact.repository.ArtifactRepository
+import org.apache.maven.artifact.Artifact
+
+/**
+ *
+ * @author raphaelpieroni
+ * @plexus.component
+ */
+class DefaultArchetypeArtifactManager
+extends AbstractLogEnabled
+implements ArchetypeArtifactManager {
+
+ /**
+ * @plexus.requirement
+ */
+ ArtifactResolver artifactResolver
+
+ /**
+ * @plexus.requirement
+ */
+ ArtifactFactory artifactFactory
+
+ def getFilesetArchetypeDescriptor( File archetypeFile ) {
+ ZipFile zipFile = getArchetypeZipFile( archetypeFile )
+ ZipEntry entry = zipFile.getEntry( ARCHETYPE_DESCRIPTOR.replaceAll( File.separator, "/" ) )
+ if( !entry ) {
+ logger.debug "No found ${ARCHETYPE_DESCRIPTOR} retrying with windows path"
+ entry = zipFile.getEntry( ARCHETYPE_DESCRIPTOR.replaceAll( "/", File.separator ) )
+ }
+ if( !entry ) throw new IOException( "The ${ARCHETYPE_DESCRIPTOR} descriptor cannot be found." )
+
+ zipFile.getInputStream entry
+ }
+
+ def getFilesetArchetypeResources( File archetypeFile ) {
+ ZipFile zipFile = getArchetypeZipFile( archetypeFile )
+ zipFile.entries().findAll { entry ->
+ !entry.isDirectory() && entry.name.startsWith ( 'archetype-resources/' )
+ }.collect { entry ->
+ entry.name.replace 'archetype-resources/', ''
+ }
+ }
+
+ def getArchetypeZipFile( File archetypeFile ) {
+ logger.debug "Loading zip file ${archetypeFile.exists()} ${archetypeFile}"
+ new ZipFile( archetypeFile )
+ }
+
+
+ def getArchetypeFile( String groupId, String artifactId, String version,
+ ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories ) {
+
+ Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version,
+ Artifact.SCOPE_RUNTIME, 'jar' )
+ artifactResolver.resolve( artifact, remoteRepositories, localRepository )
+ artifact.file
+ }
+
+ def isLegacyArchetype( File archetypeFile ) {
+ ZipFile zipFile = getArchetypeZipFile( archetypeFile )
+
+ ZipEntry regularDescriptor = zipFile.getEntry( ARCHETYPE_DESCRIPTOR.replaceAll( File.separator, "/" ) )
+ if( !regularDescriptor ) {
+ regularDescriptor = zipFile.getEntry( ARCHETYPE_DESCRIPTOR.replaceAll( "/", File.separator ) )
+ }
+ if( regularDescriptor ) return false
+
+ ZipEntry legacyDescriptor = zipFile.getEntry( LEGACY_ARCHETYPE_DESCRIPTOR.replaceAll( File.separator, "/" ) )
+ if( !legacyDescriptor ) {
+ legacyDescriptor = zipFile.getEntry( LEGACY_ARCHETYPE_DESCRIPTOR.replaceAll( "/", File.separator ) )
+ }
+ if( !legacyDescriptor ) {
+ legacyDescriptor = zipFile.getEntry( OLD_LEGACY_ARCHETYPE_DESCRIPTOR.replaceAll( File.separator, "/" ) )
+ }
+ if( !legacyDescriptor ) {
+ legacyDescriptor = zipFile.getEntry( OLD_LEGACY_ARCHETYPE_DESCRIPTOR.replaceAll( "/", File.separator ) )
+ }
+ if( legacyDescriptor ) return true
+
+ return false
+ }
+
+ def getLegacyArchetypeDescriptor( File archetypeFile ) {
+ ZipFile zipFile = getArchetypeZipFile( archetypeFile )
+ ZipEntry entry = zipFile.getEntry( LEGACY_ARCHETYPE_DESCRIPTOR.replaceAll( File.separator, "/" ) )
+ if( !entry ) {
+ logger.debug "No found ${LEGACY_ARCHETYPE_DESCRIPTOR} retrying with windows path"
+ entry = zipFile.getEntry( LEGACY_ARCHETYPE_DESCRIPTOR.replaceAll( "/", File.separator ) )
+ }
+ if( !entry ) {
+ logger.debug "No found ${LEGACY_ARCHETYPE_DESCRIPTOR} retrying with ${OLD_LEGACY_ARCHETYPE_DESCRIPTOR}"
+ entry = zipFile.getEntry( OLD_LEGACY_ARCHETYPE_DESCRIPTOR.replaceAll( File.separator, "/" ) )
+ }
+ if( !entry ) {
+ logger.debug "No found ${OLD_LEGACY_ARCHETYPE_DESCRIPTOR} retrying with windows path"
+ entry = zipFile.getEntry( OLD_LEGACY_ARCHETYPE_DESCRIPTOR.replaceAll( "/", File.separator ) )
+ }
+
+ zipFile.getInputStream entry
+ }
+
+ def getNestedArchetypeFiles( archetype, localRepository, repositories, archetypeFileMap = [:] ) {
+ def archetypeFile = getArchetypeFile(
+ archetype.groupId, archetype.artifactId, archetype.version,
+ localRepository, repositories )
+ archetypeFileMap[(archetype)] = archetypeFile
+ if( !isLegacyArchetype( archetypeFile ) ) {
+ getNestedArchetypes( archetypeFile, localRepository, repositories ).each { nestedArchetype ->
+ getNestedArchetypeFiles( nestedArchetype, localRepository, repositories, archetypeFileMap )
+ }
+ }
+ return archetypeFileMap
+ }
+ def getNestedArchetypes( archetypeFile, localRepository, repositories ) {
+ logger.debug "Searching for nested archetype of ${archetypeFile}"
+ def descriptor = new XmlSlurper().parse( getFilesetArchetypeDescriptor( archetypeFile ) )
+ def nestedArchetypes = []
+ descriptor.modules.module.each {
+ if( it.@nested.toBoolean() ) {
+ logger.debug "Module ${it.@artifactId.toString()} is a nested archetype"
+ nestedArchetypes.add toDefinition( it )
+ } else {
+ logger.debug "Module ${it.@artifactId.toString()} is a regular module"
+ getInnerArchetypes it, nestedArchetypes, localRepository, repositories
+ }
+
+ }
+ return nestedArchetypes
+ }
+ void getInnerArchetypes( module, nestedArchetypes, localRepository, repositories ) {
+ module.modules.module.each {
+ if( it.@nested.toBoolean() ) {
+ logger.debug "Module ${it.@artifactId.toString()} is a nested archetype"
+ nestedArchetypes.add toDefinition( it )
+ } else {
+ logger.debug "Module ${it.@artifactId.toString()} is a regular module"
+ getInnerArchetypes it, nestedArchetypes, localRepository, repositories
+ }
+ }
+ }
+ def toDefinition( module ) {
+ [groupId:module.@archetypeGroupId.text().toString(),
+ artifactId:module.@archetypeArtifactId.text().toString(),
+ version:module.@archetypeVersion.text().toString()]
+ }
+}
+
View
18 grarchetype-common/src/main/groovy/org/apache/maven/archetype/catalog/ArchetypeCataloger.groovy
@@ -0,0 +1,18 @@
+package org.apache.maven.archetype.catalog
+
+/**
+ *
+ * @author raphaelpieroni
+ */
+interface ArchetypeCataloger {
+ static String ROLE = 'org.apache.maven.archetype.catalog.ArchetypeCataloger'
+
+ def loadCatalog( String catalog )
+
+ def archetypeRecursivelyExists( archetype, archetypeDefinitions, localRepository, repositories )
+
+ def getArchetypesByCatalog( catalogs )
+
+ def searchArchetype( definition, archetypeCatalogs )
+}
+
View
152 grarchetype-common/src/main/groovy/org/apache/maven/archetype/catalog/DefaultArchetypeCataloger.groovy
@@ -0,0 +1,152 @@
+package org.apache.maven.archetype.catalog
+import org.codehaus.plexus.logging.AbstractLogEnabled
+import org.apache.maven.archetype.artifact.ArchetypeArtifactManager
+
+/**
+ *
+ * @author raphaelpieroni
+ * @plexus.component
+ */
+class DefaultArchetypeCataloger
+extends AbstractLogEnabled
+implements ArchetypeCataloger {
+
+ /** @plexus.requirement */
+ private ArchetypeArtifactManager artifactManager
+
+ def loadCatalog( String catalogName ) {
+ def catalog
+ switch( catalogName ) {
+ case "internal":
+ logger.info "Using internal catalog"
+ catalog = this.class.classLoader.getResourceAsStream( "archetype-catalog.xml" )
+ break
+
+ case "local":
+ logger.info "Using default local catalog"
+ catalog = new File( System.getProperty( "user.home" ), ".m2/archetype-catalog.xml" )
+ break
+
+ case "remote":
+ logger.info "Using default remote catalog"
+ catalog = "http://repo1.maven.org/maven2/archetype-catalog.xml"
+ break
+
+ case ~"file://.*":
+ logger.info "Using local catalog $catalogName"
+ break
+
+ case ~"https?://.*":
+ logger.info "Using remote catalog $catalogName"
+ catalog = catalogName
+ break
+
+ default: return null
+ }
+ if( !catalog ) {
+ logger.warn "Catalog $catalogName not found"
+ return null
+ }
+ try {
+ return new XmlSlurper().parse( catalog )
+ } catch( e ) {
+ logger.warn "Can not read catalog $catalogName: $e.message"
+ return
+ }
+ }
+
+
+ def archetypeRecursivelyExists( archetype, archetypeDefinitions, localRepository, repositories ) {
+ def archetypeFile
+ try {
+ archetypeFile = artifactManager.getArchetypeFile(
+ archetype.groupId, archetype.artifactId, archetype.version,
+ localRepository, repositories )
+ } catch( e ) {
+ logger.warn "Archetype ${archetype} not found", e
+ return false
+ }
+ if( artifactManager.isLegacyArchetype( archetypeFile ) ) {
+ return true
+ } else {
+ def recursivelyExists = true
+ getNestedArchetypes( archetypeFile, archetypeDefinitions, localRepository, repositories ).each { nestedArchetype ->
+ recursivelyExists = recursivelyExists &&
+ archetypeRecursivelyExists( nestedArchetype, archetypeDefinitions, localRepository, repositories )
+ }
+ return recursivelyExists
+ }
+ }
+ def getNestedArchetypes( archetypeFile, archetypeDefinitions, localRepository, repositories ) {
+ logger.debug "Searching for nested archetype of ${archetypeFile}"
+ def descriptor = new XmlSlurper().parse( artifactManager.getFilesetArchetypeDescriptor( archetypeFile ) )
+ def nestedArchetypes = []
+ descriptor.modules.module.each {
+ if( it.@nested.toBoolean() ) {
+ logger.debug "Module ${it.@artifactId.toString()} is a nested archetype"
+ nestedArchetypes.add toDefinition( it )
+ } else {
+ logger.debug "Module ${it.@artifactId.toString()} is a regular module"
+ getInnerArchetypes it, archetypeDefinitions, nestedArchetypes, localRepository, repositories
+ }
+
+ }
+ return nestedArchetypes
+ }
+ void getInnerArchetypes( module, archetypes, nestedArchetypes, localRepository, repositories ) {
+ module.modules.module.each {
+ if( it.@nested.toBoolean() ) {
+ logger.debug "Module ${it.@artifactId.toString()} is a nested archetype"
+ nestedArchetypes.add toDefinition( it )
+ } else {
+ logger.debug "Module ${it.@artifactId.toString()} is a regular module"
+ getInnerArchetypes it, archetypes, nestedArchetypes, localRepository, repositories
+ }
+ }
+ }
+ def getArchetypesByCatalog( catalogs ) {
+ if( !catalogs ) return null
+ def archetypes = [:]
+ catalogs.split( "," ).each { catalogName ->
+ def catalog = loadCatalog( catalogName )
+ if( !catalog ) {
+ logger.error "Unknown catalog $catalog"
+ return null
+ }
+ catalog.archetypes.archetype.each{
+ def archetype = [
+ catalog:catalogName,
+ groupId:it.groupId.text().toString(),
+ artifactId:it.artifactId.text().toString(),
+ version:it.version.text().toString(),
+ description:it.description.text().toString(),
+ repository:it.repository.text().toString()]
+ if( !archetype.repository && (catalogName =~ "(file|https?)://.*" ) ) archetype.repository = catalogName - "archetype-catalog.xml"
+
+ archetypes["${archetype.groupId}:${archetype.artifactId}:${archetype.version}".toString()] = archetype
+ }
+ }
+ return archetypes
+ }
+ def toDefinition( module ) {
+ [groupId:module.@archetypeGroupId.text().toString(),
+ artifactId:module.@archetypeArtifactId.text().toString(),
+ version:module.@archetypeVersion.text().toString()]
+ }
+ def searchArchetype( definition, archetypeCatalogs ) {
+ def archetype
+ archetypeCatalogs.each { key, value ->
+ if( !archetype &&
+ definition['groupId'] == value['groupId'] &&
+ definition['artifactId'] == value['artifactId'] &&
+ (definition['version'] ? definition['version'] == value['version'] : true) ) {
+ archetype = value
+ }
+ }
+ if( !archetype ) {
+ log.warn "Archetype ${definition} not found in any catalog"
+ }
+ return archetype
+ }
+}
+
View
13 grarchetype-common/src/main/groovy/org/apache/maven/archetype/file/ArchetypeFileResolver.groovy
@@ -0,0 +1,13 @@
+package org.apache.maven.archetype.file
+
+/**
+ *
+ * @author rafale
+ */
+interface ArchetypeFileResolver {
+ static String ROLE = 'org.apache.maven.archetype.file.ArchetypeFileResolver'
+ def getFiles( moduleOffset, fileset, archetypeResources )
+ def getFile( moduleOffset, filesetDirectory, resource, archetypeZipFile )
+ def getResourcePath( moduleOffset, filesetDirectory, resource )
+}
+
View
43 grarchetype-common/src/main/groovy/org/apache/maven/archetype/file/DefaultArchetypeFileResolver.groovy
@@ -0,0 +1,43 @@
+package org.apache.maven.archetype.file
+import org.codehaus.plexus.logging.AbstractLogEnabled
+import java.util.zip.ZipEntry
+import org.apache.maven.archetype.util.Scanner
+
+/**
+ *
+ * @author rafale
+ * @plexus.component
+ */
+class DefaultArchetypeFileResolver
+extends AbstractLogEnabled
+implements ArchetypeFileResolver {
+
+ def getFiles( moduleOffset, fileset, archetypeResources ) {
+ def resourceStart = "${moduleOffset?moduleOffset+'/':''}${fileset.directory.text().toString()?fileset.directory.text().toString()+'/':''}"
+ def scanner = new Scanner( fileset:fileset )
+// logger.error"START=${resourceStart}"
+ archetypeResources.findAll{ resource ->
+ resource.startsWith resourceStart
+ }.collect{ resource ->
+ resource.replace resourceStart, ''
+ }.findAll{resource ->
+ scanner.match resource
+ }
+ }
+
+ def getFile( moduleOffset, filesetDirectory, resource, archetypeZipFile ) {
+ def resourceZipPath = getResourcePath( moduleOffset, filesetDirectory, resource )
+// logger.error"RES${resourceZipPath}}"
+ try {
+ ZipEntry entry = archetypeZipFile.getEntry( resourceZipPath )
+ return archetypeZipFile.getInputStream( entry )
+ } catch (e) {
+ logger.error "Can not find resource ${resourceZipPath} in archetype sip file"
+ }
+ }
+
+ def getResourcePath( moduleOffset, filesetDirectory, resource ) {
+ "archetype-resources/${moduleOffset?moduleOffset+'/':''}${filesetDirectory?filesetDirectory+'/':''}${resource}".toString()
+ }
+}
+
View
359 ...ype-common/src/main/groovy/org/apache/maven/archetype/generator/AbstractFilesetArchetypeGenerator.groovy
@@ -0,0 +1,359 @@
+package org.apache.maven.archetype.generator
+import org.apache.maven.archetype.ArchetypeGenerationRequest
+import org.apache.maven.archetype.artifact.ArchetypeArtifactManager
+import org.codehaus.plexus.logging.AbstractLogEnabled
+import groovy.text.SimpleTemplateEngine
+import org.apache.maven.archetype.file.ArchetypeFileResolver
+import groovy.xml.StreamingMarkupBuilder
+import groovy.xml.StreamingSAXBuilder
+import groovy.xml.MarkupBuilder
+import org.apache.maven.archetype.pom.PomManager
+import org.apache.maven.model.Model
+import org.apache.maven.model.Parent
+import org.gparallelizer.Asynchronizer
+import org.apache.velocity.runtime.log.LogChute
+import org.apache.velocity.runtime.RuntimeServices
+import org.apache.velocity.app.VelocityEngine
+import org.apache.velocity.VelocityContext
+
+/**
+ *
+ * @author raphaelpieroni
+ */
+abstract class AbstractFilesetArchetypeGenerator
+extends AbstractLogEnabled
+implements FilesetArchetypeGenerator, LogChute {
+
+ /** @plexus.requirement */
+ ArchetypeArtifactManager archetypeArtifactManager
+ /** @plexus.requirement */
+ ArchetypeFileResolver archetypeFileResolver
+ /** @plexus.requirement */
+ PomManager pomManager
+
+ def templateEngine = new SimpleTemplateEngine()
+
+ void generateProject( ArchetypeGenerationRequest request ){
+ def archetypeDescriptor = loadArchetypeDescriptor( request.archetypeFile )
+ def archetypeResources = archetypeArtifactManager.getFilesetArchetypeResources( request.archetypeFile )
+ def archetypeZipFile = archetypeArtifactManager.getArchetypeZipFile( request.archetypeFile )
+ def velocity = getVelocityEngine( request.archetypeFile )
+ def basedirPom = new File( request.outputDirectory, 'pom.xml' )
+ def filterProperties = prepareFilterProperties( request )
+
+logger.error"RESOURCES${archetypeResources}"
+logger.error"this=${this.dump()}"
+ if( !archetypeDescriptor.@partial.toBoolean() ) {
+ logger.info "Processing complete archetype: ${archetypeDescriptor.@name}"
+ def projectOutputDirectory = new File( request.outputDirectory, filterProperties.artifactId )
+
+ if( new File( projectOutputDirectory, 'pom.xml' ).exists() ) throw new Exception( "A project already exists in ${projectOutputDirectory}" )
+
+ def processRequest = [moduleOffset:'',
+ zipModuleOffset:'',
+ archetypeDescriptor:archetypeDescriptor,
+ filterProperties:filterProperties,
+ archetypeResources:archetypeResources,
+ archetypeZipFile:archetypeZipFile,
+ outputDirectory:projectOutputDirectory,
+ updirPom:basedirPom,
+ archetypes:request.archetypes,
+ velocity:velocity
+ ]
+ processProject processRequest
+ } else {
+logger.error "Processing partial archetype: ${archetypeDescriptor.@name} in ${request.outputDirectory}"
+
+ if( !basedirPom.exists() ) throw new Exception( "No project to modify in ${request.outputDirectory}" )
+
+ def processRequest = [moduleOffset:'',
+ zipModuleOffset:'',
+ archetypeDescriptor:archetypeDescriptor,
+ filterProperties:filterProperties,
+ archetypeResources:archetypeResources,
+ archetypeZipFile:archetypeZipFile,
+ outputDirectory:request.outputDirectory,
+ archetypes:request.archetypes,
+ velocity:velocity
+ ]
+ processPartialProject processRequest
+
+ }
+ }
+
+ abstract def loadArchetypeDescriptor( File archetypeFile )
+
+ def getVelocityEngine( File jarFile ){
+ def engine = new VelocityEngine()
+ engine.setProperty VelocityEngine.RUNTIME_LOG_LOGSYSTEM, this
+ engine.setProperty VelocityEngine.RESOURCE_LOADER, 'jar'
+ engine.setProperty 'jar.resource.loader.class', 'org.apache.velocity.runtime.resource.loader.JarResourceLoader'
+ engine.setProperty 'jar.resource.loader.path', "jar:file:${jarFile.path}".toString()
+ engine.init()
+ return engine
+ }
+ void init(RuntimeServices rsvc) {/*println"init ${rsvc}"*/}
+ void log(int level, String message) {/*println"log ${level} ${message}"*/}
+ void log(int level, String message, Throwable t) {/*println "log ${level} ${message} ${t}"*/}
+ boolean isLevelEnabled(int level) {/*println"isLevelEnabled ${level}";*/ return false }
+
+
+ def prepareFilterProperties( request ) {
+logger.error"props ${request.generationFilterProperties}"
+ def filters = request.generationFilterProperties
+ if( !filters.rootArtifactId ) {
+ filters.rootArtifactId = filters.artifactId
+ }
+ filters.upArtifactId = filters.artifactId
+ filters.'package' = filters.packageName
+
+ return filters
+ }
+
+ def processPartialProject( processRequest ) {
+ def pom = mergePom( processRequest )
+ processFilesets processRequest
+ processModules processRequest, pom
+ }
+
+ def processProject( processRequest ) {
+ processRequest.outputDirectory.mkdirs()
+ def pom = processPom( processRequest )
+ processFilesets processRequest
+ processModules processRequest, pom
+ }
+ def processModules( processRequest, pom ) {
+ def moduleOffset = processRequest.moduleOffset
+ def zipModuleOffset = processRequest.zipModuleOffset
+ def outputDirectory = processRequest.outputDirectory
+ def filterProperties = processRequest.filterProperties
+ def upArtifactId = processRequest.filterProperties.artifactId
+ processRequest.archetypeDescriptor.modules.module.each { module ->
+// println"${Thread.currentThread().name} ${module?.dump()}"
+ def artifactId = getOutputName( module.@artifactId.text(), processRequest.filterProperties )
+ def moduleRequest = processRequest.clone()
+ moduleRequest.moduleOffset = "${moduleOffset ? moduleOffset + '/' : ''}${artifactId}"
+ moduleRequest.zipModuleOffset = "${zipModuleOffset ? zipModuleOffset + '/' : ''}${module.@artifactId.text()}"
+ moduleRequest.outputDirectory = new File( outputDirectory, artifactId )
+ moduleRequest.archetypeDescriptor = module
+ moduleRequest.updirPom = pom
+// println"${Thread.currentThread().name} artifactId ${artifactId}"
+// println"${Thread.currentThread().name} moduleRequest.moduleOffset ${moduleRequest.moduleOffset}"
+// println"${Thread.currentThread().name} moduleRequest.outputDirectory ${moduleRequest.outputDirectory}"
+
+ def moduleFilter = filterProperties.clone()
+ moduleFilter.upArtifactId = upArtifactId
+ moduleFilter.artifactId = artifactId
+ moduleRequest.filterProperties = moduleFilter
+
+ if(!module.@nested.toBoolean()){
+ logger.warn "Processing module ${module.@artifactId.text()} in ${moduleRequest.outputDirectory}"
+ processProject moduleRequest
+ } else {
+ def archetype = processRequest.archetypes."${module.@archetypeGroupId.toString()}:${module.@archetypeArtifactId.toString()}:${module.@archetypeVersion.toString()}"
+
+ logger.warn"Processing nested archetype ${module.@archetypeArtifactId.toString()} in ${outputDirectory}"
+ def request = new ArchetypeGenerationRequest()
+ request.archetypes = moduleRequest.archetypes
+ request.archetypeFile = archetype.file
+ request.outputDirectory = outputDirectory
+ moduleRequest.filterProperties.remove 'upArtifactId'
+ moduleRequest.filterProperties.remove 'rootArtifactId'
+ request.generationFilterProperties = moduleRequest.filterProperties
+// request.archetypes = moduleRequest.archetypes
+// request.archetypes = moduleRequest.archetypes
+// request.archetypes = moduleRequest.archetypes
+ archetype.generator.generateProject request
+ }
+ }
+ }
+
+ def mergePom( processRequest ) {
+ def pomFile = new File( processRequest.outputDirectory, 'pom.xml' )
+ Model initialModel = pomManager.loadModel( pomFile )
+
+ StringWriter writer = new StringWriter()
+ processRequest.velocity.mergeTemplate( archetypeFileResolver.getResourcePath( processRequest.zipModuleOffset, '', 'pom.xml' ), new VelocityContext( processRequest.filterProperties ), writer )
+ def slurpedPom = new XmlSlurper().parseText( writer.toString() )
+//logger.error "${Thread.currentThread().name} INITIAL POM ${pomFile}"
+ def pomBuilder = new StreamingMarkupBuilder().bind {
+ mkp.xmlDeclaration()
+ mkp.declareNamespace '':'http://maven.apache.org/POM/4.0.0'
+ mkp.yield slurpedPom
+ }
+ Model newModel = pomManager.loadModel( pomBuilder.toString() )
+
+ pomManager.writeModel pomFile, pomManager.mergeModel( initialModel, newModel )
+
+ return pomFile
+ }
+
+ def processPom( processRequest ) {
+
+ def pomFile = new File( processRequest.outputDirectory, 'pom.xml' )
+//logger.error "${Thread.currentThread().name} Processing POM ${pomFile}"
+ pomFile.parentFile.mkdirs()
+ pomFile.withWriter {
+ it.write archetypeFileResolver.getFile(
+ processRequest.zipModuleOffset, '', 'pom.xml', processRequest.archetypeZipFile
+ ).newReader().text
+ }
+
+// def initialPomFile = archetypeFileResolver.getFile(
+// processRequest.zipModuleOffset, '', 'pom.xml', processRequest.archetypeZipFile
+// ).newReader()
+// def filteredPom = templateEngine.createTemplate( initialPomFile ).
+// make( processRequest.filterProperties )
+ StringWriter writer = new StringWriter()
+ processRequest.velocity.mergeTemplate( archetypeFileResolver.getResourcePath( processRequest.zipModuleOffset, '', 'pom.xml' ), new VelocityContext( processRequest.filterProperties ), writer )
+ def slurpedPom = new XmlSlurper().parseText( writer.toString() )
+//logger.error "${Thread.currentThread().name} INITIAL POM ${pomFile}"
+ def pomBuilder = new StreamingMarkupBuilder().bind {
+ mkp.xmlDeclaration()
+ mkp.declareNamespace '':'http://maven.apache.org/POM/4.0.0'
+ mkp.yield slurpedPom
+ }
+ Model newModel = pomManager.loadModel( pomBuilder.toString() )
+
+ if( processRequest.updirPom?.exists() ) {
+ Model parentModel = pomManager.loadModel( processRequest.updirPom )
+ if( !newModel.parent ) {
+ newModel.parent = new Parent()
+ newModel.parent.groupId = parentModel.groupId
+ newModel.parent.artifactId = parentModel.artifactId
+ newModel.parent.version = parentModel.version
+ }
+//logger.error "MODULES=${parentModel.modules}"
+ if( !parentModel.modules.contains(newModel.artifactId) ) {
+ parentModel.modules << newModel.artifactId
+ pomManager.writeModel processRequest.updirPom, parentModel
+ }
+ }
+
+ pomManager.writeModel pomFile, newModel
+
+ return pomFile
+ }
+
+
+ def processFilesets( processRequest ) {
+
+//logger.error "archetypeDescriptor ${processRequest.archetypeDescriptor.fileSets.dump()}"
+//logger.error "archetypeDescriptor ${processRequest.archetypeDescriptor.fileSets.fileSet.dump()}"
+
+// Asynchronizer.withAsynchronizer {
+ processRequest.archetypeDescriptor.fileSets.fileSet.each/*Async*/ { fileset ->
+//println"A"
+//logger.error"Thread ${Thread.currentThread().name}"
+// logger.error"A${fileset.@filtered.toBoolean()}"
+// logger.error"B${fileset.@packaged.toBoolean()}"
+// logger.error"C${fileset.directory}"
+// logger.error"D${fileset.includes.include.dump()}"
+
+ def filesetResources = archetypeFileResolver.getFiles(
+ processRequest.zipModuleOffset, fileset, processRequest.archetypeResources )
+//println"B"
+//logger.error "FILESET== ${filesetResources}"
+
+ def filesetRequest = processRequest.clone()
+ filesetRequest.filesetResources = filesetResources
+ filesetRequest.packaged = fileset.@packaged.toBoolean()
+ filesetRequest.filesetDirectory = fileset.directory.text().toString()
+ filesetRequest.engine = fileset.@engine?.toString()
+
+//println"C"
+ if( fileset.@filtered.toBoolean() )
+ processFileset filesetRequest
+ else
+ copyFileset filesetRequest
+ }
+// }
+ }
+
+ def processFileset( filesetRequest ) {
+
+println"\n\n\n\n\nD"
+logger.error "Processing Fileset ${filesetRequest.filesetDirectory}"
+// Asynchronizer.withAsynchronizer {
+ VelocityContext context
+ if( 'velocity' == filesetRequest.engine ) context = new VelocityContext( filesetRequest.filterProperties )
+
+ filesetRequest.filesetResources.each { resource ->
+println"E ${resource}"
+ def resourceFile = archetypeFileResolver.getFile(
+ filesetRequest.zipModuleOffset, filesetRequest.filesetDirectory, resource, filesetRequest.archetypeZipFile
+ ).newReader()
+ def text
+ if( 'groovy' == filesetRequest.engine ) {
+ text = templateEngine.createTemplate( resourceFile ).make( filesetRequest.filterProperties )
+println"F"
+ } else {
+ StringWriter writer = new StringWriter()
+ filesetRequest.velocity.mergeTemplate( archetypeFileResolver.getResourcePath( filesetRequest.zipModuleOffset, filesetRequest.filesetDirectory, resource ), context, writer )
+ text = writer.toString()
+println"G"
+ }
+ logger.error "RESULT=\n${text}"
+ def path = getPath( filesetRequest.moduleOffset,
+ filesetRequest.filesetDirectory,
+ filesetRequest.packaged,
+ filesetRequest.filterProperties,
+ resource )
+ def outName = getOutputName( path, filesetRequest.filterProperties )
+ //templateEngine.createTemplate( path ).make( filesetRequest.filterProperties )
+ def outputFile = new File( filesetRequest.outputDirectory, outName.toString() )
+ logger.error "outputFile=${outputFile}"
+ outputFile.parentFile.mkdirs()
+ outputFile.withWriter {
+ it.write text
+ }
+// }
+ }
+println"I"
+ }
+
+ def copyFileset( filesetRequest ) {
+
+//logger.error "Processing Fileset ${filesetRequest.filesetDirectory}"
+// Asynchronizer.withAsynchronizer {
+ filesetRequest.filesetResources.each { resource ->
+ def resourceFile = archetypeFileResolver.getFile(
+ filesetRequest.zipModuleOffset, filesetRequest.filesetDirectory, resource, filesetRequest.archetypeZipFile )
+ def path = getPath( filesetRequest.moduleOffset,
+ filesetRequest.filesetDirectory,
+ filesetRequest.packaged,
+ filesetRequest.filterProperties,
+ resource )
+ def outName = getOutputName( path, filesetRequest.filterProperties )
+ //templateEngine.createTemplate( path ).make( filesetRequest.filterProperties )
+ def outputFile = new File( filesetRequest.outputDirectory, outName.toString() )
+// logger.error "outputFile=${outputFile}"
+ outputFile.parentFile.mkdirs()
+ outputFile.withOutputStream {
+ it << resourceFile
+ }
+ }
+// }
+ }
+
+ def getPath( moduleOffset, filesetDirectory, packaged, filterProperties, resource ) {
+ def offset = moduleOffset ? moduleOffset + '/' : ''
+ def packageName = packaged ? filterProperties.packageName.replace( '.', '/' ) + '/' : ''
+ return "${offset}${filesetDirectory}/${packageName}${resource}"
+ }
+
+
+ def getOutputName( path, filterProperties ) {
+ def outputName = path.toString()
+ def log = "${Thread.currentThread().name} ${outputName}"
+ filterProperties.each { key, value ->
+ outputName = outputName.replaceAll( /\$\{${key}}/, value.toString() )
+ log+= " (${key}=${value.toString()})-> ${outputName}"
+ }
+// println "${log} = ${outputName}"
+ return outputName
+ }
+
+
+}
+
View
14 ...type-common/src/main/groovy/org/apache/maven/archetype/generator/DefaultFilesetArchetypeGenerator.groovy
@@ -0,0 +1,14 @@
+package org.apache.maven.archetype.generator
+
+/**
+ *
+ * @author rafale
+ * @plexus.component role-hint="fileset"
+ */
+class DefaultFilesetArchetypeGenerator
+extends AbstractFilesetArchetypeGenerator {
+ def loadArchetypeDescriptor( File archetypeFile ) {println"DefaultFilesetArchetypeGenerator ${archetypeFile}"
+ new XmlSlurper().parse( archetypeArtifactManager.getFilesetArchetypeDescriptor( archetypeFile ) )
+ }
+}
+
View
100 grarchetype-common/src/main/groovy/org/apache/maven/archetype/generator/DefaultProjectGenerator.groovy
@@ -0,0 +1,100 @@
+package org.apache.maven.archetype.generator
+import org.codehaus.plexus.logging.AbstractLogEnabled
+import org.apache.maven.archetype.ArchetypeGenerationRequest
+import org.apache.maven.archetype.artifact.ArchetypeArtifactManager
+
+/**
+ *
+ * @author raphaelpieroni
+ * @plexus.component
+ */
+class DefaultProjectGenerator
+extends AbstractLogEnabled
+implements ProjectGenerator {
+
+ /** @plexus.requirement */
+ ArchetypeArtifactManager artifactManager
+
+ /** @plexus.requirement role-hint="fileset" */
+ FilesetArchetypeGenerator filesetGenerator
+
+ /** @plexus.requirement role-hint="legacy" */
+ FilesetArchetypeGenerator oldGenerator
+
+ void generateProject( ArchetypeGenerationRequest request ) {
+
+ def mainArchetypeName = "${request.groupId}:${request.artifactId}:${request.version}"
+ logger.info "Generating project from archetype ${mainArchetypeName} into directory ${request.outputDirectory}"
+
+ def mainArchetypeFile = artifactManager.getArchetypeFile(
+ request.groupId, request.artifactId, request.version,
+ request.localRepository, request.repositories )
+println"generateProject ${artifactManager.isLegacyArchetype( mainArchetypeFile )} ${mainArchetypeFile}"
+ if( artifactManager.isLegacyArchetype( mainArchetypeFile ) ) {
+ logger.info "Archetype ${mainArchetypeName} is a legacy archetype"
+ request.archetypeFile = mainArchetypeFile
+
+ oldGenerator.generateProject request
+
+ } else {
+ logger.info "Archetype ${mainArchetypeName} is a fileset archetype"
+ request.archetypeFile = mainArchetypeFile
+
+ def archetypes = [mainArchetypeName:[file:mainArchetypeFile, generator:filesetGenerator]]
+ getNestedArchetypes mainArchetypeFile, archetypes, request.localRepository, request.repositories
+ request.archetypes = archetypes
+
+ logger.info "Found ${archetypes.size()} archetypes to generate the project with"
+ filesetGenerator.generateProject request
+ }
+ }
+
+ void getNestedArchetypes( archetypeFile, archetypes, localRepository, repositories ) {
+ logger.info "Searching for nested archetype of ${archetypeFile}"
+ def descriptor = new XmlSlurper().parse( artifactManager.getFilesetArchetypeDescriptor( archetypeFile ) )
+ def nestedArchetypes = []
+ descriptor.modules.module.each {
+ if( it.@nested.toBoolean() ) {
+ logger.info "Module ${it.@artifactId.toString()} is a nested archetype"
+ addArchetype it, archetypes, nestedArchetypes, localRepository, repositories
+ } else {
+ logger.info "Module ${it.@artifactId.toString()} is a regular module"
+ getInnerArchetypes it, archetypes, nestedArchetypes, localRepository, repositories
+ }
+ }
+ nestedArchetypes.each { nestedFile ->
+ getNestedArchetypes nestedFile, archetypes, localRepository, repositories
+ }
+ }
+
+ void getInnerArchetypes( module, archetypes, nestedArchetypes, localRepository, repositories ) {
+ module.modules.module.each {
+ if( it.@nested.toBoolean() ) {
+ logger.info "Module ${it.@artifactId.toString()} is a nested archetype"
+ addArchetype it, archetypes, nestedArchetypes, localRepository, repositories
+ } else {
+ logger.info "Module ${it.@artifactId.toString()} is a regular module"
+ getInnerArchetypes it, archetypes, nestedArchetypes, localRepository, repositories
+ }
+ }
+ }
+
+ void addArchetype( module, archetypes, nestedArchetypes, localRepository, repositories ) {
+ def moduleFile = artifactManager.getArchetypeFile(
+ module.@archetypeGroupId.toString(),
+ module.@archetypeArtifactId.toString(),
+ module.@archetypeVersion.toString(),
+ localRepository, repositories )
+ def archetypeName = "${module.@archetypeGroupId.toString()}:${module.@archetypeArtifactId.toString()}:${module.@archetypeVersion.toString()}"
+
+ if( artifactManager.isLegacyArchetype( moduleFile ) ) {
+ logger.info "Nested Archetype ${archetypeName} is a legacy archetype"
+ archetypes."${archetypeName}" = [file:moduleFile, generator:oldGenerator]
+ } else {
+ logger.info "Nested Archetype ${archetypeName} is a fileset archetype"
+ archetypes."${archetypeName}" = [file:moduleFile, generator:filesetGenerator]
+ nestedArchetypes << moduleFile
+ }
+ }
+}
+
View
14 grarchetype-common/src/main/groovy/org/apache/maven/archetype/generator/FilesetArchetypeGenerator.groovy
@@ -0,0 +1,14 @@
+package org.apache.maven.archetype.generator
+import org.apache.maven.archetype.ArchetypeGenerationRequest
+
+/**
+ *
+ * @author rafale
+ */
+interface FilesetArchetypeGenerator {
+ static String ROLE = 'org.apache.maven.archetype.generator.FilesetArchetypeGenerator'
+
+ void generateProject( ArchetypeGenerationRequest request )
+
+}
+
View
85 grarchetype-common/src/main/groovy/org/apache/maven/archetype/generator/LegacyGenerator.groovy
@@ -0,0 +1,85 @@
+package org.apache.maven.archetype.generator
+import groovy.xml.MarkupBuilder
+
+/**
+ *
+ * @author raphaelpieroni
+ * @plexus.component role-hint="legacy"
+ */
+class LegacyGenerator
+extends AbstractFilesetArchetypeGenerator {
+ def loadArchetypeDescriptor( File archetypeFile ) {println"LegacyGenerator ${archetypeFile}"
+ def oldDescriptor = new XmlSlurper().parse( archetypeArtifactManager.getLegacyArchetypeDescriptor( archetypeFile ) )
+
+ def filesetDescriptor = new StringWriter()
+ def filesetDescriptorBuilder = new MarkupBuilder( filesetDescriptor )
+
+ filesetDescriptorBuilder.'archetype-descriptor'( name:oldDescriptor.id.toString(), partial:getPartial(oldDescriptor) ) {
+ fileSets {
+ oldDescriptor?.sources?.source.each { source ->
+ fileSet( engine:'velocity', packaged:true, filtered:true ) {
+ directory getSourceDirectory( source.toString() )
+ includes {
+ include getSourcePath( source.toString() )
+ }
+ }
+ }
+ oldDescriptor?.testSources?.source.each { source ->
+ fileSet( engine:'velocity', packaged:true, filtered:true ) {
+ directory getSourceDirectory( source.toString() )
+ includes {
+ include getSourcePath( source.toString() )
+ }
+ }
+ }
+ oldDescriptor?.resources?.resource.each { resource ->
+ fileSet( engine:'velocity', packaged:false, filtered:getFiltered( resource?.@filtered.toString() ) ) {
+ directory getResourceDirectory( resource.toString() )
+ includes {
+ include getResourcePath( resource.toString() )
+ }
+ }
+ }
+ oldDescriptor?.siteResources?.resource.each { resource ->
+ fileSet( engine:'velocity', packaged:false, filtered:getFiltered( resource?.@filtered.toString() ) ) {
+ directory getResourceDirectory( resource.toString() )
+ includes {
+ include getResourcePath( resource.toString() )
+ }
+ }
+ }
+ }
+ }
+
+// filesetDescriptor = filesetDescriptor.toString()
+ logger.error"Using translated descriptor ${filesetDescriptor.toString()}"
+
+ new XmlSlurper().parseText( filesetDescriptor.toString() )
+ }
+
+ def getPartial( oldDescriptor ) {
+ if(oldDescriptor.allowPartial.toString()) return oldDescriptor.allowPartial.toString()
+ return false
+ }
+
+ def getSourceDirectory( source ) {
+ source.substring 0, source.lastIndexOf( 'java/' ) + 4
+ }
+
+ def getResourceDirectory( source ) {
+ source.substring 0, source.lastIndexOf( '/' )
+ }
+
+ def getSourcePath( source ) {
+ source.substring source.lastIndexOf( 'java/' ) + 5
+ }
+
+ def getResourcePath( source ) {
+ source.substring source.lastIndexOf( '/' ) + 1
+ }
+
+ def getFiltered( filtered ) {
+ filtered ? filtered : true
+ }
+}
+
View
14 grarchetype-common/src/main/groovy/org/apache/maven/archetype/generator/ProjectGenerator.groovy
@@ -0,0 +1,14 @@
+package org.apache.maven.archetype.generator
+import org.apache.maven.archetype.ArchetypeGenerationRequest
+
+/**
+ *
+ * @author raphaelpieroni
+ */
+interface ProjectGenerator {
+ static String ROLE = 'org.apache.maven.archetype.generator.ProjectGenerator'
+
+ void generateProject( ArchetypeGenerationRequest request )
+
+}
+
View
265 grarchetype-common/src/main/groovy/org/apache/maven/archetype/pom/DefaultPomManager.groovy
@@ -0,0 +1,265 @@
+package org.apache.maven.archetype.pom
+import org.codehaus.plexus.logging.AbstractLogEnabled
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader
+import org.apache.maven.model.Model
+import org.jdom.input.SAXBuilder
+import org.jdom.Document
+import org.jdom.output.Format
+import org.apache.maven.model.io.jdom.MavenJDOMWriter
+import org.apache.maven.model.Build
+import org.apache.maven.model.Reporting
+import org.apache.maven.model.ModelBase
+import org.apache.maven.model.DependencyManagement
+
+/**
+ *
+ * @author rafale
+ * @plexus.component
+ */
+class DefaultPomManager extends AbstractLogEnabled implements PomManager {
+
+ def loadModel( File pomFile ) {
+ def model
+ pomFile.newReader( "UTF-8" ).withReader {
+ model = new MavenXpp3Reader().read( it, false )
+ }
+ return model
+ }
+
+ def loadModel(String pomString){
+ def model
+ new StringReader( pomString ).withReader {
+ model = new MavenXpp3Reader().read( it, false )
+ }
+ return model
+ }
+
+ void writeModel( File pomFile, Model newModel ) {
+ def pomDocument
+ pomFile.newInputStream().withStream {
+ pomDocument = new SAXBuilder().build( it )
+ }
+
+ def encoding = newModel.modelEncoding?: 'UTF-8'
+ pomFile.newWriter( encoding ).withWriter {
+ new MavenJDOMWriter().write( newModel, pomDocument, it, Format.rawFormat.setEncoding( encoding ) )
+ }
+ }
+
+ def mergeModel( Model initialModel, Model addedModel ) {
+
+ println"merge "+initialModel?.dependencies.dump()
+ println"mergeX "+initialModel?.properties.dump()
+
+
+// // Potential merging
+//
+// initialModel.getModelEncoding (); // keep initial
+// initialModel.getModelVersion (); // keep initial
+//
+// initialModel.getGroupId (); // keep initial
+// initialModel.getArtifactId (); // keep initial
+// initialModel.getVersion (); // keep initial
+// initialModel.getParent (); // keep initial
+//
+// initialModel.getId (); // keep initial
+// initialModel.getName (); // keep initial
+// initialModel.getInceptionYear (); // keep initial
+// initialModel.getDescription (); // keep initial
+// initialModel.getUrl (); // keep initial
+// initialModel.getLicenses (); // keep initial
+// initialModel.getProperties (); // merged
+ mergeProperties initialModel, addedModel
+//
+// initialModel.getOrganization (); // keep initial
+// initialModel.getMailingLists (); // keep initial
+// initialModel.getContributors (); // keep initial
+// initialModel.getDevelopers (); // keep initial
+//
+// initialModel.getScm (); // keep initial
+// initialModel.getCiManagement (); // keep initial
+// initialModel.getDistributionManagement (); // keep initial
+// initialModel.getIssueManagement (); // keep initial
+//
+// initialModel.getPackaging (); // keep initial
+// initialModel.getDependencies (); // merged
+ mergeDependencies initialModel, addedModel
+// initialModel.getDependencyManagement (); // merged
+ mergeDependencyManagement initialModel, addedModel
+// initialModel.getPrerequisites ().getMaven (); // keep initial
+// initialModel.getPrerequisites ().getModelEncoding (); // keep initial
+//
+// initialModel.getModules (); // keep initial
+// initialModel.getRepositories (); // merged
+ mergeRepositories initialModel, addedModel
+// initialModel.getPluginRepositories (); // merged
+ mergePluginRepositories initialModel, addedModel
+//
+// initialModel.getBuild ().getDefaultGoal (); // keep initial
+// initialModel.getBuild ().getFinalName (); // keep initial
+// initialModel.getBuild ().getModelEncoding (); // keep initial
+// initialModel.getBuild ().getFilters ();
+// initialModel.getBuild ().getDirectory (); // keep initial
+// initialModel.getBuild ().getOutputDirectory (); // keep initial
+// initialModel.getBuild ().getSourceDirectory (); // keep initial
+//////// initialModel.getBuild ().getResources ();
+// initialModel.getBuild ().getScriptSourceDirectory (); // keep initial
+// initialModel.getBuild ().getTestOutputDirectory (); // keep initial
+//////// initialModel.getBuild ().getTestResources ();
+// initialModel.getBuild ().getTestSourceDirectory (); // keep initial
+//////// initialModel.getBuild ().getExtensions ();
+// initialModel.getBuild ().getPluginsAsMap (); // merged
+ mergeBuildPlugins initialModel, addedModel
+// initialModel.getBuild ().getPluginManagement (); // merged
+ mergeBuildPluginManagement initialModel, addedModel
+//
+// initialModel.getReporting ().getModelEncoding (); // keep initial
+// initialModel.getReporting ().getOutputDirectory (); // keep initial
+// initialModel.getReporting ().getReportPluginsAsMap (); // merged
+ mergeReportPlugins initialModel, addedModel
+
+//////// initialModel.getProfiles ();
+
+ return initialModel
+ }
+
+ def mergeProperties( Model initialModel, Model addedModel ) {
+ if( !addedModel.properties || !addedModel.properties.size() == 0 ) return
+ if( !initialModel.properties ) initialModel.properties = addedModel.properties
+ else {
+ addedModel.properties.each { key, value ->
+ if( initialModel.properties.containsKey( key ) ) {
+ logger.warn "property $key not over written"
+ } else {
+ initialModel.properties[key] = value
+ }
+ }
+ }
+ }
+
+ def mergeDependencies( Model initialModel, Model addedModel ) {
+ if( !addedModel.dependencies || addedModel.dependencies.size() == 0 ) return
+ if( !initialModel.dependencies ) initialModel.dependencies = addedModel.dependencies
+ else {
+ def initialDependencies = getDependencyMap( initialModel.dependencies )
+ getDependencyMap( addedModel.dependencies ).each { key, dependency ->
+ if( initialDependencies.containsKey( key ) ) {
+ logger.warn "dependency $key not over written"
+ } else {
+ initialModel.dependencies.add dependency
+ }
+ }
+ }
+ }
+ def getDependencyMap( dependencies ) {
+ def map = [:]
+ dependencies.each {
+ map."${it.groupId}:${it.artifactId}" = it
+ }
+ return map
+ }
+
+ def mergeDependencyManagement( Model initialModel, Model addedModel ) {
+ if( !addedModel.dependencyManagement ||
+ !addedModel.dependencyManagement.dependencies ||
+ addedModel.dependencyManagement.dependencies.size() == 0 ) return
+ if( !initialModel.dependencyManagement ) initialModel.dependencyManagement = new DependencyManagement()
+ if( !initialModel.dependencyManagement.dependencies ) initialModel.dependencyManagement.dependencies = addedModel.dependencyManagement.dependencies
+ else {
+ def initialDependencies = getDependencyMap( initialModel.dependencyManagement.dependencies )
+ getDependencyMap( addedModel.dependencyManagement.dependencies ).each { key, dependency ->
+ if( initialDependencies.containsKey( key ) ) {
+ logger.warn "dependency $key in dependencyManagement not over written"
+ } else {
+ initialModel.dependencyManagement.dependencies.add dependency
+ }
+ }
+ }
+ }
+
+ def mergeRepositories( Model initialModel, Model addedModel ) {
+ if( !addedModel.repositories || addedModel.repositories.size() == 0 ) return
+ if( !initialModel.repositories ) initialModel.repositories = addedModel.repositories
+ else {
+ def initialRepositories = getRepositoryMap( initialModel.repositories )
+ getRepositoryMap( addedModel.repositories ).each { key, repository ->
+ if( initialRepositories.containsKey( key ) ) {
+ logger.warn "repository $key not over written"
+ } else {
+ initialModel.repositories.add repository
+ }
+ }
+ }
+ }
+ def getRepositoryMap( repositories ) {
+ def map = [:]
+ repositories.each {
+ map."${it.id}" = it
+ }
+ return map
+ }
+
+ def mergePluginRepositories( Model initialModel, Model addedModel ) {
+ if( !addedModel.pluginRepositories || addedModel.pluginRepositories.size() == 0 ) return
+ if( !initialModel.pluginRepositories ) initialModel.pluginRepositories = addedModel.pluginRepositories
+ else {
+ def initialPluginRepositories = getRepositoryMap( initialModel.pluginRepositories )
+ getRepositoryMap( addedModel.pluginRepositories ).each { key, pluginRepository ->
+ if( initialPluginRepositories.containsKey( key ) ) {
+ logger.warn "pluginRepository $key not over written"
+ } else {
+ initialModel.pluginRepositories.add pluginRepository
+ }
+ }
+ }
+ }
+
+ def mergeBuildPlugins( Model initialModel, Model addedModel ) {
+ if( !addedModel.build ) return
+ if( !addedModel.build.pluginsAsMap || addedModel.build.pluginsAsMap.size() == 0 ) return
+ if( !initialModel.build ) initialModel.build = new Build()
+ def initialPlugins = initialModel.build?.pluginsAsMap?:[:]
+ addedModel.build.pluginsAsMap.each { key, plugin ->
+ if( initialPlugins.containsKey( key ) ) {
+ logger.warn "plugin $key not over written"
+ } else {
+ initialModel.build.addPlugin plugin
+ }
+ }
+ }
+
+ def mergeBuildPluginManagement( Model initialModel, Model addedModel ) {
+ if( !addedModel.build ) return
+ if( !addedModel.build.pluginManagement ) return
+ if( !addedModel.build.pluginManagement.plugins || addedModel.build.pluginManagement.plugins.size() == 0 ) return
+ if( !initialModel.build ) initialModel.build = new Build()
+ if( !initialModel.build.pluginManagement ) initialModel.build.pluginManagement = addedModel.build.pluginManagement
+ else {
+ def initialPlugins = getDependencyMap( initialModel.build.pluginManagement.plugins )
+ getDependencyMap( addedModel.build.pluginManagement.plugins ).each { key, plugin ->
+ if( initialPlugins.containsKey( key ) ) {
+ logger.warn "plugin $key in pluginManagement not over written"
+ } else {
+ initialModel.build.pluginManagement.plugins.add plugin
+ }
+ }
+ }
+
+ }
+
+ def mergeReportPlugins( Model initialModel, Model addedModel ) {
+ if( !addedModel.reporting ) return
+ if( !addedModel.reporting.reportPluginsAsMap || addedModel.reporting.reportPluginsAsMap.size() == 0 ) return
+ if( !initialModel.reporting ) initialModel.reporting = new Reporting()
+ def initialReportPlugins = initialModel.reporting.reportPluginsAsMap?:[:]
+
+ addedModel.reporting.reportPluginsAsMap.each { key, plugin ->
+ if( initialReportPlugins.containsKey( key ) ) {
+ logger.warn "report plugin $key not over written"
+ } else {
+ initialModel.reporting.addPlugin plugin
+ }
+ }
+ }
+}
+
View
16 grarchetype-common/src/main/groovy/org/apache/maven/archetype/pom/PomManager.groovy
@@ -0,0 +1,16 @@
+package org.apache.maven.archetype.pom
+import org.apache.maven.model.Model
+
+/**
+ *
+ * @author rafale
+ */
+interface PomManager {
+ String ROLE = 'org.apache.maven.archetype.pom.PomManager'
+
+ def loadModel( File pomFile )
+ def loadModel( String pomString )
+ void writeModel( File pomFile, Model newModel )
+ def mergeModel( Model initialModel, Model addedModel )
+}
+
View
52 grarchetype-common/src/main/groovy/org/apache/maven/archetype/util/DefaultRepositoryCreator.groovy
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2009 raphaelpieroni.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * under the License.
+ */
+
+package org.apache.maven.archetype.util
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy
+import org.codehaus.plexus.logging.AbstractLogEnabled
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout
+import org.apache.maven.artifact.repository.DefaultArtifactRepository
+
+/**
+ *
+ * @author raphaelpieroni
+ * @plexus.component
+ */
+class DefaultRepositoryCreator
+extends AbstractLogEnabled
+implements RepositoryCreator{
+
+ /** @plexus.requirement */
+ private ArtifactRepositoryFactory artifactRepositoryFactory
+
+ /** @plexus.requirement roleHint="default" */
+ private ArtifactRepositoryLayout defaultArtifactRepositoryLayout
+
+ def createRepository( String repository ) {
+ String updatePolicyFlag = ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS
+ String checksumPolicyFlag = ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN
+ return artifactRepositoryFactory.createArtifactRepository(
+ "archetype-repository",
+ repository,
+ defaultArtifactRepositoryLayout,
+ new ArtifactRepositoryPolicy( true, updatePolicyFlag, checksumPolicyFlag ),
+ new ArtifactRepositoryPolicy( true, updatePolicyFlag, checksumPolicyFlag )
+ )
+ }
+}
+
View
12 grarchetype-common/src/main/groovy/org/apache/maven/archetype/util/RepositoryCreator.groovy
@@ -0,0 +1,12 @@
+package org.apache.maven.archetype.util
+
+/**
+ *
+ * @author raphaelpieroni
+ */
+interface RepositoryCreator {
+ static String ROLE = 'org.apache.maven.archetype.util.RepositoryCreator'
+
+ def createRepository( String repository )
+}
+
View
31 grarchetype-common/src/main/groovy/org/apache/maven/archetype/util/Scanner.groovy
@@ -0,0 +1,31 @@
+package org.apache.maven.archetype.util
+import org.codehaus.plexus.util.SelectorUtils
+
+/**
+ *
+ * @author rafale
+ */
+class Scanner {
+ def fileset
+
+ def match( path ) {
+ included( path ) && !excluded( path )
+ }
+ def included( path ) {
+ matchPatterns( path, fileset.includes.include )
+ }
+ def excluded( path ) {
+ matchPatterns( path, fileset.excludes.exclude )
+ }
+ def matchPatterns( path, patterns ) {
+ def found = false
+ patterns.each{ pattern ->
+ found = found || matchPattern( path, pattern.text().toString() )
+ }
+ return found
+ }
+ def matchPattern( path, pattern ) {
+ SelectorUtils.matchPath pattern, path, true
+ }
+}
+
View
44 grarchetype-common/src/main/groovy/org/gparallelizer/AsyncException.groovy
@@ -0,0 +1,44 @@
+package org.gparallelizer
+
+import java.util.List
+
+/**
+ * This class wraps multiple exception, which occured in concurrently run code inside one of the <i>AsyncInvokerUtil</i> methods.
+ * @see AsyncInvokerUtil
+ *
+ * @author Vaclav Pech
+ * Date: Nov 17, 2008
+ */
+public class AsyncException extends RuntimeException {
+ final List<Throwable> concurrentExceptions
+
+ public AsyncException(String message, List<Throwable> concurrentExceptions) {
+ super(message)
+ this.concurrentExceptions = concurrentExceptions
+ }
+
+ public List<Throwable> getConcurrentExceptions() {
+ return concurrentExceptions
+ }
+
+ @Override
+ public String getMessage() {
+ return "${super.getMessage()} ${buildMessage()}"
+ }
+
+ @Override
+ public String toString() {
+ return buildMessage()
+ }
+
+ private String buildMessage() {
+ final StringBuilder sb = new StringBuilder()
+ sb.append("${Thread.currentThread().name} AsyncException")
+ sb.append("{concurrentExceptions=").append("[\n")
+ concurrentExceptions.each {
+ sb.append(it.toString()).append("\n")
+ }
+ sb.append("]}")
+ return sb.toString()
+ }
+}
View
253 grarchetype-common/src/main/groovy/org/gparallelizer/AsyncInvokerUtil.groovy
@@ -0,0 +1,253 @@
+package org.gparallelizer
+
+import java.util.concurrent.Callable
+import java.util.concurrent.CountDownLatch
+import java.util.concurrent.ExecutorService
+import java.util.concurrent.Future
+import java.util.concurrent.atomic.AtomicBoolean
+import java.lang.Thread.UncaughtExceptionHandler
+
+/**
+ * This class forms the core of the DSL initialized by <i>Asynchronizer</i>. The static methods of <i>AsyncInvokerUtil</i>
+ * get attached to their first arguments (the Groovy Category mechanism) and can be then invoked as if they were part of
+ * the argument classes.
+ * @see org.gparallelizer.Asynchronizer
+ *
+ * @author Vaclav Pech