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
ed3f36fc
Commit
ed3f36fc
authored
2 years ago
by
Daniel Crazzolara
Browse files
Options
Downloads
Patches
Plain Diff
Fixed various paths to tmp files
parent
ab32d540
2 merge requests
!110
HotFix Artemis
,
!109
Bugfix: Fix Sharing import/export with Artemis
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 @
ed3f36fc
...
@@ -98,7 +98,7 @@ public class ExerciseService {
...
@@ -98,7 +98,7 @@ public class ExerciseService {
* - Copy, commit and push files to the new repository
* - Copy, commit and push files to the new repository
*
*
* @param exerciseInfo of the exercise to import
* @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
)
public
void
importExercise
(
ArtemisExerciseInfo
exerciseInfo
,
String
exerciseToken
,
Integer
gitlabGroupId
)
throws
GitLabApiException
,
GitAPIException
,
IOException
,
ArtemisImportError
{
throws
GitLabApiException
,
GitAPIException
,
IOException
,
ArtemisImportError
{
...
@@ -109,11 +109,11 @@ public class ExerciseService {
...
@@ -109,11 +109,11 @@ public class ExerciseService {
Group
group
=
gitlabService
.
getGroupById
(
gitlabGroupId
);
Group
group
=
gitlabService
.
getGroupById
(
gitlabGroupId
);
String
repoUrl
=
gitlabService
.
createRepository
(
group
,
exerciseInfo
.
getTitle
());
String
repoUrl
=
gitlabService
.
createRepository
(
group
,
exerciseInfo
.
getTitle
());
Repository
repo
=
gitlabService
.
checkoutRepo
(
repoUrl
);
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
();
repo
.
close
();
try
{
try
{
FileUtils
.
deleteDirectory
(
new
File
(
"/tmp"
,
exerciseToken
));
FileUtils
.
deleteDirectory
(
new
File
(
System
.
getProperty
(
"java.io.tmpdir"
)
,
exerciseToken
));
FileUtils
.
deleteDirectory
(
repo
.
getDirectory
().
getParentFile
());
FileUtils
.
deleteDirectory
(
repo
.
getDirectory
().
getParentFile
());
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
log
.
error
(
"Could not remove directory: {} \n"
,
e
.
getMessage
());
log
.
error
(
"Could not remove directory: {} \n"
,
e
.
getMessage
());
...
@@ -133,7 +133,8 @@ public class ExerciseService {
...
@@ -133,7 +133,8 @@ public class ExerciseService {
.
enable
(
DeserializationFeature
.
ACCEPT_SINGLE_VALUE_AS_ARRAY
)
.
enable
(
DeserializationFeature
.
ACCEPT_SINGLE_VALUE_AS_ARRAY
)
.
disable
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
);
.
disable
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
);
File
exerciseDetailsFile
=
Objects
.
requireNonNull
(
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
];
)[
0
];
mapArtemisExerciseInfoValues
(
exerciseDetailsFile
);
mapArtemisExerciseInfoValues
(
exerciseDetailsFile
);
...
@@ -226,10 +227,10 @@ public class ExerciseService {
...
@@ -226,10 +227,10 @@ public class ExerciseService {
private
void
storeZipInTmp
(
ZipInputStream
zipInputStream
,
String
subDir
)
throws
IOException
{
private
void
storeZipInTmp
(
ZipInputStream
zipInputStream
,
String
subDir
)
throws
IOException
{
Path
targetDir
;
Path
targetDir
;
try
{
if
(
subDir
.
startsWith
(
System
.
getProperty
(
"java.io.tmpdir"
)))
{
targetDir
=
Files
.
createTempDirectory
(
subDir
);
}
catch
(
IllegalArgumentException
e
)
{
// We expect this when calling this method recursively for contained Zip files
targetDir
=
Files
.
createDirectories
(
Paths
.
get
(
subDir
));
targetDir
=
Files
.
createDirectories
(
Paths
.
get
(
subDir
));
}
else
{
targetDir
=
Files
.
createDirectories
(
Paths
.
get
(
System
.
getProperty
(
"java.io.tmpdir"
),
subDir
));
}
}
ZipEntry
zipEntry
;
ZipEntry
zipEntry
;
...
@@ -329,7 +330,10 @@ public class ExerciseService {
...
@@ -329,7 +330,10 @@ public class ExerciseService {
ObjectMapper
mapper
=
new
ObjectMapper
(
ObjectMapper
mapper
=
new
ObjectMapper
(
new
YAMLFactory
().
enable
(
YAMLGenerator
.
Feature
.
INDENT_ARRAYS
).
disable
(
YAMLGenerator
.
Feature
.
WRITE_DOC_START_MARKER
)
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 {
...
@@ -376,17 +380,19 @@ public class ExerciseService {
private
void
renameFiles
(
String
exerciseToken
)
{
private
void
renameFiles
(
String
exerciseToken
)
{
try
{
try
{
File
problemStatementFile
=
Objects
.
requireNonNull
(
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
];
)[
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
());
log
.
error
(
"Unable to rename file [{}]. Skipping.."
,
problemStatementFile
.
getName
());
}
}
File
exerciseDetailsFile
=
Objects
.
requireNonNull
(
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
];
)[
0
];
Files
.
move
(
exerciseDetailsFile
.
toPath
(),
exerciseDetailsFile
.
toPath
().
resolveSibling
(
"Exercise-Details.json"
));
Files
.
move
(
exerciseDetailsFile
.
toPath
(),
exerciseDetailsFile
.
toPath
().
resolveSibling
(
"Exercise-Details.json"
));
}
catch
(
ArrayIndexOutOfBoundsException
e
)
{
}
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
)
{
}
catch
(
IOException
ioe
)
{
log
.
error
(
"Error while renaming file: {}"
,
ioe
.
getMessage
());
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 @
ed3f36fc
...
@@ -277,14 +277,14 @@ public class GitlabService {
...
@@ -277,14 +277,14 @@ public class GitlabService {
*/
*/
public
Repository
checkoutRepo
(
String
repoUrl
)
throws
ArtemisImportError
{
public
Repository
checkoutRepo
(
String
repoUrl
)
throws
ArtemisImportError
{
String
repoDirName
=
repoUrl
.
split
(
"/"
)[
repoUrl
.
split
(
"/"
).
length
-
1
];
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
())
{
if
(
dst
.
exists
())
{
log
.
debug
(
"Temporary directory '{}' already exists, removing it."
,
dst
.
getPath
());
log
.
debug
(
"Temporary directory '{}' already exists, removing it."
,
dst
.
getPath
());
try
{
try
{
FileUtils
.
deleteDirectory
(
dst
);
FileUtils
.
deleteDirectory
(
dst
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
log
.
error
(
"Unable to remove directory. Create another directory : {} \n"
,
e
.
getMessage
());
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
{
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