diff options
Diffstat (limited to 'org.eclipse.jgit.junit')
9 files changed, 115 insertions, 85 deletions
diff --git a/org.eclipse.jgit.junit/.settings/.api_filters b/org.eclipse.jgit.junit/.settings/.api_filters new file mode 100644 index 0000000000..e5de787fa6 --- /dev/null +++ b/org.eclipse.jgit.junit/.settings/.api_filters @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<component id="org.eclipse.jgit.junit" version="2"> + <resource path="src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java" type="org.eclipse.jgit.junit.LocalDiskRepositoryTestCase"> + <filter comment="Don't care about non-API in tests." id="643842064"> + <message_arguments> + <message_argument value="FileRepository"/> + <message_argument value="LocalDiskRepositoryTestCase"/> + <message_argument value="createBareRepository()"/> + </message_arguments> + </filter> + <filter comment="Don't care about non-API in tests." id="643842064"> + <message_arguments> + <message_argument value="FileRepository"/> + <message_argument value="LocalDiskRepositoryTestCase"/> + <message_argument value="createRepository(boolean, boolean)"/> + </message_arguments> + </filter> + <filter comment="Don't care about non-API in tests." id="643842064"> + <message_arguments> + <message_argument value="FileRepository"/> + <message_argument value="LocalDiskRepositoryTestCase"/> + <message_argument value="createWorkRepository()"/> + </message_arguments> + </filter> + </resource> + <resource path="src/org/eclipse/jgit/junit/RepositoryTestCase.java" type="org.eclipse.jgit.junit.RepositoryTestCase"> + <filter comment="Don't care about non-API in tests." id="627060751"> + <message_arguments> + <message_argument value="FileRepository"/> + <message_argument value="RepositoryTestCase"/> + <message_argument value="db"/> + </message_arguments> + </filter> + </resource> +</component> diff --git a/org.eclipse.jgit.junit/META-INF/MANIFEST.MF b/org.eclipse.jgit.junit/META-INF/MANIFEST.MF index 7e99d9d65f..749f8fe984 100644 --- a/org.eclipse.jgit.junit/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.junit/META-INF/MANIFEST.MF @@ -3,31 +3,31 @@ Bundle-ManifestVersion: 2 Bundle-Name: %plugin_name Automatic-Module-Name: org.eclipse.jgit.junit Bundle-SymbolicName: org.eclipse.jgit.junit -Bundle-Version: 4.11.7.qualifier +Bundle-Version: 5.0.4.qualifier Bundle-Localization: plugin Bundle-Vendor: %provider_name Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Import-Package: org.eclipse.jgit.api;version="[4.11.7,4.12.0)", - org.eclipse.jgit.api.errors;version="[4.11.7,4.12.0)", - org.eclipse.jgit.dircache;version="[4.11.7,4.12.0)", - org.eclipse.jgit.errors;version="[4.11.7,4.12.0)", - org.eclipse.jgit.internal.storage.file;version="[4.11.7,4.12.0)", - org.eclipse.jgit.internal.storage.pack;version="[4.11.7,4.12.0)", - org.eclipse.jgit.lib;version="[4.11.7,4.12.0)", - org.eclipse.jgit.merge;version="[4.11.7,4.12.0)", - org.eclipse.jgit.revwalk;version="[4.11.7,4.12.0)", - org.eclipse.jgit.storage.file;version="[4.11.7,4.12.0)", - org.eclipse.jgit.treewalk;version="[4.11.7,4.12.0)", - org.eclipse.jgit.treewalk.filter;version="[4.11.7,4.12.0)", - org.eclipse.jgit.util;version="[4.11.7,4.12.0)", - org.eclipse.jgit.util.io;version="[4.11.7,4.12.0)", - org.eclipse.jgit.util.time;version="[4.11.7,4.12.0)", +Import-Package: org.eclipse.jgit.api;version="[5.0.4,5.1.0)", + org.eclipse.jgit.api.errors;version="[5.0.4,5.1.0)", + org.eclipse.jgit.dircache;version="[5.0.4,5.1.0)", + org.eclipse.jgit.errors;version="[5.0.4,5.1.0)", + org.eclipse.jgit.internal.storage.file;version="[5.0.4,5.1.0)", + org.eclipse.jgit.internal.storage.pack;version="[5.0.4,5.1.0)", + org.eclipse.jgit.lib;version="[5.0.4,5.1.0)", + org.eclipse.jgit.merge;version="[5.0.4,5.1.0)", + org.eclipse.jgit.revwalk;version="[5.0.4,5.1.0)", + org.eclipse.jgit.storage.file;version="[5.0.4,5.1.0)", + org.eclipse.jgit.treewalk;version="[5.0.4,5.1.0)", + org.eclipse.jgit.treewalk.filter;version="[5.0.4,5.1.0)", + org.eclipse.jgit.util;version="[5.0.4,5.1.0)", + org.eclipse.jgit.util.io;version="[5.0.4,5.1.0)", + org.eclipse.jgit.util.time;version="[5.0.4,5.1.0)", org.junit;version="[4.12,5.0.0)", org.junit.rules;version="[4.12,5.0.0)", org.junit.runner;version="[4.12,5.0.0)", org.junit.runners.model;version="[4.12,5.0.0)" -Export-Package: org.eclipse.jgit.junit;version="4.11.7"; +Export-Package: org.eclipse.jgit.junit;version="5.0.4"; uses:="org.eclipse.jgit.dircache, org.eclipse.jgit.lib, org.eclipse.jgit.revwalk, @@ -36,4 +36,4 @@ Export-Package: org.eclipse.jgit.junit;version="4.11.7"; org.eclipse.jgit.util, org.eclipse.jgit.storage.file, org.eclipse.jgit.api", - org.eclipse.jgit.junit.time;version="4.11.7" + org.eclipse.jgit.junit.time;version="5.0.4" diff --git a/org.eclipse.jgit.junit/pom.xml b/org.eclipse.jgit.junit/pom.xml index 798f0bdda6..30ce0b3d41 100644 --- a/org.eclipse.jgit.junit/pom.xml +++ b/org.eclipse.jgit.junit/pom.xml @@ -52,7 +52,7 @@ <parent> <groupId>org.eclipse.jgit</groupId> <artifactId>org.eclipse.jgit-parent</artifactId> - <version>4.11.7-SNAPSHOT</version> + <version>5.0.4-SNAPSHOT</version> </parent> <artifactId>org.eclipse.jgit.junit</artifactId> diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java index cef81a062d..a102da1f49 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java @@ -45,7 +45,7 @@ package org.eclipse.jgit.junit; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.File; import java.io.FileNotFoundException; @@ -142,7 +142,7 @@ public abstract class JGitTestUtil { * @param fileName * @return the test resource file */ - public static File getTestResourceFile(final String fileName) { + public static File getTestResourceFile(String fileName) { if (fileName == null || fileName.length() <= 0) { return null; } @@ -242,11 +242,11 @@ public abstract class JGitTestUtil { * @throws IOException * the file could not be written. */ - public static void write(final File f, final String body) + public static void write(File f, String body) throws IOException { FileUtils.mkdirs(f.getParentFile(), true); try (Writer w = new OutputStreamWriter(new FileOutputStream(f), - UTF_8)) { + CHARSET)) { w.write(body); } } @@ -261,9 +261,9 @@ public abstract class JGitTestUtil { * @throws IOException * the file does not exist, or could not be read. */ - public static String read(final File file) throws IOException { + public static String read(File file) throws IOException { final byte[] body = IO.readFully(file); - return new String(body, 0, body.length, UTF_8); + return new String(body, 0, body.length, CHARSET); } /** @@ -274,7 +274,7 @@ public abstract class JGitTestUtil { * @return the content of the file * @throws IOException */ - public static String read(final Repository db, final String name) + public static String read(Repository db, String name) throws IOException { File file = new File(db.getWorkTree(), name); return read(file); @@ -288,7 +288,7 @@ public abstract class JGitTestUtil { * name of the file * @return {@code true} if the file exists */ - public static boolean check(final Repository db, final String name) { + public static boolean check(Repository db, String name) { File file = new File(db.getWorkTree(), name); return file.exists(); } diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java index 568bc3b0e1..6cdd0eb23c 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java @@ -45,7 +45,7 @@ package org.eclipse.jgit.junit; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertFalse; import static org.junit.Assert.fail; @@ -225,7 +225,7 @@ public abstract class LocalDiskRepositoryTestCase { * @param dir * the recursively directory to delete, if present. */ - protected void recursiveDelete(final File dir) { + protected void recursiveDelete(File dir) { recursiveDelete(dir, false, true); } @@ -352,7 +352,7 @@ public abstract class LocalDiskRepositoryTestCase { if (0 != (includedOptions & CONTENT)) { sb.append(", content:" + new String(repo.open(entry.getObjectId(), - Constants.OBJ_BLOB).getCachedBytes(), UTF_8)); + Constants.OBJ_BLOB).getCachedBytes(), CHARSET)); } if (0 != (includedOptions & ASSUME_UNCHANGED)) sb.append(", assume-unchanged:" @@ -540,7 +540,7 @@ public abstract class LocalDiskRepositoryTestCase { * @throws IOException * the file could not be written. */ - protected File write(final String body) throws IOException { + protected File write(String body) throws IOException { final File f = File.createTempFile("temp", "txt", tmp); try { write(f, body); @@ -571,7 +571,7 @@ public abstract class LocalDiskRepositoryTestCase { * @throws IOException * the file could not be written. */ - protected void write(final File f, final String body) throws IOException { + protected void write(File f, String body) throws IOException { JGitTestUtil.write(f, body); } @@ -583,11 +583,11 @@ public abstract class LocalDiskRepositoryTestCase { * @return the content of the file * @throws IOException */ - protected String read(final File f) throws IOException { + protected String read(File f) throws IOException { return JGitTestUtil.read(f); } - private static String[] toEnvArray(final Map<String, String> env) { + private static String[] toEnvArray(Map<String, String> env) { final String[] envp = new String[env.size()]; int i = 0; for (Map.Entry<String, String> e : env.entrySet()) diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java index 05d15229bc..d3d7d682e8 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java @@ -109,7 +109,7 @@ public class MockSystemReader extends SystemReader { setCurrentPlatform(); } - private void init(final String n) { + private void init(String n) { setProperty(n, n); } @@ -197,7 +197,7 @@ public class MockSystemReader extends SystemReader { * number of seconds to add to the current time. * @since 4.2 */ - public void tick(final int secDelta) { + public void tick(int secDelta) { now += secDelta * 1000L; } diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java index afc2c445cf..e983e5dfb6 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java @@ -46,7 +46,7 @@ package org.eclipse.jgit.junit; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import java.io.File; @@ -92,22 +92,15 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { * @param dst * @throws IOException */ - protected static void copyFile(final File src, final File dst) + protected static void copyFile(File src, File dst) throws IOException { - final FileInputStream fis = new FileInputStream(src); - try { - final FileOutputStream fos = new FileOutputStream(dst); - try { - final byte[] buf = new byte[4096]; - int r; - while ((r = fis.read(buf)) > 0) { - fos.write(buf, 0, r); - } - } finally { - fos.close(); + try (FileInputStream fis = new FileInputStream(src); + FileOutputStream fos = new FileOutputStream(dst)) { + final byte[] buf = new byte[4096]; + int r; + while ((r = fis.read(buf)) > 0) { + fos.write(buf, 0, r); } - } finally { - fis.close(); } } @@ -119,7 +112,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { * @return the trash file * @throws IOException */ - protected File writeTrashFile(final String name, final String data) + protected File writeTrashFile(String name, String data) throws IOException { return JGitTestUtil.writeTrashFile(db, name, data); } @@ -135,7 +128,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { * @throws Exception * @since 4.2 */ - protected Path writeLink(final String link, final String target) + protected Path writeLink(String link, String target) throws Exception { return JGitTestUtil.writeLink(db, link, target); } @@ -162,7 +155,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { * @return the file's content * @throws IOException */ - protected String read(final String name) throws IOException { + protected String read(String name) throws IOException { return JGitTestUtil.read(db, name); } @@ -173,7 +166,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { * file name * @return if the file exists */ - protected boolean check(final String name) { + protected boolean check(String name) { return JGitTestUtil.check(db, name); } @@ -184,7 +177,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { * file name * @throws IOException */ - protected void deleteTrashFile(final String name) throws IOException { + protected void deleteTrashFile(String name) throws IOException { JGitTestUtil.deleteTrashFile(db, name); } @@ -196,10 +189,10 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { * expected content * @throws IOException */ - protected static void checkFile(File f, final String checkData) + protected static void checkFile(File f, String checkData) throws IOException { try (Reader r = new InputStreamReader(new FileInputStream(f), - UTF_8)) { + CHARSET)) { if (checkData.length() > 0) { char[] data = new char[checkData.length()]; assertEquals(data.length, r.read(data)); @@ -293,10 +286,11 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { dce.setFileMode(treeItr.getEntryFileMode()); dce.setLastModified(treeItr.getEntryLastModified()); dce.setLength((int) len); - FileInputStream in = new FileInputStream( - treeItr.getEntryFile()); - dce.setObjectId(inserter.insert(Constants.OBJ_BLOB, len, in)); - in.close(); + try (FileInputStream in = new FileInputStream( + treeItr.getEntryFile())) { + dce.setObjectId( + inserter.insert(Constants.OBJ_BLOB, len, in)); + } builder.add(dce); treeItr.next(1); } @@ -380,8 +374,9 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { while (actTime <= startTime) { Thread.sleep(sleepTime); sleepTime *= 2; - FileOutputStream fos = new FileOutputStream(tmp); - fos.close(); + try (FileOutputStream fos = new FileOutputStream(tmp)) { + // Do nothing + } actTime = fs.lastModified(tmp); } return actTime; @@ -505,7 +500,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { * @param mode * @return the DirCacheEntry */ - protected DirCacheEntry createEntry(final String path, final FileMode mode) { + protected DirCacheEntry createEntry(String path, FileMode mode) { return createEntry(path, mode, DirCacheEntry.STAGE_0, path); } diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java index 41634e7cda..d23c0d3c22 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.junit; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -244,7 +244,7 @@ public class TestRepository<R extends Repository> { * @param secDelta * number of seconds to add to the current time. */ - public void tick(final int secDelta) { + public void tick(int secDelta) { mockSystemReader.tick(secDelta); } @@ -267,8 +267,8 @@ public class TestRepository<R extends Repository> { * @return reference to the blob. * @throws Exception */ - public RevBlob blob(final String content) throws Exception { - return blob(content.getBytes(UTF_8)); + public RevBlob blob(String content) throws Exception { + return blob(content.getBytes(CHARSET)); } /** @@ -279,7 +279,7 @@ public class TestRepository<R extends Repository> { * @return reference to the blob. * @throws Exception */ - public RevBlob blob(final byte[] content) throws Exception { + public RevBlob blob(byte[] content) throws Exception { ObjectId id; try (ObjectInserter ins = inserter) { id = ins.insert(Constants.OBJ_BLOB, content); @@ -298,7 +298,7 @@ public class TestRepository<R extends Repository> { * @return the entry. * @throws Exception */ - public DirCacheEntry file(final String path, final RevBlob blob) + public DirCacheEntry file(String path, RevBlob blob) throws Exception { final DirCacheEntry e = new DirCacheEntry(path); e.setFileMode(FileMode.REGULAR_FILE); @@ -315,10 +315,10 @@ public class TestRepository<R extends Repository> { * @return reference to the tree specified by the entry list. * @throws Exception */ - public RevTree tree(final DirCacheEntry... entries) throws Exception { + public RevTree tree(DirCacheEntry... entries) throws Exception { final DirCache dc = DirCache.newInCore(); final DirCacheBuilder b = dc.builder(); - for (final DirCacheEntry e : entries) + for (DirCacheEntry e : entries) b.add(e); b.finish(); ObjectId root; @@ -339,7 +339,7 @@ public class TestRepository<R extends Repository> { * @return the parsed object entry at this path, never null. * @throws Exception */ - public RevObject get(final RevTree tree, final String path) + public RevObject get(RevTree tree, String path) throws Exception { try (TreeWalk tw = new TreeWalk(pool.getObjectReader())) { tw.setFilter(PathFilterGroup.createFromStrings(Collections @@ -370,7 +370,7 @@ public class TestRepository<R extends Repository> { * @return the new commit. * @throws Exception */ - public RevCommit commit(final RevCommit... parents) throws Exception { + public RevCommit commit(RevCommit... parents) throws Exception { return commit(1, tree(), parents); } @@ -386,7 +386,7 @@ public class TestRepository<R extends Repository> { * @return the new commit. * @throws Exception */ - public RevCommit commit(final RevTree tree, final RevCommit... parents) + public RevCommit commit(RevTree tree, RevCommit... parents) throws Exception { return commit(1, tree, parents); } @@ -404,7 +404,7 @@ public class TestRepository<R extends Repository> { * @return the new commit. * @throws Exception */ - public RevCommit commit(final int secDelta, final RevCommit... parents) + public RevCommit commit(int secDelta, RevCommit... parents) throws Exception { return commit(secDelta, tree(), parents); } @@ -470,7 +470,7 @@ public class TestRepository<R extends Repository> { * @return the annotated tag object. * @throws Exception */ - public RevTag tag(final String name, final RevObject dst) throws Exception { + public RevTag tag(String name, RevObject dst) throws Exception { final TagBuilder t = new TagBuilder(); t.setObjectId(dst); t.setTag(name); @@ -759,7 +759,7 @@ public class TestRepository<R extends Repository> { final FileRepository fr = (FileRepository) db; RefWriter rw = new RefWriter(fr.getAllRefs().values()) { @Override - protected void writeFile(final String name, final byte[] bin) + protected void writeFile(String name, byte[] bin) throws IOException { File path = new File(fr.getDirectory(), name); TestRepository.this.writeFile(path, bin); @@ -791,7 +791,7 @@ public class TestRepository<R extends Repository> { * @return {@code object} * @throws Exception */ - public <T extends RevObject> T parseBody(final T object) throws Exception { + public <T extends RevObject> T parseBody(T object) throws Exception { pool.parseBody(object); return object; } @@ -944,7 +944,7 @@ public class TestRepository<R extends Repository> { return new File(packdir, "pack-" + name.name() + t); } - private void writeFile(final File p, final byte[] bin) throws IOException, + private void writeFile(File p, byte[] bin) throws IOException, ObjectWritingException { final LockFile lck = new LockFile(p); if (!lck.lock()) @@ -962,7 +962,7 @@ public class TestRepository<R extends Repository> { public class BranchBuilder { private final String ref; - BranchBuilder(final String ref) { + BranchBuilder(String ref) { this.ref = ref; } @@ -1093,7 +1093,7 @@ public class TestRepository<R extends Repository> { return add(path, blob(content)); } - public CommitBuilder add(String path, final RevBlob id) + public CommitBuilder add(String path, RevBlob id) throws Exception { return edit(new PathEdit(path) { @Override diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRng.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRng.java index 54c81f2d86..f7af36a838 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRng.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRng.java @@ -55,7 +55,7 @@ public class TestRng { * @param seed * seed to bootstrap, usually this is the test method name. */ - public TestRng(final String seed) { + public TestRng(String seed) { next = 0; for (int i = 0; i < seed.length(); i++) next = next * 11 + seed.charAt(i); @@ -68,7 +68,7 @@ public class TestRng { * number of random bytes to produce. * @return array of {@code cnt} randomly generated bytes. */ - public byte[] nextBytes(final int cnt) { + public byte[] nextBytes(int cnt) { final byte[] r = new byte[cnt]; for (int i = 0; i < cnt; i++) r[i] = (byte) nextInt(); |