Browse Source

Use constants from StandardCharsets instead of hard-coded strings

Instead of hard-coding the charset strings "US-ASCII", "UTF-8", and
"ISO-8859-1", use the corresponding constants from StandardCharsets.

UnsupportedEncodingException is not thrown when the StandardCharset
constants are used, so remove the now redundant handling.

Because the encoding names are no longer hard-coded strings, also
remove redundant $NON-NLS warning suppressions.

Also replace existing usages of the constants with static imports.

Change-Id: I0a4510d3d992db5e277f009a41434276f95bda4e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
tags/v4.10.0.201712302008-r
David Pursehouse 6 years ago
parent
commit
171f84a041
36 changed files with 235 additions and 282 deletions
  1. 2
    2
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java
  2. 2
    1
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
  3. 4
    4
      org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/SignerV4.java
  4. 3
    2
      org.eclipse.jgit.lfs.test/src/org/eclipse/jgit/lfs/test/LongObjectIdTestUtils.java
  5. 2
    2
      org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java
  6. 2
    2
      org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LongObjectIdTest.java
  7. 5
    5
      org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java
  8. 4
    5
      org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/InvalidLongObjectIdException.java
  9. 5
    6
      org.eclipse.jgit.test/exttst/org/eclipse/jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java
  10. 2
    1
      org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java
  11. 5
    7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java
  12. 2
    1
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
  13. 2
    1
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
  14. 3
    2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
  15. 2
    7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java
  16. 16
    24
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java
  17. 4
    3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java
  18. 5
    4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
  19. 3
    2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
  20. 2
    3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java
  21. 3
    2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
  22. 9
    9
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
  23. 3
    4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java
  24. 35
    34
      org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java
  25. 40
    40
      org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java
  26. 4
    3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java
  27. 2
    8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java
  28. 17
    24
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawCharUtilTest.java
  29. 9
    10
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java
  30. 3
    8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java
  31. 2
    6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java
  32. 7
    7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java
  33. 3
    1
      org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java
  34. 5
    10
      org.eclipse.jgit/src/org/eclipse/jgit/transport/HMACSHA1NonceGenerator.java
  35. 10
    18
      org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java
  36. 8
    14
      org.eclipse.jgit/src/org/eclipse/jgit/util/Base64.java

+ 2
- 2
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java View File



package org.eclipse.jgit.http.test; package org.eclipse.jgit.http.test;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_ENCODING; import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_ENCODING;
import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_LENGTH; import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_LENGTH;
import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_TYPE; import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_TYPE;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
public void testInvalidWant() throws Exception { public void testInvalidWant() throws Exception {
@SuppressWarnings("resource") @SuppressWarnings("resource")
ObjectId id = new ObjectInserter.Formatter().idFor(Constants.OBJ_BLOB, ObjectId id = new ObjectInserter.Formatter().idFor(Constants.OBJ_BLOB,
"testInvalidWant".getBytes(StandardCharsets.UTF_8));
"testInvalidWant".getBytes(UTF_8));


Repository dst = createBareRepository(); Repository dst = createBareRepository();
try (Transport t = Transport.open(dst, remoteURI); try (Transport t = Transport.open(dst, remoteURI);

+ 2
- 1
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java View File



package org.eclipse.jgit.junit; package org.eclipse.jgit.junit;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;


* @throws Exception * @throws Exception
*/ */
public RevBlob blob(final String content) throws Exception { public RevBlob blob(final String content) throws Exception {
return blob(content.getBytes("UTF-8"));
return blob(content.getBytes(UTF_8));
} }


/** /**

+ 4
- 4
org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/SignerV4.java View File

*/ */
package org.eclipse.jgit.lfs.server.s3; package org.eclipse.jgit.lfs.server.s3;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.util.HttpSupport.HDR_AUTHORIZATION; import static org.eclipse.jgit.util.HttpSupport.HDR_AUTHORIZATION;


import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;


private static byte[] hash(String s) { private static byte[] hash(String s) {
MessageDigest md = Constants.newMessageDigest(); MessageDigest md = Constants.newMessageDigest();
md.update(s.getBytes(StandardCharsets.UTF_8));
md.update(s.getBytes(UTF_8));
return md.digest(); return md.digest();
} }


private static byte[] sign(String stringData, byte[] key) { private static byte[] sign(String stringData, byte[] key) {
try { try {
byte[] data = stringData.getBytes("UTF-8"); //$NON-NLS-1$
byte[] data = stringData.getBytes(UTF_8);
Mac mac = Mac.getInstance(HMACSHA256); Mac mac = Mac.getInstance(HMACSHA256);
mac.init(new SecretKeySpec(key, HMACSHA256)); mac.init(new SecretKeySpec(key, HMACSHA256));
return mac.doFinal(data); return mac.doFinal(data);
private static String urlEncode(String url, boolean keepPathSlash) { private static String urlEncode(String url, boolean keepPathSlash) {
String encoded; String encoded;
try { try {
encoded = URLEncoder.encode(url, StandardCharsets.UTF_8.name());
encoded = URLEncoder.encode(url, UTF_8.name());
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
throw new RuntimeException(LfsServerText.get().unsupportedUtf8, e); throw new RuntimeException(LfsServerText.get().unsupportedUtf8, e);
} }

+ 3
- 2
org.eclipse.jgit.lfs.test/src/org/eclipse/jgit/lfs/test/LongObjectIdTestUtils.java View File

*/ */
package org.eclipse.jgit.lfs.test; package org.eclipse.jgit.lfs.test;


import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.MessageDigest; import java.security.MessageDigest;
*/ */
public static LongObjectId hash(String s) { public static LongObjectId hash(String s) {
MessageDigest md = Constants.newMessageDigest(); MessageDigest md = Constants.newMessageDigest();
md.update(s.getBytes(StandardCharsets.UTF_8));
md.update(s.getBytes(UTF_8));
return LongObjectId.fromRaw(md.digest()); return LongObjectId.fromRaw(md.digest());
} }



+ 2
- 2
org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java View File



package org.eclipse.jgit.lfs.lib; package org.eclipse.jgit.lfs.lib;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;


import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;


import org.eclipse.jgit.lfs.LfsPointer; import org.eclipse.jgit.lfs.LfsPointer;
import org.junit.Test; import org.junit.Test;
baos.close(); baos.close();
assertEquals("version https://git-lfs.github.com/spec/v1\noid sha256:" assertEquals("version https://git-lfs.github.com/spec/v1\noid sha256:"
+ s + "\nsize 4\n", + s + "\nsize 4\n",
baos.toString(StandardCharsets.UTF_8.name()));
baos.toString(UTF_8.name()));
} }
} }

+ 2
- 2
org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LongObjectIdTest.java View File



package org.eclipse.jgit.lfs.lib; package org.eclipse.jgit.lfs.lib;


import static java.nio.charset.StandardCharsets.US_ASCII;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Locale; import java.util.Locale;
public void testCopyFromStringByte() { public void testCopyFromStringByte() {
AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test"); AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test");
byte[] buf = new byte[64]; byte[] buf = new byte[64];
Charset cs = StandardCharsets.US_ASCII;
Charset cs = US_ASCII;
cs.encode(id1.name()).get(buf); cs.encode(id1.name()).get(buf);
AnyLongObjectId id2 = LongObjectId.fromString(buf, 0); AnyLongObjectId id2 = LongObjectId.fromString(buf, 0);
assertEquals("objects should be equals", id1, id2); assertEquals("objects should be equals", id1, id2);

+ 5
- 5
org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java View File

*/ */
package org.eclipse.jgit.lfs; package org.eclipse.jgit.lfs;


import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException; import java.nio.charset.UnsupportedCharsetException;
import java.util.Locale; import java.util.Locale;


*/ */
public void encode(OutputStream out) { public void encode(OutputStream out) {
try (PrintStream ps = new PrintStream(out, false, try (PrintStream ps = new PrintStream(out, false,
StandardCharsets.UTF_8.name())) {
UTF_8.name())) {
ps.print("version "); //$NON-NLS-1$ ps.print("version "); //$NON-NLS-1$
ps.print(VERSION + "\n"); //$NON-NLS-1$ ps.print(VERSION + "\n"); //$NON-NLS-1$
ps.print("oid " + HASH_FUNCTION_NAME + ":"); //$NON-NLS-1$ //$NON-NLS-2$ ps.print("oid " + HASH_FUNCTION_NAME + ":"); //$NON-NLS-1$ //$NON-NLS-2$
ps.print(size + "\n"); //$NON-NLS-1$ ps.print(size + "\n"); //$NON-NLS-1$
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
// should not happen, we are using a standard charset // should not happen, we are using a standard charset
throw new UnsupportedCharsetException(
StandardCharsets.UTF_8.name());
throw new UnsupportedCharsetException(UTF_8.name());
} }
} }


long sz = -1; long sz = -1;


try (BufferedReader br = new BufferedReader( try (BufferedReader br = new BufferedReader(
new InputStreamReader(in, StandardCharsets.UTF_8.name()))) {
new InputStreamReader(in, UTF_8))) {
for (String s = br.readLine(); s != null; s = br.readLine()) { for (String s = br.readLine(); s != null; s = br.readLine()) {
if (s.startsWith("#") || s.length() == 0) { //$NON-NLS-1$ if (s.startsWith("#") || s.length() == 0) { //$NON-NLS-1$
continue; continue;

+ 4
- 5
org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/InvalidLongObjectIdException.java View File



package org.eclipse.jgit.lfs.errors; package org.eclipse.jgit.lfs.errors;


import java.io.UnsupportedEncodingException;
import static java.nio.charset.StandardCharsets.US_ASCII;

import java.text.MessageFormat; import java.text.MessageFormat;


import org.eclipse.jgit.lfs.internal.LfsText; import org.eclipse.jgit.lfs.internal.LfsText;


private static String asAscii(byte[] bytes, int offset, int length) { private static String asAscii(byte[] bytes, int offset, int length) {
try { try {
return new String(bytes, offset, length, "US-ASCII"); //$NON-NLS-1$
} catch (UnsupportedEncodingException e2) {
return ""; //$NON-NLS-1$
} catch (StringIndexOutOfBoundsException e2) {
return new String(bytes, offset, length, US_ASCII);
} catch (StringIndexOutOfBoundsException e) {
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
} }

+ 5
- 6
org.eclipse.jgit.test/exttst/org/eclipse/jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java View File

*/ */
package org.eclipse.jgit.ignore; package org.eclipse.jgit.ignore;


import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.util.Arrays; import java.util.Arrays;


private String pattern; private String pattern;


public CGitIgnoreRule(File gitDir, String pattern)
throws UnsupportedEncodingException, IOException {
public CGitIgnoreRule(File gitDir, String pattern) throws IOException {
this.gitDir = gitDir; this.gitDir = gitDir;
this.pattern = pattern; this.pattern = pattern;
Files.write(FileUtils.toPath(new File(gitDir, ".gitignore")), Files.write(FileUtils.toPath(new File(gitDir, ".gitignore")),
(pattern + "\n").getBytes("UTF-8"),
StandardOpenOption.CREATE,
(pattern + "\n").getBytes(UTF_8), StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.TRUNCATE_EXISTING,
StandardOpenOption.WRITE); StandardOpenOption.WRITE);
} }
Process proc = Runtime.getRuntime().exec(command, new String[0], Process proc = Runtime.getRuntime().exec(command, new String[0],
gitDir); gitDir);
OutputStream out = proc.getOutputStream(); OutputStream out = proc.getOutputStream();
out.write((path + "\n").getBytes("UTF-8"));
out.write((path + "\n").getBytes(UTF_8));
out.flush(); out.flush();
out.close(); out.close();
return proc; return proc;

+ 2
- 1
org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java View File



package org.eclipse.jgit.patch; package org.eclipse.jgit.patch;


import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
commitId = line.substring("commit ".length()); commitId = line.substring("commit ".length());
buf = new TemporaryBuffer.LocalFile(null); buf = new TemporaryBuffer.LocalFile(null);
} else if (buf != null) { } else if (buf != null) {
buf.write(line.getBytes("ISO-8859-1"));
buf.write(line.getBytes(ISO_8859_1));
buf.write('\n'); buf.write('\n');
} }
} }

+ 5
- 7
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java View File



package org.eclipse.jgit.api; package org.eclipse.jgit.api;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.AUTO_CRLF; import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.AUTO_CRLF;
import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.AUTO_LF; import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.AUTO_LF;
import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.DIRECT; import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.DIRECT;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;


import org.eclipse.jgit.lib.CoreConfig.EolStreamType; import org.eclipse.jgit.lib.CoreConfig.EolStreamType;
EolStreamType streamTypeWithBinaryCheck, String output, EolStreamType streamTypeWithBinaryCheck, String output,
String expectedConversion) throws Exception { String expectedConversion) throws Exception {
ByteArrayOutputStream b; ByteArrayOutputStream b;
byte[] outputBytes = output.getBytes(StandardCharsets.UTF_8);
byte[] expectedConversionBytes = expectedConversion
.getBytes(StandardCharsets.UTF_8);
byte[] outputBytes = output.getBytes(UTF_8);
byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8);


// test using output text and assuming it was declared TEXT // test using output text and assuming it was declared TEXT
b = new ByteArrayOutputStream(); b = new ByteArrayOutputStream();
private void testCheckin(EolStreamType streamTypeText, private void testCheckin(EolStreamType streamTypeText,
EolStreamType streamTypeWithBinaryCheck, String input, EolStreamType streamTypeWithBinaryCheck, String input,
String expectedConversion) throws Exception { String expectedConversion) throws Exception {
byte[] inputBytes = input.getBytes(StandardCharsets.UTF_8);
byte[] expectedConversionBytes = expectedConversion
.getBytes(StandardCharsets.UTF_8);
byte[] inputBytes = input.getBytes(UTF_8);
byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8);


// test using input text and assuming it was declared TEXT // test using input text and assuming it was declared TEXT
try (InputStream in = EolStreamTypeUtil.wrapInputStream( try (InputStream in = EolStreamTypeUtil.wrapInputStream(

+ 2
- 1
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java View File

*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
FileOutputStream fos = null; FileOutputStream fos = null;
try { try {
fos = new FileOutputStream(actFile); fos = new FileOutputStream(actFile);
fos.write(string.getBytes("UTF-8"));
fos.write(string.getBytes(UTF_8));
fos.close(); fos.close();
} finally { } finally {
if (fos != null) if (fos != null)

+ 2
- 1
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java View File

*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
FileOutputStream fos = null; FileOutputStream fos = null;
try { try {
fos = new FileOutputStream(actFile); fos = new FileOutputStream(actFile);
fos.write(string.getBytes("UTF-8"));
fos.write(string.getBytes(UTF_8));
fos.close(); fos.close();
} finally { } finally {
if (fos != null) if (fos != null)

+ 3
- 2
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java View File

*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
assertEquals("GIT_AUTHOR_DATE='@123456789 -0100'", lines[2]); assertEquals("GIT_AUTHOR_DATE='@123456789 -0100'", lines[2]);


PersonIdent parsedIdent = git.rebase().parseAuthor( PersonIdent parsedIdent = git.rebase().parseAuthor(
convertedAuthor.getBytes("UTF-8"));
convertedAuthor.getBytes(UTF_8));
assertEquals(ident.getName(), parsedIdent.getName()); assertEquals(ident.getName(), parsedIdent.getName());
assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress()); assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress());
// this is rounded to the last second // this is rounded to the last second
assertEquals("GIT_AUTHOR_DATE='@123456789 +0930'", lines[2]); assertEquals("GIT_AUTHOR_DATE='@123456789 +0930'", lines[2]);


parsedIdent = git.rebase().parseAuthor( parsedIdent = git.rebase().parseAuthor(
convertedAuthor.getBytes("UTF-8"));
convertedAuthor.getBytes(UTF_8));
assertEquals(ident.getName(), parsedIdent.getName()); assertEquals(ident.getName(), parsedIdent.getName());
assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress()); assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress());
assertEquals(123456789000L, parsedIdent.getWhen().getTime()); assertEquals(123456789000L, parsedIdent.getWhen().getTime());

+ 2
- 7
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java View File



package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;


import java.io.UnsupportedEncodingException;

import org.junit.Test; import org.junit.Test;


public abstract class AbstractDiffTestCase { public abstract class AbstractDiffTestCase {
r.append(text.charAt(i)); r.append(text.charAt(i));
r.append('\n'); r.append('\n');
} }
try {
return new RawText(r.toString().getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
return new RawText(r.toString().getBytes(UTF_8));
} }
} }

+ 16
- 24
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java View File



package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;


import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;


import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.util.RawParseUtils; import org.eclipse.jgit.util.RawParseUtils;
} }


@Test @Test
public void testComparatorReduceCommonStartEnd()
throws UnsupportedEncodingException {
public void testComparatorReduceCommonStartEnd() {
final RawTextComparator c = RawTextComparator.DEFAULT; final RawTextComparator c = RawTextComparator.DEFAULT;
Edit e; Edit e;


e = c.reduceCommonStartEnd(t("abQxy"), t("abRxy"), e); e = c.reduceCommonStartEnd(t("abQxy"), t("abRxy"), e);
assertEquals(new Edit(2, 3, 2, 3), e); assertEquals(new Edit(2, 3, 2, 3), e);


RawText a = new RawText("p\na b\nQ\nc d\n".getBytes("UTF-8"));
RawText b = new RawText("p\na b \nR\n c d \n".getBytes("UTF-8"));
RawText a = new RawText("p\na b\nQ\nc d\n".getBytes(UTF_8));
RawText b = new RawText("p\na b \nR\n c d \n".getBytes(UTF_8));
e = new Edit(0, 4, 0, 4); e = new Edit(0, 4, 0, 4);
e = RawTextComparator.WS_IGNORE_ALL.reduceCommonStartEnd(a, b, e); e = RawTextComparator.WS_IGNORE_ALL.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(2, 3, 2, 3), e); assertEquals(new Edit(2, 3, 2, 3), e);
} }


@Test @Test
public void testComparatorReduceCommonStartEnd_EmptyLine()
throws UnsupportedEncodingException {
public void testComparatorReduceCommonStartEnd_EmptyLine() {
RawText a; RawText a;
RawText b; RawText b;
Edit e; Edit e;


a = new RawText("R\n y\n".getBytes("UTF-8"));
b = new RawText("S\n\n y\n".getBytes("UTF-8"));
a = new RawText("R\n y\n".getBytes(UTF_8));
b = new RawText("S\n\n y\n".getBytes(UTF_8));
e = new Edit(0, 2, 0, 3); e = new Edit(0, 2, 0, 3);
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(0, 1, 0, 2), e); assertEquals(new Edit(0, 1, 0, 2), e);


a = new RawText("S\n\n y\n".getBytes("UTF-8"));
b = new RawText("R\n y\n".getBytes("UTF-8"));
a = new RawText("S\n\n y\n".getBytes(UTF_8));
b = new RawText("R\n y\n".getBytes(UTF_8));
e = new Edit(0, 3, 0, 2); e = new Edit(0, 3, 0, 2);
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(0, 2, 0, 1), e); assertEquals(new Edit(0, 2, 0, 1), e);
} }


@Test @Test
public void testComparatorReduceCommonStartButLastLineNoEol()
throws UnsupportedEncodingException {
public void testComparatorReduceCommonStartButLastLineNoEol() {
RawText a; RawText a;
RawText b; RawText b;
Edit e; Edit e;
a = new RawText("start".getBytes("UTF-8"));
b = new RawText("start of line".getBytes("UTF-8"));
a = new RawText("start".getBytes(UTF_8));
b = new RawText("start of line".getBytes(UTF_8));
e = new Edit(0, 1, 0, 1); e = new Edit(0, 1, 0, 1);
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(0, 1, 0, 1), e); assertEquals(new Edit(0, 1, 0, 1), e);
} }


@Test @Test
public void testComparatorReduceCommonStartButLastLineNoEol_2()
throws UnsupportedEncodingException {
public void testComparatorReduceCommonStartButLastLineNoEol_2() {
RawText a; RawText a;
RawText b; RawText b;
Edit e; Edit e;
a = new RawText("start".getBytes("UTF-8"));
b = new RawText("start of\nlastline".getBytes("UTF-8"));
a = new RawText("start".getBytes(UTF_8));
b = new RawText("start of\nlastline".getBytes(UTF_8));
e = new Edit(0, 1, 0, 2); e = new Edit(0, 1, 0, 2);
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(0, 1, 0, 2), e); assertEquals(new Edit(0, 1, 0, 2), e);
r.append(text.charAt(i)); r.append(text.charAt(i));
r.append('\n'); r.append('\n');
} }
try {
return new RawText(r.toString().getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
return new RawText(r.toString().getBytes(UTF_8));
} }
} }

+ 4
- 3
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java View File



package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;


+ "A\n" // + "A\n" //
+ "B\n" // + "B\n" //
+ "B\n" // + "B\n" //
+ "B\n").getBytes("UTF-8");
+ "B\n").getBytes(UTF_8);
SimilarityIndex si = new SimilarityIndex(); SimilarityIndex si = new SimilarityIndex();
si.hash(new ByteArrayInputStream(in), in.length, false); si.hash(new ByteArrayInputStream(in), in.length, false);
assertEquals(2, si.size()); assertEquals(2, si.size());
+ "D\r\n" // + "D\r\n" //
+ "B\r\n"; + "B\r\n";
SimilarityIndex src = new SimilarityIndex(); SimilarityIndex src = new SimilarityIndex();
byte[] bytes1 = text.getBytes("UTF-8");
byte[] bytes1 = text.getBytes(UTF_8);
src.hash(new ByteArrayInputStream(bytes1), bytes1.length, true); src.hash(new ByteArrayInputStream(bytes1), bytes1.length, true);
src.sort(); src.sort();


SimilarityIndex dst = new SimilarityIndex(); SimilarityIndex dst = new SimilarityIndex();
byte[] bytes2 = text.replace("\r", "").getBytes("UTF-8");
byte[] bytes2 = text.replace("\r", "").getBytes(UTF_8);
dst.hash(new ByteArrayInputStream(bytes2), bytes2.length, true); dst.hash(new ByteArrayInputStream(bytes2), bytes2.length, true);
dst.sort(); dst.sort();



+ 5
- 4
org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java View File

*/ */
package org.eclipse.jgit.gitrepo; package org.eclipse.jgit.gitrepo;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;


repos.put("platform/base", child); repos.put("platform/base", child);


RevCommit commit = cmd RevCommit commit = cmd
.setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(StandardCharsets.UTF_8)))
.setInputStream(new ByteArrayInputStream(
xmlContent.toString().getBytes(UTF_8)))
.setRemoteReader(repos) .setRemoteReader(repos)
.setURI("platform/") .setURI("platform/")
.setTargetURI("platform/superproject") .setTargetURI("platform/superproject")
repos.put("plugins/cookbook", child); repos.put("plugins/cookbook", child);


RevCommit commit = cmd RevCommit commit = cmd
.setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(StandardCharsets.UTF_8)))
.setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)))
.setRemoteReader(repos) .setRemoteReader(repos)
.setURI("") .setURI("")
.setTargetURI("gerrit") .setTargetURI("gerrit")
repos.put(repoUrl, child); repos.put(repoUrl, child);


RevCommit commit = cmd RevCommit commit = cmd
.setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(StandardCharsets.UTF_8)))
.setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)))
.setRemoteReader(repos) .setRemoteReader(repos)
.setURI(baseUrl) .setURI(baseUrl)
.setTargetURI("gerrit") .setTargetURI("gerrit")

+ 3
- 2
org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java View File

*/ */
package org.eclipse.jgit.ignore; package org.eclipse.jgit.ignore;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.junit.Assert.assertEquals; import static org.eclipse.jgit.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
writeTrashFile(name, data.toString()); writeTrashFile(name, data.toString());
} }


private InputStream writeToString(String... rules) throws IOException {
private InputStream writeToString(String... rules) {
StringBuilder data = new StringBuilder(); StringBuilder data = new StringBuilder();
for (String line : rules) { for (String line : rules) {
data.append(line + "\n"); data.append(line + "\n");
} }
return new ByteArrayInputStream(data.toString().getBytes("UTF-8"));
return new ByteArrayInputStream(data.toString().getBytes(UTF_8));
} }
} }

+ 2
- 3
org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java View File

*/ */
package org.eclipse.jgit.indexdiff; package org.eclipse.jgit.indexdiff;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import java.io.Writer; import java.io.Writer;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
File restoreScript = new File(testDir, name + ".sh"); File restoreScript = new File(testDir, name + ".sh");
try (OutputStream out = new BufferedOutputStream( try (OutputStream out = new BufferedOutputStream(
new FileOutputStream(restoreScript)); new FileOutputStream(restoreScript));
Writer writer = new OutputStreamWriter(out,
StandardCharsets.UTF_8)) {
Writer writer = new OutputStreamWriter(out, UTF_8)) {
writer.write("echo `which git` 1>&2\n"); writer.write("echo `which git` 1>&2\n");
writer.write("echo `git --version` 1>&2\n"); writer.write("echo `git --version` 1>&2\n");
writer.write("git init " + name + " && \\\n"); writer.write("git init " + name + " && \\\n");

+ 3
- 2
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java View File



package org.eclipse.jgit.internal.storage.file; package org.eclipse.jgit.internal.storage.file;


import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
} }


@Test @Test
public void test025_computeSha1NoStore() throws IOException {
public void test025_computeSha1NoStore() {
byte[] data = "test025 some data, more than 16 bytes to get good coverage" byte[] data = "test025 some data, more than 16 bytes to get good coverage"
.getBytes("ISO-8859-1");
.getBytes(ISO_8859_1);
try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) { try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) {
final ObjectId id = formatter.idFor(Constants.OBJ_BLOB, data); final ObjectId id = formatter.idFor(Constants.OBJ_BLOB, data);
assertEquals("4f561df5ecf0dfbd53a0dc0f37262fef075d9dde", id.name()); assertEquals("4f561df5ecf0dfbd53a0dc0f37262fef075d9dde", id.name());

+ 9
- 9
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java View File

package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;


import static java.lang.Integer.valueOf; import static java.lang.Integer.valueOf;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.junit.JGitTestUtil.concat; import static org.eclipse.jgit.junit.JGitTestUtil.concat;
import static org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH; import static org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH;
import static org.eclipse.jgit.lib.Constants.OBJ_BAD; import static org.eclipse.jgit.lib.Constants.OBJ_BAD;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;


import java.io.UnsupportedEncodingException;
import java.text.MessageFormat; import java.text.MessageFormat;


import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.CorruptObjectException;


@Test @Test
public void testInvalidTreeDuplicateNames5() public void testInvalidTreeDuplicateNames5()
throws UnsupportedEncodingException, CorruptObjectException {
throws CorruptObjectException {
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
entry(b, "100644 A"); entry(b, "100644 A");
entry(b, "100644 a"); entry(b, "100644 a");
byte[] data = b.toString().getBytes("UTF-8");
byte[] data = b.toString().getBytes(UTF_8);
checker.setSafeForWindows(true); checker.setSafeForWindows(true);
assertCorrupt("duplicate entry names", OBJ_TREE, data); assertCorrupt("duplicate entry names", OBJ_TREE, data);
assertSkipListAccepts(OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data);


@Test @Test
public void testInvalidTreeDuplicateNames6() public void testInvalidTreeDuplicateNames6()
throws UnsupportedEncodingException, CorruptObjectException {
throws CorruptObjectException {
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
entry(b, "100644 A"); entry(b, "100644 A");
entry(b, "100644 a"); entry(b, "100644 a");
byte[] data = b.toString().getBytes("UTF-8");
byte[] data = b.toString().getBytes(UTF_8);
checker.setSafeForMacOS(true); checker.setSafeForMacOS(true);
assertCorrupt("duplicate entry names", OBJ_TREE, data); assertCorrupt("duplicate entry names", OBJ_TREE, data);
assertSkipListAccepts(OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data);


@Test @Test
public void testInvalidTreeDuplicateNames7() public void testInvalidTreeDuplicateNames7()
throws UnsupportedEncodingException, CorruptObjectException {
throws CorruptObjectException {
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
entry(b, "100644 \u0065\u0301"); entry(b, "100644 \u0065\u0301");
entry(b, "100644 \u00e9"); entry(b, "100644 \u00e9");
byte[] data = b.toString().getBytes("UTF-8");
byte[] data = b.toString().getBytes(UTF_8);
checker.setSafeForMacOS(true); checker.setSafeForMacOS(true);
assertCorrupt("duplicate entry names", OBJ_TREE, data); assertCorrupt("duplicate entry names", OBJ_TREE, data);
assertSkipListAccepts(OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data);


@Test @Test
public void testInvalidTreeDuplicateNames8() public void testInvalidTreeDuplicateNames8()
throws UnsupportedEncodingException, CorruptObjectException {
throws CorruptObjectException {
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
entry(b, "100644 A"); entry(b, "100644 A");
checker.setSafeForMacOS(true); checker.setSafeForMacOS(true);
checker.checkTree(b.toString().getBytes("UTF-8"));
checker.checkTree(b.toString().getBytes(UTF_8));
} }


@Test @Test

+ 3
- 4
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java View File

import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;


import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
} }
binary[50] = '\0'; binary[50] = '\0';


writeTrashFile("file", new String(binary, StandardCharsets.UTF_8));
writeTrashFile("file", new String(binary, UTF_8));
git.add().addFilepattern("file").call(); git.add().addFilepattern("file").call();
RevCommit first = git.commit().setMessage("added file").call(); RevCommit first = git.commit().setMessage("added file").call();


int idx = LINELEN * 1200 + 1; int idx = LINELEN * 1200 + 1;
byte save = binary[idx]; byte save = binary[idx];
binary[idx] = '@'; binary[idx] = '@';
writeTrashFile("file", new String(binary, StandardCharsets.UTF_8));
writeTrashFile("file", new String(binary, UTF_8));


binary[idx] = save; binary[idx] = save;
git.add().addFilepattern("file").call(); git.add().addFilepattern("file").call();


git.checkout().setCreateBranch(true).setStartPoint(first).setName("side").call(); git.checkout().setCreateBranch(true).setStartPoint(first).setName("side").call();
binary[LINELEN * 1500 + 1] = '!'; binary[LINELEN * 1500 + 1] = '!';
writeTrashFile("file", new String(binary, StandardCharsets.UTF_8));
writeTrashFile("file", new String(binary, UTF_8));
git.add().addFilepattern("file").call(); git.add().addFilepattern("file").call();
RevCommit sideCommit = git.commit().setAll(true) RevCommit sideCommit = git.commit().setAll(true)
.setMessage("modified file l 1500").call(); .setMessage("modified file l 1500").call();

+ 35
- 34
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java View File



package org.eclipse.jgit.revwalk; package org.eclipse.jgit.revwalk;


import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
assertNull(c.getTree()); assertNull(c.getTree());
assertNull(c.parents); assertNull(c.parents);


c.parseCanonical(rw, body.toString().getBytes("UTF-8"));
c.parseCanonical(rw, body.toString().getBytes(UTF_8));
assertNotNull(c.getTree()); assertNotNull(c.getTree());
assertEquals(treeId, c.getTree().getId()); assertEquals(treeId, c.getTree().getId());
assertSame(rw.lookupTree(treeId), c.getTree()); assertSame(rw.lookupTree(treeId), c.getTree());


final RevCommit c; final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toString().getBytes("UTF-8"));
c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
return c; return c;
} }




final RevCommit c; final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toString().getBytes("UTF-8"));
c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));


assertEquals("", c.getFullMessage()); assertEquals("", c.getFullMessage());
assertEquals("", c.getShortMessage()); assertEquals("", c.getShortMessage());


final RevCommit c; final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toString().getBytes("UTF-8"));
c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));


assertEquals(new PersonIdent("", "a_u_thor@example.com", 1218123387000l, 7), c.getAuthorIdent()); assertEquals(new PersonIdent("", "a_u_thor@example.com", 1218123387000l, 7), c.getAuthorIdent());
assertEquals(new PersonIdent("", "", 1218123390000l, -5), c.getCommitterIdent()); assertEquals(new PersonIdent("", "", 1218123390000l, -5), c.getCommitterIdent());
@Test @Test
public void testParse_implicit_UTF8_encoded() throws Exception { public void testParse_implicit_UTF8_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream(); final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8"));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes("UTF-8"));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes("UTF-8"));
b.write("\n".getBytes("UTF-8"));
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes("UTF-8"));
b.write("\n".getBytes("UTF-8"));
b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(UTF_8));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
final RevCommit c; final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
c.parseCanonical(new RevWalk(db), b.toByteArray()); c.parseCanonical(new RevWalk(db), b.toByteArray());
@Test @Test
public void testParse_implicit_mixed_encoded() throws Exception { public void testParse_implicit_mixed_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream(); final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8"));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes("ISO-8859-1"));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes("UTF-8"));
b.write("\n".getBytes("UTF-8"));
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes("UTF-8"));
b.write("\n".getBytes("UTF-8"));
b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(ISO_8859_1));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
final RevCommit c; final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
c.parseCanonical(new RevWalk(db), b.toByteArray()); c.parseCanonical(new RevWalk(db), b.toByteArray());
@Test @Test
public void testParse_explicit_bad_encoded() throws Exception { public void testParse_explicit_bad_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream(); final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8"));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes("ISO-8859-1"));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes("UTF-8"));
b.write("encoding EUC-JP\n".getBytes("UTF-8"));
b.write("\n".getBytes("UTF-8"));
b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
b.write("\n".getBytes("UTF-8"));
b.write("Hi\n".getBytes("UTF-8"));
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(ISO_8859_1));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
b.write("encoding EUC-JP\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("Hi\n".getBytes(UTF_8));
final RevCommit c; final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
c.parseCanonical(new RevWalk(db), b.toByteArray()); c.parseCanonical(new RevWalk(db), b.toByteArray());
@Test @Test
public void testParse_explicit_bad_encoded2() throws Exception { public void testParse_explicit_bad_encoded2() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream(); final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8"));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes("UTF-8"));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes("UTF-8"));
b.write("encoding ISO-8859-1\n".getBytes("UTF-8"));
b.write("\n".getBytes("UTF-8"));
b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
b.write("\n".getBytes("UTF-8"));
b.write("Hi\n".getBytes("UTF-8"));
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(UTF_8));
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
b.write("encoding ISO-8859-1\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("Hi\n".getBytes(UTF_8));
final RevCommit c; final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
c.parseCanonical(new RevWalk(db), b.toByteArray()); c.parseCanonical(new RevWalk(db), b.toByteArray());

+ 40
- 40
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java View File



package org.eclipse.jgit.revwalk; package org.eclipse.jgit.revwalk;


import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
assertNull(c.getObject()); assertNull(c.getObject());
assertNull(c.getTagName()); assertNull(c.getTagName());


c.parseCanonical(rw, b.toString().getBytes("UTF-8"));
c.parseCanonical(rw, b.toString().getBytes(UTF_8));
assertNotNull(c.getObject()); assertNotNull(c.getObject());
assertEquals(id, c.getObject().getId()); assertEquals(id, c.getObject().getId());
assertSame(rw.lookupAny(id, typeCode), c.getObject()); assertSame(rw.lookupAny(id, typeCode), c.getObject());
assertNull(c.getObject()); assertNull(c.getObject());
assertNull(c.getTagName()); assertNull(c.getTagName());


c.parseCanonical(rw, body.toString().getBytes("UTF-8"));
c.parseCanonical(rw, body.toString().getBytes(UTF_8));
assertNotNull(c.getObject()); assertNotNull(c.getObject());
assertEquals(treeId, c.getObject().getId()); assertEquals(treeId, c.getObject().getId());
assertSame(rw.lookupTree(treeId), c.getObject()); assertSame(rw.lookupTree(treeId), c.getObject());
assertNull(c.getObject()); assertNull(c.getObject());
assertNull(c.getTagName()); assertNull(c.getTagName());


c.parseCanonical(rw, body.toString().getBytes("UTF-8"));
c.parseCanonical(rw, body.toString().getBytes(UTF_8));
assertNotNull(c.getObject()); assertNotNull(c.getObject());
assertEquals(treeId, c.getObject().getId()); assertEquals(treeId, c.getObject().getId());
assertSame(rw.lookupTree(treeId), c.getObject()); assertSame(rw.lookupTree(treeId), c.getObject());


final RevTag c; final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toString().getBytes("UTF-8"));
c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
return c; return c;
} }


public void testParse_implicit_UTF8_encoded() throws Exception { public void testParse_implicit_UTF8_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream(); final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
.getBytes("UTF-8"));
b.write("type tree\n".getBytes("UTF-8"));
b.write("tag v1.2.3.4.5\n".getBytes("UTF-8"));
.getBytes(UTF_8));
b.write("type tree\n".getBytes(UTF_8));
b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));


b b
.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n" .write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
.getBytes("UTF-8"));
b.write("\n".getBytes("UTF-8"));
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes("UTF-8"));
b.write("\n".getBytes("UTF-8"));
b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
.getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
final RevTag c; final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toByteArray()); c.parseCanonical(new RevWalk(db), b.toByteArray());
public void testParse_implicit_mixed_encoded() throws Exception { public void testParse_implicit_mixed_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream(); final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
.getBytes("UTF-8"));
b.write("type tree\n".getBytes("UTF-8"));
b.write("tag v1.2.3.4.5\n".getBytes("UTF-8"));
b
.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
.getBytes("ISO-8859-1"));
b.write("\n".getBytes("UTF-8"));
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes("UTF-8"));
b.write("\n".getBytes("UTF-8"));
b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
.getBytes(UTF_8));
b.write("type tree\n".getBytes(UTF_8));
b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
b.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
.getBytes(ISO_8859_1));
b.write("\n".getBytes(UTF_8));
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
final RevTag c; final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toByteArray()); c.parseCanonical(new RevWalk(db), b.toByteArray());
public void testParse_explicit_bad_encoded() throws Exception { public void testParse_explicit_bad_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream(); final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
.getBytes("UTF-8"));
b.write("type tree\n".getBytes("UTF-8"));
b.write("tag v1.2.3.4.5\n".getBytes("UTF-8"));
.getBytes(UTF_8));
b.write("type tree\n".getBytes(UTF_8));
b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
b b
.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n" .write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
.getBytes("ISO-8859-1"));
b.write("encoding EUC-JP\n".getBytes("UTF-8"));
b.write("\n".getBytes("UTF-8"));
b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
b.write("\n".getBytes("UTF-8"));
b.write("Hi\n".getBytes("UTF-8"));
.getBytes(ISO_8859_1));
b.write("encoding EUC-JP\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("Hi\n".getBytes(UTF_8));
final RevTag c; final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toByteArray()); c.parseCanonical(new RevWalk(db), b.toByteArray());
public void testParse_explicit_bad_encoded2() throws Exception { public void testParse_explicit_bad_encoded2() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream(); final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
.getBytes("UTF-8"));
b.write("type tree\n".getBytes("UTF-8"));
b.write("tag v1.2.3.4.5\n".getBytes("UTF-8"));
.getBytes(UTF_8));
b.write("type tree\n".getBytes(UTF_8));
b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
b b
.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n" .write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
.getBytes("UTF-8"));
b.write("encoding ISO-8859-1\n".getBytes("UTF-8"));
b.write("\n".getBytes("UTF-8"));
b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
b.write("\n".getBytes("UTF-8"));
b.write("Hi\n".getBytes("UTF-8"));
.getBytes(UTF_8));
b.write("encoding ISO-8859-1\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
b.write("\n".getBytes(UTF_8));
b.write("Hi\n".getBytes(UTF_8));
final RevTag c; final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toByteArray()); c.parseCanonical(new RevWalk(db), b.toByteArray());

+ 4
- 3
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java View File

*/ */
package org.eclipse.jgit.storage.file; package org.eclipse.jgit.storage.file;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.util.FileUtils.pathToString; import static org.eclipse.jgit.util.FileUtils.pathToString;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;


@Test @Test
public void testUTF8withoutBOM() throws IOException, ConfigInvalidException { public void testUTF8withoutBOM() throws IOException, ConfigInvalidException {
final File file = createFile(CONTENT1.getBytes("UTF-8"));
final File file = createFile(CONTENT1.getBytes(UTF_8));
final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED); final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
config.load(); config.load();
assertEquals(ALICE, config.getString(USER, null, NAME)); assertEquals(ALICE, config.getString(USER, null, NAME));
bos1.write(0xEF); bos1.write(0xEF);
bos1.write(0xBB); bos1.write(0xBB);
bos1.write(0xBF); bos1.write(0xBF);
bos1.write(CONTENT1.getBytes("UTF-8"));
bos1.write(CONTENT1.getBytes(UTF_8));


final File file = createFile(bos1.toByteArray()); final File file = createFile(bos1.toByteArray());
final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED); final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
bos2.write(0xEF); bos2.write(0xEF);
bos2.write(0xBB); bos2.write(0xBB);
bos2.write(0xBF); bos2.write(0xBF);
bos2.write(CONTENT2.getBytes("UTF-8"));
bos2.write(CONTENT2.getBytes(UTF_8));
assertArrayEquals(bos2.toByteArray(), IO.readFully(file)); assertArrayEquals(bos2.toByteArray(), IO.readFully(file));
} }



+ 2
- 8
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java View File



package org.eclipse.jgit.util; package org.eclipse.jgit.util;


import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static org.eclipse.jgit.util.QuotedString.GIT_PATH; import static org.eclipse.jgit.util.QuotedString.GIT_PATH;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;


import java.io.UnsupportedEncodingException;

import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.junit.Test; import org.junit.Test;


} }


private static void assertDequote(final String exp, final String in) { private static void assertDequote(final String exp, final String in) {
final byte[] b;
try {
b = ('"' + in + '"').getBytes("ISO-8859-1");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
final byte[] b = ('"' + in + '"').getBytes(ISO_8859_1);
final String r = GIT_PATH.dequote(b, 0, b.length); final String r = GIT_PATH.dequote(b, 0, b.length);
assertEquals(exp, r); assertEquals(exp, r);
} }

+ 17
- 24
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawCharUtilTest.java View File



package org.eclipse.jgit.util; package org.eclipse.jgit.util;


import static java.nio.charset.StandardCharsets.US_ASCII;
import static org.eclipse.jgit.util.RawCharUtil.isWhitespace; import static org.eclipse.jgit.util.RawCharUtil.isWhitespace;
import static org.eclipse.jgit.util.RawCharUtil.trimLeadingWhitespace; import static org.eclipse.jgit.util.RawCharUtil.trimLeadingWhitespace;
import static org.eclipse.jgit.util.RawCharUtil.trimTrailingWhitespace; import static org.eclipse.jgit.util.RawCharUtil.trimTrailingWhitespace;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;


import java.io.UnsupportedEncodingException;

import org.junit.Test; import org.junit.Test;


public class RawCharUtilTest { public class RawCharUtilTest {
/** /**
* Test method for * Test method for
* {@link RawCharUtil#trimTrailingWhitespace(byte[], int, int)}. * {@link RawCharUtil#trimTrailingWhitespace(byte[], int, int)}.
*
* @throws UnsupportedEncodingException
*/ */
@Test @Test
public void testTrimTrailingWhitespace()
throws UnsupportedEncodingException {
assertEquals(0, trimTrailingWhitespace("".getBytes("US-ASCII"), 0, 0));
assertEquals(0, trimTrailingWhitespace(" ".getBytes("US-ASCII"), 0, 1));
assertEquals(1, trimTrailingWhitespace("a ".getBytes("US-ASCII"), 0, 2));
assertEquals(2,
trimTrailingWhitespace(" a ".getBytes("US-ASCII"), 0, 3));
assertEquals(3,
trimTrailingWhitespace(" a".getBytes("US-ASCII"), 0, 3));
assertEquals(6, trimTrailingWhitespace(
" test ".getBytes("US-ASCII"), 2, 9));
public void testTrimTrailingWhitespace() {
assertEquals(0, trimTrailingWhitespace("".getBytes(US_ASCII), 0, 0));
assertEquals(0, trimTrailingWhitespace(" ".getBytes(US_ASCII), 0, 1));
assertEquals(1, trimTrailingWhitespace("a ".getBytes(US_ASCII), 0, 2));
assertEquals(2, trimTrailingWhitespace(" a ".getBytes(US_ASCII), 0, 3));
assertEquals(3, trimTrailingWhitespace(" a".getBytes(US_ASCII), 0, 3));
assertEquals(6,
trimTrailingWhitespace(" test ".getBytes(US_ASCII), 2, 9));
} }


/** /**
* Test method for * Test method for
* {@link RawCharUtil#trimLeadingWhitespace(byte[], int, int)}. * {@link RawCharUtil#trimLeadingWhitespace(byte[], int, int)}.
*
* @throws UnsupportedEncodingException
*/ */
@Test @Test
public void testTrimLeadingWhitespace() throws UnsupportedEncodingException {
assertEquals(0, trimLeadingWhitespace("".getBytes("US-ASCII"), 0, 0));
assertEquals(1, trimLeadingWhitespace(" ".getBytes("US-ASCII"), 0, 1));
assertEquals(0, trimLeadingWhitespace("a ".getBytes("US-ASCII"), 0, 2));
assertEquals(1, trimLeadingWhitespace(" a ".getBytes("US-ASCII"), 0, 3));
assertEquals(2, trimLeadingWhitespace(" a".getBytes("US-ASCII"), 0, 3));
assertEquals(2, trimLeadingWhitespace(" test ".getBytes("US-ASCII"),
public void testTrimLeadingWhitespace() {
assertEquals(0, trimLeadingWhitespace("".getBytes(US_ASCII), 0, 0));
assertEquals(1, trimLeadingWhitespace(" ".getBytes(US_ASCII), 0, 1));
assertEquals(0, trimLeadingWhitespace("a ".getBytes(US_ASCII), 0, 2));
assertEquals(1, trimLeadingWhitespace(" a ".getBytes(US_ASCII), 0, 3));
assertEquals(2, trimLeadingWhitespace(" a".getBytes(US_ASCII), 0, 3));
assertEquals(2,
trimLeadingWhitespace(" test ".getBytes(US_ASCII),
2, 9)); 2, 9));
} }



+ 9
- 10
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java View File



package org.eclipse.jgit.util; package org.eclipse.jgit.util;


import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;


import java.io.UnsupportedEncodingException;

import org.junit.Test; import org.junit.Test;


public class RawParseUtils_LineMapTest { public class RawParseUtils_LineMapTest {
} }


@Test @Test
public void testTwoLineFooBar() throws UnsupportedEncodingException {
final byte[] buf = "foo\nbar\n".getBytes("ISO-8859-1");
public void testTwoLineFooBar() {
final byte[] buf = "foo\nbar\n".getBytes(ISO_8859_1);
final IntList map = RawParseUtils.lineMap(buf, 0, buf.length); final IntList map = RawParseUtils.lineMap(buf, 0, buf.length);
assertArrayEquals(new int[]{Integer.MIN_VALUE, 0, 4, buf.length}, asInts(map)); assertArrayEquals(new int[]{Integer.MIN_VALUE, 0, 4, buf.length}, asInts(map));
} }


@Test @Test
public void testTwoLineNoLF() throws UnsupportedEncodingException {
final byte[] buf = "foo\nbar".getBytes("ISO-8859-1");
public void testTwoLineNoLF() {
final byte[] buf = "foo\nbar".getBytes(ISO_8859_1);
final IntList map = RawParseUtils.lineMap(buf, 0, buf.length); final IntList map = RawParseUtils.lineMap(buf, 0, buf.length);
assertArrayEquals(new int[]{Integer.MIN_VALUE, 0, 4, buf.length}, asInts(map)); assertArrayEquals(new int[]{Integer.MIN_VALUE, 0, 4, buf.length}, asInts(map));
} }


@Test @Test
public void testBinary() throws UnsupportedEncodingException {
final byte[] buf = "xxxfoo\nb\0ar".getBytes("ISO-8859-1");
public void testBinary() {
final byte[] buf = "xxxfoo\nb\0ar".getBytes(ISO_8859_1);
final IntList map = RawParseUtils.lineMap(buf, 3, buf.length); final IntList map = RawParseUtils.lineMap(buf, 3, buf.length);
assertArrayEquals(new int[]{Integer.MIN_VALUE, 3, buf.length}, asInts(map)); assertArrayEquals(new int[]{Integer.MIN_VALUE, 3, buf.length}, asInts(map));
} }


@Test @Test
public void testFourLineBlanks() throws UnsupportedEncodingException {
final byte[] buf = "foo\n\n\nbar\n".getBytes("ISO-8859-1");
public void testFourLineBlanks() {
final byte[] buf = "foo\n\n\nbar\n".getBytes(ISO_8859_1);
final IntList map = RawParseUtils.lineMap(buf, 0, buf.length); final IntList map = RawParseUtils.lineMap(buf, 0, buf.length);


assertArrayEquals(new int[]{ assertArrayEquals(new int[]{

+ 3
- 8
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java View File

*/ */
package org.eclipse.jgit.util; package org.eclipse.jgit.util;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;


import java.io.UnsupportedEncodingException;

import org.eclipse.jgit.junit.RepositoryTestCase; import org.eclipse.jgit.junit.RepositoryTestCase;
import org.junit.Test; import org.junit.Test;


} }


private static RawCharSequence raw(String text) { private static RawCharSequence raw(String text) {
try {
byte[] bytes = text.getBytes("UTF-8");
return new RawCharSequence(bytes, 0, bytes.length);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
byte[] bytes = text.getBytes(UTF_8);
return new RawCharSequence(bytes, 0, bytes.length);
} }
} }

+ 2
- 6
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java View File



package org.eclipse.jgit.util.io; package org.eclipse.jgit.util.io;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;


import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException;


import org.junit.Test; import org.junit.Test;


} }


private static byte[] asBytes(String in) { private static byte[] asBytes(String in) {
try {
return in.getBytes("UTF-8");
} catch (UnsupportedEncodingException ex) {
throw new AssertionError();
}
return in.getBytes(UTF_8);
} }
} }

+ 7
- 7
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java View File



package org.eclipse.jgit.util.sha1; package org.eclipse.jgit.util.sha1;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;


.fromString("a9993e364706816aba3e25717850c26c9cd0d89d"); .fromString("a9993e364706816aba3e25717850c26c9cd0d89d");


MessageDigest m = MessageDigest.getInstance("SHA-1"); MessageDigest m = MessageDigest.getInstance("SHA-1");
m.update(TEST1.getBytes(StandardCharsets.UTF_8));
m.update(TEST1.getBytes(UTF_8));
ObjectId m1 = ObjectId.fromRaw(m.digest()); ObjectId m1 = ObjectId.fromRaw(m.digest());


SHA1 s = SHA1.newInstance(); SHA1 s = SHA1.newInstance();
s.update(TEST1.getBytes(StandardCharsets.UTF_8));
s.update(TEST1.getBytes(UTF_8));
ObjectId s1 = ObjectId.fromRaw(s.digest()); ObjectId s1 = ObjectId.fromRaw(s.digest());


s.reset(); s.reset();
s.update(TEST1.getBytes(StandardCharsets.UTF_8));
s.update(TEST1.getBytes(UTF_8));
ObjectId s2 = s.toObjectId(); ObjectId s2 = s.toObjectId();


assertEquals(m1, s1); assertEquals(m1, s1);
.fromString("84983e441c3bd26ebaae4aa1f95129e5e54670f1"); .fromString("84983e441c3bd26ebaae4aa1f95129e5e54670f1");


MessageDigest m = MessageDigest.getInstance("SHA-1"); MessageDigest m = MessageDigest.getInstance("SHA-1");
m.update(TEST2.getBytes(StandardCharsets.UTF_8));
m.update(TEST2.getBytes(UTF_8));
ObjectId m1 = ObjectId.fromRaw(m.digest()); ObjectId m1 = ObjectId.fromRaw(m.digest());


SHA1 s = SHA1.newInstance(); SHA1 s = SHA1.newInstance();
s.update(TEST2.getBytes(StandardCharsets.UTF_8));
s.update(TEST2.getBytes(UTF_8));
ObjectId s1 = ObjectId.fromRaw(s.digest()); ObjectId s1 = ObjectId.fromRaw(s.digest());


s.reset(); s.reset();
s.update(TEST2.getBytes(StandardCharsets.UTF_8));
s.update(TEST2.getBytes(UTF_8));
ObjectId s2 = s.toObjectId(); ObjectId s2 = s.toObjectId();


assertEquals(m1, s1); assertEquals(m1, s1);

+ 3
- 1
org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java View File



package org.eclipse.jgit.transport; package org.eclipse.jgit.transport;


import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
try { try {
final Mac m = Mac.getInstance(HMAC); final Mac m = Mac.getInstance(HMAC);
m.init(privateKey); m.init(privateKey);
sec = Base64.encodeBytes(m.doFinal(s.toString().getBytes("UTF-8"))); //$NON-NLS-1$
sec = Base64.encodeBytes(m.doFinal(s.toString().getBytes(UTF_8)));
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new IOException(MessageFormat.format(JGitText.get().noHMACsupport, HMAC, e.getMessage())); throw new IOException(MessageFormat.format(JGitText.get().noHMACsupport, HMAC, e.getMessage()));
} catch (InvalidKeyException e) { } catch (InvalidKeyException e) {

+ 5
- 10
org.eclipse.jgit/src/org/eclipse/jgit/transport/HMACSHA1NonceGenerator.java View File

*/ */
package org.eclipse.jgit.transport; package org.eclipse.jgit.transport;


import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.File; import java.io.File;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;


*/ */
public HMACSHA1NonceGenerator(String seed) throws IllegalStateException { public HMACSHA1NonceGenerator(String seed) throws IllegalStateException {
try { try {
byte[] keyBytes = seed.getBytes("ISO-8859-1"); //$NON-NLS-1$
byte[] keyBytes = seed.getBytes(ISO_8859_1);
SecretKeySpec signingKey = new SecretKeySpec(keyBytes, "HmacSHA1"); //$NON-NLS-1$ SecretKeySpec signingKey = new SecretKeySpec(keyBytes, "HmacSHA1"); //$NON-NLS-1$
mac = Mac.getInstance("HmacSHA1"); //$NON-NLS-1$ mac = Mac.getInstance("HmacSHA1"); //$NON-NLS-1$
mac.init(signingKey); mac.init(signingKey);
throw new IllegalStateException(e); throw new IllegalStateException(e);
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
} }
} }


} }


String input = path + ":" + String.valueOf(timestamp); //$NON-NLS-1$ String input = path + ":" + String.valueOf(timestamp); //$NON-NLS-1$
byte[] rawHmac;
try {
rawHmac = mac.doFinal(input.getBytes("UTF-8")); //$NON-NLS-1$
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
byte[] rawHmac = mac.doFinal(input.getBytes(UTF_8));
return Long.toString(timestamp) + "-" + toHex(rawHmac); //$NON-NLS-1$ return Long.toString(timestamp) + "-" + toHex(rawHmac); //$NON-NLS-1$
} }



+ 10
- 18
org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java View File



package org.eclipse.jgit.transport; package org.eclipse.jgit.transport;


import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.util.HttpSupport.HDR_AUTHORIZATION; import static org.eclipse.jgit.util.HttpSupport.HDR_AUTHORIZATION;
import static org.eclipse.jgit.util.HttpSupport.HDR_WWW_AUTHENTICATE; import static org.eclipse.jgit.util.HttpSupport.HDR_WWW_AUTHENTICATE;


import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL; import java.net.URL;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@Override @Override
void configureRequest(final HttpConnection conn) throws IOException { void configureRequest(final HttpConnection conn) throws IOException {
String ident = user + ":" + pass; //$NON-NLS-1$ String ident = user + ":" + pass; //$NON-NLS-1$
String enc = Base64.encodeBytes(ident.getBytes("UTF-8")); //$NON-NLS-1$
String enc = Base64.encodeBytes(ident.getBytes(UTF_8));
conn.setRequestProperty(HDR_AUTHORIZATION, type.getSchemeName() conn.setRequestProperty(HDR_AUTHORIZATION, type.getSchemeName()
+ " " + enc); //$NON-NLS-1$ + " " + enc); //$NON-NLS-1$
} }
} }


private static String H(String data) { private static String H(String data) {
try {
MessageDigest md = newMD5();
md.update(data.getBytes("UTF-8")); //$NON-NLS-1$
return LHEX(md.digest());
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("UTF-8 encoding not available", e); //$NON-NLS-1$
}
MessageDigest md = newMD5();
md.update(data.getBytes(UTF_8));
return LHEX(md.digest());
} }


private static String KD(String secret, String data) { private static String KD(String secret, String data) {
try {
MessageDigest md = newMD5();
md.update(secret.getBytes("UTF-8")); //$NON-NLS-1$
md.update((byte) ':');
md.update(data.getBytes("UTF-8")); //$NON-NLS-1$
return LHEX(md.digest());
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("UTF-8 encoding not available", e); //$NON-NLS-1$
}
MessageDigest md = newMD5();
md.update(secret.getBytes(UTF_8));
md.update((byte) ':');
md.update(data.getBytes(UTF_8));
return LHEX(md.digest());
} }


private static MessageDigest newMD5() { private static MessageDigest newMD5() {

+ 8
- 14
org.eclipse.jgit/src/org/eclipse/jgit/util/Base64.java View File



package org.eclipse.jgit.util; package org.eclipse.jgit.util;


import java.io.UnsupportedEncodingException;
import static java.nio.charset.StandardCharsets.UTF_8;

import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Arrays; import java.util.Arrays;
/** Indicates an invalid byte during decoding. */ /** Indicates an invalid byte during decoding. */
private final static byte INVALID_DEC = -3; private final static byte INVALID_DEC = -3;


/** Preferred encoding. */
private final static String UTF_8 = "UTF-8"; //$NON-NLS-1$

/** The 64 valid Base64 values. */ /** The 64 valid Base64 values. */
private final static byte[] ENC; private final static byte[] ENC;


private final static byte[] DEC; private final static byte[] DEC;


static { static {
try {
ENC = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" // //$NON-NLS-1$
+ "abcdefghijklmnopqrstuvwxyz" // //$NON-NLS-1$
+ "0123456789" // //$NON-NLS-1$
+ "+/" // //$NON-NLS-1$
).getBytes(UTF_8);
} catch (UnsupportedEncodingException uee) {
throw new RuntimeException(uee.getMessage(), uee);
}
ENC = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" // //$NON-NLS-1$
+ "abcdefghijklmnopqrstuvwxyz" // //$NON-NLS-1$
+ "0123456789" // //$NON-NLS-1$
+ "+/" // //$NON-NLS-1$
).getBytes(UTF_8);


DEC = new byte[128]; DEC = new byte[128];
Arrays.fill(DEC, INVALID_DEC); Arrays.fill(DEC, INVALID_DEC);
* @return the decoded data * @return the decoded data
*/ */
public static byte[] decode(String s) { public static byte[] decode(String s) {
byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
byte[] bytes = s.getBytes(UTF_8);
return decode(bytes, 0, bytes.length); return decode(bytes, 0, bytes.length);
} }
} }

Loading…
Cancel
Save