Skip to content

Commit 1c53fc9

Browse files
[MASSEMBLY-992] Inline Assembly Descriptors (#174)
1 parent 4acd22f commit 1c53fc9

File tree

12 files changed

+263
-7
lines changed

12 files changed

+263
-7
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Test
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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.
17+
18+
invoker.goals=org.apache.maven.plugins:maven-assembly-plugin:${project.version}:single
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
21+
<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">
22+
<modelVersion>4.0.0</modelVersion>
23+
<parent>
24+
<groupId>org.apache.maven.plugin.assembly.test</groupId>
25+
<artifactId>it-project-parent</artifactId>
26+
<version>1</version>
27+
</parent>
28+
29+
<groupId>org.test</groupId>
30+
<artifactId>inline-descriptor</artifactId>
31+
<version>1.0</version>
32+
33+
<build>
34+
<plugins>
35+
<plugin>
36+
<groupId>org.apache.maven.plugins</groupId>
37+
<artifactId>maven-assembly-plugin</artifactId>
38+
<configuration>
39+
<attach>false</attach>
40+
<inlineDescriptors>
41+
<inlineDescriptor>
42+
<id>example1</id>
43+
<formats>
44+
<format>dir</format>
45+
</formats>
46+
<files>
47+
<file>
48+
<source>TODO.txt</source>
49+
</file>
50+
</files>
51+
</inlineDescriptor>
52+
<inlineDescriptor>
53+
<id>example2</id>
54+
<formats>
55+
<format>zip</format>
56+
</formats>
57+
<files>
58+
<file>
59+
<source>TODO.txt</source>
60+
</file>
61+
</files>
62+
</inlineDescriptor>
63+
</inlineDescriptors>
64+
</configuration>
65+
</plugin>
66+
</plugins>
67+
</build>
68+
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 java.util.zip.ZipFile
21+
22+
File todo1 = new File(basedir, 'target/inline-descriptor-1.0-example1/inline-descriptor-1.0/TODO.txt')
23+
assert todo1.exists()
24+
25+
File zipFile = new File(basedir, 'target/inline-descriptor-1.0-example2.zip')
26+
assert zipFile.exists()
27+
28+
try (ZipFile zip = new ZipFile(zipFile)) {
29+
assert zip.getEntry('inline-descriptor-1.0/TODO.txt').getSize() > 0
30+
}
31+

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.apache.maven.archiver.MavenArchiveConfiguration;
2626
import org.apache.maven.execution.MavenSession;
27+
import org.apache.maven.plugins.assembly.model.Assembly;
2728
import org.apache.maven.project.MavenProject;
2829
import org.apache.maven.shared.filtering.MavenReaderFilter;
2930
import org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator;
@@ -42,6 +43,11 @@ public interface AssemblerConfigurationSource {
4243
*/
4344
String[] getDescriptorReferences();
4445

46+
/**
47+
* @return a list of inline descriptors.
48+
*/
49+
List<Assembly> getInlineDescriptors();
50+
4551
/**
4652
* @return The descriptor source directory.
4753
*/

src/main/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReader.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public List<Assembly> readAssemblies(final AssemblerConfigurationSource configSo
9696
final String[] descriptors = configSource.getDescriptors();
9797
final String[] descriptorRefs = configSource.getDescriptorReferences();
9898
final File descriptorSourceDirectory = configSource.getDescriptorSourceDirectory();
99+
final List<Assembly> inlineDescriptors = configSource.getInlineDescriptors();
99100

100101
if ((descriptors != null) && (descriptors.length > 0)) {
101102
locator.setStrategies(strategies);
@@ -130,6 +131,10 @@ public List<Assembly> readAssemblies(final AssemblerConfigurationSource configSo
130131
}
131132
}
132133

134+
if (inlineDescriptors != null) {
135+
assemblies.addAll(inlineDescriptors);
136+
}
137+
133138
if (assemblies.isEmpty()) {
134139
if (configSource.isIgnoreMissingDescriptor()) {
135140
LOGGER.debug("Ignoring missing assembly descriptors per configuration. "

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
@@ -169,6 +169,16 @@ public abstract class AbstractAssemblyMojo extends AbstractMojo implements Assem
169169
@Parameter
170170
private String[] descriptorRefs;
171171

172+
/**
173+
* An inline list of descriptor to generate from.
174+
* <p/>
175+
* Each element of list must follow <a href="./assembly.html">Assembly Descriptor</a> format.
176+
*
177+
* @since 3.7.0
178+
*/
179+
@Parameter
180+
private List<Assembly> inlineDescriptors;
181+
172182
/**
173183
* Directory to scan for descriptor files in. <b>NOTE:</b> This may not work correctly with assembly components.
174184
*/
@@ -598,6 +608,10 @@ public String[] getDescriptorReferences() {
598608
return descriptorRefs;
599609
}
600610

611+
public List<Assembly> getInlineDescriptors() {
612+
return inlineDescriptors;
613+
}
614+
601615
@Override
602616
public File getDescriptorSourceDirectory() {
603617
return descriptorSourceDirectory;

src/site/apt/examples/index.apt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,6 @@ Examples
5555

5656
* {{{./sharing-descriptors.html}Sharing Assembly Descriptors}}
5757

58+
* {{{./using-inline-descriptors.html}Using Inline Assembly Descriptors}}
59+
5860
[]
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
------
2+
Using Inline Assembly Descriptors
3+
------
4+
Slawomir Jaranowski
5+
------
6+
2023-12-17
7+
------
8+
9+
~~ Licensed to the Apache Software Foundation (ASF) under one
10+
~~ or more contributor license agreements. See the NOTICE file
11+
~~ distributed with this work for additional information
12+
~~ regarding copyright ownership. The ASF licenses this file
13+
~~ to you under the Apache License, Version 2.0 (the
14+
~~ "License"); you may not use this file except in compliance
15+
~~ with the License. You may obtain a copy of the License at
16+
~~
17+
~~ http://www.apache.org/licenses/LICENSE-2.0
18+
~~
19+
~~ Unless required by applicable law or agreed to in writing,
20+
~~ software distributed under the License is distributed on an
21+
~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22+
~~ KIND, either express or implied. See the License for the
23+
~~ specific language governing permissions and limitations
24+
~~ under the License.
25+
26+
~~ NOTE: For help with the syntax of this file, see:
27+
~~ https://maven.apache.org/doxia/references/apt-format.html
28+
29+
Using Inline Assembly Descriptors
30+
31+
* Introduction
32+
33+
For simple usage we can inline Assembly descriptor into the project configuration.
34+
We don't need to create an additional file with Assembly descriptor.
35+
36+
It can simplify configuration in case of the parent project inherited,
37+
we don't need to use a {{{./sharing-descriptors.html}Shared Assembly Descriptors}}
38+
39+
* The POM
40+
41+
We can have POM configuration of the project for the Assembly
42+
Plugin, which can look like:
43+
44+
+-----
45+
<project>
46+
[...]
47+
<build>
48+
[...]
49+
<plugins>
50+
[...]
51+
<plugin>
52+
<artifactId>maven-assembly-plugin</artifactId>
53+
<version>${project.version}</version>
54+
<configuration>
55+
<inlineDescriptors>
56+
<inlineDescriptor>
57+
<id>example1</id>
58+
<formats>
59+
<format>dir</format>
60+
</formats>
61+
<files>
62+
<file>
63+
<source>TODO.txt</source>
64+
</file>
65+
</files>
66+
</inlineDescriptor>
67+
<inlineDescriptor>
68+
<id>example2</id>
69+
<formats>
70+
<format>zip</format>
71+
</formats>
72+
<files>
73+
<file>
74+
<source>TODO.txt</source>
75+
</file>
76+
</files>
77+
</inlineDescriptor>
78+
</inlineDescriptors>
79+
</configuration>
80+
</plugin>
81+
[...]
82+
</project>
83+
+-----
84+
85+
86+
Each element of <<<inlineDescriptors>>> must follow {{{../assembly.html}Assembly Descriptor}} format.

src/site/site.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ under the License.
6262
<item name="Include Module Sources" href="./examples/multimodule/module-source-inclusion-simple.html"/>
6363
</item>
6464
<item name="Sharing Assembly Descriptors" href="./examples/sharing-descriptors.html"/>
65+
<item name="Using Inline Assembly Descriptors" href="./examples/using-inline-descriptors.html"/>
6566
</menu>
6667
</body>
6768
</project>

src/test/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReaderTest.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,27 @@
4949
import org.apache.maven.project.MavenProject;
5050
import org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator;
5151
import org.codehaus.plexus.interpolation.fixed.InterpolationState;
52-
import org.junit.Before;
5352
import org.junit.Rule;
5453
import org.junit.Test;
5554
import org.junit.rules.TemporaryFolder;
5655
import org.junit.runner.RunWith;
56+
import org.mockito.Mock;
5757
import org.mockito.junit.MockitoJUnitRunner;
5858
import org.slf4j.LoggerFactory;
5959

6060
import static org.junit.Assert.assertEquals;
6161
import static org.junit.Assert.assertNotNull;
62+
import static org.junit.Assert.assertSame;
6263
import static org.junit.Assert.fail;
63-
import static org.mockito.Mockito.mock;
6464
import static org.mockito.Mockito.when;
6565

6666
@RunWith(MockitoJUnitRunner.class)
6767
public class DefaultAssemblyReaderTest {
68+
6869
@Rule
6970
public TemporaryFolder temporaryFolder = new TemporaryFolder();
7071

72+
@Mock
7173
private AssemblerConfigurationSource configSource;
7274

7375
public static StringReader writeToStringReader(Assembly assembly) throws IOException {
@@ -79,11 +81,6 @@ public static StringReader writeToStringReader(Assembly assembly) throws IOExcep
7981
return new StringReader(sw.toString());
8082
}
8183

82-
@Before
83-
public void setUp() {
84-
configSource = mock(AssemblerConfigurationSource.class);
85-
}
86-
8784
@Test
8885
public void testIncludeSiteInAssembly_ShouldFailIfSiteDirectoryNonExistent() throws Exception {
8986
final File siteDir = Files.createTempFile("assembly-reader.", ".test").toFile();
@@ -704,6 +701,21 @@ public void testReadAssemblies_ShouldGetTwoAssemblyDescriptorsFromDirectoryWithT
704701
assertEquals(assembly2.getId(), result2.getId());
705702
}
706703

704+
@Test
705+
public void inlineAssemblyShouldBeReturned() throws Exception {
706+
// given
707+
Assembly assemby = new Assembly();
708+
assemby.setId("test-id");
709+
when(configSource.getInlineDescriptors()).thenReturn(Collections.singletonList(assemby));
710+
711+
// when
712+
List<Assembly> assemblies = new DefaultAssemblyReader().readAssemblies(configSource);
713+
714+
// then
715+
assertEquals(1, assemblies.size());
716+
assertSame(assemby, assemblies.get(0));
717+
}
718+
707719
private List<String> writeAssembliesToFile(final List<Assembly> assemblies, final File dir) throws IOException {
708720
final List<String> files = new ArrayList<>();
709721

src/test/java/org/apache/maven/plugins/assembly/testutils/PojoConfigSource.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.maven.artifact.repository.ArtifactRepository;
2727
import org.apache.maven.execution.MavenSession;
2828
import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
29+
import org.apache.maven.plugins.assembly.model.Assembly;
2930
import org.apache.maven.project.MavenProject;
3031
import org.apache.maven.shared.filtering.MavenReaderFilter;
3132
import org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator;
@@ -115,6 +116,8 @@ public class PojoConfigSource implements AssemblerConfigurationSource {
115116

116117
private String mergeManifestMode;
117118

119+
private List<Assembly> inlineDescriptors;
120+
118121
public String getDescriptor() {
119122
return descriptor;
120123
}
@@ -473,4 +476,13 @@ public String getMergeManifestMode() {
473476
public void setMergeManifestMode(String mergeManifestMode) {
474477
this.mergeManifestMode = mergeManifestMode;
475478
}
479+
480+
@Override
481+
public List<Assembly> getInlineDescriptors() {
482+
return inlineDescriptors;
483+
}
484+
485+
public void setInlineDescriptors(List<Assembly> inlineDescriptors) {
486+
this.inlineDescriptors = inlineDescriptors;
487+
}
476488
}

0 commit comments

Comments
 (0)