diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8525MavenDIPlugin.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8525MavenDIPlugin.java new file mode 100644 index 000000000000..f3b4e7379032 --- /dev/null +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8525MavenDIPlugin.java @@ -0,0 +1,66 @@ +/* + * 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.it; + +import java.io.File; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * This is a test set for MNG-8525. + * + */ +public class MavenITmng8525MavenDIPlugin extends AbstractMavenIntegrationTestCase { + + private File testDir; + + public MavenITmng8525MavenDIPlugin() { + super("[4.0.0-rc-2,)"); + } + + @BeforeEach + public void setUp() throws Exception { + testDir = extractResources("/mng-8525-maven-di-plugin"); + } + + @Test + public void testMavenDIPlugin() throws Exception { + // + // Build a plugin that uses a Maven DI plugin + // + Verifier v0 = newVerifier(testDir.getAbsolutePath()); + v0.setAutoclean(false); + v0.deleteDirectory("target"); + v0.deleteArtifacts("org.apache.maven.plugins"); + v0.addCliArgument("install"); + v0.execute(); + v0.verifyErrorFreeLog(); + + // + // Execute the Maven DI plugin + // + Verifier v1 = newVerifier(testDir.getAbsolutePath()); + v1.setAutoclean(false); + v1.addCliArgument("org.apache.maven.plugins:mavendi-maven-plugin:0.0.1-SNAPSHOT:hello"); + v1.execute(); + v1.verifyErrorFreeLog(); + v1.verifyTextInLog("Hello! I am a component that is being used via field injection!"); + } +} diff --git a/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/pom.xml b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/pom.xml new file mode 100644 index 000000000000..fc634552ae34 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/pom.xml @@ -0,0 +1,71 @@ + + + 4.0.0 + + org.apache.maven.plugins + mavendi-maven-plugin + 0.0.1-SNAPSHOT + maven-plugin + + mavendi-maven-plugin Maven Plugin + http://maven.apache.org + + + UTF-8 + 17 + 4.0.0-rc-1 + 4.0.0-beta-1 + + + + + org.apache.maven + maven-api-core + ${mavenVersion} + provided + + + org.apache.maven + maven-api-di + ${mavenVersion} + provided + + + org.apache.maven + maven-api-meta + ${mavenVersion} + provided + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + ${mavenPluginPluginVersion} + + + java-annotations + + true + + + + default-descriptor + process-classes + + ./apidocs/ + + + + generate-helpmojo + + helpmojo + + + + + + + diff --git a/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/main/java/org/apache/maven/plugins/HelloMojo.java b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/main/java/org/apache/maven/plugins/HelloMojo.java new file mode 100644 index 000000000000..e28879b90d93 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/main/java/org/apache/maven/plugins/HelloMojo.java @@ -0,0 +1,56 @@ +/* + * 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; + +/* + * 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. + */ + +import org.apache.maven.api.Lifecycle.Phase; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.plugin.annotations.Mojo; + +@Mojo(name = "hello", defaultPhase = Phase.VALIDATE, projectRequired = false) +public class HelloMojo implements org.apache.maven.api.plugin.Mojo { + + @Inject + private MavenDIComponent component; + + public void execute() { + // + // Say hello to the world, my little constructor injected component! + // + component.hello(); + } +} diff --git a/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/main/java/org/apache/maven/plugins/MavenDIComponent.java b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/main/java/org/apache/maven/plugins/MavenDIComponent.java new file mode 100644 index 000000000000..69e8b1caf386 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8525-maven-di-plugin/src/main/java/org/apache/maven/plugins/MavenDIComponent.java @@ -0,0 +1,50 @@ +/* + * 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; + +/* + * 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. + */ + +import org.apache.maven.api.di.Named; +import org.apache.maven.api.di.Singleton; + +@Named +@Singleton +public class MavenDIComponent { + + public void hello() { + System.out.println("Hello! I am a component that is being used via field injection!"); + } +}