diff --git a/pom.xml b/pom.xml index 3efb787..5da4ad6 100644 --- a/pom.xml +++ b/pom.xml @@ -72,11 +72,11 @@ under the License. - 4.0.0-rc-4 + 4.1.0-SNAPSHOT 17 7.0.0 - 4.0.0-beta-1 + 4.0.0-beta-2-SNAPSHOT 4.0.0-beta-2 4.0.0-beta-4 0.0.7 @@ -139,11 +139,6 @@ under the License. maven-filtering ${mavenFilteringVersion} - - org.sonatype.plexus - plexus-build-api - ${plexusBuildApiVersion} - org.eclipse.sisu org.eclipse.sisu.plexus diff --git a/src/main/java/org/apache/maven/plugins/resources/Providers.java b/src/main/java/org/apache/maven/plugins/resources/Providers.java deleted file mode 100644 index a9fe718..0000000 --- a/src/main/java/org/apache/maven/plugins/resources/Providers.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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. - */ -package org.apache.maven.plugins.resources; - -import org.apache.maven.api.di.Named; -import org.apache.maven.api.di.Provides; -import org.sonatype.plexus.build.incremental.BuildContext; -import org.sonatype.plexus.build.incremental.ThreadBuildContext; - -@Named -class Providers { - - @Provides - static BuildContext buildContext() { - return new ThreadBuildContext(); - } -} diff --git a/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java b/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java index 63539e0..ad9990d 100644 --- a/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java +++ b/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java @@ -32,6 +32,7 @@ import org.apache.maven.api.ProjectScope; import org.apache.maven.api.Session; import org.apache.maven.api.SourceRoot; +import org.apache.maven.api.build.context.BuildContext; import org.apache.maven.api.di.Inject; import org.apache.maven.api.plugin.Log; import org.apache.maven.api.plugin.MojoException; @@ -291,10 +292,14 @@ public class ResourcesMojo implements org.apache.maven.api.plugin.Mojo { @Inject private Log logger; + @Inject + protected BuildContext buildContext; + /** {@inheritDoc} */ public void execute() throws MojoException { if (isSkip()) { getLog().info("Skipping the execution."); + buildContext.markSkipExecution(); return; } if (resources == null) { @@ -303,6 +308,10 @@ public void execute() throws MojoException { .map(ResourcesMojo::newResource) .toList(); } + + // Incremental build support is handled by maven-filtering: + // it registers inputs with the BuildContext, processes only changed files, + // and associates outputs for stale cleanup. doExecute(); } diff --git a/src/test/java/org/apache/maven/plugins/resources/CopyResourcesMojoTest.java b/src/test/java/org/apache/maven/plugins/resources/CopyResourcesMojoTest.java index fdc45c0..9e19ff2 100644 --- a/src/test/java/org/apache/maven/plugins/resources/CopyResourcesMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/resources/CopyResourcesMojoTest.java @@ -21,15 +21,22 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; +import java.util.HashMap; import org.apache.maven.api.Project; +import org.apache.maven.api.build.context.BuildContext; +import org.apache.maven.api.di.Priority; import org.apache.maven.api.di.Provides; import org.apache.maven.api.di.Singleton; import org.apache.maven.api.plugin.testing.Basedir; import org.apache.maven.api.plugin.testing.InjectMojo; import org.apache.maven.api.plugin.testing.MojoTest; import org.apache.maven.api.plugin.testing.stubs.SessionMock; +import org.apache.maven.api.services.PathMatcherFactory; +import org.apache.maven.impl.DefaultPathMatcherFactory; import org.apache.maven.impl.InternalSession; +import org.apache.maven.internal.build.context.impl.DefaultBuildContext; +import org.apache.maven.internal.build.context.impl.FilesystemWorkspace; import org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub; import org.apache.maven.shared.filtering.Resource; import org.junit.jupiter.api.Test; @@ -76,4 +83,19 @@ private static InternalSession getMockSession() { private static Project createProject(ExtensionContext context) throws Exception { return new MavenProjectResourcesStub(); } + + @Provides + @Priority(10) + @SuppressWarnings("unused") + private static PathMatcherFactory pathMatcherFactory() { + return new DefaultPathMatcherFactory(); + } + + @Provides + @Priority(10) + @SuppressWarnings("unused") + private static BuildContext buildContext() { + return new DefaultBuildContext( + new FilesystemWorkspace(), null, new HashMap<>(), null, new DefaultPathMatcherFactory()); + } } diff --git a/src/test/java/org/apache/maven/plugins/resources/ResourcesMojoTest.java b/src/test/java/org/apache/maven/plugins/resources/ResourcesMojoTest.java index 67a04b4..4874926 100644 --- a/src/test/java/org/apache/maven/plugins/resources/ResourcesMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/resources/ResourcesMojoTest.java @@ -25,18 +25,25 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Properties; import org.apache.maven.api.Project; +import org.apache.maven.api.build.context.BuildContext; +import org.apache.maven.api.di.Priority; import org.apache.maven.api.di.Provides; import org.apache.maven.api.di.Singleton; import org.apache.maven.api.plugin.testing.Basedir; import org.apache.maven.api.plugin.testing.InjectMojo; import org.apache.maven.api.plugin.testing.MojoTest; import org.apache.maven.api.plugin.testing.stubs.SessionMock; +import org.apache.maven.api.services.PathMatcherFactory; +import org.apache.maven.impl.DefaultPathMatcherFactory; import org.apache.maven.impl.InternalSession; +import org.apache.maven.internal.build.context.impl.DefaultBuildContext; +import org.apache.maven.internal.build.context.impl.FilesystemWorkspace; import org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub; import org.apache.maven.shared.filtering.Resource; import org.junit.jupiter.api.Test; @@ -630,6 +637,21 @@ private static Project createProject() throws Exception { return new MavenProjectResourcesStub(); } + @Provides + @Priority(10) + @SuppressWarnings("unused") + private static PathMatcherFactory pathMatcherFactory() { + return new DefaultPathMatcherFactory(); + } + + @Provides + @Priority(10) + @SuppressWarnings("unused") + private static BuildContext buildContext() { + return new DefaultBuildContext( + new FilesystemWorkspace(), null, new HashMap<>(), null, new DefaultPathMatcherFactory()); + } + static List getResources(MavenProjectResourcesStub project) { return project.getBuild().getResources().stream() .map(ResourcesMojoTest::newResource) diff --git a/src/test/java/org/apache/maven/plugins/resources/TestResourcesTest.java b/src/test/java/org/apache/maven/plugins/resources/TestResourcesTest.java index 998b11c..12dc03d 100644 --- a/src/test/java/org/apache/maven/plugins/resources/TestResourcesTest.java +++ b/src/test/java/org/apache/maven/plugins/resources/TestResourcesTest.java @@ -21,16 +21,23 @@ import java.io.File; import java.nio.file.Paths; import java.util.Collections; +import java.util.HashMap; import java.util.List; import org.apache.maven.api.Project; +import org.apache.maven.api.build.context.BuildContext; +import org.apache.maven.api.di.Priority; import org.apache.maven.api.di.Provides; import org.apache.maven.api.di.Singleton; import org.apache.maven.api.plugin.testing.Basedir; import org.apache.maven.api.plugin.testing.InjectMojo; import org.apache.maven.api.plugin.testing.MojoTest; import org.apache.maven.api.plugin.testing.stubs.SessionMock; +import org.apache.maven.api.services.PathMatcherFactory; +import org.apache.maven.impl.DefaultPathMatcherFactory; import org.apache.maven.impl.InternalSession; +import org.apache.maven.internal.build.context.impl.DefaultBuildContext; +import org.apache.maven.internal.build.context.impl.FilesystemWorkspace; import org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub; import org.apache.maven.shared.filtering.Resource; import org.junit.jupiter.api.Test; @@ -106,6 +113,21 @@ private static Project createProject() throws Exception { return new MavenProjectResourcesStub(); } + @Provides + @Priority(10) + @SuppressWarnings("unused") + private static PathMatcherFactory pathMatcherFactory() { + return new DefaultPathMatcherFactory(); + } + + @Provides + @Priority(10) + @SuppressWarnings("unused") + private static BuildContext buildContext() { + return new DefaultBuildContext( + new FilesystemWorkspace(), null, new HashMap<>(), null, new DefaultPathMatcherFactory()); + } + private static List getResources(MavenProjectResourcesStub project) { return ResourcesMojoTest.getResources(project); }