Skip to content

Commit dde4c49

Browse files
committed
[MNG-7836] Add IT for alternative pom syntax
1 parent e7f977b commit dde4c49

File tree

10 files changed

+584
-1
lines changed

10 files changed

+584
-1
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.it;
20+
21+
import java.io.File;
22+
23+
import org.apache.maven.shared.verifier.Verifier;
24+
import org.apache.maven.shared.verifier.util.ResourceExtractor;
25+
import org.junit.jupiter.api.Test;
26+
27+
class MavenITmng7836AlternativePomSyntaxTest extends AbstractMavenIntegrationTestCase {
28+
29+
protected MavenITmng7836AlternativePomSyntaxTest() {
30+
// New feature in alpha-8-SNAPSHOT
31+
super("(4.0.0-alpha-7,)");
32+
}
33+
34+
@Test
35+
void testAlternativeSyntax() throws Exception {
36+
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-7836-alternative-pom-syntax");
37+
38+
final Verifier pluginVerifier = newVerifier(new File(testDir, "maven-hocon-extension").getPath());
39+
pluginVerifier.addCliArgument("clean");
40+
pluginVerifier.addCliArgument("install");
41+
pluginVerifier.addCliArgument("-V");
42+
pluginVerifier.execute();
43+
pluginVerifier.verifyErrorFreeLog();
44+
45+
final Verifier consumerVerifier = newVerifier(new File(testDir, "simple").getPath());
46+
consumerVerifier.addCliArgument("clean");
47+
consumerVerifier.addCliArgument("package");
48+
consumerVerifier.addCliArgument("-Drat.skip=true");
49+
consumerVerifier.addCliArgument("-V");
50+
consumerVerifier.execute();
51+
consumerVerifier.verifyErrorFreeLog();
52+
}
53+
}

core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ public TestSuiteOrdering() {
120120
* the tests are to finishing. Newer tests are also more likely to fail, so this is
121121
* a fail fast technique as well.
122122
*/
123+
suite.addTestSuite(MavenITmng7836AlternativePomSyntaxTest.class);
124+
suite.addTestSuite(MavenITmng5659ProjectSettingsTest.class);
123125
suite.addTestSuite(MavenITmng7228LeakyModelTest.class);
124126
suite.addTestSuite(MavenITmng7819FileLockingWithSnapshotsTest.class);
125127
suite.addTestSuite(MavenITmng5600DependencyManagementImportExclusionsTest.class);

core-it-suite/src/test/resources-filtered/bootstrap.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
com.google.code.findbugs:jsr305:1.3.9
88
com.google.guava:guava:10.0.1
99
com.thoughtworks.qdox:qdox:2.0-M9
10+
com.typesafe:config:1.4.2
1011
commons-codec:commons-codec:1.15
1112
commons-lang:commons-lang:2.6
1213
dom4j:dom4j:1.6.1
@@ -17,6 +18,7 @@ org.apache.commons:commons-text:1.10.0
1718
org.apache.geronimo.specs:geronimo-jcdi_2.0_spec:1.3
1819
org.apache.groovy:groovy-ant:4.0.6
1920
org.apache.groovy:groovy:4.0.6
21+
org.apache.maven.extensions:maven-extensions:40:pom
2022
org.apache.maven.its.plugins.class-loader:dep-c:${project.version}
2123
org.apache.maven.its.plugins:maven-it-plugin-active-collection:${project.version}
2224
org.apache.maven.its.plugins:maven-it-plugin-all:${project.version}
@@ -123,6 +125,7 @@ org.apache.maven.shared:maven-common-artifact-filters:3.1.0
123125
org.apache.maven.shared:maven-shared-utils:3.3.3
124126
org.apache.maven.skins:maven-default-skin:1.3
125127
org.apache.maven.surefire:surefire-junit4:3.0.0-M7
128+
org.apache.maven.surefire:surefire-junit-platform:3.0.0-M7
126129
org.apache.maven.wagon:wagon-webdav-jackrabbit:2.10
127130
org.apache.maven.wagon:wagon-webdav:1.0-beta-2
128131
org.apache.maven:maven-core:3.8.6
@@ -139,6 +142,7 @@ org.apache.maven:maven-settings-builder:3.1.1
139142
org.apache.maven:maven-settings:3.1.1
140143
org.apache.maven.plugin-testing:maven-plugin-testing-harness:3.3.0
141144
org.codehaus.gmavenplus:gmavenplus-plugin:1.11.0
145+
org.codehaus.modello:modello-maven-plugin:2.1.1
142146
org.codehaus.mojo:build-helper-maven-plugin:3.2.0
143147
org.codehaus.mojo:flatten-maven-plugin:1.0.0
144148
org.codehaus.mojo:versions-maven-plugin:2.15.0
@@ -155,15 +159,17 @@ org.codehaus.plexus:plexus-utils:1.5.5
155159
org.codehaus.plexus:plexus-utils:1.5.6
156160
org.codehaus.plexus:plexus-utils:2.0.4
157161
org.codehaus.plexus:plexus-utils:2.0.5
158-
org.codehaus.plexus:plexus-utils:3.0.10
159162
org.codehaus.plexus:plexus-utils:3.0.9
163+
org.codehaus.plexus:plexus-utils:3.0.10
160164
org.eclipse.aether:aether-impl:0.9.0.M2
161165
org.eclipse.aether:aether-spi:0.9.0.M2
162166
org.eclipse.sisu:org.eclipse.sisu.inject:0.0.0.M5
163167
org.eclipse.sisu:org.eclipse.sisu.plexus:0.0.0.M5
164168
org.eclipse.sisu:sisu-maven-plugin:0.3.5
165169
org.junit:junit-bom:5.9.1:pom
170+
org.junit.jupiter:junit-jupiter:5.9.1
166171
org.junit.jupiter:junit-jupiter-engine:5.9.1
172+
org.junit.platform:junit-platform-launcher:1.9.1
167173
org.ow2.asm:asm:4.1
168174
org.ow2.asm:asm:6.2
169175
org.ow2.asm:asm:7.2
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>org.apache.maven.its.mng-7836</groupId>
24+
<artifactId>maven-hocon-extension</artifactId>
25+
<version>1.0.0-SNAPSHOT</version>
26+
<packaging>jar</packaging>
27+
28+
<properties>
29+
<javaVersion>8</javaVersion>
30+
<maven.compiler.source>${javaVersion}</maven.compiler.source>
31+
<maven.compiler.target>${javaVersion}</maven.compiler.target>
32+
</properties>
33+
34+
<dependencies>
35+
<dependency>
36+
<groupId>org.apache.maven</groupId>
37+
<artifactId>maven-api-spi</artifactId>
38+
<version>4.0.0-alpha-8-SNAPSHOT</version>
39+
<scope>provided</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>com.typesafe</groupId>
43+
<artifactId>config</artifactId>
44+
<version>1.4.2</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>javax.inject</groupId>
48+
<artifactId>javax.inject</artifactId>
49+
<version>1</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>javax.annotation</groupId>
53+
<artifactId>javax.annotation-api</artifactId>
54+
<version>1.3.2</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.junit.jupiter</groupId>
58+
<artifactId>junit-jupiter</artifactId>
59+
<version>5.9.1</version>
60+
<scope>test</scope>
61+
</dependency>
62+
</dependencies>
63+
64+
<build>
65+
<plugins>
66+
<plugin>
67+
<groupId>org.apache.maven.plugins</groupId>
68+
<artifactId>maven-dependency-plugin</artifactId>
69+
<version>3.3.0</version>
70+
<executions>
71+
<execution>
72+
<id>copy-mdo</id>
73+
<goals>
74+
<goal>copy</goal>
75+
</goals>
76+
<phase>generate-sources</phase>
77+
<configuration>
78+
<artifactItems>
79+
<artifactItem>
80+
<groupId>org.apache.maven</groupId>
81+
<artifactId>maven-api-model</artifactId>
82+
<version>4.0.0-alpha-8-SNAPSHOT</version>
83+
<type>mdo</type>
84+
</artifactItem>
85+
</artifactItems>
86+
</configuration>
87+
</execution>
88+
</executions>
89+
</plugin>
90+
<plugin>
91+
<groupId>org.codehaus.modello</groupId>
92+
<artifactId>modello-maven-plugin</artifactId>
93+
<version>2.1.1</version>
94+
<executions>
95+
<execution>
96+
<id>generate-hocon-reader</id>
97+
<goals>
98+
<goal>velocity</goal>
99+
</goals>
100+
<phase>generate-sources</phase>
101+
<configuration>
102+
<version>4.2.0</version>
103+
<models>
104+
<model>target/dependency/maven-api-model-4.0.0-alpha-8-SNAPSHOT.mdo</model>
105+
</models>
106+
<templates>
107+
<template>src/mdo/hocon-reader.vm</template>
108+
</templates>
109+
<params>
110+
<param>packageModelV4=org.apache.maven.api.model</param>
111+
</params>
112+
</configuration>
113+
</execution>
114+
</executions>
115+
</plugin>
116+
<plugin>
117+
<groupId>org.eclipse.sisu</groupId>
118+
<artifactId>sisu-maven-plugin</artifactId>
119+
<version>0.3.5</version>
120+
<executions>
121+
<execution>
122+
<id>index-project</id>
123+
<goals>
124+
<goal>main-index</goal>
125+
</goals>
126+
</execution>
127+
</executions>
128+
</plugin>
129+
<plugin>
130+
<groupId>org.apache.maven.plugins</groupId>
131+
<artifactId>maven-surefire-plugin</artifactId>
132+
<version>3.0.0-M7</version>
133+
</plugin>
134+
</plugins>
135+
</build>
136+
137+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.hocon;
20+
21+
import javax.annotation.Priority;
22+
import javax.inject.Named;
23+
24+
import java.io.IOException;
25+
import java.io.InputStream;
26+
import java.io.InputStreamReader;
27+
import java.nio.charset.StandardCharsets;
28+
import java.nio.file.Files;
29+
import java.nio.file.Path;
30+
import java.util.Map;
31+
32+
import com.typesafe.config.Config;
33+
import com.typesafe.config.ConfigFactory;
34+
import org.apache.maven.api.model.Model;
35+
import org.apache.maven.api.services.Source;
36+
import org.apache.maven.api.spi.ModelParser;
37+
import org.apache.maven.api.spi.ModelParserException;
38+
39+
@Named("hocon")
40+
@Priority(1)
41+
public class HoconModelReader implements ModelParser {
42+
@Override
43+
public Path locatePom(Path path) {
44+
Path pom = path.resolve("pom.hocon");
45+
return Files.exists(pom) ? pom : null;
46+
}
47+
48+
@Override
49+
public Model parse(Source source, Map<String, ?> map) throws ModelParserException {
50+
Config config;
51+
if (source.getPath() != null) {
52+
config = ConfigFactory.parseFile(source.getPath().toFile());
53+
} else {
54+
try (InputStream input = source.getInputStream()) {
55+
config = ConfigFactory.parseReader(new InputStreamReader(input, StandardCharsets.UTF_8));
56+
} catch (IOException e) {
57+
throw new ModelParserException("Unable to parse: " + source.getLocation(), e);
58+
}
59+
}
60+
return new HoconReader().parseModel(config.root());
61+
}
62+
}

0 commit comments

Comments
 (0)