Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ public class ProvisioningMojo extends BaseMojo {
@Parameter(defaultValue = "${project.build.directory}/${project.artifactId}-${project.version}")
private File outputDirectory;

/**
* Maven artifact type for an attached archive. Defaults to the archive extension.
*/
@Parameter
private String attachmentType;

/**
* Maven classifier for archives attached by this execution. Use separate executions
* when archives need different classifiers.
*/
@Parameter
private String attachmentClassifier;

@Override
public void execute() throws MojoExecutionException {
if (skipProvision) {
Expand Down Expand Up @@ -82,8 +95,10 @@ public void execute() throws MojoExecutionException {
continue;
}
ProvisioArchive provisioArchive = result.getArchives().get(0);
if (project.getPackaging().equals("jar") || project.getPackaging().equals("takari-jar")) {
projectHelper.attachArtifact(project, provisioArchive.extension(), provisioArchive.file());
String packaging = project.getPackaging();
if (packaging.equals("pom") || packaging.equals("jar") || packaging.equals("takari-jar")) {
String type = attachmentType != null ? attachmentType : provisioArchive.extension();
projectHelper.attachArtifact(project, type, attachmentClassifier, provisioArchive.file());
continue;
}
// We have something like provisio or presto-plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
*/
package ca.vanzyl.maven.plugins.provisio;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import io.takari.maven.testing.TestProperties;
import io.takari.maven.testing.TestResources;
import io.takari.maven.testing.executor.MavenRuntime;
import io.takari.maven.testing.executor.MavenRuntime.MavenRuntimeBuilder;
import io.takari.maven.testing.executor.MavenVersions;
import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner;
import java.io.File;
import java.nio.file.Files;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -104,6 +107,25 @@ public void testReactorArchiveDependencyOrdersBuild() throws Exception {
file(basedir, "server/target/server-1.0/core.txt").isFile());
}

@Test
public void testInstallArchivesWithPomPackaging() throws Exception {
File basedir = resources.getBasedir("pom-attachments");

maven.forProject(basedir).execute("install").assertErrorFreeLog();

File installed = file(
new TestProperties().getLocalRepository(), "ca/vanzyl/provisio/maven/plugins/its/pom-attachments/1.0");
assertArrayEquals(
Files.readAllBytes(file(basedir, "pom.xml").toPath()),
Files.readAllBytes(file(installed, "pom-attachments-1.0.pom").toPath()));
for (String archive : new String[] {"pom-attachments-1.0.zip", "pom-attachments-1.0-sources.jar"}) {
assertArrayEquals(
Files.readAllBytes(file(basedir, "target/" + archive).toPath()),
Files.readAllBytes(file(installed, archive).toPath()));
}
assertFalse(file(installed, "pom-attachments-1.0.jar").exists());
}

private static File file(File directory, String name) {
return directory.toPath().resolve(name).toFile();
}
Expand Down
42 changes: 42 additions & 0 deletions provisio-maven-plugin/src/test/projects/pom-attachments/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ca.vanzyl.provisio.maven.plugins.its</groupId>
<artifactId>pom-attachments</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<build>
<plugins>
<plugin>
<groupId>ca.vanzyl.provisio.maven.plugins</groupId>
<artifactId>provisio-maven-plugin</artifactId>
<version>${it-plugin.version}</version>
<executions>
<execution>
<id>docs</id>
<goals>
<goal>provision</goal>
</goals>
<configuration>
<descriptorDirectory>${project.basedir}/src/main/provisio/docs</descriptorDirectory>
<outputDirectory>${project.build.directory}/docs</outputDirectory>
</configuration>
</execution>
<execution>
<id>sources</id>
<goals>
<goal>provision</goal>
</goals>
<configuration>
<descriptorDirectory>${project.basedir}/src/main/provisio/sources</descriptorDirectory>
<outputDirectory>${project.build.directory}/sources</outputDirectory>
<attachmentType>jar</attachmentType>
<attachmentClassifier>sources</attachmentClassifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixture content
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<runtime>
<archive name="pom-attachments-1.0.zip" useRoot="false"/>
<fileSet to="/">
<directory path="${basedir}/src/main/content"/>
</fileSet>
</runtime>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<runtime>
<archive name="pom-attachments-1.0-sources.jar" useRoot="false"/>
<fileSet to="/">
<directory path="${basedir}/src/main/content"/>
</fileSet>
</runtime>
Loading