You are viewing a plain text version of this content. The canonical link for it is here.
Posted to nmaven-commits@incubator.apache.org by si...@apache.org on 2007/05/17 17:21:49 UTC

svn commit: r539030 - in /incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/maven/ src/main/java/org/apache/maven/dotnet/ src/main/java...

Author: sisbell
Date: Thu May 17 10:21:48 2007
New Revision: 539030

URL: http://svn.apache.org/viewvc?view=rev&rev=539030
Log:
Initial import of embedder plugin.

Added:
    incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/
    incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/pom.xml   (with props)
    incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/src/
    incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/src/main/
    incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/src/main/java/
    incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/src/main/java/org/
    incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/src/main/java/org/apache/
    incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/src/main/java/org/apache/maven/
    incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/src/main/java/org/apache/maven/dotnet/
    incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/src/main/java/org/apache/maven/dotnet/plugin/
    incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/src/main/java/org/apache/maven/dotnet/plugin/embedder/
    incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/src/main/java/org/apache/maven/dotnet/plugin/embedder/EmbedderStarterMojo.java   (with props)

Added: incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/pom.xml
URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/pom.xml?view=auto&rev=539030
==============================================================================
--- incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/pom.xml (added)
+++ incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/pom.xml Thu May 17 10:21:48 2007
@@ -0,0 +1,65 @@
+<?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.
+-->
+<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">
+  <parent>
+    <groupId>org.apache.maven.dotnet.plugins</groupId>
+    <version>0.14-SNAPSHOT</version>
+    <artifactId>maven-dotnet-plugins</artifactId>
+  </parent>  
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.dotnet.plugins</groupId>
+  <artifactId>maven-embedder-plugin</artifactId>
+  <packaging>maven-plugin</packaging>
+  <version>0.14-SNAPSHOT</version>
+  <name>maven-embedder-plugin</name>
+  <description>
+    Maven Plugin for .NET
+  </description>
+  <dependencies>
+    <dependency>
+      <groupId>org.mortbay.jetty</groupId>
+      <artifactId>jetty-embedded</artifactId>
+      <version>6.1.3</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.dotnet</groupId>
+      <artifactId>dotnet-artifact</artifactId>
+      <version>0.14-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.dotnet</groupId>
+      <artifactId>dotnet-jetty</artifactId>
+      <version>0.14-SNAPSHOT</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>
\ No newline at end of file

Propchange: incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/src/main/java/org/apache/maven/dotnet/plugin/embedder/EmbedderStarterMojo.java
URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/src/main/java/org/apache/maven/dotnet/plugin/embedder/EmbedderStarterMojo.java?view=auto&rev=539030
==============================================================================
--- incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/src/main/java/org/apache/maven/dotnet/plugin/embedder/EmbedderStarterMojo.java (added)
+++ incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/src/main/java/org/apache/maven/dotnet/plugin/embedder/EmbedderStarterMojo.java Thu May 17 10:21:48 2007
@@ -0,0 +1,239 @@
+package org.apache.maven.dotnet.plugin.embedder;
+
+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.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.artifact.installer.ArtifactInstallationException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.DefaultArtifactRepository;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.dotnet.artifact.AssemblyResolver;
+import org.apache.maven.dotnet.artifact.ArtifactContext;
+import org.apache.maven.dotnet.vendor.VendorInfo;
+import org.apache.maven.dotnet.vendor.VendorFactory;
+import org.apache.maven.dotnet.vendor.VendorUnsupportedException;
+import org.apache.maven.dotnet.PlatformUnsupportedException;
+import org.apache.maven.dotnet.executable.NetExecutable;
+import org.apache.maven.dotnet.executable.ExecutionException;
+import org.apache.maven.dotnet.jetty.JettyStarter;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.HashSet;
+import java.io.File;
+
+
+/**
+ * @goal start
+ * @requiresProject false
+ * @requiresDirectInvocation true
+ */
+public class EmbedderStarterMojo
+    extends AbstractMojo
+{
+    /**
+     * The maven project.
+     *
+     * @parameter expression="${project}"
+     * @required
+     */
+    private MavenProject project;
+
+    /**
+     * @component
+     */
+    private AssemblyResolver assemblyResolver;
+
+    /**
+     * @parameter expression="${settings.localRepository}"
+     * @readonly
+     */
+    private File localRepository;
+
+    /**
+     * @component
+     */
+    private ArtifactContext artifactContext;
+
+    /**
+     * @component
+     */
+    private ArtifactFactory artifactFactory;
+
+    /**
+     * @component
+     */
+    private ArtifactResolver resolver;
+
+    /**
+     * @component
+     */
+    private ArtifactMetadataSource metadata;
+
+    /**
+     * The Vendor for the executable. Supports MONO and MICROSOFT: the default value is <code>MICROSOFT</code>. Not
+     * case or white-space sensitive.
+     *
+     * @parameter expression="${vendor}"
+     */
+    private String vendor;
+
+    /**
+     * @parameter expression = "${vendorVersion}"
+     */
+    private String vendorVersion;
+
+    /**
+     * @parameter expression = "${port}" default-value="8080"
+     */
+    private int port;
+
+    /**
+     * @parameter expression = "${warFile}"
+     * @required
+     */
+    private File warFile;
+
+    /**
+     * @parameter expression = "${frameworkVersion}"
+     */
+    private String frameworkVersion;
+
+    /**
+     * @component
+     */
+    private org.apache.maven.dotnet.executable.NetExecutableFactory netExecutableFactory;
+
+    public void execute()
+        throws MojoExecutionException, MojoFailureException
+    {
+        if ( localRepository == null )
+        {
+            localRepository = new File( System.getProperty( "user.home" ), ".m2/repository" );
+        }
+        //   ArtifactRepository remoteArtifactRepository = new DefaultArtifactRepository( "nmaven", "http://localhost:" +
+        //       port + "/repository", new DefaultRepositoryLayout() );
+
+        ArtifactRepository localArtifactRepository =
+            new DefaultArtifactRepository( "local", "file://" + localRepository, new DefaultRepositoryLayout() );
+        List<ArtifactRepository> remoteRepositories = new ArrayList<ArtifactRepository>();
+        // remoteRepositories.add( remoteArtifactRepository );
+        artifactContext.init( project, remoteRepositories, localRepository );
+
+        try
+        {
+            artifactContext.getArtifactInstaller().resolveAndInstallNetDependenciesForProfile( "VisualStudio2005",
+                                                                                               new ArrayList<Dependency>() );
+        }
+        catch ( ArtifactResolutionException e )
+        {
+            throw new MojoExecutionException( "NMAVEN-1600-003: Unable to resolve assemblies", e );
+        }
+        catch ( ArtifactNotFoundException e )
+        {
+            throw new MojoExecutionException( "NMAVEN-1600-004: Unable to resolve assemblies", e );
+        }
+        catch ( ArtifactInstallationException e )
+        {
+            throw new MojoExecutionException( "NMAVEN-1600-005: Unable to resolve assemblies", e );
+        }
+
+        Set<Artifact> artifactDependencies = new HashSet<Artifact>();
+        Artifact artifact = artifactFactory.createDependencyArtifact( "org.mortbay.jetty", "jetty-embedded",
+                                                                      VersionRange.createFromVersion( "6.1.3" ), "jar",
+                                                                      null, "runtime", null );
+        getLog().info( "NMAVEN-000-000: Dependency: Type  = " + artifact.getType() + ", Artifact ID = " +
+            artifact.getArtifactId() );
+        artifactDependencies.add( artifact );
+
+        ArtifactResolutionResult result = null;
+        try
+        {
+            result = resolver.resolveTransitively( artifactDependencies, project.getArtifact(), localArtifactRepository,
+                                                   project.getRemoteArtifactRepositories(), metadata, null );
+        }
+        catch ( ArtifactResolutionException e )
+        {
+            e.printStackTrace();
+        }
+        catch ( ArtifactNotFoundException e )
+        {
+            e.printStackTrace();
+        }
+
+        List<String> commands = new ArrayList<String>();
+        commands.add( "-Dport=" + String.valueOf( port) );
+        commands.add( "-DwarFile=" + warFile.getAbsolutePath());
+    //    commands.add( "-DwarFile=\"" + new File( localRepository,
+    //                                           "org\\apache\\maven\\dotnet\\dotnet-service-embedder\\0.14-SNAPSHOT\\dotnet-service-embedder-0.14-SNAPSHOT.war" ).getAbsolutePath() + "\"");
+        commands.add( "-classpath" );
+        commands.add( artifactsToClassPath( result.getArtifacts() ) );
+        commands.add( "org.apache.maven.dotnet.jetty.JettyStarter" );
+        System.out.println(commands);
+        VendorInfo vendorInfo = VendorInfo.Factory.createDefaultVendorInfo();
+        if ( vendor != null )
+        {
+            try
+            {
+                vendorInfo.setVendor( VendorFactory.createVendorFromName( vendor ) );
+            }
+            catch ( VendorUnsupportedException e )
+            {
+                throw new MojoExecutionException( "", e );
+            }
+        }
+        vendorInfo.setFrameworkVersion( frameworkVersion );
+        vendorInfo.setVendorVersion( vendorVersion );
+        try
+        {
+
+            Runnable executable =
+                (Runnable) netExecutableFactory.getJavaExecutableFromRepository( vendorInfo, commands );
+            Thread thread = new Thread( executable );
+            thread.start();
+        }
+        catch ( PlatformUnsupportedException e )
+        {
+            throw new MojoExecutionException(
+                "NMAVEN-1400-001: Platform Unsupported: Vendor " + ", frameworkVersion = " + frameworkVersion, e );
+        }
+        /*
+        while(true)
+        {
+            try
+            {
+                Thread.sleep( 500);
+            }
+            catch ( InterruptedException e )
+            {
+                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+            }
+        }
+        */
+    }
+
+    private String artifactsToClassPath( Set<Artifact> artifacts )
+    {
+        StringBuffer sb = new StringBuffer();
+        for ( Artifact artifact : artifacts )
+        {
+            sb.append( "\"" ).append( artifact.getFile().getAbsolutePath() ).append( "\"" ).append( ";" );
+        }
+        //TODO: Cleanup
+        File starterFile = new File( localRepository,
+                                     "org\\apache\\maven\\dotnet\\dotnet-jetty\\0.14-SNAPSHOT\\dotnet-jetty-0.14-SNAPSHOT.jar" );
+        sb.append( "\"" ).append( starterFile.getAbsolutePath() ).append( "\"" );
+        return sb.toString();
+    }
+}

Propchange: incubator/nmaven/branches/SI_XPT/plugins/maven-embedder-plugin/src/main/java/org/apache/maven/dotnet/plugin/embedder/EmbedderStarterMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native