Clone repository through Java (jGit)

92 views
Skip to first unread message

João Caramujo

unread,
Oct 10, 2017, 1:16:04 PM10/10/17
to Drools Usage
Hey all (again),
Has anyone been able to clone a repository through Java?

I did it through the command prompt but I've been trying to build a simple java application that uses jGit to clone a repository and I still can't get it working.

I don't know what URI am I supposed to pass as argument to the method

Git git = Git.cloneRepository()
.setURI("???") (or .setRemote(...) ?)
.setCredentialsProvider(new UsernamePasswordCredentialsProvider("username", "password"))
.setDirectory(localPath)
.call();

Thanks in advance,

Cheers,
João

Alexandre Porcelli

unread,
Oct 13, 2017, 7:04:17 AM10/13/17
to drools...@googlegroups.com
Something like this:

Git.cloneRepository()
.setURI("ssh://username@localhost:8001/reponame")
.setDirectory(workingDirectory)
.setTransportConfigCallback(transport -> {
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(new JschConfigSessionFactory() {
@Override
protected void configure(Host host, Session session) {
session.setPassword("password");
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
config.put("Host", "localhost");
config.put("VerifyHostKeyDNS", "no");
config.put("HostKeyAlgorithms", "+ssh-dss");
config.put("UserKnownHostsFile", "/dev/null");
session.setConfig(config);
}
});
})
.setCredentialsProvider(new
UsernamePasswordCredentialsProvider("username", "password"))
.call()
Regards,
___________________
Alexandre Porcelli
F: +1 (978) 844-8695
http://porcelli.me
> --
> You received this message because you are subscribed to the Google Groups
> "Drools Usage" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to drools-usage...@googlegroups.com.
> To post to this group, send email to drools...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/drools-usage/6b8017c3-f787-439d-a77b-8d70d686a4d6%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages