Skip to content

Commit eba6a6a

Browse files
committed
[MASSEMBLY-791] overrideUmask option to ensure permissions in packaged archive match expected ones.
1 parent 4d0130c commit eba6a6a

File tree

11 files changed

+238
-0
lines changed

11 files changed

+238
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
40777 dir-a/
2+
100666 dir-a/a1.txt
3+
100666 dir-a/a2.txt
4+
40755 dir-b/
5+
100644 dir-b/b.txt
6+
40777 dir-c/
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23+
<modelVersion>4.0.0</modelVersion>
24+
<parent>
25+
<groupId>org.apache.maven.plugin.assembly.test</groupId>
26+
<artifactId>it-project-parent</artifactId>
27+
<version>1</version>
28+
</parent>
29+
30+
<groupId>org.apache.maven.its</groupId>
31+
<artifactId>massembly-791</artifactId>
32+
<packaging>pom</packaging>
33+
<version>1.0</version>
34+
35+
<properties>
36+
<project.build.outputTimestamp>2023-06-07T10:18:31Z</project.build.outputTimestamp>
37+
</properties>
38+
39+
<build>
40+
<plugins>
41+
<plugin>
42+
<groupId>org.apache.maven.plugins</groupId>
43+
<artifactId>maven-assembly-plugin</artifactId>
44+
<executions>
45+
<execution>
46+
<id>make-assembly</id>
47+
<phase>package</phase>
48+
<goals>
49+
<goal>single</goal>
50+
</goals>
51+
<configuration>
52+
<!-- Follow permissions defined in assembly descriptor -->
53+
<overrideUmask>0</overrideUmask>
54+
<descriptors>
55+
<descriptor>src/assembly/src.xml</descriptor>
56+
</descriptors>
57+
</configuration>
58+
</execution>
59+
</executions>
60+
</plugin>
61+
</plugins>
62+
</build>
63+
64+
</project>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version='1.0'?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
23+
<id>src</id>
24+
<formats>
25+
<format>tar</format>
26+
</formats>
27+
<includeBaseDirectory>false</includeBaseDirectory>
28+
<fileSets>
29+
<fileSet>
30+
<outputDirectory/>
31+
<directory>src/main/resources</directory>
32+
<includes>
33+
<include>dir-a/</include>
34+
</includes>
35+
<fileMode>0666</fileMode>
36+
<directoryMode>0777</directoryMode>
37+
</fileSet>
38+
<fileSet>
39+
<outputDirectory/>
40+
<directory>src/main/resources</directory>
41+
<includes>
42+
<include>dir-b/</include>
43+
</includes>
44+
<fileMode>0644</fileMode>
45+
<directoryMode>0755</directoryMode>
46+
</fileSet>
47+
<fileSet>
48+
<outputDirectory/>
49+
<directory>src/main/resources</directory>
50+
<includes>
51+
<include>dir-c</include>
52+
</includes>
53+
<directoryMode>0777</directoryMode>
54+
</fileSet>
55+
</fileSets>
56+
</assembly>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Workaround to keep empty directory under source control
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import org.apache.commons.compress.archivers.tar.TarArchiveEntry
21+
import org.apache.commons.compress.archivers.tar.TarFile
22+
23+
List<String> expectedEntries = new File( basedir, "expected-entries.txt" ).readLines()
24+
25+
File assembly = new File( new File( basedir, "target" ), "massembly-791-1.0-src.tar" )
26+
27+
assert assembly.exists()
28+
29+
List<String> effectiveEntries = new ArrayList<>()
30+
try ( TarFile tarFile = new TarFile( assembly ) ) {
31+
for ( TarArchiveEntry entry : tarFile.getEntries() )
32+
{
33+
effectiveEntries.add( String.format( "%o %s", entry.getMode(), entry.getName() ) )
34+
}
35+
}
36+
37+
assert expectedEntries == effectiveEntries

src/main/java/org/apache/maven/plugins/assembly/AssemblerConfigurationSource.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,12 @@ public interface AssemblerConfigurationSource {
223223
* @return Override group name.
224224
*/
225225
String getOverrideGroupName();
226+
227+
/**
228+
* @return mask which is applied to permissions of files/directories before they are put into assembly.
229+
* If {@code null} then the mask is not explicitly configured and remains implementation-specific.
230+
*/
231+
default Integer getOverrideUmask() {
232+
return null;
233+
}
226234
}

src/main/java/org/apache/maven/plugins/assembly/archive/DefaultAssemblyArchiver.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ protected Archiver createArchiver(
347347
if (StringUtils.isNotBlank(configSource.getOverrideGroupName())) {
348348
archiver.setOverrideGroupName(StringUtils.trim(configSource.getOverrideGroupName()));
349349
}
350+
final Integer overrideUmask = configSource.getOverrideUmask();
351+
if (overrideUmask != null) {
352+
archiver.setUmask(overrideUmask);
353+
}
350354

351355
return archiver;
352356
}

src/main/java/org/apache/maven/plugins/assembly/mojos/AbstractAssemblyMojo.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,15 @@ public abstract class AbstractAssemblyMojo extends AbstractMojo implements Assem
430430
@Parameter
431431
private String overrideGroupName;
432432

433+
/**
434+
* Override of mask which is applied to permissions of files/directories before they are put into assembly.
435+
* If {@code null} then the mask is not explicitly configured and remains implementation-specific.
436+
* If invalid value is specified - like negative value - then behaviour is implementation specific, i.e. depends
437+
* on underlying library which is used for building of assembly.
438+
*/
439+
@Parameter
440+
private Integer overrideUmask;
441+
433442
public static FixedStringSearchInterpolator mainProjectInterpolator(MavenProject mainProject) {
434443
if (mainProject != null) {
435444
// 5
@@ -879,4 +888,9 @@ public Integer getOverrideGid() {
879888
public String getOverrideGroupName() {
880889
return this.overrideGroupName;
881890
}
891+
892+
@Override
893+
public Integer getOverrideUmask() {
894+
return this.overrideUmask;
895+
}
882896
}

0 commit comments

Comments
 (0)