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
8aabe7e6
Commit
8aabe7e6
authored
1 year ago
by
Lückemeyer
Browse files
Options
Download
Email Patches
Plain Diff
added solution idea comments for issue #8
parent
b80f7087
master
amg-dev-volumes
amg-svn+ssh
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/de/hftstuttgart/dtabackend/utils/JGitUtil.java
+75
-53
src/main/java/de/hftstuttgart/dtabackend/utils/JGitUtil.java
with
75 additions
and
53 deletions
+75
-53
src/main/java/de/hftstuttgart/dtabackend/utils/JGitUtil.java
+
75
-
53
View file @
8aabe7e6
package
de.hftstuttgart.dtabackend.utils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.eclipse.jgit.api.CloneCommand
;
import
org.eclipse.jgit.api.Git
;
import
org.eclipse.jgit.api.errors.GitAPIException
;
import
org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.FileSystemUtils
;
import
java.io.File
;
import
java.util.regex.Matcher
;
@Component
public
class
JGitUtil
{
private
static
final
Logger
LOG
=
LogManager
.
getLogger
(
JGitUtil
.
class
);
public
JGitUtil
()
{}
public
void
cloneRepository
(
Matcher
config
,
String
targetPath
)
{
LOG
.
debug
(
String
.
format
(
"cloning repository: %s"
,
config
.
group
(
1
)));
File
targetDirectory
=
new
File
(
targetPath
);
if
(
targetDirectory
.
exists
())
{
LOG
.
debug
(
"clone target directory existing yet, deleting now"
);
FileSystemUtils
.
deleteRecursively
(
targetDirectory
);
}
try
{
LOG
.
debug
(
"preparing clone"
);
CloneCommand
cloneCommand
=
Git
.
cloneRepository
()
.
setDirectory
(
targetDirectory
)
.
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
();
}
catch
(
GitAPIException
e
)
{
LOG
.
error
(
String
.
format
(
"Error while cloning from %s"
,
config
.
group
(
1
)),
e
);
}
LOG
.
debug
(
String
.
format
(
"cloned from %s to %s"
,
config
.
group
(
1
),
targetDirectory
));
}
}
package
de.hftstuttgart.dtabackend.utils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.eclipse.jgit.api.CloneCommand
;
import
org.eclipse.jgit.api.Git
;
import
org.eclipse.jgit.api.errors.GitAPIException
;
import
org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.FileSystemUtils
;
import
java.io.File
;
import
java.util.regex.Matcher
;
@Component
public
class
JGitUtil
{
private
static
final
Logger
LOG
=
LogManager
.
getLogger
(
JGitUtil
.
class
);
public
JGitUtil
()
{}
public
void
cloneRepository
(
Matcher
config
,
String
targetPath
)
{
LOG
.
debug
(
String
.
format
(
"cloning repository: %s"
,
config
.
group
(
1
)));
File
targetDirectory
=
new
File
(
targetPath
);
if
(
targetDirectory
.
exists
())
{
LOG
.
debug
(
"clone target directory existing yet, deleting now"
);
FileSystemUtils
.
deleteRecursively
(
targetDirectory
);
}
//create companion checkout dir "targetPath"+"_checkout"
File
checkoutDirectory
=
new
File
(
targetPath
+
"_checkout"
);
if
(
targetDirectory
.
exists
())
{
LOG
.
debug
(
"clone checkout directory existing yet, deleting now"
);
FileSystemUtils
.
deleteRecursively
(
checkoutDirectory
);
}
try
{
//check group(1) for possible directory
//if(!config.group(1).endsWith(".git"))
//cut off the directory part
//pos=instr(".git/")
//cloneURI=config.group(1).substr(1, pos+3)
//else
//cloneURI=config.group(1)
LOG
.
debug
(
"preparing clone"
);
CloneCommand
cloneCommand
=
Git
.
cloneRepository
()
.
setDirectory
(
checkoutDirectory
)
//.setURI(cloneURI)
.
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
();
//copy appropriate path from checkout directory to target directory
//if(!config.group(1).endsWith(".git"))
//copy checkout+config.group(1).substr(pos+4) to target directory
//else
//copy checkout directory to target directory directly
}
catch
(
GitAPIException
e
)
{
LOG
.
error
(
String
.
format
(
"Error while cloning from %s"
,
config
.
group
(
1
)),
e
);
}
LOG
.
debug
(
String
.
format
(
"cloned from %s to %s"
,
config
.
group
(
1
),
targetDirectory
));
}
}
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