本文整理汇总了Java中org.eclipse.jgit.transport.URIish.getPath方法的典型用法代码示例。如果您正苦于以下问题:Java URIish.getPath方法的具体用法?Java URIish.getPath怎么用?Java URIish.getPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.transport.URIish
的用法示例。
在下文中一共展示了URIish.getPath方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getGerritProjectName
import org.eclipse.jgit.transport.URIish; //导入方法依赖的package包/类
public static String getGerritProjectName(Repository repository) {
try {
RemoteConfig config = new RemoteConfig(repository.getConfig(),
"origin"); //$NON-NLS-1$
List<URIish> urls = new ArrayList<URIish>(config.getPushURIs());
urls.addAll(config.getURIs());
for (URIish uri: urls) {
if (uri.getPort() == 29418) { //Gerrit refspec
String path = uri.getPath();
while (path.startsWith("/")) { //$NON-NLS-1$
path = path.substring(1);
}
return path;
}
break;
}
} catch (Exception e) {
GerritToolsPlugin.getDefault().log(e);
}
return null;
}
示例2: format
import org.eclipse.jgit.transport.URIish; //导入方法依赖的package包/类
private static String format(URIish uri) {
StringBuilder r = new StringBuilder();
if (uri.getScheme() != null) r.append(uri.getScheme()).append("://");
if (uri.getHost() != null) {
r.append(uri.getHost());
if (uri.getScheme() != null && uri.getPort() > 0) r.append(':').append(uri.getPort());
}
if (uri.getPath() != null) {
if (uri.getScheme() != null) {
if (!uri.getPath().startsWith("/") && !uri.getPath().isEmpty()) r.append('/');
} else if(uri.getHost() != null) r.append(':');
if (uri.getScheme() != null) r.append(uri.getRawPath());
else r.append(uri.getPath());
}
return r.toString();
}
示例3: goUp
import org.eclipse.jgit.transport.URIish; //导入方法依赖的package包/类
static URIish goUp(final URIish uri) {
final String originalPath = uri.getPath();
if (originalPath == null || originalPath.length() == 0 || originalPath.equals(SLASH)) {
return null;
}
final int lastSlash;
if (originalPath.endsWith(SLASH)) {
lastSlash = originalPath.lastIndexOf(SLASH, originalPath.length() - 2);
}
else {
lastSlash = originalPath.lastIndexOf(SLASH);
}
final String pathUpOneLevel = originalPath.substring(0, lastSlash);
final URIish result;
if (pathUpOneLevel.length() == 0) {
result = uri.setPath(null);
}
else {
result = uri.setPath(pathUpOneLevel);
}
return result;
}
示例4: createLocally
import org.eclipse.jgit.transport.URIish; //导入方法依赖的package包/类
private static void createLocally(URIish uri, String head) {
try (Repository repo = new FileRepository(uri.getPath())) {
repo.create(true /* bare */);
if (head != null) {
RefUpdate u = repo.updateRef(Constants.HEAD);
u.disableRefLog();
u.link(head);
}
} catch (IOException e) {
repLog.error(String.format("Error creating local repository %s:\n", uri.getPath()), e);
}
}
示例5: updateHeadLocally
import org.eclipse.jgit.transport.URIish; //导入方法依赖的package包/类
private static void updateHeadLocally(URIish uri, String newHead) {
try (Repository repo = new FileRepository(uri.getPath())) {
if (newHead != null) {
RefUpdate u = repo.updateRef(Constants.HEAD);
u.link(newHead);
}
} catch (IOException e) {
repLog.error(
String.format("Failed to update HEAD of repository %s to %s", uri.getPath(), newHead), e);
}
}
示例6: isSSH
import org.eclipse.jgit.transport.URIish; //导入方法依赖的package包/类
private static boolean isSSH(URIish uri) {
String scheme = uri.getScheme();
if (!uri.isRemote()) {
return false;
}
if (scheme != null && scheme.toLowerCase().contains("ssh")) {
return true;
}
if (scheme == null && uri.getHost() != null && uri.getPath() != null) {
return true;
}
return false;
}
示例7: testToHTTPMirrorSuccess
import org.eclipse.jgit.transport.URIish; //导入方法依赖的package包/类
@Test
public void testToHTTPMirrorSuccess() throws IOException, GitAPIException {
final File parentFolder = createTempDirectory();
final File directory = new File(parentFolder,
TARGET_GIT);
new Clone(directory,
ORIGIN,
true,
CredentialsProvider.getDefault(),
null).execute();
final Git cloned = Git.open(directory);
assertThat(cloned).isNotNull();
assertThat(cloned.getRepository().getAllRefs()).is(new Condition<Map<String, Ref>>() {
@Override
public boolean matches(final Map<String, Ref> refs) {
final boolean hasMasterRef = refs.get("refs/heads/master") != null;
final boolean hasPullRequestRef = refs.get("refs/pull/1/head") != null;
return hasMasterRef && hasPullRequestRef;
}
});
final boolean isMirror = cloned.getRepository().getConfig().getBoolean("remote",
"origin",
"mirror",
false);
assertTrue(isMirror);
URIish remoteUri = cloned.remoteList().call().get(0).getURIs().get(0);
String remoteUrl = remoteUri.getScheme() + "://" + remoteUri.getHost() + remoteUri.getPath();
assertThat(remoteUrl).isEqualTo(ORIGIN);
}
示例8: testToHTTPUnmirrorSuccess
import org.eclipse.jgit.transport.URIish; //导入方法依赖的package包/类
@Test
public void testToHTTPUnmirrorSuccess() throws IOException, GitAPIException {
final File parentFolder = createTempDirectory();
final File directory = new File(parentFolder,
TARGET_GIT);
new Clone(directory,
ORIGIN,
false,
CredentialsProvider.getDefault(),
null).execute();
final Git cloned = Git.open(directory);
assertThat(cloned).isNotNull();
assertThat(cloned.getRepository().getAllRefs()).is(new Condition<Map<String, Ref>>() {
@Override
public boolean matches(final Map<String, Ref> refs) {
final boolean hasMasterRef = refs.get("refs/heads/master") != null;
final boolean hasPullRequestRef = refs.get("refs/pull/1/head") != null;
return hasMasterRef && !hasPullRequestRef;
}
});
final boolean isMirror = cloned.getRepository().getConfig().getBoolean("remote",
"origin",
"mirror",
false);
assertFalse(isMirror);
assertThat(new ListRefs(cloned.getRepository()).execute().get(0).getName()).isEqualTo("refs/heads/master");
URIish remoteUri = cloned.remoteList().call().get(0).getURIs().get(0);
String remoteUrl = remoteUri.getScheme() + "://" + remoteUri.getHost() + remoteUri.getPath();
assertThat(remoteUrl).isEqualTo(ORIGIN);
}
示例9: testEmptyCredentials
import org.eclipse.jgit.transport.URIish; //导入方法依赖的package包/类
@Test
public void testEmptyCredentials() throws IOException, GitAPIException {
final File parentFolder = createTempDirectory();
final File directory = new File(parentFolder,
TARGET_GIT);
new Clone(directory,
ORIGIN,
false,
null,
null).execute();
final Git cloned = Git.open(directory);
assertThat(cloned).isNotNull();
assertThat(new ListRefs(cloned.getRepository()).execute()).is(new Condition<List<Ref>>() {
@Override
public boolean matches(final List<Ref> refs) {
return refs.size() > 0;
}
});
assertThat(new ListRefs(cloned.getRepository()).execute().get(0).getName()).isEqualTo("refs/heads/master");
URIish remoteUri = cloned.remoteList().call().get(0).getURIs().get(0);
String remoteUrl = remoteUri.getScheme() + "://" + remoteUri.getHost() + remoteUri.getPath();
assertThat(remoteUrl).isEqualTo(ORIGIN);
}
示例10: getRepositoryBase
import org.eclipse.jgit.transport.URIish; //导入方法依赖的package包/类
/**
* Gets the base directory of the specified reposotory's file location.
*
* @param gitRepository the repository. Must not be {@code null}
* @return the base file. Never {@code null}
* @throws URISyntaxException
*/
public static File getRepositoryBase(final GitRepository gitRepository) throws URISyntaxException {
Validate.notNull(gitRepository, "gitRepository must not be null");
final URIish uri = new URIish(gitRepository.getUri());
if (!"file".equals(uri.getScheme())) {
throw new IllegalArgumentException("Only file:// URI scheme supported");
}
final File repositoryDirectory = new File(uri.getPath());
return repositoryDirectory;
}