You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:14:35 UTC

[sling-maven-jcrocm-plugin] 01/32: Import initial Sling source

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag maven-jcrocm-plugin-2.0.2-incubator
in repository https://gitbox.apache.org/repos/asf/sling-maven-jcrocm-plugin.git

commit 25fa8d7ed54c685e40cfad4ea5c79306d1dfc4e1
Author: Felix Meschberger <fm...@apache.org>
AuthorDate: Mon Sep 10 08:50:41 2007 +0000

    Import initial Sling source
    
    git-svn-id: https://svn.apache.org/repos/asf/incubator/sling/trunk/maven-jcrocm-plugin@574179 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |  85 +++++++
 .../maven/jcrocm/AbstractDescriptorElement.java    |  67 ++++++
 .../sling/maven/jcrocm/AbstractItemDescriptor.java | 123 ++++++++++
 .../sling/maven/jcrocm/AbstractNodeDescriptor.java | 106 +++++++++
 .../apache/sling/maven/jcrocm/BeanDescriptor.java  | 121 ++++++++++
 .../apache/sling/maven/jcrocm/ClassDescriptor.java | 252 +++++++++++++++++++++
 .../sling/maven/jcrocm/CollectionDescriptor.java   | 138 +++++++++++
 .../apache/sling/maven/jcrocm/FieldDescriptor.java | 197 ++++++++++++++++
 .../org/apache/sling/maven/jcrocm/JcrOcmMojo.java  | 235 +++++++++++++++++++
 .../org/apache/sling/maven/jcrocm/XMLWriter.java   | 100 ++++++++
 src/main/resources/META-INF/LICENSE                | 202 +++++++++++++++++
 src/main/resources/META-INF/NOTICE                 |   8 +
 12 files changed, 1634 insertions(+)

diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..c5fa81b
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+	Copyright 2007 The Apache Software Foundation.
+	
+	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.
+-->
+<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.sling</groupId>
+		<artifactId>sling</artifactId>
+		<version>1-incubator-SNAPSHOT</version>
+		<relativePath>../parent/pom.xml</relativePath>
+	</parent>
+
+	<artifactId>maven-jcrocm-plugin</artifactId>
+	<version>2.0.0-incubator-SNAPSHOT</version>
+	<packaging>maven-plugin</packaging>
+
+	<name>
+		Sling - Maven Plugin to create Jackrabbit OCM descriptors
+	</name>
+	<description>
+		The Maven JcrOCM Plugin supports extracting and generation of
+		Jackrabbit OCM descriptors from JavaDoc tags embedded in the
+		Java Classes contained in the project sources
+	</description>
+
+	<scm>
+		<url>
+			http://svn.day.com/repos/sling/trunk/maven-jcrocm-plugin
+		</url>
+		<connection>
+			scm:svn:${scm.url}
+		</connection>
+		<developerConnection>
+			scm:svn:${scm.url}
+		</developerConnection>
+	</scm>
+
+	<reporting>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-plugin-plugin</artifactId>
+			</plugin>
+		</plugins>
+	</reporting>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.maven</groupId>
+			<artifactId>maven-plugin-api</artifactId>
+			<version>2.0</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.maven</groupId>
+			<artifactId>maven-artifact</artifactId>
+			<version>2.0</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.maven</groupId>
+			<artifactId>maven-project</artifactId>
+			<version>2.0</version>
+		</dependency>
+
+		<dependency>
+			<groupId>qdox</groupId>
+			<artifactId>qdox</artifactId>
+			<version>1.6.1</version>
+		</dependency>
+	</dependencies>
+</project>
diff --git a/src/main/java/org/apache/sling/maven/jcrocm/AbstractDescriptorElement.java b/src/main/java/org/apache/sling/maven/jcrocm/AbstractDescriptorElement.java
new file mode 100644
index 0000000..d465d44
--- /dev/null
+++ b/src/main/java/org/apache/sling/maven/jcrocm/AbstractDescriptorElement.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+package org.apache.sling.maven.jcrocm;
+
+import org.apache.maven.plugin.logging.Log;
+
+import com.thoughtworks.qdox.model.AbstractJavaEntity;
+import com.thoughtworks.qdox.model.DocletTag;
+import com.thoughtworks.qdox.model.JavaClass;
+import com.thoughtworks.qdox.model.JavaClassParent;
+
+/**
+ * The <code>AbstractDescriptorElement</code> serves as the base class for the
+ * descriptor objects read from the Doclet tags.
+ */
+abstract class AbstractDescriptorElement {
+
+    private final Log log;
+
+    protected final DocletTag tag;
+
+    protected AbstractDescriptorElement(Log log, DocletTag tag) {
+        this.log = log;
+        this.tag = tag;
+    }
+
+    abstract boolean validate();
+
+    abstract void generate(XMLWriter xmlWriter);
+
+    JavaClass getJavaClass() {
+        AbstractJavaEntity aje = tag.getContext();
+        if (aje instanceof JavaClass) {
+            return (JavaClass) aje;
+        }
+
+        JavaClassParent parent = aje.getParent();
+        if (parent instanceof JavaClass) {
+            return (JavaClass) parent;
+        }
+
+        return null;
+    }
+
+    protected void log(String message) {
+        log.error("@" + tag.getName() + ": " + message + " ("
+            + tag.getContext().getSource().getURL() + ", line "
+            + tag.getLineNumber() + ")");
+    }
+
+    protected void warn(String message) {
+        log.warn(message);
+    }
+}
diff --git a/src/main/java/org/apache/sling/maven/jcrocm/AbstractItemDescriptor.java b/src/main/java/org/apache/sling/maven/jcrocm/AbstractItemDescriptor.java
new file mode 100644
index 0000000..821268e
--- /dev/null
+++ b/src/main/java/org/apache/sling/maven/jcrocm/AbstractItemDescriptor.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+package org.apache.sling.maven.jcrocm;
+
+import org.apache.maven.plugin.logging.Log;
+
+import com.thoughtworks.qdox.model.DocletTag;
+import com.thoughtworks.qdox.model.JavaMethod;
+
+/**
+ * The <code>AbstractItemDescriptor</code> is the base class for the field,
+ * bean and collection descriptors providing support for the common
+ * configuration elements.
+ */
+abstract class AbstractItemDescriptor extends AbstractDescriptorElement {
+
+    /**
+     * The name of the Doclet Tag attribute naming the field to which the
+     * descriptor applies (value is "fieldName").
+     */
+    public static final String FIELD_NAME = "fieldName";
+
+    /**
+     * The name of the Doclet Tag attribute naming the JCR item to which the
+     * descriptor applies (value is "jcrName").
+     */
+    public static final String JCR_NAME = "jcrName";
+
+    /**
+     * The name of the Doclet Tag attribute naming the field to which the
+     * descriptor applies (value is "fieldName").
+     */
+    public static final String JCR_AUTO_CREATED = "jcrAutoCreated";
+
+    public static final String JCR_MANDATORY = "jcrMandatory";
+
+    public static final String JCR_ON_PARENT_VERSION = "jcrOnParentVersion";
+
+    public static final String JCR_PROTECTED = "jcrProtected";
+
+    private String fieldName;
+
+    private String jcrName;
+
+    private boolean isJcrAutoCreated;
+
+    private boolean isJcrMandatory;
+
+    private String jcrOnParentVersion;
+
+    private boolean isJcrProtected;
+
+    /**
+     * @param log
+     * @param tag
+     */
+    public AbstractItemDescriptor(Log log, DocletTag tag, String fieldName) {
+        super(log, tag);
+
+        this.fieldName = fieldName;
+        jcrName = tag.getNamedParameter(JCR_NAME);
+        isJcrAutoCreated = Boolean.valueOf(
+            tag.getNamedParameter(JCR_AUTO_CREATED)).booleanValue();
+        isJcrMandatory = Boolean.valueOf(tag.getNamedParameter(JCR_MANDATORY)).booleanValue();
+        jcrOnParentVersion = tag.getNamedParameter(JCR_ON_PARENT_VERSION);
+        isJcrProtected = Boolean.valueOf(tag.getNamedParameter(JCR_PROTECTED)).booleanValue();
+    }
+
+    void generate(XMLWriter xmlWriter) {
+        xmlWriter.printAttribute(FIELD_NAME, fieldName);
+        xmlWriter.printAttribute(JCR_NAME, jcrName);
+        xmlWriter.printAttribute(JCR_AUTO_CREATED, isJcrAutoCreated);
+        xmlWriter.printAttribute(JCR_MANDATORY, isJcrMandatory);
+        xmlWriter.printAttribute(JCR_ON_PARENT_VERSION, jcrOnParentVersion);
+        xmlWriter.printAttribute(JCR_PROTECTED, isJcrProtected);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.sling.maven.jcrocm.AbstractDescriptorElement#validate()
+     */
+    boolean validate() {
+        boolean valid = true;
+
+        if (jcrOnParentVersion != null) {
+            if (!jcrOnParentVersion.equals("COPY")
+                && !jcrOnParentVersion.equals("VERSION")
+                && !jcrOnParentVersion.equals("INITIALIZE")
+                && !jcrOnParentVersion.equals("COMPUTE")
+                && !jcrOnParentVersion.equals("IGNORE")
+                && !jcrOnParentVersion.equals("ABORT")) {
+                log("Invalid JCR Field OnParentVersion: " + jcrOnParentVersion);
+                valid = false;
+            }
+        }
+
+        return valid;
+    }
+
+    static String getFieldFromMethod(JavaMethod method) {
+        String fieldName = method.getName();
+        if ((fieldName.startsWith("get") || fieldName.startsWith("set"))
+            && fieldName.length() >= 4) {
+            fieldName = Character.toLowerCase(fieldName.charAt(3))
+                + fieldName.substring(4);
+        }
+        return fieldName;
+    }
+}
diff --git a/src/main/java/org/apache/sling/maven/jcrocm/AbstractNodeDescriptor.java b/src/main/java/org/apache/sling/maven/jcrocm/AbstractNodeDescriptor.java
new file mode 100644
index 0000000..d5a1ed1
--- /dev/null
+++ b/src/main/java/org/apache/sling/maven/jcrocm/AbstractNodeDescriptor.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+package org.apache.sling.maven.jcrocm;
+
+import org.apache.maven.plugin.logging.Log;
+
+import com.thoughtworks.qdox.model.DocletTag;
+
+/**
+ * The <code>AbstractNodeDescriptor</code> is the base class for mostly node
+ * based descriptors (bean, collection).
+ */
+public class AbstractNodeDescriptor extends AbstractItemDescriptor {
+
+    public static final String PROXY = "proxy";
+
+    public static final String AUTO_RETRIEVE = "autoRetrieve";
+
+    public static final String AUTO_UPDATE = "autoUpdate";
+
+    public static final String AUTO_INSERT = "autoInsert";
+
+    public static final String JCR_NODE_TYPE = "jcrNodeType";
+
+    public static final String JCR_SAME_NAME_SIBBLINGS = "jcrSameNameSiblings";
+
+    private boolean isProxy = true;
+
+    private boolean isAutoRetrieve = true;
+
+    private boolean isAutoUpdate = true;
+
+    private boolean isAutoInsert = true;
+
+    private String jcrNodeType;
+
+    private boolean isJcrSameNameSibblings;
+
+    /**
+     * @param log
+     * @param tag
+     */
+    public AbstractNodeDescriptor(Log log, DocletTag tag, String fieldName) {
+        super(log, tag, fieldName);
+
+        jcrNodeType = tag.getNamedParameter(JCR_NODE_TYPE);
+        isJcrSameNameSibblings = Boolean.valueOf(
+            tag.getNamedParameter(JCR_SAME_NAME_SIBBLINGS)).booleanValue();
+
+        if (tag.getNamedParameter(PROXY) != null) {
+            isProxy = Boolean.valueOf(tag.getNamedParameter(PROXY)).booleanValue();
+        }
+        if (tag.getNamedParameter(AUTO_RETRIEVE) != null) {
+            isAutoRetrieve = Boolean.valueOf(
+                tag.getNamedParameter(AUTO_RETRIEVE)).booleanValue();
+        }
+        if (tag.getNamedParameter(AUTO_UPDATE) != null) {
+            isAutoUpdate = Boolean.valueOf(tag.getNamedParameter(AUTO_UPDATE)).booleanValue();
+        }
+        if (tag.getNamedParameter(AUTO_INSERT) != null) {
+            isAutoInsert = Boolean.valueOf(tag.getNamedParameter(AUTO_INSERT)).booleanValue();
+        }
+    }
+
+    void generate(XMLWriter xmlWriter) {
+        super.generate(xmlWriter);
+
+        xmlWriter.printAttribute(JCR_NODE_TYPE, jcrNodeType);
+        xmlWriter.printAttribute(JCR_SAME_NAME_SIBBLINGS,
+            isJcrSameNameSibblings);
+
+        if (!isProxy) {
+            xmlWriter.printAttribute(PROXY, "false");
+        }
+        if (!isAutoRetrieve) {
+            xmlWriter.printAttribute(AUTO_RETRIEVE, "false");
+        }
+        if (!isAutoUpdate) {
+            xmlWriter.printAttribute(AUTO_UPDATE, "false");
+        }
+        if (!isAutoInsert) {
+            xmlWriter.printAttribute(AUTO_INSERT, "false");
+        }
+    }
+
+    boolean validate() {
+        boolean valid = super.validate();
+
+        // do additional validation
+
+        return valid;
+    }
+}
diff --git a/src/main/java/org/apache/sling/maven/jcrocm/BeanDescriptor.java b/src/main/java/org/apache/sling/maven/jcrocm/BeanDescriptor.java
new file mode 100644
index 0000000..1f3acbb
--- /dev/null
+++ b/src/main/java/org/apache/sling/maven/jcrocm/BeanDescriptor.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+package org.apache.sling.maven.jcrocm;
+
+import org.apache.maven.plugin.logging.Log;
+
+import com.thoughtworks.qdox.model.DocletTag;
+import com.thoughtworks.qdox.model.JavaField;
+import com.thoughtworks.qdox.model.JavaMethod;
+
+/**
+ * The <code>BeanDescriptor</code> class provides support for the
+ * bean-descriptor element of a class mapping, which has the following attribute
+ * list definition:
+ * 
+ * <pre>
+ *   &lt;!ATTLIST bean-descriptor
+ *       fieldName CDATA #REQUIRED
+ *       jcrName CDATA #IMPLIED 
+ *       proxy (true | false) &quot;false&quot; 
+ *       autoRetrieve (true|false) &quot;true&quot;
+ *       autoUpdate (true|false) &quot;true&quot;
+ *       autoInsert (true|false) &quot;true&quot;  
+ *       converter CDATA #IMPLIED
+ *       jcrNodeType CDATA #IMPLIED
+ *       jcrAutoCreated (true | false) &quot;false&quot;   
+ *       jcrMandatory (true | false) &quot;false&quot;
+ *       jcrOnParentVersion (COPY | VERSION | INITIALIZE | COMPUTE | IGNORE | ABORT) &quot;COPY&quot;
+ *       jcrProtected (true | false) &quot;false&quot;
+ *       jcrSameNameSiblings (true | false) &quot;false&quot;         
+ *   &gt;
+ * </pre>
+ */
+public class BeanDescriptor extends AbstractNodeDescriptor {
+
+    public static final String TAG_BEAN_DESCRIPTOR = "ocm.bean";
+
+    public static final String CONVERTER = "converter";
+
+    public static final String ELEMENT_BEAN_DESCRIPTOR = "bean-descriptor";
+
+    private String converter;
+
+    static BeanDescriptor fromField(Log log, JavaField field) {
+
+        DocletTag tag = field.getTagByName(TAG_BEAN_DESCRIPTOR);
+        if (tag == null) {
+            return null;
+        }
+
+        return new BeanDescriptor(log, tag, field.getName());
+    }
+
+    static BeanDescriptor fromMethod(Log log, JavaMethod method) {
+
+        DocletTag tag = method.getTagByName(TAG_BEAN_DESCRIPTOR);
+        if (tag == null) {
+            return null;
+        }
+
+        // field name is the method name, unless overwritten with the fieldName
+        // tag
+        String fieldName = tag.getNamedParameter(FIELD_NAME);
+        if (fieldName == null) {
+            fieldName = getFieldFromMethod(method);
+        }
+
+        return new BeanDescriptor(log, tag, fieldName);
+    }
+
+    /**
+     * @param log
+     * @param tag
+     */
+    private BeanDescriptor(Log log, DocletTag tag, String fieldName) {
+        super(log, tag, fieldName);
+
+        converter = tag.getNamedParameter(CONVERTER);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.sling.maven.jcrocm.AbstractDescriptorElement#generate(org.apache.sling.maven.jcrocm.XMLWriter)
+     */
+    void generate(XMLWriter xmlWriter) {
+        xmlWriter.printElementStart(ELEMENT_BEAN_DESCRIPTOR, true);
+        super.generate(xmlWriter);
+
+        xmlWriter.printAttribute(CONVERTER, converter);
+
+        xmlWriter.printElementStartClose(true);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.sling.maven.jcrocm.AbstractDescriptorElement#validate()
+     */
+    boolean validate() {
+        boolean valid = super.validate();
+
+        // do additional validation
+
+        return valid;
+    }
+
+}
diff --git a/src/main/java/org/apache/sling/maven/jcrocm/ClassDescriptor.java b/src/main/java/org/apache/sling/maven/jcrocm/ClassDescriptor.java
new file mode 100644
index 0000000..574d756
--- /dev/null
+++ b/src/main/java/org/apache/sling/maven/jcrocm/ClassDescriptor.java
@@ -0,0 +1,252 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+package org.apache.sling.maven.jcrocm;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.apache.maven.plugin.logging.Log;
+
+import com.thoughtworks.qdox.model.DocletTag;
+import com.thoughtworks.qdox.model.JavaClass;
+
+/**
+ * The <code>ClassDescriptor</code> class provides support for the
+ * class-descriptor element of a class mapping, which has the following
+ * attribute list definition:
+ * 
+ * <pre>
+ *  &lt;!ATTLIST class-descriptor
+ *      className CDATA #REQUIRED
+ *      jcrNodeType CDATA #IMPLIED
+ *      jcrSuperTypes CDATA #IMPLIED
+ *      jcrMixinTypes CDATA #IMPLIED
+ *      extend CDATA #IMPLIED
+ *      abstract (true|false) &quot;false&quot;
+ *      interface (true|false) &quot;false&quot;
+ *      discriminator (true|false) &quot;true&quot;
+ *  &gt;
+ *  &lt;!ATTLIST implement-descriptor
+ *      interfaceName CDATA #REQUIRED
+ *  &gt;
+ * </pre>
+ * 
+ * <p>
+ * Additionally, as can be seen from above, the
+ * <code>implement-descriptor</code> is also supported by this class. It
+ * retrieves the list of interfaces from the described class.
+ * </p>
+ */
+public class ClassDescriptor extends AbstractDescriptorElement {
+
+    public static final String TAG_CLASS_DESCRIPTOR = "ocm.mapped";
+
+    public static final String ELEMENT_CLASS_DESCRIPTOR = "class-descriptor";
+
+    public static final String CLASS_NAME = "className";
+
+    public static final String JCR_NODE_TYPE = "jcrNodeType";
+
+    public static final String JCR_SUPER_TYPES = "jcrSuperTypes";
+
+    public static final String JCR_MIXIN_TYPES = "jcrMixinTypes";
+
+    public static final String EXTEND = "extend";
+    
+    public static final String INTERFACES = "interfaces";
+
+    public static final String ABSTRACT = "abstract";
+
+    public static final String INTERFACE = "interface";
+
+    public static final String DISCRIMINATOR = "discriminator";
+
+    public static final String ELEMENT_IMPLEMENT_DESCRIPTOR = "implement-descriptor";
+
+    public static final String INTERFACE_NAME = "interfaceName";
+
+    private String className;
+
+    private String jcrNodeType;
+
+    private String jcrSuperTypes;
+
+    private String jcrMixinTypes;
+
+    private boolean discriminator = true;
+
+    private String extend;
+
+    private boolean isAbstract;
+
+    private boolean isInterface;
+
+    private Set interfaces;
+
+    private List children;
+
+    static ClassDescriptor fromClass(Log log, JavaClass javaClass) {
+
+        DocletTag tag = javaClass.getTagByName(TAG_CLASS_DESCRIPTOR);
+        if (tag == null) {
+            return null;
+        }
+
+        ClassDescriptor cd = new ClassDescriptor(log, tag);
+        cd.className = javaClass.getFullyQualifiedName();
+        cd.isInterface = javaClass.isInterface();
+        cd.isAbstract = !cd.isInterface && javaClass.isAbstract();
+
+        cd.extend = tag.getNamedParameter(EXTEND);
+        if (cd.extend == null) {
+            if (javaClass.getSuperJavaClass() != null) {
+                cd.extend = javaClass.getSuperJavaClass().getFullyQualifiedName();
+
+                // do not declare extending Object :-)
+                if (Object.class.getName().equals(cd.extend)) {
+                    cd.extend = null;
+                }
+            }
+        } else if (cd.extend.length() == 0) {
+            // explicit empty extend value prevents extend attribute from being
+            // set
+            cd.extend = null;
+        }
+
+        String interfaceList = tag.getNamedParameter(INTERFACES);
+        if (interfaceList == null) {
+            if (javaClass.getImplementedInterfaces() != null) {
+                JavaClass[] implInterfaces = javaClass.getImplementedInterfaces();
+                cd.interfaces = new HashSet();
+                for (int i = 0; i < implInterfaces.length; i++) {
+                    cd.interfaces.add(implInterfaces[i].getFullyQualifiedName());
+                }
+            }
+        } else if (interfaceList.length() == 0) {
+            // empty interface list prevents creation of interface element
+            cd.interfaces = null;
+        } else {
+            // split list and create set for interface elements
+            StringTokenizer tokener = new StringTokenizer(interfaceList, ",");
+            cd.interfaces = new HashSet();
+            while (tokener.hasMoreTokens()) {
+                String iface = tokener.nextToken().trim();
+                if (iface.length() > 0) {
+                    cd.interfaces.add(iface);
+                }
+            }
+        }
+
+        cd.jcrNodeType = tag.getNamedParameter(JCR_NODE_TYPE);
+        cd.jcrSuperTypes = tag.getNamedParameter(JCR_SUPER_TYPES);
+        cd.jcrMixinTypes = tag.getNamedParameter(JCR_MIXIN_TYPES);
+
+        // only reset default if explicitly stated
+        if (tag.getNamedParameter(DISCRIMINATOR) != null) {
+            cd.discriminator = Boolean.valueOf(
+                tag.getNamedParameter(DISCRIMINATOR)).booleanValue();
+        }
+
+        return cd;
+    }
+
+    private ClassDescriptor(Log log, DocletTag tag) {
+        super(log, tag);
+    }
+
+    void addChild(AbstractDescriptorElement child) {
+        if (child != null) {
+            if (children == null) {
+                children = new ArrayList();
+            }
+
+            children.add(child);
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.sling.maven.jcrocm.AbstractDescriptorElement#generate(org.apache.sling.maven.jcrocm.XMLWriter)
+     */
+    void generate(XMLWriter xmlWriter) {
+
+        xmlWriter.println();
+        xmlWriter.printComment("Class: " + className);
+
+        xmlWriter.printElementStart(ELEMENT_CLASS_DESCRIPTOR, true);
+        xmlWriter.printAttribute(CLASS_NAME, className);
+        xmlWriter.printAttribute(JCR_NODE_TYPE, jcrNodeType);
+        xmlWriter.printAttribute(JCR_SUPER_TYPES, jcrSuperTypes);
+        xmlWriter.printAttribute(JCR_MIXIN_TYPES, jcrMixinTypes);
+        xmlWriter.printAttribute(EXTEND, extend);
+        xmlWriter.printAttribute(ABSTRACT, isAbstract);
+        xmlWriter.printAttribute(INTERFACE, isInterface);
+
+        // only write discriminator if false, true is the default here
+        if (!discriminator) {
+            xmlWriter.printAttribute(DISCRIMINATOR, "false");
+        }
+
+        xmlWriter.printElementStartClose(false);
+
+        // interface implementations
+        if (interfaces != null) {
+            for (Iterator ii = interfaces.iterator(); ii.hasNext();) {
+                String iface = (String) ii.next();
+                xmlWriter.println();
+                xmlWriter.printElementStart(ELEMENT_IMPLEMENT_DESCRIPTOR, true);
+                xmlWriter.printAttribute(INTERFACE_NAME, iface);
+                xmlWriter.printElementStartClose(true);
+            }
+        }
+
+        // fields, beans and collections
+        if (children != null) {
+            for (Iterator ci = children.iterator(); ci.hasNext();) {
+                AbstractDescriptorElement child = (AbstractDescriptorElement) ci.next();
+                xmlWriter.println();
+                child.generate(xmlWriter);
+            }
+        }
+
+        xmlWriter.printElementEnd(ELEMENT_CLASS_DESCRIPTOR);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.sling.maven.jcrocm.AbstractDescriptorElement#validate()
+     */
+    boolean validate() {
+        boolean valid = true;
+
+        if (children != null) {
+            if (children != null) {
+                for (Iterator ci = children.iterator(); ci.hasNext();) {
+                    AbstractDescriptorElement child = (AbstractDescriptorElement) ci.next();
+                    valid &= child.validate();
+                }
+            }
+        }
+
+        return valid;
+    }
+}
diff --git a/src/main/java/org/apache/sling/maven/jcrocm/CollectionDescriptor.java b/src/main/java/org/apache/sling/maven/jcrocm/CollectionDescriptor.java
new file mode 100644
index 0000000..e18c476
--- /dev/null
+++ b/src/main/java/org/apache/sling/maven/jcrocm/CollectionDescriptor.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+package org.apache.sling.maven.jcrocm;
+
+import org.apache.maven.plugin.logging.Log;
+
+import com.thoughtworks.qdox.model.DocletTag;
+import com.thoughtworks.qdox.model.JavaField;
+import com.thoughtworks.qdox.model.JavaMethod;
+
+/**
+ * The <code>CollectionDescriptor</code> class provides support for the
+ * collection-descriptor element of a class mapping, which has the following
+ * attribute list definition:
+ * 
+ * <pre>
+ *  &lt;!ATTLIST collection-descriptor
+ *      fieldName CDATA #REQUIRED
+ *      jcrName CDATA #IMPLIED 
+ *      proxy (true | false) &quot;false&quot;
+ *      autoRetrieve (true|false) &quot;true&quot;
+ *      autoUpdate (true|false) &quot;true&quot;
+ *      autoInsert (true|false) &quot;true&quot;  
+ *      elementClassName CDATA #IMPLIED
+ *      collectionClassName CDATA #IMPLIED
+ *      collectionConverter CDATA #IMPLIED
+ *      jcrNodeType CDATA #IMPLIED
+ *      jcrAutoCreated (true | false) &quot;false&quot;   
+ *      jcrMandatory (true | false) &quot;false&quot;
+ *      jcrOnParentVersion (COPY | VERSION | INITIALIZE | COMPUTE | IGNORE | ABORT) &quot;COPY&quot;
+ *      jcrProtected (true | false) &quot;false&quot;
+ *      jcrSameNameSiblings (true | false) &quot;false&quot;  
+ *  &gt;
+ * </pre>
+ */
+public class CollectionDescriptor extends AbstractNodeDescriptor {
+
+    public static final String TAG_COLLECTION_DESCRIPTOR = "ocm.collection";
+
+    public static final String ELEMENT_COLLECTION_DESCRIPTOR = "collection-descriptor";
+
+    private static final String ELEMENT_CLASS_NAME = "elementClassName";
+
+    private static final String COLLECTION_CLASS_NAME = "collectionClassName";
+
+    private static final String COLLECTION_CONVERTER = "collectionConverter";
+
+    private String elementClassName;
+
+    private String collectionClassName;
+
+    private String collectionConverter;
+
+    static CollectionDescriptor fromField(Log log, JavaField field) {
+
+        DocletTag tag = field.getTagByName(TAG_COLLECTION_DESCRIPTOR);
+        if (tag == null) {
+            return null;
+        }
+
+        return new CollectionDescriptor(log, tag, field.getName());
+    }
+
+    static CollectionDescriptor fromMethod(Log log, JavaMethod method) {
+
+        DocletTag tag = method.getTagByName(TAG_COLLECTION_DESCRIPTOR);
+        if (tag == null) {
+            return null;
+        }
+
+        // field name is the method name, unless overwritten with the fieldName
+        // tag
+        String fieldName = tag.getNamedParameter(FIELD_NAME);
+        if (fieldName == null) {
+            fieldName = getFieldFromMethod(method);
+        }
+
+        return new CollectionDescriptor(log, tag, fieldName);
+    }
+
+    /**
+     * @param log
+     * @param tag
+     */
+    public CollectionDescriptor(Log log, DocletTag tag, String fieldName) {
+        super(log, tag, fieldName);
+
+        elementClassName = tag.getNamedParameter(ELEMENT_CLASS_NAME);
+        collectionClassName = tag.getNamedParameter(COLLECTION_CLASS_NAME);
+        collectionConverter = tag.getNamedParameter(COLLECTION_CONVERTER);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.sling.maven.jcrocm.AbstractDescriptorElement#generate(org.apache.sling.maven.jcrocm.XMLWriter)
+     */
+    void generate(XMLWriter xmlWriter) {
+        xmlWriter.printElementStart(ELEMENT_COLLECTION_DESCRIPTOR, true);
+        super.generate(xmlWriter);
+
+        xmlWriter.printAttribute(ELEMENT_CLASS_NAME, elementClassName);
+        xmlWriter.printAttribute(COLLECTION_CLASS_NAME, collectionClassName);
+        xmlWriter.printAttribute(COLLECTION_CONVERTER, collectionConverter);
+
+        xmlWriter.printElementStartClose(true);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.sling.maven.jcrocm.AbstractDescriptorElement#validate()
+     */
+    boolean validate() {
+        boolean valid = super.validate();
+
+        // ensure element class name
+        if (elementClassName == null) {
+            elementClassName = Object.class.getName();
+        }
+
+        return valid;
+    }
+
+}
diff --git a/src/main/java/org/apache/sling/maven/jcrocm/FieldDescriptor.java b/src/main/java/org/apache/sling/maven/jcrocm/FieldDescriptor.java
new file mode 100644
index 0000000..740dd14
--- /dev/null
+++ b/src/main/java/org/apache/sling/maven/jcrocm/FieldDescriptor.java
@@ -0,0 +1,197 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+package org.apache.sling.maven.jcrocm;
+
+import org.apache.maven.plugin.logging.Log;
+
+import com.thoughtworks.qdox.model.DocletTag;
+import com.thoughtworks.qdox.model.JavaField;
+import com.thoughtworks.qdox.model.JavaMethod;
+
+/**
+ * The <code>FieldDescriptor</code> class provides support for the
+ * field-descriptor element of a class mapping, which has the following
+ * attribute list definition:
+ * 
+ * <pre>
+ *  &lt;!ATTLIST field-descriptor
+ *      fieldName CDATA #REQUIRED
+ *      fieldType CDATA #IMPLIED
+ *      jcrName CDATA #IMPLIED 
+ *      id (true | false) &quot;false&quot;
+ *      path (true | false) &quot;false&quot;
+ *      uuid (true | false) &quot;false&quot;
+ *      converter CDATA #IMPLIED
+ *      jcrDefaultValue CDATA #IMPLIED
+ *      jcrValueConstraints CDATA #IMPLIED 
+ *      jcrType (String | Date | Long | Double | Boolean | Binary) #IMPLIED
+ *      jcrAutoCreated (true | false) &quot;false&quot;
+ *      jcrMandatory (true | false) &quot;false&quot;
+ *      jcrOnParentVersion (COPY | VERSION | INITIALIZE | COMPUTE | IGNORE | ABORT) &quot;COPY&quot;
+ *      jcrProtected (true | false) &quot;false&quot;
+ *      jcrMultiple (true | false) &quot;false&quot;
+ *  &gt;
+ * </pre>
+ */
+public class FieldDescriptor extends AbstractItemDescriptor {
+
+    public static final String TAG_FIELD_DESCRIPTOR = "ocm.field";
+
+    public static final String ELEMENT_FIELD_DESCRIPTOR = "field-descriptor";
+
+    public static final String FIELD_TYPE = "fieldType";
+
+    public static final String ID = "id";
+
+    public static final String PATH = "path";
+
+    public static final String UUID = "uuid";
+
+    public static final String CONVERTER = "converter";
+
+    public static final String JCR_DEFAULT_VALUE = "jcrDefaultValue";
+
+    public static final String JCR_VALUE_CONSTRAINTS = "jcrValueConstraints";
+
+    public static final String JCR_TYPE = "jcrType";
+
+    public static final String JCR_MULTIPLE = "jcrMultiple";
+
+    private String fieldType;
+
+    private boolean isId;
+
+    private boolean isPath;
+
+    private boolean isUuid;
+
+    private String converter;
+
+    private String jcrDefaultValue;
+
+    private String jcrValueConstraints;
+
+    private String jcrType;
+
+    private boolean isJcrMultiple;
+
+    static FieldDescriptor fromField(Log log, JavaField field) {
+
+        DocletTag tag = field.getTagByName(TAG_FIELD_DESCRIPTOR);
+        if (tag == null) {
+            return null;
+        }
+
+        // field type is explicitly declared or Java field type
+        String fieldType = tag.getNamedParameter(FIELD_TYPE);
+        if (fieldType == null) {
+            fieldType = field.getType().getJavaClass().getFullyQualifiedName();
+        }
+        
+        return new FieldDescriptor(log, tag, field.getName(),
+            fieldType);
+    }
+
+    static FieldDescriptor fromMethod(Log log, JavaMethod method) {
+
+        DocletTag tag = method.getTagByName(TAG_FIELD_DESCRIPTOR);
+        if (tag == null) {
+            return null;
+        }
+
+        // field name is the method name, unless overwritten with the fieldName
+        // tag
+        String fieldName = tag.getNamedParameter(FIELD_NAME);
+        if (fieldName == null) {
+            fieldName = getFieldFromMethod(method);
+        }
+
+        // field type is explicitly declared or parameter or return value
+        String fieldType = tag.getNamedParameter(FIELD_TYPE);
+        if (fieldType == null) {
+            if (method.getParameters() != null
+                && method.getParameters().length == 1) {
+                fieldType = method.getParameters()[0].getType().getJavaClass().getFullyQualifiedName();
+            } else if (method.getReturns() != null) {
+                fieldType = method.getReturns().getJavaClass().getFullyQualifiedName();
+            }
+        }
+
+        return new FieldDescriptor(log, tag, fieldName, fieldType);
+    }
+
+    private FieldDescriptor(Log log, DocletTag tag, String fieldName,
+            String fieldType) {
+        super(log, tag, fieldName);
+
+        this.fieldType = fieldType;
+
+        isId = Boolean.valueOf(tag.getNamedParameter(ID)).booleanValue();
+        isPath = Boolean.valueOf(tag.getNamedParameter(PATH)).booleanValue();
+        isUuid = Boolean.valueOf(tag.getNamedParameter(UUID)).booleanValue();
+
+        converter = tag.getNamedParameter(CONVERTER);
+        jcrDefaultValue = tag.getNamedParameter(JCR_DEFAULT_VALUE);
+        jcrValueConstraints = tag.getNamedParameter(JCR_VALUE_CONSTRAINTS);
+        jcrType = tag.getNamedParameter(JCR_TYPE);
+        isJcrMultiple = Boolean.valueOf(tag.getNamedParameter(JCR_MULTIPLE)).booleanValue();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.sling.maven.jcrocm.AbstractDescriptorElement#generate(org.apache.sling.maven.jcrocm.XMLWriter)
+     */
+    void generate(XMLWriter xmlWriter) {
+        xmlWriter.printElementStart(ELEMENT_FIELD_DESCRIPTOR, true);
+
+        super.generate(xmlWriter);
+
+        xmlWriter.printAttribute(FIELD_TYPE, fieldType);
+        xmlWriter.printAttribute(ID, isId);
+        xmlWriter.printAttribute(PATH, isPath);
+        xmlWriter.printAttribute(UUID, isUuid);
+        xmlWriter.printAttribute(CONVERTER, converter);
+        xmlWriter.printAttribute(JCR_DEFAULT_VALUE, jcrDefaultValue);
+        xmlWriter.printAttribute(JCR_VALUE_CONSTRAINTS, jcrValueConstraints);
+        xmlWriter.printAttribute(JCR_TYPE, jcrType);
+        xmlWriter.printAttribute(JCR_MULTIPLE, isJcrMultiple);
+
+        xmlWriter.printElementStartClose(true);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.sling.maven.jcrocm.AbstractDescriptorElement#validate()
+     */
+    boolean validate() {
+        boolean valid = true;
+
+        if (jcrType != null) {
+            if (!jcrType.equals("String") && !jcrType.equals("Date")
+                && !jcrType.equals("Long") && !jcrType.equals("Double")
+                && !jcrType.equals("Boolean") && !jcrType.equals("Binary")) {
+                log("Invalid JCR Field Type: " + jcrType);
+                valid = false;
+            }
+        }
+
+        valid &= super.validate();
+
+        return valid;
+    }
+}
diff --git a/src/main/java/org/apache/sling/maven/jcrocm/JcrOcmMojo.java b/src/main/java/org/apache/sling/maven/jcrocm/JcrOcmMojo.java
new file mode 100644
index 0000000..b6c92ff
--- /dev/null
+++ b/src/main/java/org/apache/sling/maven/jcrocm/JcrOcmMojo.java
@@ -0,0 +1,235 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+package org.apache.sling.maven.jcrocm;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Resource;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+
+import com.thoughtworks.qdox.JavaDocBuilder;
+import com.thoughtworks.qdox.model.DocletTag;
+import com.thoughtworks.qdox.model.JavaClass;
+import com.thoughtworks.qdox.model.JavaField;
+import com.thoughtworks.qdox.model.JavaMethod;
+import com.thoughtworks.qdox.model.JavaSource;
+
+/**
+ * The <code>JcrOcmMojo</code> implements the (default) ocm goal of the
+ * <em>maven-jcrocm-plugin</em>. It is by default run in the
+ * <code>generate-resources</code> phase and requires the compile scoped
+ * dependencies to be resolved.
+ *
+ * @goal ocm
+ * @phase generate-resources
+ * @description Build Jackrabbit OCM Descriptors from Java Source
+ * @requiresDependencyResolution compile
+ */
+public class JcrOcmMojo extends AbstractMojo {
+
+    /**
+     * @parameter expression="${project.build.directory}/sling-generated"
+     * @required
+     * @readonly
+     */
+    private File outputDirectory;
+
+    /**
+     * The Maven project.
+     *
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    private MavenProject project;
+
+    /**
+     * Name and path of the generated descriptor.
+     *
+     * @parameter expression="${jcrocm.descriptor.name}" default-value="mappings.xml"
+     */
+    private String finalName;
+
+    public void execute() throws MojoFailureException {
+
+        boolean hasFailures = false;
+
+        // prepare QDox and prime with the compile class path of the project
+        JavaDocBuilder builder = new JavaDocBuilder();
+        try {
+            builder.getClassLibrary().addClassLoader(this.getCompileClassLoader());
+        } catch (IOException ioe) {
+            throw new MojoFailureException("Cannot prepare QDox");
+        }
+
+        // add the sources from the project
+        for (Iterator i = this.project.getCompileSourceRoots().iterator(); i.hasNext();) {
+            try {
+                builder.addSourceTree(new File((String) i.next()));
+            } catch (OutOfMemoryError oome) {
+                // this may be the case for big sources and not enough VM mem
+                builder = null; // drop the builder to help GC now
+                
+                // fail with some explanation
+                throw new MojoFailureException(
+                    "Failed analyzing source due to not enough memory, try setting Max Heap Size higher, e.g. using MAVEN_OPTS=-Xmx128m");
+            }
+        }
+
+        // parse the sources and get them
+        JavaSource[] javaSources = builder.getSources();
+        List descriptors = new ArrayList();
+        for (int i = 0; i < javaSources.length; i++) {
+            JavaClass[] javaClasses = javaSources[i].getClasses();
+            for (int j = 0; javaClasses != null && j < javaClasses.length; j++) {
+                DocletTag tag = javaClasses[j].getTagByName(ClassDescriptor.TAG_CLASS_DESCRIPTOR);
+                if (tag != null) {
+                    ClassDescriptor descriptor = this.createClassDescriptor(javaClasses[j]);
+                    if (descriptor != null) {
+                        descriptors.add(descriptor);
+                    } else {
+                        hasFailures = true;
+                    }
+                }
+            }
+        }
+
+        // after checking all classes, throw if there were any failures
+        if (hasFailures) {
+            throw new MojoFailureException("Jackrabbit OCM Descriptor parsing had failures (see log)");
+        }
+
+        // terminate if there is nothing to write
+        if (descriptors.isEmpty()) {
+            this.getLog().info("No Jackrabbit OCM Descriptors found in project");
+            return;
+        }
+
+        // finally the descriptors have to be written ....
+        if (StringUtils.isEmpty(this.finalName)) {
+            this.getLog().error("Descriptor file name must not be empty");
+            return;
+        }
+
+        // prepare the descriptor output file
+        File descriptorFile = new File(new File(this.outputDirectory, "SLING-INF"), this.finalName);
+        descriptorFile.getParentFile().mkdirs(); // ensure parent dir
+
+        this.getLog().info("Generating " + descriptors.size()
+            + " OCM Mapping Descriptors to " + descriptorFile);
+
+        // write out all the class descriptors in parse order
+        FileOutputStream descriptorStream = null;
+        XMLWriter xw = null;
+        try {
+            descriptorStream = new FileOutputStream(descriptorFile);
+            xw = new XMLWriter(descriptorStream, false);
+            xw.printElementStart("graffito-jcr", false);
+            for (Iterator di=descriptors.iterator(); di.hasNext(); ) {
+                ClassDescriptor sd = (ClassDescriptor) di.next();
+                sd.generate(xw);
+            }
+            xw.printElementEnd("graffito-jcr");
+
+        } catch (IOException ioe) {
+            hasFailures = true;
+            this.getLog().error("Cannot write descriptor to " + descriptorFile, ioe);
+            throw new MojoFailureException("Failed to write descriptor to " + descriptorFile);
+        } finally {
+            IOUtil.close(xw);
+            IOUtil.close(descriptorStream);
+
+            // remove the descriptor file in case of write failure
+            if (hasFailures) {
+                descriptorFile.delete();
+            }
+        }
+
+        // now add the descriptor file to the maven resources
+        final String ourRsrcPath = this.outputDirectory.getAbsolutePath();
+        boolean found = false;
+        final Iterator rsrcIterator = this.project.getResources().iterator();
+        while ( !found && rsrcIterator.hasNext() ) {
+            final Resource rsrc = (Resource)rsrcIterator.next();
+            found = rsrc.getDirectory().equals(ourRsrcPath);
+        }
+        if ( !found ) {
+            final Resource resource = new Resource();
+            resource.setDirectory(this.outputDirectory.getAbsolutePath());
+            this.project.addResource(resource);
+        }
+        // and set include accordingly
+        this.project.getProperties().setProperty("Sling-Mappings", "SLING-INF/" + this.finalName);
+    }
+
+    /**
+     * Creates an URL class loader containing all compile artifacts.
+     *
+     * @return The URLClassLoader for the compile artifacts.
+     * @throws IOException If any error occurrs creating URLs for the compile
+     *             artifact files.
+     */
+    private ClassLoader getCompileClassLoader() throws IOException {
+        List artifacts = this.project.getCompileArtifacts();
+        URL[] path = new URL[artifacts.size()];
+        int i = 0;
+        for (Iterator ai=artifacts.iterator(); ai.hasNext(); ) {
+            Artifact a = (Artifact) ai.next();
+            path[i++] = a.getFile().toURI().toURL();
+        }
+        return new URLClassLoader(path);
+    }
+
+    private ClassDescriptor createClassDescriptor(JavaClass javaClass) {
+
+        // create the class descriptor for the java class, return early if none
+        ClassDescriptor cd = ClassDescriptor.fromClass(this.getLog(), javaClass);
+        if (cd == null) {
+            return null;
+        }
+
+        // analyze fields for mapping descriptors
+        JavaField[] fields = javaClass.getFields();
+        for (int i=0; fields != null && i < fields.length; i++) {
+            cd.addChild(FieldDescriptor.fromField(this.getLog(), fields[i]));
+            cd.addChild(BeanDescriptor.fromField(this.getLog(), fields[i]));
+            cd.addChild(CollectionDescriptor.fromField(this.getLog(), fields[i]));
+        }
+
+        // analyze methods for mapping descriptors
+        JavaMethod[] methods = javaClass.getMethods();
+        for (int i=0; methods != null && i < methods.length; i++) {
+            cd.addChild(FieldDescriptor.fromMethod(this.getLog(), methods[i]));
+            cd.addChild(BeanDescriptor.fromMethod(this.getLog(), methods[i]));
+            cd.addChild(CollectionDescriptor.fromMethod(this.getLog(), methods[i]));
+        }
+
+        // return nothing if validation fails
+        return cd.validate() ? cd : null;
+    }
+}
diff --git a/src/main/java/org/apache/sling/maven/jcrocm/XMLWriter.java b/src/main/java/org/apache/sling/maven/jcrocm/XMLWriter.java
new file mode 100644
index 0000000..f81527d
--- /dev/null
+++ b/src/main/java/org/apache/sling/maven/jcrocm/XMLWriter.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+package org.apache.sling.maven.jcrocm;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+
+import org.codehaus.plexus.util.StringUtils;
+
+public class XMLWriter extends PrintWriter {
+
+    String indent = "";
+
+    XMLWriter(OutputStream descriptorStream, boolean append) throws IOException {
+        super(new OutputStreamWriter(descriptorStream, "UTF-8"));
+
+        if (!append) {
+            println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+        }
+    }
+
+    private void indent() {
+        indent += "  ";
+    }
+
+    private void outdent() {
+        if (indent.length() >= 2) {
+            indent = indent.substring(2);
+        }
+    }
+
+    void printComment(String message) {
+        print  (indent);
+        println("<!--");
+        print  (indent);
+        print  ("    ");
+        println(message);
+        print  (indent);
+        println("-->");
+    }
+    
+    void printElementStart(String name, boolean hasAttributes) {
+        print(indent);
+        print("<");
+        print(name);
+        if (!hasAttributes) {
+            printElementStartClose(false);
+        }
+        indent();
+    }
+
+    void printElementStartClose(boolean isEmpty) {
+        if (isEmpty) {
+            print(" /");
+            outdent();
+        }
+        println('>');
+    }
+
+    void printElementEnd(String name) {
+        outdent();
+        print(indent);
+        print("</");
+        print(name);
+        println('>');
+    }
+
+    void printAttribute(String name, String value) {
+        if (!StringUtils.isEmpty(name) && value != null) {
+            println();
+            print(indent);
+            print(' ');
+            print(name);
+            print("=\"");
+            print(value);
+            print('"');
+        }
+    }
+
+    void printAttribute(String name, boolean value) {
+        if (value) {
+            printAttribute(name, "true");
+        }
+    }
+}
diff --git a/src/main/resources/META-INF/LICENSE b/src/main/resources/META-INF/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/src/main/resources/META-INF/LICENSE
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   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.
diff --git a/src/main/resources/META-INF/NOTICE b/src/main/resources/META-INF/NOTICE
new file mode 100644
index 0000000..4894d83
--- /dev/null
+++ b/src/main/resources/META-INF/NOTICE
@@ -0,0 +1,8 @@
+Apache Sling
+Copyright 2007 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+Based on source code originally developed by
+Day Software (http://www.day.com/).

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.