Author: jvelociter
Date: 2008-02-06 00:34:56 +0100 (Wed, 06 Feb 2008)
New Revision: 7305

Added:
   xwiki-products/xwiki-watch/trunk/tools/build-xmldoc-update-plugin/
Removed:
   xwiki-products/xwiki-watch/trunk/tools/build-doc-plugin/
Modified:
   xwiki-products/xwiki-watch/trunk/tools/build-xmldoc-update-plugin/pom.xml
   
xwiki-products/xwiki-watch/trunk/tools/build-xmldoc-update-plugin/src/main/java/com/xpn/xwiki/tool/doc/AbstractDocumentMojo.java
   
xwiki-products/xwiki-watch/trunk/tools/build-xmldoc-update-plugin/src/main/java/com/xpn/xwiki/tool/doc/AttachMojo.java
   
xwiki-products/xwiki-watch/trunk/tools/build-xmldoc-update-plugin/src/main/java/com/xpn/xwiki/tool/doc/SetPropertyMojo.java
   xwiki-products/xwiki-watch/trunk/tools/pom.xml
   xwiki-products/xwiki-watch/trunk/wiki/pom.xml
Log:
XTOOLS-23 Integrate the XML Doc Update plugin that has been developped for 
XWiki Watch inside XWiki Platform Tools project.

* Prepare the plugin move : renamed parameters, code refactoring, renamed the 
plugin to build-xmldoc-update-plugin



Copied: xwiki-products/xwiki-watch/trunk/tools/build-xmldoc-update-plugin (from 
rev 7290, xwiki-products/xwiki-watch/trunk/tools/build-doc-plugin)

Modified: 
xwiki-products/xwiki-watch/trunk/tools/build-xmldoc-update-plugin/pom.xml
===================================================================
--- xwiki-products/xwiki-watch/trunk/tools/build-doc-plugin/pom.xml     
2008-02-04 20:17:18 UTC (rev 7290)
+++ xwiki-products/xwiki-watch/trunk/tools/build-xmldoc-update-plugin/pom.xml   
2008-02-05 23:34:56 UTC (rev 7305)
@@ -29,7 +29,7 @@
     <artifactId>xwiki-watch-build-tools</artifactId>
     <version>1.0-SNAPSHOT</version>
   </parent>
-  <artifactId>xwiki-watch-build-doc-plugin</artifactId>
+  <artifactId>xwiki-build-xmldoc-update-plugin</artifactId>
   <name>XWiki Products - Watch - Tools - Doc Plugin</name>
   <packaging>maven-plugin</packaging>
   <description>A Maven plugin to load XWiki documents from XML and perform 
file attachment or setting object properties, before writting the document back 
to XML</description>

Modified: 
xwiki-products/xwiki-watch/trunk/tools/build-xmldoc-update-plugin/src/main/java/com/xpn/xwiki/tool/doc/AbstractDocumentMojo.java
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/tools/build-doc-plugin/src/main/java/com/xpn/xwiki/tool/doc/AbstractDocumentMojo.java
      2008-02-04 20:17:18 UTC (rev 7290)
+++ 
xwiki-products/xwiki-watch/trunk/tools/build-xmldoc-update-plugin/src/main/java/com/xpn/xwiki/tool/doc/AbstractDocumentMojo.java
    2008-02-05 23:34:56 UTC (rev 7305)
@@ -48,6 +48,22 @@
     private MavenProject project;
 
     /**
+     * The document to perform the update on
+     * 
+     * @parameter 
expression="${basedir}/src/main/resources/XWiki/XWikiPreferences"
+     * @required
+     */
+    protected File sourceDocument;
+    
+    /**
+     * The target directory to write the document back to
+     * 
+     * @parameter expression="${project.build.outputDirectory}"
+     * @required
+     */
+    protected File outputDirectory;    
+    
+    /**
      * Loads a XWikiDocument from a XML file
      * 
      * @param file the xml file to load
@@ -92,22 +108,20 @@
     }
 
     /**
-     * Obtain the output file for a Wiki document
+     * Return the space directory as a File for a given document in a given
+     * directory, creating the directories on the fly if the do not exists
      * 
-     * @param document the document to get the output file of
-     * @return the File for that document in the build output directory
+     * @param document the document to get space for
+     * @param directory the directory in which the space will be written
+     * @return the space as a File
      * @throws MojoExecutionException
      */
-    protected File getOutputFileForDocument(File document) throws 
MojoExecutionException
+    protected File getSpaceDirectory(File directory, File document) throws 
MojoExecutionException
     {
-        File targetDir = new 
File(this.project.getBuild().getOutputDirectory());
-        if (!targetDir.exists()) {
-            targetDir.mkdirs();
-        }
-        File spaceDir = new File(targetDir, 
document.getParentFile().getName());
+        File spaceDir = new File(directory, 
document.getParentFile().getName());
         if (!spaceDir.exists()) {
             spaceDir.mkdirs();
         }
-        return new File(targetDir, spaceDir.getName() + "/" + 
document.getName());
+        return spaceDir;
     }
 }

Modified: 
xwiki-products/xwiki-watch/trunk/tools/build-xmldoc-update-plugin/src/main/java/com/xpn/xwiki/tool/doc/AttachMojo.java
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/tools/build-doc-plugin/src/main/java/com/xpn/xwiki/tool/doc/AttachMojo.java
        2008-02-04 20:17:18 UTC (rev 7290)
+++ 
xwiki-products/xwiki-watch/trunk/tools/build-xmldoc-update-plugin/src/main/java/com/xpn/xwiki/tool/doc/AttachMojo.java
      2008-02-05 23:34:56 UTC (rev 7305)
@@ -52,19 +52,11 @@
      */
     private File file;
 
-    /**
-     * Document to attach to
-     * 
-     * @parameter
-     * @required
-     */
-    private File document;
-
     public void execute() throws MojoExecutionException, MojoFailureException
     {
         try {
-            XWikiDocument doc = loadFromXML(document);
-            
+            XWikiDocument doc = loadFromXML(sourceDocument);
+
             // Create a XWiki attachment from the file
             XWikiAttachment attachment = createAttachment(file, author);
 
@@ -74,11 +66,15 @@
             doc.setAttachmentList(attachlist);
 
             // output the file
-            File outputFile = this.getOutputFileForDocument(document);
+            File outputFile =
+                new File(getSpaceDirectory(outputDirectory, sourceDocument), 
sourceDocument
+                    .getName());
             writeToXML(doc, outputFile);
 
         } catch (Exception e) {
-            throw new MojoExecutionException("Error while attaching the file", 
e);
+            throw new MojoExecutionException("Error while attaching the file 
[" + file
+                + "] on document [" + sourceDocument.getParentFile().getName() 
+ "."
+                + sourceDocument.getName() + "]", e);
         }
     }
 
@@ -89,7 +85,8 @@
      * @return the attachment
      * @throws MojoExecutionException
      */
-    private XWikiAttachment createAttachment(File file, String author) throws 
MojoExecutionException
+    private XWikiAttachment createAttachment(File file, String author)
+        throws MojoExecutionException
     {
         try {
             // Create an empty attachment

Modified: 
xwiki-products/xwiki-watch/trunk/tools/build-xmldoc-update-plugin/src/main/java/com/xpn/xwiki/tool/doc/SetPropertyMojo.java
===================================================================
--- 
xwiki-products/xwiki-watch/trunk/tools/build-doc-plugin/src/main/java/com/xpn/xwiki/tool/doc/SetPropertyMojo.java
   2008-02-04 20:17:18 UTC (rev 7290)
+++ 
xwiki-products/xwiki-watch/trunk/tools/build-xmldoc-update-plugin/src/main/java/com/xpn/xwiki/tool/doc/SetPropertyMojo.java
 2008-02-05 23:34:56 UTC (rev 7305)
@@ -23,7 +23,6 @@
 
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.project.MavenProject;
 
 import com.xpn.xwiki.doc.XWikiDocument;
 import com.xpn.xwiki.objects.BaseObject;
@@ -37,64 +36,59 @@
  */
 public class SetPropertyMojo extends AbstractDocumentMojo
 {
-    
+
     /**
-     * The document holding the object
-     * 
-     * @parameter expression="${basedir}/target/classes/XWiki/XWikiPreferences"
-     */
-    private File document;
-    
-    /**
      * The class name of the object to write the property value to
      * 
      * @parameter expression="XWiki.XWikiPreferences"
+     * @required
      */
     private String className;
-    
+
     /**
      * The object id to write the property value to
      * 
      * @parameter expression="0"
+     * @required
      */
     private int objectId;
-    
+
     /**
      * The property name
      * 
      * @parameter
      * @required
      */
-    private String propName;
-    
+    private String propertyName;
+
     /**
      * The property value to write
      * 
      * @parameter
      * @required
      */
-    private String propValue;
-    
+    private String value;
+
     /**
      * Append the value to the existing one
      * 
      * @parameter expression="false"
      */
-    private boolean append;    
-    
-    
+    private boolean append;
+
     public void execute() throws MojoExecutionException, MojoFailureException
     {
-        XWikiDocument doc = loadFromXML(document);
+        XWikiDocument doc = loadFromXML(sourceDocument);
         BaseObject bo = doc.getObject(className, objectId);
-        if(append){
-            propValue += bo.getStringValue(propName);
-        }   
-        bo.setStringValue(propName, propValue);
-        
-        File outputFile = getOutputFileForDocument(document);
-        
+        if (append) {
+            value += bo.getStringValue(propertyName);
+        }
+
+        bo.setStringValue(propertyName, value);
+
+        File outputFile =
+            new File(getSpaceDirectory(outputDirectory, sourceDocument), 
sourceDocument.getName());
+
         writeToXML(doc, outputFile);
     }
-
 }

Modified: xwiki-products/xwiki-watch/trunk/tools/pom.xml
===================================================================
--- xwiki-products/xwiki-watch/trunk/tools/pom.xml      2008-02-05 23:09:09 UTC 
(rev 7304)
+++ xwiki-products/xwiki-watch/trunk/tools/pom.xml      2008-02-05 23:34:56 UTC 
(rev 7305)
@@ -34,6 +34,6 @@
   <packaging>pom</packaging>
   <description>XWiki Products - Watch - Tools</description>
   <modules>
-    <module>build-doc-plugin</module>
+    <module>build-xmldoc-update-plugin</module>
   </modules>
 </project>

Modified: xwiki-products/xwiki-watch/trunk/wiki/pom.xml
===================================================================
--- xwiki-products/xwiki-watch/trunk/wiki/pom.xml       2008-02-05 23:09:09 UTC 
(rev 7304)
+++ xwiki-products/xwiki-watch/trunk/wiki/pom.xml       2008-02-05 23:34:56 UTC 
(rev 7305)
@@ -48,17 +48,44 @@
        </dependency>
   </dependencies>
   <build>
-    <resources>
-      <resource>
-        <directory>${basedir}/src/main/resources</directory>
-        <excludes>
-          <exclude>**/Translations.fr</exclude>
-        </excludes>
-      </resource>
-    </resources>
-       <plugins>
+   <plugins>
+      <plugin>
+        <groupId>com.xpn.xwiki.platform</groupId>
+        <artifactId>xwiki-build-xar-plugin</artifactId>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>xar</goal>
+            </goals>
+            <configuration>
+              <excludes>
+                 <exclude>**/Translations.fr</exclude>
+              </excludes>
+            </configuration>
+          </execution>
+                 <!--
+           unxar XE wiki. This would normally be done by the xar goal
+           at package time, but since we need to alter the 
XWiki.XWikiPreferences
+           to inject the Watch translations in the i18n doc bundles,
+           we need to unxar it at resources generation time.
+                  -->
+          <execution>
+            <phase>generate-resources</phase>
+            <id>unxar-xe</id>
+            <goals>
+              <goal>unxar</goal>
+            </goals>
+            <configuration>
+              <groupId>com.xpn.xwiki.products</groupId>
+              <artifactId>xwiki-enterprise-wiki</artifactId>
+              <outputDirectory>${basedir}/target/classes</outputDirectory>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
          <!--
-        Step 1: copy the GWT zip to the target directory
+           copy the GWT zip to the target directory
          -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
@@ -84,25 +111,41 @@
                  </execution>
                </executions>
          </plugin>
+         <!--
+          Attach watch JS-compiled code and resources zip
+           to WatchCode.GWT document.
+          -->
       <plugin>
-         <!--
-               Step 2: Attach watch JS-compiled code and resources zip
-                to WatchCode.GWT document.
-      -->
         <groupId>com.xpn.xwiki.products</groupId>
-        <artifactId>xwiki-watch-build-doc-plugin</artifactId>
+        <artifactId>xwiki-build-xmldoc-update-plugin</artifactId>
         <executions>
-             <execution>
+          <execution>
             <phase>generate-resources</phase>
-                       <id>attach-watch-zip</id>
+            <id>attach-watch-zip</id>
             <goals>
               <goal>attach</goal>
             </goals>
-                       <configuration>
+            <configuration>
               <file>${project.build.directory}/gwt/watch.zip</file>
-              <document>${basedir}/src/main/resources/WatchCode/GWT</document>
+              
<sourceDocument>${basedir}/src/main/resources/WatchCode/GWT</sourceDocument>
             </configuration>
           </execution>
+          <!--
+           Inject WatchCode.Translations in XWiki.XWikiPreferences
+          -->
+          <execution>
+            <phase>generate-resources</phase>
+            <id>inject-watch-translations</id>
+            <goals>
+              <goal>setproperty</goal>
+            </goals>
+            <configuration>
+             
<sourceDocument>${project.build.outputDirectory}/XWiki/XWikiPreferences</sourceDocument>
+              <propertyName>documentBundles</propertyName>
+              <value>WatchCode.Translations</value>
+              <append>false</append>
+            </configuration>
+          </execution>
         </executions>
       </plugin>
     </plugins>

_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to