This is an automated email from the ASF dual-hosted git repository.

vy pushed a commit to branch release/0.4.0
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git

commit 6e71676e60db298a56d4316645b00e8142a8b419
Author: Volkan Yazıcı <[email protected]>
AuthorDate: Fri Jun 30 14:16:22 2023 +0200

    Avoid moving templates while releasing, copy instead
---
 .../changelog/releaser/ChangelogReleaser.java      | 48 +++++-----------------
 .../log4j/changelog/ChangelogReleaserTest.java     | 11 +----
 .../5-released/.2.x.x/.release-notes.adoc.ftl      | 21 ++++++++++
 .../5-released/.2.x.x/.release-notes.common.ftl    | 18 ++++++++
 .../5-released/.2.x.x/.release-notes.txt.ftl       | 21 ++++++++++
 .../.2.x.x/.release-notes.adoc.ftl                 | 21 ++++++++++
 .../.2.x.x/.release-notes.common.ftl               | 18 ++++++++
 .../6-enriched-again/.2.x.x/.release-notes.txt.ftl | 21 ++++++++++
 .../.2.x.x/.release-notes.adoc.ftl                 | 21 ++++++++++
 .../.2.x.x/.release-notes.common.ftl               | 18 ++++++++
 .../7-released-again/.2.x.x/.release-notes.txt.ftl | 21 ++++++++++
 11 files changed, 191 insertions(+), 48 deletions(-)

diff --git 
a/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/releaser/ChangelogReleaser.java
 
b/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/releaser/ChangelogReleaser.java
index ba0d7a2..0420b04 100644
--- 
a/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/releaser/ChangelogReleaser.java
+++ 
b/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/releaser/ChangelogReleaser.java
@@ -42,17 +42,15 @@ public final class ChangelogReleaser {
 
         try {
 
-            // Populate the changelog entry files in the release directory
+            // Determine released and unreleased directories
             final Path unreleasedDirectory =
                     
ChangelogFiles.unreleasedDirectory(args.changelogDirectory, 
args.releaseVersionMajor);
             final Path releaseDirectory = 
ChangelogFiles.releaseDirectory(args.changelogDirectory, args.releaseVersion);
-            populateChangelogEntryFiles(unreleasedDirectory, releaseDirectory);
 
-            // Write the release information
+            // Populate the release changelog files
+            populateReleaseChangelogEntryFiles(unreleasedDirectory, 
releaseDirectory);
             populateReleaseXmlFiles(releaseDate, args.releaseVersion, 
releaseDirectory);
-
-            // Write the release changelog template
-            populateReleaseChangelogTemplateFile(unreleasedDirectory, 
releaseDirectory);
+            populateReleaseChangelogTemplateFiles(unreleasedDirectory, 
releaseDirectory);
 
         } catch (final IOException error) {
             throw new UncheckedIOException(error);
@@ -60,24 +58,13 @@ public final class ChangelogReleaser {
 
     }
 
-    private static void populateChangelogEntryFiles(
+    private static void populateReleaseChangelogEntryFiles(
             final Path unreleasedDirectory,
             final Path releaseDirectory)
             throws IOException {
-        if (Files.exists(releaseDirectory)) {
-            System.out.format(
-                    "release directory `%s` already exists, only moving the 
changelog entry files from `%s`%n",
-                    releaseDirectory, unreleasedDirectory);
-            moveUnreleasedChangelogEntryFiles(unreleasedDirectory, 
releaseDirectory);
-        } else {
-            System.out.format(
-                    "release directory `%s` doesn't exist, simply renaming the 
unreleased directory `%s`%n",
-                    releaseDirectory, unreleasedDirectory);
-            moveUnreleasedDirectory(unreleasedDirectory, releaseDirectory);
+        if (!Files.exists(releaseDirectory)) {
+            Files.createDirectories(releaseDirectory);
         }
-    }
-
-    private static void moveUnreleasedChangelogEntryFiles(final Path 
unreleasedDirectory, final Path releaseDirectory) {
         FileUtils.findAdjacentFiles(unreleasedDirectory, true, paths -> {
             paths.forEach(unreleasedChangelogEntryFile -> {
                 final String fileName = 
unreleasedChangelogEntryFile.getFileName().toString();
@@ -95,21 +82,6 @@ public final class ChangelogReleaser {
         });
     }
 
-    private static void moveUnreleasedDirectory(
-            final Path unreleasedDirectory,
-            final Path releaseDirectory)
-            throws IOException {
-        if (!Files.exists(unreleasedDirectory)) {
-            final String message = String.format(
-                    "`%s` does not exist! A release without any changelogs 
don't make sense!",
-                    unreleasedDirectory);
-            throw new IllegalStateException(message);
-        }
-        System.out.format("moving changelog directory `%s` to `%s`%n", 
unreleasedDirectory, releaseDirectory);
-        Files.move(unreleasedDirectory, releaseDirectory);
-        Files.createDirectories(unreleasedDirectory);
-    }
-
     private static void populateReleaseXmlFiles(
             final String releaseDate,
             final String releaseVersion,
@@ -122,7 +94,7 @@ public final class ChangelogReleaser {
         changelogRelease.writeToXmlFile(releaseXmlFile);
     }
 
-    private static void populateReleaseChangelogTemplateFile(
+    private static void populateReleaseChangelogTemplateFiles(
             final Path unreleasedDirectory,
             final Path releaseDirectory)
             throws IOException {
@@ -133,8 +105,8 @@ public final class ChangelogReleaser {
                 System.out.format("keeping the existing changelog template 
file: `%s`%n", targetFile);
             } else {
                 final Path sourceFile = 
unreleasedDirectory.resolve(releaseChangelogTemplateFileName);
-                System.out.format("moving the changelog template file `%s` to 
`%s`%n", sourceFile, targetFile);
-                Files.move(sourceFile, targetFile);
+                System.out.format("copying the changelog template file `%s` to 
`%s`%n", sourceFile, targetFile);
+                Files.copy(sourceFile, targetFile);
             }
         }
     }
diff --git 
a/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogReleaserTest.java
 
b/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogReleaserTest.java
index 21c76fa..ab8e8a6 100644
--- 
a/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogReleaserTest.java
+++ 
b/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogReleaserTest.java
@@ -17,7 +17,6 @@
 package org.apache.logging.log4j.changelog;
 
 import java.io.File;
-import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.time.LocalDate;
@@ -70,16 +69,8 @@ class ChangelogReleaserTest {
                 LocalDate.parse("2023-01-25"));
         ChangelogReleaser.performRelease(args);
 
-        // Empty folders are not tracked by git, though created by 
`ChangelogReleaser`.
-        // Create the `.2.x.x` folder to match the actual output.
-        final Path expectedChangelogDirectory = 
Paths.get(expectedOutputDirectory);
-        final Path emptyFolder = expectedChangelogDirectory.resolve(".2.x.x");
-        if (!Files.exists(emptyFolder)) {
-            Files.createDirectories(emptyFolder);
-        }
-
         // Compare the output
-        assertDirectoryContentMatches(changelogDirectory, 
expectedChangelogDirectory);
+        assertDirectoryContentMatches(changelogDirectory, 
Paths.get(expectedOutputDirectory));
 
     }
 
diff --git 
a/log4j-changelog/src/test/resources/5-released/.2.x.x/.release-notes.adoc.ftl 
b/log4j-changelog/src/test/resources/5-released/.2.x.x/.release-notes.adoc.ftl
new file mode 100644
index 0000000..baa52d9
--- /dev/null
+++ 
b/log4j-changelog/src/test/resources/5-released/.2.x.x/.release-notes.adoc.ftl
@@ -0,0 +1,21 @@
+////
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+         https://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+////
+
+= ${release.version}<#if release.date?has_content> (${release.date})</#if>
+<#include ".release-notes.common.ftl">
+
+<#include "../.changelog.adoc.ftl">
diff --git 
a/log4j-changelog/src/test/resources/5-released/.2.x.x/.release-notes.common.ftl
 
b/log4j-changelog/src/test/resources/5-released/.2.x.x/.release-notes.common.ftl
new file mode 100644
index 0000000..c0d38f7
--- /dev/null
+++ 
b/log4j-changelog/src/test/resources/5-released/.2.x.x/.release-notes.common.ftl
@@ -0,0 +1,18 @@
+<#--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements. See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License. You may obtain a copy of the License at
+
+      https://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+Changes staged for the next 2.x.x version that is yet to be released.
diff --git 
a/log4j-changelog/src/test/resources/5-released/.2.x.x/.release-notes.txt.ftl 
b/log4j-changelog/src/test/resources/5-released/.2.x.x/.release-notes.txt.ftl
new file mode 100644
index 0000000..122eabd
--- /dev/null
+++ 
b/log4j-changelog/src/test/resources/5-released/.2.x.x/.release-notes.txt.ftl
@@ -0,0 +1,21 @@
+<#--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements. See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License. You may obtain a copy of the License at
+
+      https://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+### ${release.version}<#if release.date?has_content> (${release.date})</#if> 
###
+<#include ".release-notes.common.ftl">
+
+<#include "../.changelog.txt.ftl">
diff --git 
a/log4j-changelog/src/test/resources/6-enriched-again/.2.x.x/.release-notes.adoc.ftl
 
b/log4j-changelog/src/test/resources/6-enriched-again/.2.x.x/.release-notes.adoc.ftl
new file mode 100644
index 0000000..baa52d9
--- /dev/null
+++ 
b/log4j-changelog/src/test/resources/6-enriched-again/.2.x.x/.release-notes.adoc.ftl
@@ -0,0 +1,21 @@
+////
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+         https://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+////
+
+= ${release.version}<#if release.date?has_content> (${release.date})</#if>
+<#include ".release-notes.common.ftl">
+
+<#include "../.changelog.adoc.ftl">
diff --git 
a/log4j-changelog/src/test/resources/6-enriched-again/.2.x.x/.release-notes.common.ftl
 
b/log4j-changelog/src/test/resources/6-enriched-again/.2.x.x/.release-notes.common.ftl
new file mode 100644
index 0000000..c0d38f7
--- /dev/null
+++ 
b/log4j-changelog/src/test/resources/6-enriched-again/.2.x.x/.release-notes.common.ftl
@@ -0,0 +1,18 @@
+<#--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements. See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License. You may obtain a copy of the License at
+
+      https://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+Changes staged for the next 2.x.x version that is yet to be released.
diff --git 
a/log4j-changelog/src/test/resources/6-enriched-again/.2.x.x/.release-notes.txt.ftl
 
b/log4j-changelog/src/test/resources/6-enriched-again/.2.x.x/.release-notes.txt.ftl
new file mode 100644
index 0000000..122eabd
--- /dev/null
+++ 
b/log4j-changelog/src/test/resources/6-enriched-again/.2.x.x/.release-notes.txt.ftl
@@ -0,0 +1,21 @@
+<#--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements. See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License. You may obtain a copy of the License at
+
+      https://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+### ${release.version}<#if release.date?has_content> (${release.date})</#if> 
###
+<#include ".release-notes.common.ftl">
+
+<#include "../.changelog.txt.ftl">
diff --git 
a/log4j-changelog/src/test/resources/7-released-again/.2.x.x/.release-notes.adoc.ftl
 
b/log4j-changelog/src/test/resources/7-released-again/.2.x.x/.release-notes.adoc.ftl
new file mode 100644
index 0000000..baa52d9
--- /dev/null
+++ 
b/log4j-changelog/src/test/resources/7-released-again/.2.x.x/.release-notes.adoc.ftl
@@ -0,0 +1,21 @@
+////
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+         https://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+////
+
+= ${release.version}<#if release.date?has_content> (${release.date})</#if>
+<#include ".release-notes.common.ftl">
+
+<#include "../.changelog.adoc.ftl">
diff --git 
a/log4j-changelog/src/test/resources/7-released-again/.2.x.x/.release-notes.common.ftl
 
b/log4j-changelog/src/test/resources/7-released-again/.2.x.x/.release-notes.common.ftl
new file mode 100644
index 0000000..c0d38f7
--- /dev/null
+++ 
b/log4j-changelog/src/test/resources/7-released-again/.2.x.x/.release-notes.common.ftl
@@ -0,0 +1,18 @@
+<#--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements. See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License. You may obtain a copy of the License at
+
+      https://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+Changes staged for the next 2.x.x version that is yet to be released.
diff --git 
a/log4j-changelog/src/test/resources/7-released-again/.2.x.x/.release-notes.txt.ftl
 
b/log4j-changelog/src/test/resources/7-released-again/.2.x.x/.release-notes.txt.ftl
new file mode 100644
index 0000000..122eabd
--- /dev/null
+++ 
b/log4j-changelog/src/test/resources/7-released-again/.2.x.x/.release-notes.txt.ftl
@@ -0,0 +1,21 @@
+<#--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements. See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License. You may obtain a copy of the License at
+
+      https://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+### ${release.version}<#if release.date?has_content> (${release.date})</#if> 
###
+<#include ".release-notes.common.ftl">
+
+<#include "../.changelog.txt.ftl">

Reply via email to