|
60 | 60 | import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
61 | 61 | import org.apache.maven.settings.Proxy;
|
62 | 62 | import org.apache.maven.settings.Settings;
|
| 63 | +import org.codehaus.plexus.util.DirectoryScanner; |
63 | 64 | import org.codehaus.plexus.util.FileUtils;
|
64 | 65 | import org.codehaus.plexus.util.IOUtil;
|
65 | 66 | import org.jvnet.jaxb.maven.net.CompositeURILastModifiedResolver;
|
|
75 | 76 | import org.jvnet.jaxb.maven.util.LocaleUtils;
|
76 | 77 | import org.jvnet.jaxb.maven.util.CollectionUtils.Function;
|
77 | 78 | import org.sonatype.plexus.build.incremental.BuildContext;
|
| 79 | +import org.sonatype.plexus.build.incremental.EmptyScanner; |
78 | 80 | import org.xml.sax.EntityResolver;
|
79 | 81 | import org.xml.sax.InputSource;
|
80 | 82 | import org.xml.sax.SAXException;
|
@@ -479,6 +481,7 @@ protected void doExecute() throws MojoExecutionException {
|
479 | 481 | setupDirectories();
|
480 | 482 | doExecute(options);
|
481 | 483 | addIfExistsToEpisodeSchemaBindings();
|
| 484 | + deleteEpisodeIfOnlyFileOnEmptyContext(); |
482 | 485 | final BuildContext buildContext = getBuildContext();
|
483 | 486 | getLog().debug(MessageFormat.format("Refreshing the generated directory [{0}].",
|
484 | 487 | getGenerateDirectory().getAbsolutePath()));
|
@@ -577,6 +580,33 @@ private void addIfExistsToEpisodeSchemaBindings() throws MojoExecutionException
|
577 | 580 | }
|
578 | 581 | }
|
579 | 582 |
|
| 583 | + private void deleteEpisodeIfOnlyFileOnEmptyContext() { |
| 584 | + if (!getEpisode() || getBuildContext() == null) { |
| 585 | + return; |
| 586 | + } |
| 587 | + final File episodeFile = getEpisodeFile(); |
| 588 | + if (getBuildContext().isIncremental() && getBuildContext().newScanner(getGenerateDirectory()) instanceof EmptyScanner) { |
| 589 | + if (!episodeFile.canWrite()) { |
| 590 | + getLog().warn(MessageFormat |
| 591 | + .format("Episode file [{0}] is not writable, could not delete on incremental empty build.", episodeFile)); |
| 592 | + return; |
| 593 | + } |
| 594 | + DirectoryScanner directoryScanner = new DirectoryScanner(); |
| 595 | + directoryScanner.setBasedir(getGenerateDirectory()); |
| 596 | + directoryScanner.setIncludes(getProduces()); |
| 597 | + directoryScanner.scan(); |
| 598 | + |
| 599 | + if (directoryScanner.getIncludedFiles() != null && directoryScanner.getIncludedFiles().length == 1) { |
| 600 | + String fileFound = directoryScanner.getIncludedFiles()[0]; |
| 601 | + if (new File(directoryScanner.getBasedir(), fileFound).equals(episodeFile)) { |
| 602 | + getLog().info(MessageFormat |
| 603 | + .format("directoryScanner got only one file [{0}] which is episodeFile - deleting since running in m2e context.", fileFound, episodeFile)); |
| 604 | + episodeFile.delete(); |
| 605 | + } |
| 606 | + } |
| 607 | + } |
| 608 | + } |
| 609 | + |
580 | 610 | private URILastModifiedResolver uriLastModifiedResolver;
|
581 | 611 |
|
582 | 612 | private void setupURILastModifiedResolver() {
|
|
0 commit comments