-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Programming exercises: Show build logs for submission results (#8170)
- Loading branch information
Showing
18 changed files
with
420 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/de/tum/in/www1/artemis/web/rest/localci/BuildLogResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package de.tum.in.www1.artemis.web.rest.localci; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.core.io.FileSystemResource; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import de.tum.in.www1.artemis.security.annotations.EnforceAtLeastEditor; | ||
import de.tum.in.www1.artemis.service.BuildLogEntryService; | ||
|
||
@Profile("localci") | ||
@RestController | ||
@RequestMapping("/api") | ||
public class BuildLogResource { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(BuildLogResource.class); | ||
|
||
private final BuildLogEntryService buildLogEntryService; | ||
|
||
public BuildLogResource(BuildLogEntryService buildLogEntryService) { | ||
this.buildLogEntryService = buildLogEntryService; | ||
} | ||
|
||
/** | ||
* GET /build-log/{resultId} : get the build log for a given result | ||
* | ||
* @param resultId the id of the result for which to retrieve the build log | ||
* @return the ResponseEntity with status 200 (OK) and the build log in the body, or with status 404 (Not Found) if the build log could not be found | ||
*/ | ||
@GetMapping("/build-log/{resultId}") | ||
@EnforceAtLeastEditor | ||
public ResponseEntity<Resource> getBuildLogForSubmission(@PathVariable long resultId) { | ||
log.debug("REST request to get the build log for result {}", resultId); | ||
HttpHeaders responseHeaders = new HttpHeaders(); | ||
FileSystemResource buildLog = buildLogEntryService.retrieveBuildLogsFromFileForResult(String.valueOf(resultId)); | ||
if (buildLog == null) { | ||
return new ResponseEntity<>(HttpStatus.NOT_FOUND); | ||
} | ||
responseHeaders.setContentType(MediaType.TEXT_PLAIN); | ||
responseHeaders.setContentDispositionFormData("attachment", "build-" + resultId + ".log"); | ||
return new ResponseEntity<>(buildLog, responseHeaders, HttpStatus.OK); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.