Skip to content

Commit

Permalink
[MNG-8220] Add IT to check DI in extensions (#355)
Browse files Browse the repository at this point in the history
* [MNG-8220] Add IT to check DI in extensions
  • Loading branch information
gnodet authored Aug 29, 2024
1 parent 92734d4 commit ea0b4e5
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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;

/**
* This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-8220">MNG-8220</a>.
*/
public class MavenITmng8220ExtensionWithDITest extends AbstractMavenIntegrationTestCase {
public MavenITmng8220ExtensionWithDITest() {
super("[4.0.0-beta-4,)");
}

/**
* Verify that the central url can be overridden by a user property.
*
* @throws Exception in case of failure
*/
@Test
public void testitModel() throws Exception {
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-8220-extension-with-di");

Verifier verifier = newVerifier(new File(testDir, "extension").getAbsolutePath());
verifier.addCliArgument("install");
verifier.execute();
verifier.verifyErrorFreeLog();

verifier = newVerifier(new File(testDir, "test").getAbsolutePath());
verifier.addCliArgument("validate");
verifier.execute();
verifier.verifyErrorFreeLog();
verifier.verifyTextInLog("[MNG-8220] DumbModelParser Called from extension");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public TestSuiteOrdering() {
* the tests are to finishing. Newer tests are also more likely to fail, so this is
* a fail fast technique as well.
*/
suite.addTestSuite(MavenITmng8220ExtensionWithDITest.class);
suite.addTestSuite(MavenITmng8181CentralRepoTest.class);
suite.addTestSuite(MavenITmng8123BuildCacheTest.class);
suite.addTestSuite(MavenITmng8106OverlappingDirectoryRolesTest.class);
Expand Down
1 change: 1 addition & 0 deletions core-it-suite/src/test/resources-filtered/bootstrap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ org.apache.commons:commons-text:1.10.0
org.apache.geronimo.specs:geronimo-jcdi_2.0_spec:1.3
org.apache.groovy:groovy-ant:4.0.15
org.apache.groovy:groovy:4.0.15
org.apache.maven:maven-api-impl:4.0.0-beta-3
org.apache.maven:maven-api-spi:4.0.0-alpha-8
org.apache.maven:maven-api-model:mdo:4.0.0-alpha-8
org.apache.maven.extensions:maven-extensions:pom:41
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.1.0">
<groupId>org.apache.maven.its.mng8220</groupId>
<artifactId>extension</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-di</artifactId>
<version>4.0.0-beta-3</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-impl</artifactId>
<version>4.0.0-beta-3</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.mng8220.extension;

import java.nio.file.Path;
import java.util.Map;
import java.util.Optional;

import org.apache.maven.api.di.Inject;
import org.apache.maven.api.di.Named;
import org.apache.maven.api.di.Singleton;
import org.apache.maven.api.model.Model;
import org.apache.maven.api.services.Source;
import org.apache.maven.api.spi.ModelParser;
import org.apache.maven.api.spi.ModelParserException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Singleton
@Named
final class DumbModelParser implements ModelParser {

private final Logger logger = LoggerFactory.getLogger(getClass());

@Inject
public DumbModelParser() {}

@Override
public Optional<Source> locate(Path dir) {
logger.warn("[MNG-8220] DumbModelParser Called from extension");
return Optional.empty();
}

@Override
public Model parse(Source source, Map<String, ?> options) throws ModelParserException {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.apache.maven.its.mng8220.extension.DumbModelParser
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<extensions>
<extension>
<groupId>org.apache.maven.its.mng8220</groupId>
<artifactId>extension</artifactId>
<version>1.0-SNAPSHOT</version>
</extension>
</extensions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.1.0">
<groupId>org.apache.maven.its.mng8220</groupId>
<artifactId>extension</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.mng8220.test;

public class Dumb {}

0 comments on commit ea0b4e5

Please sign in to comment.