本文整理匯總了Java中org.eclipse.jgit.util.FS類的典型用法代碼示例。如果您正苦於以下問題:Java FS類的具體用法?Java FS怎麽用?Java FS使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FS類屬於org.eclipse.jgit.util包,在下文中一共展示了FS類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: pushToRepository
import org.eclipse.jgit.util.FS; //導入依賴的package包/類
/**
* Push all changes and tags to given remote.
*
* @param git
* instance.
* @param remote
* to be used.
* @param passphrase
* to access private key.
* @param privateKey
* file location.
*
* @return List of all results of given push.
*/
public Iterable<PushResult> pushToRepository(Git git, String remote, String passphrase, Path privateKey) {
SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host host, Session session) {
session.setUserInfo(new PassphraseUserInfo(passphrase));
}
@Override
protected JSch createDefaultJSch(FS fs) throws JSchException {
if (privateKey != null) {
JSch defaultJSch = super.createDefaultJSch(fs);
defaultJSch.addIdentity(privateKey.toFile().getAbsolutePath());
return defaultJSch;
} else {
return super.createDefaultJSch(fs);
}
}
};
try {
return git.push()
.setRemote(remote)
.setPushAll()
.setPushTags()
.setTransportConfigCallback(transport -> {
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(sshSessionFactory);
})
.call();
} catch (GitAPIException e) {
throw new IllegalStateException(e);
}
}
示例2: initRepository
import org.eclipse.jgit.util.FS; //導入依賴的package包/類
@SneakyThrows
protected void initRepository() {
File repositoryFolder = rootDirectory;
if (repositoryFolder.exists() && isGitRepository(getGitDir(), FS.DETECTED)) {
return;
}
repositoryFolder.mkdirs();
repositoryFolder.deleteOnExit();
cloneRepository()
.setURI(gitProperties.getUri())
.setDirectory(repositoryFolder)
.setCredentialsProvider(createCredentialsProvider())
.call().close();
}
示例3: initSessionFactory
import org.eclipse.jgit.util.FS; //導入依賴的package包/類
private void initSessionFactory() {
JschConfigSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure(Host host, Session session) {
session.setConfig("StrictHostKeyChecking", "no");
}
@Override
protected JSch createDefaultJSch(FS fs) throws JSchException {
JSch jSch = super.createDefaultJSch(fs);
// apply customized private key
if (privateKeyPath != null) {
jSch.removeAllIdentity();
jSch.addIdentity(privateKeyPath.toString());
}
return jSch;
}
};
transportConfigCallback = transport -> {
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(sshSessionFactory);
};
}
示例4: VirtualHostConfig
import org.eclipse.jgit.util.FS; //導入依賴的package包/類
@Inject
VirtualHostConfig(SitePaths sitePaths) {
File configFile = sitePaths.etc_dir.resolve("virtualhost.config").toFile();
FileBasedConfig fileConfig = new FileBasedConfig(configFile, FS.DETECTED);
config = fileConfig;
try {
fileConfig.load();
} catch (IOException | ConfigInvalidException e) {
log.error("Unable to open or parse " + configFile + ": virtual domains are disabled", e);
enabled = false;
defaultProjects = new String[0];
return;
}
defaultProjects = config.getStringList("default", null, "projects");
enabled = !config.getSubsections("server").isEmpty() || defaultProjects.length > 0;
}
示例5: createSession
import org.eclipse.jgit.util.FS; //導入依賴的package包/類
private Session createSession(CredentialsProvider credentialsProvider,
FS fs, String user, final String pass, String host, int port,
final OpenSshConfig.Host hc) throws JSchException {
final Session session = createSession(credentialsProvider, hc, user, host, port, fs);
// We retry already in getSession() method. JSch must not retry
// on its own.
session.setConfig("MaxAuthTries", "1"); //$NON-NLS-1$ //$NON-NLS-2$
if (pass != null)
session.setPassword(pass);
final String strictHostKeyCheckingPolicy = hc
.getStrictHostKeyChecking();
if (strictHostKeyCheckingPolicy != null)
session.setConfig("StrictHostKeyChecking", //$NON-NLS-1$
strictHostKeyCheckingPolicy);
final String pauth = hc.getPreferredAuthentications();
if (pauth != null)
session.setConfig("PreferredAuthentications", pauth); //$NON-NLS-1$
if (credentialsProvider != null && !(credentialsProvider instanceof PrivateKeyCredentialsProvider)
&& (!hc.isBatchMode() || !credentialsProvider.isInteractive())) {
session.setUserInfo(new CredentialsProviderUserInfo(session,
credentialsProvider));
}
configure(hc, session);
return session;
}
示例6: knownHosts
import org.eclipse.jgit.util.FS; //導入依賴的package包/類
private static void knownHosts(final JSch sch, FS fs) throws JSchException {
final File home = fs.userHome();
if (home == null)
return;
final File known_hosts = new File(new File(home, ".ssh"), "known_hosts"); //$NON-NLS-1$ //$NON-NLS-2$
try {
final FileInputStream in = new FileInputStream(known_hosts);
try {
sch.setKnownHosts(in);
} finally {
in.close();
}
} catch (FileNotFoundException none) {
// Oh well. They don't have a known hosts in home.
} catch (IOException err) {
// Oh well. They don't have a known hosts in home.
}
}
示例7: accept
import org.eclipse.jgit.util.FS; //導入依賴的package包/類
@Override
public boolean accept(final File folder) {
if (!folder.isDirectory()) {
return false;
}
final String path = folder.getName();
if (path.equals(METADATA_FOLDER)) {
return false;
}
if (!path.equals(Constants.DOT_GIT)) {
return true;
}
return !FileKey.isGitRepository(folder, FS.DETECTED);
}
示例8: getPublicKeys
import org.eclipse.jgit.util.FS; //導入依賴的package包/類
private static List<String> getPublicKeys() throws Exception {
return new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host hc, Session session) {
}
List<String> getPublicKeys() throws Exception {
JSch jSch = createDefaultJSch(FS.DETECTED);
List<String> keys = new ArrayList<>();
for (Object o : jSch.getIdentityRepository().getIdentities()) {
Identity i = (Identity) o;
KeyPair keyPair = KeyPair.load(jSch, i.getName(), null);
StringBuilder sb = new StringBuilder();
try (StringBuilderWriter sbw = new StringBuilderWriter(sb);
OutputStream os = new WriterOutputStream(sbw, "UTF-8")) {
keyPair.writePublicKey(os, keyPair.getPublicKeyComment());
} finally {
keyPair.dispose();
}
keys.add(sb.toString().trim());
}
return keys;
}
}.getPublicKeys();
}
示例9: isValidGitRepository
import org.eclipse.jgit.util.FS; //導入依賴的package包/類
/**
* Checks if given folder is a git repository
*
* @param folder
* to check
*
* @return true if it is a git repository, false otherwise.
*/
public boolean isValidGitRepository(Path folder) {
if (Files.exists(folder) && Files.isDirectory(folder)) {
// If it has been at least initialized
if (RepositoryCache.FileKey.isGitRepository(folder.toFile(), FS.DETECTED)) {
// we are assuming that the clone worked at that time, caller should call hasAtLeastOneReference
return true;
} else {
return false;
}
} else {
return false;
}
}
示例10: pullFromRepository
import org.eclipse.jgit.util.FS; //導入依賴的package包/類
/**
* Pull repository from current branch and remote branch with same name as current
*
* @param git
* instance.
* @param remote
* to be used.
* @param remoteBranch
* to use.
* @param passphrase
* to access private key.
* @param privateKey
* file location.
*/
public PullResult pullFromRepository(final Git git, final String remote, String remoteBranch, final String passphrase,
final Path privateKey) {
SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host host, Session session) {
session.setUserInfo(new PassphraseUserInfo(passphrase));
}
@Override
protected JSch createDefaultJSch(FS fs) throws JSchException {
if (privateKey != null) {
JSch defaultJSch = super.createDefaultJSch(fs);
defaultJSch.addIdentity(privateKey.toFile().getAbsolutePath());
return defaultJSch;
} else {
return super.createDefaultJSch(fs);
}
}
};
try {
return git.pull()
.setRemote(remote)
.setRemoteBranchName(remoteBranch)
.setTransportConfigCallback(transport -> {
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(sshSessionFactory);
})
.call();
} catch (GitAPIException e) {
throw new IllegalStateException(e);
}
}
示例11: cloneRepository
import org.eclipse.jgit.util.FS; //導入依賴的package包/類
/**
* Clones a private remote git repository. Caller is responsible of closing git repository.
*
* @param remoteUrl
* to connect.
* @param localPath
* where to clone the repo.
* @param passphrase
* to access private key.
* @param privateKey
* file location. If null default (~.ssh/id_rsa) location is used.
*
* @return Git instance. Caller is responsible to close the connection.
*/
public Git cloneRepository(final String remoteUrl, final Path localPath, final String passphrase,
final Path privateKey) {
SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host host, Session session) {
session.setUserInfo(new PassphraseUserInfo(passphrase));
}
@Override
protected JSch createDefaultJSch(FS fs) throws JSchException {
if (privateKey != null) {
JSch defaultJSch = super.createDefaultJSch(fs);
defaultJSch.addIdentity(privateKey.toFile().getAbsolutePath());
return defaultJSch;
} else {
return super.createDefaultJSch(fs);
}
}
};
try {
return Git.cloneRepository()
.setURI(remoteUrl)
.setTransportConfigCallback(transport -> {
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(sshSessionFactory);
})
.setDirectory(localPath.toFile())
.call();
} catch (GitAPIException e) {
throw new IllegalStateException(e);
}
}
示例12: saveSecure
import org.eclipse.jgit.util.FS; //導入依賴的package包/類
private static void saveSecure(final FileBasedConfig sec) throws IOException {
if (FileUtil.modified(sec)) {
final byte[] out = Constants.encode(sec.toText());
final File path = sec.getFile();
final LockFile lf = new LockFile(path, FS.DETECTED);
if (!lf.lock()) {
throw new IOException("Cannot lock " + path);
}
try {
FileUtil.chmod(0600, new File(path.getParentFile(), path.getName()
+ ".lock"));
lf.write(out);
if (!lf.commit()) {
throw new IOException("Cannot commit write to " + path);
}
} finally {
lf.unlock();
}
}
}
示例13: CiDataSourceProvider
import org.eclipse.jgit.util.FS; //導入依賴的package包/類
@Inject
protected CiDataSourceProvider(SitePaths site,
@PluginName String pluginName,
@Nullable MetricMaker metrics,
Context ctx,
CiDataSourceType dst) {
File file = site.gerrit_config.toFile();
FileBasedConfig cfg = new FileBasedConfig(file, FS.DETECTED);
try {
cfg.load();
} catch (IOException | ConfigInvalidException e) {
throw new ProvisionException(e.getMessage(), e);
}
this.config = new PluginConfig(pluginName, cfg);
this.metrics = metrics;
this.ctx = ctx;
this.dst = dst;
}
示例14: getJSch
import org.eclipse.jgit.util.FS; //導入依賴的package包/類
@Override
protected JSch getJSch(Host hc, FS fs) throws JSchException {
JSch jsch = super.getJSch(hc, fs);
if (config.getKeyFile() != null) {
jsch.addIdentity(config.getKeyFile().toString());
}
if (!config.getVerifyHostKey()) {
jsch.setHostKeyRepository(new PromiscuousHostKeyRepository());
}
return jsch;
}
示例15: initSsh
import org.eclipse.jgit.util.FS; //導入依賴的package包/類
public static void initSsh(TestAccount a) {
final Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
JSch.setConfig(config);
// register a JschConfigSessionFactory that adds the private key as identity
// to the JSch instance of JGit so that SSH communication via JGit can
// succeed
SshSessionFactory.setInstance(
new JschConfigSessionFactory() {
@Override
protected void configure(Host hc, Session session) {
try {
final JSch jsch = getJSch(hc, FS.DETECTED);
jsch.addIdentity("KeyPair", a.privateKey(), a.sshKey.getPublicKeyBlob(), null);
} catch (JSchException e) {
throw new RuntimeException(e);
}
}
});
}