Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAP-253 Maven plugin to calculate directory size and report it to TC #2

Merged
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
35 changes: 35 additions & 0 deletions oap-teamcity-folder-size-maven/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<name>oap-teamcity-folder-size-maven</name>
<artifactId>oap-teamcity-folder-size-maven</artifactId>
<packaging>maven-plugin</packaging>

<parent>
<groupId>oap</groupId>
<artifactId>oap-teamcity-parent</artifactId>
<version>${oap-teamcity.project.version}</version>
</parent>

<dependencies>
<dependency>
<groupId>oap</groupId>
<artifactId>oap-teamcity</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${oap.deps.mavem-plugin-api.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>${oap.deps.mavem-plugin-annotations.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package oap.temcity.mavan;

import oap.teamcity.Teamcity;
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 java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;

@Mojo( name = "folder-size", threadSafe = true, defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST )
public class FolderSizeMojo extends AbstractMojo {
@Parameter( required = true )
public String directory;

@Parameter( alias = "statistic-name", required = true )
public String statisticName;

@Override
public void execute() throws MojoExecutionException {
try {
getLog().info( "statisticName " + statisticName + " directory " + directory );
Path folder = Paths.get( directory );
try( Stream<Path> stream = Files.walk( folder ) ) {
long size = stream
.filter( p -> p.toFile().isFile() )
.mapToLong( p -> {
getLog().debug( "file " + p + " size " + p.toFile().length() );

return p.toFile().length();
} )
.sum();

getLog().info( "statisticName " + statisticName + " directory " + directory + " size " + size );

Teamcity.statistics( statisticName, size );
}

} catch( IOException e ) {
throw new MojoExecutionException( e );
}

}
}
4 changes: 2 additions & 2 deletions oap-teamcity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<dependencies>
<dependency>
<groupId>io.github.itning</groupId>
<artifactId>guava-retrying3</artifactId>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${oap.deps.guava.version}</version>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion oap-teamcity/src/main/java/oap/teamcity/Teamcity.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static void message( MessageStatus status, String text ) {
status.name() );
}

public static void statistics( String name, Object value ) {
public static void statistics( String name, Number value ) {
if( isTeamcity() )
System.out.format( "##teamcity[buildStatisticValue flowId='%s' key='%s' value='%s']\n",
FLOW_ID,
Expand Down
25 changes: 22 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<modules>
<module>oap-teamcity</module>
<module>oap-teamcity-testng</module>
<module>oap-teamcity-folder-size-maven</module>
</modules>

<repositories>
Expand All @@ -23,14 +24,14 @@
</repositories>

<properties>
<oap-teamcity.project.version>21.0.1</oap-teamcity.project.version>
<oap-teamcity.project.version>21.0.2</oap-teamcity.project.version>

<maven.compiler.release>21</maven.compiler.release>
<encoding>UTF-8</encoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<oap.deps.guava.version>3.0.3</oap.deps.guava.version>
<oap.deps.guava.version>32.0.0-jre</oap.deps.guava.version>
<oap.deps.testng.version>7.9.0</oap.deps.testng.version>
<oap.deps.lombok.version>1.18.30</oap.deps.lombok.version>

Expand All @@ -41,9 +42,26 @@
<oap.deps.checkstyle.version>10.3.3</oap.deps.checkstyle.version>
<oap.deps.maven.source.version>3.2.1</oap.deps.maven.source.version>
<oap.deps.maven.surefire.version>3.0.0-M7</oap.deps.maven.surefire.version>

<oap.deps.mavem-plugin-api.version>3.9.6</oap.deps.mavem-plugin-api.version>
<oap.deps.mavem-plugin-annotations.version>3.11.0</oap.deps.mavem-plugin-annotations.version>
<oap.deps.maven-plugin-plugin.version>3.11.0</oap.deps.maven-plugin-plugin.version>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>${oap.deps.maven-plugin-plugin.version}</version>
<configuration>
<goalPrefix>oap</goalPrefix>
</configuration>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -114,7 +132,8 @@
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${oap.deps.maven.checkstyle.version}</version>
<configuration>
<configLocation>https://raw.githubusercontent.com/oaplatform/oap-maven/master/.idea/checkstyle.xml</configLocation>
<configLocation>https://raw.githubusercontent.com/oaplatform/oap-maven/master/.idea/checkstyle.xml
</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
Expand Down
Loading