Coverage Report - org.apache.maven.plugin.eclipse.EclipseCleanMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
EclipseCleanMojo
0%
0/30
0%
0/14
2
 
 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.ide.IdeUtils;
 26  
 
 27  
 /**
 28  
  * Deletes the .project, .classpath, .wtpmodules files and .settings folder used by Eclipse.
 29  
  * 
 30  
  * @goal clean
 31  
  */
 32  0
 public class EclipseCleanMojo
 33  
     extends AbstractMojo
 34  
 {
 35  
 
 36  
     /**
 37  
      * Definition file for Eclipse Web Tools project.
 38  
      */
 39  
     private static final String FILE_DOT_WTPMODULES = ".wtpmodules"; //$NON-NLS-1$
 40  
 
 41  
     /**
 42  
      * Classpath definition file for an Eclipse Java project.
 43  
      */
 44  
     private static final String FILE_DOT_CLASSPATH = ".classpath"; //$NON-NLS-1$
 45  
 
 46  
     /**
 47  
      * Project definition file for an Eclipse Project.
 48  
      */
 49  
     private static final String FILE_DOT_PROJECT = ".project"; //$NON-NLS-1$
 50  
 
 51  
     /**
 52  
      * Web Project definition file for Eclipse Web Tools Project (Release 1.0x).
 53  
      */
 54  
     private static final String DIR_DOT_SETTINGS = ".settings"; //$NON-NLS-1$
 55  
 
 56  
     /**
 57  
      * File name where the WTP component settings will be stored - WTP 1.0 name.
 58  
      */
 59  
     private static final String FILE_DOT_COMPONENT = ".settings/.component"; //$NON-NLS-1$
 60  
 
 61  
     /**
 62  
      * File name where the WTP component settings will be stored - WTP 1.5 name.
 63  
      */
 64  
     private static final String FILE_DOT_COMPONENT_15 = ".settings/org.eclipse.wst.common.component"; //$NON-NLS-1$
 65  
 
 66  
     /**
 67  
      * File name where Eclipse Project's Facet configuration will be stored.
 68  
      */
 69  
     private static final String FILE_FACET_CORE_XML = ".settings/org.eclipse.wst.common.project.facet.core.xml"; //$NON-NLS-1$
 70  
 
 71  
     /**
 72  
      * General project preferences.
 73  
      */
 74  
     private static final String FILE_ECLIPSE_JDT_CORE_PREFS = ".settings/org.eclipse.jdt.core.prefs"; //$NON-NLS-1$
 75  
 
 76  
     /**
 77  
      * AJDT preferences.
 78  
      */
 79  
     private static final String FILE_AJDT_PREFS = ".settings/org.eclipse.ajdt.ui.prefs"; //$NON-NLS-1$
 80  
 
 81  
     /**
 82  
      * Packaging for the current project.
 83  
      * 
 84  
      * @parameter expression="${project.packaging}"
 85  
      */
 86  
     private String packaging;
 87  
 
 88  
     /**
 89  
      * The root directory of the project
 90  
      * 
 91  
      * @parameter expression="${basedir}"
 92  
      */
 93  
     private File basedir;
 94  
 
 95  
     /**
 96  
      * Skip the operation when true.
 97  
      * 
 98  
      * @parameter expression="${eclipse.skip}" default-value="false"
 99  
      */
 100  
     private boolean skip;
 101  
 
 102  
     /**
 103  
      * additional generic configuration files for eclipse
 104  
      * 
 105  
      * @parameter
 106  
      */
 107  
     private EclipseConfigFile[] additionalConfig;
 108  
 
 109  
     /**
 110  
      * @see org.apache.maven.plugin.AbstractMojo#execute()
 111  
      */
 112  
     public void execute()
 113  
         throws MojoExecutionException
 114  
     {
 115  0
         if ( skip )
 116  
         {
 117  0
             return;
 118  
         }
 119  
 
 120  0
         if ( Constants.PROJECT_PACKAGING_POM.equals( this.packaging ) )
 121  
         {
 122  0
             return;
 123  
         }
 124  
 
 125  0
         delete( new File( basedir, FILE_DOT_PROJECT ) );
 126  0
         delete( new File( basedir, FILE_DOT_CLASSPATH ) );
 127  0
         delete( new File( basedir, FILE_DOT_WTPMODULES ) );
 128  
 
 129  0
         delete( new File( basedir, FILE_DOT_COMPONENT ) );
 130  0
         delete( new File( basedir, FILE_DOT_COMPONENT_15 ) );
 131  0
         delete( new File( basedir, FILE_FACET_CORE_XML ) );
 132  0
         delete( new File( basedir, FILE_ECLIPSE_JDT_CORE_PREFS ) );
 133  0
         delete( new File( basedir, FILE_AJDT_PREFS ) );
 134  
 
 135  0
         File settingsDir = new File( basedir, DIR_DOT_SETTINGS );
 136  0
         if ( settingsDir.exists() && settingsDir.isDirectory() && settingsDir.list().length == 0 )
 137  
         {
 138  0
             delete( settingsDir );
 139  
         }
 140  
 
 141  0
         if ( additionalConfig != null )
 142  
         {
 143  0
             for ( int i = 0; i < additionalConfig.length; i++ )
 144  
             {
 145  0
                 delete( new File( basedir, additionalConfig[i].getName() ) );
 146  
             }
 147  
         }
 148  
 
 149  0
         cleanExtras();
 150  0
     }
 151  
 
 152  
     protected void cleanExtras()
 153  
         throws MojoExecutionException
 154  
     {
 155  
         // extension point.
 156  0
     }
 157  
 
 158  
     /**
 159  
      * Delete a file, handling log messages and exceptions
 160  
      * 
 161  
      * @param f File to be deleted
 162  
      * @throws MojoExecutionException only if a file exists and can't be deleted
 163  
      */
 164  
     protected void delete( File f )
 165  
         throws MojoExecutionException
 166  
     {
 167  0
         IdeUtils.delete( f, getLog() );
 168  0
     }
 169  
 
 170  
     /**
 171  
      * Getter for <code>basedir</code>.
 172  
      * 
 173  
      * @return Returns the basedir.
 174  
      */
 175  
     public File getBasedir()
 176  
     {
 177  0
         return this.basedir;
 178  
     }
 179  
 
 180  
     /**
 181  
      * Setter for <code>basedir</code>.
 182  
      * 
 183  
      * @param basedir The basedir to set.
 184  
      */
 185  
     public void setBasedir( File basedir )
 186  
     {
 187  0
         this.basedir = basedir;
 188  0
     }
 189  
 
 190  
     /**
 191  
      * @return the packaging
 192  
      */
 193  
     public String getPackaging()
 194  
     {
 195  0
         return this.packaging;
 196  
     }
 197  
 
 198  
     /**
 199  
      * @param packaging the packaging to set
 200  
      */
 201  
     public void setPackaging( String packaging )
 202  
     {
 203  0
         this.packaging = packaging;
 204  0
     }
 205  
 
 206  
 }