You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2020/04/05 09:20:45 UTC

[jspwiki] branch master updated (af99ed7 -> a829052)

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

juanpablo pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git.


    from af99ed7  add missing AL
     new a9432ad  remove final from non-default method in PageFilter interface
     new 8e85575  refactor TranslationsChecks:
     new a829052  (Hopefully) generate Translation status page - No version bump

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Jenkinsfile                                        |   3 +
 .../org/apache/wiki/api/filters/PageFilter.java    |   2 +-
 .../java/org/apache/wiki/TranslationsCheck.java    | 237 +++++++++++----------
 3 files changed, 127 insertions(+), 115 deletions(-)


[jspwiki] 03/03: (Hopefully) generate Translation status page - No version bump

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit a829052814acb7c4c805091d3ddd37045a4f2966
Author: juanpablo <ju...@apache.org>
AuthorDate: Sun Apr 5 11:20:15 2020 +0200

    (Hopefully) generate Translation status page - No version bump
---
 Jenkinsfile | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Jenkinsfile b/Jenkinsfile
index 8e21904..80fabbb 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -45,6 +45,7 @@ try {
                     writeFile file: 'target/classes/apidocs.txt', text: 'file created in order to allow aggregated javadoc generation, target/classes is needed for all modules'
                     writeFile file: 'jspwiki-it-tests/target/classes/apidocs.txt', text: 'file created in order to allow aggregated javadoc generation, target/classes is needed for all modules'
                     sh 'mvn package javadoc:aggregate-no-fork -DskipTests -pl !jspwiki-portable'
+                    sh 'java -cp jspwiki-main/target/classes org.apache.wiki.TranslationsCheck site'
                 }
             }
         }
@@ -54,7 +55,9 @@ try {
                 dir( jbake ) {
                     git branch: jbake, url: siteRepo, credentialsId: creds, poll: false
                     sh "cp ../$build/ChangeLog.md ./src/main/config/changelog.md"
+                    sh "cp ../$build/i18n-table.txt ./src/main/config/i18n-table.md"
                     sh "cat ./src/main/config/changelog-header.txt ./src/main/config/changelog.md > ./src/main/jbake/content/development/changelog.md"
+                    sh "cat ./src/main/config/i18n-header.txt ./src/main/config/i18n-table.md > ./src/main/jbake/content/development/i18n.md"
                     sh 'mvn clean process-resources -Dplugin.japicmp.jspwiki-new=' + pom.version
                 }
                 stash name: 'jbake-website'


[jspwiki] 01/03: remove final from non-default method in PageFilter interface

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit a9432ad4135c9fc1919834d8175eb614b4c8fbd9
Author: juanpablo <ju...@apache.org>
AuthorDate: Sun Apr 5 11:17:25 2020 +0200

    remove final from non-default method in PageFilter interface
---
 jspwiki-api/src/main/java/org/apache/wiki/api/filters/PageFilter.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/jspwiki-api/src/main/java/org/apache/wiki/api/filters/PageFilter.java b/jspwiki-api/src/main/java/org/apache/wiki/api/filters/PageFilter.java
index 19cd401..a284c8e 100644
--- a/jspwiki-api/src/main/java/org/apache/wiki/api/filters/PageFilter.java
+++ b/jspwiki-api/src/main/java/org/apache/wiki/api/filters/PageFilter.java
@@ -54,7 +54,7 @@ public interface PageFilter {
      *  @param properties The properties ripped from filters.xml.
      *  @throws FilterException If the filter could not be initialized. If this is thrown, the filter is not added to the internal queues.
      */
-    void initialize( final Engine engine, final Properties properties ) throws FilterException;
+    void initialize( Engine engine, Properties properties ) throws FilterException;
 
     /**
      *  This method is called whenever a page has been loaded from the provider, but not yet been sent through the markup-translation


[jspwiki] 02/03: refactor TranslationsChecks:

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit 8e85575e956de893ccae843449c7a10b2c486d98
Author: juanpablo <ju...@apache.org>
AuthorDate: Sun Apr 5 11:19:31 2020 +0200

    refactor TranslationsChecks:
    
    * added suggested fixes and formatting from IntelliJ
    * understand special parameter 'site' to generate the 'dynamic' part of the Translation status page
---
 .../java/org/apache/wiki/TranslationsCheck.java    | 237 +++++++++++----------
 1 file changed, 123 insertions(+), 114 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/TranslationsCheck.java b/jspwiki-main/src/main/java/org/apache/wiki/TranslationsCheck.java
index 71bd2bd..470a0bb 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/TranslationsCheck.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/TranslationsCheck.java
@@ -13,10 +13,12 @@
  */
 package org.apache.wiki;
 
-import org.apache.wiki.api.Release;
-
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -27,6 +29,7 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.TreeSet;
 
+
 /**
  * Simple utility that shows you a sorted list of property differences between
  * the 'default en' and a given i18n file. It also warns if there are any duplicates.
@@ -38,173 +41,179 @@ import java.util.TreeSet;
  * <code>
  * java -cp classes TranslationsCheck fi
  * </code>
- *
  */
-public class TranslationsCheck
-{
-    private static final TreeSet<String> allProps = new TreeSet<>();  // sorted, no duplicates
-    private static final TreeSet<String> duplProps = new TreeSet<>();
+public class TranslationsCheck {
+
+    private final static String[] LANGS = { "de", "en", "es", "fi", "fr", "it", "nl", "pt_BR", "ru", "zh_CN" };
+    private final static String SITE_I18N_ROW =
+        "<tr%s>\n" +
+        "  <td title=\"Available sets of core WikiPages for %s\"><a class=\"external\" href=\"https://search.maven.org/artifact/org.apache.jspwiki.wikipages/jspwiki-wikipages-%s\">%s</a></td>\n" +
+        "  <td>%d%%</td>\n" +
+        "  <td>%d</td>\n" +
+        "  <td>%d</td>\n" +
+        "</tr>\n";
+
+    private final TreeSet< String > allProps = new TreeSet<>();  // sorted, no duplicates
+    private final TreeSet< String > duplProps = new TreeSet<>();
 
     // Change these to your settings...
-    static String base = ".";
-    static String suffix = null;
-
-    public static void main( final String[] args) throws IOException
-    {
-        if( args.length == 0 )
-        {
-            System.out.println("Usage: java TranslationsCheck <language> [<path>]");
-            System.out.println("Example: java TranslationsCheck nl [jspwiki-main/src/main/resources]");
+    String base = ".";
+    String suffix = null;
+
+    public static void main( final String[] args ) throws IOException {
+        final TranslationsCheck translations = new TranslationsCheck();
+        if( args.length == 0 ) {
+            System.out.println( "Usage: java TranslationsCheck <language> [<path>]" );
+            System.out.println( "Example: java TranslationsCheck nl [jspwiki-main/src/main/resources]" );
+            System.out.println( "To output site i18n info use java TranslationsCheck site [<path>]" );
             return;
         }
+        translations.suffix = args[ 0 ];
+        if( args.length >= 2 ) {
+            translations.base = args[ 1 ];
+        }
 
-        suffix = args[0];
-
-        if( args.length >= 2 )
-        {
-            base = args[1];
+        if( "site".equals( translations.suffix ) ) {
+            String site = "";
+            for( int i = 0; i < LANGS.length; i++ ) {
+                translations.suffix = LANGS[ i ];
+                site += translations.check( i );
+            }
+            site += "</table>\n" + // close table and formatting divs
+                    "</div>\n" +
+                    "</div>\n" +
+                    "</div>";
+            Files.write( Paths.get( "./i18n-table.txt" ), site.getBytes( StandardCharsets.UTF_8 ) );
+        } else {
+            translations.check( -1 );
         }
+    }
 
-        System.out.println("Using code base " + Release.VERSTR);
-        System.out.println("Internationalization property file differences between 'default en' and '" + suffix + "' following:\n");
+    String check( final int lang ) throws IOException {
+        // System.out.println( "Using code base " + Release.VERSTR );
+        System.out.println( "Internationalization property file differences between 'default en' and '" + suffix + "' following:\n" );
 
-        try
-        {
-            diff("/CoreResources.properties", "/CoreResources_" + suffix + ".properties");
-            detectDuplicates("/CoreResources_" + suffix + ".properties");
-        }
-        catch( final FileNotFoundException e )
-        {
-            System.err.println("Unable to locate "+"/CoreResources_" + suffix + ".properties");
-        }
+        final String fileSuffix = ( "en".equals( suffix ) ) ? "" : "_" + suffix;
+        final Map< String, Integer > coreMetrics = checkFile( "/CoreResources.properties", "/CoreResources" + fileSuffix + ".properties" );
+        final Map< String, Integer > templateMetrics = checkFile( "/templates/default.properties", "/templates/default" + fileSuffix + ".properties" );
+        final Map< String, Integer > pluginMetrics = checkFile( "/plugin/PluginResources.properties", "/plugin/PluginResources" + fileSuffix + ".properties" );
 
-        try
-        {
-            diff("/templates/default.properties", "/templates/default_" + suffix + ".properties");
-            detectDuplicates("/templates/default_" + suffix + ".properties");
-        }
-        catch( final FileNotFoundException e )
-        {
-            System.err.println("Unable to locate "+"/templates/default_" + suffix + ".properties");
+        if( lang >= 0 ) {
+            final int expected = coreMetrics.get( "expected" ) + templateMetrics.get( "expected" ) + pluginMetrics.get( "expected" );
+            final int missing = coreMetrics.get( "missing" ) + templateMetrics.get( "missing" ) + pluginMetrics.get( "missing" );
+            final int completed = 100 * ( expected - missing ) / expected;
+            final int outdated = coreMetrics.get( "outdated" ) + templateMetrics.get( "outdated" ) + pluginMetrics.get( "outdated" );
+            final String odd = lang %2 == 0 ? " class=\"odd\"" : ""; // 0 first row
+
+            return String.format( SITE_I18N_ROW, odd, suffix, suffix, suffix, completed, missing, outdated );
         }
+        return "";
+    }
 
-        try
-        {
-            diff("/plugin/PluginResources.properties", "/plugin/PluginResources_" + suffix + ".properties");
-
-            detectDuplicates("/plugin/PluginResources_" + suffix + ".properties");
-
-            System.out.println("Duplicates overall (two or more occurences):");
-            System.out.println("--------------------------------------------");
-            final Iterator< String > iter = duplProps.iterator();
-            if (duplProps.size() == 0)
-                System.out.println("(none)");
-            else
-                while (iter.hasNext())
-                    System.out.println(iter.next());
-            System.out.println();
+    Map< String, Integer > checkFile( final String en, final String lang ) throws IOException {
+        final Map< String, Integer > metrics = new HashMap<>();
+        try {
+            metrics.putAll( diff( en, lang ) );
+            metrics.put( "duplicates", detectDuplicates( lang ) );
+        } catch( final FileNotFoundException e ) {
+            System.err.println( "Unable to locate " + lang );
         }
-        catch( final FileNotFoundException e )
-        {
-            System.err.println("Unable to locate "+"/plugin/PluginResources_" + suffix + ".properties");
+        System.out.println( "Duplicates overall (two or more occurences):" );
+        System.out.println( "--------------------------------------------" );
+        final Iterator< String > iter = duplProps.iterator();
+        if( duplProps.size() == 0 ) {
+            System.out.println( "(none)" );
+        } else {
+            while( iter.hasNext() ) {
+                System.out.println( iter.next() );
+            }
         }
-
-        System.out.println("NOTE: Please remember that dependent on the usage of these i18n files, outdated " +
-                "properties maybe should not be deleted, because they may be used by previous releases. " +
-                "Moving them to a special section in the file may be the better solution.");
+        System.out.println( "" );
+        return metrics;
     }
 
-    public static Map< String, Integer > diff( final String source1, final String source2) throws FileNotFoundException, IOException
-    {
+    public Map< String, Integer > diff( final String source1, final String source2 ) throws IOException {
         int missing = 0, outdated = 0;
         // Standard Properties
         final Properties p1 = new Properties();
-        
-        p1.load( TranslationsCheck.class.getClassLoader().getResourceAsStream( base + source1 ) );
+        p1.load( getResourceAsStream( source1 ) );
 
         final Properties p2 = new Properties();
-        p2.load( TranslationsCheck.class.getClassLoader().getResourceAsStream( base + source2 ) );
+        p2.load( getResourceAsStream( source2 ) );
 
         final String msg = "Checking " + source2 + "...";
-        System.out.println(msg);
+        System.out.println( msg );
 
-        Iterator< String > iter = sortedNames(p1).iterator();
-        while (iter.hasNext())
-        {
+        Iterator< String > iter = sortedNames( p1 ).iterator();
+        while( iter.hasNext() ) {
             final String name = iter.next();
-            final String value = p1.getProperty(name);
+            final String value = p1.getProperty( name );
 
-            if (p2.get(name) == null)
-            {
+            if( p2.get( name ) == null ) {
                 missing++;
-                if (missing == 1)
-                {
-                    System.out.println("\nMissing:");
-                    System.out.println("--------");
+                if( missing == 1 ) {
+                    System.out.println( "\nMissing:" );
+                    System.out.println( "--------" );
                 }
-                System.out.println(name + " = " + value);
+                System.out.println( name + " = " + value );
             }
         }
-        if (missing > 0)
-        {
-            System.out.println();
+        if( missing > 0 ) {
+            System.out.println( "" );
         }
 
-        iter = sortedNames(p2).iterator();
-        while (iter.hasNext())
-        {
+        iter = sortedNames( p2 ).iterator();
+        while( iter.hasNext() ) {
             final String name = iter.next();
-            final String value = p2.getProperty(name);
+            final String value = p2.getProperty( name );
 
-            if (p1.get(name) == null)
-            {
+            if( p1.get( name ) == null ) {
                 outdated++;
-                if (outdated == 1)
-                {
-                    System.out.println("\nOutdated or superfluous:");
-                    System.out.println("------------------------");
+                if( outdated == 1 ) {
+                    System.out.println( "\nOutdated or superfluous:" );
+                    System.out.println( "------------------------" );
                 }
-                System.out.println(name + " = " + value);
+                System.out.println( name + " = " + value );
             }
         }
-        if (outdated > 0)
-        {
-            System.out.println();
+        if( outdated > 0 ) {
+            System.out.println( "" );
         }
 
         final Map< String, Integer > diff = new HashMap<>( 2 );
+        diff.put( "expected", p1.size() );
         diff.put( "missing", missing );
         diff.put( "outdated", outdated );
         return diff;
     }
 
-    private static List<String> sortedNames( final Properties p)
-    {
-        final List<String> list = new ArrayList<>();
-        final Enumeration<?> iter = p.propertyNames();
-        while (iter.hasMoreElements())
-        {
-            list.add( (String)iter.nextElement() );
+    private List< String > sortedNames( final Properties p ) {
+        final List< String > list = new ArrayList<>();
+        final Enumeration< ? > iter = p.propertyNames();
+        while( iter.hasMoreElements() ) {
+            list.add( ( String )iter.nextElement() );
         }
 
-        Collections.sort(list);
+        Collections.sort( list );
         return list;
     }
 
-    public static int detectDuplicates( final String source) throws IOException
-    {
+    public int detectDuplicates( final String source ) throws IOException {
         final Properties p = new Properties();
-        p.load( TranslationsCheck.class.getClassLoader().getResourceAsStream( base + source ) );
-
-        final Enumeration<?> iter = p.propertyNames();
+        p.load( getResourceAsStream( source ) );
+        final Enumeration< ? > iter = p.propertyNames();
         String currentStr;
-        while (iter.hasMoreElements())
-        {
-            currentStr = (String) iter.nextElement();
-            if (!allProps.add(currentStr))
-                duplProps.add(currentStr);
+        while( iter.hasMoreElements() ) {
+            currentStr = ( String )iter.nextElement();
+            if( !allProps.add( currentStr ) ) {
+                duplProps.add( currentStr );
+            }
         }
         return duplProps.size();
     }
 
+    InputStream getResourceAsStream( final String source ) {
+        return TranslationsCheck.class.getClassLoader().getResourceAsStream( base + source );
+    }
+
 }