Skip to content
Draft
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@v4
with:
maven4-build: true
maven4-version: '4.0.0-beta-3' # same as in project
maven4-version: '4.0.0-rc-5' # same as in project
20 changes: 13 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ under the License.

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

<guiceVersion>6.0.0</guiceVersion>
<mavenArchiverVersion>4.0.0-beta-1</mavenArchiverVersion>
<mavenPluginPluginVersion>4.0.0-beta-1</mavenPluginPluginVersion>
<mavenPluginTestingVersion>4.0.0-beta-1</mavenPluginTestingVersion>
<mavenArchiverVersion>4.0.0-beta-5</mavenArchiverVersion>
<mavenPluginPluginVersion>4.0.0-beta-2</mavenPluginPluginVersion>
<mavenPluginTestingVersion>4.0.0-beta-4</mavenPluginTestingVersion>
<mockitoVersion>5.20.0</mockitoVersion>
<plexusArchiverVersion>4.10.4</plexusArchiverVersion>
<version.maven-plugin-tools>${mavenPluginPluginVersion}</version.maven-plugin-tools>
Expand Down Expand Up @@ -128,13 +128,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 Down Expand Up @@ -162,7 +162,13 @@ under the License.
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-impl</artifactId>
<artifactId>maven-xml</artifactId>
<version>${mavenVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-impl</artifactId>
<version>${mavenVersion}</version>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Objects;

import org.apache.maven.api.Artifact;
import org.apache.maven.api.ProducedArtifact;
import org.apache.maven.api.Project;
import org.apache.maven.api.Session;
import org.apache.maven.api.Type;
Expand All @@ -40,8 +41,8 @@
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 @@ -321,7 +322,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 @@ -398,8 +399,9 @@ protected void archiveProjectContent(Project project, Archiver archiver) throws
for (Resource resource : getResources(project)) {

Path sourceDirectory = Paths.get(resource.getDirectory());
Path absoluteSourceDirectory = project.getBasedir().resolve(sourceDirectory);

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

Expand All @@ -416,9 +418,9 @@ protected void archiveProjectContent(Project project, Archiver archiver) throws
if (!targetPath.trim().endsWith("/")) {
targetPath += "/";
}
addDirectory(archiver, sourceDirectory, targetPath, combinedIncludes, combinedExcludes);
addDirectory(archiver, absoluteSourceDirectory, targetPath, combinedIncludes, combinedExcludes);
} else {
addDirectory(archiver, sourceDirectory, combinedIncludes, combinedExcludes);
addDirectory(archiver, absoluteSourceDirectory, combinedIncludes, combinedExcludes);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ public class SourceJarNoForkMojo extends AbstractSourceJarMojo {
* {@inheritDoc}
*/
protected List<Path> getSources(Project p) {
return projectManager.getCompileSourceRoots(p, ProjectScope.MAIN);
return projectManager
.getEnabledSourceRoots(p, ProjectScope.MAIN, p.getLanguage())
.map(sourceRoot -> sourceRoot.directory())
.toList();
}

/**
Expand All @@ -58,7 +61,7 @@ protected List<Resource> getResources(Project p) {
return Collections.emptyList();
}

return projectManager.getResources(p, ProjectScope.MAIN);
return p.getBuild().getResources();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ public class TestSourceJarNoForkMojo extends AbstractSourceJarMojo {
* {@inheritDoc}
*/
protected List<Path> getSources(Project p) {
return projectManager.getCompileSourceRoots(p, ProjectScope.TEST);
return projectManager
.getEnabledSourceRoots(p, ProjectScope.TEST, p.getLanguage())
.map(sourceRoot -> sourceRoot.directory())
.toList();
}

/**
Expand All @@ -58,7 +61,7 @@ protected List<Resource> getResources(Project p) {
return Collections.emptyList();
}

return projectManager.getResources(p, ProjectScope.TEST);
return p.getBuild().getTestResources();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

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;
Expand All @@ -31,7 +32,10 @@
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.configuration.internal.EnhancedCompositeBeanHelper;
import org.apache.maven.impl.DefaultSourceRoot;
import org.apache.maven.impl.InternalSession;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;

import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir;
Expand All @@ -47,6 +51,11 @@
@MojoTest
public class SourceJarMojoTest extends AbstractSourcePluginTestCase {

@AfterAll
static void cleanUp() {
EnhancedCompositeBeanHelper.clearCaches();
}

private String[] addMavenDescriptor(String project, String... listOfElements) {
final String metainf = "META-INF/";
final String mavensource = "maven/source/maven-source-plugin-test-";
Expand Down Expand Up @@ -182,18 +191,17 @@ 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), any()))
.thenAnswer(iom -> {
Project p = iom.getArgument(0, Project.class);
DefaultSourceRoot sourceRoot = new DefaultSourceRoot(
ProjectScope.MAIN,
Language.JAVA_FAMILY,
Paths.get(getBasedir())
.resolve(p.getModel().getBuild().getSourceDirectory()));

return Stream.of(sourceRoot);
});
return session;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

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;
Expand All @@ -31,7 +32,10 @@
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.configuration.internal.EnhancedCompositeBeanHelper;
import org.apache.maven.impl.DefaultSourceRoot;
import org.apache.maven.impl.InternalSession;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;

import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir;
Expand All @@ -47,6 +51,11 @@
@MojoTest
public class TestSourceJarMojoTest extends AbstractSourcePluginTestCase {

@AfterAll
static void cleanUp() {
EnhancedCompositeBeanHelper.clearCaches();
}

@Test
@InjectMojo(goal = "test-jar")
@Basedir("${basedir}/target/test-classes/unit/project-001")
Expand Down Expand Up @@ -138,18 +147,17 @@ 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.TEST))).thenAnswer(iom -> {
Project p = iom.getArgument(0, Project.class);
return Collections.singletonList(
Paths.get(getBasedir()).resolve(p.getModel().getBuild().getTestSourceDirectory()));
});
when(projectManager.getResources(any(), eq(ProjectScope.TEST))).thenAnswer(iom -> {
Project p = iom.getArgument(0, Project.class);
return p.getBuild().getTestResources().stream()
.map(r -> r.withDirectory(
Paths.get(getBasedir()).resolve(r.getDirectory()).toString()))
.toList();
});
when(projectManager.getEnabledSourceRoots(any(), eq(ProjectScope.TEST), any()))
.thenAnswer(iom -> {
Project p = iom.getArgument(0, Project.class);
DefaultSourceRoot sourceRoot = new DefaultSourceRoot(
ProjectScope.MAIN,
Language.JAVA_FAMILY,
Paths.get(getBasedir())
.resolve(p.getModel().getBuild().getTestSourceDirectory()));

return Stream.of(sourceRoot);
});
return session;
}
}
Loading