Skip to content

Commit

Permalink
Disable project types with missing license
Browse files Browse the repository at this point in the history
  • Loading branch information
magaupp committed Dec 29, 2024
1 parent 85af640 commit 5fb3abf
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package de.tum.cit.aet.artemis.programming.service;

import java.util.HashMap;
import java.util.EnumMap;
import java.util.Map;

import jakarta.annotation.Nullable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;

import de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage;
import de.tum.cit.aet.artemis.programming.domain.ProjectType;

/**
* This service provides information about features the different ProgrammingLanguages support.
Expand All @@ -18,7 +21,16 @@ public abstract class ProgrammingLanguageFeatureService implements InfoContribut

private static final Logger log = LoggerFactory.getLogger(ProgrammingLanguageFeatureService.class);

protected final Map<ProgrammingLanguage, ProgrammingLanguageFeature> programmingLanguageFeatures = new HashMap<>();
private final LicenseService licenseService;

private final Map<ProgrammingLanguage, ProgrammingLanguageFeature> programmingLanguageFeatures;

protected ProgrammingLanguageFeatureService(LicenseService licenseService) {
this.licenseService = licenseService;
this.programmingLanguageFeatures = getEnabledFeatures();
}

protected abstract Map<ProgrammingLanguage, ProgrammingLanguageFeature> getSupportedProgrammingLanguageFeatures();

/**
* Get the ProgrammingLanguageFeature configured for the given ProgrammingLanguage.
Expand All @@ -37,12 +49,45 @@ public ProgrammingLanguageFeature getProgrammingLanguageFeatures(ProgrammingLang
return programmingLanguageFeature;
}

public Map<ProgrammingLanguage, ProgrammingLanguageFeature> getProgrammingLanguageFeatures() {
return programmingLanguageFeatures;
}

@Override
public void contribute(Info.Builder builder) {
builder.withDetail("programmingLanguageFeatures", getProgrammingLanguageFeatures().values());
builder.withDetail("programmingLanguageFeatures", programmingLanguageFeatures.values());
}

private Map<ProgrammingLanguage, ProgrammingLanguageFeature> getEnabledFeatures() {
var features = new EnumMap<ProgrammingLanguage, ProgrammingLanguageFeature>(ProgrammingLanguage.class);
for (var programmingLanguageFeatureEntry : getSupportedProgrammingLanguageFeatures().entrySet()) {
var language = programmingLanguageFeatureEntry.getKey();
var feature = programmingLanguageFeatureEntry.getValue();
if (feature.projectTypes().isEmpty()) {
if (isProjectTypeUsable(language, null)) {
features.put(language, feature);
}
}
else {
var filteredProjectTypes = feature.projectTypes().stream().filter((projectType -> isProjectTypeUsable(language, projectType))).toList();
if (!filteredProjectTypes.isEmpty()) {
// @formatter:off
var filteredFeature = new ProgrammingLanguageFeature(
feature.programmingLanguage(),
feature.sequentialTestRuns(),
feature.staticCodeAnalysis(),
feature.plagiarismCheckSupported(),
feature.packageNameRequired(),
feature.checkoutSolutionRepositoryAllowed(),
filteredProjectTypes,
feature.testwiseCoverageAnalysisSupported(),
feature.auxiliaryRepositoriesSupported()
);
// @formatter:on
features.put(language, filteredFeature);
}
}
}
return features;
}

private boolean isProjectTypeUsable(ProgrammingLanguage programmingLanguage, @Nullable ProjectType projectType) {
return licenseService.isLicensed(programmingLanguage, projectType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
import static de.tum.cit.aet.artemis.programming.domain.ProjectType.MAVEN_MAVEN;
import static de.tum.cit.aet.artemis.programming.domain.ProjectType.PLAIN_MAVEN;

import java.util.EnumMap;
import java.util.List;
import java.util.Map;

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

import de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage;
import de.tum.cit.aet.artemis.programming.service.LicenseService;
import de.tum.cit.aet.artemis.programming.service.ProgrammingLanguageFeature;
import de.tum.cit.aet.artemis.programming.service.ProgrammingLanguageFeatureService;

Expand All @@ -22,10 +26,17 @@
@Profile("gitlabci")
public class GitLabCIProgrammingLanguageFeatureService extends ProgrammingLanguageFeatureService {

public GitLabCIProgrammingLanguageFeatureService() {
protected GitLabCIProgrammingLanguageFeatureService(LicenseService licenseService) {
super(licenseService);
}

@Override
protected Map<ProgrammingLanguage, ProgrammingLanguageFeature> getSupportedProgrammingLanguageFeatures() {
EnumMap<ProgrammingLanguage, ProgrammingLanguageFeature> programmingLanguageFeatures = new EnumMap<>(ProgrammingLanguage.class);
programmingLanguageFeatures.put(EMPTY, new ProgrammingLanguageFeature(EMPTY, false, false, false, false, false, List.of(), false, false));
programmingLanguageFeatures.put(JAVA, new ProgrammingLanguageFeature(JAVA, false, false, false, true, false, List.of(PLAIN_MAVEN, MAVEN_MAVEN), false, false));
programmingLanguageFeatures.put(JAVASCRIPT, new ProgrammingLanguageFeature(JAVASCRIPT, false, false, true, false, false, List.of(), false, false));
programmingLanguageFeatures.put(RUST, new ProgrammingLanguageFeature(RUST, false, false, true, false, false, List.of(), false, false));
return programmingLanguageFeatures;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,30 @@
import static de.tum.cit.aet.artemis.programming.domain.ProjectType.PLAIN_GRADLE;
import static de.tum.cit.aet.artemis.programming.domain.ProjectType.PLAIN_MAVEN;

import java.util.EnumMap;
import java.util.List;
import java.util.Map;

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

import de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage;
import de.tum.cit.aet.artemis.programming.service.LicenseService;
import de.tum.cit.aet.artemis.programming.service.ProgrammingLanguageFeature;
import de.tum.cit.aet.artemis.programming.service.ProgrammingLanguageFeatureService;

@Service
@Profile("jenkins")
public class JenkinsProgrammingLanguageFeatureService extends ProgrammingLanguageFeatureService {

public JenkinsProgrammingLanguageFeatureService() {
protected JenkinsProgrammingLanguageFeatureService(LicenseService licenseService) {
super(licenseService);
}

@Override
protected Map<ProgrammingLanguage, ProgrammingLanguageFeature> getSupportedProgrammingLanguageFeatures() {
// Must be extended once a new programming language is added
EnumMap<ProgrammingLanguage, ProgrammingLanguageFeature> programmingLanguageFeatures = new EnumMap<>(ProgrammingLanguage.class);
programmingLanguageFeatures.put(EMPTY, new ProgrammingLanguageFeature(EMPTY, false, false, false, false, false, List.of(), false, false));
programmingLanguageFeatures.put(C, new ProgrammingLanguageFeature(C, false, false, true, false, false, List.of(FACT, GCC), false, false));
programmingLanguageFeatures.put(C_PLUS_PLUS, new ProgrammingLanguageFeature(C_PLUS_PLUS, false, false, true, false, false, List.of(), false, false));
Expand All @@ -53,5 +63,6 @@ public JenkinsProgrammingLanguageFeatureService() {
// Jenkins is not supporting XCODE at the moment
programmingLanguageFeatures.put(SWIFT, new ProgrammingLanguageFeature(SWIFT, false, true, true, true, false, List.of(PLAIN), false, false));
programmingLanguageFeatures.put(TYPESCRIPT, new ProgrammingLanguageFeature(TYPESCRIPT, false, false, true, false, false, List.of(), false, false));
return programmingLanguageFeatures;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@
import static de.tum.cit.aet.artemis.programming.domain.ProjectType.PLAIN_GRADLE;
import static de.tum.cit.aet.artemis.programming.domain.ProjectType.PLAIN_MAVEN;

import java.util.EnumMap;
import java.util.List;
import java.util.Map;

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

import de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage;
import de.tum.cit.aet.artemis.programming.service.LicenseService;
import de.tum.cit.aet.artemis.programming.service.ProgrammingLanguageFeature;
import de.tum.cit.aet.artemis.programming.service.ProgrammingLanguageFeatureService;

Expand All @@ -42,8 +46,14 @@
@Profile(PROFILE_LOCALCI)
public class LocalCIProgrammingLanguageFeatureService extends ProgrammingLanguageFeatureService {

public LocalCIProgrammingLanguageFeatureService() {
protected LocalCIProgrammingLanguageFeatureService(LicenseService licenseService) {
super(licenseService);
}

@Override
protected Map<ProgrammingLanguage, ProgrammingLanguageFeature> getSupportedProgrammingLanguageFeatures() {
// Must be extended once a new programming language is added
EnumMap<ProgrammingLanguage, ProgrammingLanguageFeature> programmingLanguageFeatures = new EnumMap<>(ProgrammingLanguage.class);
programmingLanguageFeatures.put(EMPTY, new ProgrammingLanguageFeature(EMPTY, false, false, false, false, false, List.of(), false, true));
programmingLanguageFeatures.put(ASSEMBLER, new ProgrammingLanguageFeature(ASSEMBLER, false, false, false, false, false, List.of(), false, true));
programmingLanguageFeatures.put(C, new ProgrammingLanguageFeature(C, false, true, true, false, false, List.of(FACT, GCC), false, true));
Expand All @@ -63,5 +73,6 @@ public LocalCIProgrammingLanguageFeatureService() {
programmingLanguageFeatures.put(SWIFT, new ProgrammingLanguageFeature(SWIFT, false, false, true, true, false, List.of(PLAIN), false, true));
programmingLanguageFeatures.put(TYPESCRIPT, new ProgrammingLanguageFeature(TYPESCRIPT, false, false, true, false, false, List.of(), false, true));
programmingLanguageFeatures.put(VHDL, new ProgrammingLanguageFeature(VHDL, false, false, false, false, false, List.of(), false, true));
return programmingLanguageFeatures;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class ProgrammingExerciseDetailComponent implements OnInit, OnDestroy {
);
}
this.supportsAuxiliaryRepositories =
this.programmingLanguageFeatureService.getProgrammingLanguageFeature(programmingExercise.programmingLanguage).auxiliaryRepositoriesSupported ??
this.programmingLanguageFeatureService.getProgrammingLanguageFeature(programmingExercise.programmingLanguage)?.auxiliaryRepositoriesSupported ??
false;
this.localVCEnabled = profileInfo.activeProfiles.includes(PROFILE_LOCALVC);
this.localCIEnabled = profileInfo.activeProfiles.includes(PROFILE_LOCALCI);
Expand Down Expand Up @@ -248,9 +248,8 @@ export class ProgrammingExerciseDetailComponent implements OnInit, OnDestroy {
next: () => {
this.setLatestCoveredLineRatio();
this.checkAndAlertInconsistencies();
this.plagiarismCheckSupported = this.programmingLanguageFeatureService.getProgrammingLanguageFeature(
programmingExercise.programmingLanguage,
).plagiarismCheckSupported;
this.plagiarismCheckSupported =
this.programmingLanguageFeatureService.getProgrammingLanguageFeature(programmingExercise.programmingLanguage)?.plagiarismCheckSupported ?? false;

/** we make sure to await the results of the subscriptions (switchMap) to only call {@link getExerciseDetails} once */
this.updateDetailSections();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class ProgrammingExerciseUpdateComponent implements AfterViewInit, OnDest
const languageChanged = this.selectedProgrammingLanguageValue !== language;
this.selectedProgrammingLanguageValue = language;

const programmingLanguageFeature = this.programmingLanguageFeatureService.getProgrammingLanguageFeature(language);
const programmingLanguageFeature = this.programmingLanguageFeatureService.getProgrammingLanguageFeature(language)!;
this.packageNameRequired = programmingLanguageFeature?.packageNameRequired;
this.staticCodeAnalysisAllowed = programmingLanguageFeature.staticCodeAnalysis;
this.checkoutSolutionRepositoryAllowed = programmingLanguageFeature.checkoutSolutionRepositoryAllowed;
Expand Down Expand Up @@ -362,7 +362,7 @@ export class ProgrammingExerciseUpdateComponent implements AfterViewInit, OnDest

// update the project types for java programming exercises according to whether dependencies should be included
if (this.programmingExercise.programmingLanguage === ProgrammingLanguage.JAVA) {
const programmingLanguageFeature = this.programmingLanguageFeatureService.getProgrammingLanguageFeature(ProgrammingLanguage.JAVA);
const programmingLanguageFeature = this.programmingLanguageFeatureService.getProgrammingLanguageFeature(ProgrammingLanguage.JAVA)!;
if (type == ProjectType.MAVEN_BLACKBOX) {
this.selectedProjectTypeValue = ProjectType.MAVEN_BLACKBOX;
this.programmingExercise.projectType = ProjectType.MAVEN_BLACKBOX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export class ProgrammingLanguageFeatureService {
});
}

public getProgrammingLanguageFeature(programmingLanguage: ProgrammingLanguage): ProgrammingLanguageFeature {
return this.programmingLanguageFeatures.get(programmingLanguage)!;
public getProgrammingLanguageFeature(programmingLanguage: ProgrammingLanguage): ProgrammingLanguageFeature | undefined {
return this.programmingLanguageFeatures.get(programmingLanguage);
}

public supportsProgrammingLanguage(programmingLanguage: ProgrammingLanguage): boolean {
Expand Down

0 comments on commit 5fb3abf

Please sign in to comment.