本文整理匯總了Java中org.eclipse.jgit.transport.URIish.getHost方法的典型用法代碼示例。如果您正苦於以下問題:Java URIish.getHost方法的具體用法?Java URIish.getHost怎麽用?Java URIish.getHost使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jgit.transport.URIish
的用法示例。
在下文中一共展示了URIish.getHost方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getGerritURL
import org.eclipse.jgit.transport.URIish; //導入方法依賴的package包/類
public static String getGerritURL(Repository repository) {
String best = null;
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) {
best = "https://" + uri.getHost(); //$NON-NLS-1$
if (uri.getPort() == 29418) { //Gerrit refspec
return best;
}
break;
}
} catch (Exception e) {
GerritToolsPlugin.getDefault().log(e);
}
return best;
}
示例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: validateRemote
import org.eclipse.jgit.transport.URIish; //導入方法依賴的package包/類
/**
* Updates remote repository information using the local git repository.
* Verifies the remote pointed to is, indeed, a GitHub repository.
* <p>
* TODO - support additional hosts
* </p>
*
* @param git - local git repository
* @return The path to the local repostiory wrapped by the provided Git, or
* null.
*/
private String validateRemote(Git git) {
try {
// Get the remote configuration for "origin"
// TODO may want to allow selection of different repositories, or iterate
// over all repos?
RemoteConfig remConfig =
new RemoteConfig(git.getRepository().getConfig(), "origin");
URIish origin = remConfig.getURIs().get(0);
// Check for a github origin
if (!origin.getHost().equals("github.com")) {
throw new InvalidParameterException(
"GitHubBackup script executed from non-GitHub local repository: " +
origin.getHost());
}
return origin.getPath()
.substring(0, origin.getPath().lastIndexOf(".git"));
}
catch (URISyntaxException e) {
err("Failed to get a remote configuration.\n" + e.toString());
System.exit(1);
}
return null;
}
示例4: getSession
import org.eclipse.jgit.transport.URIish; //導入方法依賴的package包/類
@Override
public synchronized RemoteSession getSession (URIish uri, CredentialsProvider credentialsProvider, FS fs, int tms) throws TransportException {
boolean agentUsed = false;
String host = uri.getHost();
CredentialItem.StringType identityFile = null;
if (credentialsProvider != null) {
identityFile = new JGitCredentialsProvider.IdentityFileItem("Identity file for " + host, false);
if (credentialsProvider.isInteractive() && credentialsProvider.get(uri, identityFile) && identityFile.getValue() != null) {
LOG.log(Level.FINE, "Identity file for {0}: {1}", new Object[] { host, identityFile.getValue() }); //NOI18N
agentUsed = setupJSch(fs, host, identityFile, uri, true);
LOG.log(Level.FINE, "Setting cert auth for {0}, agent={1}", new Object[] { host, agentUsed }); //NOI18N
}
}
try {
LOG.log(Level.FINE, "Trying to connect to {0}, agent={1}", new Object[] { host, agentUsed }); //NOI18N
return super.getSession(uri, credentialsProvider, fs, tms);
} catch (Exception ex) {
// catch rather all exceptions. In case jsch-agent-proxy is broken again we should
// at least fall back on key/pasphrase
if (agentUsed) {
LOG.log(ex instanceof TransportException ? Level.FINE : Level.INFO, null, ex);
setupJSch(fs, host, identityFile, uri, false);
LOG.log(Level.FINE, "Trying to connect to {0}, agent={1}", new Object[] { host, false }); //NOI18N
return super.getSession(uri, credentialsProvider, fs, tms);
} else {
LOG.log(Level.FINE, "Connection failed: {0}", host); //NOI18N
throw ex;
}
}
}
示例5: 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;
}
示例6: toSshUri
import org.eclipse.jgit.transport.URIish; //導入方法依賴的package包/類
private URIish toSshUri(URIish uri) throws URISyntaxException {
String uriStr = uri.toString();
if (uri.getHost() != null && uriStr.startsWith(GERRIT_ADMIN_PROTOCOL_PREFIX)) {
return new URIish(uriStr.substring(0, GERRIT_ADMIN_PROTOCOL_PREFIX.length()));
}
String rawPath = uri.getRawPath();
if (!rawPath.endsWith("/")) {
rawPath = rawPath + "/";
}
URIish sshUri = new URIish("ssh://" + rawPath);
if (sshUri.getPort() < 0) {
sshUri = sshUri.setPort(SshAddressesModule.DEFAULT_PORT);
}
return sshUri;
}
示例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: getHostname
import org.eclipse.jgit.transport.URIish; //導入方法依賴的package包/類
protected static String getHostname(String uri) {
try {
URIish urIish = new URIish(uri);
return urIish.getHost();
} catch (URISyntaxException e) {
return null;
}
}
示例11: getSession
import org.eclipse.jgit.transport.URIish; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
public RemoteSession getSession(URIish uri, CredentialsProvider credentialsProvider, FS fs, int tms) throws TransportException {
try {
int p = uri.getPort();
if (p<0) p = 22;
Connection con = new Connection(uri.getHost(), p);
con.setTCPNoDelay(true);
con.connect(); // TODO: host key check
boolean authenticated;
if (credentialsProvider instanceof SmartCredentialsProvider) {
final SmartCredentialsProvider smart = (SmartCredentialsProvider) credentialsProvider;
StandardUsernameCredentialsCredentialItem
item = new StandardUsernameCredentialsCredentialItem("Credentials for " + uri, false);
authenticated = smart.supports(item)
&& smart.get(uri, item)
&& SSHAuthenticator.newInstance(con, item.getValue(), uri.getUser())
.authenticate(smart.listener);
} else if (credentialsProvider instanceof CredentialsProviderImpl) {
CredentialsProviderImpl sshcp = (CredentialsProviderImpl) credentialsProvider;
authenticated = SSHAuthenticator.newInstance(con, sshcp.cred).authenticate(sshcp.listener);
} else {
authenticated = false;
}
if (!authenticated && con.isAuthenticationComplete())
throw new TransportException("Authentication failure");
return wrap(con);
} catch (UnsupportedCredentialItem | IOException | InterruptedException e) {
throw new TransportException(uri,"Failed to connect",e);
}
}
示例12: load
import org.eclipse.jgit.transport.URIish; //導入方法依賴的package包/類
public boolean load(File repoFile) {
Repository repository;
Git git = null;
try {
repository = new FileRepositoryBuilder().setGitDir(repoFile)
.setMustExist(true)
.readEnvironment()
.build();
git = new Git(repository);
branchFull = repository.getFullBranch();
branchShort = repository.getBranch();
state = repository.getRepositoryState().getDescription();
for (Ref branch : git.branchList().call()) {
if (branch.getName().equals(branchFull)) {
BranchTrackingStatus bts = BranchTrackingStatus.of(repository, branchFull);
if (bts != null) {
RemoteConfig rc = new RemoteConfig(repository.getConfig(), repository.getRemoteName(bts.getRemoteTrackingBranch()));
for (URIish uri : rc.getURIs()) {
if (uri.isRemote() && uri.getHost().toLowerCase().equals("github.com")) {
remote = new GitInformationRemote();
remote.branch = bts.getRemoteTrackingBranch();
remote.uri = uri.toString();
remote.link = "http://" + uri.getHost() + uri.getPath().replace(".git", "");
remote.name = uri.getHumanishName();
remote.ahead = bts.getAheadCount();
remote.behind = bts.getBehindCount();
}
}
}
commits = loadCommits(repository, git, branch);
}
}
git.close();
} catch (IOException | GitAPIException | URISyntaxException e) {
e.printStackTrace();
isRepository = false;
if (git != null) git.close();
return false;
}
isRepository = true;
return true;
}