Coverage Report - org.apache.maven.plugin.eclipse.EclipseCleanMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
EclipseCleanMojo
0%
0/25
0%
0/14
2.286
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.maven.plugin.eclipse;
 20  
 
 21  
 import java.io.File;
 22  
 
 23  
 import org.apache.maven.plugin.AbstractMojo;
 24  
 import org.apache.maven.plugin.MojoExecutionException;
 25  
 import org.apache.maven.plugin.eclipse.writers.workspace.EclipseWorkspaceWriter;
 26  
 import org.apache.maven.plugin.ide.IdeUtils;
 27  
 
 28  
 /**
 29  
  * Deletes the .project, .classpath, .wtpmodules files and .settings folder used by Eclipse.
 30  
  * 
 31  
  * @goal clean
 32  
  */
 33  0
 public class EclipseCleanMojo
 34  
     extends AbstractMojo
 35  
 {
 36  
 
 37  
     /**
 38  
      * Definition file for Eclipse Web Tools project.
 39  
      */
 40  
     private static final String FILE_DOT_WTPMODULES = ".wtpmodules"; //$NON-NLS-1$
 41  
 
 42  
     /**
 43  
      * Classpath definition file for an Eclipse Java project.
 44  
      */
 45  
     private static final String FILE_DOT_CLASSPATH = ".classpath"; //$NON-NLS-1$
 46  
 
 47  
     /**
 48  
      * Project definition file for an Eclipse Project.
 49  
      */
 50  
     private static final String FILE_DOT_PROJECT = ".project"; //$NON-NLS-1$
 51  
 
 52  
     /**
 53  
      * Packaging for the current project.
 54  
      * 
 55  
      * @parameter expression="${project.packaging}"
 56  
      */
 57  
     private String packaging;
 58  
 
 59  
     /**
 60  
      * The root directory of the project
 61  
      * 
 62  
      * @parameter expression="${basedir}"
 63  
      */
 64  
     private File basedir;
 65  
 
 66  
     /**
 67  
      * Skip the operation when true.
 68  
      * 
 69  
      * @parameter expression="${eclipse.skip}" default-value="false"
 70  
      */
 71  
     private boolean skip;
 72  
 
 73  
     /**
 74  
      * additional generic configuration files for eclipse
 75  
      * 
 76  
      * @parameter
 77  
      */
 78  
     private EclipseConfigFile[] additionalConfig;
 79  
 
 80  
     /**
 81  
      * @see org.apache.maven.plugin.AbstractMojo#execute()
 82  
      */
 83  
     public void execute()
 84  
         throws MojoExecutionException
 85  
     {
 86  0
         if ( skip )
 87  
         {
 88  0
             return;
 89  
         }
 90  
 
 91  0
         if ( Constants.PROJECT_PACKAGING_POM.equals( this.packaging ) )
 92  
         {
 93  0
             return;
 94  
         }
 95  
 
 96  0
         delete( new File( basedir, FILE_DOT_PROJECT ) );
 97  0
         delete( new File( basedir, FILE_DOT_CLASSPATH ) );
 98  0
         delete( new File( basedir, FILE_DOT_WTPMODULES ) );
 99  
 
 100  0
         File settingsDir = new File( basedir, EclipseWorkspaceWriter.DIR_DOT_SETTINGS );
 101  0
         if ( settingsDir.exists() && settingsDir.isDirectory() && settingsDir.list().length == 0 )
 102  
         {
 103  0
             delete( settingsDir );
 104  
         }
 105  
 
 106  0
         if ( additionalConfig != null )
 107  
         {
 108  0
             for ( int i = 0; i < additionalConfig.length; i++ )
 109  
             {
 110  0
                 delete( new File( basedir, additionalConfig[i].getName() ) );
 111  
             }
 112  
         }
 113  
 
 114  0
         cleanExtras();
 115  0
     }
 116  
 
 117  
     protected void cleanExtras()
 118  
         throws MojoExecutionException
 119  
     {
 120  
         // extension point.
 121  0
     }
 122  
 
 123  
     /**
 124  
      * Delete a file, handling log messages and exceptions
 125  
      * 
 126  
      * @param f File to be deleted
 127  
      * @throws MojoExecutionException only if a file exists and can't be deleted
 128  
      */
 129  
     protected void delete( File f )
 130  
         throws MojoExecutionException
 131  
     {
 132  0
         IdeUtils.delete( f, getLog() );
 133  0
     }
 134  
 
 135  
     /**
 136  
      * Getter for <code>basedir</code>.
 137  
      * 
 138  
      * @return Returns the basedir.
 139  
      */
 140  
     public File getBasedir()
 141  
     {
 142  0
         return this.basedir;
 143  
     }
 144  
 
 145  
     /**
 146  
      * Setter for <code>basedir</code>.
 147  
      * 
 148  
      * @param basedir The basedir to set.
 149  
      */
 150  
     public void setBasedir( File basedir )
 151  
     {
 152  0
         this.basedir = basedir;
 153  0
     }
 154  
 
 155  
     /**
 156  
      * @return the packaging
 157  
      */
 158  
     public String getPackaging()
 159  
     {
 160  0
         return this.packaging;
 161  
     }
 162  
 
 163  
     /**
 164  
      * @param packaging the packaging to set
 165  
      */
 166  
     public void setPackaging( String packaging )
 167  
     {
 168  0
         this.packaging = packaging;
 169  0
     }
 170  
 
 171  
 }