You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by at...@apache.org on 2008/04/18 14:32:31 UTC

svn commit: r649496 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-db-tools/ components/jetspeed-db-tools/src/main/java/org/apache/jetspeed/tools/page/ components/jetspeed-db-tools/src/main/java/org/apache/jetspeed/tools/page/serializer/ co...

Author: ate
Date: Fri Apr 18 05:32:26 2008
New Revision: 649496

URL: http://svn.apache.org/viewvc?rev=649496&view=rev
Log:
Adding JetspeedPageSerializerApplication implementation for command line usage and/or maven plugin execution.
Also adding integration in jetspeed-db maven plugin for executing pages import
NB: no export support yet from maven plugins, I will probably write a new jetspeed-db:dump plugin Mojo for that soon.

Added:
    portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/main/java/org/apache/jetspeed/tools/page/
    portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/main/java/org/apache/jetspeed/tools/page/serializer/
    portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/main/java/org/apache/jetspeed/tools/page/serializer/JetspeedPageSerializerApplicationImpl.java   (with props)
    portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/test/java/org/apache/jetspeed/tools/page/
    portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/test/java/org/apache/jetspeed/tools/page/serializer/
    portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/test/java/org/apache/jetspeed/tools/page/serializer/TestJetspeedPageSerializerApplication.java   (with props)
    portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/PageSerializer.java   (with props)
Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/pom.xml
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/InitMojo.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/pom.xml?rev=649496&r1=649495&r2=649496&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/pom.xml (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/pom.xml Fri Apr 18 05:32:26 2008
@@ -145,6 +145,7 @@
         <configuration>
           <excludes>
             <exclude>**/TestJetspeedSerializerApplication.java</exclude>
+            <exclude>**/TestJetspeedPageSerializerApplication.java</exclude>
           </excludes>
         </configuration>
       </plugin>

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/main/java/org/apache/jetspeed/tools/page/serializer/JetspeedPageSerializerApplicationImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/main/java/org/apache/jetspeed/tools/page/serializer/JetspeedPageSerializerApplicationImpl.java?rev=649496&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/main/java/org/apache/jetspeed/tools/page/serializer/JetspeedPageSerializerApplicationImpl.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/main/java/org/apache/jetspeed/tools/page/serializer/JetspeedPageSerializerApplicationImpl.java Fri Apr 18 05:32:26 2008
@@ -0,0 +1,215 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.tools.page.serializer;
+
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Properties;
+
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.components.JetspeedBeanDefinitionFilter;
+import org.apache.jetspeed.components.SpringComponentManager;
+import org.apache.jetspeed.components.util.CommonsToolsLogger;
+import org.apache.jetspeed.exception.JetspeedException;
+import org.apache.jetspeed.page.JetspeedPageSerializerApplication;
+import org.apache.jetspeed.page.PageSerializer;
+import org.apache.jetspeed.page.PageSerializer.Result;
+import org.apache.jetspeed.tools.ToolsLogger;
+
+/**
+ * Commandline or standalone execution of JetspeedPageSerializer
+ * 
+ * @version $Id$
+ *
+ */
+public class JetspeedPageSerializerApplicationImpl implements JetspeedPageSerializerApplication
+{
+    private static final ToolsLogger logger = new CommonsToolsLogger(LogFactory.getLog(JetspeedPageSerializerApplicationImpl.class));
+    
+    public static void main(String[] args) throws Exception
+    {
+        JetspeedPageSerializerApplicationImpl app = new JetspeedPageSerializerApplicationImpl();
+        
+        String propertyFileName = null;
+        String applicationRootPath = null;
+        String psmlPagesPath = null;
+        String categories = null;
+        boolean doExport = false;
+        boolean doImport = false;                
+        String rootFolder = null;
+        
+        if (args == null)
+        {
+            if (args == null)
+            {
+                System.out.println("Usage for import: -I rootFolder [-psml psmlPagesPath] -c <categories | categories filter key (requires -p)> [-p <categories properties file>]");
+                System.out.println("Usage for export: -E rootFolder [-psml psmlPagesPath] -c <categories | categories filter key (requires -p)> [-p <categories properties file>]");
+            }
+        }
+
+        // Parse all the command-line arguments
+        for (int n = 0; n < args.length; n++)
+        {
+            if (args[n].equals("-c"))
+                categories = args[++n];
+            if (args[n].equals("-p"))
+                propertyFileName = args[++n];
+            else if (args[n].equals("-a"))
+                applicationRootPath = args[++n];
+            else if (args[n].equals("-I"))
+            {
+                doImport = true;
+                rootFolder = args[++n];
+            } 
+            else if (args[n].equals("-E"))
+            {
+                doExport = true;
+                rootFolder = args[++n];
+            } 
+            else if (args[n].equals("-psml"))
+            {
+                psmlPagesPath = args[++n];
+            }
+            else
+            {
+                throw new IllegalArgumentException("Unknown argument: " + args[n]);
+            }
+        
+            if ((!doImport) && (!doExport))
+            {
+              throw new IllegalArgumentException("Either import or export have to be defined (-I or -E followed by the rootFolder");
+            }
+
+            if ((doImport) && (doExport))
+            {
+                throw new IllegalArgumentException("Only one - either import or export - can be requested");
+            }
+            
+
+            if (categories == null)
+            {
+                throw new IllegalArgumentException("Argument -c defining the assembly categories filters (or the propertyFile key to it) is required");
+            }
+            
+            if (applicationRootPath == null)
+            {
+                throw new IllegalArgumentException("Argument -a specifying the path to (web)application root, is required");
+            }
+            Properties initProperties = new Properties();
+            if (psmlPagesPath != null)
+            {
+                initProperties.put("psml.pages.path", psmlPagesPath);
+            }
+            if (doImport)
+            {
+                app.execute(logger, applicationRootPath, categories, propertyFileName, initProperties, rootFolder, true);
+            }
+            if (doExport)
+            {
+                app.execute(logger, applicationRootPath, categories, propertyFileName, initProperties, rootFolder, false);
+            }
+        }
+    }            
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.tools.page.serializer.JetspeedPageSerializerApplication#importPages(org.apache.jetspeed.tools.ToolsLogger, java.lang.String, java.lang.String, java.lang.String, java.util.Properties, java.lang.String)
+     */
+    public Result importPages(ToolsLogger logger, String applicationRootPath, String categories, String filterPropertiesFileName, Properties initProperties, String rootFolder) throws JetspeedException
+    {
+        return execute(logger, applicationRootPath, categories, filterPropertiesFileName, initProperties, rootFolder, true);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.tools.page.serializer.JetspeedPageSerializerApplication#exportPages(org.apache.jetspeed.tools.ToolsLogger, java.lang.String, java.lang.String, java.lang.String, java.util.Properties, java.lang.String)
+     */
+    public Result exportPages(ToolsLogger logger, String applicationRootPath, String categories, String filterPropertiesFileName, Properties initProperties, String rootFolder) throws JetspeedException
+    {
+        return execute(logger, applicationRootPath, categories, filterPropertiesFileName, initProperties, rootFolder, false);
+    }
+
+    private Result execute(ToolsLogger logger, String applicationRootPath, String categories, String filterPropertiesFileName, Properties initProperties, String rootFolder, boolean importing) throws JetspeedException
+    {
+        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+        SpringComponentManager scm = null;
+        PageSerializer.Result result = null;
+        try
+        {
+            JetspeedBeanDefinitionFilter filter = null;
+            
+            if (filterPropertiesFileName != null)
+            {
+                filter = new JetspeedBeanDefinitionFilter("file:"+filterPropertiesFileName, categories);
+            }
+            else
+            {
+                filter = new JetspeedBeanDefinitionFilter(categories);
+            }
+            
+            String assemblyRootPath = "file:"+applicationRootPath+"/WEB-INF/assembly";
+            String[] bootConfig = {assemblyRootPath+"/boot/*.xml"};
+            String[] appConfig = { assemblyRootPath+"/*.xml", assemblyRootPath+"/override/*.xml" };                       
+            
+            ClassLoader extendedClassLoader = contextClassLoader;
+            File webInfClasses = new File(applicationRootPath, "WEB-INF/classes");
+            if (webInfClasses.exists())
+            {
+                extendedClassLoader = new URLClassLoader(new URL[]{webInfClasses.toURL()}, contextClassLoader);
+            }
+            Thread.currentThread().setContextClassLoader(extendedClassLoader);
+            
+            if (initProperties == null)
+            {
+                initProperties = new Properties();
+            }
+            initProperties.put("page.manager.permissions.security", "false");
+            initProperties.put("page.manager.constraints.security", "false");
+            
+            scm = new SpringComponentManager(filter, bootConfig, appConfig, applicationRootPath, initProperties, true);
+            scm.start();
+            
+            PageSerializer serializer = (PageSerializer)scm.getComponent(PageSerializer.class.getName());
+            if (importing)
+            {
+                result = serializer.importPages(logger, rootFolder);
+            }
+            else
+            {
+                result = serializer.exportPages(logger, rootFolder);
+            }
+        }
+        catch (Exception e)
+        {
+            logger.error(e);
+            if (e instanceof JetspeedException)
+            {
+                throw (JetspeedException)e;
+            }
+            throw new JetspeedException(e);
+        }
+        finally
+        {
+            Thread.currentThread().setContextClassLoader(contextClassLoader);
+            if (scm != null)
+            {
+                scm.stop();
+            }
+        }
+        return result;
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/main/java/org/apache/jetspeed/tools/page/serializer/JetspeedPageSerializerApplicationImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/main/java/org/apache/jetspeed/tools/page/serializer/JetspeedPageSerializerApplicationImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/main/java/org/apache/jetspeed/tools/page/serializer/JetspeedPageSerializerApplicationImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/test/java/org/apache/jetspeed/tools/page/serializer/TestJetspeedPageSerializerApplication.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/test/java/org/apache/jetspeed/tools/page/serializer/TestJetspeedPageSerializerApplication.java?rev=649496&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/test/java/org/apache/jetspeed/tools/page/serializer/TestJetspeedPageSerializerApplication.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/test/java/org/apache/jetspeed/tools/page/serializer/TestJetspeedPageSerializerApplication.java Fri Apr 18 05:32:26 2008
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.tools.page.serializer;
+
+import java.io.File;
+import java.util.Properties;
+
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.components.util.CommonsToolsLogger;
+import org.apache.jetspeed.page.JetspeedPageSerializerApplication;
+import org.apache.jetspeed.test.JetspeedTestCase;
+import org.apache.jetspeed.tools.ToolsLogger;
+
+/**
+ * @version $Id$
+ *
+ */
+public class TestJetspeedPageSerializerApplication extends JetspeedTestCase
+{
+    private static ToolsLogger logger = new CommonsToolsLogger(LogFactory.getLog(TestJetspeedPageSerializerApplication.class));
+    
+    public void testSerializer() throws Exception
+    {
+        JetspeedPageSerializerApplication app = new JetspeedPageSerializerApplicationImpl();
+        String applicationRootPath = getBaseDir()+"target/test-classes/webapp";
+        Properties initProperties = new Properties();
+        initProperties.put("psml.pages.path",getBaseDir()+"../../applications/jetspeed/src/main/webapp/WEB-INF/pages");
+        app.importPages(logger, applicationRootPath, "pageSerializer", applicationRootPath+"/WEB-INF/conf/spring-filter.properties", initProperties, "/");
+        File exportPath = new File(applicationRootPath+"/WEB-INF/exportedPages");
+        exportPath.mkdirs();
+        initProperties.put("psml.pages.path",exportPath.getAbsolutePath());
+        app.exportPages(logger, applicationRootPath, "pageSerializer", applicationRootPath+"/WEB-INF/conf/spring-filter.properties", initProperties, "/");
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/test/java/org/apache/jetspeed/tools/page/serializer/TestJetspeedPageSerializerApplication.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/test/java/org/apache/jetspeed/tools/page/serializer/TestJetspeedPageSerializerApplication.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-db-tools/src/test/java/org/apache/jetspeed/tools/page/serializer/TestJetspeedPageSerializerApplication.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/InitMojo.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/InitMojo.java?rev=649496&r1=649495&r2=649496&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/InitMojo.java (original)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/InitMojo.java Fri Apr 18 05:32:26 2008
@@ -20,6 +20,7 @@
 
 import org.apache.jetspeed.maven.utils.Artifacts;
 import org.apache.jetspeed.maven.utils.DbConnection;
+import org.apache.jetspeed.maven.utils.PageSerializer;
 import org.apache.jetspeed.maven.utils.Serializer;
 import org.apache.jetspeed.maven.utils.SqlScripts;
 import org.apache.jetspeed.maven.utils.UnpackResources;
@@ -54,6 +55,11 @@
     /**
      * @parameter
      */
+    private PageSerializer psml;
+    
+    /**
+     * @parameter
+     */
     private UnpackResources unpack;
     
     /**
@@ -110,6 +116,11 @@
         if (seed != null && seed.isConfigered())
         {
             seed.execute(getLog());
+        }
+        
+        if (psml != null && psml.isConfigered())
+        {
+            psml.execute(getLog());
         }
     }
 }

Added: portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/PageSerializer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/PageSerializer.java?rev=649496&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/PageSerializer.java (added)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/PageSerializer.java Fri Apr 18 05:32:26 2008
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.maven.utils;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.jetspeed.exception.JetspeedException;
+import org.apache.jetspeed.page.JetspeedPageSerializerApplication;
+import org.apache.jetspeed.tools.ToolsLogger;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+
+/**
+ * @version $Id$
+ *
+ */
+public class PageSerializer
+{
+    private static final String PAGE_SERIALIZER_APPLICATION_CLASS_NAME = "org.apache.jetspeed.tools.page.serializer.JetspeedPageSerializerApplicationImpl";
+
+    private String filterPropertiesFileName;    
+    private String categories;
+    private String applicationRootPath;
+    private String psmlPagesPath;
+    private String rootFolder = "/";
+    private boolean importing = true;
+    private Map initProperties;
+
+    public boolean isConfigered() throws MojoExecutionException
+    {
+        boolean configured = false;
+        
+        if (applicationRootPath == null)
+        {
+            throw new MojoExecutionException("PageSerializer applicationRootPath is required");
+        }
+        configured = true;
+        return configured;
+    }
+    
+    public void execute(Log log) throws MojoExecutionException
+    {
+        
+        JetspeedPageSerializerApplication app = null;
+        try
+        {
+            Class dfClass = Class.forName(PAGE_SERIALIZER_APPLICATION_CLASS_NAME, true, Thread.currentThread().getContextClassLoader());
+            app = (JetspeedPageSerializerApplication) dfClass.newInstance();
+        }
+        catch (Exception e)
+        {
+            throw new MojoExecutionException("Cannot find or load JetspeedPageSerializerApplication class "+ PAGE_SERIALIZER_APPLICATION_CLASS_NAME, e);
+        }
+        
+        ToolsLogger logger = new MavenToolsLogger(log);
+        
+        Properties props = new Properties();
+        if (initProperties != null)
+        {
+            // working around an odd Maven on MacOS issue which stored empty mapped properties actually as null values,
+            // which isn't allowed for properties
+            Iterator iter = initProperties.entrySet().iterator();
+            while (iter.hasNext())
+            {
+                Map.Entry entry = (Map.Entry)iter.next();
+                if (entry.getValue() == null)
+                {
+                    entry.setValue("");
+                }
+            }
+            props.putAll(initProperties);
+        }
+        if (psmlPagesPath != null)
+        {
+            props.put("psml.pages.path", psmlPagesPath);
+        }
+        
+        try
+        {
+            if (importing)
+            {
+                app.importPages(logger, applicationRootPath, categories, filterPropertiesFileName, props, rootFolder);
+            }
+            else
+            {
+                app.exportPages(logger, applicationRootPath, categories, filterPropertiesFileName, props, rootFolder);
+            }
+        }
+        catch (JetspeedException je)
+        {
+            throw new MojoExecutionException("PageSerializer error: ",je);
+        }
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/PageSerializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/PageSerializer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/PageSerializer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



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