Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
rhbz736898 - Enable new pushType option in maven client.
This option will replace the now deprecated pushTrans and allows for three possible values:
'source', 'trans', 'both'.
PushTrans may still be used but should be phased out in future releases.
  • Loading branch information
Carlos Munoz committed Apr 30, 2012
1 parent aae5947 commit 9a4be04
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 31 deletions.
Expand Up @@ -91,26 +91,28 @@ private List<LocaleMapping> findLocales()
{
if (locales != null)
return locales;
if (getOpts().getPushTrans())
if (getOpts().getPushType() == PushType.Both || getOpts().getPushType() == PushType.Trans)
{
if (getOpts().getLocales() != null)
{
locales = PublicanUtil.findLocales(getOpts().getTransDir(), getOpts().getLocales());
if (locales.size() == 0)
{
log.warn("option 'pushTrans' is set, but none of the configured locale directories was found (check zanata.xml)");
log.warn("'pushType' is set to '" + getOpts().getPushType() + "', but none of the configured locale " +
"directories was found (check zanata.xml)");
}
}
else
{
locales = PublicanUtil.findLocales(getOpts().getTransDir());
if (locales.size() == 0)
{
log.warn("option 'pushTrans' is set, but no locale directories were found");
log.warn("'pushType' is set to '\" + getOpts().getPushType() + \"', but no locale directories were found");
}
else
{
log.info("option 'pushTrans' is set, but no locales specified in configuration: importing " + locales.size() + " directories");
log.info("'pushType' is set to '\" + getOpts().getPushType() + \"', but no locales specified in configuration: " +
"importing " + locales.size() + " directories");
}
}
}
Expand Down
Expand Up @@ -109,17 +109,22 @@ private void logOptions()
log.info("Exclude patterns: {}", StringUtils.join(getOpts().getExcludes(), " "));
log.info("Default excludes: {}", getOpts().getDefaultExcludes());

if (getOpts().getPushTrans())
if (getOpts().getPushType() == PushType.Trans)
{
log.info("Pushing source and target documents");
log.info("Pushing target documents only");
log.info("Locales to push: {}", getOpts().getLocales());
}
else
else if(getOpts().getPushType() == PushType.Source)
{
log.info("Pushing source documents only");
}
else
{
log.info("Pushing source and target documents");
log.info("Locales to push: {}", getOpts().getLocales());
}
log.info("Source directory (originals): {}", getOpts().getSrcDir());
if (getOpts().getPushTrans())
if (getOpts().getPushType() == PushType.Both || getOpts().getPushType() == PushType.Trans)
{
log.info("Target base directory (translations): {}", getOpts().getTransDir());
}
Expand Down Expand Up @@ -239,12 +244,20 @@ private void pushCurrentModule() throws IOException
log.info("Obsolete docs: {}", obsoleteDocs);
}

if (getOpts().getPushTrans())
if (getOpts().getPushType() == PushType.Trans || getOpts().getPushType() == PushType.Both )
{
if (getOpts().getLocales() == null)
throw new ConfigException("pushTrans option set, but zanata.xml contains no <locales>");
log.warn("pushTrans option is set: existing translations on server may be overwritten/deleted");
confirmWithUser("This will overwrite existing documents AND TRANSLATIONS on the server, and delete obsolete documents.\n");
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");

if( getOpts().getPushType() == PushType.Both )
{
confirmWithUser("This will overwrite existing documents AND TRANSLATIONS on the server, and delete obsolete documents.\n");
}
else if( getOpts().getPushType() == PushType.Trans )
{
confirmWithUser("This will overwrite existing TRANSLATIONS on the server.\n");
}
}
else
{
Expand All @@ -259,9 +272,11 @@ private void pushCurrentModule() throws IOException
srcDoc.setName(qualifiedDocName);
debug(srcDoc);

pushSrcDocToServer(docUri, srcDoc, extensions);

if (getOpts().getPushTrans())
if( getOpts().getPushType() == PushType.Source || getOpts().getPushType() == PushType.Both )
{
pushSrcDocToServer(docUri, srcDoc, extensions);
}
if (getOpts().getPushType() == PushType.Trans || getOpts().getPushType() == PushType.Both)
{
strat.visitTranslationResources(localDocName, srcDoc, new TranslationResourcesVisitor()
{
Expand Down
Expand Up @@ -7,7 +7,7 @@
public interface PushOptions extends PushPullOptions
{
public String getSourceLang();
public boolean getPushTrans();
public PushType getPushType();
public boolean getCopyTrans();
public String getMergeType();
public List<String> getIncludes();
Expand Down
@@ -0,0 +1,64 @@
/*
* Copyright 2010, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.client.commands.push;

/**
* @author Carlos Munoz <a href="mailto:camunoz@redhat.com">camunoz@redhat.com</a>
*/
public enum PushType
{
/** Push source documents only */
Source,
/** Push Translated documents only */
Trans,
/** Push both Source and Translated documents */
Both;

/**
* Parse a PushType value from a string case-insensitively, and diregarding leading
* and trailing spaces.
*
* @param str The string to parse.
* @return The parsed PushType enum value, or null if the string did not match a value.
*/
public static PushType fromString(String str)
{
PushType enumVal = null;

if( str != null )
{
if( Source.toString().equalsIgnoreCase( str.trim() ) )
{
enumVal = Source;
}
else if( Trans.toString().equalsIgnoreCase( str.trim() ) )
{
enumVal = Trans;
}
else if( Both.toString().equalsIgnoreCase( str.trim() ) )
{
enumVal = Both;
}
}

return enumVal;
}
}
Expand Up @@ -42,6 +42,7 @@ class PushOptionsImpl extends ConfigurableProjectOptionsImpl implements PushOpti
String mergeType;
boolean copyTrans;
boolean pushTrans;
String pushType;
File transDir;
File srcDir;
String sourceLang;
Expand Down Expand Up @@ -82,12 +83,6 @@ public File getTransDir()
return transDir;
}

@Override
public boolean getPushTrans()
{
return pushTrans;
}

@Override
public boolean getCopyTrans()
{
Expand All @@ -100,6 +95,12 @@ public String getMergeType()
return mergeType;
}

@Override
public PushType getPushType()
{
return PushType.fromString( pushType );
}

@Override
public List<String> getIncludes()
{
Expand All @@ -126,12 +127,11 @@ public void setSrcDir(File file)
this.srcDir = file;
}

/**
* @param pushTrans the pushTrans to set
*/
@Deprecated
public void setPushTrans(boolean pushTrans)
{
this.pushTrans = pushTrans;
this.pushType = pushTrans ? PushType.Both.toString() : PushType.Source.toString();
}

@Override
Expand Down
31 changes: 26 additions & 5 deletions zanata-maven-plugin/src/main/java/org/zanata/maven/PushMojo.java
Expand Up @@ -7,6 +7,7 @@
import org.apache.commons.lang.StringUtils;
import org.zanata.client.commands.push.PushCommand;
import org.zanata.client.commands.push.PushOptions;
import org.zanata.client.commands.push.PushType;

/**
* Pushes source text to a Zanata project version so that it can be translated, and optionally push translated text as well.
Expand Down Expand Up @@ -41,11 +42,22 @@ public PushCommand initCommand()

/**
* Push translations from local files to the server (merge or import: see
* mergeType)
*
* mergeType). This option is deprecated, replaced by pushType.
*
* @parameter expression="${zanata.pushTrans}"
*/
private boolean pushTrans;
@Deprecated
// Using string instead of boolean to know when pushTrans has been explicitly used.
private String pushTrans;

/**
* Type of push to perform on the server: "source" pushes source documents only.
* "trans" pushes translation documents only.
* "both" pushes both source and translation documents.
*
* @parameter expression="${zanata.pushType}" default-value="source"
*/
private String pushType;

/**
* Whether the server should copy latest translations from equivalent
Expand Down Expand Up @@ -99,16 +111,25 @@ public PushCommand initCommand()
*/
private boolean deleteObsoleteModules;


@Override
public String getSourceLang()
{
return sourceLang;
}

@Override
public boolean getPushTrans()
public PushType getPushType()
{
return pushTrans;
// if the deprecated 'pushTrans' option has been used
if( pushTrans != null )
{
return Boolean.parseBoolean(pushTrans) ? PushType.Both : PushType.Source;
}
else
{
return PushType.fromString(pushType);
}
}

@Override
Expand Down
Expand Up @@ -5,6 +5,7 @@
import org.easymock.EasyMock;
import org.easymock.IMocksControl;
import org.zanata.client.commands.push.PushCommand;
import org.zanata.client.commands.push.PushType;

public class PushMojoTest extends ZanataMojoTest<PushMojo, PushCommand>
{
Expand Down Expand Up @@ -61,7 +62,27 @@ public void testPomConfig() throws Exception
assertEquals("srcDir", pushMojo.getSrcDir().toString());
assertEquals("transDir", pushMojo.getTransDir().toString());
assertEquals("es", pushMojo.getSourceLang());
assertEquals(true, pushMojo.getPushTrans());
assertEquals(PushType.Both, pushMojo.getPushType());
assertEquals(false, pushMojo.getCopyTrans());
assertEquals("import", pushMojo.getMergeType());
assertEquals(Arrays.asList("includes"), pushMojo.getIncludes());
assertEquals(Arrays.asList("excludes"), pushMojo.getExcludes());
assertEquals(false, pushMojo.getDefaultExcludes());
}

/**
* Test that the pom.xml settings are applied as expected using the pushType
* mojo paramater,
*
* @throws Exception
*/
public void testPomConfigWithPushType() throws Exception
{
applyPomParams("pom-config-pushType.xml");
assertEquals("srcDir", pushMojo.getSrcDir().toString());
assertEquals("transDir", pushMojo.getTransDir().toString());
assertEquals("es", pushMojo.getSourceLang());
assertEquals(PushType.Trans, pushMojo.getPushType());
assertEquals(false, pushMojo.getCopyTrans());
assertEquals("import", pushMojo.getMergeType());
assertEquals(Arrays.asList("includes"), pushMojo.getIncludes());
Expand Down
@@ -0,0 +1,21 @@
<project>
<build>
<plugins>
<plugin>
<artifactId>zanata-maven-plugin</artifactId>
<configuration>
<srcDir>srcDir</srcDir>
<transDir>transDir</transDir>
<sourceLang>es</sourceLang>
<pushType>trans</pushType>
<copyTrans>false</copyTrans>
<merge>import</merge>
<useSrcOrder>true</useSrcOrder>
<includes>includes</includes>
<excludes>excludes</excludes>
<defaultExcludes>false</defaultExcludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

0 comments on commit 9a4be04

Please sign in to comment.