This is the codeAbility Sharing Platform! Learn more about the
codeAbility Sharing Platform
.
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
codeAbility Sharing Platform
Manage
Activity
Members
Labels
Plan
Issues
43
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
development
sharing
codeAbility Sharing Platform
Commits
9809b90b
Commit
9809b90b
authored
2 years ago
by
Daniel Crazzolara
Browse files
Options
Downloads
Patches
Plain Diff
Fixed various paths to tmp files
parent
ca8a1962
2 merge requests
!188
Merging Peer Reviewing et. al to Master
,
!164
211 peer reviewing functionality
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/at/ac/uibk/gitsearch/service/ExerciseService.java
+18
-12
18 additions, 12 deletions
...in/java/at/ac/uibk/gitsearch/service/ExerciseService.java
src/main/java/at/ac/uibk/gitsearch/service/GitlabService.java
+2
-2
2 additions, 2 deletions
...main/java/at/ac/uibk/gitsearch/service/GitlabService.java
with
20 additions
and
14 deletions
src/main/java/at/ac/uibk/gitsearch/service/ExerciseService.java
+
18
−
12
View file @
9809b90b
...
...
@@ -98,7 +98,7 @@ public class ExerciseService {
* - Copy, commit and push files to the new repository
*
* @param exerciseInfo of the exercise to import
* @param exerciseToken of the stored exercise (in
'/tmp'
directory) to import
* @param exerciseToken of the stored exercise (in
the temporary
directory) to import
*/
public
void
importExercise
(
ArtemisExerciseInfo
exerciseInfo
,
String
exerciseToken
,
Integer
gitlabGroupId
)
throws
GitLabApiException
,
GitAPIException
,
IOException
,
ArtemisImportError
{
...
...
@@ -109,11 +109,11 @@ public class ExerciseService {
Group
group
=
gitlabService
.
getGroupById
(
gitlabGroupId
);
String
repoUrl
=
gitlabService
.
createRepository
(
group
,
exerciseInfo
.
getTitle
());
Repository
repo
=
gitlabService
.
checkoutRepo
(
repoUrl
);
gitlabService
.
commitAndPushToRepo
(
repo
,
new
File
(
"/tmp"
,
exerciseToken
));
gitlabService
.
commitAndPushToRepo
(
repo
,
new
File
(
System
.
getProperty
(
"java.io.tmpdir"
)
,
exerciseToken
));
repo
.
close
();
try
{
FileUtils
.
deleteDirectory
(
new
File
(
"/tmp"
,
exerciseToken
));
FileUtils
.
deleteDirectory
(
new
File
(
System
.
getProperty
(
"java.io.tmpdir"
)
,
exerciseToken
));
FileUtils
.
deleteDirectory
(
repo
.
getDirectory
().
getParentFile
());
}
catch
(
IOException
e
)
{
log
.
error
(
"Could not remove directory: {} \n"
,
e
.
getMessage
());
...
...
@@ -133,7 +133,8 @@ public class ExerciseService {
.
enable
(
DeserializationFeature
.
ACCEPT_SINGLE_VALUE_AS_ARRAY
)
.
disable
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
);
File
exerciseDetailsFile
=
Objects
.
requireNonNull
(
new
File
(
"/tmp"
,
exerciseToken
).
listFiles
((
file
,
name
)
->
name
.
startsWith
(
"Exercise-Details-"
)
&&
name
.
endsWith
(
".json"
))
new
File
(
System
.
getProperty
(
"java.io.tmpdir"
),
exerciseToken
)
.
listFiles
((
file
,
name
)
->
name
.
startsWith
(
"Exercise-Details-"
)
&&
name
.
endsWith
(
".json"
))
)[
0
];
mapArtemisExerciseInfoValues
(
exerciseDetailsFile
);
...
...
@@ -226,10 +227,10 @@ public class ExerciseService {
private
void
storeZipInTmp
(
ZipInputStream
zipInputStream
,
String
subDir
)
throws
IOException
{
Path
targetDir
;
try
{
targetDir
=
Files
.
createTempDirectory
(
subDir
);
}
catch
(
IllegalArgumentException
e
)
{
// We expect this when calling this method recursively for contained Zip files
if
(
subDir
.
startsWith
(
System
.
getProperty
(
"java.io.tmpdir"
)))
{
targetDir
=
Files
.
createDirectories
(
Paths
.
get
(
subDir
));
}
else
{
targetDir
=
Files
.
createDirectories
(
Paths
.
get
(
System
.
getProperty
(
"java.io.tmpdir"
),
subDir
));
}
ZipEntry
zipEntry
;
...
...
@@ -329,7 +330,10 @@ public class ExerciseService {
ObjectMapper
mapper
=
new
ObjectMapper
(
new
YAMLFactory
().
enable
(
YAMLGenerator
.
Feature
.
INDENT_ARRAYS
).
disable
(
YAMLGenerator
.
Feature
.
WRITE_DOC_START_MARKER
)
);
mapper
.
writeValue
(
new
File
(
"/tmp/"
+
exerciseToken
,
"metadata.yaml"
),
exerciseInfo
.
getExerciseInfoOnly
());
mapper
.
writeValue
(
Paths
.
get
(
System
.
getProperty
(
"java.io.tmpdir"
),
exerciseToken
,
"metadata.yaml"
).
toFile
(),
exerciseInfo
.
getExerciseInfoOnly
()
);
}
/**
...
...
@@ -376,17 +380,19 @@ public class ExerciseService {
private
void
renameFiles
(
String
exerciseToken
)
{
try
{
File
problemStatementFile
=
Objects
.
requireNonNull
(
new
File
(
"/tmp"
,
exerciseToken
).
listFiles
((
file
,
name
)
->
name
.
startsWith
(
"Problem-Statement-"
)
&&
name
.
endsWith
(
".md"
))
new
File
(
System
.
getProperty
(
"java.io.tmpdir"
),
exerciseToken
)
.
listFiles
((
file
,
name
)
->
name
.
startsWith
(
"Problem-Statement-"
)
&&
name
.
endsWith
(
".md"
))
)[
0
];
if
(!
problemStatementFile
.
renameTo
(
new
File
(
"/tmp"
+
File
.
separator
+
exerciseToken
,
"exercise.md"
)))
{
if
(!
problemStatementFile
.
renameTo
(
Paths
.
get
(
System
.
getProperty
(
"java.io.tmpdir"
),
exerciseToken
,
"exercise.md"
)
.
toFile
()
))
{
log
.
error
(
"Unable to rename file [{}]. Skipping.."
,
problemStatementFile
.
getName
());
}
File
exerciseDetailsFile
=
Objects
.
requireNonNull
(
new
File
(
"/tmp"
,
exerciseToken
).
listFiles
((
file
,
name
)
->
name
.
startsWith
(
"Exercise-Details-"
)
&&
name
.
endsWith
(
".json"
))
new
File
(
System
.
getProperty
(
"java.io.tmpdir"
),
exerciseToken
)
.
listFiles
((
file
,
name
)
->
name
.
startsWith
(
"Exercise-Details-"
)
&&
name
.
endsWith
(
".json"
))
)[
0
];
Files
.
move
(
exerciseDetailsFile
.
toPath
(),
exerciseDetailsFile
.
toPath
().
resolveSibling
(
"Exercise-Details.json"
));
}
catch
(
ArrayIndexOutOfBoundsException
e
)
{
log
.
error
(
"File to rename could not be found in [{}]."
,
"/tmp"
+
File
.
separator
+
exerciseToken
);
log
.
error
(
"File to rename could not be found in [{}]."
,
System
.
getProperty
(
"java.io.tmpdir"
)
+
File
.
separator
+
exerciseToken
);
}
catch
(
IOException
ioe
)
{
log
.
error
(
"Error while renaming file: {}"
,
ioe
.
getMessage
());
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/at/ac/uibk/gitsearch/service/GitlabService.java
+
2
−
2
View file @
9809b90b
...
...
@@ -277,14 +277,14 @@ public class GitlabService {
*/
public
Repository
checkoutRepo
(
String
repoUrl
)
throws
ArtemisImportError
{
String
repoDirName
=
repoUrl
.
split
(
"/"
)[
repoUrl
.
split
(
"/"
).
length
-
1
];
File
dst
=
new
File
(
"tmp-import"
,
repoDirName
);
File
dst
=
new
File
(
System
.
getProperty
(
"java.io.tmpdir"
)
,
repoDirName
);
if
(
dst
.
exists
())
{
log
.
debug
(
"Temporary directory '{}' already exists, removing it."
,
dst
.
getPath
());
try
{
FileUtils
.
deleteDirectory
(
dst
);
}
catch
(
IOException
e
)
{
log
.
error
(
"Unable to remove directory. Create another directory : {} \n"
,
e
.
getMessage
());
dst
=
new
File
(
"tmp-import"
,
repoDirName
+
UUID
.
randomUUID
());
dst
=
new
File
(
System
.
getProperty
(
"java.io.tmpdir"
)
,
repoDirName
+
UUID
.
randomUUID
());
}
}
try
{
...
...
This diff is collapsed.
Click to expand it.
Preview
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!
Save comment
Cancel
Please
register
or
sign in
to comment