diff --git a/github-core/src/main/java/com/github/maven/plugins/core/GitHubProjectMojo.java b/github-core/src/main/java/com/github/maven/plugins/core/GitHubProjectMojo.java
index d7c30b3f..9785abee 100644
--- a/github-core/src/main/java/com/github/maven/plugins/core/GitHubProjectMojo.java
+++ b/github-core/src/main/java/com/github/maven/plugins/core/GitHubProjectMojo.java
@@ -192,7 +192,7 @@ protected GitHubClient createClient(String host, String userName,
}
}
}
-
+
if (configureUsernamePassword(client, userName, password)
|| configureOAuth2Token(client, oauth2Token)
|| configureServerCredentials(client, serverId, settings,
@@ -215,10 +215,10 @@ protected GitHubClient createClient(String host, String userName,
protected GitHubClient createClient(String hostname)
throws MojoExecutionException {
if (!hostname.contains("://"))
- return new GitHubClientEgit(hostname);
+ return new RateLimitedGitHubClient(hostname);
try {
URL hostUrl = new URL(hostname);
- return new GitHubClientEgit(hostUrl.getHost(), hostUrl.getPort(),
+ return new RateLimitedGitHubClient(hostUrl.getHost(), hostUrl.getPort(),
hostUrl.getProtocol());
} catch (MalformedURLException e) {
throw new MojoExecutionException("Could not parse host URL "
@@ -234,7 +234,7 @@ protected GitHubClient createClient(String hostname)
* @return non-null client
*/
protected GitHubClient createClient() {
- return new GitHubClientEgit();
+ return new RateLimitedGitHubClient();
}
/**
@@ -333,7 +333,7 @@ protected boolean configureServerCredentials(final GitHubClient client,
throw new MojoExecutionException( "Unable to lookup SettingsDecrypter: " + cle.getMessage(), cle );
}
}
-
+
serverUsername = server.getUsername();
serverPassword = server.getPassword();
// }
@@ -407,7 +407,7 @@ protected Server getServer(final Settings settings, final String serverId) {
/**
* Check hostname that matched nonProxy setting
- *
+ *
* @param proxy Maven Proxy. Must not null
* @param hostname
* @return matching result. true: match nonProxy
@@ -515,10 +515,10 @@ protected Proxy getProxy(final Settings settings, final String serverId, final S
return null;
}
-
+
@Requirement
private PlexusContainer container;
-
+
/**
* {@inheritDoc}
*/
@@ -527,5 +527,5 @@ public void contextualize( Context context )
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
-
+
}
diff --git a/github-core/src/main/java/com/github/maven/plugins/core/RateLimitedGitHubClient.java b/github-core/src/main/java/com/github/maven/plugins/core/RateLimitedGitHubClient.java
new file mode 100644
index 00000000..5a3ff445
--- /dev/null
+++ b/github-core/src/main/java/com/github/maven/plugins/core/RateLimitedGitHubClient.java
@@ -0,0 +1,52 @@
+package com.github.maven.plugins.core;
+
+import com.github.maven.plugins.core.egit.GitHubClientEgit;
+import com.google.common.util.concurrent.RateLimiter;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+
+public class RateLimitedGitHubClient extends GitHubClientEgit {
+
+ /**
+ * AS per https://github.com/octokit/octokit.net/issues/638#issuecomment-67795998,
+ * it seems that GitHub only allow 20 API calls per 1-minute period
+ */
+ private RateLimiter rateLimiter = RateLimiter.create(20.0/60.0);
+
+ public RateLimitedGitHubClient() {
+ super();
+ }
+
+ public RateLimitedGitHubClient(String hostname) {
+ super(hostname);
+ }
+
+ public RateLimitedGitHubClient(String hostname, int port, String scheme) {
+ super(hostname, port, scheme);
+ }
+
+ @Override
+ protected HttpURLConnection createDelete(String uri) throws IOException {
+ //rateLimiter.acquire();
+ return super.createDelete(uri);
+ }
+
+ @Override
+ protected HttpURLConnection createGet(String uri) throws IOException {
+ //rateLimiter.acquire();
+ return super.createGet(uri);
+ }
+
+ @Override
+ protected HttpURLConnection createPost(String uri) throws IOException {
+ rateLimiter.acquire();
+ return super.createPost(uri);
+ }
+
+ @Override
+ protected HttpURLConnection createPut(String uri) throws IOException {
+ rateLimiter.acquire();
+ return super.createPut(uri);
+ }
+}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 92caa146..9fe0b605 100644
--- a/pom.xml
+++ b/pom.xml
@@ -185,6 +185,13 @@
2.2.2
+
+ com.google.guava
+ guava
+
+ 14.0
+
+
junit
junit