You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2007/03/14 16:31:18 UTC

svn commit: r518183 - in /maven/sandbox/trunk/plugins/maven-lifecycle-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/plugin/ src/main/java/org/apache/...

Author: jdcasey
Date: Wed Mar 14 08:31:16 2007
New Revision: 518183

URL: http://svn.apache.org/viewvc?view=rev&rev=518183
Log:
Plugin that uses the refactored lifecycle (in the 2.1-lifecycle-refactor branch) to output a build plan.

Added:
    maven/sandbox/trunk/plugins/maven-lifecycle-plugin/
    maven/sandbox/trunk/plugins/maven-lifecycle-plugin/pom.xml   (with props)
    maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/
    maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/
    maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/
    maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/
    maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/
    maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/maven/
    maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/maven/plugin/
    maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/maven/plugin/lifecycle/
    maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/maven/plugin/lifecycle/BuildPlanMojo.java   (with props)

Added: maven/sandbox/trunk/plugins/maven-lifecycle-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-lifecycle-plugin/pom.xml?view=auto&rev=518183
==============================================================================
--- maven/sandbox/trunk/plugins/maven-lifecycle-plugin/pom.xml (added)
+++ maven/sandbox/trunk/plugins/maven-lifecycle-plugin/pom.xml Wed Mar 14 08:31:16 2007
@@ -0,0 +1,67 @@
+<?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">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>maven-plugins</artifactId>
+    <groupId>org.apache.maven.plugins</groupId>
+    <version>8</version>
+  </parent>
+  <artifactId>maven-lifecycle-plugin</artifactId>
+  <packaging>maven-plugin</packaging>
+  <name>Maven Lifecycle Utilities Plugin</name>
+  <version>1.0-SNAPSHOT</version>
+  
+  <prerequisites>
+    <maven>2.1-SNAPSHOT</maven>
+  </prerequisites>
+  
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-lifecycle</artifactId>
+      <version>2.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-core</artifactId>
+      <version>2.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>

Propchange: maven/sandbox/trunk/plugins/maven-lifecycle-plugin/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/plugins/maven-lifecycle-plugin/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/maven/plugin/lifecycle/BuildPlanMojo.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/maven/plugin/lifecycle/BuildPlanMojo.java?view=auto&rev=518183
==============================================================================
--- maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/maven/plugin/lifecycle/BuildPlanMojo.java (added)
+++ maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/maven/plugin/lifecycle/BuildPlanMojo.java Wed Mar 14 08:31:16 2007
@@ -0,0 +1,148 @@
+package org.apache.maven.plugin.lifecycle;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import org.apache.maven.lifecycle.LifecycleLoaderException;
+import org.apache.maven.lifecycle.LifecycleSpecificationException;
+import org.apache.maven.lifecycle.plan.BuildPlan;
+import org.apache.maven.lifecycle.plan.BuildPlanUtils;
+import org.apache.maven.lifecycle.plan.BuildPlanner;
+import org.apache.maven.lifecycle.plan.LifecyclePlannerException;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.IOUtil;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+/**
+ * Retrieves the build plan for the current project, and displays it to the logger's INFO log-level,
+ * or a file.
+ *
+ * @goal build-plan
+ */
+public class BuildPlanMojo
+    extends AbstractMojo
+{
+    /**
+     * File for writing the build-plan.
+     * 
+     * @parameter
+     */
+    private File output;
+    
+    /**
+     * Comma-separated list of tasks to complete in the proposed build.
+     * 
+     * @parameter expression="${tasks}" default-value="${package}"
+     * @required
+     */
+    private String tasks;
+    
+    /**
+     * @parameter default-value="${project}"
+     * @required
+     * @readonly
+     */
+    private MavenProject project;
+    
+    /**
+     * @component
+     */
+    private BuildPlanner buildPlanner;
+    
+    public void execute()
+        throws MojoExecutionException
+    {
+        StringTokenizer tokens = new StringTokenizer( tasks, "," );
+        List taskList = new ArrayList( tokens.countTokens() );
+        
+        while( tokens.hasMoreTokens() )
+        {
+            taskList.add( tokens.nextToken().trim() );
+        }
+        
+        BuildPlan buildPlan;
+        try
+        {
+            buildPlan = buildPlanner.constructLifecyclePlan( taskList, project );
+        }
+        catch ( LifecycleLoaderException e )
+        {
+            throw new MojoExecutionException( "Failed to construct build plan. Reason: " + e.getMessage(), e );
+        }
+        catch ( LifecycleSpecificationException e )
+        {
+            throw new MojoExecutionException( "Failed to construct build plan. Reason: " + e.getMessage(), e );
+        }
+        catch ( LifecyclePlannerException e )
+        {
+            throw new MojoExecutionException( "Failed to construct build plan. Reason: " + e.getMessage(), e );
+        }
+        
+        String listing;
+        try
+        {
+            listing = BuildPlanUtils.listBuildPlan( buildPlan );
+        }
+        catch ( LifecycleSpecificationException e )
+        {
+            throw new MojoExecutionException( "Failed to list build plan. Reason: " + e.getMessage(), e );
+        }
+        catch ( LifecyclePlannerException e )
+        {
+            throw new MojoExecutionException( "Failed to list build plan. Reason: " + e.getMessage(), e );
+        }
+        
+        if ( output != null )
+        {
+            if ( output.getParentFile() != null )
+            {
+                output.getParentFile().mkdirs();
+            }
+            
+            FileWriter writer = null;
+            try
+            {
+                writer = new FileWriter( output );
+                
+                writer.write( "Project: " + project.getId() );
+                writer.write( "\nTasks: " + tasks );
+                writer.write( "\nBuildPlan:\n" );
+                writer.write( listing );
+                writer.flush();
+            }
+            catch ( IOException e )
+            {
+                throw new MojoExecutionException( "Failed to write build plan to: " + output + ". Reason: " + e.getMessage(), e );
+            }
+            finally
+            {
+                IOUtil.close( writer );
+            }
+        }
+        else
+        {
+            getLog().info( "\n\nProject: " + project.getId() + "\nTasks: " + tasks + "\nBuild Plan:\n" + listing + "\n\n" );
+        }
+    }
+}

Propchange: maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/maven/plugin/lifecycle/BuildPlanMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/maven/plugin/lifecycle/BuildPlanMojo.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"