Skip to content

Commit

Permalink
fix: Init command must replace inceptionYear placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Dec 21, 2022
1 parent 7a0d6c1 commit 94bbac7
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -725,4 +725,11 @@ ERROR_nexus_release_repository = Could not release staging repository {
ERROR_nexus_deploy_artifact = Error when deploying artifact {}
ERROR_deployer_stage_resolution = Some paths failed to be resolved
ERROR_deployer_unexpected_error_stage = Unexpected error when resolving staged artifacts
ERROR_deployer_maven_central_rules = Rules for publishing to Maven Central were not met
ERROR_deployer_maven_central_rules = Rules for publishing to Maven Central were not met

# text
jreleaser.init.TEXT_writing_file = Writing file {}
jreleaser.init.TEXT_success = JReleaser initialized at {}
# errors
jreleaser.init.ERROR_invalid_format = Unsupported file format. Must be one of [{}]
jreleaser.init.ERROR_file_exists = File {} already exists and overwrite was set to false.
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,13 @@ s3.object.write = escrivint s3://{}/{}
s3.object.acl = afegint permisos de lectura a s3://{}/{}
ERROR_unexpected_s3_client_config = Error durant la construcció del client AWS S3

# text
jreleaser.init.TEXT_writing_file = Escrivint fitxer {}
jreleaser.init.TEXT_success = JReleaser inicialitzat en {}
# errors
jreleaser.init.ERROR_invalid_format = Format de fitxer no admès. Ha de ser un dels [{}]
jreleaser.init.ERROR_file_exists = Fitxer {} ja existeix i la sobreescriptura s'ha definit com a falsa.

disco.fetch.packages = recollint paquets amb {}
disco.fetch.package = recollint paquet {}
disco.multiple.packages = Disco ha retornat {} paquet(s)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,10 @@ disco.multiple.packages = 디스코에서 {}개의 패키지를
disco.package.not.downloadable = {}는 직접 다운로드할 수 없습니다.
ERROR_disco_resolve_package = Disco가 결과를 리턴하지 않음: {}
ERROR_disco_resolve_pkg = Disco는 ephemeralId {}에 대한 결과를 리턴하지 않음.

# text
jreleaser.init.TEXT_writing_file = {} 파일 쓰는 중
jreleaser.init.TEXT_success = {} 으로 JReleaser 초기화 됨.
# errors
jreleaser.init.ERROR_invalid_format = 지원하지 않는 파일 포맷. [{}] 중 하나여야 함.
jreleaser.init.ERROR_file_exists = 이미 {} 파일이 존재하고, 덮어쓰기가 false로 설정됨.
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,11 @@ disco.fetch.package = получение пакета {}
disco.multiple.packages = Disco вернула {} пакетов
disco.package.not.downloadable = {} не может быть загружен напрямую
ERROR_disco_resolve_package = Disco не вернула результатов: {}
ERROR_disco_resolve_pkg = Disco не вернула результат для ephemeralId {}
ERROR_disco_resolve_pkg = Disco не вернула результат для ephemeralId {}

# text
jreleaser.init.TEXT_writing_file = Запись файла {}
jreleaser.init.TEXT_success = JReleaser инициализирован в {}
# errors
jreleaser.init.ERROR_invalid_format = Неподдерживаемый формат файла. Должен быть одним из [{}]
jreleaser.init.ERROR_file_exists = Файл {} уже существует, и для перезаписи задано значение false.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
import org.jreleaser.model.JReleaserException;
import org.jreleaser.templates.TemplateResource;
import org.jreleaser.templates.TemplateUtils;
import org.jreleaser.templates.VersionDecoratingWriter;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Writer;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.LocalDate;
import java.util.LinkedHashSet;
import java.util.ServiceLoader;
import java.util.Set;
Expand All @@ -37,6 +40,7 @@
import static java.nio.file.StandardOpenOption.CREATE_NEW;
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
import static java.nio.file.StandardOpenOption.WRITE;
import static org.jreleaser.bundle.RB.$;

/**
* @author Andres Almiray
Expand All @@ -46,26 +50,31 @@ public class Init {
public static void execute(JReleaserLogger logger, String format, boolean overwrite, Path outputDirectory) {
try {
if (!getSupportedConfigFormats().contains(format)) {
throw new JReleaserException("Unsupported file format. Must be one of [" +
String.join("|", getSupportedConfigFormats()) + "]");
throw new IllegalArgumentException($("jreleaser.init.ERROR_invalid_format",
String.join("|", getSupportedConfigFormats())));
}

Path outputFile = outputDirectory.resolve("jreleaser." + format);

TemplateResource template = TemplateUtils.resolveTemplate(logger, "init/jreleaser." + format + ".tpl");

logger.info("Writing file " + outputFile.toAbsolutePath());
try (Writer writer = Files.newBufferedWriter(outputFile, overwrite ? CREATE : CREATE_NEW, WRITE, TRUNCATE_EXISTING)) {
IOUtils.copy(template.getReader(), writer);
String content = IOUtils.toString(template.getReader());
LocalDate now = LocalDate.now();
content = content.replaceAll("@year@", now.getYear() + "");

logger.info($("jreleaser.init.TEXT_writing_file"), outputFile.toAbsolutePath());

try (Writer fileWriter = Files.newBufferedWriter(outputFile, overwrite ? CREATE : CREATE_NEW, WRITE, TRUNCATE_EXISTING);
BufferedWriter decoratedWriter = new VersionDecoratingWriter(fileWriter)) {
decoratedWriter.write(content);
} catch (FileAlreadyExistsException e) {
logger.error("File {} already exists and overwrite was set to false.", outputFile.toAbsolutePath());
logger.error($("jreleaser.init.ERROR_file_exists"), outputFile.toAbsolutePath());
return;
}

logger.info("JReleaser initialized at " + outputDirectory.toAbsolutePath());
logger.info($("jreleaser.init.TEXT_success"), outputDirectory.toAbsolutePath());
} catch (IllegalStateException | IOException e) {
logger.trace(e);
throw new JReleaserException("Unexpected error", e);
throw new JReleaserException($("ERROR_unexpected_error"), e);
} finally {
if (logger != null) logger.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
[distributions.app]
artifacts = [
{ path = "path/to/{{distributionName}}-{{projectVersion}}.zip" }
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ release:
distributions:
app:
artifacts:
- path: path/to/{{distributionName}}-{{projectVersion}}.zip
- path: path/to/{{distributionName}}-{{projectVersion}}.zip
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,6 @@ jreleaser.init.usage.headerHeading =
jreleaser.init.usage.header = Create a jreleaser config file.
# options
jreleaser.init.format = Configuration file format.
# text
jreleaser.init.TEXT_writing_file = Writing file {}
jreleaser.init.TEXT_success = JReleaser initialized at {}
# errors
jreleaser.init.ERROR_invalid_format = Unsupported file format. Must be one of [{}]
jreleaser.init.ERROR_file_exists = File {} already exists and overwrite was set to false.

###############################################################################
# Package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ jreleaser.init.usage.headerHeading =
jreleaser.init.usage.header = Cria un fitxer de configuració de jreleaser.
# options
jreleaser.init.format = Format de fitxer de configuració.
# text
jreleaser.init.TEXT_writing_file = Escrivint fitxer {}
jreleaser.init.TEXT_success = JReleaser inicialitzat en {}
# errors
jreleaser.init.ERROR_invalid_format = Format de fitxer no admès. Ha de ser un dels [{}]
jreleaser.init.ERROR_file_exists = Fitxer {} ja existeix i la sobreescriptura s'ha definit com a falsa.

###############################################################################
# Package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,6 @@ jreleaser.init.usage.headerHeading =
jreleaser.init.usage.header = jreleaser 설정 파일 생성.
# options
jreleaser.init.format = 파일 포맷 설정.
# text
jreleaser.init.TEXT_writing_file = {} 파일 쓰는 중
jreleaser.init.TEXT_success = {} 으로 JReleaser 초기화 됨.
# errors
jreleaser.init.ERROR_invalid_format = 지원하지 않는 파일 포맷. [{}] 중 하나여야 함.
jreleaser.init.ERROR_file_exists = 이미 {} 파일이 존재하고, 덮어쓰기가 false로 설정됨.


###############################################################################
# Package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ jreleaser.init.usage.headerHeading =
jreleaser.init.usage.header = Создать файл конфигурации jreleaser.
# options
jreleaser.init.format = Формат файла конфигурации.
# text
jreleaser.init.TEXT_writing_file = Запись файла {}
jreleaser.init.TEXT_success = JReleaser инициализирован в {}
# errors
jreleaser.init.ERROR_invalid_format = Неподдерживаемый формат файла. Должен быть одним из [{}]
jreleaser.init.ERROR_file_exists = Файл {} уже существует, и для перезаписи задано значение false.

###############################################################################
# Package
Expand Down

0 comments on commit 94bbac7

Please sign in to comment.