io.opentelemetry.maven.MavenUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opentelemetry-maven-extension Show documentation
Show all versions of opentelemetry-maven-extension Show documentation
Maven extension to observe Maven builds with distributed traces using OpenTelemetry SDK
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.maven;
import org.apache.maven.plugin.MojoExecution;
final class MavenUtils {
private MavenUtils() {}
/**
* Shorten plugin identifiers.
*
* Examples:
*
*
* - maven-clean-plugin -> clean
*
- sisu-maven-plugin -> sisu
*
- spotbugs-maven-plugin -> spotbugs
*
*
* @param pluginArtifactId the artifact ID of the mojo {@link MojoExecution#getArtifactId()}
* @return shortened name
*/
static String getPluginArtifactIdShortName(String pluginArtifactId) {
if (pluginArtifactId.endsWith("-maven-plugin")) {
return pluginArtifactId.substring(0, pluginArtifactId.length() - "-maven-plugin".length());
} else if (pluginArtifactId.startsWith("maven-") && pluginArtifactId.endsWith("-plugin")) {
return pluginArtifactId.substring(
"maven-".length(), pluginArtifactId.length() - "-plugin".length());
} else {
return pluginArtifactId;
}
}
}