From 727c0df701e454aeaf4435e7f69d0b610cc6bd21 Mon Sep 17 00:00:00 2001 From: nazoking Date: Thu, 27 Nov 2014 15:36:51 +0900 Subject: [PATCH] format --- .../src/org/eclipse/jgit/pgm/LsRemote.java | 6 +- .../org/eclipse/jgit/transport/AmazonS3.java | 6 +- .../jgit/transport/TransportAmazonS3.java | 72 ++++++++++--------- 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java index 8cc943580ea..e7cad536444 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java @@ -108,9 +108,9 @@ static class TailMatcher { private Pattern tailPattern; public TailMatcher(String pattern) { - String p = "(^|/)" - + Pattern.quote(pattern).replaceAll("\\*", "\\\\E.*\\\\Q") - + "$"; + String p = "(^|/)" //$NON-NLS-1$ + + Pattern.quote(pattern).replaceAll("\\*", "\\\\E.*\\\\Q") //$NON-NLS-1$ //$NON-NLS-2$ + + "$"; //$NON-NLS-1$ tailPattern = Pattern.compile(p); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java index 703af27490a..5abc991406f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java @@ -588,9 +588,9 @@ private HttpURLConnection open(final String method, final String bucket, } private void authorize(final HttpURLConnection c) throws IOException { - if(token != null){ - c.setRequestProperty("x-amz-security-token", token); - } + if (token != null) { + c.setRequestProperty("x-amz-security-token", token); //$NON-NLS-1$ + } final Map> reqHdr = c.getRequestProperties(); final SortedMap sigHdr = new TreeMap(); for (final Map.Entry> entry : reqHdr.entrySet()) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java index 00277ace90b..72fec619b53 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java @@ -153,6 +153,7 @@ public Transport open(URIish uri) throws NotSupportedException { * keyPrefix + "/". */ private final String keyPrefix; + TransportAmazonS3(final Repository local, final URIish uri) throws NotSupportedException { super(local, uri); @@ -181,13 +182,13 @@ public Transport open(URIish uri) throws NotSupportedException { } private Properties loadProperties() throws NotSupportedException { - if ("IAM".equals(uri.getUser())) { - try{ - return instanceCredentialProfile(); - }catch(IOException e){ - throw new RuntimeException(e); - } - } + if ("IAM".equals(uri.getUser())) { //$NON-NLS-1$ + try { + return instanceCredentialProfile(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } File propsFile; if (local != null) { if (local.getDirectory() != null) { @@ -218,33 +219,38 @@ private Properties loadProperties() throws NotSupportedException { return props; } - private static final Pattern jsonStringPropertyPattern = Pattern.compile("\"([^\"]*)\"\\s*:\\s*\"([^\"]*)\""); - private static final String roleUrl = "http://169.254.169.254/latest/meta-data/iam/security-credentials/"; - private static Properties instanceCredentialProfile() throws IOException{ + private static final Pattern jsonStringPropertyPattern = Pattern + .compile("\"([^\"]*)\"\\s*:\\s*\"([^\"]*)\""); //$NON-NLS-1$ + + private static final String roleUrl = "http://169.254.169.254/latest/meta-data/iam/security-credentials/"; //$NON-NLS-1$ + + private static Properties instanceCredentialProfile() throws IOException { Properties props = new Properties(); - String role = getHttpBody(roleUrl); - String jsonBody = getHttpBody(roleUrl+role); - Matcher matcher = jsonStringPropertyPattern.matcher(jsonBody); - HashMap values = new HashMap(); - while(matcher.find()){ - values.put(matcher.group(1),matcher.group(2)); - } - props.setProperty("accesskey", values.get("AccessKeyId")); - props.setProperty("secretkey", values.get("SecretAccessKey")); - props.setProperty("token", values.get("Token")); - return props; - } - private static String getHttpBody(String url) throws IOException{ - final URL u = new URL(url); - final HttpURLConnection c = (HttpURLConnection) u.openConnection(); - final InputStream in = c.getInputStream(); - final int len = c.getContentLength(); - try { - return new String(IO.readWholeStream(in, len == -1 ? 1000 : len).array(), "UTF-8"); - } finally { - in.close(); - } - } + String role = getHttpBody(roleUrl); + String jsonBody = getHttpBody(roleUrl + role); + Matcher matcher = jsonStringPropertyPattern.matcher(jsonBody); + HashMap values = new HashMap(); + while (matcher.find()) { + values.put(matcher.group(1), matcher.group(2)); + } + props.setProperty("accesskey", values.get("AccessKeyId")); //$NON-NLS-1$ //$NON-NLS-2$ + props.setProperty("secretkey", values.get("SecretAccessKey")); //$NON-NLS-1$ //$NON-NLS-2$ + props.setProperty("token", values.get("Token")); //$NON-NLS-1$ //$NON-NLS-2$ + return props; + } + + private static String getHttpBody(String url) throws IOException { + final URL u = new URL(url); + final HttpURLConnection c = (HttpURLConnection) u.openConnection(); + final InputStream in = c.getInputStream(); + final int len = c.getContentLength(); + try { + return new String(IO.readWholeStream(in, len == -1 ? 1000 : len) + .array(), "UTF-8"); //$NON-NLS-1$ + } finally { + in.close(); + } + } private static Properties loadPropertiesFile(File propsFile) throws NotSupportedException {