diff --git a/settings.gradle b/settings.gradle index dc8897e1b9b1..b9f9d365979c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,5 @@ +import org.apache.tools.ant.DirectoryScanner + pluginManagement { plugins { id 'org.springframework.boot' version "${spring_boot_version}" @@ -13,3 +15,7 @@ pluginManagement { rootProject.name = 'Artemis' include 'supporting_scripts:analysis-of-endpoint-connections' + +// needed for programming exercise templates +DirectoryScanner.removeDefaultExclude "**/.gitattributes" +DirectoryScanner.removeDefaultExclude "**/.gitignore" \ No newline at end of file diff --git a/src/main/java/de/tum/in/www1/artemis/service/FileService.java b/src/main/java/de/tum/in/www1/artemis/service/FileService.java index ba4abe261aff..e1f05333bacf 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/FileService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/FileService.java @@ -108,21 +108,6 @@ public class FileService implements DisposableBean { public static final String PICTURE_FILE_SUBPATH = "/api/files/drag-and-drop/drag-items/"; - /** - * Filenames for which the template filename differs from the filename it should have in the repository. - */ - // @formatter:off - private static final Map FILENAME_REPLACEMENTS = Map.ofEntries( - Map.entry("git.ignore.file", ".gitignore"), - Map.entry("git.attributes.file", ".gitattributes"), - Map.entry("Makefile.file", "Makefile"), - Map.entry("dune.file", "dune"), - Map.entry("Fast.file", "Fastfile"), - Map.entry("App.file", "Appfile"), - Map.entry("Scan.file", "Scanfile"), - Map.entry("gradlew.file", "gradlew")); - // @formatter:on - /** * These directories get falsely marked as files and should be ignored during copying. */ @@ -421,8 +406,7 @@ private Path generateTargetPath(final Resource resource, final Path prefix, fina filePath = Path.of(url); } - final Path targetPath = generateTargetPath(filePath, prefix, targetDirectory, keepParentDirectory); - return applyFilenameReplacements(targetPath); + return generateTargetPath(filePath, prefix, targetDirectory, keepParentDirectory); } /** @@ -467,19 +451,6 @@ private List getPathElements(final Path path) { return elements; } - /** - * Replaces filenames where the template name differs from the name the file should have in the repository. - * - * @param originalTargetPath The path to a file. - * @return The path with replacements applied where necessary. - */ - private Path applyFilenameReplacements(final Path originalTargetPath) { - final Path filename = originalTargetPath.getFileName(); - - final String newFilename = FILENAME_REPLACEMENTS.getOrDefault(filename.toString(), filename.toString()); - return originalTargetPath.getParent().resolve(newFilename); - } - /** * Checks if the given path has been identified as a file, but it actually points to a directory. * diff --git a/src/main/java/de/tum/in/www1/artemis/service/ResourceLoaderService.java b/src/main/java/de/tum/in/www1/artemis/service/ResourceLoaderService.java index 8a83a6a84b95..6ebd27960333 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/ResourceLoaderService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/ResourceLoaderService.java @@ -10,6 +10,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -37,7 +38,7 @@ public class ResourceLoaderService { private static final Logger log = LoggerFactory.getLogger(ResourceLoaderService.class); - private static final String ALL_FILES_GLOB = "**" + File.separator + "*.*"; + private static final String ALL_PATHS_ANT_PATTERN = "**"; @Value("${artemis.template-path:#{null}}") private Optional templateFileSystemPath; @@ -68,7 +69,7 @@ public Resource getResource(final Path path) { // Try to load from filesystem if override is allowed for path if (isOverrideAllowed(path)) { - final String resourceLocation = getFileResourceLocation(path); + final String resourceLocation = getFileSystemResourceLocation(path); resource = resourceLoader.getResource(resourceLocation); } @@ -84,20 +85,20 @@ public Resource getResource(final Path path) { /** * Recursively loads the resources from the specified directory. *

- * Only relative paths are allowed. + * Only relative paths are allowed. Does not return directories. * * @param basePath A relative path pattern to a resource. * @return The resources located by the specified pathPattern. */ @NotNull - public Resource[] getResources(final Path basePath) { - return getResources(basePath, ALL_FILES_GLOB); + public Resource[] getFileResources(final Path basePath) { + return getFileResources(basePath, ALL_PATHS_ANT_PATTERN); } /** * Loads the resources from the specified path pattern. *

- * Only relative paths are allowed. + * Only relative paths are allowed. Does not return directories. *

* Examples for path patterns: {@code *.sh}, {@code base/**}. Use forward slashes to separate path parts. * @@ -106,16 +107,16 @@ public Resource[] getResources(final Path basePath) { * @return The resources located by the specified pathPattern. */ @NotNull - public Resource[] getResources(final Path basePath, final String pattern) { + public Resource[] getFileResources(final Path basePath, final String pattern) { checkValidPathElseThrow(basePath); Resource[] resources = null; // Try to load from filesystem if override is allowed for pathPattern if (isOverrideAllowed(basePath)) { - final String resourceLocation = getFileResourceLocation(basePath, pattern); + final String resourceLocation = getFileSystemResourceLocation(basePath, pattern); try { - resources = resourceLoader.getResources(resourceLocation); + resources = getFileResources(resourceLocation); } catch (IOException e) { log.debug("Could not load resources '{}' from filesystem.", resourceLocation, e); @@ -126,7 +127,7 @@ public Resource[] getResources(final Path basePath, final String pattern) { if (resources == null || resources.length == 0) { final String resourceLocation = getClassPathResourceLocation(basePath, pattern); try { - resources = resourceLoader.getResources(resourceLocation); + resources = getFileResources(resourceLocation); } catch (IOException e) { log.debug("Could not load resources '{}' from classpath.", resourceLocation, e); @@ -136,17 +137,32 @@ public Resource[] getResources(final Path basePath, final String pattern) { return Objects.requireNonNullElseGet(resources, () -> new Resource[0]); } + /** + * Loads non-directory resources from the specified patterns. + *

+ * Each resource can be read via {@link Resource#getInputStream()}. + * + * @param locationPattern The resource pattern passed to the resource loader. + * @return The resources with readable content located by the specified locationPattern. + * @throws IOException in case of I/O errors + */ + private Resource[] getFileResources(final String locationPattern) throws IOException { + final var fileAndDirectoryResources = resourceLoader.getResources(locationPattern); + + return Arrays.stream(fileAndDirectoryResources).filter(Resource::isReadable).toArray(Resource[]::new); + } + private void checkValidPathElseThrow(final Path path) { if (path.isAbsolute()) { throw new IllegalArgumentException("Cannot load resources from absolute paths!"); } } - private String getFileResourceLocation(final Path resourcePath) { + private String getFileSystemResourceLocation(final Path resourcePath) { return "file:" + resolveResourcePath(resourcePath).toString(); } - private String getFileResourceLocation(final Path resourcePath, final String pathPattern) { + private String getFileSystemResourceLocation(final Path resourcePath, final String pathPattern) { final String systemPathPattern = File.separator + adaptPathPatternToSystem(pathPattern); return "file:" + resolveResourcePath(resourcePath).toString() + systemPathPattern; } diff --git a/src/main/java/de/tum/in/www1/artemis/service/connectors/BuildScriptProviderService.java b/src/main/java/de/tum/in/www1/artemis/service/connectors/BuildScriptProviderService.java index d56e175774b0..620182f07764 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/connectors/BuildScriptProviderService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/connectors/BuildScriptProviderService.java @@ -57,7 +57,7 @@ public BuildScriptProviderService(ResourceLoaderService resourceLoaderService) { */ @EventListener(ApplicationReadyEvent.class) public void cacheOnBoot() { - var resources = this.resourceLoaderService.getResources(Path.of("templates", "aeolus")); + var resources = this.resourceLoaderService.getFileResources(Path.of("templates", "aeolus")); for (var resource : resources) { try { String filename = resource.getFilename(); diff --git a/src/main/java/de/tum/in/www1/artemis/service/connectors/aeolus/AeolusTemplateService.java b/src/main/java/de/tum/in/www1/artemis/service/connectors/aeolus/AeolusTemplateService.java index 3e1043d8b19f..af573482bbd5 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/connectors/aeolus/AeolusTemplateService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/connectors/aeolus/AeolusTemplateService.java @@ -62,7 +62,7 @@ public AeolusTemplateService(ProgrammingLanguageConfiguration programmingLanguag @EventListener(ApplicationReadyEvent.class) public void cacheOnBoot() { // load all scripts into the cache - var resources = this.resourceLoaderService.getResources(Path.of("templates", "aeolus")); + var resources = this.resourceLoaderService.getFileResources(Path.of("templates", "aeolus")); for (var resource : resources) { try { String filename = resource.getFilename(); diff --git a/src/main/java/de/tum/in/www1/artemis/service/programming/JavaTemplateUpgradeService.java b/src/main/java/de/tum/in/www1/artemis/service/programming/JavaTemplateUpgradeService.java index 12f1d29523c8..223bf6a42a7a 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/programming/JavaTemplateUpgradeService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/programming/JavaTemplateUpgradeService.java @@ -144,13 +144,13 @@ private Resource[] getTemplateResources(ProgrammingExercise exercise, String fil // Get general template resources final Path programmingLanguageTemplate = ProgrammingExerciseService.getProgrammingLanguageTemplatePath(exercise.getProgrammingLanguage()); - Resource[] templatePoms = resourceLoaderService.getResources(programmingLanguageTemplate, filePattern); + Resource[] templatePoms = resourceLoaderService.getFileResources(programmingLanguageTemplate, filePattern); // Get project type specific template resources if (exercise.getProjectType() != null) { final Path projectTypeTemplate = ProgrammingExerciseService.getProgrammingLanguageProjectTypePath(exercise.getProgrammingLanguage(), exercise.getProjectType()); - final Resource[] projectTypePoms = resourceLoaderService.getResources(projectTypeTemplate, filePattern); + final Resource[] projectTypePoms = resourceLoaderService.getFileResources(projectTypeTemplate, filePattern); // Prefer project type specific resources templatePoms = projectTypePoms.length > 0 ? projectTypePoms : templatePoms; diff --git a/src/main/java/de/tum/in/www1/artemis/service/programming/ProgrammingExerciseRepositoryService.java b/src/main/java/de/tum/in/www1/artemis/service/programming/ProgrammingExerciseRepositoryService.java index f7d4db755b7a..f60ddf2fca53 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/programming/ProgrammingExerciseRepositoryService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/programming/ProgrammingExerciseRepositoryService.java @@ -136,7 +136,7 @@ private RepositoryResources getRepositoryResources(final ProgrammingExercise pro // Get path, files and prefix for the programming-language dependent files. They are copied first. final Path generalTemplatePath = ProgrammingExerciseService.getProgrammingLanguageTemplatePath(programmingExercise.getProgrammingLanguage()) .resolve(projectTypeTemplateDir); - Resource[] resources = resourceLoaderService.getResources(generalTemplatePath); + Resource[] resources = resourceLoaderService.getFileResources(generalTemplatePath); Path prefix = Path.of(programmingLanguage).resolve(projectTypeTemplateDir); @@ -152,7 +152,7 @@ private RepositoryResources getRepositoryResources(final ProgrammingExercise pro final Path projectTypeSpecificPrefix = generalProjectTypePrefix.resolve(projectTypeTemplateDir); final Path projectTypeTemplatePath = programmingLanguageProjectTypePath.resolve(projectTypeTemplateDir); - final Resource[] projectTypeSpecificResources = resourceLoaderService.getResources(projectTypeTemplatePath); + final Resource[] projectTypeSpecificResources = resourceLoaderService.getFileResources(projectTypeTemplatePath); if (ProjectType.XCODE.equals(projectType)) { // For Xcode, we don't share source code, so we only copy files once @@ -312,7 +312,7 @@ private void setupJVMTestTemplateAndPush(final RepositoryResources resources, fi // Java supports multiple variants as test template final Path projectTemplatePath = getJavaProjectTemplatePath(templatePath, projectType); - final Resource[] projectTemplate = resourceLoaderService.getResources(projectTemplatePath); + final Resource[] projectTemplate = resourceLoaderService.getFileResources(projectTemplatePath); // keep the folder structure fileService.copyResources(projectTemplate, Path.of("projectTemplate"), repoLocalPath, true); @@ -375,7 +375,7 @@ private void setupJVMTestTemplateProjectTypeResources(final RepositoryResources final Path projectTypeProjectTemplatePath = projectTypeTemplatePath.resolve("projectTemplate"); try { - final Resource[] projectTypeProjectTemplate = resourceLoaderService.getResources(projectTypeProjectTemplatePath); + final Resource[] projectTypeProjectTemplate = resourceLoaderService.getFileResources(projectTypeProjectTemplatePath); fileService.copyResources(projectTypeProjectTemplate, resources.projectTypePrefix, repoLocalPath, false); } catch (FileNotFoundException fileNotFoundException) { @@ -397,7 +397,7 @@ private void setupTestTemplateRegularTestRuns(final RepositoryResources resource final ProjectType projectType = programmingExercise.getProjectType(); final Path repoLocalPath = getRepoAbsoluteLocalPath(resources.repository); final Path testFilePath = templatePath.resolve(TEST_FILES_PATH); - final Resource[] testFileResources = resourceLoaderService.getResources(testFilePath); + final Resource[] testFileResources = resourceLoaderService.getFileResources(testFilePath); final Path packagePath = repoLocalPath.resolve(TEST_DIR).resolve(PACKAGE_NAME_FOLDER_PLACEHOLDER).toAbsolutePath(); sectionsMap.put("non-sequential", true); @@ -440,7 +440,7 @@ private void setupBuildToolProjectFile(final Path repoLocalPath, final ProjectTy private void setupStaticCodeAnalysisConfigFiles(final RepositoryResources resources, final Path templatePath, final Path repoLocalPath) throws IOException { final Path staticCodeAnalysisConfigPath = templatePath.resolve("staticCodeAnalysisConfig"); - final Resource[] staticCodeAnalysisResources = resourceLoaderService.getResources(staticCodeAnalysisConfigPath); + final Resource[] staticCodeAnalysisResources = resourceLoaderService.getFileResources(staticCodeAnalysisConfigPath); fileService.copyResources(staticCodeAnalysisResources, resources.prefix, repoLocalPath, true); } @@ -450,7 +450,7 @@ private void overwriteProjectTypeSpecificFiles(final RepositoryResources resourc .resolve(TEST_DIR); try { - final Resource[] projectTypeTestFileResources = resourceLoaderService.getResources(projectTypeTemplatePath); + final Resource[] projectTypeTestFileResources = resourceLoaderService.getFileResources(projectTypeTemplatePath); // filter non-existing resources to avoid exceptions final List existingProjectTypeTestFileResources = new ArrayList<>(); for (final Resource resource : projectTypeTestFileResources) { @@ -562,7 +562,7 @@ private void setupBuildStage(final Path resourcePrefix, final Path templatePath, } final Path buildStageResourcesPath = templatePath.resolve(TEST_FILES_PATH).resolve(buildStageTemplateSubDirectory); - final Resource[] buildStageResources = resourceLoaderService.getResources(buildStageResourcesPath); + final Resource[] buildStageResources = resourceLoaderService.getFileResources(buildStageResourcesPath); fileService.copyResources(buildStageResources, resourcePrefix, packagePath, false); if (projectType != null) { @@ -574,7 +574,7 @@ private void overwriteStageFilesForProjectType(final Path resourcePrefix, final throws IOException { final Path buildStageResourcesPath = projectTemplatePath.resolve(TEST_FILES_PATH).resolve(buildStageTemplateSubDirectory); try { - final Resource[] buildStageResources = resourceLoaderService.getResources(buildStageResourcesPath); + final Resource[] buildStageResources = resourceLoaderService.getFileResources(buildStageResourcesPath); fileService.copyResources(buildStageResources, resourcePrefix, packagePath, false); } catch (FileNotFoundException fileNotFoundException) { diff --git a/src/main/resources/templates/assembler/exercise/git.ignore.file b/src/main/resources/templates/assembler/exercise/.gitignore similarity index 100% rename from src/main/resources/templates/assembler/exercise/git.ignore.file rename to src/main/resources/templates/assembler/exercise/.gitignore diff --git a/src/main/resources/templates/assembler/exercise/Makefile.file b/src/main/resources/templates/assembler/exercise/Makefile similarity index 100% rename from src/main/resources/templates/assembler/exercise/Makefile.file rename to src/main/resources/templates/assembler/exercise/Makefile diff --git a/src/main/resources/templates/assembler/solution/git.ignore.file b/src/main/resources/templates/assembler/solution/.gitignore similarity index 100% rename from src/main/resources/templates/assembler/solution/git.ignore.file rename to src/main/resources/templates/assembler/solution/.gitignore diff --git a/src/main/resources/templates/assembler/solution/Makefile.file b/src/main/resources/templates/assembler/solution/Makefile similarity index 100% rename from src/main/resources/templates/assembler/solution/Makefile.file rename to src/main/resources/templates/assembler/solution/Makefile diff --git a/src/main/resources/templates/assembler/test/Makefile.file b/src/main/resources/templates/assembler/test/Makefile similarity index 100% rename from src/main/resources/templates/assembler/test/Makefile.file rename to src/main/resources/templates/assembler/test/Makefile diff --git a/src/main/resources/templates/c/fact/test/Makefile.file b/src/main/resources/templates/c/fact/test/Makefile similarity index 100% rename from src/main/resources/templates/c/fact/test/Makefile.file rename to src/main/resources/templates/c/fact/test/Makefile diff --git a/src/main/resources/templates/c/gcc/exercise/git.attributes.file b/src/main/resources/templates/c/gcc/exercise/.gitattributes similarity index 100% rename from src/main/resources/templates/c/gcc/exercise/git.attributes.file rename to src/main/resources/templates/c/gcc/exercise/.gitattributes diff --git a/src/main/resources/templates/c/gcc/exercise/git.ignore.file b/src/main/resources/templates/c/gcc/exercise/.gitignore similarity index 100% rename from src/main/resources/templates/c/gcc/exercise/git.ignore.file rename to src/main/resources/templates/c/gcc/exercise/.gitignore diff --git a/src/main/resources/templates/c/gcc/exercise/Makefile.file b/src/main/resources/templates/c/gcc/exercise/Makefile similarity index 100% rename from src/main/resources/templates/c/gcc/exercise/Makefile.file rename to src/main/resources/templates/c/gcc/exercise/Makefile diff --git a/src/main/resources/templates/c/gcc/solution/git.attributes.file b/src/main/resources/templates/c/gcc/solution/.gitattributes similarity index 100% rename from src/main/resources/templates/c/gcc/solution/git.attributes.file rename to src/main/resources/templates/c/gcc/solution/.gitattributes diff --git a/src/main/resources/templates/c/gcc/solution/git.ignore.file b/src/main/resources/templates/c/gcc/solution/.gitignore similarity index 100% rename from src/main/resources/templates/c/gcc/solution/git.ignore.file rename to src/main/resources/templates/c/gcc/solution/.gitignore diff --git a/src/main/resources/templates/c/gcc/solution/Makefile.file b/src/main/resources/templates/c/gcc/solution/Makefile similarity index 100% rename from src/main/resources/templates/c/gcc/solution/Makefile.file rename to src/main/resources/templates/c/gcc/solution/Makefile diff --git a/src/main/resources/templates/c/gcc/test/Makefile.file b/src/main/resources/templates/c/gcc/test/Makefile similarity index 100% rename from src/main/resources/templates/c/gcc/test/Makefile.file rename to src/main/resources/templates/c/gcc/test/Makefile diff --git a/src/main/resources/templates/haskell/exercise/git.attributes.file b/src/main/resources/templates/haskell/exercise/.gitattributes similarity index 100% rename from src/main/resources/templates/haskell/exercise/git.attributes.file rename to src/main/resources/templates/haskell/exercise/.gitattributes diff --git a/src/main/resources/templates/haskell/exercise/git.ignore.file b/src/main/resources/templates/haskell/exercise/.gitignore similarity index 100% rename from src/main/resources/templates/haskell/exercise/git.ignore.file rename to src/main/resources/templates/haskell/exercise/.gitignore diff --git a/src/main/resources/templates/haskell/solution/git.attributes.file b/src/main/resources/templates/haskell/solution/.gitattributes similarity index 100% rename from src/main/resources/templates/haskell/solution/git.attributes.file rename to src/main/resources/templates/haskell/solution/.gitattributes diff --git a/src/main/resources/templates/haskell/solution/git.ignore.file b/src/main/resources/templates/haskell/solution/.gitignore similarity index 100% rename from src/main/resources/templates/haskell/solution/git.ignore.file rename to src/main/resources/templates/haskell/solution/.gitignore diff --git a/src/main/resources/templates/haskell/test/git.attributes.file b/src/main/resources/templates/haskell/test/.gitattributes similarity index 100% rename from src/main/resources/templates/haskell/test/git.attributes.file rename to src/main/resources/templates/haskell/test/.gitattributes diff --git a/src/main/resources/templates/haskell/test/git.ignore.file b/src/main/resources/templates/haskell/test/.gitignore similarity index 100% rename from src/main/resources/templates/haskell/test/git.ignore.file rename to src/main/resources/templates/haskell/test/.gitignore diff --git a/src/main/resources/templates/java/exercise/git.attributes.file b/src/main/resources/templates/java/exercise/.gitattributes similarity index 100% rename from src/main/resources/templates/java/exercise/git.attributes.file rename to src/main/resources/templates/java/exercise/.gitattributes diff --git a/src/main/resources/templates/java/exercise/git.ignore.file b/src/main/resources/templates/java/exercise/.gitignore similarity index 100% rename from src/main/resources/templates/java/exercise/git.ignore.file rename to src/main/resources/templates/java/exercise/.gitignore diff --git a/src/main/resources/templates/java/gradle_gradle/exercise/git.ignore.file b/src/main/resources/templates/java/gradle_gradle/exercise/.gitignore similarity index 100% rename from src/main/resources/templates/java/gradle_gradle/exercise/git.ignore.file rename to src/main/resources/templates/java/gradle_gradle/exercise/.gitignore diff --git a/src/main/resources/templates/java/gradle_gradle/exercise/gradlew.file b/src/main/resources/templates/java/gradle_gradle/exercise/gradlew similarity index 100% rename from src/main/resources/templates/java/gradle_gradle/exercise/gradlew.file rename to src/main/resources/templates/java/gradle_gradle/exercise/gradlew diff --git a/src/main/resources/templates/java/gradle_gradle/solution/git.ignore.file b/src/main/resources/templates/java/gradle_gradle/solution/.gitignore similarity index 100% rename from src/main/resources/templates/java/gradle_gradle/solution/git.ignore.file rename to src/main/resources/templates/java/gradle_gradle/solution/.gitignore diff --git a/src/main/resources/templates/java/gradle_gradle/solution/gradlew.file b/src/main/resources/templates/java/gradle_gradle/solution/gradlew similarity index 100% rename from src/main/resources/templates/java/gradle_gradle/solution/gradlew.file rename to src/main/resources/templates/java/gradle_gradle/solution/gradlew diff --git a/src/main/resources/templates/java/plain_gradle/exercise/git.ignore.file b/src/main/resources/templates/java/plain_gradle/exercise/.gitignore similarity index 100% rename from src/main/resources/templates/java/plain_gradle/exercise/git.ignore.file rename to src/main/resources/templates/java/plain_gradle/exercise/.gitignore diff --git a/src/main/resources/templates/java/plain_gradle/exercise/gradlew.file b/src/main/resources/templates/java/plain_gradle/exercise/gradlew similarity index 100% rename from src/main/resources/templates/java/plain_gradle/exercise/gradlew.file rename to src/main/resources/templates/java/plain_gradle/exercise/gradlew diff --git a/src/main/resources/templates/java/plain_gradle/solution/git.ignore.file b/src/main/resources/templates/java/plain_gradle/solution/.gitignore similarity index 100% rename from src/main/resources/templates/java/plain_gradle/solution/git.ignore.file rename to src/main/resources/templates/java/plain_gradle/solution/.gitignore diff --git a/src/main/resources/templates/java/plain_gradle/solution/gradlew.file b/src/main/resources/templates/java/plain_gradle/solution/gradlew similarity index 100% rename from src/main/resources/templates/java/plain_gradle/solution/gradlew.file rename to src/main/resources/templates/java/plain_gradle/solution/gradlew diff --git a/src/main/resources/templates/java/solution/git.attributes.file b/src/main/resources/templates/java/solution/.gitattributes similarity index 100% rename from src/main/resources/templates/java/solution/git.attributes.file rename to src/main/resources/templates/java/solution/.gitattributes diff --git a/src/main/resources/templates/java/solution/git.ignore.file b/src/main/resources/templates/java/solution/.gitignore similarity index 100% rename from src/main/resources/templates/java/solution/git.ignore.file rename to src/main/resources/templates/java/solution/.gitignore diff --git a/src/main/resources/templates/java/test/blackbox/projectTemplate/git.ignore.file b/src/main/resources/templates/java/test/blackbox/projectTemplate/.gitignore similarity index 100% rename from src/main/resources/templates/java/test/blackbox/projectTemplate/git.ignore.file rename to src/main/resources/templates/java/test/blackbox/projectTemplate/.gitignore diff --git a/src/main/resources/templates/java/test/gradle/projectTemplate/git.ignore.file b/src/main/resources/templates/java/test/gradle/projectTemplate/.gitignore similarity index 100% rename from src/main/resources/templates/java/test/gradle/projectTemplate/git.ignore.file rename to src/main/resources/templates/java/test/gradle/projectTemplate/.gitignore diff --git a/src/main/resources/templates/java/test/gradle/projectTemplate/gradlew.file b/src/main/resources/templates/java/test/gradle/projectTemplate/gradlew similarity index 100% rename from src/main/resources/templates/java/test/gradle/projectTemplate/gradlew.file rename to src/main/resources/templates/java/test/gradle/projectTemplate/gradlew diff --git a/src/main/resources/templates/java/test/maven/projectTemplate/git.ignore.file b/src/main/resources/templates/java/test/maven/projectTemplate/.gitignore similarity index 100% rename from src/main/resources/templates/java/test/maven/projectTemplate/git.ignore.file rename to src/main/resources/templates/java/test/maven/projectTemplate/.gitignore diff --git a/src/main/resources/templates/kotlin/exercise/git.attributes.file b/src/main/resources/templates/kotlin/exercise/.gitattributes similarity index 100% rename from src/main/resources/templates/kotlin/exercise/git.attributes.file rename to src/main/resources/templates/kotlin/exercise/.gitattributes diff --git a/src/main/resources/templates/kotlin/exercise/git.ignore.file b/src/main/resources/templates/kotlin/exercise/.gitignore similarity index 100% rename from src/main/resources/templates/kotlin/exercise/git.ignore.file rename to src/main/resources/templates/kotlin/exercise/.gitignore diff --git a/src/main/resources/templates/kotlin/solution/git.attributes.file b/src/main/resources/templates/kotlin/solution/.gitattributes similarity index 100% rename from src/main/resources/templates/kotlin/solution/git.attributes.file rename to src/main/resources/templates/kotlin/solution/.gitattributes diff --git a/src/main/resources/templates/kotlin/solution/git.ignore.file b/src/main/resources/templates/kotlin/solution/.gitignore similarity index 100% rename from src/main/resources/templates/kotlin/solution/git.ignore.file rename to src/main/resources/templates/kotlin/solution/.gitignore diff --git a/src/main/resources/templates/kotlin/test/maven/projectTemplate/git.ignore.file b/src/main/resources/templates/kotlin/test/maven/projectTemplate/.gitignore similarity index 100% rename from src/main/resources/templates/kotlin/test/maven/projectTemplate/git.ignore.file rename to src/main/resources/templates/kotlin/test/maven/projectTemplate/.gitignore diff --git a/src/main/resources/templates/ocaml/exercise/git.attributes.file b/src/main/resources/templates/ocaml/exercise/.gitattributes similarity index 100% rename from src/main/resources/templates/ocaml/exercise/git.attributes.file rename to src/main/resources/templates/ocaml/exercise/.gitattributes diff --git a/src/main/resources/templates/ocaml/exercise/git.ignore.file b/src/main/resources/templates/ocaml/exercise/.gitignore similarity index 100% rename from src/main/resources/templates/ocaml/exercise/git.ignore.file rename to src/main/resources/templates/ocaml/exercise/.gitignore diff --git a/src/main/resources/templates/ocaml/exercise/src/dune.file b/src/main/resources/templates/ocaml/exercise/src/dune similarity index 100% rename from src/main/resources/templates/ocaml/exercise/src/dune.file rename to src/main/resources/templates/ocaml/exercise/src/dune diff --git a/src/main/resources/templates/ocaml/solution/git.attributes.file b/src/main/resources/templates/ocaml/solution/.gitattributes similarity index 100% rename from src/main/resources/templates/ocaml/solution/git.attributes.file rename to src/main/resources/templates/ocaml/solution/.gitattributes diff --git a/src/main/resources/templates/ocaml/solution/git.ignore.file b/src/main/resources/templates/ocaml/solution/.gitignore similarity index 100% rename from src/main/resources/templates/ocaml/solution/git.ignore.file rename to src/main/resources/templates/ocaml/solution/.gitignore diff --git a/src/main/resources/templates/ocaml/solution/src/dune.file b/src/main/resources/templates/ocaml/solution/src/dune similarity index 100% rename from src/main/resources/templates/ocaml/solution/src/dune.file rename to src/main/resources/templates/ocaml/solution/src/dune diff --git a/src/main/resources/templates/ocaml/test/git.attributes.file b/src/main/resources/templates/ocaml/test/.gitattributes similarity index 100% rename from src/main/resources/templates/ocaml/test/git.attributes.file rename to src/main/resources/templates/ocaml/test/.gitattributes diff --git a/src/main/resources/templates/ocaml/test/git.ignore.file b/src/main/resources/templates/ocaml/test/.gitignore similarity index 100% rename from src/main/resources/templates/ocaml/test/git.ignore.file rename to src/main/resources/templates/ocaml/test/.gitignore diff --git a/src/main/resources/templates/ocaml/test/assignment/dune.file b/src/main/resources/templates/ocaml/test/assignment/dune similarity index 100% rename from src/main/resources/templates/ocaml/test/assignment/dune.file rename to src/main/resources/templates/ocaml/test/assignment/dune diff --git a/src/main/resources/templates/ocaml/test/checker/dune.file b/src/main/resources/templates/ocaml/test/checker/dune similarity index 100% rename from src/main/resources/templates/ocaml/test/checker/dune.file rename to src/main/resources/templates/ocaml/test/checker/dune diff --git a/src/main/resources/templates/ocaml/test/overrides/dune.file b/src/main/resources/templates/ocaml/test/overrides/dune similarity index 100% rename from src/main/resources/templates/ocaml/test/overrides/dune.file rename to src/main/resources/templates/ocaml/test/overrides/dune diff --git a/src/main/resources/templates/ocaml/test/solution/dune.file b/src/main/resources/templates/ocaml/test/solution/dune similarity index 100% rename from src/main/resources/templates/ocaml/test/solution/dune.file rename to src/main/resources/templates/ocaml/test/solution/dune diff --git a/src/main/resources/templates/ocaml/test/test/dune.file b/src/main/resources/templates/ocaml/test/test/dune similarity index 100% rename from src/main/resources/templates/ocaml/test/test/dune.file rename to src/main/resources/templates/ocaml/test/test/dune diff --git a/src/main/resources/templates/python/exercise/git.attributes.file b/src/main/resources/templates/python/exercise/.gitattributes similarity index 100% rename from src/main/resources/templates/python/exercise/git.attributes.file rename to src/main/resources/templates/python/exercise/.gitattributes diff --git a/src/main/resources/templates/python/exercise/git.ignore.file b/src/main/resources/templates/python/exercise/.gitignore similarity index 100% rename from src/main/resources/templates/python/exercise/git.ignore.file rename to src/main/resources/templates/python/exercise/.gitignore diff --git a/src/main/resources/templates/python/solution/git.attributes.file b/src/main/resources/templates/python/solution/.gitattributes similarity index 100% rename from src/main/resources/templates/python/solution/git.attributes.file rename to src/main/resources/templates/python/solution/.gitattributes diff --git a/src/main/resources/templates/python/solution/git.ignore.file b/src/main/resources/templates/python/solution/.gitignore similarity index 100% rename from src/main/resources/templates/python/solution/git.ignore.file rename to src/main/resources/templates/python/solution/.gitignore diff --git a/src/main/resources/templates/swift/exercise/git.attributes.file b/src/main/resources/templates/swift/exercise/.gitattributes similarity index 100% rename from src/main/resources/templates/swift/exercise/git.attributes.file rename to src/main/resources/templates/swift/exercise/.gitattributes diff --git a/src/main/resources/templates/swift/exercise/git.ignore.file b/src/main/resources/templates/swift/exercise/.gitignore similarity index 100% rename from src/main/resources/templates/swift/exercise/git.ignore.file rename to src/main/resources/templates/swift/exercise/.gitignore diff --git a/src/main/resources/templates/swift/solution/git.attributes.file b/src/main/resources/templates/swift/solution/.gitattributes similarity index 100% rename from src/main/resources/templates/swift/solution/git.attributes.file rename to src/main/resources/templates/swift/solution/.gitattributes diff --git a/src/main/resources/templates/swift/solution/git.ignore.file b/src/main/resources/templates/swift/solution/.gitignore similarity index 100% rename from src/main/resources/templates/swift/solution/git.ignore.file rename to src/main/resources/templates/swift/solution/.gitignore diff --git a/src/main/resources/templates/swift/xcode/exercise/git.attributes.file b/src/main/resources/templates/swift/xcode/exercise/.gitattributes similarity index 100% rename from src/main/resources/templates/swift/xcode/exercise/git.attributes.file rename to src/main/resources/templates/swift/xcode/exercise/.gitattributes diff --git a/src/main/resources/templates/swift/xcode/exercise/git.ignore.file b/src/main/resources/templates/swift/xcode/exercise/.gitignore similarity index 100% rename from src/main/resources/templates/swift/xcode/exercise/git.ignore.file rename to src/main/resources/templates/swift/xcode/exercise/.gitignore diff --git a/src/main/resources/templates/swift/xcode/solution/git.attributes.file b/src/main/resources/templates/swift/xcode/solution/.gitattributes similarity index 100% rename from src/main/resources/templates/swift/xcode/solution/git.attributes.file rename to src/main/resources/templates/swift/xcode/solution/.gitattributes diff --git a/src/main/resources/templates/swift/xcode/solution/git.ignore.file b/src/main/resources/templates/swift/xcode/solution/.gitignore similarity index 100% rename from src/main/resources/templates/swift/xcode/solution/git.ignore.file rename to src/main/resources/templates/swift/xcode/solution/.gitignore diff --git a/src/main/resources/templates/swift/xcode/test/fastlane/App.file b/src/main/resources/templates/swift/xcode/test/fastlane/Appfile similarity index 100% rename from src/main/resources/templates/swift/xcode/test/fastlane/App.file rename to src/main/resources/templates/swift/xcode/test/fastlane/Appfile diff --git a/src/main/resources/templates/swift/xcode/test/fastlane/Fast.file b/src/main/resources/templates/swift/xcode/test/fastlane/Fastfile similarity index 100% rename from src/main/resources/templates/swift/xcode/test/fastlane/Fast.file rename to src/main/resources/templates/swift/xcode/test/fastlane/Fastfile diff --git a/src/main/resources/templates/swift/xcode/test/fastlane/Scan.file b/src/main/resources/templates/swift/xcode/test/fastlane/Scanfile similarity index 100% rename from src/main/resources/templates/swift/xcode/test/fastlane/Scan.file rename to src/main/resources/templates/swift/xcode/test/fastlane/Scanfile diff --git a/src/main/resources/templates/vhdl/exercise/git.ignore.file b/src/main/resources/templates/vhdl/exercise/.gitignore similarity index 100% rename from src/main/resources/templates/vhdl/exercise/git.ignore.file rename to src/main/resources/templates/vhdl/exercise/.gitignore diff --git a/src/main/resources/templates/vhdl/exercise/Makefile.file b/src/main/resources/templates/vhdl/exercise/Makefile similarity index 100% rename from src/main/resources/templates/vhdl/exercise/Makefile.file rename to src/main/resources/templates/vhdl/exercise/Makefile diff --git a/src/main/resources/templates/vhdl/solution/git.ignore.file b/src/main/resources/templates/vhdl/solution/.gitignore similarity index 100% rename from src/main/resources/templates/vhdl/solution/git.ignore.file rename to src/main/resources/templates/vhdl/solution/.gitignore diff --git a/src/main/resources/templates/vhdl/solution/Makefile.file b/src/main/resources/templates/vhdl/solution/Makefile similarity index 100% rename from src/main/resources/templates/vhdl/solution/Makefile.file rename to src/main/resources/templates/vhdl/solution/Makefile diff --git a/src/main/resources/templates/vhdl/test/Makefile.file b/src/main/resources/templates/vhdl/test/Makefile similarity index 100% rename from src/main/resources/templates/vhdl/test/Makefile.file rename to src/main/resources/templates/vhdl/test/Makefile diff --git a/src/test/java/de/tum/in/www1/artemis/service/FileServiceTest.java b/src/test/java/de/tum/in/www1/artemis/service/FileServiceTest.java index ed89d38e8a8a..55d55346bfae 100644 --- a/src/test/java/de/tum/in/www1/artemis/service/FileServiceTest.java +++ b/src/test/java/de/tum/in/www1/artemis/service/FileServiceTest.java @@ -382,26 +382,12 @@ void testCopyResourceRemovePrefix(@TempDir Path targetDir) throws IOException { assertThat(expectedTargetFile).exists().isNotEmptyFile(); } - @Test - void testRenameSpecialFilename(@TempDir Path targetDir) throws IOException { - final Path sourceFile = overridableBasePath.resolve("Makefile.file"); - FileUtils.writeStringToFile(sourceFile.toFile(), "content", Charset.defaultCharset()); - - final Resource[] resources = resourceLoaderService.getResources(overridableBasePath); - assertThat(resources).isNotEmpty(); - - fileService.copyResources(resources, Path.of("templates"), targetDir, true); - - final Path expectedTargetFile = targetDir.resolve("jenkins").resolve("Makefile"); - assertThat(expectedTargetFile).exists().isNotEmptyFile(); - } - @Test void testIgnoreDirectoryFalsePositives(@TempDir Path targetDir) throws IOException { final Path sourceDirectory = overridableBasePath.resolve("package.xcworkspace"); Files.createDirectories(sourceDirectory); - final Resource[] resources = resourceLoaderService.getResources(overridableBasePath); + final Resource[] resources = resourceLoaderService.getFileResources(overridableBasePath); assertThat(resources).isNotEmpty(); fileService.copyResources(resources, Path.of("templates"), targetDir, true); diff --git a/src/test/java/de/tum/in/www1/artemis/service/ResourceLoaderServiceTest.java b/src/test/java/de/tum/in/www1/artemis/service/ResourceLoaderServiceTest.java index 85239865dd8a..835f4ebc3488 100644 --- a/src/test/java/de/tum/in/www1/artemis/service/ResourceLoaderServiceTest.java +++ b/src/test/java/de/tum/in/www1/artemis/service/ResourceLoaderServiceTest.java @@ -15,6 +15,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Arrays; import java.util.List; import org.apache.commons.io.FileUtils; @@ -59,7 +60,7 @@ void testShouldNotAllowAbsolutePathsSingleResource() { @Test void testShouldNotAllowAbsolutePathsMultipleResources() { final Path path = publicPath.toAbsolutePath(); - assertThatIllegalArgumentException().isThrownBy(() -> resourceLoaderService.getResources(path)); + assertThatIllegalArgumentException().isThrownBy(() -> resourceLoaderService.getFileResources(path)); } @Test @@ -93,7 +94,7 @@ void testLoadMultipleResourcesFromFilesystem(final String pathPattern) throws IO final String content = "filesystem"; setupJavaFiles(content); - Resource[] resources = resourceLoaderService.getResources(jenkinsFilesystemPaths.get(0).getParent(), pathPattern); + Resource[] resources = resourceLoaderService.getFileResources(jenkinsFilesystemPaths.get(0).getParent(), pathPattern); assertThat(resources).hasSize(2); for (final Resource resource : resources) { @@ -110,7 +111,7 @@ void testLoadMultipleResourcesNonOverridable(final String pathPattern) throws IO FileUtils.writeStringToFile(publicFile.toFile(), content, Charset.defaultCharset()); } - Resource[] resources = resourceLoaderService.getResources(Path.of("public"), pathPattern); + Resource[] resources = resourceLoaderService.getFileResources(Path.of("public"), pathPattern); assertThat(resources).hasSize(1); assertThat(resources[0].getFile()).hasContent("classpath"); @@ -118,10 +119,41 @@ void testLoadMultipleResourcesNonOverridable(final String pathPattern) throws IO @Test void testLoadNonExistingResources() { - Resource[] resources = resourceLoaderService.getResources(Path.of("non", "existing"), "*"); + Resource[] resources = resourceLoaderService.getFileResources(Path.of("non", "existing"), "*"); assertThat(resources).isNotNull().isEmpty(); } + @Test + void testLoadResourcesWithoutFileExtension() { + final Resource[] resources = resourceLoaderService.getFileResources(Path.of("templates", "c")); + final List resourceNames = Arrays.stream(resources).map(Resource::getFilename).toList(); + + assertThat(resourceNames).contains("Makefile"); + } + + @Test + void testLoadGitResources() { + final Resource gitignore = resourceLoaderService.getResource(Path.of("templates", "java", ".gitignore")); + final Resource gitattributes = resourceLoaderService.getResource(Path.of("templates", "java", ".gitattributes")); + + assertThat(gitignore.exists()).isTrue(); + assertThat(gitattributes.exists()).isTrue(); + } + + @Test + void testShouldNotLoadDirectories() { + final Resource[] resources = resourceLoaderService.getFileResources(Path.of("templates")); + + assertThat(resources).noneMatch(r -> { + try { + return r.getFile().isDirectory(); + } + catch (IOException e) { + throw new RuntimeException(e); + } + }); + } + private void setupJavaFiles(final String content) throws IOException { for (Path javaFilesystemPath : jenkinsFilesystemPaths) { FileUtils.writeStringToFile(javaFilesystemPath.toFile(), content, Charset.defaultCharset()); diff --git a/src/test/resources/templates/c/Makefile b/src/test/resources/templates/c/Makefile new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/src/test/resources/templates/java/.gitattributes b/src/test/resources/templates/java/.gitattributes new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/src/test/resources/templates/java/.gitignore b/src/test/resources/templates/java/.gitignore new file mode 100644 index 000000000000..e69de29bb2d1