This is an automated email from the ASF dual-hosted git repository. eolivelli pushed a commit to branch maven-metrics in repository https://gitbox.apache.org/repos/asf/maven-studies.git
commit b2db5fd355f81d5461931d523ce88379956bbab7 Author: Enrico Olivelli <eolive...@apache.org> AuthorDate: Sun May 10 16:07:01 2020 +0200 separate metrics api --- .../installer/DefaultArtifactInstaller.java | 7 +- maven-core/pom.xml | 2 +- .../maven/lifecycle/internal/MojoExecutor.java | 8 +- .../DefaultPluginDependenciesResolver.java | 7 +- .../maven/project/DefaultProjectBuilder.java | 7 +- .../main/java/org/apache/maven/cli/MavenCli.java | 4 +- .../transfer/AbstractMavenTransferListener.java | 22 +++- .../transfer/BatchModeMavenTransferListener.java | 5 +- .../cli/transfer/ConsoleMavenTransferListener.java | 7 +- .../cli/transfer/Slf4jMavenTransferListener.java | 21 +++- maven-metrics/pom.xml | 44 ------- .../java/org/apache/maven/metrics/Counter.java | 54 --------- .../main/java/org/apache/maven/metrics/Gauge.java | 38 ------ .../main/java/org/apache/maven/metrics/Metric.java | 47 -------- .../org/apache/maven/metrics/MetricsContext.java | 92 -------------- .../org/apache/maven/metrics/MetricsProvider.java | 71 ----------- .../metrics/MetricsProviderLifeCycleException.java | 51 -------- .../org/apache/maven/metrics/MetricsSystem.java | 42 ------- .../java/org/apache/maven/metrics/Summary.java | 37 ------ .../java/org/apache/maven/metrics/SummarySet.java | 39 ------ .../maven/metrics/impl/NullMetricsProvider.java | 132 --------------------- pom.xml | 6 +- 22 files changed, 68 insertions(+), 675 deletions(-) diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java b/maven-compat/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java index abdae8b..8b23e05 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java @@ -32,6 +32,7 @@ import org.apache.maven.artifact.repository.metadata.Snapshot; import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.Versioning; import org.apache.maven.metrics.MetricsSystem; +import org.apache.maven.metrics.util.MetricsUtils; import org.apache.maven.plugin.LegacySupport; import org.apache.maven.project.artifact.ProjectArtifactMetadata; import org.codehaus.plexus.component.annotations.Component; @@ -76,7 +77,7 @@ public class DefaultArtifactInstaller public void install( File source, Artifact artifact, ArtifactRepository localRepository ) throws ArtifactInstallationException { - long startInstall = System.currentTimeMillis(); + long startInstall = MetricsUtils.now(); RepositorySystemSession session = LegacyLocalRepositoryManager.overlay( localRepository, legacySupport.getRepositorySession(), repoSystem ); @@ -137,8 +138,8 @@ public class DefaultArtifactInstaller artifact.addMetadata( new ArtifactRepositoryMetadata( artifact, versioning ) ); metricsSystem .getMetricsContext() - .getSummary("installArtifact", "Time to install an artifact (ms)") - .add(System.currentTimeMillis() - startInstall); + .getSummary( "installArtifact", "Time to install an artifact (ms)" ) + .add( MetricsUtils.elapsedMillis( startInstall ) ); } } diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 6fba007..1789296 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -41,7 +41,7 @@ under the License. </dependency> <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-metrics</artifactId> + <artifactId>maven-metrics-api</artifactId> </dependency> <!-- Remove the following two deps to see how to remove Settings from the core --> <dependency> diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java index 36421d4..cf0993b 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java @@ -40,6 +40,7 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.MissingProjectException; import org.apache.maven.metrics.MetricsSystem; +import org.apache.maven.metrics.util.MetricsUtils; import org.apache.maven.plugin.BuildPluginManager; import org.apache.maven.plugin.MavenPluginManager; import org.apache.maven.plugin.MojoExecution; @@ -168,7 +169,7 @@ public class MojoExecutor DependencyContext dependencyContext ) throws LifecycleExecutionException { - long startExecute = System.currentTimeMillis(); + long startExecute = MetricsUtils.now(); MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); try @@ -217,8 +218,9 @@ public class MojoExecutor { pluginManager.executeMojo( session, mojoExecution ); metricsSystem.getMetricsContext() - .getSummarySet("executeMojo", "Time to execute a mojo (ms)") - .add(mojoExecution.getLifecyclePhase()+"_"+mojoExecution.getGoal(), System.currentTimeMillis() - startExecute); + .getSummarySet( "executeMojo", "Time to execute a mojo (ms)" ) + .add( mojoExecution.getLifecyclePhase() + "_" + mojoExecution.getGoal(), + MetricsUtils.elapsedMillis( startExecute ) ); } catch ( MojoFailureException | PluginManagerException | PluginConfigurationException | MojoExecutionException e ) diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java index 9ea1f52..e9d46ae 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java @@ -31,6 +31,7 @@ import javax.inject.Singleton; import org.apache.maven.RepositoryUtils; import org.apache.maven.metrics.MetricsSystem; +import org.apache.maven.metrics.util.MetricsUtils; import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.PluginResolutionException; @@ -99,7 +100,7 @@ public class DefaultPluginDependenciesResolver public Artifact resolve( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session ) throws PluginResolutionException { - long startResolve = System.currentTimeMillis(); + long startResolve = MetricsUtils.now(); RequestTrace trace = RequestTrace.newChild( null, plugin ); Artifact pluginArtifact = toArtifact( plugin, session ); @@ -141,8 +142,8 @@ public class DefaultPluginDependenciesResolver } metricsSystem .getMetricsContext() - .getSummary("resolvePluginDependency", "Time to resolve dependencies of a plugin (ms)") - .add(System.currentTimeMillis() - startResolve); + .getSummary( "resolvePluginDependency", "Time to resolve dependencies of a plugin (ms)" ) + .add( MetricsUtils.elapsedMillis( startResolve ) ); return pluginArtifact; } diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index c204c8e..118fbdb 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -45,6 +45,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.LegacyLocalRepositoryManager; import org.apache.maven.bridge.MavenRepositorySystem; import org.apache.maven.metrics.MetricsSystem; +import org.apache.maven.metrics.util.MetricsUtils; import org.apache.maven.model.Build; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; @@ -323,13 +324,13 @@ public class DefaultProjectBuilder ArtifactRequest pomRequest = new ArtifactRequest(); pomRequest.setArtifact( pomArtifact ); pomRequest.setRepositories( config.repositories ); - long startResolvePom = System.currentTimeMillis(); + long startResolvePom = MetricsUtils.now(); ArtifactResult pomResult = repoSystem.resolveArtifact( config.session, pomRequest ); metricsSystem .getMetricsContext() - .getSummary("resolvePom", "Time to resolve pom artifact (ms)") - .add(System.currentTimeMillis() - startResolvePom); + .getSummary( "resolvePom" , "Time to resolve pom artifact (ms)" ) + .add( MetricsUtils.elapsedMillis( startResolvePom ) ); pomArtifact = pomResult.getArtifact(); localProject = pomResult.getRepository() instanceof WorkspaceRepository; diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index ffbd3ed..b8dc9b9 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -1744,12 +1744,12 @@ public class MavenCli protected TransferListener getConsoleTransferListener( boolean printResourceNames ) { - return new ConsoleMavenTransferListener( System.out, printResourceNames ); + return new ConsoleMavenTransferListener( System.out, printResourceNames, metricsSystem.getMetricsContext() ); } protected TransferListener getBatchTransferListener() { - return new Slf4jMavenTransferListener(); + return new Slf4jMavenTransferListener( metricsSystem.getMetricsContext() ); } protected void customizeContainer( PlexusContainer container ) diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java index 72bffc3..15b8371 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java @@ -25,6 +25,7 @@ import java.text.DecimalFormatSymbols; import java.util.Locale; import org.apache.commons.lang3.Validate; +import org.apache.maven.metrics.MetricsContext; import org.eclipse.aether.transfer.AbstractTransferListener; import org.eclipse.aether.transfer.TransferCancelledException; import org.eclipse.aether.transfer.TransferEvent; @@ -210,11 +211,13 @@ public abstract class AbstractMavenTransferListener } } - protected PrintStream out; + protected final PrintStream out; + private final MetricsContext metricsContext; - protected AbstractMavenTransferListener( PrintStream out ) + protected AbstractMavenTransferListener( PrintStream out , MetricsContext metricsContext ) { this.out = out; + this.metricsContext = metricsContext; } @Override @@ -247,7 +250,7 @@ public abstract class AbstractMavenTransferListener { String action = ( event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded" ); String direction = event.getRequestType() == TransferEvent.RequestType.PUT ? "to" : "from"; - + String metricDescription = event.getRequestType() == TransferEvent.RequestType.PUT ? "uploads" : "downloads"; TransferResource resource = event.getResource(); long contentLength = event.getTransferredBytes(); FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH ); @@ -267,6 +270,19 @@ public abstract class AbstractMavenTransferListener message.append( ')' ); out.println( message.toString() ); + + metricsContext + .getContext( "transfer" ) + .getSummary( event.getRequestType().name().toLowerCase() + "_bytes", + "total bytes ( " + metricDescription + ")" ) + .add( contentLength ); + + metricsContext + .getContext( "transfer" ) + .getSummary( event.getRequestType().name().toLowerCase() + "_time", + "total time (" + metricDescription + ") " ) + .add( duration ); + } } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/BatchModeMavenTransferListener.java b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/BatchModeMavenTransferListener.java index 2eee8f6..38adf53 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/BatchModeMavenTransferListener.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/BatchModeMavenTransferListener.java @@ -20,6 +20,7 @@ package org.apache.maven.cli.transfer; */ import java.io.PrintStream; +import org.apache.maven.metrics.MetricsContext; /** * BatchModeMavenTransferListener @@ -27,9 +28,9 @@ import java.io.PrintStream; public class BatchModeMavenTransferListener extends AbstractMavenTransferListener { - public BatchModeMavenTransferListener( PrintStream out ) + public BatchModeMavenTransferListener( PrintStream out, MetricsContext metricsContext ) { - super( out ); + super( out, metricsContext ); } } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListener.java b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListener.java index 950b5d0..e9e6125 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListener.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListener.java @@ -27,6 +27,7 @@ import java.util.Locale; import java.util.Map; import org.apache.commons.lang3.StringUtils; +import org.apache.maven.metrics.MetricsContext; import org.eclipse.aether.transfer.TransferCancelledException; import org.eclipse.aether.transfer.TransferEvent; import org.eclipse.aether.transfer.TransferResource; @@ -43,12 +44,12 @@ public class ConsoleMavenTransferListener private Map<TransferResource, Long> transfers = Collections.synchronizedMap( new LinkedHashMap<>() ); - private boolean printResourceNames; + private final boolean printResourceNames; private int lastLength; - public ConsoleMavenTransferListener( PrintStream out, boolean printResourceNames ) + public ConsoleMavenTransferListener( PrintStream out, boolean printResourceNames, MetricsContext metricsContext ) { - super( out ); + super( out, metricsContext ); this.printResourceNames = printResourceNames; } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/Slf4jMavenTransferListener.java b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/Slf4jMavenTransferListener.java index 57e69ba..88cb37c 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/Slf4jMavenTransferListener.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/Slf4jMavenTransferListener.java @@ -22,6 +22,7 @@ package org.apache.maven.cli.transfer; import java.util.Locale; import org.apache.maven.cli.transfer.AbstractMavenTransferListener.FileSizeFormat; +import org.apache.maven.metrics.MetricsContext; import org.eclipse.aether.transfer.AbstractTransferListener; import org.eclipse.aether.transfer.TransferCancelledException; import org.eclipse.aether.transfer.TransferEvent; @@ -37,16 +38,19 @@ public class Slf4jMavenTransferListener { protected final Logger out; + private final MetricsContext metricsContext; - public Slf4jMavenTransferListener() + public Slf4jMavenTransferListener( MetricsContext metricsContext ) { this.out = LoggerFactory.getLogger( Slf4jMavenTransferListener.class ); + this.metricsContext = metricsContext; } // TODO should we deprecate? - public Slf4jMavenTransferListener( Logger out ) + public Slf4jMavenTransferListener( Logger out, MetricsContext metricsContext ) { this.out = out; + this.metricsContext = metricsContext; } @Override @@ -78,6 +82,7 @@ public class Slf4jMavenTransferListener { String action = ( event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded" ); String direction = event.getRequestType() == TransferEvent.RequestType.PUT ? "to" : "from"; + String metricDescription = event.getRequestType() == TransferEvent.RequestType.PUT ? "uploads" : "downloads"; TransferResource resource = event.getResource(); long contentLength = event.getTransferredBytes(); @@ -98,6 +103,18 @@ public class Slf4jMavenTransferListener message.append( ')' ); out.info( message.toString() ); + + metricsContext + .getContext( "transfer" ) + .getSummary( event.getRequestType().name().toLowerCase() + "_bytes", + "total bytes ( " + metricDescription + ")" ) + .add( contentLength ); + + metricsContext + .getContext( "transfer" ) + .getSummary( event.getRequestType().name().toLowerCase() + "_time", + "total time (" + metricDescription + ") " ) + .add( duration ); } } diff --git a/maven-metrics/pom.xml b/maven-metrics/pom.xml deleted file mode 100644 index ab30cb6..0000000 --- a/maven-metrics/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ -<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.maven</groupId> - <artifactId>maven</artifactId> - <version>3.7.0-SNAPSHOT</version> - </parent> - - <artifactId>maven-metrics</artifactId> - - <name>Maven Metrics</name> - - <dependencies> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - </dependency> - </dependencies> - - <build> - </build> -</project> diff --git a/maven-metrics/src/main/java/org/apache/maven/metrics/Counter.java b/maven-metrics/src/main/java/org/apache/maven/metrics/Counter.java deleted file mode 100644 index e2eb1d1..0000000 --- a/maven-metrics/src/main/java/org/apache/maven/metrics/Counter.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.apache.maven.metrics; - -/* - * 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. - */ - -/** - * A counter refers to a value which can only increase. - * Usually the value is reset when the process starts. - */ -public interface Counter -{ - - /** - * Increment the value by one. - * <p>This method is thread safe, The MetricsProvider will take care of synchronization.</p> - */ - default void inc() - { - add( 1 ); - } - - /** - * Increment the value by a given amount. - * <p>This method is thread safe, The MetricsProvider will take care of synchronization.</p> - * - * @param delta amount to increment, this cannot be a negative number. - */ - void add( long delta ); - - /** - * Get the current value held by the counter. - * <p>This method is thread safe, The MetricsProvider will take care of synchronization.</p> - * - * @return the current value - */ - long get(); - -} diff --git a/maven-metrics/src/main/java/org/apache/maven/metrics/Gauge.java b/maven-metrics/src/main/java/org/apache/maven/metrics/Gauge.java deleted file mode 100644 index 1c6559c..0000000 --- a/maven-metrics/src/main/java/org/apache/maven/metrics/Gauge.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.apache.maven.metrics; - -/* - * 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. - */ - -/** - * A Gauge is an application provided object which will be called by the framework in order to sample the value - * of an integer value. - */ -public interface Gauge -{ - - /** - * Returns the current value associated with this gauge. - * The MetricsProvider will call this callback without taking care of synchronization, it is up to the application - * to handle thread safety. - * - * @return the current value for the gauge - */ - Number get(); - -} diff --git a/maven-metrics/src/main/java/org/apache/maven/metrics/Metric.java b/maven-metrics/src/main/java/org/apache/maven/metrics/Metric.java deleted file mode 100644 index f77c850..0000000 --- a/maven-metrics/src/main/java/org/apache/maven/metrics/Metric.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.apache.maven.metrics; - -/* - * 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. - */ - -/** - * Interface common to every metrics. - * It allows the user to define common metadata about the metric. - */ -public interface Metric -{ - /** - * Define a textual label for the metric - * @param label the label (plain text) - * @return the metric handle itself - */ - default <T extends Metric> T setLabel( String label ) - { - return (T) this; - } - - /** - * Define a textual help for the metric - * @param help the help (plain text) - * @return the metric handle itself - */ - default <T extends Metric> T setHelp( String help ) - { - return (T) this; - } -} diff --git a/maven-metrics/src/main/java/org/apache/maven/metrics/MetricsContext.java b/maven-metrics/src/main/java/org/apache/maven/metrics/MetricsContext.java deleted file mode 100644 index cb85793..0000000 --- a/maven-metrics/src/main/java/org/apache/maven/metrics/MetricsContext.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.apache.maven.metrics; - -/* - * 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. - */ - -/** - * A MetricsContext is like a namespace for metrics. Each component/submodule - * will have its own MetricsContext. - * <p> - * In some cases it is possible to have a separate MetricsContext for each - * instance of a component, for instance on the server side a possible usecase - * it to gather metrics for every other peer. - * </p> - * <p> - * Contexts are organized in a hierarchy. - * </p> - * - */ -public interface MetricsContext -{ - - /** - * Returns a sub context. - * - * @param name the name of the subcontext - * - * @return a new metrics context. - */ - MetricsContext getContext( String name ); - - /** - * Returns a counter. - * - * @param name - * @return the counter identified by name in this context. - */ - Counter getCounter( String name, String description ); - - /** - * Registers an user provided {@link Gauge} which will be called by the - * MetricsProvider in order to sample an integer value. - * If another Gauge was already registered the new one will - * take its place. - * Registering a null callback is not allowed. - * - * @param name unique name of the Gauge in this context - * @param gauge the implementation of the Gauge - * - */ - void registerGauge( String name, String description, Gauge gauge ); - - /** - * Unregisters the user provided {@link Gauge} bound to the given name. - * - * @param name unique name of the Gauge in this context - * - */ - void unregisterGauge( String name ); - - /** - * Returns a summary. - * - * @param name - * @return the summary identified by name in this context. - */ - Summary getSummary( String name, String description ); - - /** - * Returns a set of summaries. - * - * @param name - * @return the summary identified by name in this context. - */ - SummarySet getSummarySet( String name, String description ); - -} diff --git a/maven-metrics/src/main/java/org/apache/maven/metrics/MetricsProvider.java b/maven-metrics/src/main/java/org/apache/maven/metrics/MetricsProvider.java deleted file mode 100644 index f4af144..0000000 --- a/maven-metrics/src/main/java/org/apache/maven/metrics/MetricsProvider.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.apache.maven.metrics; - -/* - * 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. - */ - -/** - * A MetricsProvider is a system which collects Metrics and publishes current values to external facilities. - * - * The system will create an instance of the configured class using the default constructor, which must be public.<br> - * After the instantiation of the provider, the system will call {@link #configure(java.util.Properties) } - * in order to provide configuration, - * and then when the system is ready to work it will call {@link #start() }. - * <br> - * Providers can be used both on ZooKeeper servers and on ZooKeeper clients. - */ -public interface MetricsProvider -{ - /** - * Start the provider. - * For instance such method will start a network endpoint. - * - * @throws MetricsProviderLifeCycleException in case of failure - */ - default void start() throws MetricsProviderLifeCycleException - { - } - - /** - * Provides access to the root context. - * - * @return the root context - */ - MetricsContext getRootContext(); - - /** - * Releases resources held by the provider.<br> - * This method must not throw exceptions. - * The provider may dump the results to the logs or send - * the results to an external <br> - * This method can be called more than once. - */ - default void stop() - { - } - - /** - * Reset all values. - * This method is optional and can be noop, depending - * on the underlying implementation. - */ - default void resetAllValues() - { - } - -} diff --git a/maven-metrics/src/main/java/org/apache/maven/metrics/MetricsProviderLifeCycleException.java b/maven-metrics/src/main/java/org/apache/maven/metrics/MetricsProviderLifeCycleException.java deleted file mode 100644 index ecf7d5b..0000000 --- a/maven-metrics/src/main/java/org/apache/maven/metrics/MetricsProviderLifeCycleException.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.apache.maven.metrics; - -/* - * 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. - */ - -/** - * A generic exception thrown during the licecycle of a MetricsProvider. - * <p>These exception will prevent the system from booting.</p> - * <p>Normally these exception will be ignored during shutdown.</p> - */ -public class MetricsProviderLifeCycleException extends Exception -{ - - private static final long serialVersionUID = 1L; - - public MetricsProviderLifeCycleException() - { - } - - public MetricsProviderLifeCycleException( String message ) - { - super( message ); - } - - public MetricsProviderLifeCycleException( String message, Throwable cause ) - { - super( message, cause ); - } - - public MetricsProviderLifeCycleException( Throwable cause ) - { - super( cause ); - } - -} diff --git a/maven-metrics/src/main/java/org/apache/maven/metrics/MetricsSystem.java b/maven-metrics/src/main/java/org/apache/maven/metrics/MetricsSystem.java deleted file mode 100644 index 9e70db5..0000000 --- a/maven-metrics/src/main/java/org/apache/maven/metrics/MetricsSystem.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.apache.maven.metrics; - -/* - * 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. - */ - -/** - * Component to access Metrics System - * @author Enrico Olivelli - */ -public interface MetricsSystem -{ - - String HINT = "metricsSystem"; - - /** - * Access current metrics context. - * @return the metrics context - */ - MetricsContext getMetricsContext(); - - /** - * Low level Access to the Provider - * @return the provider - */ - MetricsProvider getMetricsProvider(); -} diff --git a/maven-metrics/src/main/java/org/apache/maven/metrics/Summary.java b/maven-metrics/src/main/java/org/apache/maven/metrics/Summary.java deleted file mode 100644 index 9ad49c1..0000000 --- a/maven-metrics/src/main/java/org/apache/maven/metrics/Summary.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.apache.maven.metrics; - -/* - * 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. - */ - -/** - * Summaries track the size and number of events. - * They are able to publish minumum, maximum, average values, depending on the capabilities of the MetricsProvider. - */ -public interface Summary -{ - - /** - * Register a value. - * <p>This method is thread safe, The MetricsProvider will take care of synchronization.</p> - * - * @param value current value - */ - void add( long value ); - -} diff --git a/maven-metrics/src/main/java/org/apache/maven/metrics/SummarySet.java b/maven-metrics/src/main/java/org/apache/maven/metrics/SummarySet.java deleted file mode 100644 index e31764a..0000000 --- a/maven-metrics/src/main/java/org/apache/maven/metrics/SummarySet.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.apache.maven.metrics; - -/* - * 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. - */ - -/** - * Summaries track the size and number of events. - * They are able to publish minumum, maximum, average values, depending on the capabilities of the MetricsProvider. - * A SummarySet is a set of {@link Summary}. - */ -public interface SummarySet -{ - - /** - * Register a value. - * <p>This method is thread safe, The MetricsProvider will take care of synchronization.</p> - * - * @param key the key to access the Summary for the given key - * @param value current value - */ - void add( String key, long value ); - -} diff --git a/maven-metrics/src/main/java/org/apache/maven/metrics/impl/NullMetricsProvider.java b/maven-metrics/src/main/java/org/apache/maven/metrics/impl/NullMetricsProvider.java deleted file mode 100644 index a94c3b2..0000000 --- a/maven-metrics/src/main/java/org/apache/maven/metrics/impl/NullMetricsProvider.java +++ /dev/null @@ -1,132 +0,0 @@ -package org.apache.maven.metrics.impl; - -/* - * 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. - */ - -import org.apache.maven.metrics.Counter; -import org.apache.maven.metrics.Gauge; -import org.apache.maven.metrics.MetricsContext; -import org.apache.maven.metrics.MetricsProvider; -import org.apache.maven.metrics.Summary; -import org.apache.maven.metrics.SummarySet; - -/** - * This is a dummy MetricsProvider which does nothing. - */ -public class NullMetricsProvider implements MetricsProvider -{ - - /** - * Instance of NullMetricsProvider useful for tests. - */ - public static final MetricsProvider INSTANCE = new NullMetricsProvider(); - - @Override - public MetricsContext getRootContext() - { - return NullMetricsContext.INSTANCE; - } - - /** - * Default no-op implementation. - */ - public static final class NullMetricsContext implements MetricsContext - { - - public static final NullMetricsContext INSTANCE = new NullMetricsContext(); - - @Override - public MetricsContext getContext( String name ) - { - return INSTANCE; - } - - @Override - public Counter getCounter( String name, String description ) - { - return NullCounter.INSTANCE; - } - - @Override - public void registerGauge( String name, String description, Gauge gauge ) - { - } - - @Override - public void unregisterGauge( String name ) - { - } - - @Override - public Summary getSummary( String name, String description ) - { - return NullSummary.INSTANCE; - } - - @Override - public SummarySet getSummarySet( String name, String description ) - { - return NullSummarySet.INSTANCE; - } - - } - - private static final class NullCounter implements Counter - { - - private static final NullCounter INSTANCE = new NullCounter(); - - @Override - public void add( long delta ) - { - } - - @Override - public long get() - { - return 0; - } - - } - - private static final class NullSummary implements Summary - { - - private static final NullSummary INSTANCE = new NullSummary(); - - @Override - public void add( long value ) - { - } - - } - - private static final class NullSummarySet implements SummarySet - { - - private static final NullSummarySet INSTANCE = new NullSummarySet(); - - @Override - public void add( String key, long value ) - { - } - - } - -} diff --git a/pom.xml b/pom.xml index 2b6f841..9e09825 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,7 @@ under the License. <securityDispatcherVersion>1.4</securityDispatcherVersion> <cipherVersion>1.8</cipherVersion> <modelloVersion>1.11</modelloVersion> + <metricsVersion>1.0.0-SNAPSHOT</metricsVersion> <jxpathVersion>1.3</jxpathVersion> <resolverVersion>1.4.2</resolverVersion> <slf4jVersion>1.7.29</slf4jVersion> @@ -84,7 +85,6 @@ under the License. <module>maven-builder-support</module> <module>maven-model</module> <module>maven-model-builder</module> - <module>maven-metrics</module> <module>maven-core</module> <module>maven-settings</module> <module>maven-settings-builder</module> @@ -186,8 +186,8 @@ under the License. </dependency> <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-metrics</artifactId> - <version>${project.version}</version> + <artifactId>maven-metrics-api</artifactId> + <version>${metricsVersion}</version> </dependency> <dependency> <groupId>org.apache.maven</groupId>