Skip to content

Commit

Permalink
refactor: Close logger on init & template commands
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Nov 30, 2022
1 parent 3018630 commit ebd17cb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public void execute() throws BuildException {
} catch (IllegalStateException | IOException e) {
logger.trace(e);
throw new JReleaserException("Unexpected error", e);
} finally {
if (logger != null) logger.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public void execute() throws BuildException {
} catch (TemplateGenerationException e) {
logger.trace(e);
throw new JReleaserException("Unexpected error", e);
} finally {
if (logger != null) logger.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,26 @@ abstract class JReleaserTemplateTask extends DefaultTask {

@TaskAction
void generateTemplate() {
Path output = TemplateGenerator.builder()
.logger(jlogger.get())
.distributionName(distributionName.orNull)
.distributionType(distributionType.orNull)
.packagerName(packagerName.orNull)
.announcerName(announcerName.orNull)
.assemblerType(assemblerType.orNull)
.assemblerName(distributionName.orNull)
.outputDirectory(outputDirectory.get().asFile.toPath())
.overwrite(overwrite.get())
.snapshot(snapshot.get())
.build()
.generate()

if (output) {
logger.info('Template generated at {}', output.toAbsolutePath())
try {
Path output = TemplateGenerator.builder()
.logger(jlogger.get())
.distributionName(distributionName.orNull)
.distributionType(distributionType.orNull)
.packagerName(packagerName.orNull)
.announcerName(announcerName.orNull)
.assemblerType(assemblerType.orNull)
.assemblerName(distributionName.orNull)
.outputDirectory(outputDirectory.get().asFile.toPath())
.overwrite(overwrite.get())
.snapshot(snapshot.get())
.build()
.generate()

if (output) {
logger.info('Template generated at {}', output.toAbsolutePath())
}
} finally {
jlogger.get().close()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
} catch (TemplateGenerationException e) {
throw new MojoExecutionException("Unexpected error", e);
} finally {
getLogger().close();
}
}

Expand Down
2 changes: 2 additions & 0 deletions plugins/jreleaser/src/main/java/org/jreleaser/cli/Init.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ protected void execute() {
}
} catch (IllegalStateException | IOException 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 @@ -155,6 +155,8 @@ protected void execute() {
}
} catch (TemplateGenerationException e) {
throw new JReleaserException($("ERROR_unexpected_error"), e);
} finally {
if (logger != null) logger.close();
}
}

Expand Down

0 comments on commit ebd17cb

Please sign in to comment.