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
09af96c7
Commit
09af96c7
authored
2 months ago
by
mamunozgil
Browse files
Options
Download
Email Patches
Plain Diff
repoUtil refactoring
parent
f8255ef9
Pipeline
#10979
passed with stage
in 18 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
+69
-72
src/main/java/de/hftstuttgart/dtabackend/utils/RepoUtil.java
with
69 additions
and
72 deletions
+69
-72
src/main/java/de/hftstuttgart/dtabackend/utils/RepoUtil.java
+
69
-
72
View file @
09af96c7
...
...
@@ -13,9 +13,6 @@ import org.tmatesoft.svn.core.SVNException;
import
org.tmatesoft.svn.core.SVNURL
;
import
org.tmatesoft.svn.core.auth.BasicAuthenticationManager
;
import
org.tmatesoft.svn.core.auth.ISVNAuthenticationManager
;
import
org.tmatesoft.svn.core.io.SVNRepository
;
import
org.tmatesoft.svn.core.io.SVNRepositoryFactory
;
import
org.tmatesoft.svn.core.wc.SVNUpdateClient
;
import
org.tmatesoft.svn.core.wc.SVNWCUtil
;
import
org.tmatesoft.svn.core.wc2.SvnCheckout
;
import
org.tmatesoft.svn.core.wc2.SvnOperationFactory
;
...
...
@@ -23,7 +20,6 @@ import org.tmatesoft.svn.core.wc2.SvnTarget;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.util.regex.Matcher
;
...
...
@@ -35,85 +31,86 @@ public class RepoUtil {
public
RepoUtil
()
{}
public
void
cloneRepository
(
Matcher
config
,
String
targetPath
,
String
subDir
)
{
LOG
.
debug
(
String
.
format
(
"cloning repository: %s"
,
config
.
group
(
1
)));
if
(!
config
.
matches
())
{
LOG
.
error
(
"Invalid repository URL format."
);
return
;
}
String
repoUrl
=
config
.
group
(
1
);
String
username
=
config
.
group
(
2
);
String
password
=
config
.
group
(
3
);
LOG
.
debug
(
String
.
format
(
"Cloning repository: %s"
,
repoUrl
));
File
targetDirectory
=
new
File
(
targetPath
);
if
(
targetDirectory
.
exists
())
{
LOG
.
debug
(
"
clone t
arget directory exist
ing yet
, deleting
now
"
);
LOG
.
debug
(
"
T
arget directory exist
s
, deleting
it.
"
);
FileSystemUtils
.
deleteRecursively
(
targetDirectory
);
}
File
checkoutDirectory
=
targetDirectory
;
//if an optional directory parameter was given
if
(
subDir
!=
""
)
{
//create companion checkout dir "targetPath"+"_checkout"
checkoutDirectory
=
new
File
(
targetPath
+
"_checkout"
);
if
(!
subDir
.
isEmpty
())
{
checkoutDirectory
=
new
File
(
targetPath
+
"_checkout"
);
if
(
checkoutDirectory
.
exists
())
{
LOG
.
debug
(
"
clone c
heckout directory exist
ing yet
, deleting
now
"
);
LOG
.
debug
(
"
C
heckout directory exist
s
, deleting
it.
"
);
FileSystemUtils
.
deleteRecursively
(
checkoutDirectory
);
}
}
try
{
LOG
.
debug
(
"preparing clone"
);
if
(
config
.
group
(
1
).
endsWith
(
".git"
))
{
LOG
.
debug
(
"Preparing clone..."
);
if
(
repoUrl
.
endsWith
(
".git"
))
{
CloneCommand
cloneCommand
=
Git
.
cloneRepository
()
.
setDirectory
(
checkoutDirectory
)
.
setURI
(
config
.
group
(
1
)
);
.
setURI
(
repoUrl
);
if
(!
config
.
group
(
2
).
equals
(
"none"
)
&&
!
config
.
group
(
3
).
equals
(
"none"
))
{
LOG
.
debug
(
"
s
etting credentials"
);
cloneCommand
.
setCredentialsProvider
(
new
UsernamePasswordCredentialsProvider
(
config
.
group
(
2
),
config
.
group
(
3
)
));
if
(!
"none"
.
equals
(
username
)
&&
!
"none"
.
equals
(
password
))
{
LOG
.
debug
(
"
S
etting
Git
credentials
.
"
);
cloneCommand
.
setCredentialsProvider
(
new
UsernamePasswordCredentialsProvider
(
username
,
password
));
}
LOG
.
debug
(
"
c
loning..."
);
LOG
.
debug
(
"
C
loning
Git repository
..."
);
cloneCommand
.
call
().
close
();
}
else
{
URL
sourceUrl
=
new
URL
(
config
.
group
(
1
));
SVNURL
url
=
SVNURL
.
create
(
sourceUrl
.
getProtocol
(),
null
,
sourceUrl
.
getHost
(),
sourceUrl
.
getPort
(),
sourceUrl
.
getPath
(),
false
);
}
else
{
SvnOperationFactory
operationFactory
=
new
SvnOperationFactory
();
try
{
URL
sourceUrl
=
new
URL
(
repoUrl
);
SVNURL
svnUrl
=
SVNURL
.
create
(
sourceUrl
.
getProtocol
(),
null
,
sourceUrl
.
getHost
(),
sourceUrl
.
getPort
(),
sourceUrl
.
getPath
(),
false
);
SvnCheckout
checkout
=
operationFactory
.
createCheckout
();
checkout
.
setSingleTarget
(
SvnTarget
.
fromFile
(
new
File
(
targetPath
)));
checkout
.
setSource
(
SvnTarget
.
fromURL
(
url
));
String
protocol
=
url
.
getProtocol
();
if
(!
config
.
group
(
2
).
equals
(
"none"
)
&&
!
config
.
group
(
3
).
equals
(
"none"
))
{
if
(
protocol
.
equals
(
"https"
))
{
LOG
.
debug
(
"Setting SVN credentials for HTTPS checkout with username/password"
);
operationFactory
.
setAuthenticationManager
(
new
BasicAuthenticationManager
(
config
.
group
(
2
),
config
.
group
(
3
)));
}
else
if
(
protocol
.
equals
(
"svn+ssh"
))
{
LOG
.
debug
(
"Setting credentials for SVN+SSH Authentication with username/password"
);
//ISVNAuthenticationManager authManager = new BasicAuthenticationManager(new SVNAuthentication[] { new SVNSSHAuthentication(username, password, -1, false)});//SVNWCUtil.createDefaultAuthenticationManager(username, password);
ISVNAuthenticationManager
authManager
=
SVNWCUtil
.
createDefaultAuthenticationManager
(
config
.
group
(
2
),
config
.
group
(
3
).
toCharArray
());
checkout
.
setSource
(
SvnTarget
.
fromURL
(
svnUrl
));
checkout
.
setDepth
(
SVNDepth
.
INFINITY
);
if
(!
"none"
.
equals
(
username
)
&&
!
"none"
.
equals
(
password
))
{
if
(
repoUrl
.
startsWith
(
"https"
))
{
LOG
.
debug
(
"Setting SVN credentials for HTTPS."
);
operationFactory
.
setAuthenticationManager
(
new
BasicAuthenticationManager
(
username
,
password
));
}
else
if
(
repoUrl
.
startsWith
(
"svn+ssh"
))
{
LOG
.
debug
(
"Setting SVN credentials for SSH."
);
ISVNAuthenticationManager
authManager
=
SVNWCUtil
.
createDefaultAuthenticationManager
(
username
,
password
.
toCharArray
());
operationFactory
.
setAuthenticationManager
(
authManager
);
}
}
LOG
.
debug
(
"Performing SVN checkout..."
);
checkout
.
run
();
LOG
.
debug
(
"SVN checkout completed successfully."
);
}
//if an optional directory parameter was given
if
(
subDir
!=
""
)
{
//copy appropriate path from checkout directory to target directory
FileSystemUtils
.
copyRecursively
(
new
File
(
checkoutDirectory
+
subDir
),
new
File
(
targetPath
));
}
finally
{
operationFactory
.
dispose
();
}
LOG
.
debug
(
String
.
format
(
"cloned from %s via %s to %s"
,
config
.
group
(
1
),
checkoutDirectory
+
subDir
,
targetDirectory
));
}
catch
(
IOException
e
)
{
LOG
.
error
(
String
.
format
(
"Error while cloning from %s: could not copy to unit test dir"
,
config
.
group
(
1
)),
e
);
if
(!
subDir
.
isEmpty
())
{
File
sourceSubDir
=
new
File
(
checkoutDirectory
,
subDir
);
if
(
sourceSubDir
.
exists
())
{
FileSystemUtils
.
copyRecursively
(
sourceSubDir
,
targetDirectory
);
}
else
{
LOG
.
error
(
"Specified subdirectory does not exist."
);
}
catch
(
GitAPIException
e
)
{
LOG
.
error
(
String
.
format
(
"Error while cloning from %s: could not read from Git"
,
config
.
group
(
1
)),
e
);
}
catch
(
SVNException
e
)
{
LOG
.
error
(
String
.
format
(
"Error while cloning from %s: could not read from Svn"
,
config
.
group
(
1
)),
e
);
LOG
.
debug
(
String
.
format
(
"Repository cloned from %s to %s"
,
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