diff --git a/src/it/projects/bugs/massembly-791/expected-entries.txt b/src/it/projects/bugs/massembly-791/expected-entries.txt new file mode 100644 index 00000000..19bcddb4 --- /dev/null +++ b/src/it/projects/bugs/massembly-791/expected-entries.txt @@ -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/ \ No newline at end of file diff --git a/src/it/projects/bugs/massembly-791/pom.xml b/src/it/projects/bugs/massembly-791/pom.xml new file mode 100644 index 00000000..b01a400f --- /dev/null +++ b/src/it/projects/bugs/massembly-791/pom.xml @@ -0,0 +1,64 @@ + + + + 4.0.0 + + org.apache.maven.plugin.assembly.test + it-project-parent + 1 + + + org.apache.maven.its + massembly-791 + pom + 1.0 + + + 2023-06-07T10:18:31Z + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + make-assembly + package + + single + + + + 0 + + src/assembly/src.xml + + + + + + + + + diff --git a/src/it/projects/bugs/massembly-791/src/assembly/src.xml b/src/it/projects/bugs/massembly-791/src/assembly/src.xml new file mode 100644 index 00000000..bd51a0e2 --- /dev/null +++ b/src/it/projects/bugs/massembly-791/src/assembly/src.xml @@ -0,0 +1,56 @@ + + + + src + + tar + + false + + + + src/main/resources + + dir-a/ + + 0666 + 0777 + + + + src/main/resources + + dir-b/ + + 0644 + 0755 + + + + src/main/resources + + dir-c + + 0777 + + + diff --git a/src/it/projects/bugs/massembly-791/src/main/resources/dir-a/a1.txt b/src/it/projects/bugs/massembly-791/src/main/resources/dir-a/a1.txt new file mode 100644 index 00000000..978b68af --- /dev/null +++ b/src/it/projects/bugs/massembly-791/src/main/resources/dir-a/a1.txt @@ -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. diff --git a/src/it/projects/bugs/massembly-791/src/main/resources/dir-a/a2.txt b/src/it/projects/bugs/massembly-791/src/main/resources/dir-a/a2.txt new file mode 100644 index 00000000..978b68af --- /dev/null +++ b/src/it/projects/bugs/massembly-791/src/main/resources/dir-a/a2.txt @@ -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. diff --git a/src/it/projects/bugs/massembly-791/src/main/resources/dir-b/b.txt b/src/it/projects/bugs/massembly-791/src/main/resources/dir-b/b.txt new file mode 100644 index 00000000..978b68af --- /dev/null +++ b/src/it/projects/bugs/massembly-791/src/main/resources/dir-b/b.txt @@ -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. diff --git a/src/it/projects/bugs/massembly-791/src/main/resources/dir-c/.gitignore b/src/it/projects/bugs/massembly-791/src/main/resources/dir-c/.gitignore new file mode 100644 index 00000000..da5988a3 --- /dev/null +++ b/src/it/projects/bugs/massembly-791/src/main/resources/dir-c/.gitignore @@ -0,0 +1 @@ +# Workaround to keep empty directory under source control diff --git a/src/it/projects/bugs/massembly-791/verify.groovy b/src/it/projects/bugs/massembly-791/verify.groovy new file mode 100644 index 00000000..2e18d962 --- /dev/null +++ b/src/it/projects/bugs/massembly-791/verify.groovy @@ -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 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 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 diff --git a/src/main/java/org/apache/maven/plugins/assembly/AssemblerConfigurationSource.java b/src/main/java/org/apache/maven/plugins/assembly/AssemblerConfigurationSource.java index 49a14279..ffb72936 100644 --- a/src/main/java/org/apache/maven/plugins/assembly/AssemblerConfigurationSource.java +++ b/src/main/java/org/apache/maven/plugins/assembly/AssemblerConfigurationSource.java @@ -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; + } } diff --git a/src/main/java/org/apache/maven/plugins/assembly/archive/DefaultAssemblyArchiver.java b/src/main/java/org/apache/maven/plugins/assembly/archive/DefaultAssemblyArchiver.java index 9e54cddd..f950c2d0 100644 --- a/src/main/java/org/apache/maven/plugins/assembly/archive/DefaultAssemblyArchiver.java +++ b/src/main/java/org/apache/maven/plugins/assembly/archive/DefaultAssemblyArchiver.java @@ -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; } diff --git a/src/main/java/org/apache/maven/plugins/assembly/mojos/AbstractAssemblyMojo.java b/src/main/java/org/apache/maven/plugins/assembly/mojos/AbstractAssemblyMojo.java index d5eeea79..3039557f 100644 --- a/src/main/java/org/apache/maven/plugins/assembly/mojos/AbstractAssemblyMojo.java +++ b/src/main/java/org/apache/maven/plugins/assembly/mojos/AbstractAssemblyMojo.java @@ -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 @@ -879,4 +888,9 @@ public Integer getOverrideGid() { public String getOverrideGroupName() { return this.overrideGroupName; } + + @Override + public Integer getUmask() { + return this.umask; + } }