Optional mapping sections in Maven RPM plugin? - maven

I have a Maven RPM plugin mapping thus:
<mapping>
<directory>/etc/myconfig</directory>
<configuration>true</configuration>
<sources>
<source>
<location>${project.build.directory}</location>
<includes>
<include>*.conf</include>
</includes>
</source>
</sources>
</mapping>
However, depending on the packaging process, there may be zero .conf files to put in /etc. When this occurs, RPM plugin says:
[ERROR] Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.1.2:rpm (default) on project clients:
Unable to copy files for packaging: You must set at least one file. -> [Help 1]
Is there any way to have a mapping section that is happy with including zero files?

The best I've been able to come up with is omitting the <includes> tag, which takes everything from what's specified in <location>.
location
The file or directory to include. If a directory is specified, all files and subdirectories are also included.
You will need to be as specific as possible in the path for these mappings that don't have include patterns specified. I added confs to the location below to avoid pulling in everything else in project.build.directory.
Even if no files are selected, the <directory> will still be created.
<mapping>
<directory>/etc/myconfig</directory>
<configuration>true</configuration>
<sources>
<source>
<location>${project.build.directory}/confs</location>
</source>
</sources>
</mapping>

Me too faced the same issue and was trying hard to resolve it. The error message is not so intuitive. It's really hard to address such issue.
error :
[ERROR] Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.1-alpha-3x:attached-rpm (generate-rpm) on project XXX_assembly: Unable to copy files for packaging: You must set at least one file. -> [Help 1]
I was using below version of plugin
*
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.1-alpha-3x</version>
*
Below is my Mapping tag from plugin
What this mapping was trying to is copy batch-test-1.0.war from ../batch/target location to target location at ${app.prefix}/batch
Issue was tag was having name of war file which does not exist and incorrect. i have given wrong name of war file so Maven was complaining that it should have something to copy.i corrected it by giving correct name of my war file as below.
batch-test-1.0.war

Related

How to best copy files within a maven build?

After updating maven-resources-plugin to version 3.2.0 to get the fix for maintaining file permissions (x-bits), the copy fails when encountering a symbolic link of the form file -> ../file (and possibly other symlinks too):
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:copy-resources
(copy-jdk) on project preinstall: <target>/jre/lib/amd64/server/libjsig.so -> [Help 1]
ll <source>/jre/lib/amd64/server/
lrwxrwxrwx 1 user users 13 Oct 22 15:09 libjsig.so -> ../libjsig.so
...
The target's jre/lib/amd64 folder received some files, but not yet libjsig.so. <source>/jre/lib/amd64/libjsig.so exists, therefore the symlink's target would be created if the plugin did not abort.
Can anyone tell me if that's a bug or a feature? Any configuration / idea / workaround that allows to keep the source's file permissions and have symbolic links copied?
Here's the relevant pom.xml part:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<!-- version 3.2.0 stops on symlinks in the jdk, when the symlink target is not yet copied -->
<version>3.1.0</version>
<executions>
<execution>
<id>copy-jdk</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${product.install.folder}/jdk</outputDirectory>
<resources>
<resource>
<directory>${jdk.tmp.folder}/${jdk.directory}</directory>
<filtering>false</filtering>
<include>**/*</include>
</resource>
</resources>
</configuration>
</execution>
...
Edit: BTW, creating a dummy target at <target>/jre/lib/amd64/libjsig.so helps to continue with the copy task, but then, that dummy is not replaced during the copy (probably because it is newer) ...
Edit2: Playing around with the above dummy idea and the <overwrite> option. That option is not usable if the file tree contains read-only files. <overwrite> does not delete and recreate the files but tries to rewrite them, which fails for read-only files.
Therefore I think, the maven-resources-plugin might be the wrong approach to copy files around - here's the evolved question:
What is the best approach to copy a larger set of files (such as a jdk, which includes read-only files, executable files and symbolic links) from within a maven build?

Maven rpm plugin does not overwrite files

I have below configuration in pom.xml file for rpm. I want to copy a jar at specific folder when rpm runs. The code is as below in pom.xml:
<mapping>
<directory>/var/lib/abc</directory>
<filemode>777</filemode>
<username>aaa</username>
<groupname>aaa</groupname>
<sources>
<source>
<location>/opt/lib/temp.jar</location>
</source>
</sources>
</mapping>
The same configuration I have in another pom file for another rpm.
The problem is, when I run the any rpm first it created the folder, copy the file.
Working as expected but I run another rpm file, it generated error that the files are already present and not overwrite those file.
I just want to know, is there any way to overwrite those file or any way avoid the error if the files are already present to that location.
Thanks,
Atul
The issue has been resolved.
There is strange fix I did:
<filemode>777</filemode>
This line I have to added in pom file, where it was missing.
I thought, it would allow me, as the directoy is already created.

cxf-codegen-plugin to exclude XSD files

I use cxf-codegen-plugin to generate a series of WS clients using Maven, on construction time. These WSDL reference some XSD schema definitions using a relative path like so: ../someService/schema.xsd
Now when I trigger a construction from Eclipse this works properly since my XSD files are placed in the right path.
But when I launch a construction job from Jenkins, it fails because it seems it's using Jenkins workspace as the root of the construction.
I don't even know if you can change this behavior of Jenkins, but since I have no control over my Jenkins instance, what I would like to know is for cxf-codegen-plugin to exclude XSD processing altogether, and then generate those classes explicitly using a different execution phase with a different plugin.
I've read you can do it like this:
<defaultOptions>
<extraargs>
<extraarg>-nexclude</extraarg>
<extraarg>http://*.ws.cntxes.emprego.xunta.es</extraarg>
</extraargs>
</defaultOptions>
But this assumes I know those namespaces prior to constructing, which I don't (WSDL files are taken from external dependencies using maven dependency plugin).
I also tried:
<wsdlRoot>${basedir}/src/main/resources/wsdl</wsdlRoot>
<includes>
<include>
**/*.wsdl
</include>
</includes>
<excludes>
<exclude>
*.xsd
</exclude>
</excludes>
But this does not work, the plugin just keeps parsing the XSD files and generating the related classes.
Is there any other way I'm missing to prevent the parsing of XSD files and just process the WSDL definitions?
EDIT: this is the error Jenkins is giving me:
[ERROR] Failed to execute goal org.apache.cxf:cxf-codegen-plugin:2.7.3:wsdl2java (generate-sources-wsclient-cxf) on project my-project: Execution generate-sources-wsclient-cxf of goal org.apache.cxf:cxf-codegen-plugin:2.7.3:wsdl2java failed: org.apache.cxf.wsdl11.WSDLRuntimeException: Fail to create wsdl definition from : file:/var/lib/jenkins/workspace/MYPROJECT/myproject-webservice/src/main/resources/wsdl/Descriptor/serviceDescriptor.wsdl
[ERROR] Caused by : WSDLException (at /definitions/types/xsd:schema): faultCode=PARSER_ERROR: Problem parsing '../xsd/schema.xsd'.: java.io.FileNotFoundException: /var/lib/jenkins/workspace/xsd/actividadFormativa.xsd (No such file or directory)
It is looking on the root of jenkins' workspace instead of /var/lib/jenkins/workspace/MYPROJECT/myproject-webservice/src/main/resources/wsdl/xsd/schema.xsd
I had the same problem (only with the wsdl files). After long research I figured out that the problem was a case sensitivity issue - windows (local CLI and eclipse builds) and the linux/unix hudson/jenkins build environment:
The problematic wsdl had a big letter S
<wsdlOption>
<wsdl>${basedir}/src/main/resources/Some.wsdl</wsdl>
</wsdlOption>
But on the filesystem the file was some.wsdl
So it was not the path issue (.../workspace/...) as I also initially expected...

Maven RPM plugin not generating correct %files section

I'm building a package using the Maven RPM plugin, and it's generating the %files section in the .spec file in a way that causes conflicts during installation. I want to install a file into /usr/bin, but the .spec file contains the following directive:
%attr(755,root,root) /usr/bin
This causes the RPM install to fail due to a conflict with another package which already owns that directory.
What I would like to do is have Maven specify the filename directly, which would avoid the entire issue. Here's the mapping section for that particular file:
<mapping>
<directory>/usr/bin</directory>
<filemode>755</filemode>
<sources>
<source>
<location>src/main/scripts/foobar.sh</location>
<destination>foobar</destination>
</source>
</sources>
</mapping>
Any suggestions?
(I've opened an issue at the plugin bug tracker for this)
As pointed out in the bug, the directoryIncluded[1] mapping controls this behavior. If you set this to false you will get the behavior you desire.
[1] - http://mojo.codehaus.org/rpm-maven-plugin/map-params.html#directoryIncluded
One of the maintainers answered my question on the issue tracker. It turns out that the directoryIncluded mapping does exactly what I want.

Maven rpm plugin does not like 'executable' as a directory path name

In the source mappings, I specify many different directories. All works well.
However if I specify the directory which has the name executable the RPM plugin returns an error code of 1. The files strangely enough are still copied to the RPM buildroot, but the RPM plugin overall fails. I renamed the directory to 'lib' and it builds fine.
Is the executable a reserved word or keyword of some sort??? The mapping below causes the build to fail. I have checked spelling and that is fine. The path exists. So why is it failing???
<mapping>
<directory>/executable</directory> //rpm directory
<filemode>0644</filemode>
<sources>
<source>
<location>/path/to/directory/executable</location> // local dir under target
</source>
</sources>
</mapping>

Resources