Skip to content

Commit

Permalink
[MPIR-460] Dependency Information for maven-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Jun 2, 2024
1 parent 2ca83d0 commit dc1710d
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/it/MPIR-460-jar/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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.

invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:dependency-info
39 changes: 39 additions & 0 deletions src/it/MPIR-460-jar/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.plugins.project-info-reports</groupId>
<artifactId>MPIR-460-jar</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>MPIR-460 IT test: dependency-info for jar packaging</name>
<description>
Coordinates list are generated for many tools
</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
31 changes: 31 additions & 0 deletions src/it/MPIR-460-jar/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.
*/
def report = new File( basedir, 'target/site/dependency-info.html' ).text

assert !report.contains('<pre>&lt;plugin&gt;')
assert !report.contains('&lt;/plugin&gt;</pre>')

assert report.contains('<pre>&lt;dependency&gt;')
assert report.contains('&lt;/dependency&gt;</pre>')

assert report.contains('Apache Ivy')
assert report.contains('Groovy Grape')
assert report.contains('Gradle/Grails')
assert report.contains('Scala SBT')
assert report.contains('Leiningen')
18 changes: 18 additions & 0 deletions src/it/MPIR-460-maven-plugin/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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.

invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:dependency-info
39 changes: 39 additions & 0 deletions src/it/MPIR-460-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.plugins.project-info-reports</groupId>
<artifactId>MPIR-460-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>MPIR-460 IT test: dependency-info for maven-plugin</name>
<description>
Only coordinates for Maven plugin is generated
</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
31 changes: 31 additions & 0 deletions src/it/MPIR-460-maven-plugin/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.
*/
def report = new File( basedir, 'target/site/dependency-info.html' ).text

assert report.contains('<pre>&lt;plugin&gt;')
assert report.contains('&lt;/plugin&gt;</pre>')

assert !report.contains('<pre>&lt;dependency&gt;')
assert !report.contains('&lt;/dependency&gt;</pre>')

assert !report.contains('Apache Ivy')
assert !report.contains('Groovy Grape')
assert !report.contains('Gradle/Grails')
assert !report.contains('Scala SBT')
assert !report.contains('Leiningen')
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
public final class DependencyInformationReport extends AbstractProjectInfoReport {

private static final String JAR_PACKAGING = "jar";
private static final String PLUGIN_PACKAGING = "maven-plugin";

/**
*/
Expand Down Expand Up @@ -130,6 +131,32 @@ protected String getI18Nsection() {
protected void renderBody() {
startSection(getTitle());

if (PLUGIN_PACKAGING.equals(packaging)) {
renderMavenPluginCoordinates();
} else {
renderMavenDependencyCoordinates();
renderIvyDependencyCoordinates();
renderGrapeDependencyCoordinates();
renderGradleDependencyCoordinates();
renderScalaDependencyCoordinates();
renderLeiningenDependencyCoordinates();
}

endSection();
}

private void renderMavenPluginCoordinates() {
Formatter plugin = new Formatter()
.format("<plugin>%n")
.format(" <groupId>%s</groupId>%n", groupId)
.format(" <artifactId>%s</artifactId>%n", artifactId)
.format(" <version>%s</version>%n", version)
.format("</plugin>");

renderDependencyInfo("Apache Maven", plugin);
}

private void renderMavenDependencyCoordinates() {
Formatter mavenDependency = new Formatter()
.format("<dependency>%n")
.format(" <groupId>%s</groupId>%n", groupId)
Expand All @@ -141,31 +168,39 @@ protected void renderBody() {
}

renderDependencyInfo("Apache Maven", mavenDependency.format("</dependency>"));
}

private void renderIvyDependencyCoordinates() {
renderDependencyInfo(
"Apache Ivy",
new Formatter()
.format("<dependency org=\"%s\" name=\"%s\" rev=\"%s\">%n", groupId, artifactId, version)
.format(" <artifact name=\"%s\" type=\"%s\" />%n", artifactId, packaging)
.format("</dependency>"));
}

private void renderGrapeDependencyCoordinates() {
renderDependencyInfo(
"Groovy Grape",
new Formatter()
.format("@Grapes(%n")
.format("@Grab(group='%s', module='%s', version='%s')%n", groupId, artifactId, version)
.format(")"));
}

private void renderGradleDependencyCoordinates() {
renderDependencyInfo(
"Gradle/Grails", new Formatter().format("implementation '%s:%s:%s'", groupId, artifactId, version));
}

private void renderScalaDependencyCoordinates() {
renderDependencyInfo(
"Scala SBT",
new Formatter()
.format("libraryDependencies += \"%s\" %% \"%s\" %% \"%s\"", groupId, artifactId, version));
}

// Leiningen

private void renderLeiningenDependencyCoordinates() {
Formatter leiningenDependency = new Formatter().format("[%s", groupId);

if (!groupId.equals(artifactId)) {
Expand All @@ -175,8 +210,6 @@ protected void renderBody() {
leiningenDependency.format(" \"%s\"]", version);

renderDependencyInfo("Leiningen", leiningenDependency);

endSection();
}

private void renderDependencyInfo(String name, Formatter formatter) {
Expand Down

0 comments on commit dc1710d

Please sign in to comment.