You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Matthias Epheser (JIRA)" <ji...@apache.org> on 2010/04/22 17:49:50 UTC

[jira] Created: (SOLR-1888) Annotated beans source generation with maven plugin

Annotated beans source generation with maven plugin
---------------------------------------------------

                 Key: SOLR-1888
                 URL: https://issues.apache.org/jira/browse/SOLR-1888
             Project: Solr
          Issue Type: New Feature
          Components: clients - java
    Affects Versions: 1.5
         Environment: java, maven
            Reporter: Matthias Epheser
             Fix For: 1.5


As I stumbled over a lot of copy pasting while creating java annotated beans representing a schema.xml, i decided to make a shortcut and create a maven plugin.

Think about it as source generation similar to castor/jaxb code generation from an xsd. You just point to a schema.xml and connect to the generate-sources phase. This leads to a java bean in target/generated-sources/solr that contains all fields from the schema well annotated. 

The mapping reads the <fields> section and maps field="string" to solr.StringField to java.lang String etc. Multivalured fields generate lists, dynamic fields Maps. Currently the code generation is plain simple, just a fileWriter with some intends. The getValidJavaName(String name) may act more professional than now.

Just install the plugin contained in the zip using mvn install and connect it to an existing solrj project:

{{
<plugin>
	     <groupId>org.apache.solr</groupId>
	     <artifactId>maven-solr-plugin</artifactId>
	     <configuration>
	       <schemaFile>test-data/solr/conf/schema.xml</schemaFile>
	       <qualifiedName>org.test.MyBean</qualifiedName>
	     </configuration>
	     <executions>
          <execution>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
 </plugin>
}}

The generated fiels will be automatically added to the classpath after the first run of mvn generate/compile. So just execute mvn eclipse:eclipse once after that. After every change in the schema, generate again and your bean will be updated and fields and getters and setters will be present.
 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


[jira] Updated: (SOLR-1888) Annotated beans source generation with maven plugin

Posted by "Matthias Epheser (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SOLR-1888?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matthias Epheser updated SOLR-1888:
-----------------------------------

    Attachment: maven-solr-plugin.zip

> Annotated beans source generation with maven plugin
> ---------------------------------------------------
>
>                 Key: SOLR-1888
>                 URL: https://issues.apache.org/jira/browse/SOLR-1888
>             Project: Solr
>          Issue Type: New Feature
>          Components: clients - java
>    Affects Versions: 1.5
>         Environment: java, maven
>            Reporter: Matthias Epheser
>             Fix For: 1.5
>
>         Attachments: maven-solr-plugin.zip
>
>
> As I stumbled over a lot of copy pasting while creating java annotated beans representing a schema.xml, i decided to make a shortcut and create a maven plugin.
> Think about it as source generation similar to castor/jaxb code generation from an xsd. You just point to a schema.xml and connect to the generate-sources phase. This leads to a java bean in target/generated-sources/solr that contains all fields from the schema well annotated. 
> The mapping reads the <fields> section and maps field="string" to solr.StringField to java.lang String etc. Multivalured fields generate lists, dynamic fields Maps. Currently the code generation is plain simple, just a fileWriter with some intends. The getValidJavaName(String name) may act more professional than now.
> Just install the plugin contained in the zip using mvn install and connect it to an existing solrj project:
> {{
> <plugin>
> 	     <groupId>org.apache.solr</groupId>
> 	     <artifactId>maven-solr-plugin</artifactId>
> 	     <configuration>
> 	       <schemaFile>test-data/solr/conf/schema.xml</schemaFile>
> 	       <qualifiedName>org.test.MyBean</qualifiedName>
> 	     </configuration>
> 	     <executions>
>           <execution>
>             <phase>generate-sources</phase>
>             <goals>
>               <goal>generate</goal>
>             </goals>
>           </execution>
>         </executions>
>  </plugin>
> }}
> The generated fiels will be automatically added to the classpath after the first run of mvn generate/compile. So just execute mvn eclipse:eclipse once after that. After every change in the schema, generate again and your bean will be updated and fields and getters and setters will be present.
>  

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org