]
Karel Piwko updated SHRINKRES-217:
----------------------------------
Fix Version/s: 2.2.0-beta-3
(was: 2.2.0-cr-1)
FileUtil.fileFromClassLoaderResource() creates non-unique temporary
file
------------------------------------------------------------------------
Key: SHRINKRES-217
URL:
https://issues.jboss.org/browse/SHRINKRES-217
Project: ShrinkWrap Resolvers
Issue Type: Bug
Components: maven
Affects Versions: 2.0.2
Reporter: Falko M.
Fix For: 2.2.0-beta-3
{{org.jboss.shrinkwrap.resolver.impl.maven.util.FileUtil}} copies a classpath file to the
system temp directory (defined by {{java.io.tmpdir}}) to be able to work with it as a
plain file.
The problem is that the file name is used *as is*.
Now imagine multiple maven-surefire processes running Tests using the same classpath
resource. They all and up trying to write a file with the same name in a (more or less)
global temporary directory.
Because of this we have seen multiple build failures on or Jenkins CI machine which uses
{{-T...}} and {{-DforkCount=...}} liberally like this one:
{noformat}Caused by: org.jboss.shrinkwrap.resolver.api.InvalidConfigurationFileException:
Found 1 problems while building POM model from
/tmp/someproject-main-continuous-1.1.1/META-INF-maven-com.somecompany.someproject-middleware-common-test-pom.xml
1/ [FATAL] Non-readable POM
/tmp/someproject-main-continuous-1.1.1/META-INF-maven-com.somecompany.someproject-middleware-common-test-pom.xml:
no more data available - expected end tags
</version></dependency></dependencies></project> to close start
tag <version> from line 75 and start tag <dependency> from line 77 and start
tag <dependencies> from line 48 and start tag <project> from line 2, parser
stopped on TEXT seen ...<dependency>\n <gro... @78:17 @
/tmp/someproject-main-continuous-1.1.1/META-INF-maven-com.somecompany.someproject-middleware-common-test-pom.xml{noformat}
Solution:
Instead of:
{noformat}File localResource = new File(tmpDir, resourceName.replace("/",
"-").replace("\\", "-").replace(File.pathSeparator,
"-").replaceAll("\\s", "-"));{noformat}
use:
{{File localResource = java.io.File.createTempFile(...)}}
which generates a file name that will most likely be "unique" for a certain
time.