Skip to content

Commit

Permalink
Merge branch 'release/0.8.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
micheljung committed Sep 8, 2017
2 parents f747740 + 28d2a37 commit a2a6890
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ apply plugin: 'org.springframework.boot'
apply plugin: 'propdeps'

group = 'faforever'
version = '0.8.0'
version = '0.8.1'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/faforever/api/data/domain/FeaturedMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class FeaturedMod {
private int order;
private String gitUrl;
private String gitBranch;
private Boolean replaceExisting;
private Boolean allowOverride;
private String fileExtension;

@Id
Expand Down Expand Up @@ -65,9 +65,9 @@ public String getGitBranch() {
return gitBranch;
}

@Column(name = "replace_existing")
public Boolean isReplaceExisting() {
return replaceExisting;
@Column(name = "allow_override")
public Boolean isAllowOverride() {
return allowOverride;
}

@Column(name = "file_extension")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ public void run() {

String repositoryUrl = featuredMod.getGitUrl();
String branch = featuredMod.getGitBranch();
boolean replaceExisting = featuredMod.isReplaceExisting();
boolean allowOverride = featuredMod.isAllowOverride();
String modFilesExtension = featuredMod.getFileExtension();
Map<String, Short> fileIds = featuredModService.getFileIds(modName);

log.info("Starting deployment of '{}' from '{}', branch '{}', replaceExisting '{}', modFilesExtension '{}'",
modName, repositoryUrl, branch, replaceExisting, modFilesExtension);
log.info("Starting deployment of '{}' from '{}', branch '{}', allowOverride '{}', modFilesExtension '{}'",
modName, repositoryUrl, branch, allowOverride, modFilesExtension);

Path repositoryDirectory = buildRepositoryDirectoryPath(repositoryUrl);
checkoutCode(repositoryDirectory, repositoryUrl, branch);

short version = readModVersion(repositoryDirectory);
verifyVersion(version, replaceExisting, modName);
verifyVersion(version, allowOverride, modName);

Deployment deployment = apiProperties.getDeployment();
Path targetFolder = Paths.get(deployment.getFeaturedModsTargetDirectory(), String.format(deployment.getFilesDirectoryFormat(), modName));
Expand Down Expand Up @@ -134,8 +134,8 @@ private short readModVersion(Path modPath) {
return (short) Integer.parseInt(new ModReader().readDirectory(modPath).getVersion().toString());
}

private void verifyVersion(int version, boolean replaceExisting, String modName) {
if (!replaceExisting) {
private void verifyVersion(int version, boolean allowOverride, String modName) {
if (!allowOverride) {
// Normally I'd create a proper query, but this is a hotfix and a protest against the DB-driven patcher
// Luckily, BiReUS is coming "soon".
OptionalInt existingVersion = featuredModService.getFiles(modName, version).stream()
Expand All @@ -153,7 +153,7 @@ private void updateDatabase(List<StagedFile> files, short version, String modNam
List<FeaturedModFile> featuredModFiles = files.stream()
.map(file -> new FeaturedModFile()
.setMd5(noCatch(() -> hash(file.getTargetFile().toFile(), md5())).toString())
.setFileId(file.getFileId())
.setFileId((short) file.getFileId())
.setName(file.getTargetFile().getFileName().toString())
.setVersion(version)
)
Expand Down Expand Up @@ -279,7 +279,7 @@ private class StagedFile {
/**
* ID of the file as stored in the database.
*/
private final int fileId;
private final short fileId;
/**
* The staged file, already in the correct location, that is ready to be renamed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
@Immutable
@Entity
@EntityListeners(FeaturedModFileEnricher.class)
// Thanks to the dynamic table nature of the legacy updater, this class is not mapped to an underlying database but
// Thanks to the dynamic table nature of the legacy updater, this class is not mapped to an underlying table but
// a native query instead. This is why the columns here can't be found in any table.
public class FeaturedModFile {

private int id;
private String group;
private String md5;
private String name;
private short version;
private int version;
private String url;
private String folderName;
private int fileId;
private short fileId;

@Id
@Column(name = "id")
Expand All @@ -48,12 +48,12 @@ public String getName() {
}

@Column(name = "version")
public short getVersion() {
public int getVersion() {
return version;
}

@Column(name = "fileId")
public int getFileId() {
public short getFileId() {
return fileId;
}

Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/config/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ faf-api:
mandrill-api-key: ${MANDRILL_API_KEY}
clan:
website-url-format: ${CLAN_WEBSITE_URL_FORMAT}
challonge:
key: ${CHALLONGE_KEY:}

spring:
datasource:
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ faf-api:
html-format: <p>Dear %1$s,</p><p>welcome to the Forged Alliance Forever community. Please visit the following link to activate your account:</p><p><a href="%2$s">%2$s</a></p><p>-- The Forged Alliance Forever team.</p>
clan:
invite-link-expire-duration-minutes: ${CLAN_INVITE_LINK_EXPIRE_DURATION_MINUTES:604800}
challonge:
key: ${CHALLONGE_KEY:}

spring:
application:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ public void testRunNoFileIds() throws Exception {
.setGitBranch("branch")
.setFileExtension("nx3")
.setTechnicalName("faf")
.setReplaceExisting(true)
.setAllowOverride(true)
.setGitUrl("git@example.com/FAForever/faf"));

Mockito.doAnswer(invocation -> {
Path repoFolder = invocation.getArgument(0);
Files.createDirectories(repoFolder.resolve("someDir"));
Files.copy(
LegacyFeaturedModDeploymentTaskTest.class.getResourceAsStream("/featured_mod/mod_info.lua"),
repoFolder.resolve("mod_info.lua")
LegacyFeaturedModDeploymentTaskTest.class.getResourceAsStream("/featured_mod/mod_info.lua"),
repoFolder.resolve("mod_info.lua")
);
return null;
}).when(gitWrapper).checkoutRef(any(), any());
Expand All @@ -105,18 +105,18 @@ public void testRun() throws Exception {
.setGitBranch("branch")
.setFileExtension("nx3")
.setTechnicalName("faf")
.setReplaceExisting(true)
.setAllowOverride(true)
.setGitUrl("git@example.com/FAForever/faf"));

Mockito.doAnswer(invocation -> {
Path repoFolder = invocation.getArgument(0);
Files.createDirectories(repoFolder.resolve("someDir"));
Files.copy(
LegacyFeaturedModDeploymentTaskTest.class.getResourceAsStream("/featured_mod/mod_info.lua"),
repoFolder.resolve("mod_info.lua")
LegacyFeaturedModDeploymentTaskTest.class.getResourceAsStream("/featured_mod/mod_info.lua"),
repoFolder.resolve("mod_info.lua")
);
Files.copy(LegacyFeaturedModDeploymentTaskTest.class.getResourceAsStream("/featured_mod/someDir/someFile"),
repoFolder.resolve("someDir/someFile")
repoFolder.resolve("someDir/someFile")
);
return null;
}).when(gitWrapper).checkoutRef(any(), any());
Expand All @@ -125,8 +125,8 @@ public void testRun() throws Exception {
new FeaturedMod().setTechnicalName("faf")
));
when(featuredModService.getFileIds("faf")).thenReturn(ImmutableMap.of(
"ForgedAlliance.exe", (short) 1,
"someDir.nx3", (short) 2
"ForgedAlliance.exe", (short) 1,
"someDir.nx3", (short) 2
));

Path dummyExe = repositoriesFolder.getRoot().toPath().resolve("TemplateForgedAlliance.exe");
Expand All @@ -141,15 +141,15 @@ public void testRun() throws Exception {
List<FeaturedModFile> files = filesCaptor.getValue();
files.sort(Comparator.comparing(FeaturedModFile::getFileId));

assertThat(files.get(0).getFileId(), is(1));
assertThat(files.get(0).getFileId(), is((short) 1));
assertThat(files.get(0).getMd5(), is("47df959058cb52fe966ea5936dbd8f4c"));
assertThat(files.get(0).getName(), is("ForgedAlliance.1337.exe"));
assertThat(files.get(0).getVersion(), is((short) 1337));
assertThat(files.get(0).getVersion(), is(1337));

assertThat(files.get(1).getFileId(), is(2));
assertThat(files.get(1).getFileId(), is((short) 2));
assertThat(files.get(1).getMd5(), is(notNullValue()));
assertThat(files.get(1).getName(), is("someDir.1337.nx3"));
assertThat(files.get(1).getVersion(), is((short) 1337));
assertThat(files.get(1).getVersion(), is(1337));

assertThat(Files.exists(targetFolder.getRoot().toPath().resolve("updates_faf_files/someDir.1337.nx3")), is(true));
assertThat(Files.exists(targetFolder.getRoot().toPath().resolve("updates_faf_files/ForgedAlliance.1337.exe")), is(true));
Expand Down

0 comments on commit a2a6890

Please sign in to comment.