From aac2328994dfedd7abfd8c282b4d5165607a3d23 Mon Sep 17 00:00:00 2001 From: Jonas Rutishauser Date: Thu, 18 Jan 2024 12:52:03 +0100 Subject: [PATCH] [MNG-8005] test for ide WorkspaceReader (#332) Adds an IT that verifies that "ide" WorkspaceReader is used by Maven. Relates to fix https://github.com/apache/maven/commit/3f47580dcc3715c1fa416e6dbc77558ac8db9c91 --- ...enITmng8005IdeWorkspaceReaderUsedTest.java | 48 +++++++++++++ .../apache/maven/it/TestSuiteOrdering.java | 1 + .../resources/mng-8005/.mvn/extensions.xml | 28 ++++++++ .../mng-8005/extension/.mvn/.gitkeep | 0 .../test/resources/mng-8005/extension/pom.xml | 68 +++++++++++++++++++ .../its/extensions/IdeWorkspaceReader.java | 62 +++++++++++++++++ .../resources/META-INF/maven/extension.xml | 26 +++++++ .../src/test/resources/mng-8005/pom.xml | 31 +++++++++ 8 files changed, 264 insertions(+) create mode 100644 its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8005IdeWorkspaceReaderUsedTest.java create mode 100644 its/core-it-suite/src/test/resources/mng-8005/.mvn/extensions.xml create mode 100644 its/core-it-suite/src/test/resources/mng-8005/extension/.mvn/.gitkeep create mode 100644 its/core-it-suite/src/test/resources/mng-8005/extension/pom.xml create mode 100644 its/core-it-suite/src/test/resources/mng-8005/extension/src/main/java/org/apache/maven/its/extensions/IdeWorkspaceReader.java create mode 100644 its/core-it-suite/src/test/resources/mng-8005/extension/src/main/resources/META-INF/maven/extension.xml create mode 100644 its/core-it-suite/src/test/resources/mng-8005/pom.xml diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8005IdeWorkspaceReaderUsedTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8005IdeWorkspaceReaderUsedTest.java new file mode 100644 index 0000000000..8394636c86 --- /dev/null +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8005IdeWorkspaceReaderUsedTest.java @@ -0,0 +1,48 @@ +/* + * 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.apache.maven.shared.verifier.Verifier; +import org.apache.maven.shared.verifier.util.ResourceExtractor; +import org.junit.jupiter.api.Test; + +public class MavenITmng8005IdeWorkspaceReaderUsedTest extends AbstractMavenIntegrationTestCase { + public MavenITmng8005IdeWorkspaceReaderUsedTest() { + super("(3.5.0,)"); + } + + @Test + public void testWithIdeWorkspaceReaderUsed() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-8005"); + + Verifier verifier = newVerifier(new File(testDir, "extension").getAbsolutePath()); + verifier.addCliArgument("install"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + verifier = newVerifier(testDir.getAbsolutePath()); + + verifier.addCliArgument("process-resources"); + verifier.execute(); + + verifier.verifyTextInLog("[INFO] findArtifact(org.apache.maven.plugins:maven-resources-plugin:pom:"); + } +} diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java index 39faaec324..27fe7d9d01 100644 --- a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java @@ -120,6 +120,7 @@ public class TestSuiteOrdering implements ClassOrderer { * the tests are to finishing. Newer tests are also more likely to fail, so this is * a fail fast technique as well. */ + suite.addTestSuite(MavenITmng8005IdeWorkspaceReaderUsedTest.class); suite.addTestSuite(MavenITmng7967ArtifactHandlerLanguageTest.class); suite.addTestSuite(MavenITmng7965PomDuplicateTagsTest.class); suite.addTestSuite(MavenITmng7939PluginsValidationExcludesTest.class); diff --git a/its/core-it-suite/src/test/resources/mng-8005/.mvn/extensions.xml b/its/core-it-suite/src/test/resources/mng-8005/.mvn/extensions.xml new file mode 100644 index 0000000000..b2c1c4896c --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8005/.mvn/extensions.xml @@ -0,0 +1,28 @@ + + + + + + + org.apache.maven.its.8005 + ide-workspace-reader + 0.1 + + diff --git a/its/core-it-suite/src/test/resources/mng-8005/extension/.mvn/.gitkeep b/its/core-it-suite/src/test/resources/mng-8005/extension/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/its/core-it-suite/src/test/resources/mng-8005/extension/pom.xml b/its/core-it-suite/src/test/resources/mng-8005/extension/pom.xml new file mode 100644 index 0000000000..7b29c040af --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8005/extension/pom.xml @@ -0,0 +1,68 @@ + + + + 4.0.0 + + org.apache.maven.its.8005 + ide-workspace-reader + 0.1 + jar + + Maven Integration Test :: ide-workspace-reader + Ide Workspace Reader + + + + + + org.apache.maven + maven-core + 3.8.6 + provided + + + + javax.inject + javax.inject + 1 + provided + + + + + + + org.eclipse.sisu + sisu-maven-plugin + 0.3.5 + + + generate-index + + main-index + + + + + + + diff --git a/its/core-it-suite/src/test/resources/mng-8005/extension/src/main/java/org/apache/maven/its/extensions/IdeWorkspaceReader.java b/its/core-it-suite/src/test/resources/mng-8005/extension/src/main/java/org/apache/maven/its/extensions/IdeWorkspaceReader.java new file mode 100644 index 0000000000..5b794f35d1 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8005/extension/src/main/java/org/apache/maven/its/extensions/IdeWorkspaceReader.java @@ -0,0 +1,62 @@ +/* + * 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.its.extensions; + +import javax.inject.Named; +import javax.inject.Singleton; + +import java.io.File; +import java.util.Collections; +import java.util.List; + +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.repository.WorkspaceReader; +import org.eclipse.aether.repository.WorkspaceRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Named("ide") +@Singleton +public class IdeWorkspaceReader implements WorkspaceReader { + + private static final Logger log = LoggerFactory.getLogger(IdeWorkspaceReader.class); + + private final WorkspaceRepository repository = new WorkspaceRepository(); + + public IdeWorkspaceReader() { + log.info("created"); + } + + @Override + public WorkspaceRepository getRepository() { + return repository; + } + + @Override + public File findArtifact(Artifact artifact) { + log.info("findArtifact({})", artifact); + return null; + } + + @Override + public List findVersions(Artifact artifact) { + log.info("findVersions({})", artifact); + return Collections.emptyList(); + } +} diff --git a/its/core-it-suite/src/test/resources/mng-8005/extension/src/main/resources/META-INF/maven/extension.xml b/its/core-it-suite/src/test/resources/mng-8005/extension/src/main/resources/META-INF/maven/extension.xml new file mode 100644 index 0000000000..dc3b4f5456 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8005/extension/src/main/resources/META-INF/maven/extension.xml @@ -0,0 +1,26 @@ + + + + + + + org.apache.maven.its.extensions + + \ No newline at end of file diff --git a/its/core-it-suite/src/test/resources/mng-8005/pom.xml b/its/core-it-suite/src/test/resources/mng-8005/pom.xml new file mode 100644 index 0000000000..90f9325b56 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8005/pom.xml @@ -0,0 +1,31 @@ + + + + 4.0.0 + + org.apache.maven.its.8005 + test + 0.1 + jar + + Maven Integration Test :: mng-8005 + Verify that Maven uses the ide workspace reader. + +