Author: adietish
Date: 2012-01-23 07:33:09 -0500 (Mon, 23 Jan 2012)
New Revision: 38027
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/GitIgnore.java
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/META-INF/MANIFEST.MF
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/GitIgnoreTest.java
Log:
[JBIDE-10687] switched internal set to LinkedHashSet. Added tests to ensure the ordering
of the entries is not altered when adding,writing.
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/GitIgnore.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/GitIgnore.java 2012-01-23
11:03:36 UTC (rev 38026)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/GitIgnore.java 2012-01-23
12:33:09 UTC (rev 38027)
@@ -15,7 +15,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.Set;
import org.eclipse.core.resources.IFile;
@@ -45,7 +45,7 @@
}
private void initEntries(IFile gitIgnore) throws IOException, CoreException {
- this.entries = new HashSet<String>();
+ this.entries = new LinkedHashSet<String>();
if (gitIgnore == null
|| !gitIgnore.isAccessible()) {
return;
Modified: trunk/openshift/tests/org.jboss.tools.openshift.egit.test/META-INF/MANIFEST.MF
===================================================================
---
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/META-INF/MANIFEST.MF 2012-01-23
11:03:36 UTC (rev 38026)
+++
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/META-INF/MANIFEST.MF 2012-01-23
12:33:09 UTC (rev 38027)
@@ -14,3 +14,4 @@
org.jboss.tools.openshift.egit.core;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
+Import-Package: org.jboss.tools.common.util
Modified:
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/GitIgnoreTest.java
===================================================================
---
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/GitIgnoreTest.java 2012-01-23
11:03:36 UTC (rev 38026)
+++
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/GitIgnoreTest.java 2012-01-23
12:33:09 UTC (rev 38027)
@@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.tools.openshift.egit.internal.test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
@@ -21,6 +23,7 @@
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jgit.lib.Constants;
+import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.openshift.egit.core.GitIgnore;
import org.junit.Test;
@@ -87,7 +90,65 @@
silentlyDelete(project);
}
}
+
+ @Test
+ public void writingDoesNotAlterOrdering() throws CoreException, IOException {
+ IFile gitIgnoreFile = null;
+ IProject project = null;
+ try {
+ project = createRandomProject();
+ gitIgnoreFile = createGitFile(project, "redhat", "jboss",
"tools");
+ String entries = FileUtil.readStream(gitIgnoreFile);
+ GitIgnore gitIgnore = new GitIgnore(gitIgnoreFile);
+ gitIgnore.write(null);
+ String entriesAfterWrite = FileUtil.readStream(gitIgnoreFile);
+ assertEquals(entries, entriesAfterWrite);
+
+ } finally {
+ silentlyDelete(project);
+ }
+ }
+
+ @Test
+ public void newEntriesAreAddedToTheEnd() throws CoreException, IOException {
+ IFile gitIgnoreFile = null;
+ IProject project = null;
+ try {
+ project = createRandomProject();
+ gitIgnoreFile = createGitFile(project, "redhat", "jboss",
"tools");
+ String entries = FileUtil.readStream(gitIgnoreFile);
+ GitIgnore gitIgnore = new GitIgnore(gitIgnoreFile);
+ gitIgnore.add("adietish");
+ gitIgnore.write(null);
+
+ String entriesAfterWrite = FileUtil.readStream(gitIgnoreFile);
+ assertFalse(entries.equals(entriesAfterWrite));
+ assertTrue(entriesAfterWrite.indexOf(entries) == 0);
+ } finally {
+ silentlyDelete(project);
+ }
+ }
+
+ @Test
+ public void addingExistingEntryDoesNotMoveItToTheEnd() throws CoreException, IOException
{
+ IFile gitIgnoreFile = null;
+ IProject project = null;
+ try {
+ project = createRandomProject();
+ gitIgnoreFile = createGitFile(project, "redhat", "jboss",
"tools");
+ String entries = FileUtil.readStream(gitIgnoreFile);
+ GitIgnore gitIgnore = new GitIgnore(gitIgnoreFile);
+ gitIgnore.add("jboss");
+ gitIgnore.write(null);
+
+ String entriesAfterWrite = FileUtil.readStream(gitIgnoreFile);
+ assertEquals(entries, entriesAfterWrite);
+ } finally {
+ silentlyDelete(project);
+ }
+ }
+
private IFile createGitFile(IProject project, String... gitIgnoreEntries) throws
CoreException {
IFile gitFile = project.getFile(Constants.GITIGNORE_FILENAME);
StringBuilder builder = new StringBuilder();