use of org.jreleaser.util.JReleaserException in project jreleaser by jreleaser.
the class Init method execute.
protected void execute() {
try {
outputDirectory = null != basedir ? basedir : Paths.get(".").normalize();
initLogger();
if (!getSupportedConfigFormats().contains(format)) {
spec.commandLine().getErr().println(spec.commandLine().getColorScheme().errorText($("jreleaser.init.ERROR_invalid_format", String.join("|", getSupportedConfigFormats()))));
spec.commandLine().usage(parent.out);
throw new HaltExecutionException();
}
Path outputFile = outputDirectory.resolve("jreleaser." + format);
Reader template = TemplateUtils.resolveTemplate(logger, "jreleaser." + format + ".tpl");
StringWriter sw = new StringWriter();
try (Scanner scanner = new Scanner(template)) {
while (scanner.hasNextLine()) {
sw.write(scanner.nextLine() + System.lineSeparator());
}
}
String content = sw.toString();
LocalDate now = LocalDate.now();
content = content.replaceAll("@year@", now.getYear() + "");
logger.info($("jreleaser.init.TEXT_writing_file"), outputFile.toAbsolutePath());
try {
Files.write(outputFile, content.getBytes(), (overwrite ? CREATE : CREATE_NEW), WRITE, TRUNCATE_EXISTING);
} catch (FileAlreadyExistsException e) {
logger.error($("jreleaser.init.ERROR_file_exists"), outputFile.toAbsolutePath());
return;
}
if (!quiet) {
logger.info($("jreleaser.init.TEXT_success"), outputDirectory.toAbsolutePath());
}
} catch (IllegalStateException | IOException e) {
throw new JReleaserException($("ERROR_unexpected_error"), e);
}
}
use of org.jreleaser.util.JReleaserException in project jreleaser by jreleaser.
the class TemplateUtils method resolveTemplates.
public static Map<String, Reader> resolveTemplates(String distributionType, String toolName, boolean snapshot, Path templateDirectory) {
Map<String, Reader> templates = new LinkedHashMap<>();
Path snapshotTemplateDirectory = templateDirectory.resolveSibling(templateDirectory.getFileName() + "-snapshot");
Path directory = templateDirectory;
if (snapshot && snapshotTemplateDirectory.toFile().exists()) {
directory = snapshotTemplateDirectory;
}
Path actualTemplateDirectory = directory;
try {
Files.walkFileTree(actualTemplateDirectory, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
templates.put(actualTemplateDirectory.relativize(file).toString(), Files.newBufferedReader(file));
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
String distributionTypeName = distributionType.toLowerCase().replace('_', '-');
throw new JReleaserException(RB.$("ERROR_unexpected_reading_templates_distribution", distributionTypeName, toolName, actualTemplateDirectory.toAbsolutePath()));
}
return templates;
}
use of org.jreleaser.util.JReleaserException in project jreleaser by jreleaser.
the class Artifacts method resolveFiles.
public static Set<Artifact> resolveFiles(JReleaserLogger logger, Path basedir, Collection<String> globs) throws JReleaserException {
if (null == globs || globs.isEmpty()) {
return Collections.emptySet();
}
FileSystem fileSystem = FileSystems.getDefault();
List<PathMatcher> matchers = new ArrayList<>();
for (String glob : globs) {
matchers.add(fileSystem.getPathMatcher(glob));
}
GlobResolver resolver = new GlobResolver(logger, basedir, matchers);
try {
java.nio.file.Files.walkFileTree(basedir, resolver);
if (resolver.failed) {
throw new JReleaserException(RB.$("ERROR_artifacts_glob_resolution"));
}
return Artifact.sortArtifacts(resolver.artifacts);
} catch (IOException e) {
throw new JReleaserException(RB.$("ERROR_artifacts_unexpected_error_globs"), e);
}
}
use of org.jreleaser.util.JReleaserException in project jreleaser by jreleaser.
the class Artifacts method resolveFiles.
public static Set<Artifact> resolveFiles(JReleaserLogger logger, Map<String, Object> props, Path basedir, Collection<String> globs) throws JReleaserException {
if (null == globs || globs.isEmpty()) {
return Collections.emptySet();
}
FileSystem fileSystem = FileSystems.getDefault();
List<PathMatcher> matchers = new ArrayList<>();
for (String glob : globs) {
matchers.add(fileSystem.getPathMatcher(resolveTemplate(glob, props)));
}
GlobResolver resolver = new GlobResolver(logger, basedir, matchers);
try {
java.nio.file.Files.walkFileTree(basedir, resolver);
if (resolver.failed) {
throw new JReleaserException(RB.$("ERROR_artifacts_glob_resolution"));
}
return Artifact.sortArtifacts(resolver.artifacts);
} catch (IOException e) {
throw new JReleaserException(RB.$("ERROR_artifacts_unexpected_error_globs"), e);
}
}
use of org.jreleaser.util.JReleaserException in project jreleaser by jreleaser.
the class Artifacts method copyFile.
public static void copyFile(JReleaserContext context, Path src, Path dest) throws JReleaserException {
try {
java.nio.file.Files.createDirectories(dest.getParent());
java.nio.file.Files.copy(src, dest, REPLACE_EXISTING, COPY_ATTRIBUTES);
} catch (IOException e) {
throw new JReleaserException(RB.$("ERROR_artifacts_unexpected_error_copying", context.relativizeToBasedir(src), context.relativizeToBasedir(dest)));
}
}
Aggregations