Permalink
Browse files

rhbz736898 - Implement -Dzanata.locales option on maven client.

The new option allows users to push documents and/or translations for specific locales.
  • Loading branch information...
1 parent 9a4be04 commit 8c9762f5e302ea0918950ce427fa78bb0a4c5029 @carlosmunoz carlosmunoz committed Apr 30, 2012
Showing with 99 additions and 40 deletions.
  1. +2 −2 zanata-client-ant-po/src/main/java/org/zanata/client/ant/po/ConfigurableProjectTask.java
  2. +2 −2 zanata-client-commands/src/main/java/org/zanata/client/commands/ConfigurableProjectOptions.java
  3. +2 −2 zanata-client-commands/src/main/java/org/zanata/client/commands/ConfigurableProjectOptionsImpl.java
  4. +1 −1 zanata-client-commands/src/main/java/org/zanata/client/commands/OptionsUtil.java
  5. +1 −1 zanata-client-commands/src/main/java/org/zanata/client/commands/PublicanPullCommand.java
  6. +2 −2 zanata-client-commands/src/main/java/org/zanata/client/commands/PublicanPushCommand.java
  7. +2 −2 ...t-commands/src/main/java/org/zanata/client/commands/glossary/push/AbstractGlossaryPushReader.java
  8. +2 −2 zanata-client-commands/src/main/java/org/zanata/client/commands/pull/PullCommand.java
  9. +1 −1 zanata-client-commands/src/main/java/org/zanata/client/commands/push/AbstractPushStrategy.java
  10. +2 −2 zanata-client-commands/src/main/java/org/zanata/client/commands/push/GettextDirStrategy.java
  11. +1 −1 zanata-client-commands/src/main/java/org/zanata/client/commands/push/PropertiesStrategy.java
  12. +4 −3 zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushCommand.java
  13. +1 −1 zanata-client-commands/src/main/java/org/zanata/client/commands/push/XliffStrategy.java
  14. +1 −1 zanata-client-commands/src/main/java/org/zanata/client/commands/push/XmlStrategy.java
  15. +1 −1 zanata-client-commands/src/test/java/org/zanata/client/commands/PublicanPullCommandTest.java
  16. +1 −1 zanata-client-commands/src/test/java/org/zanata/client/commands/PublicanPushCommandTest.java
  17. +2 −4 ...client-commands/src/test/java/org/zanata/client/commands/glossary/push/GlossaryCSVReaderTest.java
  18. +1 −1 ...-client-commands/src/test/java/org/zanata/client/commands/glossary/push/GlossaryPoReaderTest.java
  19. +1 −1 zanata-client-commands/src/test/java/org/zanata/client/commands/push/PushCommandTest.java
  20. +4 −4 zanata-client-commands/src/test/java/org/zanata/client/commands/push/XliffStrategyTest.java
  21. +5 −5 zanata-maven-plugin/src/main/java/org/zanata/maven/ConfigurableProjectMojo.java
  22. +60 −0 zanata-maven-plugin/src/main/java/org/zanata/maven/PushMojo.java
@@ -61,12 +61,12 @@ public File getProjectConfig()
return projectConfig;
}
- public LocaleList getLocales()
+ public LocaleList getLocaleMapList()
{
return locales;
}
- public void setLocales(LocaleList locales)
+ public void setLocaleMapList(LocaleList locales)
{
this.locales = locales;
}
@@ -36,8 +36,8 @@
public File getProjectConfig();
- public LocaleList getLocales();
+ public LocaleList getLocaleMapList();
- public void setLocales(LocaleList locales);
+ public void setLocaleMapList(LocaleList locales);
}
@@ -102,13 +102,13 @@ public File getProjectConfig()
}
@Override
- public LocaleList getLocales()
+ public LocaleList getLocaleMapList()
{
return locales;
}
@Override
- public void setLocales(LocaleList locales)
+ public void setLocaleMapList(LocaleList locales)
{
this.locales = locales;
}
@@ -93,7 +93,7 @@ private static void applyProjectConfig(ConfigurableProjectOptions opts, ZanataCo
opts.setProjectType(config.getProjectType());
}
LocaleList locales = config.getLocales();
- opts.setLocales(locales);
+ opts.setLocaleMapList(locales);
}
/**
@@ -83,7 +83,7 @@ public void run() throws Exception
}
log.info("PO base directory (translations): {}", getOpts().getDstDir());
- LocaleList locales = getOpts().getLocales();
+ LocaleList locales = getOpts().getLocaleMapList();
if (locales == null)
throw new ConfigException("no locales specified");
PoWriter2 poWriter = new PoWriter2();
@@ -172,9 +172,9 @@ else if (getOpts().isInteractiveMode())
List<LocaleMapping> locales = null;
if (getOpts().getImportPo())
{
- if (getOpts().getLocales() != null)
+ if (getOpts().getLocaleMapList() != null)
{
- locales = PublicanUtil.findLocales(getOpts().getSrcDir(), getOpts().getLocales());
+ locales = PublicanUtil.findLocales(getOpts().getSrcDir(), getOpts().getLocaleMapList());
if (locales.size() == 0)
{
log.warn("option 'importPo' is set, but none of the configured locale directories was found (check zanata.xml)");
@@ -42,9 +42,9 @@
protected LocaleId getLocaleFromMap(String localLocale)
{
- if (!getOpts().getLocales().isEmpty())
+ if (!getOpts().getLocaleMapList().isEmpty())
{
- for (LocaleMapping loc : getOpts().getLocales())
+ for (LocaleMapping loc : getOpts().getLocaleMapList())
{
if (loc.getLocalLocale().equals(localLocale))
{
@@ -85,7 +85,7 @@ private void logOptions()
}
}
}
- log.info("Locales to pull: {}", getOpts().getLocales());
+ log.info("Locales to pull: {}", getOpts().getLocaleMapList());
if (getOpts().getPullSrc())
{
log.info("Pulling source and target (translation) documents");
@@ -109,7 +109,7 @@ public void run() throws Exception
{
logOptions();
- LocaleList locales = getOpts().getLocales();
+ LocaleList locales = getOpts().getLocaleMapList();
if (locales == null)
throw new ConfigException("no locales specified");
PullStrategy strat = getStrategy(getOpts().getProjectType());
@@ -83,7 +83,7 @@ public AbstractPushStrategy(StringSet extensions, String fileExtension)
private void excludeLocaleFileName(List<String> excludes)
{
- for (LocaleMapping locMap : opts.getLocales())
+ for (LocaleMapping locMap : opts.getLocaleMapList())
{
String loc = locMap.getJavaLocale().toLowerCase();
excludes.add("**/*_" + loc + fileExtension);
@@ -93,9 +93,9 @@ public Resource loadSrcDoc(File sourceDir, String docName) throws IOException
return locales;
if (getOpts().getPushType() == PushType.Both || getOpts().getPushType() == PushType.Trans)
{
- if (getOpts().getLocales() != null)
+ if (getOpts().getLocaleMapList() != null)
{
- locales = PublicanUtil.findLocales(getOpts().getTransDir(), getOpts().getLocales());
+ locales = PublicanUtil.findLocales(getOpts().getTransDir(), getOpts().getLocaleMapList());
if (locales.size() == 0)
{
log.warn("'pushType' is set to '" + getOpts().getPushType() + "', but none of the configured locale " +
@@ -113,7 +113,7 @@ private TranslationsResource loadTranslationsResource(Resource srcDoc, File tran
@Override
public void visitTranslationResources(String docName, Resource srcDoc, TranslationResourcesVisitor callback) throws IOException
{
- for (LocaleMapping locale : getOpts().getLocales())
+ for (LocaleMapping locale : getOpts().getLocaleMapList())
{
String filename = docNameToFilename(docName, locale);
File transFile = new File(getOpts().getTransDir(), filename);
@@ -18,6 +18,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zanata.client.commands.PushPullCommand;
+import org.zanata.client.config.LocaleList;
import org.zanata.client.config.LocaleMapping;
import org.zanata.client.exceptions.ConfigException;
import org.zanata.common.LocaleId;
@@ -112,7 +113,7 @@ private void logOptions()
if (getOpts().getPushType() == PushType.Trans)
{
log.info("Pushing target documents only");
- log.info("Locales to push: {}", getOpts().getLocales());
+ log.info("Locales to push: {}", getOpts().getLocaleMapList());
}
else if(getOpts().getPushType() == PushType.Source)
{
@@ -121,7 +122,7 @@ else if(getOpts().getPushType() == PushType.Source)
else
{
log.info("Pushing source and target documents");
- log.info("Locales to push: {}", getOpts().getLocales());
+ log.info("Locales to push: {}", getOpts().getLocaleMapList());
}
log.info("Source directory (originals): {}", getOpts().getSrcDir());
if (getOpts().getPushType() == PushType.Both || getOpts().getPushType() == PushType.Trans)
@@ -246,7 +247,7 @@ private void pushCurrentModule() throws IOException
if (getOpts().getPushType() == PushType.Trans || getOpts().getPushType() == PushType.Both )
{
- if (getOpts().getLocales() == null)
+ if (getOpts().getLocaleMapList() == null)
throw new ConfigException("pushType set to '" + getOpts().getPushType() + "', but zanata.xml contains no <locales>");
log.warn("pushType set to '" + getOpts().getPushType() + "': existing translations on server may be overwritten/deleted");
@@ -79,7 +79,7 @@ public Resource loadSrcDoc(File sourceDir, String docName) throws IOException
@Override
public void visitTranslationResources(String docName, Resource srcDoc, TranslationResourcesVisitor visitor) throws FileNotFoundException
{
- for (LocaleMapping locale : getOpts().getLocales())
+ for (LocaleMapping locale : getOpts().getLocaleMapList())
{
String filename = docNameToFilename(docName, locale);
File transFile = new File(getOpts().getTransDir(), filename);
@@ -97,7 +97,7 @@ public void visitTranslationResources(String docName, Resource srcDoc, Translati
{
try
{
- for (LocaleMapping locale : getOpts().getLocales())
+ for (LocaleMapping locale : getOpts().getLocaleMapList())
{
String filename = docNameToFilename(docName, locale);
File transFile = new File(getOpts().getTransDir(), filename);
@@ -78,7 +78,7 @@ private void publicanPull(boolean exportPot, boolean mapLocale) throws Exception
{
LocaleList locales = new LocaleList();
locales.add(new LocaleMapping("ja", "ja-JP"));
- opts.setLocales(locales);
+ opts.setLocaleMapList(locales);
}
List<ResourceMeta> resourceMetaList = new ArrayList<ResourceMeta>();
@@ -83,7 +83,7 @@ private void publicanPush(boolean importPo, boolean mapLocale) throws Exception
{
LocaleList locales = new LocaleList();
locales.add(new LocaleMapping("ja", "ja-JP"));
- opts.setLocales(locales);
+ opts.setLocaleMapList(locales);
}
List<ResourceMeta> resourceMetaList = new ArrayList<ResourceMeta>();
@@ -31,8 +31,6 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
-import org.zanata.client.commands.glossary.push.GlossaryCSVReader;
-import org.zanata.client.commands.glossary.push.GlossaryPushOptions;
import org.zanata.client.config.LocaleList;
import org.zanata.client.config.LocaleMapping;
import org.zanata.rest.dto.Glossary;
@@ -82,7 +80,7 @@ public void extractGlossaryTest1() throws IOException
mockPushOption = createMock("mockPushGlossaryOption", GlossaryPushOptions.class);
EasyMock.expect(mockPushOption.getSourceLang()).andReturn("en-US").anyTimes();
EasyMock.expect(mockPushOption.getTransLang()).andReturn("hi").anyTimes();
- EasyMock.expect(mockPushOption.getLocales()).andReturn(locales).anyTimes();
+ EasyMock.expect(mockPushOption.getLocaleMapList()).andReturn(locales).anyTimes();
EasyMock.expect(mockPushOption.getTreatSourceCommentsAsTarget()).andReturn(false).anyTimes();
EasyMock.expect(mockPushOption.getCommentCols()).andReturn(commentHeaders).anyTimes();
@@ -113,7 +111,7 @@ public void extractGlossaryTest2() throws IOException
mockPushOption = createMock("mockPushGlossaryOption", GlossaryPushOptions.class);
EasyMock.expect(mockPushOption.getSourceLang()).andReturn("en-US").anyTimes();
EasyMock.expect(mockPushOption.getTransLang()).andReturn("hi").anyTimes();
- EasyMock.expect(mockPushOption.getLocales()).andReturn(locales).anyTimes();
+ EasyMock.expect(mockPushOption.getLocaleMapList()).andReturn(locales).anyTimes();
EasyMock.expect(mockPushOption.getTreatSourceCommentsAsTarget()).andReturn(false).anyTimes();
EasyMock.expect(mockPushOption.getCommentCols()).andReturn(commentHeaders).anyTimes();
@@ -74,7 +74,7 @@ public void extractGlossaryTest() throws IOException
mockPushOption = createMock("mockPushGlossaryOption", GlossaryPushOptions.class);
EasyMock.expect(mockPushOption.getSourceLang()).andReturn("en-US").anyTimes();
EasyMock.expect(mockPushOption.getTransLang()).andReturn("hi").anyTimes();
- EasyMock.expect(mockPushOption.getLocales()).andReturn(locales).anyTimes();
+ EasyMock.expect(mockPushOption.getLocaleMapList()).andReturn(locales).anyTimes();
EasyMock.expect(mockPushOption.getTreatSourceCommentsAsTarget()).andReturn(false).anyTimes();
reader.setOpts(mockPushOption);
@@ -97,7 +97,7 @@ private void push(boolean pushTrans, boolean mapLocale) throws Exception
{
locales.add(new LocaleMapping("ja-JP"));
}
- opts.setLocales(locales);
+ opts.setLocaleMapList(locales);
List<ResourceMeta> resourceMetaList = new ArrayList<ResourceMeta>();
resourceMetaList.add(new ResourceMeta("obsolete"));
@@ -60,7 +60,7 @@ public void findDocNamesTest() throws IOException
include.add("**/**StringResource_en_US*");
// EasyMock.expect(mockPushOption.getIncludes()).andReturn(include);
- EasyMock.expect(mockPushOption.getLocales()).andReturn(locales).anyTimes();
+ EasyMock.expect(mockPushOption.getLocaleMapList()).andReturn(locales).anyTimes();
EasyMock.expect(mockPushOption.getSourceLang()).andReturn("en-US").anyTimes();
EasyMock.expect(mockPushOption.getDefaultExcludes()).andReturn(true).anyTimes();
@@ -87,7 +87,7 @@ public void loadSrcDocTest() throws IOException
// EasyMock.expect(mockPushOption.getIncludes()).andReturn(include);
EasyMock.expect(mockPushOption.getTransDir()).andReturn(sourceDir).anyTimes();
- EasyMock.expect(mockPushOption.getLocales()).andReturn(locales).anyTimes();
+ EasyMock.expect(mockPushOption.getLocaleMapList()).andReturn(locales).anyTimes();
EasyMock.expect(mockPushOption.getSourceLang()).andReturn("en-US").anyTimes();
EasyMock.expect(mockPushOption.getDefaultExcludes()).andReturn(true).anyTimes();
@@ -134,7 +134,7 @@ public void loadSrcDocTestWithExcludeFileOption() throws IOException
// EasyMock.expect(mockPushOption.getIncludes()).andReturn(include);
EasyMock.expect(mockPushOption.getTransDir()).andReturn(sourceDir).anyTimes();
- EasyMock.expect(mockPushOption.getLocales()).andReturn(locales).anyTimes();
+ EasyMock.expect(mockPushOption.getLocaleMapList()).andReturn(locales).anyTimes();
EasyMock.expect(mockPushOption.getSourceLang()).andReturn("en-US").anyTimes();
EasyMock.expect(mockPushOption.getDefaultExcludes()).andReturn(true).anyTimes();
@@ -185,7 +185,7 @@ public void loadSrcDocTestWithExcludeOption() throws IOException
// EasyMock.expect(mockPushOption.getIncludes()).andReturn(include);
EasyMock.expect(mockPushOption.getTransDir()).andReturn(sourceDir).anyTimes();
- EasyMock.expect(mockPushOption.getLocales()).andReturn(locales).anyTimes();
+ EasyMock.expect(mockPushOption.getLocaleMapList()).andReturn(locales).anyTimes();
EasyMock.expect(mockPushOption.getSourceLang()).andReturn("en-US").anyTimes();
EasyMock.expect(mockPushOption.getDefaultExcludes()).andReturn(true).anyTimes();
@@ -54,7 +54,7 @@
*/
private String projectType;
- private LocaleList locales;
+ private LocaleList localeMapList;
public ConfigurableProjectMojo()
{
@@ -110,15 +110,15 @@ public void setProjectType(String projectType)
}
@Override
- public LocaleList getLocales()
+ public LocaleList getLocaleMapList()
{
- return locales;
+ return localeMapList;
}
@Override
- public void setLocales(LocaleList locales)
+ public void setLocaleMapList(LocaleList localeMapList)
{
- this.locales = locales;
+ this.localeMapList = localeMapList;
}
}
@@ -8,6 +8,9 @@
import org.zanata.client.commands.push.PushCommand;
import org.zanata.client.commands.push.PushOptions;
import org.zanata.client.commands.push.PushType;
+import org.zanata.client.config.LocaleList;
+import org.zanata.client.config.LocaleMapping;
+import org.zanata.client.exceptions.ConfigException;
/**
* Pushes source text to a Zanata project version so that it can be translated, and optionally push translated text as well.
@@ -111,6 +114,18 @@ public PushCommand initCommand()
*/
private boolean deleteObsoleteModules;
+ /**
+ * Locales to push to the server.
+ * By default all locales in zanata.xml will be pushed.
+ * Usage: -Dzanata.locales=locale1,locale2,locale3
+ *
+ * @parameter expression="${zanata.locales}"
+ */
+ private String[] locales;
+
+ // Cached copy of the effective locales to avoid calculating it more than once
+ private LocaleList effectiveLocales;
+
@Override
public String getSourceLang()
@@ -180,4 +195,49 @@ public boolean getDefaultExcludes()
return defaultExcludes;
}
+ /**
+ * Override the default {@link org.zanata.maven.ConfigurableProjectMojo#getLocaleMapList()} method as the push
+ * command can have locales specified via command line.
+ *
+ * @return The locale map list taking into account the global locales in zanata.xml as well as the command line
+ * argument ones.
+ */
+ @Override
+ public LocaleList getLocaleMapList()
+ {
+ if( effectiveLocales == null )
+ {
+ if(locales != null && locales.length > 0)
+ {
+ // filter the locales that are specified in both the global config and the parameter list
+ effectiveLocales = new LocaleList();
+
+ for( String locale : locales )
+ {
+ boolean foundLocale = false;
+ for(LocaleMapping lm : super.getLocaleMapList())
+ {
+ if( lm.getLocale().equals(locale) ||
+ (lm.getMapFrom() != null && lm.getMapFrom().equals( locale )) )
+ {
+ effectiveLocales.add(lm);
+ foundLocale = true;
+ break;
+ }
+ }
+
+ if(!foundLocale)
+ {
+ throw new ConfigException("Specified locale '" + locale + "' was not found in zanata.xml!" );
+ }
+ }
+ }
+ else
+ {
+ effectiveLocales = super.getLocaleMapList();
+ }
+ }
+
+ return effectiveLocales;
+ }
}

0 comments on commit 8c9762f

Please sign in to comment.