|
38 | 38 | import org.apache.maven.toolchain.ToolchainManager;
|
39 | 39 | import org.codehaus.plexus.archiver.Archiver;
|
40 | 40 | import org.codehaus.plexus.archiver.jar.JarArchiver;
|
| 41 | +import org.codehaus.plexus.archiver.util.DefaultFileSet; |
41 | 42 |
|
42 | 43 | /**
|
43 | 44 | * Base class for creating a jar from project classes.
|
@@ -169,6 +170,38 @@ public abstract class AbstractJarMojo extends AbstractMojo {
|
169 | 170 | @Parameter(property = "maven.jar.detectMultiReleaseJar", defaultValue = "true")
|
170 | 171 | private boolean detectMultiReleaseJar;
|
171 | 172 |
|
| 173 | + /** |
| 174 | + * If set to {@code false}, the files and directories that by default are excluded from the resulting archive, |
| 175 | + * like {@code .gitignore}, {@code .cvsignore} etc. will be included. |
| 176 | + * This means all files like the following will be included. |
| 177 | + * <ul> |
| 178 | + * <li>Misc: **/*~, **/#*#, **/.#*, **/%*%, **/._*</li> |
| 179 | + * <li>CVS: **/CVS, **/CVS/**, **/.cvsignore</li> |
| 180 | + * <li>RCS: **/RCS, **/RCS/**</li> |
| 181 | + * <li>SCCS: **/SCCS, **/SCCS/**</li> |
| 182 | + * <li>VSSercer: **/vssver.scc</li> |
| 183 | + * <li>MKS: **/project.pj</li> |
| 184 | + * <li>SVN: **/.svn, **/.svn/**</li> |
| 185 | + * <li>GNU: **/.arch-ids, **/.arch-ids/**</li> |
| 186 | + * <li>Bazaar: **/.bzr, **/.bzr/**</li> |
| 187 | + * <li>SurroundSCM: **/.MySCMServerInfo</li> |
| 188 | + * <li>Mac: **/.DS_Store</li> |
| 189 | + * <li>Serena Dimension: **/.metadata, **/.metadata/**</li> |
| 190 | + * <li>Mercurial: **/.hg, **/.hg/**</li> |
| 191 | + * <li>Git: **/.git, **/.git/**</li> |
| 192 | + * <li>Bitkeeper: **/BitKeeper, **/BitKeeper/**, **/ChangeSet, |
| 193 | + * **/ChangeSet/**</li> |
| 194 | + * <li>Darcs: **/_darcs, **/_darcs/**, **/.darcsrepo, |
| 195 | + * **/.darcsrepo/****/-darcs-backup*, **/.darcs-temp-mail |
| 196 | + * </ul> |
| 197 | + * |
| 198 | + * @see <a href="https://codehaus-plexus.github.io/plexus-utils/apidocs/org/codehaus/plexus/util/AbstractScanner.html#DEFAULTEXCLUDES">DEFAULTEXCLUDES</a> |
| 199 | + * |
| 200 | + * @since 3.4.0 |
| 201 | + */ |
| 202 | + @Parameter(defaultValue = "true") |
| 203 | + private boolean addDefaultExcludes; |
| 204 | + |
172 | 205 | /**
|
173 | 206 | * Return the specific output directory to serve as the root for the archive.
|
174 | 207 | * @return get classes directory.
|
@@ -281,7 +314,7 @@ public File createArchive() throws MojoExecutionException {
|
281 | 314 | getLog().warn("JAR will be empty - no content was marked for inclusion!");
|
282 | 315 | }
|
283 | 316 | } else {
|
284 |
| - archiver.getArchiver().addDirectory(contentDirectory, getIncludes(), getExcludes()); |
| 317 | + archiver.getArchiver().addFileSet(getFileSet(contentDirectory)); |
285 | 318 | }
|
286 | 319 |
|
287 | 320 | archiver.createArchive(session, project, archive);
|
@@ -353,4 +386,14 @@ private String[] getExcludes() {
|
353 | 386 | }
|
354 | 387 | return DEFAULT_EXCLUDES;
|
355 | 388 | }
|
| 389 | + |
| 390 | + private org.codehaus.plexus.archiver.FileSet getFileSet(File contentDirectory) { |
| 391 | + DefaultFileSet fileSet = DefaultFileSet.fileSet(contentDirectory) |
| 392 | + .prefixed("") |
| 393 | + .includeExclude(getIncludes(), getExcludes()) |
| 394 | + .includeEmptyDirs(true); |
| 395 | + |
| 396 | + fileSet.setUsingDefaultExcludes(addDefaultExcludes); |
| 397 | + return fileSet; |
| 398 | + } |
356 | 399 | }
|
0 commit comments