Keep permissions on files with Maven resources:tes

2019-03-23 08:41发布

Is it possible to keep permissions on file with Maven resources:testResources? My use case is a Selenium binary driver that I put in /src/test/resources that I would like to be able to use from my tests. My -rwxr-xr-x is however changed to -rw-r--r-- in target/test-classes

2条回答
欢心
2楼-- · 2019-03-23 09:11

I added a profile that gets activated automatically when run on a Unix machine. It executes an in-line shell script to adopt file permissions from all files in a folder recursively to files of the same name in another folder (see SRC and DST variables). The script requires a /bin/sh as well as find, xargs and chmod, which should exist on all modern systems.

    <profile>
        <id>unix</id>
        <activation>
            <os>
                <family>unix</family>
            </os>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>fix-resource-permissions</id>
                            <goals>
                                <goal>exec</goal>
                            </goals>
                            <phase>process-test-resources</phase>
                            <configuration>
                                <executable>/bin/sh</executable>
                                <arguments>
                                    <argument>-c</argument>
                                    <argument>
                                        set -x

                                        SRC="${basedir}/src/test/resources"
                                        DST="${project.build.directory}/test-classes"

                                        find "$$SRC" -printf "%P\0" | xargs --verbose -0 -I {} chmod --reference="$$SRC/{}" -f "$$DST/{}"
                                    </argument>
                                </arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
查看更多
Fickle 薄情
3楼-- · 2019-03-23 09:15

This seems to be a bug in the Maven Resource Plugin

If you are using the Maven Assembly Plugin, you can configure the file permissions there.

If not, you might consider a workaround. You could do this via Ant by doing something like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <id>process-test-classes</id>
            <phase>process-test-classes</phase>
            <configuration>
                <target>
                    <chmod file="target/test-classes/test.sh" perm="755"/>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>
查看更多
登录 后发表回答