Search in sources :

Example 1 with Deployment

use of com.faforever.api.config.FafApiProperties.Deployment in project faf-java-api by FAForever.

the class LegacyFeaturedModDeploymentTaskTest method setUp.

@Before
public void setUp() throws Exception {
    properties = new FafApiProperties();
    Deployment deployment = properties.getDeployment();
    deployment.setRepositoriesDirectory(repositoriesFolder.getRoot().getAbsolutePath());
    deployment.setFeaturedModsTargetDirectory(targetFolder.getRoot().getAbsolutePath());
    instance = new LegacyFeaturedModDeploymentTask(gitWrapper, featuredModService, properties);
}
Also used : Deployment(com.faforever.api.config.FafApiProperties.Deployment) FafApiProperties(com.faforever.api.config.FafApiProperties) Before(org.junit.Before)

Example 2 with Deployment

use of com.faforever.api.config.FafApiProperties.Deployment in project faf-java-api by FAForever.

the class LegacyFeaturedModDeploymentTask method run.

@Override
@SneakyThrows
@Transactional(TxType.MANDATORY)
public void run() {
    Assert.state(featuredMod != null, "Configuration must be set");
    String modName = featuredMod.getTechnicalName();
    Assert.state(featuredModService.getFeaturedMods().stream().anyMatch(featuredMod -> Objects.equals(featuredMod.getTechnicalName(), modName)), "Unknown mod: " + modName);
    String repositoryUrl = featuredMod.getGitUrl();
    String branch = featuredMod.getGitBranch();
    boolean allowOverride = Optional.ofNullable(featuredMod.isAllowOverride()).orElse(false);
    String modFilesExtension = featuredMod.getFileExtension();
    Map<String, Short> fileIds = featuredModService.getFileIds(modName);
    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, allowOverride, modName);
    Deployment deployment = apiProperties.getDeployment();
    Path targetFolder = Paths.get(deployment.getFeaturedModsTargetDirectory(), String.format(deployment.getFilesDirectoryFormat(), modName));
    List<StagedFile> files = packageDirectories(repositoryDirectory, version, fileIds, targetFolder);
    createPatchedExe(version, fileIds, targetFolder).ifPresent(files::add);
    if (files.isEmpty()) {
        log.warn("Could not find any files to deploy. Is the configuration correct?");
        return;
    }
    files.forEach(this::finalizeFile);
    updateDatabase(files, version, modName);
    log.info("Deployment of '{}' version '{}' was successful", modName, version);
}
Also used : FeaturedModService(com.faforever.api.featuredmods.FeaturedModService) Setter(lombok.Setter) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) Deployment(com.faforever.api.config.FafApiProperties.Deployment) SneakyThrows(lombok.SneakyThrows) ForgedAllianceExePatcher(com.faforever.commons.fa.ForgedAllianceExePatcher) OptionalInt(java.util.OptionalInt) FeaturedMod(com.faforever.api.data.domain.FeaturedMod) StandardCopyOption(java.nio.file.StandardCopyOption) FilePermissionUtil(com.faforever.api.utils.FilePermissionUtil) Hashing.md5(com.google.common.hash.Hashing.md5) Files.hash(com.google.common.io.Files.hash) Map(java.util.Map) GitWrapper(com.faforever.api.deployment.git.GitWrapper) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) Path(java.nio.file.Path) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) TxType(javax.transaction.Transactional.TxType) Transactional(javax.transaction.Transactional) Files(java.nio.file.Files) FeaturedModFile(com.faforever.api.featuredmods.FeaturedModFile) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Files.createDirectories(java.nio.file.Files.createDirectories) Collectors(java.util.stream.Collectors) File(java.io.File) Objects(java.util.Objects) Consumer(java.util.function.Consumer) FileVisitResult(java.nio.file.FileVisitResult) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) Stream(java.util.stream.Stream) ValidationException(javax.validation.ValidationException) Paths(java.nio.file.Paths) ByteStreams(com.google.common.io.ByteStreams) Data(lombok.Data) ModReader(com.faforever.commons.mod.ModReader) Optional(java.util.Optional) Lazy(org.springframework.context.annotation.Lazy) FafApiProperties(com.faforever.api.config.FafApiProperties) NoCatch.noCatch(com.github.nocatch.NoCatch.noCatch) Assert(org.springframework.util.Assert) InputStream(java.io.InputStream) Path(java.nio.file.Path) Deployment(com.faforever.api.config.FafApiProperties.Deployment) SneakyThrows(lombok.SneakyThrows) Transactional(javax.transaction.Transactional)

Aggregations

FafApiProperties (com.faforever.api.config.FafApiProperties)2 Deployment (com.faforever.api.config.FafApiProperties.Deployment)2 FeaturedMod (com.faforever.api.data.domain.FeaturedMod)1 GitWrapper (com.faforever.api.deployment.git.GitWrapper)1 FeaturedModFile (com.faforever.api.featuredmods.FeaturedModFile)1 FeaturedModService (com.faforever.api.featuredmods.FeaturedModService)1 FilePermissionUtil (com.faforever.api.utils.FilePermissionUtil)1 ForgedAllianceExePatcher (com.faforever.commons.fa.ForgedAllianceExePatcher)1 ModReader (com.faforever.commons.mod.ModReader)1 NoCatch.noCatch (com.github.nocatch.NoCatch.noCatch)1 Hashing.md5 (com.google.common.hash.Hashing.md5)1 ByteStreams (com.google.common.io.ByteStreams)1 Files.hash (com.google.common.io.Files.hash)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 FileVisitResult (java.nio.file.FileVisitResult)1 Files (java.nio.file.Files)1 Files.createDirectories (java.nio.file.Files.createDirectories)1 Path (java.nio.file.Path)1