From 816e8ce50a3cf3cfa300935aff0a8e8faca57400 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel <lkundrak@v3.sk> Date: Thu, 24 Dec 2009 17:22:01 +0100 Subject: [PATCH] Replace plexus.lang dependency with plexus.i18n Changes to POM and script that migrates the source. --- mercury-lang-i18n.pl | 29 +++++++++++++++++++++++++++++ pom.xml | 8 ++++---- 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 mercury-lang-i18n.pl diff --git a/mercury-lang-i18n.pl b/mercury-lang-i18n.pl new file mode 100644 index 0000000..33c6817 --- /dev/null +++ b/mercury-lang-i18n.pl @@ -0,0 +1,29 @@ +#!/usr/bin/perl -ni + +# Refactor mercury to use plexus.i18n instead of plexus.lang (which is, according to upstream, "stalled") +# find -name '*.java' -exec grep -l org.codehaus.plexus.lang '{}' \; |xargs perl -ni mercury-lang-i18n.pl + +# Replace plexus.lang with plexus.i18n +s/org.codehaus.plexus.lang.DefaultLanguage/org.codehaus.plexus.i18n.DefaultI18N;\nimport org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException/; +s/org.codehaus.plexus.lang.Language/org.codehaus.plexus.i18n.I18N/; +s/private static final Language (\S+) = new DefaultLanguage\S*\([^\)]*\)/private static final DefaultI18N $1 = new DefaultI18N ()/ and ($lang = $1, $thisclass = $class); + +# Initialize I18N in constructors of classes that instantiate I18N +/^\s*(public)?\s*class\s+(\S+)/ and ($class = $2, $thisclass = undef); +if ($inclass == 2) +{ + /^(\s*)(\})?/; $ws = $2 ? "$1 " : $1; + $f = "$1try { $lang.initialize (); } catch( InitializationException e ) {} /* $class = $thisclass */"; + if (/this/) { s/$/\n$f/ } + else { s/^/$f\n/ } + $inclass = 0; +} +$thisclass and /(public|protected)\s+$thisclass/ and $inclass = 1; +/\}/ and $inclass = 0; +$inclass and /\{/ and $inclass++; + +# Rewrite getMessage calls +s/$lang.getMessage\s*\(\s*(\"[^\"\)]*\")\s*\)/$lang.getString ($class.class.getPackage().getName()+".Messages", null, $1)/; +s/$lang.getMessage\s*\(([^\)]*,[^\)]*)/$lang.format ($class.class.getPackage().getName()+".Messages", null, $1/; + +print; diff --git a/pom.xml b/pom.xml index cefeefc..4a03c50 100644 --- a/pom.xml +++ b/pom.xml @@ -80,7 +80,7 @@ under the License. <plexus.component.annotations.version>1.0-beta-3.0.6</plexus.component.annotations.version> <plexus.component.metadata.version>1.0-beta-3.0.6</plexus.component.metadata.version> <plexus.utils.version>1.5.5</plexus.utils.version> - <plexus.lang.version>1.1</plexus.lang.version> + <plexus.i18n.version>1.0</plexus.i18n.version> <plexus.spice.model.builder.version>1.8</plexus.spice.model.builder.version> @@ -266,8 +266,8 @@ under the License. <dependency> <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-lang</artifactId> - <version>${plexus.lang.version}</version> + <artifactId>plexus-i18n</artifactId> + <version>${plexus.i18n.version}</version> </dependency> <!--dependency> @@ -442,7 +442,7 @@ under the License. <dependencies> <dependency> <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-lang</artifactId> + <artifactId>plexus-i18n</artifactId> <exclusions> <exclusion> <groupId>org.codehaus.plexus</groupId> -- 1.6.5.2