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
e8ed1d99
Commit
e8ed1d99
authored
8 months ago
by
Lückemeyer
Browse files
Options
Download
Email Patches
Plain Diff
cleaned repo handling
parent
d8949da8
master
amg-dev-volumes
amg-svn+ssh
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/main/java/de/hftstuttgart/dtabackend/rest/v1/task/TaskUpload.java
+2
-2
...a/de/hftstuttgart/dtabackend/rest/v1/task/TaskUpload.java
src/main/java/de/hftstuttgart/dtabackend/rest/v1/unittest/UnitTestUpload.java
+3
-3
...stuttgart/dtabackend/rest/v1/unittest/UnitTestUpload.java
src/main/java/de/hftstuttgart/dtabackend/utils/ExecuteTestUtil.java
+2
-2
...ava/de/hftstuttgart/dtabackend/utils/ExecuteTestUtil.java
src/main/java/de/hftstuttgart/dtabackend/utils/RepoUtil.java
+119
-0
src/main/java/de/hftstuttgart/dtabackend/utils/RepoUtil.java
with
126 additions
and
7 deletions
+126
-7
src/main/java/de/hftstuttgart/dtabackend/rest/v1/task/TaskUpload.java
+
2
-
2
View file @
e8ed1d99
...
...
@@ -31,13 +31,13 @@ import jakarta.servlet.annotation.MultipartConfig;
public
class
TaskUpload
{
private
static
final
Logger
LOG
=
LogManager
.
getLogger
(
TaskUpload
.
class
);
private
final
JGit
Util
jGitUtil
;
private
final
Repo
Util
jGitUtil
;
private
final
Path
testTmpPath
;
private
final
ExecuteTestUtil
executeTestUtil
;
public
TaskUpload
(
Environment
env
,
JGit
Util
jGitUtil
,
Repo
Util
jGitUtil
,
ExecuteTestUtil
executeTestUtil
)
{
this
.
jGitUtil
=
jGitUtil
;
...
...
This diff is collapsed.
Click to expand it.
src/main/java/de/hftstuttgart/dtabackend/rest/v1/unittest/UnitTestUpload.java
+
3
-
3
View file @
e8ed1d99
package
de.hftstuttgart.dtabackend.rest.v1.unittest
;
import
de.hftstuttgart.dtabackend.utils.
JGit
Util
;
import
de.hftstuttgart.dtabackend.utils.
Repo
Util
;
import
de.hftstuttgart.dtabackend.utils.RegexUtil
;
import
org.apache.logging.log4j.LogManager
;
...
...
@@ -30,10 +30,10 @@ import java.util.regex.Pattern;
public
class
UnitTestUpload
{
private
static
final
Logger
LOG
=
LogManager
.
getLogger
(
UnitTestUpload
.
class
);
private
final
JGit
Util
jGitUtil
;
private
final
Repo
Util
jGitUtil
;
private
final
String
assignmentBasePath
;
public
UnitTestUpload
(
Environment
env
,
JGit
Util
jGitUtil
)
{
public
UnitTestUpload
(
Environment
env
,
Repo
Util
jGitUtil
)
{
this
.
jGitUtil
=
jGitUtil
;
Path
p
=
Paths
.
get
(
env
.
getProperty
(
"data.dir"
),
env
.
getProperty
(
"data.dir.test.folder.name"
));
...
...
This diff is collapsed.
Click to expand it.
src/main/java/de/hftstuttgart/dtabackend/utils/ExecuteTestUtil.java
+
2
-
2
View file @
e8ed1d99
...
...
@@ -26,7 +26,7 @@ import java.util.regex.Pattern;
public
class
ExecuteTestUtil
{
private
static
final
Logger
LOG
=
LogManager
.
getLogger
(
ExecuteTestUtil
.
class
);
private
final
JGit
Util
jGitUtil
;
private
final
Repo
Util
jGitUtil
;
private
final
DockerUtil
dockerUtil
;
private
final
String
assignmentBasePath
;
private
final
Path
testTmpPathHost
;
...
...
@@ -34,7 +34,7 @@ public class ExecuteTestUtil {
public
ExecuteTestUtil
(
Environment
env
,
JGit
Util
jGitUtil
,
Repo
Util
jGitUtil
,
DockerUtil
dockerUtil
)
{
this
.
jGitUtil
=
jGitUtil
;
...
...
This diff is collapsed.
Click to expand it.
src/main/java/de/hftstuttgart/dtabackend/utils/
JGit
Util.java
→
src/main/java/de/hftstuttgart/dtabackend/utils/
Repo
Util.java
+
119
-
0
View file @
e8ed1d99
...
...
@@ -8,17 +8,31 @@ import org.eclipse.jgit.api.errors.GitAPIException;
import
org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.FileSystemUtils
;
import
org.tmatesoft.svn.core.SVNDepth
;
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
;
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
;
@Component
public
class
JGit
Util
{
public
class
Repo
Util
{
private
static
final
Logger
LOG
=
LogManager
.
getLogger
(
JGit
Util
.
class
);
private
static
final
Logger
LOG
=
LogManager
.
getLogger
(
Repo
Util
.
class
);
public
JGit
Util
()
{}
public
Repo
Util
()
{}
public
void
cloneRepository
(
Matcher
config
,
String
targetPath
,
String
subDir
)
{
LOG
.
debug
(
String
.
format
(
"cloning repository: %s"
,
config
.
group
(
1
)));
...
...
@@ -42,19 +56,48 @@ public class JGitUtil {
}
try
{
LOG
.
debug
(
"preparing clone"
);
CloneCommand
cloneCommand
=
Git
.
cloneRepository
()
.
setDirectory
(
checkoutDirectory
)
.
setURI
(
config
.
group
(
1
));
LOG
.
debug
(
"preparing clone"
);
if
(!
config
.
group
(
2
).
equals
(
"none"
)
&&
!
config
.
group
(
3
).
equals
(
"none"
))
{
LOG
.
debug
(
"setting credentials"
);
cloneCommand
.
setCredentialsProvider
(
new
UsernamePasswordCredentialsProvider
(
config
.
group
(
2
),
config
.
group
(
3
)));
}
if
(
config
.
group
(
1
).
endsWith
(
".git"
))
{
CloneCommand
cloneCommand
=
Git
.
cloneRepository
()
.
setDirectory
(
checkoutDirectory
)
.
setURI
(
config
.
group
(
1
));
if
(!
config
.
group
(
2
).
equals
(
"none"
)
&&
!
config
.
group
(
3
).
equals
(
"none"
))
{
LOG
.
debug
(
"setting credentials"
);
cloneCommand
.
setCredentialsProvider
(
new
UsernamePasswordCredentialsProvider
(
config
.
group
(
2
),
config
.
group
(
3
)));
}
LOG
.
debug
(
"cloning..."
);
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
);
SvnOperationFactory
operationFactory
=
new
SvnOperationFactory
();
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
());
operationFactory
.
setAuthenticationManager
(
authManager
);
}
}
LOG
.
debug
(
"cloning..."
);
cloneCommand
.
call
().
close
();
checkout
.
run
();
LOG
.
debug
(
"SVN checkout completed successfully."
);
}
//if an optional directory parameter was given
if
(
subDir
!=
""
)
{
...
...
@@ -69,5 +112,8 @@ public class JGitUtil {
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
);
}
}
}
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