Skip to content

Commit

Permalink
Deploy Prep
Browse files Browse the repository at this point in the history
* Set version to 3.0.0-beta-1
* Add version info to user agent
* Setup pom for OSSRH deploy requirements
  • Loading branch information
bhelx committed Jul 25, 2019
1 parent 4b4558e commit 96f19b2
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 18 deletions.
7 changes: 7 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2019 Recurly Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
148 changes: 137 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,50 @@

<groupId>com.recurly.v3</groupId>
<artifactId>api-client</artifactId>
<version>1.0-SNAPSHOT</version>
<version>3.0.0-beta-1-SNAPSHOT</version>

<name>Recurly API V3 Java Client</name>
<description>The official Java client for Recurly's V3 API.</description>
<url>https://github.com/recurly/recurly-client-java</url>

<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
</license>
</licenses>

<developers>
<developer>
<name>Benjamin Eckel</name>
<email>[email protected]</email>
<organization>Recurly</organization>
<organizationUrl>https://recurly.com</organizationUrl>
</developer>
<developer>
<name>Aaron Suarez</name>
<email>[email protected]</email>
<organization>Recurly</organization>
<organizationUrl>https://recurly.com</organizationUrl>
</developer>
</developers>

<scm>
<connection>scm:git:git://github.com/recurly/recurly-client-java.git</connection>
<developerConnection>scm:git:ssh://github.com:recurly/recurly-client-java.git</developerConnection>
<url>https://github.com/recurly/recurly-client-java</url>
</scm>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<properties>
<java.version>1.8</java.version>
Expand All @@ -21,6 +64,16 @@
<defaultGoal>install</defaultGoal>
<finalName>${project.artifactId}-${project.version}</finalName>

<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>version.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -82,16 +135,89 @@
</executions>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.3.0</version>
<configuration>
<!-- TODO: Don't commit repoToken pubically! Find a way to integrate securely -->
<repoToken>yourcoverallsprojectrepositorytoken</repoToken>
<jacocoReports>
<param>${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml</param>
</jacocoReports>
</configuration>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.3.0</version>
<configuration>
<!-- TODO: Don't commit repoToken pubically! Find a way to integrate securely -->
<repoToken>yourcoverallsprojectrepositorytoken</repoToken>
<jacocoReports>
<param>${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml</param>
</jacocoReports>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- <plugin> -->
<!-- <groupId>org.apache.maven.plugins</groupId> -->
<!-- <artifactId>maven&#45;javadoc&#45;plugin</artifactId> -->
<!-- <version>2.9.1</version> -->
<!-- <configuration> -->
<!-- <release>jdk11</release> -->
<!-- </configuration> -->
<!-- <executions> -->
<!-- <execution> -->
<!-- <id>attach&#45;javadocs</id> -->
<!-- <goals> -->
<!-- <goal>jar</goal> -->
<!-- </goals> -->
<!-- </execution> -->
<!-- </executions> -->
<!-- </plugin> -->

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>deploy</phase>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
<!--<autoReleaseAfterClose>true</autoReleaseAfterClose>-->
</configuration>
</plugin>
</plugins>
</build>
Expand Down
30 changes: 25 additions & 5 deletions src/main/java/com/recurly/v3/http/HeaderInterceptor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.recurly.v3.http;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
Expand All @@ -9,6 +12,7 @@ public class HeaderInterceptor implements Interceptor {

private final String apiVersion;
private final String authToken;
private static String USER_AGENT = buildUserAgent();

public HeaderInterceptor(final String authToken, final String apiVersion) {
this.apiVersion = apiVersion;
Expand All @@ -24,15 +28,31 @@ public Response intercept(final Chain chain) throws IOException {
.header("Authorization", authToken)
.header("Accept", "application/vnd.recurly." + apiVersion)
.header("Content-Type", "application/json")
.header("User-Agent", userAgent());
.header("User-Agent", USER_AGENT);

Request request = builder.build();
return chain.proceed(request);
}

private String userAgent() {
// TODO: pull version from pom.xml
final String version = "3.0.0-beta-1";
return String.format("Recurly/%s; Java V3 Client", version);
private static String buildUserAgent() {
final String defaultVersion = "3.?.?";
final String defaultJvmInfo = "?";
final Properties properties = new Properties();

try {
final InputStream inputStream = HeaderInterceptor.class.getResourceAsStream("/version.properties");
if (inputStream != null) {
properties.load(inputStream);
final String version = properties.getProperty("version", defaultVersion);
final String jvmInfo = System.getProperty("java.version", defaultJvmInfo);
return String.format("Recurly/%s; java %s", version, jvmInfo);
}
} catch (Exception e) {
// TODO rethrow exception in strict-mode
System.out.println("[Recurly][WARNING] " + e.getStackTrace().toString());
}

System.out.println("[Recurly][WARNING] Could not set user agent header.");
return String.format("Recurly/%s; java %s", defaultVersion, defaultJvmInfo);
}
}
3 changes: 3 additions & 0 deletions src/main/resources/version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version=${project.version}
groupId=${project.groupId}
artifactId=${project.artifactId}
6 changes: 4 additions & 2 deletions src/test/java/com/recurly/v3/HeaderInterceptorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ public void testHttpHeaders() throws IOException, InterruptedException {
assertEquals("application/vnd.recurly.version", request.getHeader("Accept"));
assertEquals("application/json", request.getHeader("Content-Type"));

// TODO: pull this from pom.xml
assertEquals("Recurly/3.0.0-beta-1; Java V3 Client", request.getHeader("User-Agent"));
// TODO this regex will change on GA
// BETA semver sequence is forced until then
final String agentFormat = "Recurly/3\\.\\d+\\.\\d+-beta-\\d+-SNAPSHOT;\\s+java\\s+\\d+\\.\\d+\\.\\d+.*";
assertEquals(request.getHeader("User-Agent").matches(agentFormat), true);

mockWebServer.shutdown();
}
Expand Down

0 comments on commit 96f19b2

Please sign in to comment.