From 38568e49bcce60b4a610c5025e5ca70db9b9b611 Mon Sep 17 00:00:00 2001 From: yaga Date: Sat, 29 Sep 2018 19:03:53 +0000 Subject: [PATCH] Fixed description processing, packaging NPE and empty dirs * Package descritption processing conserves empty lines and trims leading spaces * Fixed NPE when autoDependencies set to false and no package attributes provided * Version of snapshot (byyyyMMddHHmmss) packages use UTC time * No empty directory `/usr/share/` during dependency processing is created if package has no dependencies. --- README.MD | 2 +- changelog.md | 13 ++++++++++++- .../plugin/maven/deb/pack/PackageMojo.java | 19 ++++++++++++++----- .../maven/deb/populate/PopulateMojo.java | 5 ++--- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/README.MD b/README.MD index 26dd286..8ecb157 100644 --- a/README.MD +++ b/README.MD @@ -17,7 +17,7 @@ the pom file. io.solit.maven deb-maven-plugin - 0.5 + 1.0-RC2 true diff --git a/changelog.md b/changelog.md index e45614f..f34bf33 100644 --- a/changelog.md +++ b/changelog.md @@ -4,7 +4,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## Unreleased +## [Unreleased] + +## [1.0-RC2] - 2018-09-30 +### Fixed +* `package` goal failed with npe if `autoDependencies` set to false and no + `packageAttributes` present in configuration +* empty lines were ignored in package description +* snapshot package version is based was base on local time instead of UTC +* `populate` goal created empty '/usr/share/' directory if project + has no runtime dependencies + +## [1.0-RC1] - 2018-03-18 ### Added * `man` goal to generate roff man pages from markdown * `changelog` goal to generate changelog.gz from markdown diff --git a/src/main/java/io/solit/plugin/maven/deb/pack/PackageMojo.java b/src/main/java/io/solit/plugin/maven/deb/pack/PackageMojo.java index 7649a3c..069950f 100644 --- a/src/main/java/io/solit/plugin/maven/deb/pack/PackageMojo.java +++ b/src/main/java/io/solit/plugin/maven/deb/pack/PackageMojo.java @@ -31,6 +31,9 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; @@ -301,7 +304,7 @@ private Control createControl() { String version = this.version, revision = this.revision; if (version.endsWith(SNAPSHOT)) { version = version.substring(0, version.length() - SNAPSHOT.length()); - version += "+b" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")); + version += "+b" + ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")); } String maintainer = this.maintainer; if (maintainer == null) @@ -312,7 +315,7 @@ private Control createControl() { control.setDescription(processDescription()); if (packageAttributes != null) packageAttributes.fillControl(control); - if (autoDependencies && packageAttributes == null || packageAttributes.getDepends() == null) + if (autoDependencies && (packageAttributes == null || packageAttributes.getDepends() == null)) fillAutoDependencies(control); if (homepage != null) control.setHomepage(homepage); @@ -333,7 +336,8 @@ private String processDescription() { while(scanner.hasNextLine()) { String line = scanner.nextLine(); if (result.length() == 0) { //first line is trimmed by maven - result.append(line.trim()).append('\n'); + line = line.substring(countWhitespaces(line)); // trim leading spaces just in case + result.append(line); continue; } int ws = countWhitespaces(line); @@ -342,8 +346,13 @@ private String processDescription() { lines.add(line); } for (String line: lines) - if (line.length() > maxWhitespaces) // empty lines left as is - result.append(line.substring(maxWhitespaces)).append('\n'); + if (line.length() > maxWhitespaces) // short lines considered empty + result.append('\n').append(line.substring(maxWhitespaces)); + else + result.append('\n'); + for (int i = result.length(); i > 0; i--) + if (result.charAt(i - 1) != '\n') + return result.substring(0, i); return result.toString(); } diff --git a/src/main/java/io/solit/plugin/maven/deb/populate/PopulateMojo.java b/src/main/java/io/solit/plugin/maven/deb/populate/PopulateMojo.java index 392986c..a73d047 100644 --- a/src/main/java/io/solit/plugin/maven/deb/populate/PopulateMojo.java +++ b/src/main/java/io/solit/plugin/maven/deb/populate/PopulateMojo.java @@ -35,6 +35,8 @@ protected void processDependency(DependencyArtifact node, Void nothing, File dep return; else throw new MojoExecutionException("Unresolved dependency: " + node.getArtifact().toString()); + if (!dependencyDir.isDirectory() && !dependencyDir.mkdirs()) + throw new MojoExecutionException("Unable to create directory " + dependencyDir.toString()); Path target = new File(dependencyDir, src.getName()).toPath(); if (Files.exists(target)) return; @@ -48,9 +50,6 @@ protected void processDependency(DependencyArtifact node, Void nothing, File dep @Override public void execute() throws MojoExecutionException, MojoFailureException { - File dependencyDir = getDependencyDirectory(); - if (!dependencyDir.isDirectory() && !dependencyDir.mkdirs()) - throw new MojoExecutionException("Unable to create directory " + dependencyDir.toString()); traverseDependencies(null); }