diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2010-06-25 17:42:01 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2010-06-25 17:46:39 -0700 |
commit | 479fcf9e32fd5a802c5a959d0e697f85a6eee369 (patch) | |
tree | 387780bfc24794335e8ee63a707bec454d31d697 /org.eclipse.jgit/src/org/eclipse/jgit/transport | |
parent | f39c9fc7415c9b74c2c4fc12978d865b03cc330d (diff) | |
download | jgit-479fcf9e32fd5a802c5a959d0e697f85a6eee369.tar.gz jgit-479fcf9e32fd5a802c5a959d0e697f85a6eee369.zip |
Refactor amazon-s3:// property file loading to support no directory
In the future getDirectory() can return null. Avoid an NPE here by
refactoring the code to support conditionally skipping a check for
the properties file in the repository directory, falling to only
the user's ~/ file location.
Change-Id: I76f5503d4063fdd9d24b7c1b58e1b09ddf1a5670
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/transport')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java | 45 |
1 files changed, 28 insertions, 17 deletions
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 56a5c9796d..79b88b6a73 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java @@ -126,23 +126,7 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { throws NotSupportedException { super(local, uri); - Properties props = null; - File propsFile = new File(local.getDirectory(), uri.getUser()); - if (!propsFile.isFile()) - propsFile = new File(local.getFS().userHome(), uri.getUser()); - if (propsFile.isFile()) { - try { - props = AmazonS3.properties(propsFile); - } catch (IOException e) { - throw new NotSupportedException(MessageFormat.format(JGitText.get().cannotReadFile, propsFile), e); - } - } else { - props = new Properties(); - props.setProperty("accesskey", uri.getUser()); - props.setProperty("secretkey", uri.getPass()); - } - - s3 = new AmazonS3(props); + s3 = new AmazonS3(loadProperties()); bucket = uri.getHost(); String p = uri.getPath(); @@ -153,6 +137,33 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { keyPrefix = p; } + private Properties loadProperties() throws NotSupportedException { + if (local.getDirectory() != null) { + File propsFile = new File(local.getDirectory(), uri.getUser()); + if (propsFile.isFile()) + return loadPropertiesFile(propsFile); + } + + File propsFile = new File(local.getFS().userHome(), uri.getUser()); + if (propsFile.isFile()) + return loadPropertiesFile(propsFile); + + Properties props = new Properties(); + props.setProperty("accesskey", uri.getUser()); + props.setProperty("secretkey", uri.getPass()); + return props; + } + + private static Properties loadPropertiesFile(File propsFile) + throws NotSupportedException { + try { + return AmazonS3.properties(propsFile); + } catch (IOException e) { + throw new NotSupportedException(MessageFormat.format( + JGitText.get().cannotReadFile, propsFile), e); + } + } + @Override public FetchConnection openFetch() throws TransportException { final DatabaseS3 c = new DatabaseS3(bucket, keyPrefix + "/objects"); |