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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ Find the latest [version here](https://search.maven.org/search?q=g:com.appoptics
<dependency>
<groupId>com.appoptics.metrics</groupId>
<artifactId>appoptics-api-java</artifactId>
<version>1.0.2</version>
<version>1.0.6</version>
</dependency>

You may also pull in a shaded uber jar that has all the dependencies:

<dependency>
<groupId>com.appoptics.metrics</groupId>
<artifactId>appoptics-api-java</artifactId>
<version>1.0.6</version>
<classifier>nodeps</classifier>
</dependency>

## Setup
Expand Down
49 changes: 30 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@
<goals>
<goal>jar</goal>
</goals>
<configuration>
<!-- don't attach sources here as the shade plugin will also attach sources -->
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>
Expand Down Expand Up @@ -109,17 +105,26 @@
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<version>3.5.1</version>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<phase>package</phase>
<configuration>
<finalName>${project.artifactId}-${project.version}-nodeps</finalName>
<artifactSet>
<includes>
<include>com.squareup.**</include>
<include>com.fasterxml.**</include>
</includes>
</artifactSet>
<relocations>
Expand All @@ -131,8 +136,11 @@
<pattern>okio</pattern>
<shadedPattern>com.appoptics.appopticsjava.shaded.okio</shadedPattern>
</relocation>
<relocation>
<pattern>com.fasterxml</pattern>
<shadedPattern>com.appoptics.appopticsjava.shaded.com.fasterxml</shadedPattern>
</relocation>
</relocations>
<createSourcesJar>true</createSourcesJar>
</configuration>
</execution>
</executions>
Expand All @@ -151,16 +159,18 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<version>3.11.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
<debug>true</debug>
<parameters>true</parameters>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<version>3.2.2</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
Expand All @@ -169,7 +179,7 @@
</build>
<packaging>jar</packaging>
<properties>
<jackson.version>2.9.8</jackson.version>
<jackson.version>2.16.0</jackson.version>
</properties>
<dependencies>
<dependency>
Expand All @@ -187,26 +197,27 @@
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.11.0</version>
<version>4.12.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.7.36</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
<version>1.7.36</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/appoptics/metrics/client/DefaultPoster.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.appoptics.metrics.client;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import static java.util.concurrent.TimeUnit.MILLISECONDS;

public class DefaultPoster implements IPoster {
private static final Logger log = LoggerFactory.getLogger(DefaultPoster.class);
private static final Logger log = Logger.getLogger(DefaultPoster.class.getName());

@Override
public HttpResponse post(String uri, Duration connectTimeout, Duration readTimeout, Map<String, String> headers, byte[] payload) {
Expand Down Expand Up @@ -43,7 +42,7 @@ public HttpResponse post(String uri, Duration connectTimeout, Duration readTimeo
responseStream = connection.getErrorStream();
}
if(responseStream == null) {
log.warn("responseStream null for {} responseCode {}", uri, responseCode);
log.warning(() -> "responseStream null for " + uri + " responseCode " + responseCode);
responseBody = new byte[0];
} else {
responseBody = readResponse(responseStream);
Expand Down Expand Up @@ -92,7 +91,7 @@ void close(Closeable closeable) {
closeable.close();
}
} catch (IOException e) {
log.warn("Could not close " + closeable, e);
log.log(Level.WARNING, e, () -> "Could not close " + closeable);
}
}

Expand Down
14 changes: 5 additions & 9 deletions src/main/java/com/appoptics/metrics/client/Versions.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package com.appoptics.metrics.client;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Encapsulates logic about versions found in POM files
*/
public class Versions {
private static final Logger LOG = LoggerFactory.getLogger(Versions.class);

private Versions() {
// do not construct.
Expand All @@ -30,21 +28,19 @@ public static String getVersion(String path, Class<?> klass) {
try {
final InputStream in = klass.getClassLoader().getResourceAsStream(path);
if (in != null) {
try {
final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
String line = reader.readLine();
while (line != null) {
if (line.startsWith("version")) {
return line.split("=")[1];
}
line = reader.readLine();
}
} finally {
in.close();
}
}
} catch (IOException e) {
LOG.error("Could not read package version using path " + path + ":", e);
Logger logger = Logger.getLogger(Versions.class.getName());
logger.log(Level.SEVERE, e, () -> "Could not read package version using path " + path);
}
return "unknown";
}
Expand Down