Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion EmptyProject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,47 @@
<artifactId>EmptyProject</artifactId>
<version>1.0-SNAPSHOT</version>

<parent>
<groupId>org.plugin</groupId>
<artifactId>MavenPluginParent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
<developers>
<developer>
<id>dev1</id>
<name>Test User 1</name>
<email>test.user1@example.com</email>
<url>https://github.com/testuser1</url>
</developer>
<developer>
<id>dev2</id>
<name>Test User 2</name>
<email>test.user2@example.com</email>
<url>https://github.com/testuser2</url>
</developer>
</developers>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>

<plugin>
<groupId>org.plugin</groupId>
<artifactId>MavenPlugin</artifactId>
<version>1.0-SNAPSHOT</version>
</plugin>
</plugins>
</build>

</project>
62 changes: 62 additions & 0 deletions MavenPlugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,73 @@
<groupId>org.plugin</groupId>
<artifactId>MavenPlugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>


<parent>
<groupId>org.plugin</groupId>
<artifactId>MavenPluginParent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>


<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<dependencies>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.9.6</version>
</dependency>


<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.9.6</version>
<scope>provided</scope>
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.9.0</version>
<executions>
<execution>
<id>generate-descriptor</id>
<phase>compile</phase>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>


</project>
48 changes: 48 additions & 0 deletions MavenPlugin/src/main/java/org/plugin/ DeveloperInfoMojo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.plugin;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import org.apache.maven.model.Developer;
import org.apache.maven.project.MavenProject;

import java.util.List;

@Mojo(name = "show-developers", defaultPhase = LifecyclePhase.PACKAGE)
public class DeveloperInfoMojo extends AbstractMojo {

@Parameter(defaultValue = "${project}", readonly = true)
private MavenProject project;

@Parameter(property = "showEmails", defaultValue = "true")
private boolean showEmails;

@Parameter(property = "showUrls", defaultValue = "true")
private boolean showUrls;

public void execute() throws MojoExecutionException {
List<Developer> developers = project.getDevelopers();

if (developers.isEmpty()) {
getLog().info("No developers found");
return;
}

getLog().info("Developer(s) info:");
developers.forEach(this::logDeveloperInfo);
}

private void logDeveloperInfo(Developer dev) {
getLog().info("Name: " + dev.getName());
if (showEmails && dev.getEmail() != null) {
getLog().info("Email: " + dev.getEmail());
}
if (showUrls && dev.getUrl() != null) {
getLog().info("URL: " + dev.getUrl());
}
getLog().info("------------------------");
}
}