Skip to content

[MSOURCES-95] Fix source Jar is re-created even when sources are not changed #2

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

Closed
wants to merge 1 commit into from
Closed

[MSOURCES-95] Fix source Jar is re-created even when sources are not changed #2

wants to merge 1 commit into from

Conversation

plamentotev
Copy link
Contributor

@plamentotev plamentotev commented Jun 17, 2019

If there is an empty source directory (such as generated-sources/annotations for example) the sources Jar will be re-created even if the sources are not changed. The reason is the default include pattern - **/*. It does not include the directory itself and if the directory is empty there is no way for Plexus Archiver to know if the archive is up to date (no file or directory to compare with the last modification time of the archive), so it does the safe thing and re-creates the archive.

Change the default includes pattern to **/**. That will cause the empty directory itself (generated-sources/annotations in our example) to be considered when checking the last modification date so the
archive will not be re-created if it is up to date. Please note that the change of the pattern will not change what is included in the archive - the directory itself will not be included, only its content.

p.s. This is updated version of #1, but I had to create new pull request as I was not able to update the original.

@plamentotev
Copy link
Contributor Author

plamentotev commented Jun 17, 2019

In order to keep the empty source folders I've added .gitingore files. I'm not too happy with the solution as those are git specific files, but I couldn't think of a way to tell the invoker plugin not to copy certain files. SCM files such as .gitingore are part of the default excludes so that at least works - the directory is not empty in the repository so it can be committed, bit on other hand the invoker plugin does not copies its content so it is empty for the tests. Is there a a better way to do that?

@michael-o
Copy link
Member

The canonical approach in Git for retaining empty directories is to put a .gitkeep file into it. I will run your code and adapt it. No issue.

@plamentotev
Copy link
Contributor Author

I've tried with .gitkeep but the invoker plugin copies it and breaks the test (they always pass) because the source folders are not longer empty. It should either be .gitignore (part of the default excludes) or we should somehow add .gitkeep to the excluded files. Didn't fount how to configure this for the invoker plugin (maybe I missed something).

Probably we should add .gitkeep to the default excludes in plexus utils as it is missing and it makes sense to be excluded it. Even more than .gitignore

asfgit pushed a commit that referenced this pull request Jun 17, 2019
If there is an empty source directory (such as
generated-sources/annotations for example) the sources JAR will be
re-created even if the sources have not changed. The reason is the
default include pattern: "**/*". It does not include the directory
itself and if the directory is empty there is no way for
Plexus Archiver to know if the archive is up to date
(no file or directory to compare with the last modification time
of the archive),
so it does the safe thing and re-creates the archive.

Change the default includes pattern to "**/**". That will cause the
empty directory itself (generated-sources/annotations in our example)
to be considered when checking the last modification date so the
archive will not be re-created if it is up to date. Please note that
the change of the pattern will not change what is included in the
archive -- the directory itself will not be included, only its content.

This closes #2
asfgit pushed a commit that referenced this pull request Jun 17, 2019
If there is an empty source directory (such as
generated-sources/annotations for example) the sources JAR will be
re-created even if the sources have not changed. The reason is the
default include pattern: "**/*". It does not include the directory
itself and if the directory is empty there is no way for
Plexus Archiver to know if the archive is up to date
(no file or directory to compare with the last modification time
of the archive),
so it does the safe thing and re-creates the archive.

Change the default includes pattern to "**/**". That will cause the
empty directory itself (generated-sources/annotations in our example)
to be considered when checking the last modification date so the
archive will not be re-created if it is up to date. Please note that
the change of the pattern will not change what is included in the
archive -- the directory itself will not be included, only its content.

This closes #2
@michael-o
Copy link
Member

@plamentotev Something is fishy here: https://builds.apache.org/job/maven-box/job/maven-source-plugin/job/MSOURCES-95/3/console

I cannot make it fail locally. Any idea?

@plamentotev
Copy link
Contributor Author

plamentotev commented Jun 19, 2019

It is interesting case. Actually the code works but the check fails. The test searches for the log messages that the jar is created and then that the jar is up to date:

// Make sure the jars are created on the first build
assert buildLog.text.contains( " Building jar: ${sourcesJarFileName}" )
assert buildLog.text.contains( " Building jar: ${testSourcesJarFileName}" )

// Make sure the jars are not re-created on subsequent builds
assert buildLog.text.contains( " Archive ${sourcesJarFileName} is uptodate" )
assert buildLog.text.contains( " Archive ${testSourcesJarFileName} is uptodate" )

Unfortunately it looks like this does not work on Windows in some cases. The tests searches for f:\jenkins\jenkins-slave\workspace\_maven-source-plugin_MSOURCES-95@2\windows-jdk7-m3.2.x_build\target\it\MSOURCES-95\target\empty-source-directory-1.0-SNAPSHOT-sources.jar but in the logs it is F:\jenkins\jenkins-slave\workspace\_maven-source-plugin_MSOURCES-95@2\windows-jdk7-m3.2.x_build\target\it\MSOURCES-95\target\empty-source-directory-1.0-SNAPSHOT-sources.jar. Notice that the two are equal except for the capital F. In this case the two are equal as the case of the drive latter does not matter.

I've modified the post build script to build the jar files names using file objects instead of concatenating strings. I think that this should fix it. @michael-o would you please try it again. Unfortunately it is not easy to reproduce it locally even on my Windows machine. If this solution does not work I'll use comparison that ignores the letters case.

asfgit pushed a commit that referenced this pull request Jun 19, 2019
If there is an empty source directory (such as
generated-sources/annotations for example) the sources JAR will be
re-created even if the sources have not changed. The reason is the
default include pattern: "**/*". It does not include the directory
itself and if the directory is empty there is no way for
Plexus Archiver to know if the archive is up to date
(no file or directory to compare with the last modification time
of the archive),
so it does the safe thing and re-creates the archive.

Change the default includes pattern to "**/**". That will cause the
empty directory itself (generated-sources/annotations in our example)
to be considered when checking the last modification date so the
archive will not be re-created if it is up to date. Please note that
the change of the pattern will not change what is included in the
archive -- the directory itself will not be included, only its content.

This closes #2
@michael-o
Copy link
Member

Unfortunately, it does not work. I guess Jenkins does lowercase drive letters. Please reset your branch on top of the pushed one and modify the verify script.

…changed

If there is an empty source directory (such as
generated-sources/annotations for example) the sources Jar will be
re-created even if the sources are not changed. The reason is the
default include pattern - "**/*". It does not include the directory
itself and if the directory is empty there is no way for
Plexus Archiver to know if the archive is up to date
(no file or directory to compare with the last modification time
of the archive),
so it does the safe thing and re-creates the archive.

Change the default includes pattern to "**/**". That will cause the
empty directory itself (generated-sources/annotations in our example)
to be considered when checking the last modification date so the
archive will not be re-created if it is up to date. Please note that
the change of the pattern will not change what is included in the
archive - the directory itself will not be included, only its content.
@plamentotev
Copy link
Contributor Author

@michael-o thank you for trying my change. I've updated the verify script to use regex instead of string match.

@asfgit asfgit closed this in 6e715b1 Jun 23, 2019
@plamentotev
Copy link
Contributor Author

@michael-o thank you for updating the verify script.

@jira-importer
Copy link
Collaborator

Resolve #168

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants