Skip to content
Open
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 @@ -20,4 +20,11 @@

/** @deprecated Use {@link org.apache.maven.testing.plugin.stubs.ProducedArtifactStub} instead */
@Deprecated(since = "4.0.0-rc-6", forRemoval = true)
public class ProducedArtifactStub extends org.apache.maven.testing.plugin.stubs.ProducedArtifactStub {}
public class ProducedArtifactStub extends org.apache.maven.testing.plugin.stubs.ProducedArtifactStub {
public ProducedArtifactStub() {}

public ProducedArtifactStub(
String groupId, String artifactId, String classifier, String version, String extension) {
super(groupId, artifactId, classifier, version, extension);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,10 @@ public void beforeEach(ExtensionContext context) throws Exception {

String pluginBasedir = MavenDIExtension.getBasedir();

String basedir = AnnotationSupport.findAnnotation(context.getElement().orElseThrow(), Basedir.class)
.map(Basedir::value)
.orElse(pluginBasedir);
String basedir = findBasedirValue(context.getElement().orElseThrow());
if (basedir == null) {
basedir = pluginBasedir;
}
if (basedir.isEmpty()) {
basedir = pluginBasedir + "/target/tests/"
+ context.getRequiredTestClass().getSimpleName() + "/"
Expand Down Expand Up @@ -746,6 +747,18 @@ public static void setVariableValueToObject(Object object, String variable, Obje
field.set(object, value);
}

@SuppressWarnings("deprecation")
private static String findBasedirValue(AnnotatedElement element) {
Basedir a = AnnotationSupport.findAnnotation(element, Basedir.class).orElse(null);
if (a != null) {
return a.value();
}
org.apache.maven.api.plugin.testing.Basedir d = AnnotationSupport.findAnnotation(
element, org.apache.maven.api.plugin.testing.Basedir.class)
.orElse(null);
return d != null ? d.value() : null;
}

@SuppressWarnings("deprecation")
private static String[] findInjectMojoAttrs(AnnotatedElement element) {
InjectMojo a = element.getAnnotation(InjectMojo.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;

Expand Down Expand Up @@ -99,6 +100,17 @@ public void testParams(ExpressionEvaluatorMojo mojo) {
assertDoesNotThrow(mojo::execute);
}

@Test
@SuppressWarnings("removal")
@org.apache.maven.api.plugin.testing.InjectMojo(goal = COORDINATES, pom = CONFIG)
@org.apache.maven.api.plugin.testing.Basedir("${basedir}/target/test-classes")
@org.apache.maven.api.plugin.testing.MojoParameter(name = "param", value = "deprecatedParamValue")
public void testDeprecatedAnnotations(ExpressionEvaluatorMojo mojo) throws IllegalAccessException {
assertTrue(Paths.get(MojoExtension.getBasedir()).endsWith(Paths.get("target", "test-classes")));
assertEquals("deprecatedParamValue", MojoExtension.getVariableValueFromObject(mojo, "param"));
assertDoesNotThrow(mojo::execute);
}

@Mojo(name = "goal")
@Named("test:test-plugin:0.0.1-SNAPSHOT:goal") // this one is usually generated by maven-plugin-plugin
public static class ExpressionEvaluatorMojo implements org.apache.maven.api.plugin.Mojo {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.api.plugin.testing.stubs;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class ProducedArtifactStubTest {

@Test
@SuppressWarnings("removal")
void deprecatedConstructorRemainsSourceCompatible() {
ProducedArtifactStub artifact = new ProducedArtifactStub("group", "artifact", "tests", "1.0", "jar");

assertEquals("group", artifact.getGroupId());
assertEquals("artifact", artifact.getArtifactId());
assertEquals("tests", artifact.getClassifier());
assertEquals("1.0", artifact.getVersion().toString());
assertEquals("jar", artifact.getExtension());
}
}