You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2023/12/17 11:17:08 UTC
(maven-assembly-plugin) branch MASSEMBLY-992 created (now a7d6cf89)
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a change to branch MASSEMBLY-992
in repository https://gitbox.apache.org/repos/asf/maven-assembly-plugin.git
at a7d6cf89 [MASSEMBLY-992] Inline Assembly Descriptors
This branch includes the following new commits:
new a7d6cf89 [MASSEMBLY-992] Inline Assembly Descriptors
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(maven-assembly-plugin) 01/01: [MASSEMBLY-992] Inline Assembly Descriptors
Posted by sj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch MASSEMBLY-992
in repository https://gitbox.apache.org/repos/asf/maven-assembly-plugin.git
commit a7d6cf8941699bd0ccd2ca4ba8c7ae14beea8e61
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Sun Dec 17 12:16:56 2023 +0100
[MASSEMBLY-992] Inline Assembly Descriptors
---
.../basic-features/inline-descriptor/TODO.txt | 1 +
.../inline-descriptor/invoker.properties | 18 +++++
.../basic-features/inline-descriptor/pom.xml | 68 +++++++++++++++++
.../basic-features/inline-descriptor/verify.groovy | 31 ++++++++
.../assembly/AssemblerConfigurationSource.java | 6 ++
.../plugins/assembly/io/DefaultAssemblyReader.java | 5 ++
.../assembly/mojos/AbstractAssemblyMojo.java | 14 ++++
src/site/apt/examples/index.apt | 2 +
.../apt/examples/using-inline-descriptors.apt.vm | 86 ++++++++++++++++++++++
src/site/site.xml | 1 +
.../assembly/io/DefaultAssemblyReaderTest.java | 26 +++++--
.../assembly/testutils/PojoConfigSource.java | 12 +++
12 files changed, 263 insertions(+), 7 deletions(-)
diff --git a/src/it/projects/basic-features/inline-descriptor/TODO.txt b/src/it/projects/basic-features/inline-descriptor/TODO.txt
new file mode 100644
index 00000000..345e6aef
--- /dev/null
+++ b/src/it/projects/basic-features/inline-descriptor/TODO.txt
@@ -0,0 +1 @@
+Test
diff --git a/src/it/projects/basic-features/inline-descriptor/invoker.properties b/src/it/projects/basic-features/inline-descriptor/invoker.properties
new file mode 100644
index 00000000..6e45db42
--- /dev/null
+++ b/src/it/projects/basic-features/inline-descriptor/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals=org.apache.maven.plugins:maven-assembly-plugin:${project.version}:single
diff --git a/src/it/projects/basic-features/inline-descriptor/pom.xml b/src/it/projects/basic-features/inline-descriptor/pom.xml
new file mode 100644
index 00000000..64a572e6
--- /dev/null
+++ b/src/it/projects/basic-features/inline-descriptor/pom.xml
@@ -0,0 +1,68 @@
+<?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/maven-v4_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.test</groupId>
+ <artifactId>inline-descriptor</artifactId>
+ <version>1.0</version>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <attach>false</attach>
+ <inlineDescriptors>
+ <inlineDescriptor>
+ <id>example1</id>
+ <formats>
+ <format>dir</format>
+ </formats>
+ <files>
+ <file>
+ <source>TODO.txt</source>
+ </file>
+ </files>
+ </inlineDescriptor>
+ <inlineDescriptor>
+ <id>example2</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <files>
+ <file>
+ <source>TODO.txt</source>
+ </file>
+ </files>
+ </inlineDescriptor>
+ </inlineDescriptors>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/projects/basic-features/inline-descriptor/verify.groovy b/src/it/projects/basic-features/inline-descriptor/verify.groovy
new file mode 100644
index 00000000..7aa19b12
--- /dev/null
+++ b/src/it/projects/basic-features/inline-descriptor/verify.groovy
@@ -0,0 +1,31 @@
+/*
+ * 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 java.util.zip.ZipFile
+
+File todo1 = new File(basedir, 'target/inline-descriptor-1.0-example1/inline-descriptor-1.0/TODO.txt')
+assert todo1.exists()
+
+File zipFile = new File(basedir, 'target/inline-descriptor-1.0-example2.zip')
+assert zipFile.exists()
+
+try (ZipFile zip = new ZipFile(zipFile)) {
+ assert zip.getEntry('inline-descriptor-1.0/TODO.txt').getSize() > 0
+}
+
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 8b1a76c2..5347e88d 100644
--- a/src/main/java/org/apache/maven/plugins/assembly/AssemblerConfigurationSource.java
+++ b/src/main/java/org/apache/maven/plugins/assembly/AssemblerConfigurationSource.java
@@ -24,6 +24,7 @@ import java.util.Properties;
import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugins.assembly.model.Assembly;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.filtering.MavenReaderFilter;
import org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator;
@@ -42,6 +43,11 @@ public interface AssemblerConfigurationSource {
*/
String[] getDescriptorReferences();
+ /**
+ * @return a list of inline descriptors.
+ */
+ List<Assembly> getInlineDescriptors();
+
/**
* @return The descriptor source directory.
*/
diff --git a/src/main/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReader.java b/src/main/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReader.java
index c5cefac7..be4af0d1 100644
--- a/src/main/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReader.java
+++ b/src/main/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReader.java
@@ -96,6 +96,7 @@ public class DefaultAssemblyReader implements AssemblyReader {
final String[] descriptors = configSource.getDescriptors();
final String[] descriptorRefs = configSource.getDescriptorReferences();
final File descriptorSourceDirectory = configSource.getDescriptorSourceDirectory();
+ final List<Assembly> inlineDescriptors = configSource.getInlineDescriptors();
if ((descriptors != null) && (descriptors.length > 0)) {
locator.setStrategies(strategies);
@@ -130,6 +131,10 @@ public class DefaultAssemblyReader implements AssemblyReader {
}
}
+ if (inlineDescriptors != null) {
+ assemblies.addAll(inlineDescriptors);
+ }
+
if (assemblies.isEmpty()) {
if (configSource.isIgnoreMissingDescriptor()) {
LOGGER.debug("Ignoring missing assembly descriptors per configuration. "
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 d81b3056..814e6f59 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
@@ -169,6 +169,16 @@ public abstract class AbstractAssemblyMojo extends AbstractMojo implements Assem
@Parameter
private String[] descriptorRefs;
+ /**
+ * An inline list of descriptor to generate from.
+ * <p/>
+ * Each element of list must follow <a href="./assembly.html">Assembly Descriptor</a> format.
+ *
+ * @since 3.7.0
+ */
+ @Parameter
+ private List<Assembly> inlineDescriptors;
+
/**
* Directory to scan for descriptor files in. <b>NOTE:</b> This may not work correctly with assembly components.
*/
@@ -598,6 +608,10 @@ public abstract class AbstractAssemblyMojo extends AbstractMojo implements Assem
return descriptorRefs;
}
+ public List<Assembly> getInlineDescriptors() {
+ return inlineDescriptors;
+ }
+
@Override
public File getDescriptorSourceDirectory() {
return descriptorSourceDirectory;
diff --git a/src/site/apt/examples/index.apt b/src/site/apt/examples/index.apt
index 39a6d28a..66c51039 100644
--- a/src/site/apt/examples/index.apt
+++ b/src/site/apt/examples/index.apt
@@ -55,4 +55,6 @@ Examples
* {{{./sharing-descriptors.html}Sharing Assembly Descriptors}}
+ * {{{./using-inline-descriptors.html}Using Inline Assembly Descriptors}}
+
[]
diff --git a/src/site/apt/examples/using-inline-descriptors.apt.vm b/src/site/apt/examples/using-inline-descriptors.apt.vm
new file mode 100644
index 00000000..c6f8c03a
--- /dev/null
+++ b/src/site/apt/examples/using-inline-descriptors.apt.vm
@@ -0,0 +1,86 @@
+ ------
+ Using Inline Assembly Descriptors
+ ------
+ Slawomir Jaranowski
+ ------
+ 2023-12-17
+ ------
+
+~~ 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.
+
+~~ NOTE: For help with the syntax of this file, see:
+~~ https://maven.apache.org/doxia/references/apt-format.html
+
+Using Inline Assembly Descriptors
+
+* Introduction
+
+ For simple usage we can inline Assembly descriptor into project configuration.
+ We don't need to create additional file with Assembly descriptor.
+
+ It can allow simplify configuration in case of inherited,
+ we don't need to use a {{{./sharing-descriptors.html}Shared Assembly Descriptors}}
+
+* The POM
+
+ We can have POM configuration of the project for the Assembly
+ Plugin, which can look like:
+
++-----
+<project>
+ [...]
+ <build>
+ [...]
+ <plugins>
+ [...]
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>${project.version}</version>
+ <configuration>
+ <inlineDescriptors>
+ <inlineDescriptor>
+ <id>example1</id>
+ <formats>
+ <format>dir</format>
+ </formats>
+ <files>
+ <file>
+ <source>TODO.txt</source>
+ </file>
+ </files>
+ </inlineDescriptor>
+ <inlineDescriptor>
+ <id>example2</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <files>
+ <file>
+ <source>TODO.txt</source>
+ </file>
+ </files>
+ </inlineDescriptor>
+ </inlineDescriptors>
+ </configuration>
+ </plugin>
+ [...]
+</project>
++-----
+
+
+ Each element of <<<inlineDescriptors>>> must follow {{{../assembly.html}Assembly Descriptor}} format.
diff --git a/src/site/site.xml b/src/site/site.xml
index 8a9d90d1..0af4fefd 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -62,6 +62,7 @@ under the License.
<item name="Include Module Sources" href="./examples/multimodule/module-source-inclusion-simple.html"/>
</item>
<item name="Sharing Assembly Descriptors" href="./examples/sharing-descriptors.html"/>
+ <item name="Using Inline Assembly Descriptors" href="./examples/using-inline-descriptors.html"/>
</menu>
</body>
</project>
diff --git a/src/test/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReaderTest.java b/src/test/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReaderTest.java
index 451c0c29..5f7ea5c9 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReaderTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReaderTest.java
@@ -49,25 +49,27 @@ import org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Writer;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator;
import org.codehaus.plexus.interpolation.fixed.InterpolationState;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.slf4j.LoggerFactory;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class DefaultAssemblyReaderTest {
+
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
+ @Mock
private AssemblerConfigurationSource configSource;
public static StringReader writeToStringReader(Assembly assembly) throws IOException {
@@ -79,11 +81,6 @@ public class DefaultAssemblyReaderTest {
return new StringReader(sw.toString());
}
- @Before
- public void setUp() {
- configSource = mock(AssemblerConfigurationSource.class);
- }
-
@Test
public void testIncludeSiteInAssembly_ShouldFailIfSiteDirectoryNonExistent() throws Exception {
final File siteDir = Files.createTempFile("assembly-reader.", ".test").toFile();
@@ -704,6 +701,21 @@ public class DefaultAssemblyReaderTest {
assertEquals(assembly2.getId(), result2.getId());
}
+ @Test
+ public void inlineAssemblyShouldBeReturned() throws Exception {
+ // given
+ Assembly assemby = new Assembly();
+ assemby.setId("test-id");
+ when(configSource.getInlineDescriptors()).thenReturn(Collections.singletonList(assemby));
+
+ // when
+ List<Assembly> assemblies = new DefaultAssemblyReader().readAssemblies(configSource);
+
+ // then
+ assertEquals(1, assemblies.size());
+ assertSame(assemby, assemblies.get(0));
+ }
+
private List<String> writeAssembliesToFile(final List<Assembly> assemblies, final File dir) throws IOException {
final List<String> files = new ArrayList<>();
diff --git a/src/test/java/org/apache/maven/plugins/assembly/testutils/PojoConfigSource.java b/src/test/java/org/apache/maven/plugins/assembly/testutils/PojoConfigSource.java
index 468f787c..dca7bdb3 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/testutils/PojoConfigSource.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/testutils/PojoConfigSource.java
@@ -26,6 +26,7 @@ import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
+import org.apache.maven.plugins.assembly.model.Assembly;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.filtering.MavenReaderFilter;
import org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator;
@@ -115,6 +116,8 @@ public class PojoConfigSource implements AssemblerConfigurationSource {
private String mergeManifestMode;
+ private List<Assembly> inlineDescriptors;
+
public String getDescriptor() {
return descriptor;
}
@@ -473,4 +476,13 @@ public class PojoConfigSource implements AssemblerConfigurationSource {
public void setMergeManifestMode(String mergeManifestMode) {
this.mergeManifestMode = mergeManifestMode;
}
+
+ @Override
+ public List<Assembly> getInlineDescriptors() {
+ return inlineDescriptors;
+ }
+
+ public void setInlineDescriptors(List<Assembly> inlineDescriptors) {
+ this.inlineDescriptors = inlineDescriptors;
+ }
}