Author: adietish
Date: 2012-01-31 04:10:34 -0500 (Tue, 31 Jan 2012)
New Revision: 38313
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/EGitUtils.java
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/EGitUtilsTest.java
Log:
[JBIDE-10479] added EGitUtils#getRemoteConfig(name) and test
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/EGitUtils.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/EGitUtils.java 2012-01-31
02:30:06 UTC (rev 38312)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/EGitUtils.java 2012-01-31
09:10:34 UTC (rev 38313)
@@ -428,12 +428,13 @@
private static String getErrors(PushOperationResult pushResult) {
StringBuilder builder = new StringBuilder();
- for(RemoteRefUpdate failedUpdate : getFailedUpdates(pushResult)) {
+ for (RemoteRefUpdate failedUpdate : getFailedUpdates(pushResult)) {
builder.append(MessageFormat.format(
- "push from {0} to {1} was {2}", failedUpdate.getSrcRef(),
failedUpdate.getRemoteName(), failedUpdate.getStatus()));
+ "push from {0} to {1} was {2}", failedUpdate.getSrcRef(),
failedUpdate.getRemoteName(),
+ failedUpdate.getStatus()));
}
return builder.toString();
-
+
}
private static PushOperation createPushOperation(RemoteConfig remoteConfig, Repository
repository, boolean force)
@@ -647,30 +648,32 @@
/**
* Gets the remote config with the given name from the list of remote
- * repositories. Returns <code>null</code> if it was not found.
+ * configs. Returns <code>null</code> if it was not found.
*
* @param remoteName
* the remote name
* @param remoteRepositories
* the remote repositories
* @return the remote config
+ *
+ * @see #getAllRemoteConfigs(Repository)
*/
- private static RemoteConfig getRemoteConfig(String remoteName, List<RemoteConfig>
remoteRepositories) {
- RemoteConfig defaultConfig = null;
- RemoteConfig configuredConfig = null;
- for (RemoteConfig config : remoteRepositories) {
- // if (config.getName().equals(Constants.DEFAULT_REMOTE_NAME))
- // defaultConfig = config;
- if (remoteName != null && config.getName().equals(remoteName))
- configuredConfig = config;
+ public static RemoteConfig getRemoteConfig(String name, List<RemoteConfig>
remoteConfigs) {
+ Assert.isLegal(name != null);
+ RemoteConfig remoteConfig = null;
+ for (RemoteConfig config : remoteConfigs) {
+ if (name != null && config.getName().equals(name)) {
+ remoteConfig = config;
+ break;
+ }
}
+ return remoteConfig;
+ }
- if (configuredConfig == null) {
- return defaultConfig;
- }
- return configuredConfig;
+ public static boolean hasRemoteConfig(String name, List<RemoteConfig>
remoteConfigs) {
+ return getRemoteConfig(name, remoteConfigs) != null;
}
-
+
/**
* Returns all the remote configs from the given repository.
*
@@ -688,13 +691,22 @@
}
}
- public static boolean hasRemote(String regex, Repository repository) throws
CoreException {
- return hasRemote(Pattern.compile(regex), repository);
+ public static boolean hasRemoteUrl(String regex, Repository repository) throws
CoreException {
+ return hasRemoteUrl(Pattern.compile(regex), repository);
}
-
- public static boolean hasRemote(Pattern pattern, Repository repository) throws
CoreException {
+
+ /**
+ * Returns <code>true</code> if the given repository has a configured
remote
+ * repository with an url that matches the given pattern.
+ *
+ * @param pattern
+ * @param repository
+ * @return
+ * @throws CoreException
+ */
+ public static boolean hasRemoteUrl(Pattern pattern, Repository repository) throws
CoreException {
for (RemoteConfig config : getAllRemoteConfigs(repository)) {
- for(URIish uri : config.getURIs()) {
+ for (URIish uri : config.getURIs()) {
Matcher matcher = pattern.matcher(uri.toString());
if (matcher.find()) {
return true;
Modified:
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/EGitUtilsTest.java
===================================================================
---
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/EGitUtilsTest.java 2012-01-31
02:30:06 UTC (rev 38312)
+++
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/EGitUtilsTest.java 2012-01-31
09:10:34 UTC (rev 38313)
@@ -8,7 +8,9 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
import java.net.URISyntaxException;
+import java.util.List;
import java.util.Set;
import org.eclipse.core.resources.IFile;
@@ -18,6 +20,7 @@
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.transport.RemoteConfig;
import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.openshift.egit.core.EGitUtils;
import org.jboss.tools.openshift.egit.internal.test.util.TestProject;
@@ -59,7 +62,6 @@
testRepository2.connect(testProject2.getProject());
this.testRepositoryClone = cloneRepository(testRepository);
-// testRepositoryClone.addRemoteTo(REPO2_REMOTE_NAME, testRepository2.getRepository());
}
private TestRepository cloneRepository(TestRepository repository) throws
URISyntaxException,
@@ -231,4 +233,29 @@
assertTrue(EGitUtils.isDirty(testRepository.getRepository()));
}
+ @Test
+ public void canGetSingleRemoteConfig() throws CoreException, MalformedURLException,
URISyntaxException, IOException {
+ String remoteName = "repo2";
+
+ testRepository.addRemoteTo(remoteName, testRepository2.getRepository());
+ List<RemoteConfig> allRemoteConfigs =
EGitUtils.getAllRemoteConfigs(testRepository.getRepository());
+ assertNotNull(allRemoteConfigs);
+ assertEquals(1, allRemoteConfigs.size());
+ RemoteConfig repo2Config = EGitUtils.getRemoteConfig(remoteName, allRemoteConfigs);
+ assertNotNull(repo2Config);
+ }
+
+ @Test
+ public void canGetFromSeveralRemoteConfig() throws CoreException, MalformedURLException,
URISyntaxException, IOException {
+ String repo2RemoteName = "repo2";
+
+ testRepositoryClone.addRemoteTo(repo2RemoteName, testRepository2.getRepository());
+ List<RemoteConfig> allRemoteConfigs =
EGitUtils.getAllRemoteConfigs(testRepositoryClone.getRepository());
+ assertNotNull(allRemoteConfigs);
+ // clone already has repo1 as origin
+ assertEquals(2, allRemoteConfigs.size());
+ RemoteConfig repo2Config = EGitUtils.getRemoteConfig(repo2RemoteName,
allRemoteConfigs);
+ assertNotNull(repo2Config);
+ }
+
}