Skip to content

Commit

Permalink
[MASSEMBLY-791] umask option to ensure permissions in packaged archiv…
Browse files Browse the repository at this point in the history
…e match expected ones.
  • Loading branch information
mabrarov committed Jul 8, 2023
1 parent 4d0130c commit 679ede9
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/it/projects/bugs/massembly-791/expected-entries.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
40777 dir-a/
100666 dir-a/a1.txt
100666 dir-a/a2.txt
40755 dir-b/
100644 dir-b/b.txt
40777 dir-c/
64 changes: 64 additions & 0 deletions src/it/projects/bugs/massembly-791/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.plugin.assembly.test</groupId>
<artifactId>it-project-parent</artifactId>
<version>1</version>
</parent>

<groupId>org.apache.maven.its</groupId>
<artifactId>massembly-791</artifactId>
<packaging>pom</packaging>
<version>1.0</version>

<properties>
<project.build.outputTimestamp>2023-06-07T10:18:31Z</project.build.outputTimestamp>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<!-- Follow permissions defined in assembly descriptor -->
<umask>0</umask>
<descriptors>
<descriptor>src/assembly/src.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
56 changes: 56 additions & 0 deletions src/it/projects/bugs/massembly-791/src/assembly/src.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version='1.0'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>src</id>
<formats>
<format>tar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<outputDirectory/>
<directory>src/main/resources</directory>
<includes>
<include>dir-a/</include>
</includes>
<fileMode>0666</fileMode>
<directoryMode>0777</directoryMode>
</fileSet>
<fileSet>
<outputDirectory/>
<directory>src/main/resources</directory>
<includes>
<include>dir-b/</include>
</includes>
<fileMode>0644</fileMode>
<directoryMode>0755</directoryMode>
</fileSet>
<fileSet>
<outputDirectory/>
<directory>src/main/resources</directory>
<includes>
<include>dir-c</include>
</includes>
<directoryMode>0777</directoryMode>
</fileSet>
</fileSets>
</assembly>
16 changes: 16 additions & 0 deletions src/it/projects/bugs/massembly-791/src/main/resources/dir-a/a1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
16 changes: 16 additions & 0 deletions src/it/projects/bugs/massembly-791/src/main/resources/dir-a/a2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
16 changes: 16 additions & 0 deletions src/it/projects/bugs/massembly-791/src/main/resources/dir-b/b.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Workaround to keep empty directory under source control
37 changes: 37 additions & 0 deletions src/it/projects/bugs/massembly-791/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.commons.compress.archivers.tar.TarArchiveEntry
import org.apache.commons.compress.archivers.tar.TarFile

List<String> expectedEntries = new File( basedir, "expected-entries.txt" ).readLines()

File assembly = new File( new File( basedir, "target" ), "massembly-791-1.0-src.tar" )

assert assembly.exists()

List<String> effectiveEntries = new ArrayList<>()
try ( TarFile tarFile = new TarFile( assembly ) ) {
for ( TarArchiveEntry entry : tarFile.getEntries() )
{
effectiveEntries.add( String.format( "%o %s", entry.getMode(), entry.getName() ) )
}
}

assert expectedEntries == effectiveEntries
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,12 @@ public interface AssemblerConfigurationSource {
* @return Override group name.
*/
String getOverrideGroupName();

/**
* @return mask which is applied to permissions of files/directories before they are put into the assembly.
* If {@code null} then the mask is not explicitly configured and remains implementation-specific.
*/
default Integer getUmask() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ protected Archiver createArchiver(
if (StringUtils.isNotBlank(configSource.getOverrideGroupName())) {
archiver.setOverrideGroupName(StringUtils.trim(configSource.getOverrideGroupName()));
}
final Integer umask = configSource.getUmask();
if (umask != null) {
archiver.setUmask(umask);
}

return archiver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,15 @@ public abstract class AbstractAssemblyMojo extends AbstractMojo implements Assem
@Parameter
private String overrideGroupName;

/**
* Mask which is applied to permissions of files/directories before they are put into assembly.
* If {@code null} then the mask is not explicitly configured and remains implementation-specific.
* If an invalid value is specified, such as a negative value, then the behaviour is implementation specific.
* That is, it depends on the underlying library which is used for building the assembly.
*/
@Parameter
private Integer umask;

public static FixedStringSearchInterpolator mainProjectInterpolator(MavenProject mainProject) {
if (mainProject != null) {
// 5
Expand Down Expand Up @@ -879,4 +888,9 @@ public Integer getOverrideGid() {
public String getOverrideGroupName() {
return this.overrideGroupName;
}

@Override
public Integer getUmask() {
return this.umask;
}
}

0 comments on commit 679ede9

Please sign in to comment.