Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/maven-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v5
with:
maven4-build: true
maven4-version: '4.0.0-beta-3' # same as in project
maven4-version: '4.0.0-rc-6' # the same as used in project
27 changes: 7 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,10 @@ under the License.

<properties>
<javaVersion>17</javaVersion>
<mavenVersion>4.0.0-beta-3</mavenVersion>
<mavenVersion>4.0.0-rc-6</mavenVersion>

<guiceVersion>6.0.0</guiceVersion>
<mavenArchiverVersion>4.0.0-beta-1</mavenArchiverVersion>
<mavenArchiverVersion>4.0.0-beta-5</mavenArchiverVersion>
<mavenPluginPluginVersion>4.0.0-beta-1</mavenPluginPluginVersion>
<mavenPluginTestingVersion>4.0.0-beta-1</mavenPluginTestingVersion>
<mockitoVersion>5.23.0</mockitoVersion>
<plexusArchiverVersion>4.12.0</plexusArchiverVersion>
<version.maven-plugin-tools>${mavenPluginPluginVersion}</version.maven-plugin-tools>
Expand Down Expand Up @@ -126,13 +124,13 @@ under the License.
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-meta</artifactId>
<artifactId>maven-api-annotations</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-archiver</artifactId>
<version>${mavenArchiverVersion}</version>
</dependency>
Expand All @@ -146,30 +144,19 @@ under the License.
<artifactId>plexus-utils</artifactId>
</dependency>

<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>${mavenPluginTestingVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<artifactId>maven-testing</artifactId>
<version>${mavenVersion}</version>
<scope>test</scope>
</dependency>
<!-- the mojo tests build SourceRoot stubs with org.apache.maven.impl.DefaultSourceRoot -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-impl</artifactId>
<artifactId>maven-impl</artifactId>
<version>${mavenVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>${guiceVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/it/MSOURCES-140/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

File buildLog = new File( basedir, 'build.log' )

assert buildLog.text =~ /\[INFO\] Artifact org.apache.maven.its.sources:jar-no-fork:jar:sources:1.0-SNAPSHOT already attached to target" + File.separator + "jar-no-fork-1.0-SNAPSHOT-sources.jar: ignoring same re-attach \(same artifact, same file\)/
assert buildLog.text =~ /\[INFO\] Artifact org.apache.maven.its.sources:jar-no-fork:jar:sources:1.0-SNAPSHOT already attached to target[\/\\]jar-no-fork-1.0-SNAPSHOT-sources.jar: ignoring same re-attach \(same artifact, same file\)/
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,29 @@
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import org.apache.maven.api.Artifact;
import org.apache.maven.api.Language;
import org.apache.maven.api.ProducedArtifact;
import org.apache.maven.api.Project;
import org.apache.maven.api.ProjectScope;
import org.apache.maven.api.Session;
import org.apache.maven.api.SourceRoot;
import org.apache.maven.api.Type;
import org.apache.maven.api.di.Inject;
import org.apache.maven.api.model.Resource;
import org.apache.maven.api.plugin.Log;
import org.apache.maven.api.plugin.Mojo;
import org.apache.maven.api.plugin.MojoException;
import org.apache.maven.api.plugin.annotations.Parameter;
import org.apache.maven.api.services.ArtifactManager;
import org.apache.maven.api.services.ProjectManager;
import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.shared.archiver.MavenArchiveConfiguration;
import org.apache.maven.shared.archiver.MavenArchiver;
import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.jar.JarArchiver;
Expand Down Expand Up @@ -258,10 +260,10 @@ protected void doExecute() {

/**
* @param p {@link Project} not null
* @return the compile or test resources
* @return the compile or test resource roots
* @throws MojoException in case of an error.
*/
protected abstract List<Resource> getResources(Project p) throws MojoException;
protected abstract List<SourceRoot> getResources(Project p) throws MojoException;

/**
* @param p {@link Project}
Expand Down Expand Up @@ -321,7 +323,7 @@ protected void packageSources(List<Project> theProjects) throws MojoException {
}

if (attach) {
Artifact artifact = session.createArtifact(
ProducedArtifact artifact = session.createProducedArtifact(
project.getGroupId(),
project.getArtifactId(),
project.getVersion(),
Expand Down Expand Up @@ -385,23 +387,23 @@ protected void archiveProjectContent(Project project, Archiver archiver) throws
}

// MAPI: this should be taken from the resources plugin
for (Resource resource : getResources(project)) {
for (SourceRoot resource : getResources(project)) {

Path sourceDirectory = Paths.get(resource.getDirectory());
Path sourceDirectory = resource.directory();

if (!Files.exists(sourceDirectory)) {
continue;
}

List<String> resourceIncludes = resource.getIncludes();
List<String> resourceIncludes = resource.includes();

String[] combinedIncludes = getCombinedIncludes(resourceIncludes);

List<String> resourceExcludes = resource.getExcludes();
List<String> resourceExcludes = resource.excludes();

String[] combinedExcludes = getCombinedExcludes(resourceExcludes);

String targetPath = resource.getTargetPath();
String targetPath = resource.targetPath().map(Path::toString).orElse(null);
if (targetPath != null) {
if (!targetPath.trim().endsWith("/")) {
targetPath += "/";
Expand All @@ -426,20 +428,12 @@ protected MavenArchiver createArchiver() throws MojoException {
// configure for Reproducible Builds based on outputTimestamp value
archiver.configureReproducibleBuild(outputTimestamp);

if (project.getBuild() != null) {
List<org.apache.maven.api.model.Resource> resources =
project.getBuild().getResources();

for (org.apache.maven.api.model.Resource r : resources) {
if (r.getDirectory().endsWith("maven-shared-archive-resources")) {
addDirectory(
archiver.getArchiver(),
Paths.get(r.getDirectory()),
getCombinedIncludes(null),
getCombinedExcludes(null));
}
}
}
projectManager
.getEnabledSourceRoots(project, ProjectScope.MAIN, Language.RESOURCES)
.map(SourceRoot::directory)
.filter(directory -> directory.endsWith("maven-shared-archive-resources"))
.forEach(directory -> addDirectory(
archiver.getArchiver(), directory, getCombinedIncludes(null), getCombinedExcludes(null)));

return archiver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
import java.util.Collections;
import java.util.List;

import org.apache.maven.api.Language;
import org.apache.maven.api.Project;
import org.apache.maven.api.ProjectScope;
import org.apache.maven.api.model.Resource;
import org.apache.maven.api.SourceRoot;
import org.apache.maven.api.plugin.annotations.Mojo;
import org.apache.maven.api.plugin.annotations.Parameter;

Expand All @@ -47,18 +48,23 @@ public class SourceJarNoForkMojo extends AbstractSourceJarMojo {
* {@inheritDoc}
*/
protected List<Path> getSources(Project p) {
return projectManager.getCompileSourceRoots(p, ProjectScope.MAIN);
return projectManager
.getEnabledSourceRoots(p, ProjectScope.MAIN, Language.JAVA_FAMILY)
.map(SourceRoot::directory)
.toList();
}

/**
* {@inheritDoc}
*/
protected List<Resource> getResources(Project p) {
protected List<SourceRoot> getResources(Project p) {
if (excludeResources) {
return Collections.emptyList();
}

return projectManager.getResources(p, ProjectScope.MAIN);
return projectManager
.getEnabledSourceRoots(p, ProjectScope.MAIN, Language.RESOURCES)
.toList();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
import java.util.Collections;
import java.util.List;

import org.apache.maven.api.Language;
import org.apache.maven.api.Project;
import org.apache.maven.api.ProjectScope;
import org.apache.maven.api.model.Resource;
import org.apache.maven.api.SourceRoot;
import org.apache.maven.api.plugin.annotations.Mojo;
import org.apache.maven.api.plugin.annotations.Parameter;

Expand All @@ -47,18 +48,23 @@ public class TestSourceJarNoForkMojo extends AbstractSourceJarMojo {
* {@inheritDoc}
*/
protected List<Path> getSources(Project p) {
return projectManager.getCompileSourceRoots(p, ProjectScope.TEST);
return projectManager
.getEnabledSourceRoots(p, ProjectScope.TEST, Language.JAVA_FAMILY)
.map(SourceRoot::directory)
.toList();
}

/**
* {@inheritDoc}
*/
protected List<Resource> getResources(Project p) {
protected List<SourceRoot> getResources(Project p) {
if (excludeResources) {
return Collections.emptyList();
}

return projectManager.getResources(p, ProjectScope.TEST);
return projectManager
.getEnabledSourceRoots(p, ProjectScope.TEST, Language.RESOURCES)
.toList();
}

/**
Expand Down
13 changes: 0 additions & 13 deletions src/site/site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,6 @@ under the License.

<site xmlns="http://maven.apache.org/SITE/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SITE/2.0.0 https://maven.apache.org/xsd/site-2.0.0.xsd">
<!--
Workaround for Maven 4.0.0-beta-3, the version this plugin currently builds against:
on beta-3 the parent site descriptor is not resolved, so the skin declared in the
Maven parent is not inherited and maven-site-plugin fails with "skin cannot be null".
Parent resolution works again on Maven 4.0.0-rc-5+, where this <skin> is redundant
(the parent's skin is inherited). Re-check and drop this once the build moves off
beta-3. See apache/maven-site-plugin#1286 for the cryptic-error part.
-->
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>2.1.0</version>
</skin>
<body>
<menu name="Overview">
<item name="Introduction" href="index.html"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir;
import static org.apache.maven.testing.plugin.MojoExtension.getBasedir;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,23 @@

import java.io.File;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.stream.Stream;

import org.apache.maven.api.Language;
import org.apache.maven.api.Project;
import org.apache.maven.api.ProjectScope;
import org.apache.maven.api.di.Provides;
import org.apache.maven.api.plugin.testing.Basedir;
import org.apache.maven.api.plugin.testing.InjectMojo;
import org.apache.maven.api.plugin.testing.MojoParameter;
import org.apache.maven.api.plugin.testing.MojoTest;
import org.apache.maven.api.plugin.testing.stubs.SessionMock;
import org.apache.maven.api.services.ProjectManager;
import org.apache.maven.internal.impl.InternalSession;
import org.apache.maven.impl.DefaultSourceRoot;
import org.apache.maven.impl.InternalSession;
import org.apache.maven.testing.plugin.Basedir;
import org.apache.maven.testing.plugin.InjectMojo;
import org.apache.maven.testing.plugin.MojoParameter;
import org.apache.maven.testing.plugin.MojoTest;
import org.apache.maven.testing.plugin.stubs.SessionMock;
import org.junit.jupiter.api.Test;

import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir;
import static org.apache.maven.testing.plugin.MojoExtension.getBasedir;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
Expand Down Expand Up @@ -182,18 +184,23 @@ InternalSession createSession() {
InternalSession session = SessionMock.getMockSession("target/local-repo");
ProjectManager projectManager = mock(ProjectManager.class);
when(session.getService(ProjectManager.class)).thenReturn(projectManager);
when(projectManager.getCompileSourceRoots(any(), eq(ProjectScope.MAIN))).thenAnswer(iom -> {
Project p = iom.getArgument(0, Project.class);
return Collections.singletonList(
Paths.get(getBasedir()).resolve(p.getModel().getBuild().getSourceDirectory()));
});
when(projectManager.getResources(any(), eq(ProjectScope.MAIN))).thenAnswer(iom -> {
Project p = iom.getArgument(0, Project.class);
return p.getBuild().getResources().stream()
.map(r -> r.withDirectory(
Paths.get(getBasedir()).resolve(r.getDirectory()).toString()))
.toList();
});
when(projectManager.getEnabledSourceRoots(any(), eq(ProjectScope.MAIN), eq(Language.JAVA_FAMILY)))
.thenAnswer(iom -> {
Project p = iom.getArgument(0, Project.class);
// since 4.0.0-rc-x the model no longer carries a default <sourceDirectory>
String sourceDirectory = p.getModel().getBuild().getSourceDirectory();
return Stream.of(new DefaultSourceRoot(
ProjectScope.MAIN,
Language.JAVA_FAMILY,
Paths.get(getBasedir())
.resolve(sourceDirectory != null ? sourceDirectory : "src/main/java")));
});
when(projectManager.getEnabledSourceRoots(any(), eq(ProjectScope.MAIN), eq(Language.RESOURCES)))
.thenAnswer(iom -> {
Project p = iom.getArgument(0, Project.class);
return p.getBuild().getResources().stream()
.map(r -> new DefaultSourceRoot(Paths.get(getBasedir()), ProjectScope.MAIN, r));
});
return session;
}
}
Loading
Loading