Author: baerrach
Date: Sun Dec 14 22:04:54 2008
New Revision: 726621
URL: http://svn.apache.org/viewvc?rev=726621&view=rev
Log:
[MECLIPSE-504] Add a new mojo eclipse:remove-cache
- Moved delete(File) from EclipseCleanMojo into IdeUtils.java
- Added RemoveCacheMojo
- Added IT tests for RemoveCacheMojo
- added commons-io:commons-io:1.4 as a dependency
Added:
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/RemoveCacheMojo.java
(with props)
maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/RemoveCacheMojoIT.java
(with props)
Modified:
maven/plugins/trunk/maven-eclipse-plugin/pom.xml
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java
maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
Modified: maven/plugins/trunk/maven-eclipse-plugin/pom.xml
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/pom.xml?rev=726621&r1=726620&r2=726621&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/pom.xml Sun Dec 14 22:04:54 2008
@@ -48,6 +48,11 @@
</properties>
<dependencies>
<dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>1.0-alpha-7</version>
Modified:
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java?rev=726621&r1=726620&r2=726621&view=diff
==============================================================================
---
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java
(original)
+++
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java
Sun Dec 14 22:04:54 2008
@@ -19,11 +19,10 @@
package org.apache.maven.plugin.eclipse;
import java.io.File;
-import java.io.IOException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
-import org.codehaus.plexus.util.FileUtils;
+import org.apache.maven.plugin.ide.IdeUtils;
/**
* Deletes the .project, .classpath, .wtpmodules files and .settings folder
used by Eclipse.
@@ -165,35 +164,7 @@
protected void delete( File f )
throws MojoExecutionException
{
- if ( f.isDirectory() )
- {
- getLog().info( Messages.getString(
"EclipseCleanMojo.deletingDirectory", f.getName() ) ); //$NON-NLS-1$
- }
- else
- {
- getLog().info( Messages.getString(
"EclipseCleanMojo.deletingFile", f.getName() ) ); //$NON-NLS-1$
- }
-
- if ( f.exists() )
- {
- if ( !f.delete() )
- {
- try
- {
- FileUtils.forceDelete( f );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( Messages.getString(
"EclipseCleanMojo.failedtodelete", //$NON-NLS-1$
- new
Object[] { f.getName(),
-
f.getAbsolutePath() } ) );
- }
- }
- }
- else
- {
- getLog().debug( Messages.getString(
"EclipseCleanMojo.nofilefound", f.getName() ) ); //$NON-NLS-1$
- }
+ IdeUtils.delete( f, getLog() );
}
/**
Added:
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/RemoveCacheMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/RemoveCacheMojo.java?rev=726621&view=auto
==============================================================================
---
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/RemoveCacheMojo.java
(added)
+++
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/RemoveCacheMojo.java
Sun Dec 14 22:04:54 2008
@@ -0,0 +1,110 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugin.eclipse;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.SuffixFileFilter;
+import org.apache.commons.io.filefilter.TrueFileFilter;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.ide.IdeUtils;
+
+/**
+ * Removes the not-available marker files from the repository.
+ *
+ * @author <a href="mailto:[email protected]">Barrie Treloar</a>
+ * @version $Id$
+ * @goal remove-cache
+ */
+public class RemoveCacheMojo
+ extends AbstractMojo
+{
+ /**
+ * Local maven repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ * @readonly
+ */
+ private ArtifactRepository localRepository;
+
+ public void execute()
+ throws MojoExecutionException, MojoFailureException
+ {
+ getLog().info( Messages.getString( "RemoveCacheMojo.checking" ) );
+ List notAvailableMarkerFiles = getNotAvailableMarkerFiles();
+ if ( !notAvailableMarkerFiles.isEmpty() )
+ {
+ deleteMarkerFiles( notAvailableMarkerFiles );
+ }
+ getLog().info( Messages.getString( "RemoveCacheMojo.complete" ) );
+ }
+
+ /**
+ * Delete each file in the notAvailableMarkerFiles list.
+ *
+ * @param notAvailableMarkerFiles the list of marker files to delete.
+ */
+ private void deleteMarkerFiles( List/* <File> */notAvailableMarkerFiles )
+ {
+ for ( Iterator iter = notAvailableMarkerFiles.iterator();
iter.hasNext(); )
+ {
+ File markerFile = (File) iter.next();
+ try
+ {
+ IdeUtils.delete( markerFile, getLog() );
+ }
+ catch ( MojoExecutionException e )
+ {
+ getLog().warn( e.getMessage(), e );
+ }
+ }
+ }
+
+ /**
+ * A list of all the not available marker <code>File</code>s in the
localRepository. If there are no marker files
+ * then an empty list is returned.
+ *
+ * @return all the not available marker files in the localRepository or an
empty list.
+ */
+ private List/* <File> */getNotAvailableMarkerFiles()
+ {
+ File localRepositoryBaseDirectory = new File(
localRepository.getBasedir() );
+ List markerFiles = new ArrayList();
+
+ Iterator iterator =
+ FileUtils.iterateFiles( localRepositoryBaseDirectory,
+ new SuffixFileFilter(
IdeUtils.NOT_AVAILABLE_MARKER_FILE_SUFFIX ),
+ TrueFileFilter.INSTANCE );
+ while ( iterator.hasNext() )
+ {
+ File notAvailableMarkerFile = (File) iterator.next();
+ markerFiles.add( notAvailableMarkerFile );
+ }
+ return markerFiles;
+ }
+
+}
Propchange:
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/RemoveCacheMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java?rev=726621&r1=726620&r2=726621&view=diff
==============================================================================
---
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java
(original)
+++
maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java
Sun Dec 14 22:04:54 2008
@@ -37,6 +37,7 @@
import org.apache.maven.plugin.eclipse.Messages;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
@@ -82,6 +83,50 @@
*/
private static final String PROPERTY_TARGET = "target"; //$NON-NLS-1$
+ /**
+ * The suffix used to mark a file as not available.
+ */
+ public static final String NOT_AVAILABLE_MARKER_FILE_SUFFIX =
"-not-available";
+
+ /**
+ * Delete a file, handling log messages and exceptions
+ *
+ * @param f File to be deleted
+ * @throws MojoExecutionException only if a file exists and can't be
deleted
+ */
+ public static void delete( File f, Log log ) throws MojoExecutionException
+ {
+ if ( f.isDirectory() )
+ {
+ log.info( Messages.getString(
"EclipseCleanMojo.deletingDirectory", f.getName() ) ); //$NON-NLS-1$
+ }
+ else
+ {
+ log.info( Messages.getString( "EclipseCleanMojo.deletingFile",
f.getName() ) ); //$NON-NLS-1$
+ }
+
+ if ( f.exists() )
+ {
+ if ( !f.delete() )
+ {
+ try
+ {
+ FileUtils.forceDelete( f );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( Messages.getString(
"EclipseCleanMojo.failedtodelete", //$NON-NLS-1$
+ new
Object[] { f.getName(),
+
f.getAbsolutePath() } ) );
+ }
+ }
+ }
+ else
+ {
+ log.debug( Messages.getString( "EclipseCleanMojo.nofilefound",
f.getName() ) ); //$NON-NLS-1$
+ }
+ }
+
public static String getCanonicalPath( File file )
throws MojoExecutionException
{
@@ -309,8 +354,8 @@
* @param artifact the artifact
* @return the not-available marker file for the specified artifact
*/
- public static File getNotAvailableMarkerFile(ArtifactRepository
localRepository, Artifact artifact) {
- return new File( localRepository.getBasedir(), localRepository.pathOf(
artifact ) + "-not-available");
+ public static File getNotAvailableMarkerFile( ArtifactRepository
localRepository, Artifact artifact ) {
+ return new File( localRepository.getBasedir(), localRepository.pathOf(
artifact ) + NOT_AVAILABLE_MARKER_FILE_SUFFIX);
}
/**
Modified:
maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties?rev=726621&r1=726620&r2=726621&view=diff
==============================================================================
---
maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
(original)
+++
maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
Sun Dec 14 22:04:54 2008
@@ -75,3 +75,6 @@
AbstractIdeSupportMojo.unabletodeletenotavailablemarkerfile=Unable to delete
marker file: {0}
IdeUtils.errorresolving=Error resolving {0} artifact. Artifact id: {1}
(Message: {2})
+
+RemoveCacheMojo.checking=Checking cache for not available markers
+RemoveCacheMojo.complete=Done
Added:
maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/RemoveCacheMojoIT.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/RemoveCacheMojoIT.java?rev=726621&view=auto
==============================================================================
---
maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/RemoveCacheMojoIT.java
(added)
+++
maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/RemoveCacheMojoIT.java
Sun Dec 14 22:04:54 2008
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+
+package org.apache.maven.plugin.eclipse.it;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * @author <a href="mailto:[email protected]">Barrie Treloar</a>
+ * @version $Id$
+ */
+public class RemoveCacheMojoIT
+ extends AbstractEclipsePluginIT
+{
+ /**
+ * Project-46 uses which does not have sources/javadocs for
biz.aQute:bndlib:0.0.145. Once the repo is seeded with
+ * marker files run remove-cache and verify the marker files no longer
exist.
+ *
+ * @throws Exception test failures
+ */
+ public void testRemoveCache()
+ throws Exception
+ {
+ testProject( "project-46" );
+ assertNotAvailableMarkerFileExists( "biz.aQute", "bndlib", "0.0.145",
null, "sources" );
+ assertNotAvailableMarkerFileExists( "biz.aQute", "bndlib", "0.0.145",
null, "javadoc" );
+
+ File basedir = getTestFile( "target/test-classes/projects/project-46"
);
+ File pom = new File( basedir, "pom.xml" );
+ String pluginSpec = getPluginCLISpecification();
+ List goals = new ArrayList();
+ goals.add( pluginSpec + ":remove-cache" );
+ executeMaven( pom, new Properties(), goals );
+
+ assertNotAvailableMarkerFileDoesNotExist( "biz.aQute", "bndlib",
"0.0.145", null, "sources" );
+ assertNotAvailableMarkerFileDoesNotExist( "biz.aQute", "bndlib",
"0.0.145", null, "javadoc" );
+ }
+}
Propchange:
maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/RemoveCacheMojoIT.java
------------------------------------------------------------------------------
svn:eol-style = native