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/03/18 04:32:22 UTC

svn commit: r638189 [1/2] - in /portals/jetspeed-2/portal/trunk/maven: ./ jetspeed-build-maven-plugin/ jetspeed-build-maven-plugin/src/ jetspeed-build-maven-plugin/src/main/ jetspeed-build-maven-plugin/src/main/java/ jetspeed-build-maven-plugin/src/mai...

Author: ate
Date: Mon Mar 17 20:32:13 2008
New Revision: 638189

URL: http://svn.apache.org/viewvc?rev=638189&view=rev
Log:
New set of independent maven plugins replacing the previous single jetspeed-maven-plugins artifact.
This adds a new (still incomplete) DeployMojo and largely rewritten DatabaseMojo and UnpackMojo.
Running a Mojo standalone (not tied to a lifecycle) means only a single configuration can be used *per* plugin.
Therefore, putting multiple Mojos (which might need to be run standalone) in one plugin artifact is bad practice.

Note: this is still work in progress!  

Added:
    portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/pom.xml   (with props)
    portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DDLGeneratorMojo.java   (with props)
    portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/UnpackMojo.java   (with props)
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/pom.xml   (with props)
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DatabaseMojo.java   (with props)
    portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/pom.xml   (with props)
    portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java   (with props)
    portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/pom.xml   (with props)
    portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/
    portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/Artifacts.java   (with props)
    portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/DbConnection.java   (with props)
    portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/SeedConfig.java   (with props)
    portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/SqlScripts.java   (with props)
    portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/UnpackResources.java   (with props)
Modified:
    portals/jetspeed-2/portal/trunk/maven/pom.xml

Added: portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/pom.xml?rev=638189&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/pom.xml (added)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/pom.xml Mon Mar 17 20:32:13 2008
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+  
+  $Id$
+-->
+<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>
+  <prerequisites>
+    <maven>2.0.7</maven>
+  </prerequisites>
+
+  <artifactId>jetspeed-build-maven-plugin</artifactId>
+  <name>Jetspeed 2 Build Maven Plugin</name>
+  <description>Jetspeed 2 Build Maven Plugin</description>
+  <parent>
+    <groupId>org.apache.portals.jetspeed-2</groupId>
+    <artifactId>maven</artifactId>
+    <version>2.2-SNAPSHOT</version>
+  </parent>
+  <packaging>maven-plugin</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>jetspeed-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>jetspeed-maven-utils</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.0.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0.7</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.ddlutils</groupId>
+      <artifactId>ddlutils</artifactId>
+    </dependency>
+    <dependency>
+      <artifactId>plexus-utils</artifactId>
+      <groupId>org.codehaus.plexus</groupId>
+      <version>1.4.1</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-plugin-plugin</artifactId>        
+        <configuration>
+          <goalPrefix>jetspeed-build</goalPrefix>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DDLGeneratorMojo.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DDLGeneratorMojo.java?rev=638189&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DDLGeneratorMojo.java (added)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DDLGeneratorMojo.java Mon Mar 17 20:32:13 2008
@@ -0,0 +1,316 @@
+/*
+ * 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.plugins;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+
+import org.apache.ddlutils.Platform;
+import org.apache.ddlutils.PlatformFactory;
+import org.apache.ddlutils.io.DatabaseIO;
+import org.apache.ddlutils.model.Database;
+import org.apache.ddlutils.model.Table;
+import org.apache.ddlutils.platform.CreationParameters;
+import org.apache.ddlutils.platform.oracle.Oracle8Platform;
+import org.apache.ddlutils.task.TableSpecificParameter;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.DirectoryScanner;
+
+/**
+ * @version $Id:DDLGeneratorMojo.java 523594 2007-03-29 07:07:32Z ate $
+ * @goal ddl
+ * @phase process-resources
+ */
+public class DDLGeneratorMojo extends AbstractMojo
+{
+    /** The DDLUtils databases
+     * @parameter
+     * @required
+     */
+    private String[] databases;
+
+    /** Whether to use delimited SQL identifiers.
+     * @parameter default-value="false"
+     */
+    private boolean useDelimitedSqlIdentifiers;
+    
+    /** Whether read foreign keys shall be sorted.
+     * @parameter default-value="false"
+     */
+    private boolean sortForeignKeys;
+    
+    /** The set of ddl schema filenames. Schema names may
+     * include wildcards.
+     * @parameter
+     */
+    private String[] schemas;
+    
+    /**
+     * The output directory where the ddl scripts will be generated
+     * @parameter expression="${project.build.directory}/generated-sources/schema-ddl"
+     */
+    private String outputTarget;
+    
+    /**
+     * @parameter
+     */
+    private TableSpecificParameter[] parameters;
+    
+    /**
+     * @parameter default-value="false"
+     */
+    private boolean validateXml;
+    
+    /**
+     * @parameter default-value="true"
+     */
+    private boolean useInternalDtd;
+    
+    /** The Maven project.
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    private MavenProject project;
+    
+    public void execute() throws MojoExecutionException, MojoFailureException
+    {
+        File[] schemaFiles = getSchemaFiles();
+        if ( schemaFiles.length > 0)
+        {
+            Database model = readModel(schemaFiles);
+            Platform platforms[] = new Platform[databases.length];
+            if ( databases.length == 0 )
+            {
+                getLog().warn("No databases specified, no ddl generated");
+            }
+            else
+            {
+                for ( int i = 0; i < databases.length; i++ )
+                {            
+                    try
+                    {
+                        platforms[i] = PlatformFactory.createNewPlatformInstance(databases[i]);
+                    }
+                    catch (Exception ex)
+                    {
+                        throw new MojoExecutionException("Database type "+databases[i]+" is not supported.", ex);
+                    }
+                    if (platforms[i] == null)
+                    {
+                        throw new MojoExecutionException("Database type "+databases[i]+" is not supported.");
+                    }
+                    platforms[i].setDelimitedIdentifierModeOn(useDelimitedSqlIdentifiers);
+                    platforms[i].setForeignKeysSorted(sortForeignKeys);
+                }
+                
+                for (int i = 0; i < platforms.length; i++ )
+                {
+                    Platform platform = platforms[i];
+                    platform.setScriptModeOn(true);
+                    File outputDir = new File(outputTarget,databases[i].toLowerCase());
+                    if ( !outputDir.exists() )
+                    {
+                        outputDir.mkdirs();
+                    }
+                    if (platform.getPlatformInfo().isSqlCommentsSupported())
+                    {
+                        // we're generating SQL comments if possible
+                        platform.setSqlCommentsOn(true);
+                    }
+                    if ( platform instanceof Oracle8Platform )
+                    {
+                        // hack to map LONGVARCHAR to VARCHAR2(4000) on Oracle, the predefined CLOB type really isn't usable
+                        platform.getPlatformInfo().addNativeTypeMapping("LONGVARCHAR", "VARCHAR2(4000)");
+                    }
+                    CreationParameters params = getFilteredParameters(model, platform.getName(), useDelimitedSqlIdentifiers);
+                    try
+                    {
+                        StringWriter stringWriter = new StringWriter();
+                        platform.getSqlBuilder().setWriter(stringWriter);
+                        platform.getSqlBuilder().createTables(model, params, false);
+                        int createSchemaLength = stringWriter.getBuffer().length();
+                        writeOutput(new File(outputDir,"create-schema.sql"),stringWriter.toString());
+                        stringWriter.getBuffer().setLength(0);
+                        platform.getSqlBuilder().createTables(model, params, true);
+                        stringWriter.getBuffer().setLength(stringWriter.getBuffer().length()-createSchemaLength);
+                        writeOutput(new File(outputDir,"drop-schema.sql"), stringWriter.toString());
+                    }
+                    catch (IOException ioe)
+                    {
+                        throw new MojoExecutionException("Failed to generate ddl for "+databases[i], ioe);
+                    }
+                    getLog().info("Written "+databases[i]+" schema sql to " + outputDir.getAbsolutePath());
+                }
+            }
+        }
+    }
+    
+    protected void writeOutput(File outputFile, String content) throws MojoExecutionException
+    {
+        if (outputFile.exists() && (!outputFile.isFile() || !outputFile.canWrite())) 
+        {
+            throw new MojoExecutionException("Cannot write to output file "+outputFile.getAbsolutePath());
+        }
+        FileWriter outputWriter = null;
+        try
+        {
+            outputWriter = new FileWriter(outputFile);
+            outputWriter.append(content);
+            outputWriter.close();
+            outputWriter = null;
+        }
+        catch (IOException ioe)
+        {
+            throw new MojoExecutionException("Cannot open output file "+outputFile.getAbsolutePath(), ioe);
+        }
+        finally
+        {
+            if ( outputWriter != null )
+            {
+                try
+                {
+                    outputWriter.close();
+                }
+                catch (IOException ioe)
+                {
+                }
+            }
+        }
+    }
+    
+    protected File[] getSchemaFiles()
+    {
+        if (schemas == null  ||  schemas.length == 0)
+        {
+            schemas = new String[]{"src/main/ddl-schema/*.xml"};
+        }
+        DirectoryScanner ds = new DirectoryScanner();
+        final File baseDir = project.getBasedir();
+        ds.setBasedir(baseDir);
+        ds.setIncludes(schemas);
+        ds.scan();
+        String[] files = ds.getIncludedFiles();
+        File[] schemaFiles = new File[files.length];
+        for (int i = 0;  i < schemaFiles.length;  i++)
+        {
+            schemaFiles[i] = new File(baseDir, files[i]);
+        }
+        if (schemaFiles.length == 0) {
+            StringBuffer sb = new StringBuffer();
+            sb.append("Schema specification returns no result: ");
+            for (int i = 0;  i < schemas.length;  i++)
+            {
+                if (i > 0) 
+                {
+                    sb.append(",");
+                }
+                sb.append(schemas[i]);
+            }
+            getLog().warn(sb);
+        }
+        return schemaFiles;
+    }
+
+    protected Database readModel(File[] files) throws MojoExecutionException
+    {
+        DatabaseIO reader = new DatabaseIO();
+        Database   model  = null;
+
+        reader.setValidateXml(validateXml);
+        reader.setUseInternalDtd(useInternalDtd);
+        
+        for (int idx = 0; (files != null) && (idx < files.length); idx++)
+        {
+            Database curModel = null;
+            if (!files[idx].isFile())
+            {
+                throw new MojoExecutionException("Path " + files[idx].getAbsolutePath() + " does not denote a file");
+            }
+            else if (!files[idx].canRead())
+            {
+                throw new MojoExecutionException("Could not read schema file " + files[idx].getAbsolutePath());
+            }
+            else
+            {
+                try
+                {
+                    curModel = reader.read(files[idx]);
+                    getLog().info("Read schema file " + files[idx].getAbsolutePath());
+                }
+                catch (Exception ex)
+                {
+                    throw new MojoExecutionException("Could not read schema file "+files[idx].getAbsolutePath()+": "+ex.getLocalizedMessage(), ex);
+                }
+            }
+
+            if (model == null)
+            {
+                model = curModel;
+            }
+            else if (curModel != null)
+            {
+                try
+                {
+                    model.mergeWith(curModel);
+                }
+                catch (IllegalArgumentException ex)
+                {
+                    throw new MojoExecutionException("Could not merge with schema from file "+files[idx]+": "+ex.getLocalizedMessage(), ex);
+                }
+            }
+        }
+        return model;
+    }
+    
+    /**
+     * Filters the parameters for the given model and platform.
+     * 
+     * @param model           The database model
+     * @param platformName    The name of the platform
+     * @param isCaseSensitive Whether case is relevant when comparing names of tables
+     * @return The filtered parameters
+     */
+    protected CreationParameters getFilteredParameters(Database model, String platformName, boolean isCaseSensitive)
+    {
+        CreationParameters creationParameters = new CreationParameters();
+
+        if ( parameters != null ) {
+            for (int i=0; i < parameters.length; i++ )
+            {
+                if (parameters[i].isForPlatform(platformName))
+                {
+                    for (int idx = 0; idx < model.getTableCount(); idx++)
+                    {
+                        Table table = model.getTable(idx);
+
+                        if (parameters[i].isForTable(table, isCaseSensitive))
+                        {
+                            creationParameters.addParameter(table, parameters[i].getName(), parameters[i].getValue());
+                        }
+                    }
+                }
+            }
+        }
+        return creationParameters;
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DDLGeneratorMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DDLGeneratorMojo.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DDLGeneratorMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/UnpackMojo.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/UnpackMojo.java?rev=638189&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/UnpackMojo.java (added)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/UnpackMojo.java Mon Mar 17 20:32:13 2008
@@ -0,0 +1,84 @@
+/*
+ * 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.plugins;
+
+import java.util.Set;
+
+import org.apache.jetspeed.maven.utils.Artifacts;
+import org.apache.jetspeed.maven.utils.UnpackResources;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * UnpackResourcesMojo provides extracting specific folders within a (remote) resource bundle jar to specific output folders.
+ * 
+ * @version $Id$
+ * @goal unpack
+ */
+public class UnpackMojo extends AbstractMojo
+{
+    /**
+     * When true, skip the execution.
+     * @parameter default-value="false"
+     */
+    private boolean skip;
+    
+    /**
+     * When true, INFO log copied/skipped resources
+     * @parameter default-value="false"
+     */
+    private boolean verbose;
+    
+    /**
+     * @parameter
+     */
+    private UnpackResources unpack;
+    
+    /** @parameter expression="${plugin.introducedDependencyArtifacts}"
+     *  @readonly
+     **/
+    private Set pluginDependencyArtifacts;
+    private Artifacts artifacts;
+    
+    /** The Maven project.
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    private MavenProject project;
+
+    /* (non-Javadoc)
+     * @see org.apache.maven.plugin.Mojo#execute()
+     */
+    public void execute() throws MojoExecutionException, MojoFailureException
+    {
+        if ( skip )
+        {
+            this.getLog().info( "Skipping unpack" );
+            return;
+        }
+
+        artifacts = new Artifacts(pluginDependencyArtifacts);
+        
+        if (unpack != null)
+        {
+            unpack.unpack(artifacts, project.getBuild().getDirectory(), getLog(), false);
+        }
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/UnpackMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/UnpackMojo.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-build-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/UnpackMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/pom.xml?rev=638189&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/pom.xml (added)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/pom.xml Mon Mar 17 20:32:13 2008
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+  
+  $Id$
+-->
+<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>
+  <prerequisites>
+    <maven>2.0.7</maven>
+  </prerequisites>
+
+  <artifactId>jetspeed-db-maven-plugin</artifactId>
+  <name>Jetspeed 2 Database Maven Plugin</name>
+  <description>Jetspeed 2 Database Maven Plugin</description>
+  <parent>
+    <groupId>org.apache.portals.jetspeed-2</groupId>
+    <artifactId>maven</artifactId>
+    <version>2.2-SNAPSHOT</version>
+  </parent>
+  <packaging>maven-plugin</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>jetspeed-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>jetspeed-maven-utils</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.0.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0.7</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.ddlutils</groupId>
+      <artifactId>ddlutils</artifactId>
+    </dependency>
+    <dependency>
+      <artifactId>plexus-utils</artifactId>
+      <groupId>org.codehaus.plexus</groupId>
+      <version>1.4.1</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-plugin-plugin</artifactId>        
+        <configuration>
+          <goalPrefix>jetspeed-db</goalPrefix>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DatabaseMojo.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/DatabaseMojo.java?rev=638189&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DatabaseMojo.java (added)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DatabaseMojo.java Mon Mar 17 20:32:13 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.plugins;
+
+import java.util.Set;
+
+import org.apache.jetspeed.maven.utils.Artifacts;
+import org.apache.jetspeed.maven.utils.DbConnection;
+import org.apache.jetspeed.maven.utils.SeedConfig;
+import org.apache.jetspeed.maven.utils.SqlScripts;
+import org.apache.jetspeed.maven.utils.UnpackResources;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Settings;
+
+/**
+ * @version $Id$
+ * @goal run
+ */
+public class DatabaseMojo extends AbstractMojo
+{
+    /**
+     * Database connection
+     * @parameter 
+     */
+    private DbConnection connection;
+
+    /**
+     * @parameter
+     */
+    private SqlScripts sql;
+    
+    /**
+     * @parameter
+     */
+    private UnpackResources unpack;
+    
+    /**
+     * @parameter
+     */
+    private SeedConfig seedConfig;
+    
+    /**
+     * @parameter expression="${settings}"
+     * @required
+     * @readonly
+     */
+    private Settings settings;
+    
+    /**
+     * When true, skip the execution.
+     * @parameter default-value="false"
+     */
+    private boolean skip;
+    
+    /** @parameter expression="${plugin.introducedDependencyArtifacts}"
+     *  @readonly
+     **/
+    private Set pluginDependencyArtifacts;
+    private Artifacts artifacts;
+    
+    /** The Maven project.
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    private MavenProject project;
+
+    public void execute() throws MojoExecutionException, MojoFailureException
+    {
+        if ( skip )
+        {
+            this.getLog().info( "Skipping init-db" );
+            return;
+        }
+        
+        artifacts = new Artifacts(pluginDependencyArtifacts);
+        
+        if (unpack != null)
+        {
+            unpack.unpack(artifacts, project.getBuild().getDirectory(), getLog(), false);
+        }
+        
+        if (sql != null && sql.isConfigered())
+        {
+            if (connection == null)
+            {
+                throw new MojoExecutionException("Cannot execute sql without a connection configuration");
+            }
+            connection.checkSettings(settings);
+            sql.execute(connection, getLog());
+        }
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DatabaseMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DatabaseMojo.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-db-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DatabaseMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/pom.xml?rev=638189&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/pom.xml (added)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/pom.xml Mon Mar 17 20:32:13 2008
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+  
+  $Id$
+-->
+<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>
+  <prerequisites>
+    <maven>2.0.7</maven>
+  </prerequisites>
+
+  <artifactId>jetspeed-deploy-maven-plugin</artifactId>
+  <name>Jetspeed 2 Deploy Maven Plugin</name>
+  <description>Jetspeed 2 Deploy Maven Plugin</description>
+  <parent>
+    <groupId>org.apache.portals.jetspeed-2</groupId>
+    <artifactId>maven</artifactId>
+    <version>2.2-SNAPSHOT</version>
+  </parent>
+  <packaging>maven-plugin</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>jetspeed-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>jetspeed-maven-utils</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.0.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0.7</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <artifactId>plexus-utils</artifactId>
+      <groupId>org.codehaus.plexus</groupId>
+      <version>1.4.1</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-plugin-plugin</artifactId>        
+        <configuration>
+          <goalPrefix>jetspeed-deploy</goalPrefix>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java?rev=638189&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java (added)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java Mon Mar 17 20:32:13 2008
@@ -0,0 +1,546 @@
+/*
+ * 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.plugins;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.channels.FileChannel;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.apache.jetspeed.maven.utils.Artifacts;
+import org.apache.jetspeed.tools.deploy.DeployFactory;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * DeployerMojo is a generic Jetspeed Portal artifacts en resources deployer.
+ * 
+ * @version $Id$
+ * @goal deploy
+ */
+public class DeployMojo extends AbstractMojo
+{
+    private static final String DEPLOY_FACTORY_CLASS_NAME = "org.apache.jetspeed.tools.deploy.JetspeedDeployFactory";
+
+    public static class Deployment
+    {
+        private String artifact;
+        private String file;
+        private String type;
+        private String target;
+        private String delete;
+        private boolean expand;
+        private boolean infuse;
+        private Boolean stripLoggers;
+        private String forcedVersion;
+    }
+    
+    private static class DeploymentObject
+    {
+        Deployment deployment;
+        String name;
+        File fileHandle;
+        Artifact artifact;
+    }
+    
+    /**
+     * The target deploy directory.
+     * @parameter
+     * @required
+     */
+    private String targetDeployDirectory;
+    
+    /**
+     * @parameter expression="false";
+     */
+    private boolean infusionStripLoggers;
+    
+    /**
+     * @parameter expression="2.3";
+     */
+    private String infusionForcedVersion;
+    
+    /**
+     * When true, INFO log copied/skipped resources
+     * @parameter default-value="false"
+     */
+    private boolean verbose;
+    
+    /**
+     * @parameter
+     * @required
+     */
+    private Deployment[] deployments;
+    
+    private List objects = new ArrayList();
+    
+    /** The Maven project.
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    private MavenProject project;
+    
+    /**
+     * @parameter
+     */
+    private Map paths;
+
+    /** @parameter expression="${plugin.introducedDependencyArtifacts}" */
+    private Set pluginDependencyArtifacts;
+    private Artifacts artifacts;
+    
+    /* (non-Javadoc)
+     * @see org.apache.maven.plugin.Mojo#execute()
+     */
+    public void execute() throws MojoExecutionException, MojoFailureException
+    {
+        File targetBaseDir = new File(targetDeployDirectory);
+        if (targetBaseDir.exists() && targetBaseDir.isFile())
+        {
+            throw new MojoExecutionException("targetBaseDirectory "+targetDeployDirectory+" points to a file, not a directory");
+        }
+        else if (!targetBaseDir.exists())
+        {
+            targetBaseDir.mkdirs();
+        }
+        
+        artifacts = new Artifacts(pluginDependencyArtifacts);
+        
+        HashMap pathsMap = new HashMap();
+        // init default for tomcat5.5
+        pathsMap.put("lib","shared/lib");
+        pathsMap.put("war", "webapps");
+        pathsMap.put("portal", "jetspeed");
+        pathsMap.put("deploy", "WEB-INF/deploy");        
+        pathsMap.put("local", "WEB-INF/deploy/local");
+        if (paths != null)
+        {
+            pathsMap.putAll(paths);
+        }
+        
+        boolean infusion = false;
+        for (int i = 0; i < deployments.length; i++)
+        {
+            DeploymentObject dobj = new DeploymentObject();
+            dobj.deployment = deployments[i];
+            if (dobj.deployment.artifact != null)
+            {
+                dobj.artifact = artifacts.get(dobj.deployment.artifact);
+                if (dobj.artifact == null)
+                {
+                    throw new MojoExecutionException("Artifact "+dobj.deployment.artifact+" dependency not defined");
+                }
+                dobj.fileHandle = dobj.artifact.getFile();
+                dobj.name = dobj.deployment.artifact;
+            }
+            else if (dobj.deployment.file != null)
+            {
+                dobj.fileHandle = new File(dobj.deployment.file);
+                if (!dobj.fileHandle.exists() || !dobj.fileHandle.isFile())
+                {
+                    throw new MojoExecutionException("Deployment file "+dobj.deployment.file+" not found");
+                }
+                dobj.name = dobj.deployment.file;
+            }
+            if (pathsMap.get(dobj.deployment.type) == null)
+            {
+                throw new MojoExecutionException("Deployment "+dobj.name+" has unknown type "+dobj.deployment.type);
+            }
+            if ("war".equals(dobj.deployment.type))
+            {
+                if (dobj.deployment.infuse)
+                {
+                    infusion = true;
+                    dobj.deployment.stripLoggers = getValue(dobj.deployment.stripLoggers,infusionStripLoggers);
+                    dobj.deployment.forcedVersion = getValue(dobj.deployment.forcedVersion,infusionForcedVersion);
+                }
+            }
+            objects.add(dobj);
+        }
+        
+        DeployFactory deployFactory = null;
+        if (infusion)
+        {                
+            if (deployFactory == null)
+            {
+                try
+                {
+                    Class dfClass = Class.forName(DEPLOY_FACTORY_CLASS_NAME, true, Thread.currentThread().getContextClassLoader());
+                    deployFactory = (DeployFactory) dfClass.newInstance();
+                }
+                catch (Exception e)
+                {
+                    throw new MojoExecutionException("Cannot find or load DeployFactory class "+ DEPLOY_FACTORY_CLASS_NAME, e);
+                }
+            }
+        }
+        
+        for (Iterator iter = objects.iterator(); iter.hasNext(); )
+        {
+            DeploymentObject dobj = (DeploymentObject)iter.next();
+            File targetDir;
+            if ("deploy".equals(dobj.deployment.type)||"local".equals(dobj.deployment.type))
+            {
+                targetDir = new File(new File(new File(targetBaseDir,(String)pathsMap.get("war")), (String)pathsMap.get("portal")), (String)pathsMap.get(dobj.deployment.type));                
+            }
+            else
+            {
+                targetDir = new File(targetBaseDir,(String)pathsMap.get(dobj.deployment.type));
+            }
+            if (targetDir.exists() && targetBaseDir.isFile())
+            {
+                throw new MojoExecutionException("targetDirectory "+targetDir.getAbsolutePath()+" points to a file, not a directory");
+            }
+            else if (!targetDir.exists())
+            {
+                targetDir.mkdirs();
+            }
+            File target = null;
+            if ("war".equals(dobj.deployment.type))
+            {
+                if (!dobj.deployment.expand)
+                {
+                    if (dobj.deployment.target == null)
+                    {
+                        if (dobj.artifact != null)
+                        {
+                            target = new File(targetDir, dobj.artifact.getArtifactId() + "." + dobj.artifact.getType());
+                        }
+                        else
+                        {
+                            target = new File(targetDir, dobj.fileHandle.getName());
+                        }
+                    }
+                    else
+                    {
+                        target = new File(targetDir, dobj.deployment.target);
+                    }
+                    if (target.isDirectory())
+                    {
+                        throw new MojoExecutionException("Resolved target file "+ target.getAbsolutePath()+" points to a directory");
+                    }
+                }
+                else
+                {
+                    if (dobj.deployment.target != null)
+                    {
+                        target = new File(targetDir, dobj.deployment.target);
+                    }
+                    else
+                    {
+                        String name = dobj.fileHandle.getName();
+                        int index = name.lastIndexOf(".");
+                        if (index > -1)
+                        {
+                            name = name.substring(0, index);
+                        }
+                        target = new File(targetDir, name);
+                    }
+                    if (target.isFile())
+                    {
+                        throw new MojoExecutionException("Resolved target directory "+ target.getAbsolutePath()+" points to a file");
+                    }
+                    if (target.exists() && !rmdir(target))
+                    {
+                        throw new MojoExecutionException("Failed to remove target directory "+ target.getAbsolutePath());
+                    }
+                }
+                if (dobj.deployment.delete != null)
+                {
+                    File delete = null;
+                    if (dobj.deployment.expand)
+                    {
+                        delete = new File(target, dobj.deployment.delete);
+                    }
+                    else
+                    {
+                        delete = new File(target.getParentFile(), dobj.deployment.delete);
+                    }
+                    if (delete.exists())
+                    {
+                        if (delete.isDirectory())
+                        {
+                            if (!rmdir(delete))
+                            {
+                                throw new MojoExecutionException("Failed to delete directory "+ delete.getAbsolutePath());
+                            }
+                        }
+                        else
+                        {
+                            if (!delete.delete())
+                            {
+                                throw new MojoExecutionException("Failed to delete file "+ target.getAbsolutePath());
+                            }
+                        }
+                    }
+                }
+            }
+            else 
+            {
+                if (dobj.deployment.target != null)
+                {
+                    target = new File(targetDir, dobj.deployment.target);
+                }
+                else
+                {
+                    target = new File(targetDir, dobj.fileHandle.getName());
+                }
+                
+                if ("lib".equals(dobj.deployment.type) && dobj.artifact != null)
+                {
+                    deleteMatchingFiles(targetDir, dobj.artifact.getArtifactId(), dobj.artifact.getType());
+                }
+            }
+            if (dobj.deployment.infuse)
+            {                
+                File tmpTarget = null;
+                String targetPath;            
+                if (dobj.deployment.expand)
+                {
+                    try
+                    {
+                        tmpTarget = File.createTempFile(target.getName(), "");
+                        targetPath = tmpTarget.getAbsolutePath();
+                    }
+                    catch (IOException e)
+                    {
+                        throw new MojoExecutionException("Failed to create temporary file",e);
+                    }
+                }
+                else
+                {
+                    targetPath = target.getAbsolutePath();
+                }
+                try
+                {
+                    deployFactory.getInstance(dobj.fileHandle.getAbsolutePath(), targetPath, dobj.deployment.stripLoggers.booleanValue(), dobj.deployment.forcedVersion);
+                }
+                catch (Exception e)
+                {
+                    throw new MojoExecutionException("Failed to infuse "+dobj.fileHandle.getAbsolutePath(),e);
+                }
+                if (tmpTarget != null)
+                {
+                    try
+                    {
+                        expandWar(tmpTarget, target);
+                    }
+                    catch (IOException e)
+                    {
+                        throw new MojoExecutionException("Failed to expand infused war",e);
+                    }
+                    finally
+                    {
+                        tmpTarget.delete();
+                    }
+                }
+            }
+            else
+            {
+                try
+                {
+                    copyFile(dobj.fileHandle, target);
+                }
+                catch (Exception e)
+                {
+                    e.printStackTrace();
+                    throw new MojoExecutionException("Failed to copy "+dobj.fileHandle.getAbsolutePath() +" to "+target.getAbsolutePath(),e);
+                }
+            }
+        }
+    }
+    
+    private static String getValue(String value, String defaultValue)
+    {
+        return value != null ? value : defaultValue;
+    }
+    
+    private static Boolean getValue(Boolean value, boolean defaultValue)
+    {
+        return value != null ? value : new Boolean(defaultValue);
+    }
+    
+    private static final void deleteMatchingFiles(File dir, final String namePrefix, final String ext)
+    {
+        File[] matched = dir.listFiles(new FileFilter(){
+
+            public boolean accept(File file)
+            {
+                String name = file.getName();
+                int index = name.lastIndexOf(".");
+                return index > -1 && file.isFile() && ext.equals(name.substring(index+1)) && name.startsWith(namePrefix);
+            }});
+        
+        if (matched != null)
+        {
+            for (int i = 0; i < matched.length; i++ )
+            {
+                matched[i].delete();
+            }
+        }
+    }
+    
+    private void copyFile(File src, File dest) throws IOException
+    {
+        FileChannel srcChannel = null;
+        FileChannel dstChannel = null;
+
+        try
+        {
+            dest.createNewFile();
+            srcChannel = new FileInputStream(src).getChannel();
+            dstChannel = new FileOutputStream(dest).getChannel();
+            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
+            srcChannel.close();
+            dstChannel.close();
+        }
+        finally
+        {
+            if ( srcChannel != null && srcChannel.isOpen() )
+            {
+                try
+                {
+                    srcChannel.close();
+                }
+                catch (Exception e)
+                {
+                }
+            }
+            if ( dstChannel != null && dstChannel.isOpen() )
+            {
+                try
+                {
+                    dstChannel.close();
+                }
+                catch (Exception e)
+                {
+                }
+            }
+        }
+    }
+
+    private static final boolean rmdir(File dir)
+    {    
+        if (dir.isDirectory())
+        {
+            String[] children = dir.list();
+            for (int i = 0; i < children.length; i++)
+            {
+                boolean success = rmdir(new File(dir, children[i]));
+                if (!success)
+                {
+                    return false;
+                }
+            }
+        }
+        // The directory is now empty so delete it OR it is a plain file
+        return dir.delete();
+    }
+
+    private static void expandWar( File file, File target) throws IOException
+    {
+        JarFile jarFile = new JarFile(file);
+
+        if (!target.exists())
+        {
+            target.mkdirs();
+        }
+
+        Enumeration entries = jarFile.entries();
+        while (entries.hasMoreElements())
+        {
+            JarEntry jarEntry = (JarEntry) entries.nextElement();
+            String name = jarEntry.getName();
+            if (jarEntry.isDirectory())
+            {
+                new File(target, name).mkdir();
+            }
+            else
+            {
+                copyEntryToFile(jarFile, target, jarEntry);
+            }
+        }
+    }
+
+    /**
+     * <p>
+     * copyEntryToFile
+     * </p>
+     * 
+     * @param jarFile
+     * @param target
+     * @param jarEntry
+     * @throws IOException
+     * @throws FileNotFoundException
+     */
+    private static void copyEntryToFile( JarFile jarFile, File target, JarEntry jarEntry ) throws IOException,
+            FileNotFoundException
+    {
+        String name = jarEntry.getName();
+        File file = new File(target, name);
+        if (!file.getParentFile().exists())
+        {
+            file.getParentFile().mkdirs();
+        }
+        file.createNewFile();
+
+        InputStream is = null;
+        OutputStream os = null;
+        try
+        {
+            is = jarFile.getInputStream(jarEntry);
+            os = new FileOutputStream(file);
+
+            byte[] buf = new byte[1024];
+            int len;
+            while ((len = is.read(buf)) > 0)
+            {
+                os.write(buf, 0, len);
+            }
+        }
+        finally
+        {
+            if (is != null)
+            {
+                is.close();
+            }
+
+            if (os != null)
+            {
+                os.close();
+            }
+        }
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/pom.xml?rev=638189&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/pom.xml (added)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/pom.xml Mon Mar 17 20:32:13 2008
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+  
+  $Id$
+-->
+<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>
+  <prerequisites>
+    <maven>2.0.7</maven>
+  </prerequisites>
+
+  <artifactId>jetspeed-maven-utils</artifactId>
+  <name>Jetspeed 2 Maven Utils</name>
+  <description>Jetspeed 2 Maven Utils</description>
+  <parent>
+    <groupId>org.apache.portals.jetspeed-2</groupId>
+    <artifactId>maven</artifactId>
+    <version>2.2-SNAPSHOT</version>
+  </parent>
+  <packaging>jar</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.0.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0.7</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <artifactId>plexus-utils</artifactId>
+      <groupId>org.codehaus.plexus</groupId>
+      <version>1.4.1</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+</project>

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/Artifacts.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/Artifacts.java?rev=638189&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/Artifacts.java (added)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/Artifacts.java Mon Mar 17 20:32:13 2008
@@ -0,0 +1,59 @@
+/*
+ * 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.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * @version $Id$
+ *
+ */
+public class Artifacts
+{
+    private HashMap artifactsMap = new HashMap();
+    
+    public Artifacts(Set artifacts)
+    {
+        if (artifacts != null)
+        {
+            for (Iterator iter = artifacts.iterator(); iter.hasNext(); )
+            {
+                Artifact artifact = (Artifact)iter.next();
+                artifactsMap.put(artifact.getGroupId()+":"+artifact.getArtifactId()+":"+artifact.getType(), artifact);
+            }
+        }        
+    }
+    
+    public int size()
+    {
+        return artifactsMap.size();
+    }
+    
+    public Artifact getFirstArtifact()
+    {
+        return (Artifact)artifactsMap.values().iterator().next();
+    }
+    
+    public Artifact get(String key)
+    {
+        return (Artifact)artifactsMap.get(key);
+    }
+}
\ No newline at end of file

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

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

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

Added: portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/DbConnection.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/DbConnection.java?rev=638189&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/DbConnection.java (added)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/DbConnection.java Mon Mar 17 20:32:13 2008
@@ -0,0 +1,132 @@
+/*
+ * 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.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.settings.Server;
+import org.apache.maven.settings.Settings;
+
+/**
+ * @version $Id$
+ * 
+ */
+public class DbConnection
+{
+    private String username;
+    private String password;
+    private String driver;
+    private String url;
+    private String settingsKey;
+    
+    public String getUrl()
+    {
+        return url;
+    }
+    
+    public String getUsername()
+    {
+        return username;
+    }
+    
+    public void checkSettings(Settings settings)
+    {
+        if (username==null && password==null && settings!=null && settingsKey!=null)
+        {
+            Server server = settings.getServer( settingsKey );
+
+            if ( server != null )
+            {
+                if ( username == null )
+                {
+                    username = server.getUsername();
+                }
+
+                if ( password == null )
+                {
+                    password = server.getPassword();
+                }
+            }
+        }
+
+        if ( username == null )
+        {
+            username = "";
+        }
+
+        if ( password == null )
+        {
+            password = "";
+        }
+    }
+    
+    
+    public Connection getConnection() throws MojoExecutionException
+    {
+        Connection connection = null;
+        
+        if (driver == null)
+        {
+            throw new MojoExecutionException( "dbConnection.driver attribute not specified" );
+        }
+        
+        if (url == null)
+        {
+            throw new MojoExecutionException( "dbConnection.url attribute not specified" );
+        }
+        
+        try
+        {
+            Properties info = new Properties();
+            info.put( "user", username );
+            info.put( "password", password );
+            Driver driverInstance = null;
+            try
+            {
+                Class dc = Class.forName( driver );
+                driverInstance = (Driver) dc.newInstance();
+            }
+            catch ( ClassNotFoundException e )
+            {
+                throw new MojoExecutionException( "Driver class not found: " + driver, e );
+            }
+            catch ( Exception e )
+            {
+                throw new MojoExecutionException( "Failure loading driver: " + driver, e );
+            }
+
+            connection = driverInstance.connect( url, info );
+
+            if ( connection == null )
+            {
+                throw new SQLException( "No suitable Driver for " + url );
+            }
+
+            connection.setAutoCommit( true );
+        }
+        catch ( SQLException e )
+        {
+            throw new MojoExecutionException( e.getMessage(), e );
+        }
+        
+        return connection;
+    }
+}

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

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

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

Added: portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/SeedConfig.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/SeedConfig.java?rev=638189&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/SeedConfig.java (added)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/SeedConfig.java Mon Mar 17 20:32:13 2008
@@ -0,0 +1,82 @@
+/*
+ * 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;
+
+/**
+ * @version $Id$
+ *
+ */
+public class SeedConfig
+{
+    private String propertiesFile;
+    private String applicationPath;
+    private String bootConfigFiles;
+    private String configFiles;
+    private String logLevel;
+    private String options;
+    
+    public String getApplicationPath()
+    {
+        return applicationPath;
+    }
+    public void setApplicationPath(String applicationPath)
+    {
+        this.applicationPath = applicationPath;
+    }
+    public String getBootConfigFiles()
+    {
+        return bootConfigFiles;
+    }
+    public void setBootConfigFiles(String bootConfigFiles)
+    {
+        this.bootConfigFiles = bootConfigFiles;
+    }
+    public String getConfigFiles()
+    {
+        return configFiles;
+    }
+    public void setConfigFiles(String configFiles)
+    {
+        this.configFiles = configFiles;
+    }
+    public String getLogLevel()
+    {
+        return logLevel;
+    }
+    public void setLogLevel(String logLevel)
+    {
+        this.logLevel = logLevel;
+    }
+    public String getOptions()
+    {
+        return options;
+    }
+    public void setOptions(String options)
+    {
+        this.options = options;
+    }
+    public String getPropertiesFile()
+    {
+        return propertiesFile;
+    }
+    public void setPropertiesFile(String propertiesFile)
+    {
+        this.propertiesFile = propertiesFile;
+    }
+    
+    
+}

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

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

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

Added: portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/SqlScripts.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/SqlScripts.java?rev=638189&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/SqlScripts.java (added)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/SqlScripts.java Mon Mar 17 20:32:13 2008
@@ -0,0 +1,298 @@
+/*
+ * 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.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.Reader;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Statement;
+import java.util.StringTokenizer;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.settings.Settings;
+
+/**
+ * @version $Id$
+ *
+ */
+public class SqlScripts
+{
+    public static class Script
+    {
+        String delimiter;
+        String delimiterType;
+        String path;
+        Boolean ignoreErrors;        
+        Boolean escapeProcessing;
+    }
+    
+    private String delimiter = ";";
+    private String delimiterType = "normal";
+    private Boolean escapeProcessing = Boolean.TRUE;
+    private Boolean ignoreErrors = Boolean.FALSE;
+    private Script[] scripts;
+    
+    public boolean isConfigered() throws MojoExecutionException
+    {
+        if (scripts != null && scripts.length > 0)
+        {
+            for (int i = 0; i < scripts.length; i++)
+            {
+                scripts[i].delimiter = getValue(scripts[i].delimiter, delimiter);
+                scripts[i].delimiterType = getValue(scripts[i].delimiterType, delimiterType);
+                scripts[i].escapeProcessing = getValue(scripts[i].escapeProcessing, escapeProcessing);
+                scripts[i].ignoreErrors = getValue(scripts[i].ignoreErrors, ignoreErrors);
+                if (scripts[i].path==null||scripts[i].path.length()==0)
+                {
+                    throw new MojoExecutionException( "sql script["+i+"] path not specified" );
+                }
+            }
+            return true;
+        }
+        return false;
+    }
+    
+    private static String getValue(String value, String defaultValue)
+    {
+        return value != null ? value : defaultValue;
+    }
+    
+    private static Boolean getValue(Boolean value, Boolean defaultValue)
+    {
+        return value != null ? value : defaultValue;
+    }
+    
+    public void execute(DbConnection dbConnection, Log log) throws MojoExecutionException
+    {
+        Connection connection = dbConnection.getConnection();
+        
+        log.info("Running sql scripts against: "+dbConnection.getUrl()+" for user: "+dbConnection.getUsername());
+        
+        try
+        {
+            for ( int i = 0; i < scripts.length; i++ )
+            {
+                runScript(connection, scripts[i], log);
+            }
+        }
+        finally
+        {
+            if ( connection != null )
+            {
+                try
+                {
+                    connection.close();
+                }
+                catch ( SQLException ex )
+                {
+                    // ignore
+                }
+            }
+        }
+    }
+
+    /**
+     * read in lines and execute them
+     */
+    private void runScript( Connection connection, Script script, Log log ) throws MojoExecutionException
+    {
+        File scriptFile = new File(script.path);
+        if ( !scriptFile.exists() || !scriptFile.isFile() )
+        {
+            throw new MojoExecutionException("SQL script file "+scriptFile.getAbsolutePath()+" not found");
+        }
+        else
+        {
+            log.info( "Executing SQL script file: " + scriptFile.getAbsolutePath() );
+            Reader reader = null;
+            Statement statement = null;
+            try
+            {
+                statement = connection.createStatement();
+                statement.setEscapeProcessing(script.escapeProcessing.booleanValue());
+                
+                reader = new FileReader(scriptFile);
+
+                StringBuffer sql = new StringBuffer();
+                String line;
+
+                BufferedReader in = new BufferedReader( reader );
+
+                while ( ( line = in.readLine() ) != null )
+                {
+                    line = line.trim();
+
+                    if ( line.startsWith( "//" ) )
+                    {
+                        continue;
+                    }
+                    if ( line.startsWith( "--" ) )
+                    {
+                        continue;
+                    }
+                    StringTokenizer st = new StringTokenizer( line );
+                    if ( st.hasMoreTokens() )
+                    {
+                        String token = st.nextToken();
+                        if ( "REM".equalsIgnoreCase( token ) )
+                        {
+                            continue;
+                        }
+                    }
+                    sql.append( " " ).append( line );
+
+                    // SQL defines "--" as a comment to EOL
+                    // and in Oracle it may contain a hint
+                    // so we cannot just remove it, instead we must end it
+                    if ( line.indexOf( "--" ) >= 0 )
+                    {
+                        sql.append( "\n" );
+                    }
+                    
+                    if ( ( script.delimiterType.equals( "normal" ) && sql.toString().endsWith( script.delimiter ) )
+                        || ( script.delimiterType.equals( "row" ) && line.equals( script.delimiter ) ) )
+                    {
+                        execSQL( connection, statement, sql.substring( 0, sql.length() - script.delimiter.length() ), script.ignoreErrors.booleanValue(), log );
+                        sql.replace( 0, sql.length(), "" );
+                    }
+                }
+                
+                // Catch any statements not followed by specified delimiter
+                if ( !sql.equals( "" ) )
+                {
+                    execSQL( connection, statement, sql.toString(), script.ignoreErrors.booleanValue(), log );
+                }
+            }
+            catch (Exception e)
+            {
+                throw new MojoExecutionException("Unepected error", e);
+            }
+            finally
+            {
+                if ( statement != null )
+                {
+                    try
+                    {
+                        statement.close();
+                    }
+                    catch ( SQLException ex )
+                    {
+                        // ignore
+                    }
+                }
+                if ( reader != null )
+                {
+                    try
+                    {
+                        reader.close();
+                    }
+                    catch (Exception e)
+                    {
+                        // ignore
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Exec the sql statement.
+     */
+    private void execSQL( Connection connection, Statement statement, String sql, boolean ignoreErrors, Log log ) throws MojoExecutionException
+    {
+        // Check and ignore empty statements
+        if ( "".equals( sql.trim() ) )
+        {
+            return;
+        }
+
+        ResultSet resultSet = null;
+        try
+        {
+            log.debug( "SQL: " + sql );
+
+            boolean ret;
+            int updateCount, updateCountTotal = 0;
+
+            ret = statement.execute( sql );
+            updateCount = statement.getUpdateCount();
+            resultSet = statement.getResultSet();
+            do
+            {
+                if ( !ret )
+                {
+                    if ( updateCount != -1 )
+                    {
+                        updateCountTotal += updateCount;
+                    }
+                }
+                ret = statement.getMoreResults();
+                if ( ret )
+                {
+                    updateCount = statement.getUpdateCount();
+                    resultSet = statement.getResultSet();
+                }
+            }
+            while ( ret );
+
+            if ( updateCountTotal > 0)
+            {
+                log.debug( updateCountTotal + " rows affected" );
+
+                StringBuffer line = new StringBuffer();
+                line.append( updateCountTotal ).append( " rows affected" );
+            }
+
+            SQLWarning warning = connection.getWarnings();
+            while ( warning != null )
+            {
+                log.debug( warning + " sql warning" );
+                warning = warning.getNextWarning();
+            }
+            connection.clearWarnings();
+        }
+        catch ( SQLException e )
+        {
+            log.error( "Failed to execute: " + sql );
+            if ( !ignoreErrors )
+            {
+                throw new MojoExecutionException("Failed to execute: " + sql, e);
+            }
+            log.error( e.toString() );
+        }
+        finally
+        {
+            if ( resultSet != null )
+            {
+                try
+                {
+                    resultSet.close();
+                }
+                catch (SQLException e)
+                {
+                    throw new MojoExecutionException("Unexpected SQL exception: ", e);
+                }
+            }
+        }
+    }
+}

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

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

Propchange: portals/jetspeed-2/portal/trunk/maven/jetspeed-maven-utils/src/main/java/org/apache/jetspeed/maven/utils/SqlScripts.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