Skip to content

Commit

Permalink
POM syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Sep 14, 2023
1 parent 37b9369 commit a35b2ce
Show file tree
Hide file tree
Showing 11 changed files with 685 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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 java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import org.apache.maven.shared.verifier.Verifier;
import org.apache.maven.shared.verifier.util.ResourceExtractor;
import org.junit.jupiter.api.Test;

class MavenITmng7836AlternativePomSyntaxTest extends AbstractMavenIntegrationTestCase {

protected MavenITmng7836AlternativePomSyntaxTest() {
// New feature in alpha-8-SNAPSHOT
super("(4.0.0-alpha-7,)");
}

@Test
void testAlternativeSyntax() throws Exception {
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-7836-alternative-pom-syntax");

final Verifier pluginVerifier = newVerifier(new File(testDir, "maven-hocon-extension").getPath());
pluginVerifier.addCliArgument("clean");
pluginVerifier.addCliArgument("install");
pluginVerifier.addCliArgument("-V");
pluginVerifier.execute();
pluginVerifier.verifyErrorFreeLog();

final Verifier consumerVerifier = newVerifier(new File(testDir, "simple").getPath());
consumerVerifier.addCliArgument("clean");
consumerVerifier.addCliArgument("install");
consumerVerifier.addCliArgument("-Drat.skip=true");
consumerVerifier.addCliArgument("-V");

Path consumerPom = Paths.get(consumerVerifier.getArtifactPath(
"org.apache.maven.its.mng-7836", "hocon-simple", "1.0.0-SNAPSHOT", "pom", ""));
Path buildPom = Paths.get(consumerVerifier.getArtifactPath(
"org.apache.maven.its.mng-7836", "hocon-simple", "1.0.0-SNAPSHOT", "pom", "build"));
consumerVerifier.deleteArtifacts("org.apache.maven.its.mng-7836", "hocon-simple", "1.0.0-SNAPSHOT");

consumerVerifier.execute();
consumerVerifier.verifyErrorFreeLog();

assertTrue(Files.isRegularFile(consumerPom));
List<String> consumerPomLines = Files.readAllLines(consumerPom, StandardCharsets.UTF_8);
assertTrue(consumerPomLines.stream().anyMatch(l -> l.contains("<name>Apache-2.0</name>")));
assertFalse(consumerPomLines.stream().anyMatch(l -> l.contains("<parent>")));

// The build pom is the original POM, so the hocon file
assertTrue(Files.isRegularFile(buildPom));
List<String> buildPomLines = Files.readAllLines(buildPom, StandardCharsets.UTF_8);
assertTrue(buildPomLines.stream().anyMatch(l -> l.contains("groupId = org.apache.maven.extensions")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ 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(MavenITmng7836AlternativePomSyntaxTest.class);
suite.addTestSuite(MavenITmng6401ProxyPortInterpolationTest.class);
suite.addTestSuite(MavenITmng7228LeakyModelTest.class);
suite.addTestSuite(MavenITmng7819FileLockingWithSnapshotsTest.class);
suite.addTestSuite(MavenITmng5659ProjectSettingsTest.class);
suite.addTestSuite(MavenITmng5600DependencyManagementImportExclusionsTest.class);
suite.addTestSuite(MavenITmng7740ConsumerBuildShouldCleanUpOldFilesTest.class);
suite.addTestSuite(MavenITmng7587Jsr330.class);
Expand Down
8 changes: 7 additions & 1 deletion core-it-suite/src/test/resources-filtered/bootstrap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
com.google.code.findbugs:jsr305:1.3.9
com.google.guava:guava:10.0.1
com.thoughtworks.qdox:qdox:2.0-M9
com.typesafe:config:1.4.2
commons-codec:commons-codec:1.15
commons-lang:commons-lang:2.6
dom4j:dom4j:1.6.1
Expand All @@ -17,6 +18,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.6
org.apache.groovy:groovy:4.0.6
org.apache.maven.extensions:maven-extensions:40:pom
org.apache.maven.its.plugins.class-loader:dep-c:${project.version}
org.apache.maven.its.plugins:maven-it-plugin-active-collection:${project.version}
org.apache.maven.its.plugins:maven-it-plugin-all:${project.version}
Expand Down Expand Up @@ -123,6 +125,7 @@ org.apache.maven.shared:maven-common-artifact-filters:3.1.0
org.apache.maven.shared:maven-shared-utils:3.3.3
org.apache.maven.skins:maven-default-skin:1.3
org.apache.maven.surefire:surefire-junit4:3.0.0-M7
org.apache.maven.surefire:surefire-junit-platform:3.0.0-M7
org.apache.maven.wagon:wagon-webdav-jackrabbit:2.10
org.apache.maven.wagon:wagon-webdav:1.0-beta-2
org.apache.maven:maven-core:3.8.6
Expand All @@ -139,6 +142,7 @@ org.apache.maven:maven-settings-builder:3.1.1
org.apache.maven:maven-settings:3.1.1
org.apache.maven.plugin-testing:maven-plugin-testing-harness:3.3.0
org.codehaus.gmavenplus:gmavenplus-plugin:1.11.0
org.codehaus.modello:modello-maven-plugin:2.1.1
org.codehaus.mojo:build-helper-maven-plugin:3.2.0
org.codehaus.mojo:flatten-maven-plugin:1.0.0
org.codehaus.mojo:versions-maven-plugin:2.15.0
Expand All @@ -155,15 +159,17 @@ org.codehaus.plexus:plexus-utils:1.5.5
org.codehaus.plexus:plexus-utils:1.5.6
org.codehaus.plexus:plexus-utils:2.0.4
org.codehaus.plexus:plexus-utils:2.0.5
org.codehaus.plexus:plexus-utils:3.0.10
org.codehaus.plexus:plexus-utils:3.0.9
org.codehaus.plexus:plexus-utils:3.0.10
org.eclipse.aether:aether-impl:0.9.0.M2
org.eclipse.aether:aether-spi:0.9.0.M2
org.eclipse.sisu:org.eclipse.sisu.inject:0.0.0.M5
org.eclipse.sisu:org.eclipse.sisu.plexus:0.0.0.M5
org.eclipse.sisu:sisu-maven-plugin:0.3.5
org.junit:junit-bom:5.9.1:pom
org.junit.jupiter:junit-jupiter:5.9.1
org.junit.jupiter:junit-jupiter-engine:5.9.1
org.junit.platform:junit-platform-launcher:1.9.1
org.ow2.asm:asm:4.1
org.ow2.asm:asm:6.2
org.ow2.asm:asm:7.2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?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.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">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.its.mng-7836</groupId>
<artifactId>maven-hocon-extension</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<javaVersion>8</javaVersion>
<maven.compiler.source>${javaVersion}</maven.compiler.source>
<maven.compiler.target>${javaVersion}</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-spi</artifactId>
<version>4.0.0-alpha-8-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-core</artifactId>
<version>4.0.0-alpha-8-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>copy-mdo</id>
<goals>
<goal>copy</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-model</artifactId>
<version>4.0.0-alpha-8-SNAPSHOT</version>
<type>mdo</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<id>generate-hocon-reader</id>
<goals>
<goal>velocity</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<version>4.2.0</version>
<models>
<model>target/dependency/maven-api-model-4.0.0-alpha-8-SNAPSHOT.mdo</model>
</models>
<templates>
<template>src/mdo/hocon-reader.vm</template>
</templates>
<params>
<param>packageModelV4=org.apache.maven.api.model</param>
</params>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.sisu</groupId>
<artifactId>sisu-maven-plugin</artifactId>
<version>0.3.5</version>
<executions>
<execution>
<id>index-project</id>
<goals>
<goal>main-index</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.hocon;

import javax.annotation.Priority;
import javax.inject.Named;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.Optional;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
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;

@Named("hocon")
@Priority(1)
public class HoconModelReader implements ModelParser {

@Override
public Optional<Source> locate(Path path) {
Path pom = Files.isDirectory(path) ? path.resolve("pom.hocon") : path;
return Files.isRegularFile(pom) ? Optional.of(new PathSource(pom)) : Optional.empty();
}

@Override
public Model parse(Source source, Map<String, ?> map) throws ModelParserException {
Config config;
if (source.getPath() != null) {
config = ConfigFactory.parseFile(source.getPath().toFile());
} else {
try (InputStream input = source.openStream()) {
config = ConfigFactory.parseReader(new InputStreamReader(input, StandardCharsets.UTF_8));
} catch (IOException e) {
throw new ModelParserException("Unable to parse: " + source.getLocation(), e);
}
}
return new HoconReader().parseModel(config.root());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.hocon;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;

import org.apache.maven.api.services.Source;

public class PathSource implements Source {

private final Path path;

public PathSource(Path path) {
this.path = Objects.requireNonNull(path);
}

@Override
public Path getPath() {
return path;
}

@Override
public InputStream openStream() throws IOException {
return Files.newInputStream(path);
}

@Override
public String getLocation() {
return path.toString();
}
}
Loading

0 comments on commit a35b2ce

Please sign in to comment.