You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/08/15 10:42:43 UTC
[tomcat] branch master updated: Refactor for a separate class to
back-port translations
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push:
new 5ac9b8f Refactor for a separate class to back-port translations
5ac9b8f is described below
commit 5ac9b8fe0175de9aae56816b50edef636c23e39c
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Aug 15 11:41:58 2019 +0100
Refactor for a separate class to back-port translations
---
.../{BackportEnglish.java => BackportBase.java} | 36 +++++++++-----------
.../buildutil/translate/BackportEnglish.java | 38 +++++-----------------
2 files changed, 24 insertions(+), 50 deletions(-)
diff --git a/java/org/apache/tomcat/buildutil/translate/BackportEnglish.java b/java/org/apache/tomcat/buildutil/translate/BackportBase.java
similarity index 60%
copy from java/org/apache/tomcat/buildutil/translate/BackportEnglish.java
copy to java/org/apache/tomcat/buildutil/translate/BackportBase.java
index 180be8f..1a4830f 100644
--- a/java/org/apache/tomcat/buildutil/translate/BackportEnglish.java
+++ b/java/org/apache/tomcat/buildutil/translate/BackportBase.java
@@ -23,22 +23,22 @@ import java.util.Map;
import java.util.Properties;
/**
- * Generates a set of English property files to back-port updates to a previous
- * version. Where a key exists in the source and target versions the value is
- * copied from the source to the target, overwriting the value in the target.
- * The expectation is that the changes will be manually reviewed before
- * committing them.
+ * Base class providing common implementation for back-port utilities.
*/
-public class BackportEnglish {
+public abstract class BackportBase {
- private static final Map<String,Properties> sourceTranslations = new HashMap<>();
- private static final Map<String,Properties> targetTranslations = new HashMap<>();
+ protected final Map<String,Properties> sourceTranslations = new HashMap<>();
+ protected final Map<String,Properties> targetTranslations = new HashMap<>();
+ protected final File targetRoot;
+ protected final Properties sourceEnglish;
+ protected final Properties targetEnglish;
+ protected final File storageDir;
- public static void main(String... args) throws IOException {
+ protected BackportBase(String... args) throws IOException {
if (args.length != 1) {
throw new IllegalArgumentException("Missing back-port target");
}
- File targetRoot = new File(args[0]);
+ targetRoot = new File(args[0]);
if (!targetRoot.isDirectory()) {
throw new IllegalArgumentException("Back-port target not a directory");
@@ -55,17 +55,11 @@ public class BackportEnglish {
Utils.processDirectory(targetRoot, directory, targetTranslations);
}
- Properties sourceEnglish = sourceTranslations.get("");
- Properties targetEnglish = targetTranslations.get("");
+ sourceEnglish = sourceTranslations.get("");
+ targetEnglish = targetTranslations.get("");
- for (Object key : sourceEnglish.keySet()) {
- if (targetEnglish.containsKey(key)) {
- targetEnglish.put(key, sourceEnglish.get(key));
- }
- }
-
- File storageDir = new File(targetRoot, Constants.STORAGE_DIR);
-
- Utils.export("", targetEnglish, storageDir);
+ storageDir = new File(targetRoot, Constants.STORAGE_DIR);
}
+
+ protected abstract void execute() throws IOException;
}
diff --git a/java/org/apache/tomcat/buildutil/translate/BackportEnglish.java b/java/org/apache/tomcat/buildutil/translate/BackportEnglish.java
index 180be8f..c6f9608 100644
--- a/java/org/apache/tomcat/buildutil/translate/BackportEnglish.java
+++ b/java/org/apache/tomcat/buildutil/translate/BackportEnglish.java
@@ -16,11 +16,7 @@
*/
package org.apache.tomcat.buildutil.translate;
-import java.io.File;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
/**
* Generates a set of English property files to back-port updates to a previous
@@ -29,43 +25,27 @@ import java.util.Properties;
* The expectation is that the changes will be manually reviewed before
* committing them.
*/
-public class BackportEnglish {
-
- private static final Map<String,Properties> sourceTranslations = new HashMap<>();
- private static final Map<String,Properties> targetTranslations = new HashMap<>();
+public class BackportEnglish extends BackportBase {
public static void main(String... args) throws IOException {
- if (args.length != 1) {
- throw new IllegalArgumentException("Missing back-port target");
- }
- File targetRoot = new File(args[0]);
+ BackportEnglish backport = new BackportEnglish(args);
+ backport.execute();
+ }
- if (!targetRoot.isDirectory()) {
- throw new IllegalArgumentException("Back-port target not a directory");
- }
- File sourceRoot = new File(".");
- for (String dir : Constants.SEARCH_DIRS) {
- File directory = new File(dir);
- Utils.processDirectory(sourceRoot, directory, sourceTranslations);
- }
-
- for (String dir : Constants.SEARCH_DIRS) {
- File directory = new File(targetRoot, dir);
- Utils.processDirectory(targetRoot, directory, targetTranslations);
- }
+ protected BackportEnglish(String[] args) throws IOException {
+ super(args);
+ }
- Properties sourceEnglish = sourceTranslations.get("");
- Properties targetEnglish = targetTranslations.get("");
+ @Override
+ protected void execute() throws IOException {
for (Object key : sourceEnglish.keySet()) {
if (targetEnglish.containsKey(key)) {
targetEnglish.put(key, sourceEnglish.get(key));
}
}
- File storageDir = new File(targetRoot, Constants.STORAGE_DIR);
-
Utils.export("", targetEnglish, storageDir);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org