Permalink
Browse files

Fixes sync plugin, which missed sonatype credentials

  • Loading branch information...
1 parent fb0bb39 commit f039cf3e75f77a114392fe7f88f1208d9c1b4ff6 @adriancole adriancole committed May 12, 2016
View
@@ -20,6 +20,11 @@
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
+ <id>sonatype</id>
+ <username>${env.SONATYPE_USER}</username>
+ <password>${env.SONATYPE_PASSWORD}</password>
+ </server>
+ <server>
<id>bintray</id>
<username>${env.BINTRAY_USER}</username>
<password>${env.BINTRAY_KEY}</password>
View
@@ -70,6 +70,10 @@ env:
- secure: "dFvQkGjZDQpPCMsJU5K5+CQWZYSWkN2b2XBpXTNu9fQc22nQb5alxNYGx/YwE9JsMP4Dxh3Ros0gh3sB1F3bbIMsFvhkbablnYm3uJiHszbOt9hwBPAqeddS+kgT6admBSYNE2b9Zhb0vRlWPs/dSO9NQ0pEIhFDtcZgZ2Q+0F1p0nACR2rPwqYKmSMR2LTQDTZrPPxAsNx2a2gnGZWxQJe2tl5mgX5j/EBC+HKef9txn0n5AIUsFhzNposGMOE0iNDg/eGcbG7LCmyx6EazlDSAvbmJBZd7Hho3snGvnroqm1yFo1ry2Rlg2W+rsiy7o38Ng5j8oLjYcpejQJwgPMdIA2wM1GUHb+Dg7UebzWocrVwGMv91nS5+VcCZ4/mvK5bOI0VRyMB8TwI5mlcmqwIDmd/pbdYbpJKwsEARaHEPT1s1t8SL1plrFdCthnEcEUwT7LyvubgDPsLcwzODsmyuKrK+aUvZWU7U5o8/XqEMy6cDHb1Fu4qjVbpOchonsvlCOO1CP9cIAkMhNmT5Pvp/oL/c7rov0JpUuexdPwi9NtgJ0uUcBIoU17v/2erK3NNssj98oKLPuhXBwl60bEEFsx0+TyI4tcwPXS8+PuWHUzewmcFHzUVIK7hclRMHdbdY6L0/C42VoVvkp+FEl5Ycihi4O6uLnv3I4Z42lH8="
# Ex. travis encrypt GH_TOKEN=XXX-https://github.com/settings/tokens-XXX --add
- secure: "Iu7X1ePN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
@@ -14,8 +14,10 @@
package zipkin.maven;
import java.io.IOException;
-import okhttp3.FormBody;
+import java.util.concurrent.TimeUnit;
+import okhttp3.Credentials;
import okhttp3.HttpUrl;
+import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
@@ -33,7 +35,9 @@
*/
@Mojo(name = "sync", defaultPhase = LifecyclePhase.DEPLOY)
public class CentralSyncMojo extends AbstractMojo {
- final OkHttpClient client = new OkHttpClient();
+ final OkHttpClient client = new OkHttpClient.Builder()
+ .readTimeout(10, TimeUnit.MINUTES) // central sync is synchronous and takes a long time
+ .build();
@Parameter(defaultValue = "${project.version}", required = true)
String version;
@@ -48,54 +52,71 @@
/** settings/server/id containing the username and password */
@Parameter
- String serverId = "bintray";
+ String bintrayServerId = "bintray";
+
+ @Parameter
+ String sonatypeServerId = "sonatype";
@Parameter
String baseUrl = "https://api.bintray.com";
@Parameter
- String repository = "maven";
+ String subject = "openzipkin";
+
+ @Parameter
+ String repo = "maven";
@Parameter
String packageName = "zipkin-java";
@Override
public void execute() throws MojoExecutionException {
- Server server = settings.getServer(serverId);
- if (server == null) {
- throw new IllegalStateException("settings/server/id " + serverId + " not found!");
- }
- if (server.getUsername() == null) {
- throw new IllegalStateException("settings/server/" + serverId + "/username not found!");
- }
- if (server.getPassword() == null) {
- throw new IllegalStateException("settings/server/" + serverId + "/password not found!");
- }
+ Server bintray = verifyCredentialsPresent(bintrayServerId);
+ Server sonatype = verifyCredentialsPresent(sonatypeServerId);
- RequestBody formBody = new FormBody.Builder()
- .add("username", server.getUsername())
- .add("password", server.getPassword())
- .build();
HttpUrl url = HttpUrl.parse(baseUrl).newBuilder()
.addPathSegment("maven_central_sync")
- .addPathSegment(repository)
+ .addPathSegment(subject)
+ .addPathSegment(repo)
.addPathSegment(packageName)
.addPathSegment("versions")
.addPathSegment(version).build();
Request request = new Request.Builder()
.url(url)
+ .addHeader("Authorization", Credentials.basic(bintray.getUsername(), bintray.getPassword()))
.addHeader("User-Agent", "openzipkin/zipkin-java release process, centralsync-maven-plugin")
- .post(formBody)
+ .post(RequestBody.create(MediaType.parse("application/json"), "{\n"
+ + " \"username\": \"" + sonatype.getUsername() + "\",\n"
+ + " \"password\": \"" + sonatype.getPassword() + "\"\n"
+ + "}"))
.build();
if (dryRun) {
getLog().info("(Dry run) Would Sync to Maven Central via: POST " + request.url());
return;
}
try {
Response response = client.newCall(request).execute();
- getLog().info(response.body().string());
+ if (response.isSuccessful()) {
+ getLog().info(response.body().string());
+ } else {
+ throw new MojoExecutionException(request.url() + " failed: " + response);
+ }
} catch (IOException e) {
- throw new MojoExecutionException("API call failed", e);
+ throw new MojoExecutionException(request.url() + " failed: " + e.getMessage(), e);
+ }
+ }
+
+ Server verifyCredentialsPresent(String id) {
+ Server server = settings.getServer(id);
+ if (server == null) {
+ throw new IllegalStateException("settings/server/id " + id + " not found!");
+ }
+ if (server.getUsername() == null) {
+ throw new IllegalStateException("settings/server/" + id + "/username not found!");
+ }
+ if (server.getPassword() == null) {
+ throw new IllegalStateException("settings/server/" + id + "/password not found!");
}
+ return server;
}
}
@@ -13,6 +13,7 @@
*/
package zipkin.maven;
+import okhttp3.Credentials;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
@@ -33,7 +34,8 @@
public ExpectedException thrown = ExpectedException.none();
CentralSyncMojo mojo;
- Server serverSettings;
+ Server bintrayServer;
+ Server sonatypeServer;
@Before
public void setupCentralSyncMojo() {
@@ -42,25 +44,72 @@ public void setupCentralSyncMojo() {
mojo.settings = new Settings();
mojo.settings.addServer(new Server());
mojo.baseUrl = server.url("").toString();
- serverSettings = new Server();
- serverSettings.setId("bintray");
+ bintrayServer = new Server();
+ bintrayServer.setId("bintray");
+ bintrayServer.setUsername("bintray-user");
+ bintrayServer.setPassword("bintray-api-key");
+ sonatypeServer = new Server();
+ sonatypeServer.setId("sonatype");
+ sonatypeServer.setUsername("sync-user");
+ sonatypeServer.setPassword("sync-password");
+ }
+
+ @Test
+ public void failsWhenSonatypeNotInSettings() throws MojoExecutionException {
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("settings/server/id sonatype not found");
+
+ mojo.settings.addServer(bintrayServer);
+
+ mojo.execute();
+ }
+
+ @Test
+ public void failsWhenSonatypeUsernameNotInSettings() throws MojoExecutionException {
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("settings/server/sonatype/username not found");
+
+ mojo.settings.addServer(bintrayServer);
+
+ Server serverSettings = new Server();
+ serverSettings.setId("sonatype");
+ mojo.settings.addServer(serverSettings);
+
+ mojo.execute();
+ }
+
+ @Test
+ public void failsWhenSonatypePasswordNotInSettings() throws MojoExecutionException {
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("settings/server/sonatype/password not found!");
+
+ mojo.settings.addServer(bintrayServer);
+
+ Server serverSettings = new Server();
+ serverSettings.setId("sonatype");
serverSettings.setUsername("sync-user");
- serverSettings.setPassword("sync-password");
+ mojo.settings.addServer(serverSettings);
+
+ mojo.execute();
}
@Test
- public void failsWhenServerNotInSettings() throws MojoExecutionException {
+ public void failsWhenBintrayNotInSettings() throws MojoExecutionException {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("settings/server/id bintray not found");
+ mojo.settings.addServer(sonatypeServer);
+
mojo.execute();
}
@Test
- public void failsWhenServerUsernameNotInSettings() throws MojoExecutionException {
+ public void failsWhenBintrayUsernameNotInSettings() throws MojoExecutionException {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("settings/server/bintray/username not found");
+ mojo.settings.addServer(sonatypeServer);
+
Server serverSettings = new Server();
serverSettings.setId("bintray");
mojo.settings.addServer(serverSettings);
@@ -69,10 +118,12 @@ public void failsWhenServerUsernameNotInSettings() throws MojoExecutionException
}
@Test
- public void failsWhenServerPasswordNotInSettings() throws MojoExecutionException {
+ public void failsWhenBintrayPasswordNotInSettings() throws MojoExecutionException {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("settings/server/bintray/password not found!");
+ mojo.settings.addServer(sonatypeServer);
+
Server serverSettings = new Server();
serverSettings.setId("bintray");
serverSettings.setUsername("sync-user");
@@ -83,7 +134,8 @@ public void failsWhenServerPasswordNotInSettings() throws MojoExecutionException
@Test
public void doesntExecuteOnDryRun() throws MojoExecutionException {
- mojo.settings.addServer(serverSettings);
+ mojo.settings.addServer(sonatypeServer);
+ mojo.settings.addServer(bintrayServer);
mojo.dryRun = true;
mojo.execute();
@@ -94,13 +146,19 @@ public void doesntExecuteOnDryRun() throws MojoExecutionException {
public void execute() throws MojoExecutionException, InterruptedException {
server.enqueue(new MockResponse());
- mojo.settings.addServer(serverSettings);
+ mojo.settings.addServer(sonatypeServer);
+ mojo.settings.addServer(bintrayServer);
mojo.execute();
RecordedRequest request = server.takeRequest();
assertThat(request.getMethod()).isEqualTo("POST");
- assertThat(request.getPath()).isEqualTo("/maven_central_sync/maven/zipkin-java/versions/1.1");
- assertThat(request.getBody().readUtf8()).isEqualTo("username=sync-user&password=sync-password");
+ assertThat(request.getPath()).isEqualTo("/maven_central_sync/openzipkin/maven/zipkin-java/versions/1.1");
+ assertThat(request.getBody().readUtf8()).isEqualTo("{\n"
+ + " \"username\": \"sync-user\",\n"
+ + " \"password\": \"sync-password\"\n"
+ + "}");
+ assertThat(request.getHeader("Authorization"))
+ .isEqualTo(Credentials.basic("bintray-user", "bintray-api-key"));
assertThat(request.getHeader("User-Agent"))
.isEqualTo("openzipkin/zipkin-java release process, centralsync-maven-plugin");
}
View
@@ -116,8 +116,10 @@ if is_pull_request; then
elif is_travis_branch_master || is_version_tag; then
./mvnw --batch-mode -s ./.settings.xml -Prelease -nsu -pl -:benchmarks,-:interop,-:centralsync-maven-plugin -DskipTests deploy
- # If the deployment succeeded, sync it to Maven Central
- is_version_tag && ./mvnw --batch-mode -s ./.settings.xml -Prelease -nsu -pl -:benchmarks,-:interop,-:centralsync-maven-plugin io.zipkin.java:centralsync-maven-plugin:sync
+ # If the deployment succeeded, sync it to Maven Central. Note: this needs to be done once per project, not module, hence -N
+ if is_version_tag; then
+ ./mvnw --batch-mode -s ./.settings.xml -nsu -N io.zipkin.java:centralsync-maven-plugin:sync
+ fi
# If we are on a release tag, the following will update any version references and push a version tag for deployment.
elif build_started_by_tag; then

0 comments on commit f039cf3

Please sign in to comment.