Skip to content

Commit

Permalink
Align Maven build with github.com/prometheus/client_java
Browse files Browse the repository at this point in the history
  • Loading branch information
fstab committed Jul 1, 2021
1 parent 6c2111b commit 77a5b8f
Show file tree
Hide file tree
Showing 15 changed files with 938 additions and 174 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Expand Up @@ -17,7 +17,8 @@ jobs:
- checkout
- restore_cache:
key: maven-dependencies-{{ checksum "pom.xml" }}
- run: mvn clean verify
- run: ./mvnw clean install
- run: ./mvnw javadoc:jar
- save_cache:
paths:
- ~/.m2
Expand Down
117 changes: 117 additions & 0 deletions .mvn/wrapper/MavenWrapperDownloader.java
@@ -0,0 +1,117 @@
/*
* Copyright 2007-present the original author or authors.
*
* Licensed 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 java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;

public class MavenWrapperDownloader {

private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";

/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";

/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";

/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";

public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());

// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);

File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}

private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}

}
Binary file added .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
8 changes: 3 additions & 5 deletions collector/pom.xml
Expand Up @@ -7,8 +7,8 @@
<version>0.15.1-SNAPSHOT</version>
</parent>

<groupId>io.prometheus.jmx</groupId>
<artifactId>collector</artifactId>
<name>Prometheus JMX Exporter - Collector</name>
<description>
See https://github.com/prometheus/jmx_exporter/blob/master/README.md
</description>
Expand All @@ -18,22 +18,20 @@
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.10.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.23</version> <!-- updating this breaks Java 6 compatibility -->
<version>1.23</version> <!-- required for the Java 6 release -->
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
Expand Down
18 changes: 9 additions & 9 deletions integration_tests/agent_smoke_test/pom.xml
Expand Up @@ -10,7 +10,15 @@
</parent>

<artifactId>agent_smoke_test</artifactId>
<name>Agent Smoke Test</name>
<name>Prometheus JMX Exporter - Agent Smoke Test</name>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<dependencies>
<dependency>
Expand Down Expand Up @@ -69,12 +77,4 @@
</plugin>
</plugins>
</build>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
</project>
19 changes: 9 additions & 10 deletions integration_tests/jmx_example_application/pom.xml
Expand Up @@ -10,15 +10,22 @@
</parent>

<artifactId>jmx_example_application</artifactId>
<name>JMX Example Application</name>
<name>Prometheus JMX Exporter - Example Application</name>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<build>
<finalName>${artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
Expand All @@ -37,12 +44,4 @@
</plugin>
</plugins>
</build>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
</project>
3 changes: 1 addition & 2 deletions integration_tests/pom.xml
Expand Up @@ -11,8 +11,7 @@
<artifactId>integration_tests</artifactId>
<packaging>pom</packaging>

<name>Prometheus JMX Exporter Integration Tests</name>

<name>Prometheus JMX Exporter - Integration Tests</name>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
Expand Down
13 changes: 10 additions & 3 deletions jmx_prometheus_httpserver/pom.xml
Expand Up @@ -8,25 +8,32 @@
</parent>

<artifactId>jmx_prometheus_httpserver</artifactId>
<name>Prometheus JMX Exporter - Http Server</name>
<description>
See https://github.com/prometheus/jmx_exporter/blob/master/README.md
</description>
<url>http://github.com/prometheus/jmx_exporter</url>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<dependencies>
<dependency>
<groupId>io.prometheus.jmx</groupId>
<artifactId>collector</artifactId>
<version>0.15.1-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_httpserver</artifactId>
<version>0.10.0</version>
</dependency>
</dependencies>


<build>
<plugins>
<!-- Build a full jar with dependencies -->
Expand Down
10 changes: 9 additions & 1 deletion jmx_prometheus_javaagent/pom.xml
Expand Up @@ -9,11 +9,20 @@
</parent>

<artifactId>jmx_prometheus_javaagent</artifactId>
<name>Prometheus JMX Exporter - Java Agent</name>
<description>
See https://github.com/prometheus/jmx_exporter/blob/master/README.md
</description>
<url>http://github.com/prometheus/jmx_exporter</url>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<dependencies>
<dependency>
<groupId>io.prometheus.jmx</groupId>
Expand Down Expand Up @@ -41,7 +50,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
20 changes: 12 additions & 8 deletions jmx_prometheus_javaagent_java6/pom.xml
Expand Up @@ -8,31 +8,38 @@
</parent>

<artifactId>jmx_prometheus_javaagent_java6</artifactId>
<name>Prometheus JMX Exporter - Java Agent for Java 6</name>
<description>
See https://github.com/prometheus/jmx_exporter/blob/master/README.md
</description>
<url>http://github.com/prometheus/jmx_exporter</url>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<dependencies>
<dependency>
<groupId>io.prometheus.jmx</groupId>
<artifactId>collector</artifactId>
<version>0.15.1-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
<version>0.10.0</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_httpserver</artifactId>
<version>0.10.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -44,7 +51,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -95,7 +101,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<systemPropertyVariables>
<buildDirectory>${project.build.directory}</buildDirectory>
Expand All @@ -106,7 +111,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<version>3.2.0</version>
<executions>
<execution>
<id>reserve-network-port</id>
Expand All @@ -125,7 +130,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
Expand Down

0 comments on commit 77a5b8f

Please sign in to comment.