From add24f2a361463002b875fc8e581df95f42480c9 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 5 Oct 2009 11:43:01 -0700 Subject: [PATCH 1/5] Standardize the source code formatter for Eclipse We now supply an exported format description for anyone to import into their own workbench, and all projects reference this style in a consistent way. Change-Id: Ic243544a761ef2db29025a89ba6bb932a3a3ce34 Signed-off-by: Shawn O. Pearce --- .../.settings/org.eclipse.jdt.core.prefs | 15 +- .../.settings/org.eclipse.jdt.ui.prefs | 6 +- .../.settings/org.eclipse.jdt.core.prefs | 15 +- .../.settings/org.eclipse.jdt.ui.prefs | 6 +- tools/eclipse-JGit-Format.xml | 267 ++++++++++++++++++ 5 files changed, 301 insertions(+), 8 deletions(-) create mode 100644 tools/eclipse-JGit-Format.xml diff --git a/org.eclipse.jgit.pgm/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jgit.pgm/.settings/org.eclipse.jdt.core.prefs index f0c80d363..413e63b95 100644 --- a/org.eclipse.jgit.pgm/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.jgit.pgm/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ -#Sun Mar 15 19:46:39 CET 2009 +#Fri Oct 02 18:44:57 PDT 2009 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 @@ -103,6 +103,7 @@ org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 org.eclipse.jdt.core.formatter.blank_lines_before_method=1 org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 org.eclipse.jdt.core.formatter.blank_lines_before_package=0 +org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line @@ -116,9 +117,14 @@ org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line org.eclipse.jdt.core.formatter.comment.clear_blank_lines=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false +org.eclipse.jdt.core.formatter.comment.format_block_comments=true org.eclipse.jdt.core.formatter.comment.format_comments=true org.eclipse.jdt.core.formatter.comment.format_header=false org.eclipse.jdt.core.formatter.comment.format_html=true +org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true +org.eclipse.jdt.core.formatter.comment.format_line_comments=true org.eclipse.jdt.core.formatter.comment.format_source_code=true org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true org.eclipse.jdt.core.formatter.comment.indent_root_tags=true @@ -141,6 +147,9 @@ org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false org.eclipse.jdt.core.formatter.indentation.size=4 org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert @@ -293,6 +302,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=inser org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert @@ -313,9 +323,12 @@ org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false org.eclipse.jdt.core.formatter.lineSplit=80 +org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false +org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true org.eclipse.jdt.core.formatter.tabulation.char=tab org.eclipse.jdt.core.formatter.tabulation.size=4 org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false +org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true diff --git a/org.eclipse.jgit.pgm/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jgit.pgm/.settings/org.eclipse.jdt.ui.prefs index 709a44074..7210d0f74 100644 --- a/org.eclipse.jgit.pgm/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.jgit.pgm/.settings/org.eclipse.jdt.ui.prefs @@ -1,7 +1,7 @@ -#Wed May 09 00:20:24 CEST 2007 +#Fri Oct 02 18:43:47 PDT 2009 eclipse.preferences.version=1 -formatter_profile=_JGit -formatter_settings_version=10 +formatter_profile=_JGit Format +formatter_settings_version=11 org.eclipse.jdt.ui.ignorelowercasenames=true org.eclipse.jdt.ui.importorder=java;javax;org;com; org.eclipse.jdt.ui.ondemandthreshold=99 diff --git a/org.eclipse.jgit/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jgit/.settings/org.eclipse.jdt.core.prefs index 8e8e17240..76557139e 100644 --- a/org.eclipse.jgit/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.jgit/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ -#Sun Mar 15 01:13:43 CET 2009 +#Fri Oct 02 18:43:47 PDT 2009 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 @@ -103,6 +103,7 @@ org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 org.eclipse.jdt.core.formatter.blank_lines_before_method=1 org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 org.eclipse.jdt.core.formatter.blank_lines_before_package=0 +org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line @@ -116,9 +117,14 @@ org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line org.eclipse.jdt.core.formatter.comment.clear_blank_lines=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false +org.eclipse.jdt.core.formatter.comment.format_block_comments=true org.eclipse.jdt.core.formatter.comment.format_comments=true org.eclipse.jdt.core.formatter.comment.format_header=false org.eclipse.jdt.core.formatter.comment.format_html=true +org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true +org.eclipse.jdt.core.formatter.comment.format_line_comments=true org.eclipse.jdt.core.formatter.comment.format_source_code=true org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true org.eclipse.jdt.core.formatter.comment.indent_root_tags=true @@ -141,6 +147,9 @@ org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false org.eclipse.jdt.core.formatter.indentation.size=4 org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert @@ -293,6 +302,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=inser org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert @@ -313,9 +323,12 @@ org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false org.eclipse.jdt.core.formatter.lineSplit=80 +org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false +org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true org.eclipse.jdt.core.formatter.tabulation.char=tab org.eclipse.jdt.core.formatter.tabulation.size=4 org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false +org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true diff --git a/org.eclipse.jgit/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jgit/.settings/org.eclipse.jdt.ui.prefs index 709a44074..056d54651 100644 --- a/org.eclipse.jgit/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.jgit/.settings/org.eclipse.jdt.ui.prefs @@ -1,7 +1,7 @@ -#Wed May 09 00:20:24 CEST 2007 +#Fri Oct 02 18:44:57 PDT 2009 eclipse.preferences.version=1 -formatter_profile=_JGit -formatter_settings_version=10 +formatter_profile=_JGit Format +formatter_settings_version=11 org.eclipse.jdt.ui.ignorelowercasenames=true org.eclipse.jdt.ui.importorder=java;javax;org;com; org.eclipse.jdt.ui.ondemandthreshold=99 diff --git a/tools/eclipse-JGit-Format.xml b/tools/eclipse-JGit-Format.xml new file mode 100644 index 000000000..52845ca93 --- /dev/null +++ b/tools/eclipse-JGit-Format.xml @@ -0,0 +1,267 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 1640812b89b6adffce580ec0472c266f6fcc0403 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 2 Oct 2009 19:01:04 -0700 Subject: [PATCH 2/5] Remove useless test005_todopack test This test doesn't work because it requires a pack file which we have lost to the ages. We couldn't include it because the pack was actually a copy of the GPL'd C git.git project, and was there to test some sort of corner case that the test never documented properly. Change-Id: I282ee1c6a637a8654df93a3847507a6c60e4cfab Signed-off-by: Shawn O. Pearce --- .../eclipse/jgit/lib/T0004_PackReader.java | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0004_PackReader.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0004_PackReader.java index adddbfe09..be801e494 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0004_PackReader.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0004_PackReader.java @@ -83,32 +83,4 @@ public void test004_lookupDeltifiedObject() throws IOException { assertEquals(18009, or.getSize()); assertEquals(537, ((PackedObjectLoader) or).getDataOffset()); } - - public void test005_todopack() throws IOException { - final File todopack = JGitTestUtil.getTestResourceFile("todopack"); - if (!todopack.isDirectory()) { - System.err.println("Skipping " + getName() + ": no " + todopack); - return; - } - - final File packDir = new File(db.getObjectsDirectory(), "pack"); - final String packname = "pack-2e71952edc41f3ce7921c5e5dd1b64f48204cf35"; - copyFile(new File(todopack, packname + ".pack"), new File(packDir, - packname + ".pack")); - copyFile(new File(todopack, packname + ".idx"), new File(packDir, - packname + ".idx")); - Tree t; - - t = db - .mapTree(ObjectId.fromString( - "aac9df07f653dd18b935298deb813e02c32d2e6f")); - assertNotNull(t); - t.memberCount(); - - t = db - .mapTree(ObjectId.fromString( - "6b9ffbebe7b83ac6a61c9477ab941d999f5d0c96")); - assertNotNull(t); - t.memberCount(); - } } From 3ce8c91e759ee1a9fca1d7b3cb2646b76388de6c Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 2 Oct 2009 18:54:20 -0700 Subject: [PATCH 3/5] Move setupReflog test function to only test that cares Only one test class actually needs this function, so instead of us inheriting it down into every test, move it to that one class. Change-Id: I5700ca48df4177153f2b3861dec7c538c621e775 Signed-off-by: Shawn O. Pearce --- .../eclipse/jgit/lib/ReflogReaderTest.java | 22 +++++++++++++++++++ .../eclipse/jgit/lib/RepositoryTestCase.java | 19 ---------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogReaderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogReaderTest.java index dae7cb895..1f2f25d5e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogReaderTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogReaderTest.java @@ -44,6 +44,10 @@ package org.eclipse.jgit.lib; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; import java.text.SimpleDateFormat; import java.util.List; @@ -173,4 +177,22 @@ public void testNoLog() throws Exception { assertEquals(0, db.getReflogReader("master").getReverseEntries().size()); assertNull(db.getReflogReader("master").getLastEntry()); } + + private void setupReflog(String logName, byte[] data) + throws FileNotFoundException, IOException { + File logfile = new File(db.getDirectory(), logName); + if (!logfile.getParentFile().mkdirs() + && !logfile.getParentFile().isDirectory()) { + throw new IOException( + "oops, cannot create the directory for the test reflog file" + + logfile); + } + FileOutputStream fileOutputStream = new FileOutputStream(logfile); + try { + fileOutputStream.write(data); + } finally { + fileOutputStream.close(); + } + } + } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java index 2870e4126..ac8881b1f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java @@ -46,7 +46,6 @@ import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; @@ -326,22 +325,4 @@ public void run() { repositoriesToClose.add(newRepo); return newRepo; } - - protected void setupReflog(String logName, byte[] data) - throws FileNotFoundException, IOException { - File logfile = new File(db.getDirectory(), logName); - if (!logfile.getParentFile().mkdirs() - && !logfile.getParentFile().isDirectory()) { - throw new IOException( - "oops, cannot create the directory for the test reflog file" - + logfile); - } - FileOutputStream fileOutputStream = new FileOutputStream(logfile); - try { - fileOutputStream.write(data); - } finally { - fileOutputStream.close(); - } - } - } From 8d5510d51c27d9fccbeb9cfd82f218a5c3ebf530 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 3 Oct 2009 15:43:34 -0700 Subject: [PATCH 4/5] Move AmazonS3 command line utility to jgit-pgm This removes one of the few remaining dependencies on AWTAuthenticator from the core library. For the most part the interface is identical to the prior main method. The jgit-pgm Main class already sets up the HTTP proxy and authenticator for us, so we don't need to do that in our new run method. Change-Id: Ia2cce34d34c97b88214a8bd8f2cc542845e19032 Signed-off-by: Shawn O. Pearce --- .../org/eclipse/jgit/pgm/AmazonS3Client.java | 136 ++++++++++++++++++ .../services/org.eclipse.jgit.pgm.TextBuiltin | 1 + .../src/org/eclipse/jgit/pgm/Die.java | 13 ++ .../src/org/eclipse/jgit/pgm/TextBuiltin.java | 11 ++ .../org/eclipse/jgit/transport/AmazonS3.java | 66 --------- 5 files changed, 161 insertions(+), 66 deletions(-) create mode 100644 jgit-pgm/src/main/java/org/eclipse/jgit/pgm/AmazonS3Client.java diff --git a/jgit-pgm/src/main/java/org/eclipse/jgit/pgm/AmazonS3Client.java b/jgit-pgm/src/main/java/org/eclipse/jgit/pgm/AmazonS3Client.java new file mode 100644 index 000000000..179a32bdb --- /dev/null +++ b/jgit-pgm/src/main/java/org/eclipse/jgit/pgm/AmazonS3Client.java @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2009, Google Inc. + * Copyright (C) 2008, Shawn O. Pearce + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.eclipse.jgit.pgm; + +import java.io.EOFException; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URLConnection; +import java.util.Properties; + +import org.eclipse.jgit.transport.AmazonS3; +import org.kohsuke.args4j.Argument; + +@Command(name = "amazon-s3-client", common = false, usage = "Command line client for Amazon's S3 service") +class AmazonS3Client extends TextBuiltin { + @Argument(index = 0, metaVar = "conn.prop", required = true) + private File propertyFile; + + @Argument(index = 1, metaVar = "OP", required = true) + private String op; + + @Argument(index = 2, metaVar = "BUCKET", required = true) + private String bucket; + + @Argument(index = 3, metaVar = "KEY", required = true) + private String key; + + @Override + protected final boolean requiresRepository() { + return false; + } + + @Override + protected void run() throws Exception { + final AmazonS3 s3 = new AmazonS3(properties()); + + if ("get".equals(op)) { + final URLConnection c = s3.get(bucket, key); + int len = c.getContentLength(); + final InputStream in = c.getInputStream(); + try { + final byte[] tmp = new byte[2048]; + while (len > 0) { + final int n = in.read(tmp); + if (n < 0) + throw new EOFException("Expected " + len + " bytes."); + System.out.write(tmp, 0, n); + len -= n; + } + } finally { + in.close(); + } + + } else if ("ls".equals(op) || "list".equals(op)) { + for (final String k : s3.list(bucket, key)) + System.out.println(k); + + } else if ("rm".equals(op) || "delete".equals(op)) { + s3.delete(bucket, key); + + } else if ("put".equals(op)) { + final OutputStream os = s3.beginPut(bucket, key, null, null); + final byte[] tmp = new byte[2048]; + int n; + while ((n = System.in.read(tmp)) > 0) + os.write(tmp, 0, n); + os.close(); + + } else { + throw die("Unsupported operation: " + op); + } + } + + private Properties properties() { + try { + final InputStream in = new FileInputStream(propertyFile); + try { + final Properties p = new Properties(); + p.load(in); + return p; + } finally { + in.close(); + } + } catch (FileNotFoundException e) { + throw die("no such file: " + propertyFile, e); + } catch (IOException e) { + throw die("cannot read " + propertyFile, e); + } + } +} diff --git a/org.eclipse.jgit.pgm/src/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin b/org.eclipse.jgit.pgm/src/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin index 9c8933f5d..6c2a65306 100644 --- a/org.eclipse.jgit.pgm/src/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin +++ b/org.eclipse.jgit.pgm/src/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin @@ -1,3 +1,4 @@ +org.eclipse.jgit.pgm.AmazonS3Client org.eclipse.jgit.pgm.Branch org.eclipse.jgit.pgm.Clone org.eclipse.jgit.pgm.Daemon diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Die.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Die.java index e514ca514..a2f406082 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Die.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Die.java @@ -1,4 +1,5 @@ /* + * Copyright (C) 2009, Google Inc. * Copyright (C) 2008, Shawn O. Pearce * and other copyright owners as documented in the project's IP log. * @@ -62,4 +63,16 @@ public class Die extends RuntimeException { public Die(final String why) { super(why); } + + /** + * Construct a new message explaining what has gone wrong. + * + * @param why + * the message to show to the end-user. + * @param cause + * why the command has failed. + */ + public Die(final String why, final Throwable cause) { + super(why, cause); + } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java index edd4fbcf9..13b45e242 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java @@ -229,6 +229,17 @@ protected static Die die(final String why) { return new Die(why); } + /** + * @param why + * textual explanation + * @param cause + * why the command has failed. + * @return a runtime exception the caller is expected to throw + */ + protected static Die die(final String why, final Throwable cause) { + return new Die(why, cause); + } + String abbreviateRef(String dst, boolean abbreviateRemote) { if (dst.startsWith(R_HEADS)) dst = dst.substring(R_HEADS.length()); 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 9343f4aba..46ebf8255 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java @@ -44,7 +44,6 @@ package org.eclipse.jgit.transport; import java.io.ByteArrayOutputStream; -import java.io.EOFException; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -79,7 +78,6 @@ import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; -import org.eclipse.jgit.awtui.AwtAuthenticator; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.ProgressMonitor; @@ -623,70 +621,6 @@ private void authorize(final HttpURLConnection c) throws IOException { c.setRequestProperty("Authorization", "AWS " + publicKey + ":" + sec); } - /** - * Simple command line interface to {@link AmazonS3}. - * - * @param argv - * command line arguments. See usage for details. - * @throws IOException - * an error occurred. - */ - public static void main(final String[] argv) throws IOException { - if (argv.length != 4) { - commandLineUsage(); - return; - } - - AwtAuthenticator.install(); - HttpSupport.configureHttpProxy(); - - final AmazonS3 s3 = new AmazonS3(properties(new File(argv[0]))); - final String op = argv[1]; - final String bucket = argv[2]; - final String key = argv[3]; - if ("get".equals(op)) { - final URLConnection c = s3.get(bucket, key); - int len = c.getContentLength(); - final InputStream in = c.getInputStream(); - try { - final byte[] tmp = new byte[2048]; - while (len > 0) { - final int n = in.read(tmp); - if (n < 0) - throw new EOFException("Expected " + len + " bytes."); - System.out.write(tmp, 0, n); - len -= n; - } - } finally { - in.close(); - } - } else if ("ls".equals(op) || "list".equals(op)) { - for (final String k : s3.list(bucket, key)) - System.out.println(k); - } else if ("rm".equals(op) || "delete".equals(op)) { - s3.delete(bucket, key); - } else if ("put".equals(op)) { - final OutputStream os = s3.beginPut(bucket, key, null, null); - final byte[] tmp = new byte[2048]; - int n; - while ((n = System.in.read(tmp)) > 0) - os.write(tmp, 0, n); - os.close(); - } else { - commandLineUsage(); - } - } - - private static void commandLineUsage() { - System.err.println("usage: conn.prop op bucket key"); - System.err.println(); - System.err.println(" where conn.prop is a jets3t properties file."); - System.err.println(" op is one of: get ls rm put"); - System.err.println(" bucket is the name of the S3 bucket"); - System.err.println(" key is the name of the object."); - System.exit(1); - } - static Properties properties(final File authFile) throws FileNotFoundException, IOException { final Properties p = new Properties(); From 41e4b2fed4cf8da887fb5384f61bda823c51970c Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 3 Oct 2009 15:53:24 -0700 Subject: [PATCH 5/5] Move HttpSupport's configureHttpProxy to jgit-pgm This is the last chunk of code in jgit-core which references the awtui package. Moving it to the only consumer in jgit-pgm allows us to move the awtui package over to the jgit-awtui module. Change-Id: I2fd81be2076117b2f2c5f8ed45de7f29272af6cf Signed-off-by: Shawn O. Pearce --- .../src/org/eclipse/jgit/pgm/Main.java | 54 ++++++++++++++++--- .../org/eclipse/jgit/util/HttpSupport.java | 42 --------------- 2 files changed, 46 insertions(+), 50 deletions(-) diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java index 625132ae5..45d941e2d 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java @@ -1,6 +1,4 @@ /* - * Copyright (C) 2008-2009, Google Inc. - * Copyright (C) 2008, Marek Zawirski * Copyright (C) 2006, Robin Rosenberg * Copyright (C) 2008, Shawn O. Pearce * and other copyright owners as documented in the project's IP log. @@ -47,19 +45,20 @@ package org.eclipse.jgit.pgm; import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.List; -import org.kohsuke.args4j.Argument; -import org.kohsuke.args4j.CmdLineException; -import org.kohsuke.args4j.ExampleMode; -import org.kohsuke.args4j.Option; import org.eclipse.jgit.awtui.AwtAuthenticator; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.pgm.opt.CmdLineParser; import org.eclipse.jgit.pgm.opt.SubcommandHandler; -import org.eclipse.jgit.util.HttpSupport; +import org.kohsuke.args4j.Argument; +import org.kohsuke.args4j.CmdLineException; +import org.kohsuke.args4j.ExampleMode; +import org.kohsuke.args4j.Option; /** Command line entry point. */ public class Main { @@ -88,7 +87,7 @@ public static void main(final String[] argv) { final Main me = new Main(); try { AwtAuthenticator.install(); - HttpSupport.configureHttpProxy(); + configureHttpProxy(); me.execute(argv); } catch (Die err) { System.err.println("fatal: " + err.getMessage()); @@ -181,4 +180,43 @@ private static File findGitDir() { } return null; } + + /** + * Configure the JRE's standard HTTP based on http_proxy. + *

+ * The popular libcurl library honors the http_proxy + * environment variable as a means of specifying an HTTP proxy for requests + * made behind a firewall. This is not natively recognized by the JRE, so + * this method can be used by command line utilities to configure the JRE + * before the first request is sent. + * + * @throws MalformedURLException + * the value in http_proxy is unsupportable. + */ + private static void configureHttpProxy() throws MalformedURLException { + final String s = System.getenv("http_proxy"); + if (s == null || s.equals("")) + return; + + final URL u = new URL((s.indexOf("://") == -1) ? "http://" + s : s); + if (!"http".equals(u.getProtocol())) + throw new MalformedURLException("Invalid http_proxy: " + s + + ": Only http supported."); + + final String proxyHost = u.getHost(); + final int proxyPort = u.getPort(); + + System.setProperty("http.proxyHost", proxyHost); + if (proxyPort > 0) + System.setProperty("http.proxyPort", String.valueOf(proxyPort)); + + final String userpass = u.getUserInfo(); + if (userpass != null && userpass.contains(":")) { + final int c = userpass.indexOf(':'); + final String user = userpass.substring(0, c); + final String pass = userpass.substring(c + 1); + AwtAuthenticator.add(new AwtAuthenticator.CachedAuthentication( + proxyHost, proxyPort, user, pass)); + } + } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java index 40134d0e4..3910c8bd7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java @@ -47,56 +47,14 @@ import java.io.UnsupportedEncodingException; import java.net.ConnectException; import java.net.HttpURLConnection; -import java.net.MalformedURLException; import java.net.Proxy; import java.net.ProxySelector; import java.net.URISyntaxException; import java.net.URL; import java.net.URLEncoder; -import org.eclipse.jgit.awtui.AwtAuthenticator; - /** Extra utilities to support usage of HTTP. */ public class HttpSupport { - /** - * Configure the JRE's standard HTTP based on http_proxy. - *

- * The popular libcurl library honors the http_proxy - * environment variable as a means of specifying an HTTP proxy for requests - * made behind a firewall. This is not natively recognized by the JRE, so - * this method can be used by command line utilities to configure the JRE - * before the first request is sent. - * - * @throws MalformedURLException - * the value in http_proxy is unsupportable. - */ - public static void configureHttpProxy() throws MalformedURLException { - final String s = System.getenv("http_proxy"); - if (s == null || s.equals("")) - return; - - final URL u = new URL((s.indexOf("://") == -1) ? "http://" + s : s); - if (!"http".equals(u.getProtocol())) - throw new MalformedURLException("Invalid http_proxy: " + s - + ": Only http supported."); - - final String proxyHost = u.getHost(); - final int proxyPort = u.getPort(); - - System.setProperty("http.proxyHost", proxyHost); - if (proxyPort > 0) - System.setProperty("http.proxyPort", String.valueOf(proxyPort)); - - final String userpass = u.getUserInfo(); - if (userpass != null && userpass.contains(":")) { - final int c = userpass.indexOf(':'); - final String user = userpass.substring(0, c); - final String pass = userpass.substring(c + 1); - AwtAuthenticator.add(new AwtAuthenticator.CachedAuthentication( - proxyHost, proxyPort, user, pass)); - } - } - /** * URL encode a value string into an output buffer. *