summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorBenjamin Muskalla2010-08-05 12:02:44 (EDT)
committer Benjamin Muskalla2010-08-05 12:02:44 (EDT)
commitc4e85d9fe3b30c7e033a30406f026df96757bad8 (patch)
treecf1f5351db09297c09702fac2680129809226fd6
parentd1c38ce1072252d727bc443e99ae75bee395465f (diff)
downloadegit-c4e85d9fe3b30c7e033a30406f026df96757bad8.zip
egit-c4e85d9fe3b30c7e033a30406f026df96757bad8.tar.gz
egit-c4e85d9fe3b30c7e033a30406f026df96757bad8.tar.bz2
Fixed several warnings around ConnectProviderOperationrefs/changes/42/1242/1
Removed suspect usage of Job to wait for a test result even though the operation in question can run synchronously. Removed parameter assignment in Operation and replaced ObjectWriter with ObjectInserter. Change-Id: I578d2e64d1fe5181395c518329b339339051d870 Signed-off-by: Benjamin Muskalla <bmuskalla@eclipsesource.com>
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitTestCase.java13
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java27
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConnectProviderOperation.java19
3 files changed, 22 insertions, 37 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitTestCase.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitTestCase.java
index ac971b2..a6ceca2 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitTestCase.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitTestCase.java
@@ -18,7 +18,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.ObjectWriter;
+import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.SystemReader;
@@ -57,8 +57,15 @@ public abstract class GitTestCase {
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(content);
fileWriter.close();
- ObjectWriter objectWriter = new ObjectWriter(repository);
- return objectWriter.writeBlob(file);
+ byte[] fileContents = IO.readFully(file);
+ ObjectInserter inserter = repository.newObjectInserter();
+ try {
+ ObjectId objectId = inserter.insert(Constants.OBJ_BLOB, fileContents);
+ inserter.flush();
+ return objectId;
+ } finally {
+ inserter.release();
+ }
}
protected ObjectId createFileCorruptShort(Repository repository, IProject actProject, String name, String content) throws IOException {
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java
index ecb2022..42ec2e4 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java
@@ -22,9 +22,6 @@ import java.util.TimeZone;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.egit.core.op.ConnectProviderOperation;
import org.eclipse.egit.core.test.GitTestCase;
import org.eclipse.jgit.lib.Commit;
@@ -56,8 +53,6 @@ public class ConnectProviderOperationTest extends GitTestCase {
@Test
public void testNewRepository() throws CoreException, IOException {
- File gitDir = new File(project.getProject().getWorkspace().getRoot()
- .getRawLocation().toFile(), Constants.DOT_GIT);
Repository repository = new FileRepository(gitDir);
repository.create();
repository.close();
@@ -71,16 +66,13 @@ public class ConnectProviderOperationTest extends GitTestCase {
}
@Test
- public void testNewUnsharedFile() throws CoreException, IOException,
- InterruptedException {
+ public void testNewUnsharedFile() throws CoreException, IOException {
project.createSourceFolder();
IFile fileA = project.getProject().getFolder("src").getFile("A.java");
String srcA = "class A {\n" + "}\n";
fileA.create(new ByteArrayInputStream(srcA.getBytes()), false, null);
- File gitDir = new File(project.getProject().getWorkspace().getRoot()
- .getRawLocation().toFile(), Constants.DOT_GIT);
Repository thisGit = new FileRepository(gitDir);
thisGit.create();
Tree rootTree = new Tree(thisGit);
@@ -108,23 +100,6 @@ public class ConnectProviderOperationTest extends GitTestCase {
project.getProject(), gitDir);
operation.execute(null);
- final boolean f[] = new boolean[1];
- new Job("wait") {
- protected IStatus run(IProgressMonitor monitor) {
-
- f[0] = true;
- return null;
- }
-
- {
- setRule(project.getProject());
- schedule();
- }
- };
- while (!f[0]) {
- Thread.sleep(1000);
- }
-
assertNotNull(RepositoryProvider.getProvider(project.getProject()));
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConnectProviderOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConnectProviderOperation.java
index 08d3ac4..9a0c87c 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConnectProviderOperation.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConnectProviderOperation.java
@@ -82,17 +82,20 @@ public class ConnectProviderOperation implements IEGitOperation {
* @see org.eclipse.egit.core.op.IEGitOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
*/
public void execute(IProgressMonitor m) throws CoreException {
+ IProgressMonitor monitor;
if (m == null) {
- m = new NullProgressMonitor();
+ monitor = new NullProgressMonitor();
+ } else {
+ monitor = m;
}
- m.beginTask(CoreText.ConnectProviderOperation_connecting,
+ monitor.beginTask(CoreText.ConnectProviderOperation_connecting,
100 * projects.size());
try {
for (Iterator iterator = projects.keySet().iterator(); iterator.hasNext();) {
IProject project = (IProject) iterator.next();
- m.setTaskName(NLS.bind(
+ monitor.setTaskName(NLS.bind(
CoreText.ConnectProviderOperation_ConnectingProject,
project.getName()));
// TODO is this the right location?
@@ -102,7 +105,7 @@ public class ConnectProviderOperation implements IEGitOperation {
"Locating repository for " + project); //$NON-NLS-1$
Collection<RepositoryMapping> repos = new RepositoryFinder(
- project).find(new SubProgressMonitor(m, 40));
+ project).find(new SubProgressMonitor(monitor, 40));
File suggestedRepo = projects.get(project);
RepositoryMapping actualMapping= findActualRepository(repos, suggestedRepo);
if (actualMapping != null) {
@@ -121,8 +124,8 @@ public class ConnectProviderOperation implements IEGitOperation {
.map(project, GitProvider.class.getName());
projectData = GitProjectData.get(project);
project.refreshLocal(IResource.DEPTH_INFINITE,
- new SubProgressMonitor(m, 50));
- m.worked(10);
+ new SubProgressMonitor(monitor, 50));
+ monitor.worked(10);
} else {
// TODO is this the right location?
if (GitTraceLocation.CORE.isActive())
@@ -130,11 +133,11 @@ public class ConnectProviderOperation implements IEGitOperation {
GitTraceLocation.CORE.getLocation(),
"Attempted to share project without repository ignored :" //$NON-NLS-1$
+ project);
- m.worked(60);
+ monitor.worked(60);
}
}
} finally {
- m.done();
+ monitor.done();
}
}