Author: adietish
Date: 2012-02-07 14:07:02 -0500 (Tue, 07 Feb 2012)
New Revision: 38479
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/internal/utils/
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/internal/utils/RegexUtils.java
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/internal/EGitCoreActivator.java
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/util/TestRepository.java
Log:
[JBIDE-10479] implemented EGitUtils#hasRemote(name, url) that reponds whether a repo has a
configured remote with the given name and url
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-02-07
16:31:34 UTC (rev 38478)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/EGitUtils.java 2012-02-07
19:07:02 UTC (rev 38479)
@@ -71,6 +71,7 @@
import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.wst.server.core.IServer;
import org.jboss.tools.openshift.egit.core.internal.EGitCoreActivator;
+import org.jboss.tools.openshift.egit.core.internal.utils.RegexUtils;
/**
* The Class EGitUtils.
@@ -363,20 +364,20 @@
public static List<URIish> getRemoteURIs(IProject p) throws CoreException {
RemoteConfig rc = getRemoteConfig(p);
- if( rc != null ) {
+ if (rc != null) {
return rc.getURIs();
}
return new ArrayList<URIish>();
}
-
+
public static RemoteConfig getRemoteConfig(IProject project) throws CoreException {
Repository rep = getRepository(project);
- if( rep != null ) {
+ if (rep != null) {
return getRemoteConfig(rep);
}
return null;
}
-
+
/**
* Pushes the current branch of the given repository to the remote
* repository that it originates from.
@@ -686,10 +687,6 @@
return remoteConfig;
}
- public static boolean hasRemoteConfig(String name, List<RemoteConfig>
remoteConfigs) {
- return getRemoteConfig(name, remoteConfigs) != null;
- }
-
/**
* Returns all the remote configs from the given repository.
*
@@ -706,10 +703,6 @@
repository.toString()));
}
}
-
- public static boolean hasRemoteUrl(String regex, Repository repository) throws
CoreException {
- return hasRemoteUrl(Pattern.compile(regex), repository);
- }
/**
* Returns <code>true</code> if the given repository has a configured
remote
@@ -722,17 +715,46 @@
*/
public static boolean hasRemoteUrl(Pattern pattern, Repository repository) throws
CoreException {
for (RemoteConfig config : getAllRemoteConfigs(repository)) {
- for (URIish uri : config.getURIs()) {
- Matcher matcher = pattern.matcher(uri.toString());
- if (matcher.find()) {
- return true;
- }
+ if (hasRemoteUrl(pattern, config)) {
+ return true;
}
}
return false;
}
+ public static boolean hasRemoteUrl(Pattern pattern, RemoteConfig config) {
+ for (URIish uri : config.getURIs()) {
+ Matcher matcher = pattern.matcher(uri.toString());
+ if (matcher.find()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
+ * Returns <code>true</code> if the given repository has a remote config
+ * with the given name and url.
+ *
+ * @param name
+ * the name that the remote config shall match
+ * @param url
+ * the url that the remote config shall match
+ * @param repository
+ * the repository that is searched
+ * @return
+ * @throws CoreException
+ */
+ public static boolean hasRemote(String name, String url, Repository repository) throws
CoreException {
+ RemoteConfig remoteConfig = getRemoteConfig(name, repository);
+ if (remoteConfig == null) {
+ return false;
+ }
+
+ return hasRemoteUrl(Pattern.compile(RegexUtils.toPatternString(url)), remoteConfig);
+ }
+
+ /**
* Returns <code>true</code> if the given repository has several configured
* remotes
*
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/internal/EGitCoreActivator.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/internal/EGitCoreActivator.java 2012-02-07
16:31:34 UTC (rev 38478)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/internal/EGitCoreActivator.java 2012-02-07
19:07:02 UTC (rev 38479)
@@ -37,6 +37,10 @@
EGitCoreActivator.context = null;
}
+ public static IStatus createErrorStatus(String message) {
+ return createStatus(IStatus.ERROR, message, null);
+ }
+
public static IStatus createErrorStatus(String message, Throwable throwable) {
return createStatus(IStatus.ERROR, message, throwable);
}
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/internal/utils/RegexUtils.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/internal/utils/RegexUtils.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/internal/utils/RegexUtils.java 2012-02-07
19:07:02 UTC (rev 38479)
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.egit.core.internal.utils;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class RegexUtils {
+
+ public static String toPatternString(String string) {
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < string.length(); ++i) {
+ char ch = string.charAt(i);
+ if ("\\.^$|?*+[]{}()".indexOf(ch) != -1) {
+ // reserved char char
+ builder.append('\\').append(ch);
+// } else if (Character.isLetter(ch)) {
+// // letter
+// builder.append("[A-Za-z]");
+// } else if (Character.isDigit(ch)) {
+// // digit
+// builder.append("\\d");
+ } else {
+ builder.append(ch);
+ }
+ }
+ return builder.toString();
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/internal/utils/RegexUtils.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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-02-07
16:31:34 UTC (rev 38478)
+++
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/EGitUtilsTest.java 2012-02-07
19:07:02 UTC (rev 38479)
@@ -258,4 +258,12 @@
assertNotNull(repo2Config);
}
+ @Test
+ public void canCheckIfHasRemote() throws CoreException, MalformedURLException,
URISyntaxException, IOException {
+ String repo2RemoteName = "repo2";
+
+ testRepositoryClone.addRemoteTo(repo2RemoteName, testRepository2.getRepository());
+ assertTrue(
+ EGitUtils.hasRemote(repo2RemoteName, testRepository2.getUri().toString(),
testRepositoryClone.getRepository()));
+ }
}
Modified:
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/util/TestRepository.java
===================================================================
---
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/util/TestRepository.java 2012-02-07
16:31:34 UTC (rev 38478)
+++
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/util/TestRepository.java 2012-02-07
19:07:02 UTC (rev 38479)
@@ -282,7 +282,7 @@
* @throws IOException
*/
public void add(File file) throws IOException {
- String repoPath =
+ String repoPath =
getRepoRelativePath(file.getAbsolutePath());
try {
new Git(repository).add().addFilepattern(repoPath).call();
@@ -575,4 +575,8 @@
config.save();
}
+ public URIish getUri() throws MalformedURLException {
+ return new URIish(repository.getDirectory().toURI().toURL());
+ }
+
}