1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.eclipse;
20
21 import java.io.File;
22 import java.util.ArrayList;
23 import java.util.Iterator;
24 import java.util.List;
25
26 import org.apache.commons.io.FileUtils;
27 import org.apache.commons.io.filefilter.SuffixFileFilter;
28 import org.apache.commons.io.filefilter.TrueFileFilter;
29 import org.apache.maven.artifact.repository.ArtifactRepository;
30 import org.apache.maven.plugin.AbstractMojo;
31 import org.apache.maven.plugin.MojoExecutionException;
32 import org.apache.maven.plugin.MojoFailureException;
33 import org.apache.maven.plugin.ide.IdeUtils;
34 import org.apache.maven.plugins.annotations.Mojo;
35 import org.apache.maven.plugins.annotations.Parameter;
36
37
38
39
40
41
42
43 @Mojo( name = "remove-cache" )
44 public class RemoveCacheMojo
45 extends AbstractMojo
46 {
47
48
49
50 @Parameter( property = "localRepository", required = true, readonly = true )
51 private ArtifactRepository localRepository;
52
53 public void execute()
54 throws MojoExecutionException, MojoFailureException
55 {
56 getLog().info( Messages.getString( "RemoveCacheMojo.checking" ) );
57 List notAvailableMarkerFiles = getNotAvailableMarkerFiles();
58 if ( !notAvailableMarkerFiles.isEmpty() )
59 {
60 deleteMarkerFiles( notAvailableMarkerFiles );
61 }
62 getLog().info( Messages.getString( "RemoveCacheMojo.complete" ) );
63 }
64
65
66
67
68
69
70 private void deleteMarkerFiles( ListnotAvailableMarkerFiles )
71 {
72 for (Object notAvailableMarkerFile : notAvailableMarkerFiles) {
73 File markerFile = (File) notAvailableMarkerFile;
74 try {
75 IdeUtils.delete(markerFile, getLog());
76 } catch (MojoExecutionException e) {
77 getLog().warn(e.getMessage(), e);
78 }
79 }
80 }
81
82
83
84
85
86
87
88 private ListgetNotAvailableMarkerFiles()
89 {
90 File localRepositoryBaseDirectory = new File( localRepository.getBasedir() );
91 List markerFiles = new ArrayList();
92
93 Iterator iterator =
94 FileUtils.iterateFiles( localRepositoryBaseDirectory,
95 new SuffixFileFilter( IdeUtils.NOT_AVAILABLE_MARKER_FILE_SUFFIX ),
96 TrueFileFilter.INSTANCE );
97 while ( iterator.hasNext() )
98 {
99 File notAvailableMarkerFile = (File) iterator.next();
100 markerFiles.add( notAvailableMarkerFile );
101 }
102 return markerFiles;
103 }
104
105 }