Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BBesrour committed Aug 20, 2024
1 parent 9984fe7 commit 15a5753
Show file tree
Hide file tree
Showing 66 changed files with 1,996 additions and 79 deletions.
8 changes: 8 additions & 0 deletions src/main/java/de/tum/in/www1/artemis/config/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,14 @@ public final class Constants {
*/
public static final int MIN_SCORE_ORANGE = 40;

public static final String ASSIGNMENT_REPO_PLACEHOLDER = "${studentWorkingDirectory}";

public static final String TEST_REPO_PLACEHOLDER = "${testWorkingDirectory}";

public static final String SOLUTION_REPO_PLACEHOLDER = "${solutionWorkingDirectory}";

public static final String ASSIGNMENT_REPO_PARENT_PLACEHOLDER = "${studentParentWorkingDirectoryName}";

private Constants() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import de.tum.in.www1.artemis.domain.ProgrammingExerciseBuildConfig;
import de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage;
import de.tum.in.www1.artemis.domain.enumeration.ProjectType;
import de.tum.in.www1.artemis.service.ProfileService;
import de.tum.in.www1.artemis.service.ResourceLoaderService;
import de.tum.in.www1.artemis.service.connectors.aeolus.AeolusTemplateService;

Expand All @@ -39,14 +40,17 @@ public class BuildScriptProviderService {

private final Map<String, String> scriptCache = new ConcurrentHashMap<>();

private final ProfileService profileService;

/**
* Constructor for BuildScriptProvider, which loads all scripts into the cache to speed up retrieval
* during the runtime of the application
*
* @param resourceLoaderService resourceLoaderService
*/
public BuildScriptProviderService(ResourceLoaderService resourceLoaderService) {
public BuildScriptProviderService(ResourceLoaderService resourceLoaderService, ProfileService profileService) {
this.resourceLoaderService = resourceLoaderService;
this.profileService = profileService;
}

/**
Expand All @@ -58,14 +62,16 @@ public BuildScriptProviderService(ResourceLoaderService resourceLoaderService) {
*/
@EventListener(ApplicationReadyEvent.class)
public void cacheOnBoot() {
var resources = this.resourceLoaderService.getFileResources(Path.of("templates", "aeolus"));
String templateDirectory = profileService.isLocalCiActive() ? "local" : "aeolus";
var resources = this.resourceLoaderService.getFileResources(Path.of("templates", templateDirectory));
for (var resource : resources) {
try {
String filename = resource.getFilename();
if (filename == null || filename.endsWith(".yaml")) {
continue;
}
String directory = resource.getURL().getPath().split("templates/aeolus/")[1].split("/")[0];
String pathPrefix = "templates/" + templateDirectory + "/";
String directory = resource.getURL().getPath().split(pathPrefix)[1].split("/")[0];
String uniqueKey = directory + "_" + filename;
byte[] fileContent = IOUtils.toByteArray(resource.getInputStream());
String script = new String(fileContent, StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import de.tum.in.www1.artemis.domain.ProgrammingExerciseBuildConfig;
import de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage;
import de.tum.in.www1.artemis.domain.enumeration.ProjectType;
import de.tum.in.www1.artemis.service.ProfileService;
import de.tum.in.www1.artemis.service.ResourceLoaderService;
import de.tum.in.www1.artemis.service.connectors.BuildScriptProviderService;

Expand All @@ -45,13 +46,16 @@ public class AeolusTemplateService {

private final BuildScriptProviderService buildScriptProviderService;

private final ProfileService profileService;

private static final ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());

public AeolusTemplateService(ProgrammingLanguageConfiguration programmingLanguageConfiguration, ResourceLoaderService resourceLoaderService,
BuildScriptProviderService buildScriptProviderService) {
BuildScriptProviderService buildScriptProviderService, ProfileService profileService) {
this.programmingLanguageConfiguration = programmingLanguageConfiguration;
this.resourceLoaderService = resourceLoaderService;
this.buildScriptProviderService = buildScriptProviderService;
this.profileService = profileService;
}

/**
Expand All @@ -63,14 +67,16 @@ public AeolusTemplateService(ProgrammingLanguageConfiguration programmingLanguag
@EventListener(ApplicationReadyEvent.class)
public void cacheOnBoot() {
// load all scripts into the cache
var resources = this.resourceLoaderService.getFileResources(Path.of("templates", "aeolus"));
String templateDirectory = profileService.isLocalCiActive() ? "local" : "aeolus";
var resources = this.resourceLoaderService.getFileResources(Path.of("templates", templateDirectory));
for (var resource : resources) {
try {
String filename = resource.getFilename();
if (filename == null || !filename.endsWith(".yaml")) {
continue;
}
String directory = resource.getURL().getPath().split("templates/aeolus/")[1].split("/")[0];
String pathPrefix = "templates/" + templateDirectory + "/";
String directory = resource.getURL().getPath().split(pathPrefix)[1].split("/")[0];
Optional<ProjectType> optionalProjectType = extractProjectType(filename);
String uniqueKey = directory + "_" + filename;
byte[] fileContent = IOUtils.toByteArray(resource.getInputStream());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import static de.tum.in.www1.artemis.config.Constants.LOCALCI_WORKING_DIRECTORY;
import static de.tum.in.www1.artemis.config.Constants.PROFILE_LOCALCI;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

import de.tum.in.www1.artemis.config.Constants;
import de.tum.in.www1.artemis.domain.ProgrammingExercise;
import de.tum.in.www1.artemis.domain.ProgrammingExerciseBuildConfig;
import de.tum.in.www1.artemis.exception.LocalCIException;
Expand Down Expand Up @@ -71,7 +73,31 @@ public String createBuildScript(ProgrammingExercise programmingExercise) {
});

}
return buildScriptBuilder.toString();
return replacePlaceholders(buildScriptBuilder.toString(), programmingExercise.getBuildConfig());
}

public List<String> replaceResultPathsPlaceholders(List<String> resultPaths, ProgrammingExerciseBuildConfig buildConfig) {
List<String> replacedResultPaths = new ArrayList<>();
for (String resultPath : resultPaths) {
String replacedResultPath = replacePlaceholders(resultPath, buildConfig);
replacedResultPaths.add(replacedResultPath);
}
return replacedResultPaths;
}

private String replacePlaceholders(String originalString, ProgrammingExerciseBuildConfig buildConfig) {
String assignmentRepo = buildConfig.getAssignmentCheckoutPath();
assignmentRepo = assignmentRepo != null && !assignmentRepo.isBlank() ? assignmentRepo : Constants.ASSIGNMENT_REPO_NAME;
String solutionRepo = buildConfig.getSolutionCheckoutPath();
solutionRepo = solutionRepo != null && !solutionRepo.isBlank() ? solutionRepo : Constants.SOLUTION_REPO_NAME;
String testRepo = buildConfig.getTestCheckoutPath();
testRepo = testRepo != null && !testRepo.isBlank() ? testRepo : Constants.TEST_REPO_NAME;

String replacedResultPath = originalString.replace(Constants.ASSIGNMENT_REPO_PARENT_PLACEHOLDER, assignmentRepo);
replacedResultPath = replacedResultPath.replace(Constants.ASSIGNMENT_REPO_PLACEHOLDER, "/" + assignmentRepo + "/src");
replacedResultPath = replacedResultPath.replace(Constants.SOLUTION_REPO_PLACEHOLDER, solutionRepo);
replacedResultPath = replacedResultPath.replace(Constants.TEST_REPO_PLACEHOLDER, testRepo);
return replacedResultPath;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ private BuildConfig getBuildConfig(ProgrammingExerciseParticipation participatio
}

List<String> resultPaths = getTestResultPaths(windfile);
resultPaths = localCIBuildConfigurationService.replaceResultPathsPlaceholders(resultPaths, buildConfig);

// Todo: If build agent does not have access to filesystem, we need to send the build script to the build agent and execute it there.
programmingExercise.setBuildConfig(buildConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,15 +677,15 @@ void replacePlaceholders(final ProgrammingExercise programmingExercise, final Re
String solutionWorkingDirectory = buildConfig.getSolutionCheckoutPath() != null && !buildConfig.getSolutionCheckoutPath().isBlank() ? buildConfig.getSolutionCheckoutPath()
: Constants.SOLUTION_REPO_NAME;

replacements.put("${studentWorkingDirectory}", "/" + studentWorkingDirectory + "/src");
if (programmingLanguage == ProgrammingLanguage.PYTHON) {
replacements.put("${studentParentWorkingDirectoryName}", studentWorkingDirectory.replace("/", "."));
replacements.put(Constants.ASSIGNMENT_REPO_PARENT_PLACEHOLDER, studentWorkingDirectory.replace("/", "."));
}
else {
replacements.put("${studentParentWorkingDirectoryName}", studentWorkingDirectory);
replacements.put(Constants.ASSIGNMENT_REPO_PARENT_PLACEHOLDER, studentWorkingDirectory);
}
replacements.put("${testWorkingDirectory}", testWorkingDirectory);
replacements.put("${solutionWorkingDirectory}", solutionWorkingDirectory);
replacements.put(Constants.ASSIGNMENT_REPO_PLACEHOLDER, "/" + studentWorkingDirectory + "/src");
replacements.put(Constants.TEST_REPO_PLACEHOLDER, testWorkingDirectory);
replacements.put(Constants.SOLUTION_REPO_PLACEHOLDER, solutionWorkingDirectory);
fileService.replaceVariablesInFileRecursive(repository.getLocalPath().toAbsolutePath(), replacements, List.of("gradle-wrapper.jar"));
}

Expand Down
22 changes: 11 additions & 11 deletions src/main/resources/templates/aeolus/assembler/default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ provide_environment_information () {
python3 --version
pip3 --version
echo "--------------------Contents of tests repository--------------------"
ls -la ${testWorkingDirectory}
ls -la tests
echo "---------------------------------------------"
echo "--------------------Contents of assignment repository--------------------"
ls -la ${studentParentWorkingDirectoryName}
ls -la assignment
echo "---------------------------------------------"
#Fallback in case Docker does not work as intended
REQ_FILE=${testWorkingDirectory}/requirements.txt
REQ_FILE=tests/requirements.txt
if [ -f "$REQ_FILE" ]; then
pip3 install --user -r ${testWorkingDirectory}/requirements.txt
pip3 install --user -r tests/requirements.txt
else
echo "$REQ_FILE does not exist"
fi
Expand All @@ -25,18 +25,18 @@ provide_environment_information () {
prepare_makefile () {
echo '⚙️ executing prepare_makefile'
#!/usr/bin/env bash
rm -f ${studentParentWorkingDirectoryName}/{GNUmakefile, Makefile, makefile}
rm -f ${studentParentWorkingDirectoryName}/io.inc
cp -f ${testWorkingDirectory}/Makefile ${studentParentWorkingDirectoryName}/Makefile || exit 2
cp -f ${testWorkingDirectory}/io.inc ${studentParentWorkingDirectoryName}/io.inc || exit 2
rm -f assignment/{GNUmakefile, Makefile, makefile}
rm -f assignment/io.inc
cp -f tests/Makefile assignment/Makefile || exit 2
cp -f tests/io.inc assignment/io.inc || exit 2
}

run_and_compile () {
echo '⚙️ executing run_and_compile'
cd ${testWorkingDirectory}
python3 compileTest.py ../${studentParentWorkingDirectoryName}/
cd tests
python3 compileTest.py ../assignment/
rm compileTest.py
cp result.xml ../${studentParentWorkingDirectoryName}/result.xml
cp result.xml ../assignment/result.xml
}

junit () {
Expand Down
14 changes: 7 additions & 7 deletions src/main/resources/templates/aeolus/c/fact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ setup_the_build_environment () {
# Task Description:
# Build and run all tests
# ------------------------------
# Updating ${studentParentWorkingDirectoryName} and test-reports ownership...
sudo chown artemis_user:artemis_user ${studentParentWorkingDirectoryName}/ -R || true
# Updating assignment and test-reports ownership...
sudo chown artemis_user:artemis_user assignment/ -R || true
sudo mkdir test-reports
sudo chown artemis_user:artemis_user test-reports/ -R || true
}
Expand All @@ -22,13 +22,13 @@ build_and_run_all_tests () {
# Build and run all tests
# ------------------------------

rm -f ${studentParentWorkingDirectoryName}/GNUmakefile
rm -f ${studentParentWorkingDirectoryName}/Makefile
cp -f ${testWorkingDirectory}/Makefile ${studentParentWorkingDirectoryName}/Makefile || exit 2
cd ${testWorkingDirectory}
rm -f assignment/GNUmakefile
rm -f assignment/Makefile
cp -f tests/Makefile assignment/Makefile || exit 2
cd tests
python3 Tests.py
rm Tests.py
rm -rf ./${testWorkingDirectory} || true
rm -rf ./tests || true
}

main () {
Expand Down
24 changes: 12 additions & 12 deletions src/main/resources/templates/aeolus/c/gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ setup_the_build_environment () {
# Build and run all tests
# ------------------------------

# Updating ${studentParentWorkingDirectoryName} and test-reports ownership...
sudo chown artemis_user:artemis_user ${studentParentWorkingDirectoryName}/ -R
# Updating assignment and test-reports ownership...
sudo chown artemis_user:artemis_user assignment/ -R
mkdir test-reports
chown artemis_user:artemis_user test-reports/ -R

# assignment
cd ${testWorkingDirectory}
cd tests
REQ_FILE=requirements.txt
if [ -f "$REQ_FILE" ]; then
pip3 install --user -r requirements.txt || true
Expand All @@ -35,18 +35,18 @@ setup_makefile () {
# Setup makefile
# ------------------------------

shadowFilePath="../${testWorkingDirectory}/testUtils/c/shadow_exec.c"
shadowFilePath="../tests/testUtils/c/shadow_exec.c"

foundIncludeDirs=`grep -m 1 'INCLUDEDIRS\s*=' ${studentParentWorkingDirectoryName}/Makefile`
foundIncludeDirs=`grep -m 1 'INCLUDEDIRS\s*=' assignment/Makefile`

foundSource=`grep -m 1 'SOURCE\s*=' ${studentParentWorkingDirectoryName}/Makefile`
foundSource=`grep -m 1 'SOURCE\s*=' assignment/Makefile`
foundSource="$foundSource $shadowFilePath"

rm -f ${studentParentWorkingDirectoryName}/GNUmakefile
rm -f ${studentParentWorkingDirectoryName}/makefile
rm -f assignment/GNUmakefile
rm -f assignment/makefile

cp -f ${testWorkingDirectory}/Makefile ${studentParentWorkingDirectoryName}/Makefile || exit 2
sed -i "s~\bINCLUDEDIRS\s*=.*~${foundIncludeDirs}~; s~\bSOURCE\s*=.*~${foundSource}~" ${studentParentWorkingDirectoryName}/Makefile
cp -f tests/Makefile assignment/Makefile || exit 2
sed -i "s~\bINCLUDEDIRS\s*=.*~${foundIncludeDirs}~; s~\bSOURCE\s*=.*~${foundSource}~" assignment/Makefile
}

build_and_run_all_tests () {
Expand All @@ -58,10 +58,10 @@ build_and_run_all_tests () {
# Build and run all tests if the compilation succeeds
# ------------------------------
sudo chown artemis_user:artemis_user .
gcc -c -Wall ${studentParentWorkingDirectoryName}/*.c || error=true
gcc -c -Wall assignment/*.c || error=true
if [ ! $error ]
then
cd ${testWorkingDirectory} || exit 0
cd tests || exit 0
python3 Tests.py || true
fi
}
Expand Down
24 changes: 12 additions & 12 deletions src/main/resources/templates/aeolus/c/gcc_static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ setup_the_build_environment () {
# Build and run all tests
# ------------------------------

# Updating ${studentParentWorkingDirectoryName} and test-reports ownership...
sudo chown artemis_user:artemis_user ${studentParentWorkingDirectoryName}/ -R
# Updating assignment and test-reports ownership...
sudo chown artemis_user:artemis_user assignment/ -R
mkdir test-reports
chown artemis_user:artemis_user test-reports/ -R

# assignment
cd ${testWorkingDirectory}
cd tests
REQ_FILE=requirements.txt
if [ -f "$REQ_FILE" ]; then
pip3 install --user -r requirements.txt || true
Expand All @@ -35,18 +35,18 @@ setup_makefile () {
# Setup makefile
# ------------------------------

shadowFilePath="../${testWorkingDirectory}/testUtils/c/shadow_exec.c"
shadowFilePath="../tests/testUtils/c/shadow_exec.c"

foundIncludeDirs=`grep -m 1 'INCLUDEDIRS\s*=' ${studentParentWorkingDirectoryName}/Makefile`
foundIncludeDirs=`grep -m 1 'INCLUDEDIRS\s*=' assignment/Makefile`

foundSource=`grep -m 1 'SOURCE\s*=' ${studentParentWorkingDirectoryName}/Makefile`
foundSource=`grep -m 1 'SOURCE\s*=' assignment/Makefile`
foundSource="$foundSource $shadowFilePath"

rm -f ${studentParentWorkingDirectoryName}/GNUmakefile
rm -f ${studentParentWorkingDirectoryName}/makefile
rm -f assignment/GNUmakefile
rm -f assignment/makefile

cp -f ${testWorkingDirectory}/Makefile ${studentParentWorkingDirectoryName}/Makefile || exit 2
sed -i "s~\bINCLUDEDIRS\s*=.*~${foundIncludeDirs}~; s~\bSOURCE\s*=.*~${foundSource}~" ${studentParentWorkingDirectoryName}/Makefile
cp -f tests/Makefile assignment/Makefile || exit 2
sed -i "s~\bINCLUDEDIRS\s*=.*~${foundIncludeDirs}~; s~\bSOURCE\s*=.*~${foundSource}~" assignment/Makefile
}

build_and_run_all_tests () {
Expand All @@ -58,10 +58,10 @@ build_and_run_all_tests () {
# Build and run all tests if the compilation succeeds
# ------------------------------
sudo chown artemis_user:artemis_user .
gcc -c -Wall ${studentParentWorkingDirectoryName}/*.c || error=true
gcc -c -Wall assignment/*.c || error=true
if [ ! $error ]
then
cd ${testWorkingDirectory} || exit 0
cd tests || exit 0
python3 Tests.py || true
else
exit 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ build () {
checkers () {
echo '⚙️ executing checkers'
# all java files in the assignment folder should have maximal line length 80
pipeline-helper line-length -l 80 -s ${studentParentWorkingDirectoryName}/ -e java
pipeline-helper line-length -l 80 -s assignment/ -e java
# checks that the file exists and is not empty for non gui programs
pipeline-helper file-exists ${studentParentWorkingDirectoryName}/Tests.txt
pipeline-helper file-exists assignment/Tests.txt

main_checker_output=$(pipeline-helper main-method -s target/classes)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ build () {
checkers () {
echo '⚙️ executing checkers'
# all java files in the assignment folder should have maximal line length 80
pipeline-helper line-length -l 80 -s ${studentParentWorkingDirectoryName}/ -e java
pipeline-helper line-length -l 80 -s assignment/ -e java
# checks that the file exists and is not empty for non gui programs
pipeline-helper file-exists ${studentParentWorkingDirectoryName}/Tests.txt
pipeline-helper file-exists assignment/Tests.txt

main_checker_output=$(pipeline-helper main-method -s target/classes)

Expand Down
Loading

0 comments on commit 15a5753

Please sign in to comment.