-
Notifications
You must be signed in to change notification settings - Fork 101
[#502] : delete episodeFile if only file generated in configuration phase of m2e #503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ | |
import org.apache.maven.project.artifact.InvalidDependencyVersionException; | ||
import org.apache.maven.settings.Proxy; | ||
import org.apache.maven.settings.Settings; | ||
import org.codehaus.plexus.util.DirectoryScanner; | ||
import org.codehaus.plexus.util.FileUtils; | ||
import org.codehaus.plexus.util.IOUtil; | ||
import org.jvnet.jaxb.maven.net.CompositeURILastModifiedResolver; | ||
|
@@ -75,6 +76,7 @@ | |
import org.jvnet.jaxb.maven.util.LocaleUtils; | ||
import org.jvnet.jaxb.maven.util.CollectionUtils.Function; | ||
import org.sonatype.plexus.build.incremental.BuildContext; | ||
import org.sonatype.plexus.build.incremental.EmptyScanner; | ||
import org.xml.sax.EntityResolver; | ||
import org.xml.sax.InputSource; | ||
import org.xml.sax.SAXException; | ||
|
@@ -479,6 +481,7 @@ protected void doExecute() throws MojoExecutionException { | |
setupDirectories(); | ||
doExecute(options); | ||
addIfExistsToEpisodeSchemaBindings(); | ||
deleteEpisodeIfOnlyFileOnEmptyContext(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be better to just not call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alerosmile : there is some scenario (simple ones with no bindings / catalog) where files are just created the right way There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @laurentschoelens : You are right but I once read this: maven-resources-plugin:copy-resources does nothing during onConfiguration. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So you suggest that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the source roots must be added during runOnConfiguration, but according to Igor's comment, no files should be created. I'm not sure but I think Igor is one of the main creator of m2e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact, it's working as expected with only runOnIncremental 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Or not 😄 |
||
final BuildContext buildContext = getBuildContext(); | ||
getLog().debug(MessageFormat.format("Refreshing the generated directory [{0}].", | ||
getGenerateDirectory().getAbsolutePath())); | ||
|
@@ -577,6 +580,33 @@ private void addIfExistsToEpisodeSchemaBindings() throws MojoExecutionException | |
} | ||
} | ||
|
||
private void deleteEpisodeIfOnlyFileOnEmptyContext() { | ||
if (!getEpisode() || getBuildContext() == null) { | ||
return; | ||
} | ||
final File episodeFile = getEpisodeFile(); | ||
if (getBuildContext().isIncremental() && getBuildContext().newScanner(getGenerateDirectory()) instanceof EmptyScanner) { | ||
if (!episodeFile.canWrite()) { | ||
getLog().warn(MessageFormat | ||
.format("Episode file [{0}] is not writable, could not delete on incremental empty build.", episodeFile)); | ||
return; | ||
} | ||
DirectoryScanner directoryScanner = new DirectoryScanner(); | ||
directoryScanner.setBasedir(getGenerateDirectory()); | ||
directoryScanner.setIncludes(getProduces()); | ||
directoryScanner.scan(); | ||
|
||
if (directoryScanner.getIncludedFiles() != null && directoryScanner.getIncludedFiles().length == 1) { | ||
String fileFound = directoryScanner.getIncludedFiles()[0]; | ||
if (new File(directoryScanner.getBasedir(), fileFound).equals(episodeFile)) { | ||
getLog().info(MessageFormat | ||
.format("directoryScanner got only one file [{0}] which is episodeFile - deleting since running in m2e context.", fileFound, episodeFile)); | ||
laurentschoelens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
episodeFile.delete(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private URILastModifiedResolver uriLastModifiedResolver; | ||
|
||
private void setupURILastModifiedResolver() { | ||
|
Uh oh!
There was an error while loading. Please reload this page.