Skip to content

[MASSEMBLY-992] Inline Assembly Descriptors #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/it/projects/basic-features/inline-descriptor/TODO.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test
Original file line number Diff line number Diff line change
@@ -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
68 changes: 68 additions & 0 deletions src/it/projects/basic-features/inline-descriptor/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
31 changes: 31 additions & 0 deletions src/it/projects/basic-features/inline-descriptor/verify.groovy
Original file line number Diff line number Diff line change
@@ -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
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

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;
Expand All @@ -42,6 +43,11 @@ public interface AssemblerConfigurationSource {
*/
String[] getDescriptorReferences();

/**
* @return a list of inline descriptors.
*/
List<Assembly> getInlineDescriptors();

/**
* @return The descriptor source directory.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public List<Assembly> readAssemblies(final AssemblerConfigurationSource configSo
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);
Expand Down Expand Up @@ -130,6 +131,10 @@ public List<Assembly> readAssemblies(final AssemblerConfigurationSource configSo
}
}

if (inlineDescriptors != null) {
assemblies.addAll(inlineDescriptors);
}

if (assemblies.isEmpty()) {
if (configSource.isIgnoreMissingDescriptor()) {
LOGGER.debug("Ignoring missing assembly descriptors per configuration. "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -598,6 +608,10 @@ public String[] getDescriptorReferences() {
return descriptorRefs;
}

public List<Assembly> getInlineDescriptors() {
return inlineDescriptors;
}

@Override
public File getDescriptorSourceDirectory() {
return descriptorSourceDirectory;
Expand Down
2 changes: 2 additions & 0 deletions src/site/apt/examples/index.apt
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ Examples

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

* {{{./using-inline-descriptors.html}Using Inline Assembly Descriptors}}

[]
86 changes: 86 additions & 0 deletions src/site/apt/examples/using-inline-descriptors.apt.vm
Original file line number Diff line number Diff line change
@@ -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 the project configuration.
We don't need to create an additional file with Assembly descriptor.

It can simplify configuration in case of the parent project 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.
1 change: 1 addition & 0 deletions src/site/site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,27 @@
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 {
Expand All @@ -79,11 +81,6 @@ public static StringReader writeToStringReader(Assembly assembly) throws IOExcep
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();
Expand Down Expand Up @@ -704,6 +701,21 @@ public void testReadAssemblies_ShouldGetTwoAssemblyDescriptorsFromDirectoryWithT
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<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -115,6 +116,8 @@ public class PojoConfigSource implements AssemblerConfigurationSource {

private String mergeManifestMode;

private List<Assembly> inlineDescriptors;

public String getDescriptor() {
return descriptor;
}
Expand Down Expand Up @@ -473,4 +476,13 @@ public String getMergeManifestMode() {
public void setMergeManifestMode(String mergeManifestMode) {
this.mergeManifestMode = mergeManifestMode;
}

@Override
public List<Assembly> getInlineDescriptors() {
return inlineDescriptors;
}

public void setInlineDescriptors(List<Assembly> inlineDescriptors) {
this.inlineDescriptors = inlineDescriptors;
}
}