This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new 5dce0e6 Remove unused code. 5dce0e6 is described below commit 5dce0e6bf383508b65cb556301c09fcd30ba3120 Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Sep 2 21:55:41 2021 +0100 Remove unused code. No requirement to back-port translations from 8.5.x now. --- .../tomcat/buildutil/translate/BackportBase.java | 65 ---------------- .../buildutil/translate/BackportEnglish.java | 67 ---------------- .../buildutil/translate/BackportTranslations.java | 76 ------------------ .../tomcat/buildutil/translate/Constants.java | 2 - .../apache/tomcat/buildutil/translate/Utils.java | 89 ---------------------- 5 files changed, 299 deletions(-) diff --git a/java/org/apache/tomcat/buildutil/translate/BackportBase.java b/java/org/apache/tomcat/buildutil/translate/BackportBase.java deleted file mode 100644 index 1a4830f..0000000 --- a/java/org/apache/tomcat/buildutil/translate/BackportBase.java +++ /dev/null @@ -1,65 +0,0 @@ -/* -* 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 -* -* http://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. -*/ -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; - -/** - * Base class providing common implementation for back-port utilities. - */ -public abstract class BackportBase { - - 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; - - protected BackportBase(String... args) throws IOException { - if (args.length != 1) { - throw new IllegalArgumentException("Missing back-port target"); - } - targetRoot = new File(args[0]); - - 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); - } - - sourceEnglish = sourceTranslations.get(""); - targetEnglish = targetTranslations.get(""); - - 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 deleted file mode 100644 index 9a0c7ae..0000000 --- a/java/org/apache/tomcat/buildutil/translate/BackportEnglish.java +++ /dev/null @@ -1,67 +0,0 @@ -/* -* 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 -* -* http://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. -*/ -package org.apache.tomcat.buildutil.translate; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; - -/** - * 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. - */ -public class BackportEnglish extends BackportBase { - - private static Set<String> keysToExclude = new HashSet<>(); - - - public static void main(String... args) throws IOException { - // Exclude keys known to be different between 8.5.x and 7.0.x - keysToExclude.add("java.org.apache.catalina.manager.zzz.htmlManagerServlet.deployPath"); - keysToExclude.add("java.org.apache.catalina.mbeans.zzz.jmxRemoteLifecycleListener.deprecated"); - keysToExclude.add("java.org.apache.catalina.session.zzz.managerBase.contextNull"); - keysToExclude.add("java.org.apache.catalina.startup.zzz.catalina.stopServer.connectException"); - keysToExclude.add("java.org.apache.jasper.resources.zzz.jsp.error.jsproot.version.invalid"); - keysToExclude.add("java.org.apache.jasper.resources.zzz.jsp.tldCache.noTldInJar"); - keysToExclude.add("java.org.apache.jasper.resources.zzz.jspc.usage"); - keysToExclude.add("java.org.apache.jasper.resources.zzz.jspc.webfrg.header"); - keysToExclude.add("java.org.apache.jasper.resources.zzz.jspc.webxml.header"); - - BackportEnglish backport = new BackportEnglish(args); - backport.execute(); - } - - - protected BackportEnglish(String[] args) throws IOException { - super(args); - } - - - @Override - protected void execute() throws IOException { - for (Object key : sourceEnglish.keySet()) { - if (targetEnglish.containsKey(key) && !keysToExclude.contains(key)) { - targetEnglish.put(key, sourceEnglish.get(key)); - } - } - - Utils.export("", targetEnglish, storageDir); - } -} diff --git a/java/org/apache/tomcat/buildutil/translate/BackportTranslations.java b/java/org/apache/tomcat/buildutil/translate/BackportTranslations.java deleted file mode 100644 index 1da15de..0000000 --- a/java/org/apache/tomcat/buildutil/translate/BackportTranslations.java +++ /dev/null @@ -1,76 +0,0 @@ -/* -* 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 -* -* http://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. -*/ -package org.apache.tomcat.buildutil.translate; - -import java.io.IOException; -import java.util.Iterator; -import java.util.Map; -import java.util.Properties; - -/** - * Generates a set of translated property files to back-port updates to a - * previous version. If the source and target use the same value for the English - * key then any translated value for that key is copied from the source to the - * target. - */ -public class BackportTranslations extends BackportBase { - - public static void main(String... args) throws IOException { - BackportTranslations backport = new BackportTranslations(args); - backport.execute(); - } - - protected BackportTranslations(String[] args) throws IOException { - super(args); - } - - - @Override - protected void execute() throws IOException { - for (String language : targetTranslations.keySet()) { - // Skip source - if (language.length() == 0) { - continue; - } - - Properties sourceTranslated = sourceTranslations.get(language); - Properties targetTranslated = targetTranslations.get(language); - if (targetTranslated == null) { - targetTranslated = new Properties(); - targetTranslations.put(language, targetTranslated); - } - - for (Object key : targetEnglish.keySet()) { - if (sourceTranslated.containsKey(key) && - targetEnglish.get(key).equals(sourceEnglish.get(key))) { - - targetTranslated.put(key, sourceTranslated.get(key)); - } - } - - // Remove translated values for keys that have been removed - Iterator<Map.Entry<Object,Object>> iter = targetTranslated.entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry<Object,Object> entry = iter.next(); - if (!targetEnglish.containsKey(entry.getKey())) { - iter.remove(); - } - } - Utils.export(language, targetTranslated, storageDir); - } - } -} diff --git a/java/org/apache/tomcat/buildutil/translate/Constants.java b/java/org/apache/tomcat/buildutil/translate/Constants.java index 403daa6..d8e8838 100644 --- a/java/org/apache/tomcat/buildutil/translate/Constants.java +++ b/java/org/apache/tomcat/buildutil/translate/Constants.java @@ -21,8 +21,6 @@ public class Constants { public static final String L10N_PREFIX = "LocalStrings"; public static final String L10N_SUFFIX = ".properties"; - public static final String[] SEARCH_DIRS = new String[] { "java", "webapps" }; - public static final String STORAGE_DIR = ".settings/translations"; public static final String END_PACKAGE_MARKER = ".zzz."; diff --git a/java/org/apache/tomcat/buildutil/translate/Utils.java b/java/org/apache/tomcat/buildutil/translate/Utils.java index 80a7756..88d75c6 100644 --- a/java/org/apache/tomcat/buildutil/translate/Utils.java +++ b/java/org/apache/tomcat/buildutil/translate/Utils.java @@ -18,15 +18,10 @@ package org.apache.tomcat.buildutil.translate; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; -import java.io.OutputStreamWriter; import java.io.Reader; -import java.io.Writer; import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Map; import java.util.Properties; import java.util.regex.Pattern; @@ -60,19 +55,6 @@ public class Utils { } - static String formatValueExport(String in) { - String result; - - if (in.startsWith("\n")) { - result = PADDING + in; - } else { - result = in; - } - - return formatValueCommon(result); - } - - static String formatValueImport(String in) { String result; @@ -102,75 +84,4 @@ public class Utils { return result; } - - - static void processDirectory(File root, File dir, Map<String,Properties> translations) throws IOException { - File[] files = dir.listFiles(); - if (files == null) { - throw new IllegalArgumentException("Not a directory [" + dir.getAbsolutePath() + "]"); - } - for (File f : files) { - if (f.isDirectory()) { - processDirectory(root, f, translations); - } else if (f.isFile()) { - processFile(root, f, translations); - } - } - } - - - static void processFile(File root, File f, Map<String,Properties> translations) throws IOException { - String name = f.getName(); - - // non-l10n files - if (!name.startsWith(Constants.L10N_PREFIX)) { - return; - } - - // Determine language - String language = Utils.getLanguage(name); - - String keyPrefix = getKeyPrefix(root, f); - Properties props = Utils.load(f); - - // Create a Map for the language if one does not exist. - Properties translation = translations.get(language); - if (translation == null) { - translation = new Properties(); - translations.put(language, translation); - } - - // Add the properties from this file to the combined file, prefixing the - // key with the package name to ensure uniqueness. - for (Object obj : props.keySet()) { - String key = (String) obj; - String value = props.getProperty(key); - - translation.put(keyPrefix + key, value); - } - } - - - static String getKeyPrefix(File root, File f) throws IOException { - String prefix = f.getParentFile().getCanonicalPath(); - prefix = prefix.substring(root.getCanonicalPath().length() + 1); - prefix = prefix.replace(File.separatorChar, '.'); - prefix = prefix + Constants.END_PACKAGE_MARKER; - return prefix; - } - - - static void export(String language, Properties translation, File storageDir) { - File out = new File(storageDir, Constants.L10N_PREFIX + language + Constants.L10N_SUFFIX); - try (FileOutputStream fos = new FileOutputStream(out); - Writer w = new OutputStreamWriter(fos, StandardCharsets.UTF_8)) { - String[] keys = translation.keySet().toArray(new String[0]); - Arrays.sort(keys); - for (Object key : keys) { - w.write(key + "=" + Utils.formatValueExport(translation.getProperty((String) key)) + "\n"); - } - } catch (IOException ioe) { - ioe.printStackTrace(); - } - } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org