Skip to content

Commit

Permalink
Merge b66d67b into 32a5acb
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Sep 5, 2019
2 parents 32a5acb + b66d67b commit d13005e
Show file tree
Hide file tree
Showing 45 changed files with 1,183 additions and 624 deletions.
17 changes: 16 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ dependencyManagement {
}
}

test {
useJUnitPlatform {
}
testLogging {
events("passed", "skipped", "failed")
}
}

dependencies {
compileOnly("org.projectlombok:lombok:${lombokVersion}")
annotationProcessor("org.projectlombok:lombok:${lombokVersion}")
Expand Down Expand Up @@ -251,7 +259,6 @@ dependencies {
compile("org.luaj:luaj-jse:${luajVersion}")
compile("com.github.micheljung:nocatch:${nocatchVersion}")
compile("junit-addons:junit-addons:${junitAddonsVersion}")
compile("com.googlecode.zohhak:zohhak:${zohhakVersion}")
compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${jacksonDatatypeJsr310Version}")
compile("com.mandrillapp.wrapper.lutung:lutung:${lutungVersion}")
compile("org.apache.commons:commons-compress:${commonsCompressVersion}")
Expand All @@ -265,9 +272,17 @@ dependencies {
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("org.springframework.restdocs:spring-restdocs-mockmvc")
testCompile("org.springframework.security:spring-security-test")
testImplementation("junit:junit")
testImplementation("org.junit.jupiter:junit-jupiter:${jUnit5Version}")
testImplementation("org.junit.jupiter:junit-jupiter-params:${jUnit5Version}")
testImplementation("org.mockito:mockito-junit-jupiter:${mockitoVersion}")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:${jUnit5Version}")
testCompile("com.h2database:h2:${h2Version}")
testCompile("com.jayway.jsonpath:json-path:${jsonPath}")
testCompile("com.jayway.jsonpath:json-path-assert:${jsonPathAssert}")

codacy("com.github.codacy:codacy-coverage-reporter:${codacyCoverageReporterVersion}")
}

ext["mockito.version"] = "${mockitoVersion}"
ext["junit-jupiter.version"] = "${jUnit5Version}"
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ springBootAdminClientVersion=2.0.6
luajVersion=3.0.1
nocatchVersion=1.1
junitAddonsVersion=1.4
zohhakVersion=1.1.1
githubApiVersion=1.84
jgitVersionn=4.5.0.201609210915-r
fafCommonsVersion=8860b91752f6b5713926036dbb4740197d27211b
fafCommonsVersion=49fc2bf75413930043fe15e5dfce418c89cecafb
h2Version=1.4.193
jacksonDatatypeJsr310Version=2.9.7
mockitoVersion=2.19.0
mockitoVersion=2.23.4
lutungVersion=0.0.7
commonsCompressVersion=1.13
jsonPath=2.2.0
Expand All @@ -32,3 +31,4 @@ codacyCoverageReporterVersion=4.0.0
jsonVersion=20180813
javaxInterceptorApiVersion=1.2
lombokVersion=1.18.4
jUnit5Version=5.5.1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.springframework.security.web.util.matcher.RequestMatcher;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -91,7 +90,7 @@ public boolean matches(HttpServletRequest request) {

@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/faforever/api/error/ApiException.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.ToString;

import java.util.Arrays;
import java.util.Collection;

@Getter
@ToString
Expand All @@ -15,8 +16,16 @@ public ApiException(Error error) {
this(new Error[]{error});
}

public ApiException(Error[] errors) {
public ApiException(Error... errors) {
super(Arrays.toString(errors));
this.errors = errors;
}

public static ApiException of(ErrorCode errorCode, Object... args) {
return new ApiException(new Error(errorCode, args));
}

public static ApiException of(Collection<Error> errors) {
return new ApiException(errors.toArray(new Error[0]));
}
}
10 changes: 7 additions & 3 deletions src/main/java/com/faforever/api/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ public enum ErrorCode {
VOTING_SUBJECT_DOES_NOT_EXIST(180, "Voting subject does not exist", "There is no voting subject with the ID ''{0}''."),
VOTING_CHOICE_DOES_NOT_EXIST(181, "Invalid choice", "There is no voting choice with the ID ''{0}''."),
STEAM_ID_ALREADY_LINKED(182, " Steam account already linked to a FAF account", "You linked this account already to user with name ''{0}''."),
MAP_NAME_INVALID(183, "Map name invalid", "The name of the map in the scenario file can only contain printable ASCII characters and blanks."),
MOD_NAME_INVALID(184, "Mod name invalid", "The name of the mod in the scenario file can only contain printable ASCII characters and blanks.");

MAP_NAME_INVALID_CHARACTER(183, "Map name invalid", "Only latin characters, numbers, blanks and the minus are allowed."),
MOD_NAME_INVALID(184, "Mod name invalid", "The name of the mod in the scenario file can only contain printable ASCII characters and blanks."),
MAP_NAME_INVALID_MINUS_OCCURENCE(185, "Map name invalid", "Only a maximum of {0} minus characters are allowed."),
MAP_SCRIPT_LINE_MISSING(186, "Missing scenario.lua line", "The scenario.lua has to contain the following line: {0}"),
MAP_NAME_TOO_SHORT(187, "Map name invalid", "The map name must have at least {0, number} characters, was: {1, number}"),
MAP_NAME_DOES_NOT_START_WITH_LETTER(188, "Map name invalid", "The map name has to begin with a letter"),
PARSING_LUA_FILE_FAILED(189, "Parsing lua files failed", "During the parsing of the lua file an error occured: {0}");

private final int code;
private final String title;
Expand Down
104 changes: 104 additions & 0 deletions src/main/java/com/faforever/api/map/MapLuaAccessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.faforever.api.map;

import com.faforever.commons.lua.LuaAccessor;
import org.luaj.vm2.LuaValue;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional;
import java.util.OptionalInt;

public class MapLuaAccessor {
private static final String ROOT_ELEMENT = "ScenarioInfo";
private static final String CONFIGURATIONS = "Configurations";
private static final String NAME = "name";
private static final String DESCRIPTION = "description";
private static final String TYPE = "type";
private static final String SIZE = "size";
private static final String MAP_VERSION = "map_version";
private static final String CONFIGURATION_STANDARD = "standard";
private static final String CONFIGURATION_STANDARD_TEAMS = "teams";
private static final String CONFIGURATION_STANDARD_TEAMS_NAME = "name";
private static final String CONFIGURATION_STANDARD_TEAMS_ARMIES = "armies";


private final LuaAccessor luaAccessor;

private MapLuaAccessor(LuaAccessor luaAccessor) {
this.luaAccessor = luaAccessor;
}

public static MapLuaAccessor of(Path scenarioLuaPath) throws IOException {
return new MapLuaAccessor(LuaAccessor.of(scenarioLuaPath, ROOT_ELEMENT));
}

public static MapLuaAccessor of(String scenarioLuaCode) throws IOException {
return new MapLuaAccessor(LuaAccessor.of(scenarioLuaCode, ROOT_ELEMENT));
}

public Optional<String> getName() {
return luaAccessor.readVariableString(NAME);
}

public Optional<String> getDescription() {
return luaAccessor.readVariableString(DESCRIPTION);
}

public Optional<String> getType() {
return luaAccessor.readVariableString(TYPE);
}

public Optional<LuaValue> getSize() {
return luaAccessor.readVariable(SIZE);
}

public OptionalInt getMapVersion() {
return luaAccessor.readVariableInt(MAP_VERSION);
}

public boolean hasVariableMatching(String regex, String... names) {
return luaAccessor.hasVariableMatching(regex, names);
}

public Optional<LuaValue> getFirstTeam() {
Optional<LuaValue> configurationStandardTeamsOptional = luaAccessor.readVariable(
CONFIGURATIONS, CONFIGURATION_STANDARD, CONFIGURATION_STANDARD_TEAMS);

return configurationStandardTeamsOptional
.map(teams -> teams.get(1));
}

public boolean hasInvalidTeam() {
return getFirstTeam()
.map(firstTeam ->
!LuaAccessor.isValue(firstTeam, CONFIGURATION_STANDARD_TEAMS_NAME) ||
!LuaAccessor.isValue(firstTeam, CONFIGURATION_STANDARD_TEAMS_ARMIES) ||
!firstTeam.get(CONFIGURATION_STANDARD_TEAMS_NAME).tojstring().equals("FFA"))
.orElse(true);
}

public String getName$() {
return getName().get();
}

public String getDescription$() {
return getDescription().get();
}

public String getType$() {
return getType().get();
}

public LuaValue getSize$() {
return getSize().get();
}

public int getMapVersion$() {
return getMapVersion().getAsInt();
}

public LuaValue getFirstTeam$() {
return getFirstTeam().get();
}

}
22 changes: 22 additions & 0 deletions src/main/java/com/faforever/api/map/MapNameValidationResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.faforever.api.map;

import lombok.Builder;
import lombok.Value;

@Value
@Builder
public class MapNameValidationResponse {
String displayName;
int nextVersion;
String folderName;
FileNames fileNames;

@Value
@Builder
static class FileNames {
String scmap;
String saveLua;
String scenarioLua;
String scriptLua;
}
}
Loading

0 comments on commit d13005e

Please sign in to comment.