Maven rpm plugin does not overwrite files - maven

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.

Related

rpmbuild - download files during prescriptlet

I'm using the rpm-maven-plugin to build an rpm install of my app.
As part of the rpm install I want to deploy a few tools to the machine that installs the rpm. The downloads are tar files and I want to unzip it to a specific location as part of the post-install steps.
During the prepare step (%pre) I'm downloading a few tools via the prepareScriptlet tag :
wget some-url-tool1 -O ${rpm.info.downloads_dir}/tool1.tar.gz
wget some-url-tool2 -O ${rpm.info.downloads_dir}/tool2.tar.gz
wget some-url-tool3 -O ${rpm.info.downloads_dir}/tool3.tar.gz
I added to the mapping the downloads dir :
<mapping>
<directory>${rpm.info.install_dir}/rpms</directory>
<filemode>700</filemode>
<sources>
<source>
<location>${rpm.info.downloads_dir}</location>
</source>
</sources>
</mapping>
The problem is that the downloads_dir doesn't exist and I need to create it before the spec file is created. I'm getting the following error because I set the directory in the mapping because it doesn't exist (otherwise I will get other error for unchecked files):
[ERROR] Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.2.0:rpm (default-rpm) on project my-project-rpm: Source location /tmp/rpmbuild-downloads does not exist -> [Help 1]
I don't want to download the files to a directory that already exist (/tmp for example) and add a specific include tag for every tar file. Any way to create the directory before the spec file is created?

How do I specify a directory prefix on a set of resources in maven's pom.xml

I have a set of files I'd like to include in the .jar generated by mvn compile. Unfortunately, I would like them to be placed in a specific path inside the .jar. For example, I want shaders/main.glsl to be in the .jar file as com/purplefrog/expglsl/castle/main.glsl
How do I specify this mapping in the pom.xml ? I can not mess with the directory heirarchy of the source project without throwing a wrench into other coders' workflows.
During the process-resources phase non-compilable files can be moved (by the maven-resources-plugin). What you should do is add a resource-block to your pom. Here you need to specify the directory. You can also add a targetPath. All together it would look like
<resource>
<directory>shaders</directory>
<!-- include all ore just a couple of files? -- >
<includes>
<include>main.glsl</include>
</includes>
<targetPath>com/purplefrog/expglsl/castle</targetPath>
</resource>
Now these files are copied to the target/classes and during the package phase they'll become part of the jar.
Take a look at the Maven Resources Plugin and this question.
Sounds like that should handle what you're looking to do if modifying the project structure up front isn't an option.

Optional mapping sections in Maven RPM plugin?

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

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