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
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
.idea
*.iws
*.iml
*.ipr
Expand Down
52 changes: 52 additions & 0 deletions EmptyProject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,62 @@
<artifactId>EmptyProject</artifactId>
<version>1.0-SNAPSHOT</version>

<developers>
<developer>
<id>jdoe</id>
<name>John Doe</name>
<email>jdoe@example.com</email>
<url>https://www.example.com/jdoe</url>
<organization>ACME</organization>
<organizationUrl>https://www.example.com</organizationUrl>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
<timezone>America/New_York</timezone>
<properties>
<picUrl>https://www.example.com/jdoe/pic</picUrl>
</properties>
</developer>
<developer>
<id>jadoe</id>
<name>Jane Doe</name>
<email>jadoe@example.com</email>
<url>https://www.example.com/jadoe</url>
<organization>ACME</organization>
<organizationUrl>https://www.example.com</organizationUrl>
<roles>
<role>qa</role>
<role>corpse</role>
</roles>
<timezone>America/New_York</timezone>
<properties>
<picUrl>https://www.example.com/jadoe/pic</picUrl>
</properties>
</developer>
</developers>

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

<build>
<plugins>
<plugin>
<groupId>org.plugin</groupId>
<artifactId>developers-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>developers-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
25 changes: 24 additions & 1 deletion MavenPlugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,36 @@
<modelVersion>4.0.0</modelVersion>

<groupId>org.plugin</groupId>
<artifactId>MavenPlugin</artifactId>
<artifactId>developers-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.0-SNAPSHOT</version>

<name>developers-maven-plugin Maven Mojo</name>
<url>https://maven.apache.org</url>

<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.10</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.15.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.9.10</version>
</dependency>
</dependencies>

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

import org.apache.maven.model.Developer;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
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.project.MavenProject;

import java.util.List;
import java.util.stream.Collectors;

@Mojo(name = "developers-info", defaultPhase = LifecyclePhase.COMPILE)
public class DevelopersInfoMojo extends AbstractMojo {
private static final String DEVELOPERS_INFO = """
Developer:
id: %s
name: %s
email: %s
url: %s
organization: %s
organizationUrl: %s
roles: %s
timezone: %s
picUrl: %s
""";
public static final String NOT_SPECIFIED = "Not specified";
public static final String PROPERTY_PIC_URL = "picUrl";
public static final String NO_DEVELOPERS_FOUND = "No developers found.";

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

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
List<Developer> developers = mavenProject.getDevelopers();
if (developers == null || developers.isEmpty()) {
getLog().warn(NO_DEVELOPERS_FOUND);
return;
}

String developersInfo = developers.stream()
.map(DevelopersInfoMojo::generateDeveloperInfo)
.collect(Collectors.joining("\n", "Developers info:\n", ""));
getLog().info(developersInfo);
}

private static String generateDeveloperInfo(Developer developer) {
return String.format(DEVELOPERS_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.

тут тож надо всякие проверки на npe добавить

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

developer.getId() != null ? developer.getId() : NOT_SPECIFIED,
developer.getName() != null ? developer.getName() : NOT_SPECIFIED,
developer.getEmail() != null ? developer.getEmail() : NOT_SPECIFIED,
developer.getUrl() != null ? developer.getUrl() : NOT_SPECIFIED,
developer.getOrganization() != null ? developer.getOrganization() : NOT_SPECIFIED,
developer.getOrganizationUrl() != null ? developer.getOrganizationUrl() : NOT_SPECIFIED,
developer.getRoles() != null ? String.join(", ", developer.getRoles()) : NOT_SPECIFIED,
developer.getTimezone() != null ? developer.getTimezone() : "",
developer.getProperties() != null && developer.getProperties().getProperty(PROPERTY_PIC_URL) != null
? developer.getProperties().getProperty(PROPERTY_PIC_URL)
: NOT_SPECIFIED
);
}
}
8 changes: 6 additions & 2 deletions MavenPlugin/src/main/java/org/plugin/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.example;
package org.plugin;

import java.util.logging.Logger;

public class Main {
private static final Logger logger = Logger.getLogger(Main.class.getName());

public static void main(String[] args) {
System.out.println("Hello world!");
logger.info("Hello world!");
}
}