Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CoTA
cota-backend
Commits
5e2566f4
Commit
5e2566f4
authored
1 month ago
by
mamunozgil
Browse files
Options
Download
Email Patches
Plain Diff
repoUtil update
parent
fc3343bf
Pipeline
#10998
passed with stage
in 15 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/de/hftstuttgart/dtabackend/utils/RepoUtil.java
+13
-23
src/main/java/de/hftstuttgart/dtabackend/utils/RepoUtil.java
with
13 additions
and
23 deletions
+13
-23
src/main/java/de/hftstuttgart/dtabackend/utils/RepoUtil.java
+
13
-
23
View file @
5e2566f4
...
...
@@ -10,6 +10,8 @@ import org.springframework.stereotype.Component;
import
org.springframework.util.FileSystemUtils
;
import
org.tmatesoft.svn.core.*
;
import
org.tmatesoft.svn.core.auth.ISVNAuthenticationManager
;
import
org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions
;
import
org.tmatesoft.svn.core.wc.SVNClientManager
;
import
org.tmatesoft.svn.core.wc.SVNWCUtil
;
import
org.tmatesoft.svn.core.wc2.SvnCheckout
;
import
org.tmatesoft.svn.core.wc2.SvnOperationFactory
;
...
...
@@ -34,7 +36,7 @@ public class RepoUtil {
String
repoUrl
=
config
.
group
(
1
);
String
username
=
config
.
group
(
2
);
String
password
=
config
.
group
(
3
);
// Not used for SSH authentication
String
password
=
config
.
group
(
3
);
LOG
.
debug
(
"Cloning repository: {}"
,
repoUrl
);
...
...
@@ -57,7 +59,7 @@ public class RepoUtil {
LOG
.
debug
(
"Preparing clone..."
);
if
(
repoUrl
.
endsWith
(
".git"
))
{
// GIT R
epository
Clone
LOG
.
debug
(
"Cloning Git r
epository
..."
);
CloneCommand
cloneCommand
=
Git
.
cloneRepository
()
.
setDirectory
(
checkoutDirectory
)
.
setURI
(
repoUrl
);
...
...
@@ -67,11 +69,9 @@ public class RepoUtil {
cloneCommand
.
setCredentialsProvider
(
new
UsernamePasswordCredentialsProvider
(
username
,
password
));
}
LOG
.
debug
(
"Cloning Git repository..."
);
cloneCommand
.
call
().
close
();
LOG
.
info
(
"Git repository successfully cloned to {}"
,
checkoutDirectory
.
getAbsolutePath
());
}
else
{
// SVN Repository Clone (including svn+ssh support)
SvnOperationFactory
operationFactory
=
new
SvnOperationFactory
();
try
{
SVNURL
svnUrl
=
SVNURL
.
parseURIEncoded
(
repoUrl
);
...
...
@@ -80,37 +80,29 @@ public class RepoUtil {
checkout
.
setSource
(
SvnTarget
.
fromURL
(
svnUrl
));
checkout
.
setDepth
(
SVNDepth
.
INFINITY
);
// **Use SSH authentication if URL starts with svn+ssh://**
if
(
repoUrl
.
startsWith
(
"svn+ssh://"
))
{
LOG
.
debug
(
"Setting up SSH authentication for SVN..."
);
String
sshPrivateKeyPath
=
"/home/appuser/.ssh/id_rsa"
;
File
privateKeyFile
=
new
File
(
sshPrivateKeyPath
);
LOG
.
debug
(
"Using SSH authentication for SVN..."
);
File
privateKeyFile
=
new
File
(
"/home/appuser/.ssh/id_rsa"
);
if
(!
privateKeyFile
.
exists
())
{
LOG
.
error
(
"SSH private key not found at: {}"
,
sshP
rivateKeyPath
);
LOG
.
error
(
"SSH private key not found at: {}"
,
p
rivateKey
File
.
getAbsolute
Path
()
);
throw
new
SVNException
(
SVNErrorMessage
.
create
(
SVNErrorCode
.
AUTHN_CREDS_UNAVAILABLE
,
"SSH key not found"
));
}
ISVNAuthenticationManager
authManager
=
SVNWCUtil
.
createDefaultAuthenticationManager
(
new
File
(
"/home/appuser/.ssh/id_rsa"
),
// Explicit SSH Key
username
,
null
,
new
File
(
"/home/appuser/.ssh/known_hosts"
),
// Explicit Known Hosts
false
);
privateKeyFile
,
username
,
new
char
[
0
],
null
,
false
);
DefaultSVNOptions
options
=
SVNWCUtil
.
createDefaultOptions
(
true
);
SVNClientManager
clientManager
=
SVNClientManager
.
newInstance
(
options
,
authManager
);
operationFactory
.
setAuthenticationManager
(
authManager
);
}
LOG
.
debug
(
"Performing SVN checkout..."
);
checkout
.
run
();
LOG
.
info
(
"SVN repository successfully cloned to {}"
,
checkoutDirectory
.
getAbsolutePath
());
}
finally
{
operationFactory
.
dispose
();
}
}
// Handle subdirectory case
if
(!
subDir
.
isEmpty
())
{
File
sourceSubDir
=
new
File
(
checkoutDirectory
,
subDir
);
if
(
sourceSubDir
.
exists
())
{
...
...
@@ -121,10 +113,8 @@ public class RepoUtil {
}
LOG
.
debug
(
"Repository successfully cloned from {} to {}"
,
repoUrl
,
targetDirectory
);
}
catch
(
IOException
|
GitAPIException
|
SVNException
e
)
{
LOG
.
error
(
"Error while cloning repository: "
+
repoUrl
,
e
);
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets