|
36 | 36 | import org.apache.maven.shared.model.fileset.util.FileSetManager; |
37 | 37 | import org.codehaus.plexus.archiver.Archiver; |
38 | 38 | import org.codehaus.plexus.archiver.jar.JarArchiver; |
| 39 | +import org.codehaus.plexus.archiver.util.DefaultFileSet; |
39 | 40 |
|
40 | 41 | /** |
41 | 42 | * Base class for creating a jar from project classes. |
@@ -161,6 +162,36 @@ public abstract class AbstractJarMojo extends AbstractMojo { |
161 | 162 | @Parameter(property = "maven.jar.detectMultiReleaseJar", defaultValue = "true") |
162 | 163 | private boolean detectMultiReleaseJar; |
163 | 164 |
|
| 165 | + /** |
| 166 | + * If set to {@code false}, the files that by default are excluded from the resulting archive, |
| 167 | + * like {@code .gitignore}, {@code .cvsignore} etc. will be included. |
| 168 | + * This means all files like the following will be included. |
| 169 | + * <ul> |
| 170 | + * <li>Misc: **/*~, **/#*#, **/.#*, **/%*%, **/._*</li> |
| 171 | + * <li>CVS: **/CVS, **/CVS/**, **/.cvsignore</li> |
| 172 | + * <li>RCS: **/RCS, **/RCS/**</li> |
| 173 | + * <li>SCCS: **/SCCS, **/SCCS/**</li> |
| 174 | + * <li>VSSercer: **/vssver.scc</li> |
| 175 | + * <li>MKS: **/project.pj</li> |
| 176 | + * <li>SVN: **/.svn, **/.svn/**</li> |
| 177 | + * <li>GNU: **/.arch-ids, **/.arch-ids/**</li> |
| 178 | + * <li>Bazaar: **/.bzr, **/.bzr/**</li> |
| 179 | + * <li>SurroundSCM: **/.MySCMServerInfo</li> |
| 180 | + * <li>Mac: **/.DS_Store</li> |
| 181 | + * <li>Serena Dimension: **/.metadata, **/.metadata/**</li> |
| 182 | + * <li>Mercurial: **/.hg, **/.hg/**</li> |
| 183 | + * <li>Git: **/.git, **/.git/**</li> |
| 184 | + * <li>Bitkeeper: **/BitKeeper, **/BitKeeper/**, **/ChangeSet, |
| 185 | + * **/ChangeSet/**</li> |
| 186 | + * <li>Darcs: **/_darcs, **/_darcs/**, **/.darcsrepo, |
| 187 | + * **/.darcsrepo/****/-darcs-backup*, **/.darcs-temp-mail |
| 188 | + * </ul> |
| 189 | + * |
| 190 | + * @since 3.4.0 |
| 191 | + */ |
| 192 | + @Parameter(defaultValue = "true") |
| 193 | + private boolean addDefaultExcludes; |
| 194 | + |
164 | 195 | /** |
165 | 196 | * Return the specific output directory to serve as the root for the archive. |
166 | 197 | * @return get classes directory. |
@@ -222,6 +253,7 @@ public File createArchive() throws MojoExecutionException { |
222 | 253 | jarContentFileSet.setDirectory(getClassesDirectory().getAbsolutePath()); |
223 | 254 | jarContentFileSet.setIncludes(Arrays.asList(getIncludes())); |
224 | 255 | jarContentFileSet.setExcludes(Arrays.asList(getExcludes())); |
| 256 | + jarContentFileSet.setUseDefaultExcludes(addDefaultExcludes); |
225 | 257 |
|
226 | 258 | String[] includedFiles = fileSetManager.getIncludedFiles(jarContentFileSet); |
227 | 259 |
|
@@ -262,7 +294,7 @@ public File createArchive() throws MojoExecutionException { |
262 | 294 | getLog().warn("JAR will be empty - no content was marked for inclusion!"); |
263 | 295 | } |
264 | 296 | } else { |
265 | | - archiver.getArchiver().addDirectory(contentDirectory, getIncludes(), getExcludes()); |
| 297 | + archiver.getArchiver().addFileSet(getFileSet(contentDirectory)); |
266 | 298 | } |
267 | 299 |
|
268 | 300 | archiver.createArchive(session, project, archive); |
@@ -334,4 +366,13 @@ private String[] getExcludes() { |
334 | 366 | } |
335 | 367 | return DEFAULT_EXCLUDES; |
336 | 368 | } |
| 369 | + |
| 370 | + private org.codehaus.plexus.archiver.FileSet getFileSet(File contentDirectory) { |
| 371 | + DefaultFileSet fileSet = DefaultFileSet.fileSet(contentDirectory) |
| 372 | + .includeExclude(getIncludes(), getExcludes()) |
| 373 | + .includeEmptyDirs(true); |
| 374 | + |
| 375 | + fileSet.setUsingDefaultExcludes(false); |
| 376 | + return fileSet; |
| 377 | + } |
337 | 378 | } |
0 commit comments