mojohaus / rpm-maven-plugin

http://www.mojohaus.org/rpm-maven-plugin/
Other
56 stars 48 forks source link

Cannot exclude a certain directory entries. #45

Open aonishuk opened 8 years ago

aonishuk commented 8 years ago

I want to exclude specific directories from being included to rpm like /usr/sbin, /usr/lib, /etc/init.d, /var/lib, /var/log, /var (not it's contents though) this is critical since centos7 won't let you install rpm without doing that. Also I don't want to exclude other directories which are specific to my project (critical for empty dirs). So directoryIncluded=false works bad for me.

Excluding directories with seems not working. Once I add something to exclude it just stops listing directories at all

Here is my definition:

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>rpm-maven-plugin</artifactId>
        <version>2.1.5</version>
        <executions>
          <execution>
            <!-- unbinds rpm creation from maven lifecycle -->
            <phase>none</phase>
            <goals>
              <goal>rpm</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <copyright>2012, Apache Software Foundation</copyright>
          <group>Development</group>
          <description>Maven Recipe: RPM Package.</description>
          <requires>
            <require>${rpm.dependency.list}</require>
          </requires>
          <postinstallScriptlet>
            <scriptFile>src/main/package/rpm/postinstall.sh</scriptFile>
            <fileEncoding>utf-8</fileEncoding>
          </postinstallScriptlet>
          <preinstallScriptlet>
            <scriptFile>src/main/package/rpm/preinstall.sh</scriptFile>
            <fileEncoding>utf-8</fileEncoding>
          </preinstallScriptlet>
          <preremoveScriptlet>
            <scriptFile>src/main/package/rpm/preremove.sh</scriptFile>
            <fileEncoding>utf-8</fileEncoding>
          </preremoveScriptlet>
          <posttransScriptlet>
            <scriptFile>src/main/package/rpm/posttrans_agent.sh</scriptFile>
            <fileEncoding>utf-8</fileEncoding>
          </posttransScriptlet>

          <needarch>x86_64</needarch>
          <autoRequires>false</autoRequires>
          <mappings>
            <mapping>
              <directory>/</directory>
              <sources>
                <source>
                  <location>${project.build.directory}${dirsep}${project.artifactId}-${project.version}</location>
                </source>
              </sources>
            </mapping>
          </mappings>
        </configuration>
      </plugin>

Here is the rpm files list I get:

/etc
/etc/ambari-agent
/etc/ambari-agent/conf
/etc/ambari-agent/conf/ambari-agent.ini
/etc/ambari-agent/conf/logging.conf.sample
/etc/init
/etc/init.d
/etc/init.d/ambari-agent
/etc/init/ambari-agent.conf
/usr
/usr/lib
/usr/lib/ambari-agent
/usr/lib/ambari-agent/lib
/usr/lib/ambari-agent/lib/ambari_commons
/usr/lib/ambari-agent/lib/ambari_commons/__init__.py

This results in problems while installing the package on centos7:

Transaction check error:
  file /usr/lib from install of ambari-server-2.4.0.0-141.x86_64 conflicts with file from package filesystem-3.2-18.el7.x86_64
  file /usr/sbin from install of ambari-server-2.4.0.0-141.x86_64 conflicts with file from package filesystem-3.2-18.el7.x86_64
aonishuk commented 8 years ago

Also I wonder if there's any workaround for this issue, which I can implement in the project not waiting for the rpm-maven-plugin where this is fixed?

dantran commented 8 years ago

2 suggestions:

use:

<mapping>
      <directory>/</directory>
      <sources>
        <source>
          <location>${project.build.directory}${dirsep}${project.artifactId}-${project.version}</location>
          <noDefaultExcludes>true</noDefaultExcludes> <!--add this, not sure it would work -->
        </source>
      </sources>
</mapping>

or split into multiple mappings, each has its own directory ( ie /etc/initd, /use/lib/xxxxx, /etc/init/xxxx, etc )

aonishuk commented 8 years ago

Thanks for quick response dantran.

  1. noDefaultExcludes doesn't work unfortunely.
  2. While splitting works fine, but it is a bit ugly, since mapping have to be duplicated to multiple modules (still the only working way to do fix the issue).

Also I noticed that from the spec point of view this should be as simple as adding:

%exclude /etc
%exclude /etc/init.d
...

in the %files section.

I wonder If there is any way I can do that for rpm maven plugin?

dantran commented 8 years ago
  1. what kind of error do you see?
  2. I am not familiar of maven to %exclude mapping ( may be there is none), need PR :)

I would suggest dont put high hope into this plugin to do complex mappings :-)

foxpluto commented 5 years ago

Hi,

two year are passed since the submission of this problem and I have fallen in the same issue.

I can't understand the "splitting" suggestion read before.

Is there any valuable way to avoid this problem?

Regards, S.

foxpluto commented 5 years ago

opssss,

I have tried the

<directoryIncluded>false</directoryIncluded>

and it actually worked! So now is possible to exclude some directory creation from rpm ?

Regards, S.

dantran commented 5 years ago

like 2-year-old suggestion. I no longer try to do complex mapping at rpm-m-p configuration. The simplest is to stage as much as you can under a dir under 'target' and push all into rpm-m-p in one shot

foxpluto commented 5 years ago

Sorry,

I am not an expert of rpm and maven, I still don't understand. let me explain, I would like to build a rpm for installing these files:

/etc/csvconverter/csvconverter.cfg
/etc/csvconverter/log4j2.xml
/urs/share/csvconverter/lib/commons-cli-1.4.jar
/urs/share/csvconverter/lib/commons-csv-1.5.jar
/urs/share/csvconverter/lib/csvconverter.jar
/urs/share/csvconverter/lib/javax.json-1.1.2.jar
/urs/share/csvconverter/lib/log4j-api-2.11.0.jar
/urs/share/csvconverter/lib/log4j-core-2.11.0.jar
/usr/lib/systemd/system/csvconverter.service

All the files but the last one are in new directory, the last one (/usr/lib/systemd/system/csvconverter.service) is in a system directory that my rpm doesn't have to create.

Which is your suggestion to achieve such a goal?

I have written a pom like this:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>rpm-maven-plugin</artifactId>
    <version>2.2.0</version>
    <executions>
        <execution>
            <id>generate-rpm</id>
            <goals>
                <goal>rpm</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <workarea>/Users/fox/Documents/workspace/2018-03-31_-_CSVConverter</workarea>
        <license>xxx</license>
        <distribution>xxx</distribution>
        <group>Application/Collectors</group>
        <packager>Stefano Bossi</packager>
        <prefix>/usr/share/csvconverter</prefix>
        <changelogFile>src/changelog</changelogFile>
        <version>1.0</version>
        <release>12345</release>
        <requires>
            <require>jre &gt; 1.8</require>
        </requires>
        <needarch>x86_64</needarch>
        <targetOS>linux</targetOS>
        <mappings>
            <mapping>
                <directory>/usr/lib/systemd/system</directory>
                <filemode>644</filemode>
                <username>root</username>
                <groupname>root</groupname>
                <directoryIncluded>false</directoryIncluded>
                <sources>
                    <source>
                        <location>src/main/resources_deploy/csvconverter.service</location>
                    </source>
                </sources>
            </mapping>
            <mapping>
                <directory>/etc/csvconverter</directory>
                <filemode>644</filemode>
                <username>root</username>
                <groupname>root</groupname>
                <configuration>true</configuration>
                <sources>
                    <source>
                        <location>src/main/resources_deploy/csvconverter.cfg</location>
                    </source>
                </sources>
            </mapping>
            <mapping>
                <directory>/etc/csvconverter</directory>
                <filemode>644</filemode>
                <username>root</username>
                <groupname>root</groupname>
                <configuration>true</configuration>
                <sources>
                    <source>
                        <location>src/main/resources_deploy/log4j2.xml</location>
                    </source>
                </sources>
            </mapping>
            <mapping>
                <directory>/urs/share/csvconverter/lib</directory>
                <filemode>644</filemode>
                <username>root</username>
                <groupname>root</groupname>
                <sources>
                    <source>
                        <location>target/csvconverter-1.0.jar</location>
                        <destination>csvconverter.jar</destination>
                    </source>
                </sources>
            </mapping>
            <mapping>
                <directory>/urs/share/csvconverter/lib</directory>
                <filemode>644</filemode>
                <username>root</username>
                <groupname>root</groupname>
                <dependency>
                    <includes>
                        <include>org.apache.commons:commons-csv:1.5</include>
                    </includes>
                </dependency>
            </mapping>
            <mapping>
                <directory>/urs/share/csvconverter/lib</directory>
                <filemode>644</filemode>
                <username>root</username>
                <groupname>root</groupname>
                <dependency>
                    <includes>
                        <include>org.apache.logging.log4j:log4j-api:2.11.0</include>
                    </includes>
                </dependency>
            </mapping>
            <mapping>
                <directory>/urs/share/csvconverter/lib</directory>
                <filemode>644</filemode>
                <username>root</username>
                <groupname>root</groupname>
                <dependency>
                    <includes>
                        <include>org.apache.logging.log4j:log4j-core:2.11.0</include>
                    </includes>
                </dependency>
            </mapping>
            <mapping>
                <directory>/urs/share/csvconverter/lib</directory>
                <filemode>644</filemode>
                <username>root</username>
                <groupname>root</groupname>
                <dependency>
                    <includes>
                        <include>commons-cli:commons-cli:1.4</include>
                    </includes>
                </dependency>
            </mapping>
            <mapping>
                <directory>/urs/share/csvconverter/lib</directory>
                <filemode>644</filemode>
                <username>root</username>
                <groupname>root</groupname>
                <dependency>
                    <includes>
                        <include>org.glassfish:javax.json:1.1.2</include>
                    </includes>
                </dependency>
            </mapping>
        </mappings>
        <postinstallScriptlet>
            <scriptFile>src/main/resources_deploy/postInstallScript.sh</scriptFile>
        </postinstallScriptlet>
    </configuration>
</plugin>

Do you think this could work?

Regards, S.

dantran commented 5 years ago

looks reasonable. you can also use rpm:unpack validate

foxpluto commented 5 years ago

Thanks for the suggestion.

unfortunately running the installation of the package with rpm -vvvi to debug the steps rpm decide to take, I have:

D: ========== Directories not explicitly included in package:
D:          0 /etc/csvconverter/
D:          1 /urs/share/csvconverter/lib/
D:          2 /usr/lib/systemd/system/
D: ==========

Which is wrong, the expected is that only the /usr/lib/systemd/system/ should appear there because is the only one where I have used <directoryIncluded>false</directoryIncluded>.

Is this a bug? Any suggestion to fix the problem?

Thanks, S.

dantran commented 5 years ago

try this

                <source>
                    <location>src/main/resources_deploy</location>
                    <includes>
                       <include>csvconverter.cfg</include>
                    </includes>
                </source>
foxpluto commented 5 years ago

After a lot of tries I finally found a configuration which works for my rpm:

     <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>rpm-maven-plugin</artifactId>
        <version>2.2.0</version>
        <executions>
          <execution>
            <id>generate-rpm</id>
            <goals>
              <goal>rpm</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <workarea>/Users/fox/Documents/workspace/2018-03-31_-_CSVConverter</workarea>
          <license>xxx</license>
          <distribution>xxx</distribution>
          <group>Application/Collectors</group>
          <packager>Stefano Bossi</packager>
          <prefix>/usr/share/csvconverter</prefix>
          <changelogFile>src/changelog</changelogFile>
          <version>1.0</version>
          <release>12345</release>
          <requires>
            <require>jre &gt; 1.8</require>
          </requires>
          <needarch>x86_64</needarch>
          <targetOS>linux</targetOS>
          <mappings>
            <mapping>
              <directory>/etc/csvconverter</directory>
              <filemode>644</filemode>
              <username>root</username>
              <groupname>root</groupname>
              <configuration>true</configuration>
              <sources>
                <source>
                  <location>src/main/resources_deploy/log4j2.xml</location>
                </source>
                <source>
                  <location>src/main/resources_deploy/csvconverter.cfg</location>
                </source>
              </sources>
            </mapping>
            <mapping>
              <directory>/urs/share/csvconverter</directory>
              <filemode>644</filemode>
              <username>root</username>
              <groupname>root</groupname>
            </mapping>
            <mapping>
              <directory>/usr/share/csvconverter/lib</directory>
              <filemode>644</filemode>
              <username>root</username>
              <groupname>root</groupname>
              <sources>
                <source>
                  <location>target/csvconverter-1.0.jar</location>
                  <destination>csvconverter.jar</destination>
                </source>
              </sources>
              <dependency>
                <includes>
                  <include>org.apache.commons:commons-csv:1.5</include>
                  <include>org.apache.logging.log4j:log4j-api:2.11.0</include>
                  <include>org.apache.logging.log4j:log4j-core:2.11.0</include>
                  <include>commons-cli:commons-cli:1.4</include>
                  <include>org.glassfish:javax.json:1.1.2</include>
                </includes>
              </dependency>
            </mapping>
            <mapping>
              <directory>/usr/lib/systemd/system</directory>
              <filemode>644</filemode>
              <username>root</username>
              <groupname>root</groupname>
              <directoryIncluded>false</directoryIncluded>
              <sources>
                <source>
                  <location>src/main/resources_deploy/csvconverter.service</location>
                </source>
              </sources>
            </mapping>
          </mappings>
          <postinstallScriptlet>
            <scriptFile>src/main/resources_deploy/postInstallScript.sh</scriptFile>
          </postinstallScriptlet>
        </configuration>
      </plugin>

Hope this could help other guys using this plugin.

Regards, S.