You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by ev...@apache.org on 2004/04/20 16:06:57 UTC

cvs commit: maven-components/maven-plugins/maven-clean-plugin/src/main/resources/META-INF/maven plugin.xml

evenisse    2004/04/20 07:06:57

  Modified:    maven-core bootstrap.plugins
               maven-plugins project.xml
  Added:       maven-plugins/maven-clean-plugin .cvsignore project.xml
               maven-plugins/maven-clean-plugin/src/main/java/org/apache/maven/plugin
                        CleanPlugin.java
               maven-plugins/maven-clean-plugin/src/main/resources/META-INF/maven
                        plugin.xml
  Log:
  A simple clean plugin
  
  Revision  Changes    Path
  1.4       +1 -0      maven-components/maven-core/bootstrap.plugins
  
  Index: bootstrap.plugins
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/bootstrap.plugins,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- bootstrap.plugins	7 Apr 2004 15:17:28 -0000	1.3
  +++ bootstrap.plugins	20 Apr 2004 14:06:57 -0000	1.4
  @@ -1,3 +1,4 @@
  +maven-clean-plugin
   maven-compiler-plugin
   maven-hello-plugin
   maven-jar-plugin
  
  
  
  1.5       +9 -0      maven-components/maven-plugins/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-plugins/project.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- project.xml	16 Apr 2004 14:27:08 -0000	1.4
  +++ project.xml	20 Apr 2004 14:06:57 -0000	1.5
  @@ -32,6 +32,15 @@
           <role>Release Manager</role>
         </roles>
       </developer>
  +    <developer>
  +      <name>Emmanuel Venisse</name>
  +      <id>evenisse</id>
  +      <email>evenisse@apache.org</email>
  +      <organization>Maven</organization>
  +      <roles>
  +        <role>Java Developer</role>
  +      </roles>
  +    </developer>
     </developers>
   
     <build>
  
  
  
  1.1                  maven-components/maven-plugins/maven-clean-plugin/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  *~
  *.log
  target
  *.ipr
  *.iws
  
  
  
  1.1                  maven-components/maven-plugins/maven-clean-plugin/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <project>
    <parent>
      <groupId>maven</groupId>
      <artifactId>maven-plugin</artifactId>
      <version>2.0-SNAPSHOT</version>
    </parent>
    <groupId>maven-clean-plugin</groupId>
    <artifactId>maven-clean-plugin</artifactId>
    <name>Maven</name>
    <currentVersion>1.0-SNAPSHOT</currentVersion>
    <inceptionYear>2001</inceptionYear>
    <package>org.apache.maven</package>
    <logo>/images/maven.gif</logo>
    <repository>
      <connection>scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven-components/maven-plugins/maven-clean-plugin</connection>
      <developerConnection>scm:cvs:ext:${maven.username}@cvs.apache.org:/home/cvs:maven-components/maven-plugins/maven-clean-plugin</developerConnection>
      <url>http://cvs.apache.org/viewcvs.cgi/maven/</url>
    </repository>
    <dependencies>
      <dependency>
        <groupId>maven</groupId>
        <artifactId>maven-core</artifactId>
        <version>2.0-SNAPSHOT</version>
      </dependency>
    </dependencies>
  </project>
  
  
  
  1.1                  maven-components/maven-plugins/maven-clean-plugin/src/main/java/org/apache/maven/plugin/CleanPlugin.java
  
  Index: CleanPlugin.java
  ===================================================================
  package org.apache.maven.plugin;
  
  /*
   * Copyright 2001-2004 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 java.io.File;
  
  /**
   * @author <a href="mailto:evenisse@maven.org">Emmanuel Venisse</a>
   *
   * @version $Id: CleanPlugin.java,v 1.1 2004/04/20 14:06:57 evenisse Exp $
   */
  
  public class CleanPlugin
      extends AbstractPlugin
  {
      private static final int DELETE_RETRY_SLEEP_MILLIS = 10;
  
      private String outputDirectory;
  
      private boolean failedOnError; 
  
      public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
          throws Exception
      {
          outputDirectory = (String) request.getParameter( "outputDirectory" );
  
          failedOnError = Boolean.valueOf(
              (String)request.getParameter( "failedOnError" )).booleanValue();
  
          if ( outputDirectory != null )
          {
              File dir = new File( outputDirectory );
      
              if ( dir.exists() && dir.isDirectory() )
              {
                  log("Deleting directory " + dir.getAbsolutePath());
                  removeDir( dir );
              }
          }
      }
  
      /**
       * Accommodate Windows bug encountered in both Sun and IBM JDKs.
       * Others possible. If the delete does not work, call System.gc(),
       * wait a little and try again.
       */
      private boolean delete(File f)
      {
          if (!f.delete())
          {
              if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1)
              {
                  System.gc();
              }
              try
              {
                  Thread.sleep(DELETE_RETRY_SLEEP_MILLIS);
                  return f.delete();
              }
              catch (InterruptedException ex)
              {
                  return f.delete();
              }
          }
          return true;
      }
  
      /**
       * Delete a directory
       *
       * @param d the directory to delete
       */
      protected void removeDir(File d) throws Exception
      {
          String[] list = d.list();
          if (list == null)
          {
              list = new String[0];
          }
          for (int i = 0; i < list.length; i++)
          {
              String s = list[i];
              File f = new File(d, s);
              if (f.isDirectory())
              {
                  removeDir(f);
              }
              else
              {
                  //log("Deleting " + f.getAbsolutePath());
                  if (!delete(f))
                  {
                      String message = "Unable to delete file "
                          + f.getAbsolutePath();
                      if (failedOnError)
                      {
                          throw new Exception(message);
                      }
                      else
                      {
                          log(message);
                      }
                  }
              }
          }
          //log("Deleting directory " + d.getAbsolutePath());
          if (!delete(d))
          {
              String message = "Unable to delete directory "
                  + d.getAbsolutePath();
              if (failedOnError)
              {
                  throw new Exception(message);
              }
              else
              {
                  log(message);
              }
          }
      }
      
      private void log( String message )
      {
          System.out.println( message );
      }
  }
  
  
  
  1.1                  maven-components/maven-plugins/maven-clean-plugin/src/main/resources/META-INF/maven/plugin.xml
  
  Index: plugin.xml
  ===================================================================
  <plugin>
    <id>clean</id>
    <implementation>org.apache.maven.plugin.CleanPlugin</implementation>
    <instantiation-strategy>singleton</instantiation-strategy>
    <mode>integrated</mode>
    <goals>
      <goal>
        <name>clean</name>
        <parameters>
          <parameter>
            <name>failedOnError</name>
            <expression>false</expression>
          </parameter>
          <parameter>
            <name>outputDirectory</name>
            <expression>#maven.build.dir</expression>
          </parameter>
        </parameters>
      </goal>
    </goals>
  </plugin>
  
  
  

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