tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject svn commit: r440106 - in /incubator/tuscany/java/sca/plugins: ./ plugin.war/ plugin.war/src/ plugin.war/src/main/ plugin.war/src/main/java/ plugin.war/src/main/java/org/ plugin.war/src/main/java/org/apache/ plugin.war/src/main/java/org/apache/tuscany/ ...
Date Mon, 04 Sep 2006 15:28:02 GMT
Author: jboynes
Date: Mon Sep  4 08:27:56 2006
New Revision: 440106

URL: http://svn.apache.org/viewvc?view=rev&rev=440106
Log:
add war plugin contributed by Meeraj for TUSCANY-688

Added:
    incubator/tuscany/java/sca/plugins/plugin.war/   (with props)
    incubator/tuscany/java/sca/plugins/plugin.war/pom.xml   (with props)
    incubator/tuscany/java/sca/plugins/plugin.war/src/
    incubator/tuscany/java/sca/plugins/plugin.war/src/main/
    incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/
    incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/
    incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/
    incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/
    incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/
    incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/
    incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/Dependency.java
  (with props)
    incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/TuscanyWarMojo.java
  (with props)
Modified:
    incubator/tuscany/java/sca/plugins/pom.xml

Propchange: incubator/tuscany/java/sca/plugins/plugin.war/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Sep  4 08:27:56 2006
@@ -0,0 +1,14 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Added: incubator/tuscany/java/sca/plugins/plugin.war/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/plugins/plugin.war/pom.xml?view=auto&rev=440106
==============================================================================
--- incubator/tuscany/java/sca/plugins/plugin.war/pom.xml (added)
+++ incubator/tuscany/java/sca/plugins/plugin.war/pom.xml Mon Sep  4 08:27:56 2006
@@ -0,0 +1,41 @@
+<project>
+
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.apache.tuscany</groupId>
+    <artifactId>tuscany-war-plugin</artifactId>
+    <packaging>maven-plugin</packaging>
+    <version>1.0-SNAPSHOT</version>
+    <name>Tuscany War Plugin</name>
+    
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-plugin-api</artifactId>
+            <version>2.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-artifact</artifactId>
+            <version>2.0</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>1.2</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    
+</project>

Propchange: incubator/tuscany/java/sca/plugins/plugin.war/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/plugins/plugin.war/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/Dependency.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/Dependency.java?view=auto&rev=440106
==============================================================================
--- incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/Dependency.java
(added)
+++ incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/Dependency.java
Mon Sep  4 08:27:56 2006
@@ -0,0 +1,62 @@
+/*
+ * 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.tuscany.plugin.war;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+
+/**
+ * Represents a configured tuscany dependency for boot and extension
+ * libraries.
+ * 
+ * @version
+ */
+public class Dependency {
+    
+    /**
+     * JAR type artifact.
+     */
+    private static final String TYPE_JAR = "jar";
+    
+    /** 
+     * Group Id that is injected in from configuration.
+     */
+    private String groupId;
+    
+    /** 
+     * Artifact Id that is injected in from configuration.
+     */
+    private String artifactId;
+    
+    /** 
+     * Version that is injected in from configuration.
+     */
+    private String version;
+    
+    /**
+     * Gets the artifact using the specified artifact factory.
+     * 
+     * @param artifactFactory Artifact factory to use.
+     * @return Artifact identified by the dependency.
+     */
+    public Artifact getArtifact(ArtifactFactory artifactFactory) {
+        return artifactFactory.createArtifact(groupId, artifactId, version, Artifact.SCOPE_RUNTIME,
TYPE_JAR);
+    }
+
+}

Propchange: incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/Dependency.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/Dependency.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/TuscanyWarMojo.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/TuscanyWarMojo.java?view=auto&rev=440106
==============================================================================
--- incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/TuscanyWarMojo.java
(added)
+++ incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/TuscanyWarMojo.java
Mon Sep  4 08:27:56 2006
@@ -0,0 +1,248 @@
+/*
+ * 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.tuscany.plugin.war;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.JarOutputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * Goal which touches a timestamp file.
+ * 
+ * @goal tuscany-war
+ * @phase package
+ * @version
+ */
+public class TuscanyWarMojo extends AbstractMojo {
+
+    /**
+     * Tuscany boot path.
+     */
+    private static final String BOOT_PATH = "WEB-INF/tuscany/boot/";
+
+    /**
+     * Tuscany boot path.
+     */
+    private static final String EXTENSION_PATH = "WEB-INF/tuscany/extensions/";
+
+    /**
+     * Used to look up Artifacts in the remote repository.
+     * @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
+     * @required
+     * @readonly
+     */
+    private ArtifactFactory artifactFactory;
+
+    /**
+     * Used to look up Artifacts in the remote repository.
+     * @parameter expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}"
+     * @required
+     * @readonly
+     */
+    protected ArtifactResolver resolver;
+
+    /**
+     * Location of the local repository.
+     * @parameter expression="${localRepository}"
+     * @readonly
+     * @required
+     */
+    private ArtifactRepository localRepository;
+
+    /**
+     * List of Remote Repositories used by the resolver
+     * @parameter expression="${project.remoteArtifactRepositories}"
+     * @readonly
+     * @required
+     */
+    private List remoteRepositories;
+
+    /**
+     * The directory for the generated WAR.
+     * 
+     * @parameter expression="${project.build.directory}"
+     * @required
+     */
+    private String outputDirectory;
+
+    /**
+     * The directory for the generated WAR.
+     * 
+     * @parameter
+     * @required
+     */
+    private Dependency[] bootLibs;
+
+    /**
+     * The directory for the generated WAR.
+     * 
+     * @parameter
+     * @required
+     */
+    private Dependency[] extensions;
+
+    /**
+     * The name of the generated WAR.
+     * 
+     * @parameter expression="${project.build.finalName}"
+     * @required
+     */
+    private String warName;
+
+    /**
+     * Executes the task.
+     * 
+     * The plugin executes the following tasks.
+     * 
+     * <ul>
+     * <li>Adds the specified boot libraries to WEB-INF/tuscany/boot directory</li>
+     * <li>Adds the specified extension artifacts to WEB-INF/tuscany/extensions</li>
+     * <li>Checks for the tuscany context listener in WEB-INF/web.xml</li>
+     * <li>Adds the context listener if not present</li>
+     * <ul>
+     */
+    public void execute() throws MojoExecutionException {
+
+        JarFile originalWar = null;
+        JarOutputStream newWar = null;
+        File originalWarFile = null;
+        File newWarFile = null;
+        
+        boolean success = false;
+        
+        try {
+
+            originalWarFile = new File(outputDirectory, warName + ".war");
+            originalWar = new JarFile(originalWarFile);
+
+            newWarFile = new File(outputDirectory, warName + "-temp.war");
+            newWar = new JarOutputStream(new FileOutputStream(newWarFile));
+
+            copyOriginal(originalWar, newWar);
+
+            for (Dependency dependency : bootLibs) {
+                addTuscanyDependency(newWar, dependency, BOOT_PATH);
+            }
+            for (Dependency dependency : extensions) {
+                addTuscanyDependency(newWar, dependency, EXTENSION_PATH);
+            }
+
+            success = true;
+
+        } catch (Exception ex) {
+            throw new MojoExecutionException(ex.getMessage(), ex);
+        } finally {
+            IOUtils.closeQuietly(newWar);
+        }
+        
+        if(success) {
+            if(!originalWarFile.delete()) {
+                throw new MojoExecutionException("Unable to rename war file");
+            }
+            if(!newWarFile.renameTo(originalWarFile)) {
+                throw new MojoExecutionException("Unable to rename war file");
+            }
+        }
+
+    }
+
+    /**
+     * Adds the tuscany dependency.
+     * 
+     * @param newWar New WAR file.
+     * @param dependency Dependency to be added.
+     * @param path Path to the dependency.
+     * @throws ArtifactNotFoundException 
+     * @throws ArtifactResolutionException 
+     * @throws ArtifactResolutionException If artifact is not resolved.
+     * @throws ArtifactNotFoundException If artifact is not found.
+     * @throws IOException 
+     * @throws IOException In case of an IO error.
+     */
+    private void addTuscanyDependency(JarOutputStream newWar, Dependency dependency, String
path) throws ArtifactResolutionException,
+            ArtifactNotFoundException, IOException {
+
+        FileInputStream artifactStream = null;
+
+        try {
+
+            Artifact artifact = dependency.getArtifact(artifactFactory);
+            resolver.resolve(artifact, remoteRepositories, localRepository);
+
+            File artifactFile = artifact.getFile();
+            artifactStream = new FileInputStream(artifactFile);
+
+            newWar.putNextEntry(new JarEntry(path + artifactFile.getName()));
+            IOUtils.copy(artifactStream, newWar);
+
+            getLog().info("Processed " + path + artifactFile.getName());
+
+        } finally {
+            IOUtils.closeQuietly(artifactStream);
+        }
+    }
+
+    /**
+     * Copy the contents of the original WAR to a temporary WAR.
+     * 
+     * @param originalWar Original WAR file.
+     * @param newWar New war file.
+     * @throws IOException Thrown in case of an IO error.
+     */
+    private void copyOriginal(JarFile originalWar, JarOutputStream newWar) throws IOException
{
+
+        Enumeration entries = originalWar.entries();
+        
+        while (entries.hasMoreElements()) {
+            
+            JarEntry entry = (JarEntry) entries.nextElement();
+            InputStream jarEntryStream = null;
+            
+            try {                
+                jarEntryStream = originalWar.getInputStream(entry);                
+                newWar.putNextEntry(entry);
+                IOUtils.copy(jarEntryStream, newWar);                
+            } finally {
+                IOUtils.closeQuietly(jarEntryStream);
+            }
+            
+        }
+        
+        originalWar.close();
+
+    }
+
+}

Propchange: incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/TuscanyWarMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/plugins/plugin.war/src/main/java/org/apache/tuscany/plugin/war/TuscanyWarMojo.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/plugins/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/plugins/pom.xml?view=diff&rev=440106&r1=440105&r2=440106
==============================================================================
--- incubator/tuscany/java/sca/plugins/pom.xml (original)
+++ incubator/tuscany/java/sca/plugins/pom.xml Mon Sep  4 08:27:56 2006
@@ -27,6 +27,7 @@
     <name>Tuscany SCA Maven Plugins</name>
 
     <modules>
+        <module>plugin.war</module>
         <module>plugin.wsdl2java</module>
         <module>plugin.java2wsdl</module>
     </modules>



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message