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
38 changes: 38 additions & 0 deletions EmptyProject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,42 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<developers>
<developer>
<id>jdoe</id>
<name>John Doe</name>
<email>jdoe@example.com</email>
<url>http://www.example.com/jdoe</url>
<organization>ACME</organization>
<organizationUrl>http://www.example.com</organizationUrl>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
<timezone>America/New_York</timezone>
</developer>
<developer>
<id>SW</id>
<name>Sergey White</name>
<email>s_white@mail.com</email>
<url>http://www.example.com/sw</url>
<organization>Google</organization>
<organizationUrl>http://www.google.com</organizationUrl>
<roles>
<role>developer</role>
</roles>
<timezone>Russia/S-Pb</timezone>
</developer>
</developers>

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

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

<name>Developer Info Maven Plugin</name>
<description>Maven plugin to display developer information from POM</description>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.version>3.9.4</maven.version>
<plugin.tools.version>3.9.0</plugin.tools.version>
<compiler.plugin.version>3.11.0</compiler.plugin.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>${plugin.tools.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler.plugin.version}</version>
<configuration>
<source>17</source>
<target>17</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>${plugin.tools.version}</version>
<configuration>
<goalPrefix>developer</goalPrefix>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

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

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.model.Developer;

import java.util.List;

@Mojo(name = "info")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

добавь дефолтную фазу

public class DeveloperInfoMojo extends AbstractMojo {


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

public void execute() {

List<Developer> developers = project.getDevelopers();

if (developers == null || developers.isEmpty()) {
getLog().info("No developers found in the project POM.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warn

return;
}

getLog().info("=== PROJECT DEVELOPERS ===");

for (int i = 0; i < developers.size(); i++) {
Developer developer = developers.get(i);
printDeveloperInfo(developer, i + 1);
}

getLog().info("Total developers: " + developers.size());
}

private void printDeveloperInfo(Developer developer, int number) {
getLog().info("Developer #" + number + ":");

getLog().info(" Name: " + getSafeValue(developer.getName()));
getLog().info(" ID: " + getSafeValue(developer.getId()));
getLog().info(" Email: " + getSafeValue(developer.getEmail()));

if (developer.getOrganization() != null) {
getLog().info(" Organization: " + developer.getOrganization());
}

if (developer.getOrganizationUrl() != null) {
getLog().info(" Organization URL: " + developer.getOrganizationUrl());
}

if (developer.getRoles() != null && !developer.getRoles().isEmpty()) {
getLog().info(" Roles: " + String.join(", ", developer.getRoles()));
}

if (developer.getTimezone() != null) {
getLog().info(" Timezone: " + developer.getTimezone());
}

getLog().info("");
}

private String getSafeValue(String value) {
return value != null ? value : "Not specified";
}
}