Skip to content
Browse files

Merge branch 'merging'

  • Loading branch information...
2 parents d4e942d + 9b12ba8 commit 4580bd887d2874113e22bc290c967115e03928a1 @davidmason davidmason committed
Showing with 1,529 additions and 525 deletions.
  1. +10 −0 client/zanata-adapter-properties/pom.xml
  2. +3 −3 ...operties/src/test/java/org/zanata/adapter/properties/{PropReaderTests.java → PropReaderTest.java}
  3. +10 −0 client/zanata-adapter-xliff/pom.xml
  4. +2 −4 client/zanata-client-ant-po/eclipse/DownloadPoTask --help.launch
  5. +2 −5 client/zanata-client-ant-po/eclipse/DownloadPoTask.launch
  6. +2 −4 client/zanata-client-ant-po/eclipse/UploadPoTask --help.launch
  7. +0 −14 client/zanata-client-ant-po/eclipse/UploadPoTask hudson.launch
  8. +0 −2 client/zanata-client-ant-po/eclipse/UploadPoTask localhost.launch
  9. +3 −3 client/zanata-client-ant-po/pom.xml
  10. +8 −4 client/zanata-client-ant-po/src/main/java/org/zanata/client/ant/po/ConfigurableProjectTask.java
  11. +0 −56 client/zanata-client-ant-po/src/main/java/org/zanata/client/ant/po/DownloadPoTask.java
  12. +2 −1 client/zanata-client-ant-po/src/test/java/org/zanata/client/ant/po/LocalTest.java
  13. +4 −0 client/zanata-client-ant-po/src/test/resources/org/zanata/client/ant/po/build.xml
  14. +2 −2 client/zanata-client-ant-po/src/test/resources/org/zanata/client/ant/po/downloadpo.xml
  15. +2 −2 client/zanata-client-ant-po/src/test/resources/org/zanata/client/ant/po/roundtrip.xml
  16. +1 −1 client/zanata-client-ant-po/src/test/resources/org/zanata/client/ant/po/uploadpo.xml
  17. +3 −3 client/zanata-client-ant-properties/pom.xml
  18. +3 −2 client/zanata-client-ant-properties/src/test/java/org/zanata/client/ant/properties/LocalTest.java
  19. +4 −0 client/zanata-client-ant-properties/src/test/resources/org/zanata/client/ant/properties/build.xml
  20. +4 −2 ...t/zanata-client-commands/src/main/java/org/zanata/client/commands/ConfigurableProjectOptions.java
  21. +5 −3 ...nata-client-commands/src/main/java/org/zanata/client/commands/ConfigurableProjectOptionsImpl.java
  22. +2 −13 client/zanata-client-commands/src/main/java/org/zanata/client/commands/OptionsUtil.java
  23. +182 −0 client/zanata-client-commands/src/main/java/org/zanata/client/commands/PushPullCommand.java
  24. +52 −0 client/zanata-client-commands/src/main/java/org/zanata/client/commands/PushPullOptions.java
  25. +71 −81 client/zanata-client-commands/src/main/java/org/zanata/client/commands/pull/PullCommand.java
  26. +2 −6 client/zanata-client-commands/src/main/java/org/zanata/client/commands/pull/PullOptions.java
  27. +5 −4 client/zanata-client-commands/src/main/java/org/zanata/client/commands/pull/PullStrategy.java
  28. +204 −127 client/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushCommand.java
  29. +3 −5 client/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushOptions.java
  30. +18 −5 client/zanata-client-commands/src/main/java/org/zanata/client/config/LocaleList.java
  31. +2 −2 client/zanata-client-commands/src/test/java/org/zanata/client/commands/DummyResponse.java
  32. +1 −1 client/zanata-client-commands/src/test/java/org/zanata/client/commands/PublicanPullCommandTest.java
  33. +129 −0 client/zanata-client-commands/src/test/java/org/zanata/client/commands/push/PushCommandTest.java
  34. +197 −0 client/zanata-client-commands/src/test/java/org/zanata/client/commands/push/PushOptionsImpl.java
  35. +32 −1 client/zanata-maven-plugin/pom.xml
  36. +10 −4 client/zanata-maven-plugin/src/main/java/org/zanata/maven/ConfigurableMojo.java
  37. +7 −4 client/zanata-maven-plugin/src/main/java/org/zanata/maven/ConfigurableProjectMojo.java
  38. +2 −1 client/zanata-maven-plugin/src/main/java/org/zanata/maven/GlossaryDeleteMojo.java
  39. +4 −3 client/zanata-maven-plugin/src/main/java/org/zanata/maven/ListLocalMojo.java
  40. +3 −2 client/zanata-maven-plugin/src/main/java/org/zanata/maven/ListRemoteMojo.java
  41. +3 −2 client/zanata-maven-plugin/src/main/java/org/zanata/maven/PublicanPullMojo.java
  42. +3 −2 client/zanata-maven-plugin/src/main/java/org/zanata/maven/PublicanPushMojo.java
  43. +2 −30 client/zanata-maven-plugin/src/main/java/org/zanata/maven/PullMojo.java
  44. +15 −28 client/zanata-maven-plugin/src/main/java/org/zanata/maven/PushMojo.java
  45. +160 −0 client/zanata-maven-plugin/src/main/java/org/zanata/maven/PushPullMojo.java
  46. +2 −1 client/zanata-maven-plugin/src/main/java/org/zanata/maven/PutProjectMojo.java
  47. +2 −1 client/zanata-maven-plugin/src/main/java/org/zanata/maven/PutUserMojo.java
  48. +2 −1 client/zanata-maven-plugin/src/main/java/org/zanata/maven/PutVersionMojo.java
  49. +0 −16 client/zanata-maven-plugin/src/test/java/org/zanata/maven/PublicanPushMojoTest.java
  50. +76 −0 client/zanata-maven-plugin/src/test/java/org/zanata/maven/PushMojoTest.java
  51. +47 −0 client/zanata-maven-plugin/src/test/java/org/zanata/maven/ZanataMojoTest.java
  52. +0 −13 client/zanata-maven-plugin/src/test/resources/publican-push-test/plugin-config.xml
  53. +21 −0 client/zanata-maven-plugin/src/test/resources/push-test/pom-config.xml
  54. +10 −0 common/zanata-adapter-po/pom.xml
  55. +12 −6 common/zanata-common-api/pom.xml
  56. +2 −0 common/zanata-common-api/src/main/java/org/zanata/rest/dto/Person.java
  57. +24 −18 ...ommon-api/src/test/java/org/zanata/rest/dto/v1/{SerializationTests.java → SerializationTest.java}
  58. +11 −0 common/zanata-common-util/pom.xml
  59. +1 −1 common/zanata-common-util/src/test/java/org/zanata/util/TestShortString.java
  60. +6 −0 common/zanata-rest-client/pom.xml
  61. +3 −1 common/zanata-rest-client/src/main/java/org/zanata/rest/client/ZanataProxyFactory.java
  62. +72 −0 common/zanata-rest-client/src/test/java/org/zanata/rest/client/ApiKeyHeaderDecoratorTest.java
  63. +17 −4 ...t/service → common/zanata-rest-client/src/test/java/org/zanata/rest/client}/TestProxyFactory.java
  64. +10 −6 server/zanata-model/pom.xml
  65. +14 −0 server/zanata-war/pom.xml
  66. +1 −0 server/zanata-war/src/main/java/org/zanata/rest/service/TranslationResourcesService.java
  67. +1 −0 server/zanata-war/src/test/java/org/zanata/rest/service/GlossaryServiceSeamTest.java
  68. +2 −6 server/zanata-war/src/test/java/org/zanata/rest/service/ResourceTranslationServiceSeamTest.java
  69. +2 −5 server/zanata-war/src/test/java/org/zanata/rest/service/VersionSeamTest.java
  70. +12 −14 zanata-parent/pom.xml
View
10 client/zanata-adapter-properties/pom.xml
@@ -48,5 +48,15 @@
<version>2.0.1</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
View
6 ...a/adapter/properties/PropReaderTests.java → ...ta/adapter/properties/PropReaderTest.java
@@ -27,9 +27,9 @@
import org.zanata.rest.dto.resource.TextFlow;
import org.zanata.rest.dto.resource.TranslationsResource;
-public class PropReaderTests
+public class PropReaderTest
{
- private static final Logger log = LoggerFactory.getLogger(PropReaderTests.class);
+ private static final Logger log = LoggerFactory.getLogger(PropReaderTest.class);
private static final String TEST_OUTPUT_DIR_STRING = "target/test-output";
private static final File TEST_OUTPUT_DIR = new File(TEST_OUTPUT_DIR_STRING);
PropReader propReader;
@@ -114,7 +114,7 @@ private void assertInputAndOutputDocContentSame(String docName) throws FileNotFo
private InputStream getResourceAsStream(String relativeResourceName) throws FileNotFoundException
{
- InputStream stream = PropReaderTests.class.getResourceAsStream(relativeResourceName);
+ InputStream stream = PropReaderTest.class.getResourceAsStream(relativeResourceName);
if (stream == null)
throw new FileNotFoundException(relativeResourceName);
return stream;
View
10 client/zanata-adapter-xliff/pom.xml
@@ -43,5 +43,15 @@
<artifactId>stax</artifactId>
<version>1.2.0</version>
</dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
View
6 client/zanata-client-ant-po/eclipse/DownloadPoTask --help.launch
@@ -1,14 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
-<listEntry value="/zanata-client-ant-po"/>
+<listEntry value="/zanata-client-ant-po/src/main/java/org/zanata/client/ant/po/DownloadPoTask.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
-<listEntry value="4"/>
+<listEntry value="1"/>
</listAttribute>
-<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.classpathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.zanata.client.ant.po.DownloadPoTask"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--help"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="zanata-client-ant-po"/>
-<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.sourcepathProvider"/>
</launchConfiguration>
View
7 client/zanata-client-ant-po/eclipse/DownloadPoTask.launch
@@ -1,14 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
-<listEntry value="/zanata-client-ant-po"/>
+<listEntry value="/zanata-client-ant-po/src/main/java/org/zanata/client/ant/po/DownloadPoTask.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
-<listEntry value="4"/>
+<listEntry value="1"/>
</listAttribute>
-<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.classpathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.zanata.client.ant.po.DownloadPoTask"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--debug --user admin --key b6d7044e9ee3b2447c28fb7c50d86d98 --src http://localhost:8080/zanata/seam/resource/restv1/projects/p/sample-project/iterations/i/1.1/documents --dst target/test-output"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="zanata-client-ant-po"/>
-<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.sourcepathProvider"/>
</launchConfiguration>
View
6 client/zanata-client-ant-po/eclipse/UploadPoTask --help.launch
@@ -1,14 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
-<listEntry value="/zanata-client-ant-po"/>
+<listEntry value="/zanata-client-ant-po/src/main/java/org/zanata/client/ant/po/UploadPoTask.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
-<listEntry value="4"/>
+<listEntry value="1"/>
</listAttribute>
-<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.classpathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.zanata.client.ant.po.UploadPoTask"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--help"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="zanata-client-ant-po"/>
-<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.sourcepathProvider"/>
</launchConfiguration>
View
14 client/zanata-client-ant-po/eclipse/UploadPoTask hudson.launch
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
-<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
-<listEntry value="/zanata-client-ant-po"/>
-</listAttribute>
-<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
-<listEntry value="4"/>
-</listAttribute>
-<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.classpathProvider"/>
-<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.zanata.client.ant.po.UploadPoTask"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--debug --user admin --key b6d7044e9ee3b2447c28fb7c50d86d98 --src src/test/resources/test-input --dst http://hudson.englab.bne.redhat.com/zanata/seam/resource/restv1/projects/p/sample-project/iterations/i/1.1/documents"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="zanata-client-ant-po"/>
-<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.sourcepathProvider"/>
-</launchConfiguration>
View
2 client/zanata-client-ant-po/eclipse/UploadPoTask localhost.launch
@@ -6,9 +6,7 @@
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
-<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.classpathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.zanata.client.ant.po.UploadPoTask"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--debug --user admin --key b6d7044e9ee3b2447c28fb7c50d86d98 --src src/test/resources/test-input --dst http://localhost:8080/zanata/seam/resource/restv1/projects/p/sample-project/iterations/i/1.1/documents"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="zanata-client-ant-po"/>
-<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.sourcepathProvider"/>
</launchConfiguration>
View
6 client/zanata-client-ant-po/pom.xml
@@ -42,7 +42,7 @@
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
- <version>1.7.1</version>
+ <version>1.8.2</version>
<scope>compile</scope>
</dependency>
<!--
@@ -55,13 +55,13 @@
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-launcher</artifactId>
- <version>1.7.1</version>
+ <version>1.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-testutil</artifactId>
- <version>1.7.1</version>
+ <version>1.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
View
12 .../zanata-client-ant-po/src/main/java/org/zanata/client/ant/po/ConfigurableProjectTask.java
@@ -1,12 +1,16 @@
package org.zanata.client.ant.po;
+import java.io.File;
+
import org.kohsuke.args4j.Option;
+import org.zanata.client.commands.ConfigurableProjectOptions;
import org.zanata.client.config.LocaleList;
-public abstract class ConfigurableProjectTask extends ConfigurableTask
+public abstract class ConfigurableProjectTask extends ConfigurableTask implements ConfigurableProjectOptions
{
- private String projectConfig = "zanata.xml";
+ // FIXME when running in Ant, interpret relative to getProject().getBaseDir()
+ private File projectConfig = new File("zanata.xml");
private String project;
private String projectVersion;
@@ -25,7 +29,7 @@ public void setProj(String projectSlug)
}
@Option(name = "--project-config", metaVar = "FILENAME", usage = "Project configuration, eg zanata.xml", required = false)
- public void setProjectConfig(String projectConfig)
+ public void setProjectConfig(File projectConfig)
{
this.projectConfig = projectConfig;
}
@@ -52,7 +56,7 @@ public void setProjectType(String projectType)
this.projectType = projectType;
}
- public String getProjectConfig()
+ public File getProjectConfig()
{
return projectConfig;
}
View
56 client/zanata-client-ant-po/src/main/java/org/zanata/client/ant/po/DownloadPoTask.java
@@ -2,21 +2,14 @@
import java.io.File;
-
import org.kohsuke.args4j.Option;
import org.zanata.client.commands.ArgsUtil;
import org.zanata.client.commands.PublicanPullCommand;
import org.zanata.client.commands.PublicanPullOptions;
import org.zanata.client.commands.ZanataCommand;
-import org.zanata.client.config.LocaleList;
public class DownloadPoTask extends ConfigurableProjectTask implements PublicanPullOptions
{
- private String projectConfig = "zanata.xml";
-
- private String project;
- private String projectVersion;
- private LocaleList locales;
private File dstDir;
private File dstDirPot;
private boolean exportPot;
@@ -45,55 +38,6 @@ public ZanataCommand initCommand()
return new PublicanPullCommand(this);
}
- public String getProj()
- {
- return project;
- }
-
- @Option(name = "--project", metaVar = "PROJ", usage = "Project ID. This value is required unless specified in zanata.xml.")
- public void setProj(String projectSlug)
- {
- this.project = projectSlug;
- }
-
- @Override
- @Option(name = "--project-config", metaVar = "FILENAME", usage = "Project configuration file, eg zanata.xml", required = false)
- public void setProjectConfig(String projectConfig)
- {
- this.projectConfig = projectConfig;
- }
-
- @Override
- public String getProjectVersion()
- {
- return projectVersion;
- }
-
- @Override
- @Option(name = "--project-version", metaVar = "VER", usage = "Project version ID This value is required unless specified in zanata.xml.")
- public void setProjectVersion(String versionSlug)
- {
- this.projectVersion = versionSlug;
- }
-
- @Override
- public String getProjectConfig()
- {
- return projectConfig;
- }
-
- @Override
- public LocaleList getLocales()
- {
- return locales;
- }
-
- @Override
- public void setLocales(LocaleList locales)
- {
- this.locales = locales;
- }
-
@Override
public void setDstDir(File dstDir)
{
View
3 client/zanata-client-ant-po/src/test/java/org/zanata/client/ant/po/LocalTest.java
@@ -30,7 +30,8 @@ protected String getBuildFile()
public static Test suite()
{
TestSuite suite = new TestSuite(LocalTest.class.getName());
- // FIXME
+ suite.addTest(new LocalTest("dummy"));
+ // FIXME get the other tests working
// suite.addTest(new LocalTest("uploadpo"));
// suite.addTest(new LocalTest("downloadpo"));
// suite.addTest(new LocalTest("roundtriplocal"));
View
4 client/zanata-client-ant-po/src/test/resources/org/zanata/client/ant/po/build.xml
@@ -15,6 +15,10 @@
<property name="iter" value="1.1" />
+ <target name="dummy">
+ <!-- FIXME get the other tests working -->
+ </target>
+
<target name="uploadpo">
<ant antfile="uploadpo.xml" target="_uploadpo">
<property name="docsUrl" value="${out.dir}/project.xml" />
View
4 client/zanata-client-ant-po/src/test/resources/org/zanata/client/ant/po/downloadpo.xml
@@ -1,8 +1,8 @@
<project>
<target name="_downloadpo">
<downloadpo
- user="bob"
- apiKey="${bob.key}"
+ username="bob"
+ key="${bob.key}"
src="test2/documents.xml"
dstDir="${out.dir}/test2"
debug="true" />
View
4 client/zanata-client-ant-po/src/test/resources/org/zanata/client/ant/po/roundtrip.xml
@@ -7,8 +7,8 @@
<mkdir dir="${out.dir}" />
<!-- run 2 way test -->
- <uploadpo user="bob" apiKey="${bob.key}" dst="${docsUrl}" srcDir="${in.dir}" debug="false" />
- <downloadpo user="bob" apiKey="${bob.key}" src="${docsUrl}" dstDir="${out.dir}" debug="false" />
+ <uploadpo username="bob" key="${bob.key}" dst="${docsUrl}" srcDir="${in.dir}" debug="false" />
+ <downloadpo username="bob" key="${bob.key}" src="${docsUrl}" dstDir="${out.dir}" debug="false" />
<!-- diff (unified, recursive) to find out if input and output are same
View
2 client/zanata-client-ant-po/src/test/resources/org/zanata/client/ant/po/uploadpo.xml
@@ -1,5 +1,5 @@
<project>
<target name="_uploadpo">
- <uploadpo user="bob" apiKey="${bob.key}" dst="${docsUrl}" srcDir="${in.dir}" debug="true" />
+ <uploadpo username="bob" key="${bob.key}" dst="${docsUrl}" srcDir="${in.dir}" debug="true" />
</target>
</project>
View
6 client/zanata-client-ant-properties/pom.xml
@@ -27,7 +27,7 @@
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
- <version>1.7.1</version>
+ <version>1.8.2</version>
<scope>compile</scope>
</dependency>
<!-- If only it were released! (want org.apache.ant.antunit.junit3.AntUnitSuite)
@@ -41,13 +41,13 @@
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-launcher</artifactId>
- <version>1.7.1</version>
+ <version>1.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-testutil</artifactId>
- <version>1.7.1</version>
+ <version>1.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
View
5 ...anata-client-ant-properties/src/test/java/org/zanata/client/ant/properties/LocalTest.java
@@ -14,7 +14,7 @@
* build.xml
*/
@SuppressWarnings("unchecked")
- static Class[] testedClasses = { Props2DocsTask.class, Docs2PropsTask.class };
+ static Class<?>[] testedClasses = { Props2DocsTask.class, Docs2PropsTask.class };
public LocalTest(String name)
{
@@ -30,7 +30,8 @@ protected String getBuildFile()
public static Test suite()
{
TestSuite suite = new TestSuite(LocalTest.class.getName());
- // FIXME
+ suite.addTest(new LocalTest("dummy"));
+ // FIXME get the other tests working
// suite.addTest(new LocalTest("props2docs"));
// suite.addTest(new LocalTest("docs2props"));
// suite.addTest(new LocalTest("roundtriplocal"));
View
4 ...anata-client-ant-properties/src/test/resources/org/zanata/client/ant/properties/build.xml
@@ -5,6 +5,10 @@
<property name="out.dir" value="${user.dir}/target/test-output" />
<property name="bob.key" value="34567890123456789012345678901234" />
+ <target name="dummy">
+ <!-- FIXME get the other tests working -->
+ </target>
+
<target name="props2docs">
<props2docs
srcDir="test1" sourceLang="en_US" locales="de,fr" debug="true" />
View
6 ...-client-commands/src/main/java/org/zanata/client/commands/ConfigurableProjectOptions.java
@@ -1,6 +1,8 @@
package org.zanata.client.commands;
+import java.io.File;
+
import org.kohsuke.args4j.Option;
import org.zanata.client.config.LocaleList;
@@ -20,7 +22,7 @@
public void setProj(String projectSlug);
@Option(name = "--project-config", metaVar = "FILENAME", usage = "Project configuration file, eg zanata.xml", required = false)
- public void setProjectConfig(String projectConfig);
+ public void setProjectConfig(File projectConfig);
public String getProjectVersion();
@@ -32,7 +34,7 @@
@Option(name = "--project-type", metaVar = "PROJTYPE", usage = "Project type This value is required unless specified in zanata.xml.")
public void setProjectType(String projectType);
- public String getProjectConfig();
+ public File getProjectConfig();
public LocaleList getLocales();
View
8 ...ent-commands/src/main/java/org/zanata/client/commands/ConfigurableProjectOptionsImpl.java
@@ -21,6 +21,8 @@
package org.zanata.client.commands;
+import java.io.File;
+
import org.kohsuke.args4j.Option;
import org.zanata.client.config.LocaleList;
@@ -40,7 +42,7 @@
// When used as a CLI command, the default path (specified here) is relative
// to CWD. ConfigurableProjectMojo specifies another default, which is
// relative to project's basedir.
- private String projectConfig = "zanata.xml";
+ private File projectConfig = new File("zanata.xml");
private String project;
private String projectVersion;
@@ -62,7 +64,7 @@ public void setProj(String projectSlug)
@Override
@Option(name = "--project-config", metaVar = "FILENAME", usage = "Project configuration file, eg zanata.xml", required = false)
- public void setProjectConfig(String projectConfig)
+ public void setProjectConfig(File projectConfig)
{
this.projectConfig = projectConfig;
}
@@ -94,7 +96,7 @@ public void setProjectType(String projectType)
}
@Override
- public String getProjectConfig()
+ public File getProjectConfig()
{
return projectConfig;
}
View
15 client/zanata-client-commands/src/main/java/org/zanata/client/commands/OptionsUtil.java
@@ -38,18 +38,7 @@ public static void applyConfigFiles(ConfigurableOptions opts) throws Configurati
{
JAXBContext jc = JAXBContext.newInstance(ZanataConfig.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
- String projectConfigName = projOpts.getProjectConfig();
- File projectConfigFile = new File(projectConfigName);
- if (!projectConfigFile.isAbsolute())
- {
- String userDir = System.getProperty("user.dir");
- File projectDir = new File(userDir);
- while (projectDir != null && !(projectConfigFile = new File(projectDir, projectConfigName)).exists())
- {
- projectDir = projectDir.getParentFile();
- }
- }
-
+ File projectConfigFile = projOpts.getProjectConfig();
if (projectConfigFile.exists())
{
log.info("Loading project config from {}", projectConfigFile);
@@ -60,7 +49,7 @@ public static void applyConfigFiles(ConfigurableOptions opts) throws Configurati
}
else
{
- log.warn("Project config file '{}' not found; ignoring.", projectConfigName);
+ log.warn("Project config file '{}' not found; ignoring.", projectConfigFile);
}
}
}
View
182 client/zanata-client-commands/src/main/java/org/zanata/client/commands/PushPullCommand.java
@@ -0,0 +1,182 @@
+/*
+ * Copyright 2011, 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;
+
+import java.io.Console;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+
+import org.jboss.resteasy.client.ClientResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.zanata.rest.client.ClientUtility;
+import org.zanata.rest.client.ITranslationResources;
+import org.zanata.rest.client.ZanataProxyFactory;
+import org.zanata.rest.dto.resource.Resource;
+import org.zanata.rest.dto.resource.ResourceMeta;
+import org.zanata.rest.dto.resource.TranslationsResource;
+
+/**
+ * @author Sean Flanigan <a href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
+ *
+ */
+public abstract class PushPullCommand<O extends PushPullOptions> extends ConfigurableProjectCommand<O>
+{
+ private static final Logger log = LoggerFactory.getLogger(PushPullCommand.class);
+
+ protected final ITranslationResources translationResources;
+ protected URI uri;
+ private Marshaller marshaller;
+ private String modulePrefix;
+
+ public PushPullCommand(O opts, ZanataProxyFactory factory, ITranslationResources translationResources, URI uri)
+ {
+ super(opts, factory);
+ this.translationResources = translationResources;
+ this.uri = uri;
+ this.modulePrefix = opts.getEnableModules() ? getOpts().getCurrentModule() + opts.getModuleSuffix() : "";
+ }
+
+ private PushPullCommand(O opts, ZanataProxyFactory factory)
+ {
+ this(opts, factory, factory.getTranslationResources(opts.getProj(), opts.getProjectVersion()), factory.getTranslationResourcesURI(opts.getProj(), opts.getProjectVersion()));
+ }
+
+ public PushPullCommand(O opts)
+ {
+ this(opts, OptionsUtil.createRequestFactory(opts));
+ }
+
+ protected void confirmWithUser(String message) throws IOException
+ {
+ if (getOpts().isInteractiveMode())
+ {
+ Console console = System.console();
+ if (console == null)
+ throw new RuntimeException("console not available: please run Maven from a console, or use batch mode (mvn -B)");
+ console.printf(message + "\nAre you sure (y/n)? ");
+ expectYes(console);
+ }
+ }
+
+ protected static void expectYes(Console console) throws IOException
+ {
+ String line = console.readLine();
+ if (line == null)
+ throw new IOException("console stream closed");
+ if (!line.toLowerCase().equals("y") && !line.toLowerCase().equals("yes"))
+ throw new RuntimeException("operation aborted by user");
+ }
+
+ protected void debug(Object jaxbElement)
+ {
+ try
+ {
+ if (getOpts().isDebugSet())
+ {
+ StringWriter writer = new StringWriter();
+ getMarshaller().marshal(jaxbElement, writer);
+ log.debug("{}", writer);
+ }
+ }
+ catch (JAXBException e)
+ {
+ log.debug(e.toString(), e);
+ }
+ }
+
+ /**
+ * @return
+ * @throws JAXBException
+ */
+ private Marshaller getMarshaller() throws JAXBException
+ {
+ if (marshaller == null)
+ {
+ JAXBContext jc = JAXBContext.newInstance(Resource.class, TranslationsResource.class);
+ marshaller = jc.createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ }
+ return marshaller;
+ }
+
+ protected String qualifiedDocName(String localDocName)
+ {
+ String qualifiedDocName = modulePrefix + localDocName;
+ return qualifiedDocName;
+ }
+
+ protected String unqualifiedDocName(String qualifiedDocName)
+ {
+ assert qualifiedDocName.startsWith(modulePrefix);
+ return qualifiedDocName.substring(modulePrefix.length());
+ }
+
+ protected boolean belongsToCurrentModule(String qualifiedDocName)
+ {
+ return qualifiedDocName.startsWith(modulePrefix);
+ }
+
+ protected List<String> getQualifiedDocNamesForCurrentModuleFromServer()
+ {
+ List<ResourceMeta> remoteDocList = getDocListForProjectIterationFromServer();
+ List<String> docNames = new ArrayList<String>();
+ for (ResourceMeta doc : remoteDocList)
+ {
+ // NB ResourceMeta.name = HDocument.docId
+ String qualifiedDocName = doc.getName();
+ if (getOpts().getEnableModules())
+ {
+ if (belongsToCurrentModule(qualifiedDocName))
+ {
+ docNames.add(qualifiedDocName);
+ }
+ else
+ {
+ log.debug("found extra-modular document: {}", qualifiedDocName);
+ }
+ }
+ else
+ {
+ docNames.add(qualifiedDocName);
+ }
+ }
+ return docNames;
+ }
+
+ // TODO use a cache which will be accessible to all invocations
+ protected List<ResourceMeta> getDocListForProjectIterationFromServer()
+ {
+ ClientResponse<List<ResourceMeta>> getResponse = translationResources.get(null);
+ ClientUtility.checkResult(getResponse, uri);
+ List<ResourceMeta> remoteDocList = getResponse.getEntity();
+ return remoteDocList;
+ }
+
+}
View
52 client/zanata-client-commands/src/main/java/org/zanata/client/commands/PushPullOptions.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2011, 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;
+
+import java.io.File;
+import java.util.Set;
+
+/**
+ * @author Sean Flanigan <a href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
+ *
+ */
+public interface PushPullOptions extends ConfigurableProjectOptions
+{
+
+ /**
+ * Character or characters which must appear after moduleIDs when constructing qualified document names
+ * @return
+ */
+ String getModuleSuffix();
+
+ /**
+ * A regex for document names, which captures the module ID as group 1 and the unqualified docname as group 2.
+ * This regex should broadly follow the pattern "(moduleID)moduleSuffix(localDocName)".
+ */
+ String getDocNameRegex();
+ boolean isDryRun();
+ File getSrcDir();
+ File getTransDir();
+ boolean getEnableModules();
+ boolean isRootModule();
+ String getCurrentModule();
+ Set<String> getAllModules();
+}
View
152 client/zanata-client-commands/src/main/java/org/zanata/client/commands/pull/PullCommand.java
@@ -1,23 +1,18 @@
package org.zanata.client.commands.pull;
-import java.io.Console;
import java.io.IOException;
-import java.io.StringWriter;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.Response;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
+import org.apache.commons.lang.StringUtils;
import org.jboss.resteasy.client.ClientResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.zanata.client.commands.ConfigurableProjectCommand;
-import org.zanata.client.commands.OptionsUtil;
+import org.zanata.client.commands.PushPullCommand;
import org.zanata.client.config.LocaleList;
import org.zanata.client.config.LocaleMapping;
import org.zanata.client.exceptions.ConfigException;
@@ -27,7 +22,6 @@
import org.zanata.rest.client.ITranslationResources;
import org.zanata.rest.client.ZanataProxyFactory;
import org.zanata.rest.dto.resource.Resource;
-import org.zanata.rest.dto.resource.ResourceMeta;
import org.zanata.rest.dto.resource.TranslationsResource;
/**
@@ -35,7 +29,7 @@
* href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
*
*/
-public class PullCommand extends ConfigurableProjectCommand<PullOptions>
+public class PullCommand extends PushPullCommand<PullOptions>
{
private static final Logger log = LoggerFactory.getLogger(PullCommand.class);
private static final String UTF_8 = "UTF-8";
@@ -50,26 +44,14 @@
strategies.put(PROJECT_TYPE_XML, new XmlStrategy());
}
- Marshaller m = null;
-
- private final ITranslationResources translationResources;
- private final URI uri;
-
- public PullCommand(PullOptions opts, ZanataProxyFactory factory, ITranslationResources translationResources, URI uri)
- {
- super(opts, factory);
- this.translationResources = translationResources;
- this.uri = uri;
- }
-
- private PullCommand(PullOptions opts, ZanataProxyFactory factory)
+ public PullCommand(PullOptions opts)
{
- this(opts, factory, factory.getTranslationResources(opts.getProj(), opts.getProjectVersion()), factory.getTranslationResourcesURI(opts.getProj(), opts.getProjectVersion()));
+ super(opts);
}
- public PullCommand(PullOptions opts)
+ public PullCommand(PullOptions opts, ZanataProxyFactory factory, ITranslationResources translationResources, URI uri)
{
- this(opts, OptionsUtil.createRequestFactory(opts));
+ super(opts, factory, translationResources, uri);
}
private PullStrategy getStrategy(String strategyType)
@@ -83,13 +65,27 @@ private PullStrategy getStrategy(String strategyType)
return strat;
}
- @Override
- public void run() throws Exception
+ private void logOptions()
{
log.info("Server: {}", getOpts().getUrl());
log.info("Project: {}", getOpts().getProj());
log.info("Version: {}", getOpts().getProjectVersion());
log.info("Username: {}", getOpts().getUsername());
+ log.info("Project type: {}", getOpts().getProjectType());
+ log.info("Enable modules: {}", getOpts().getEnableModules());
+ if (getOpts().getEnableModules())
+ {
+ log.info("Current Module: {}", getOpts().getCurrentModule());
+ if (getOpts().isRootModule())
+ {
+ log.info("Root module: YES");
+ if (log.isDebugEnabled())
+ {
+ log.debug("Modules: {}", StringUtils.join(getOpts().getAllModules(), ", "));
+ }
+ }
+ }
+ log.info("Locales to pull: {}", getOpts().getLocales());
if (getOpts().getPullSrc())
{
log.info("Pulling source and target (translation) documents");
@@ -101,51 +97,58 @@ public void run() throws Exception
}
log.info("Target-language base directory (translations): {}", getOpts().getTransDir());
- if (getOpts().getPullSrc())
+ if (getOpts().isDryRun())
{
- log.warn("pullSrc option is set: existing source-language files may be overwritten/deleted");
- confirmWithUser("This will overwrite/delete any existing documents and translations in the above directories.\n");
+ log.info("DRY RUN: no permanent changes will be made");
}
- else
+ }
+
+ @Override
+ public void run() throws Exception
+ {
+ logOptions();
+
+ LocaleList locales = getOpts().getLocales();
+ if (locales == null)
+ throw new ConfigException("no locales specified");
+ PullStrategy strat = getStrategy(getOpts().getProjectType());
+ List<String> docNamesForModule = getQualifiedDocNamesForCurrentModuleFromServer();
+
+ // TODO compare docNamesForModule with localDocNames, offer to delete obsolete translations from filesystem
+ if (docNamesForModule.isEmpty())
{
- confirmWithUser("This will overwrite/delete any existing translations in the above directory.\n");
+ log.info("No documents in remote module: {}; nothing to do", getOpts().getCurrentModule());
+ return;
}
- PullStrategy strat = getStrategy(getOpts().getProjectType());
+ log.info("Pulling {} docs for this module from the server", docNamesForModule.size());
+ log.debug("Doc names: {}", docNamesForModule);
- JAXBContext jc = null;
- if (getOpts().isDebugSet()) // || opts.getValidate())
+ if (getOpts().getPullSrc())
{
- jc = JAXBContext.newInstance(Resource.class, TranslationsResource.class);
+ log.warn("The pullSrc option is set: existing source-language files may be overwritten/deleted");
+ confirmWithUser("This will overwrite/delete any existing documents and translations in the above directories.\n");
}
- if (getOpts().isDebugSet())
+ else
{
- m = jc.createMarshaller();
- m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ confirmWithUser("This will overwrite/delete any existing translations in the above directory.\n");
}
- LocaleList locales = getOpts().getLocales();
- if (locales == null)
- throw new ConfigException("no locales specified");
-
- ClientResponse<List<ResourceMeta>> listResponse = translationResources.get(null);
- ClientUtility.checkResult(listResponse, uri);
- List<ResourceMeta> resourceMetaList = listResponse.getEntity();
- for (ResourceMeta resourceMeta : resourceMetaList)
+ for (String qualifiedDocName : docNamesForModule)
{
Resource doc = null;
- String docName = resourceMeta.getName();
- // TODO follow a Link
- String docUri = RestUtil.convertToDocumentURIId(docName);
+ String localDocName = unqualifiedDocName(qualifiedDocName);
+ // TODO follow a Link instead of generating the URI
+ String docUri = RestUtil.convertToDocumentURIId(qualifiedDocName);
if (strat.needsDocToWriteTrans() || getOpts().getPullSrc())
{
ClientResponse<Resource> resourceResponse = translationResources.getResource(docUri, strat.getExtensions());
ClientUtility.checkResult(resourceResponse, uri);
doc = resourceResponse.getEntity();
+ doc.setName(localDocName);
}
if (getOpts().getPullSrc())
{
- log.info("writing source file for document {}", docName);
- strat.writeSrcFile(doc);
+ writeSrcDoc(strat, doc);
}
for (LocaleMapping locMapping : locales)
@@ -156,54 +159,41 @@ public void run() throws Exception
// ignore 404 (no translation yet for specified document)
if (transResponse.getResponseStatus() == Response.Status.NOT_FOUND)
{
- log.info("no translations found in locale {} for document {}", locale, docName);
+ log.info("No translations found in locale {} for document {}", locale, localDocName);
continue;
}
ClientUtility.checkResult(transResponse, uri);
TranslationsResource targetDoc = transResponse.getEntity();
- log.info("writing translation file in locale {} for document {}", locMapping.getLocalLocale(), docName);
- strat.writeTransFile(doc, docName, locMapping, targetDoc);
+ writeTargetDoc(strat, localDocName, locMapping, doc, targetDoc);
}
}
}
- private void confirmWithUser(String message) throws IOException
+ private void writeSrcDoc(PullStrategy strat, Resource doc) throws IOException
{
- if (getOpts().isInteractiveMode())
+ if (!getOpts().isDryRun())
{
- Console console = System.console();
- if (console == null)
- throw new RuntimeException("console not available: please run Maven from a console, or use batch mode (mvn -B)");
- console.printf(message + "\nAre you sure (y/n)? ");
- expectYes(console);
+ log.info("Writing source file for document {}", doc.getName());
+ strat.writeSrcFile(doc);
+ }
+ else
+ {
+ log.info("Writing source file for document {} (skipped due to dry run)", doc.getName());
}
}
- protected static void expectYes(Console console) throws IOException
- {
- String line = console.readLine();
- if (line == null)
- throw new IOException("console stream closed");
- if (!line.toLowerCase().equals("y") && !line.toLowerCase().equals("yes"))
- throw new RuntimeException("operation aborted by user");
- }
-
- protected void debug(Object jaxbElement)
+ private void writeTargetDoc(PullStrategy strat, String localDocName, LocaleMapping locMapping, Resource doc, TranslationsResource targetDoc) throws IOException
{
- try
+ if (!getOpts().isDryRun())
{
- if (getOpts().isDebugSet())
- {
- StringWriter writer = new StringWriter();
- m.marshal(jaxbElement, writer);
- log.debug("{}", writer);
- }
+ log.info("Writing translation file in locale {} for document {}", locMapping.getLocalLocale(), localDocName);
+ strat.writeTransFile(doc, localDocName, locMapping, targetDoc);
}
- catch (JAXBException e)
+ else
{
- log.debug(e.toString(), e);
+ log.info("Writing translation file in locale {} for document {} (skipped due to dry run)", locMapping.getLocalLocale(), localDocName);
}
}
View
8 client/zanata-client-commands/src/main/java/org/zanata/client/commands/pull/PullOptions.java
@@ -21,17 +21,13 @@
package org.zanata.client.commands.pull;
-import java.io.File;
-
-import org.zanata.client.commands.ConfigurableProjectOptions;
+import org.zanata.client.commands.PushPullOptions;
/**
* @author Sean Flanigan <a href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
*
*/
-public interface PullOptions extends ConfigurableProjectOptions
+public interface PullOptions extends PushPullOptions
{
- File getSrcDir();
- File getTransDir();
boolean getPullSrc();
}
View
9 ...nt/zanata-client-commands/src/main/java/org/zanata/client/commands/pull/PullStrategy.java
@@ -18,14 +18,15 @@
* @param doc
* @throws IOException
*/
- void writeSrcFile(Resource doc) throws IOException;
+ void writeSrcFile(Resource docWithLocalName) throws IOException;
/**
- * @param doc may be null if needsDocToWriteTrans() returns false
- * @param docName
+ * pre: docWithLocalName.getName() must match docName if docWithLocalName is not null
+ * @param docName may be null if needsDocToWriteTrans() returns false
* @param localeMapping
* @param targetDoc
+ * @param localDocName
* @throws IOException
*/
- void writeTransFile(Resource doc, String docName, LocaleMapping localeMapping, TranslationsResource targetDoc) throws IOException;
+ void writeTransFile(Resource docWithLocalName, String docName, LocaleMapping localeMapping, TranslationsResource targetDoc) throws IOException;
}
View
331 client/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushCommand.java
@@ -1,24 +1,23 @@
package org.zanata.client.commands.push;
-import java.io.Console;
import java.io.File;
import java.io.IOException;
-import java.io.StringWriter;
import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-
+import org.apache.commons.lang.StringUtils;
import org.jboss.resteasy.client.ClientResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.zanata.client.commands.ConfigurableProjectCommand;
-import org.zanata.client.commands.OptionsUtil;
+import org.zanata.client.commands.PushPullCommand;
import org.zanata.client.config.LocaleMapping;
import org.zanata.client.exceptions.ConfigException;
import org.zanata.common.LocaleId;
@@ -36,7 +35,7 @@
* href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
*
*/
-public class PushCommand extends ConfigurableProjectCommand<PushOptions>
+public class PushCommand extends PushPullCommand<PushOptions>
{
private static final Logger log = LoggerFactory.getLogger(PushCommand.class);
private static final String UTF_8 = "UTF-8";
@@ -56,26 +55,14 @@
strategies.put(PROJECT_TYPE_XML, new XmlStrategy());
}
- Marshaller m = null;
-
- private final ITranslationResources translationResources;
- private final URI uri;
-
- public PushCommand(PushOptions opts, ZanataProxyFactory factory, ITranslationResources translationResources, URI uri)
- {
- super(opts, factory);
- this.translationResources = translationResources;
- this.uri = uri;
- }
-
- private PushCommand(PushOptions opts, ZanataProxyFactory factory)
+ public PushCommand(PushOptions opts)
{
- this(opts, factory, factory.getTranslationResources(opts.getProj(), opts.getProjectVersion()), factory.getTranslationResourcesURI(opts.getProj(), opts.getProjectVersion()));
+ super(opts);
}
- public PushCommand(PushOptions opts)
+ public PushCommand(PushOptions opts, ZanataProxyFactory factory, ITranslationResources translationResources, URI uri)
{
- this(opts, OptionsUtil.createRequestFactory(opts));
+ super(opts, factory, translationResources, uri);
}
private AbstractPushStrategy getStrategy(String strategyType)
@@ -89,9 +76,12 @@ private AbstractPushStrategy getStrategy(String strategyType)
return strat;
}
- @Override
- public void run() throws Exception
+ private void logOptions()
{
+ if (!log.isInfoEnabled())
+ {
+ return;
+ }
log.info("Server: {}", getOpts().getUrl());
log.info("Project: {}", getOpts().getProj());
log.info("Version: {}", getOpts().getProjectVersion());
@@ -100,33 +90,27 @@ public void run() throws Exception
log.info("Source language: {}", getOpts().getSourceLang());
log.info("Copy previous translations: {}", getOpts().getCopyTrans());
log.info("Merge type: {}", getOpts().getMergeType());
-
- if (!getOpts().getIncludes().isEmpty())
+ log.info("Enable modules: {}", getOpts().getEnableModules());
+ if (getOpts().getEnableModules())
{
- StringBuilder sb = new StringBuilder();
- for (String pattern : getOpts().getIncludes())
+ log.info("Current module: {}", getOpts().getCurrentModule());
+ if (getOpts().isRootModule())
{
- sb.append(pattern);
- sb.append(" ");
- }
- log.info("Include patterns: {}", sb.toString());
- }
-
- if (!getOpts().getExcludes().isEmpty())
- {
- StringBuilder sb = new StringBuilder();
- for(String pattern:getOpts().getExcludes())
- {
- sb.append(pattern);
- sb.append(" ");
+ log.info("Root module: YES");
+ if (log.isDebugEnabled())
+ {
+ log.debug("Modules: {}", StringUtils.join(getOpts().getAllModules(), ", "));
+ }
}
- log.info("Exclude patterns: {}", sb.toString());
}
- log.info("Default exclude: {}", getOpts().getDefaultExcludes());
+ log.info("Include patterns: {}", StringUtils.join(getOpts().getIncludes(), " "));
+ log.info("Exclude patterns: {}", StringUtils.join(getOpts().getExcludes(), " "));
+ log.info("Default excludes: {}", getOpts().getDefaultExcludes());
if (getOpts().getPushTrans())
{
log.info("Pushing source and target documents");
+ log.info("Locales to push: {}", getOpts().getLocales());
}
else
{
@@ -137,144 +121,237 @@ public void run() throws Exception
{
log.info("Target base directory (translations): {}", getOpts().getTransDir());
}
- File sourceDir = getOpts().getSrcDir();
+ if (getOpts().isDryRun())
+ {
+ log.info("DRY RUN: no permanent changes will be made");
+ }
+ }
- if (!sourceDir.exists())
+ @Override
+ public void run() throws Exception
+ {
+ logOptions();
+ pushCurrentModule();
+
+ if (getOpts().getEnableModules() && getOpts().isRootModule())
{
- throw new RuntimeException("directory '" + sourceDir + "' does not exist - check sourceDir option");
+ List<String> obsoleteDocs = getObsoleteDocNamesForProjectIterationFromServer();
+ log.info("found {} docs in obsolete modules (or no module): {}", obsoleteDocs.size(), obsoleteDocs);
+ if (getOpts().getDeleteObsoleteModules() && !obsoleteDocs.isEmpty())
+ {
+ // offer to delete obsolete documents
+ confirmWithUser("Do you want to delete all documents from the server which don't belong to any module in the Maven reactor?\n");
+ deleteDocsFromServer(obsoleteDocs);
+ }
+ else
+ {
+ log.warn("found {} docs in obsolete modules (or no module). use -Dzanata.deleteObsoleteModules to delete them", obsoleteDocs.size());
+ }
}
+ }
- if (getOpts().getPushTrans())
+ /**
+ * gets doc list from server,
+ * returns a list of qualified doc names from obsolete modules, or from no module.
+ */
+ protected List<String> getObsoleteDocNamesForProjectIterationFromServer()
+ {
+ if (!getOpts().getEnableModules())
+ return Collections.emptyList();
+ List<ResourceMeta> remoteDocList = getDocListForProjectIterationFromServer();
+
+ Pattern p = Pattern.compile(getOpts().getDocNameRegex());
+ Set<String> modules = new HashSet<String>(getOpts().getAllModules());
+
+ List<String> obsoleteDocs = new ArrayList<String>();
+ for (ResourceMeta doc : remoteDocList)
{
- 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/delete any existing documents AND TRANSLATIONS on the server.\n");
+ // NB ResourceMeta.name == HDocument.docId
+ String docName = doc.getName();
+
+ Matcher matcher = p.matcher(docName);
+ if (matcher.matches())
+ {
+ String module = matcher.group(1);
+ if (modules.contains(module))
+ {
+ log.debug("doc {} belongs to non-obsolete module {}", docName, module);
+ }
+ else
+ {
+ obsoleteDocs.add(docName);
+ log.info("doc {} belongs to obsolete module {}", docName, module);
+ }
+ }
+ else
+ {
+ obsoleteDocs.add(docName);
+ log.warn("doc {} doesn't belong to any module", docName);
+ }
}
- else
+ return obsoleteDocs;
+ }
+
+ private void pushCurrentModule() throws IOException
+ {
+ File sourceDir = getOpts().getSrcDir();
+
+ if (!sourceDir.exists())
{
- confirmWithUser("This will overwrite/delete any existing documents on the server.\n");
+ if (getOpts().getEnableModules())
+ {
+ log.info("source directory '" + sourceDir + "' not found; skipping docs push for module " + getOpts().getCurrentModule());
+ return;
+ }
+ else
+ {
+ throw new RuntimeException("directory '" + sourceDir + "' does not exist - check srcDir option");
+ }
}
AbstractPushStrategy strat = getStrategy(getOpts().getProjectType());
+ final StringSet extensions = strat.getExtensions();
- JAXBContext jc = null;
- if (getOpts().isDebugSet()) // || opts.getValidate())
+ // to save memory, we don't load all the docs into a HashMap
+ Set<String> localDocNames = strat.findDocNames(sourceDir, getOpts().getIncludes(), getOpts().getExcludes(), getOpts().getDefaultExcludes());
+ for (String docName : localDocNames)
{
- jc = JAXBContext.newInstance(Resource.class, TranslationsResource.class);
+ log.info("Found source document: {}", docName);
}
- if (getOpts().isDebugSet())
+ List<String> obsoleteDocs = getObsoleteDocsInModuleFromServer(localDocNames);
+ if (obsoleteDocs.isEmpty())
{
- m = jc.createMarshaller();
- m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ if (localDocNames.isEmpty())
+ {
+ log.info("no documents in module: {}; nothing to do", getOpts().getCurrentModule());
+ return;
+ }
+ else
+ {
+ // nop
+ }
+ }
+ else
+ {
+ log.warn("Found {} obsolete docs on the server which will be DELETED", obsoleteDocs.size());
+ log.info("Obsolete docs: {}", obsoleteDocs);
}
- // NB we don't load all the docs into a HashMap, because that would waste
- // memory
-
- Set<String> localDocNames = strat.findDocNames(sourceDir, getOpts().getIncludes(), getOpts().getExcludes(), getOpts().getDefaultExcludes());
- for (String docName : localDocNames)
+ if (getOpts().getPushTrans())
{
- log.info("Source file to be uploaded: {}", docName);
+ 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");
+ }
+ else
+ {
+ confirmWithUser("This will overwrite existing documents on the server, and delete obsolete documents.\n");
}
- deleteObsoleteDocsFromServer(localDocNames);
- for (String docName : localDocNames)
+ for (String localDocName : localDocNames)
{
- final String docUri = RestUtil.convertToDocumentURIId(docName);
- final Resource srcDoc = strat.loadSrcDoc(sourceDir, docName);
+ final Resource srcDoc = strat.loadSrcDoc(sourceDir, localDocName);
+ String qualifiedDocName = qualifiedDocName(localDocName);
+ final String docUri = RestUtil.convertToDocumentURIId(qualifiedDocName);
+ srcDoc.setName(qualifiedDocName);
debug(srcDoc);
- // if (opts.getValidate())
- // {
- // JaxbUtil.validateXml(srcDoc, jc);
- // }
- final StringSet extensions = strat.getExtensions();
- log.info("pushing source document [name={}] to server", srcDoc.getName());
- boolean copyTrans = getOpts().getCopyTrans();
- ClientResponse<String> putResponse = translationResources.putResource(docUri, srcDoc, extensions, copyTrans);
- ClientUtility.checkResult(putResponse, uri);
+ pushSrcDocToServer(docUri, srcDoc, extensions);
if (getOpts().getPushTrans())
{
- strat.visitTranslationResources(docName, srcDoc, new TranslationResourcesVisitor()
+ strat.visitTranslationResources(localDocName, srcDoc, new TranslationResourcesVisitor()
{
@Override
public void visit(LocaleMapping locale, TranslationsResource targetDoc)
{
debug(targetDoc);
- // if (opts.getValidate())
- // {
- // JaxbUtil.validateXml(targetDoc, jc);
- // }
- log.info("pushing target document [name={} client-locale={}] to server [locale={}]", new Object[] { srcDoc.getName(), locale.getLocalLocale(), locale.getLocale() });
- ClientResponse<String> putTransResponse = translationResources.putTranslations(docUri, new LocaleId(locale.getLocale()), targetDoc, extensions, getOpts().getMergeType());
- ClientUtility.checkResult(putTransResponse, uri);
- String entity = putTransResponse.getEntity(String.class);
- if (entity != null && !entity.isEmpty())
- {
- log.warn("{}", entity);
- }
+ pushTargetDocToServer(docUri, locale, srcDoc, targetDoc, extensions);
}
});
}
}
+ deleteDocsFromServer(obsoleteDocs);
}
- protected void deleteObsoleteDocsFromServer(Set<String> localDocNames)
+ /**
+ * Returns obsolete docs which belong to the current module.
+ * Returns any docs in the current module from the server, unless they are found in the localDocNames set.
+ * @param localDocNames
+ */
+ private List<String> getObsoleteDocsInModuleFromServer(Set<String> localDocNames)
{
- ClientResponse<List<ResourceMeta>> getResponse = translationResources.get(null);
- ClientUtility.checkResult(getResponse, uri);
- List<ResourceMeta> remoteDocList = getResponse.getEntity();
- for (ResourceMeta doc : remoteDocList)
+ List<String> qualifiedDocNames = getQualifiedDocNamesForCurrentModuleFromServer();
+ List<String> obsoleteDocs = new ArrayList<String>(qualifiedDocNames.size());
+ for (String qualifiedDocName : qualifiedDocNames)
{
- // NB ResourceMeta.name = HDocument.docId
- String docName = doc.getName();
- String docUri = RestUtil.convertToDocumentURIId(docName);
- if (!localDocNames.contains(docName))
+ String unqualifiedDocName = unqualifiedDocName(qualifiedDocName);
+ if (!localDocNames.contains(unqualifiedDocName))
{
- log.info("deleting resource {} from server", docName);
- ClientResponse<String> deleteResponse = translationResources.deleteResource(docUri);
- ClientUtility.checkResult(deleteResponse, uri);
+ obsoleteDocs.add(qualifiedDocName);
}
}
+ return obsoleteDocs;
}
- private void confirmWithUser(String message) throws IOException
+ /**
+ * @param qualifiedDocNames
+ */
+ private void deleteDocsFromServer(List<String> qualifiedDocNames)
{
- if (getOpts().isInteractiveMode())
+ for (String qualifiedDocName : qualifiedDocNames)
{
- Console console = System.console();
- if (console == null)
- throw new RuntimeException("console not available: please run Maven from a console, or use batch mode (mvn -B)");
- console.printf(message + "\nAre you sure (y/n)? ");
- expectYes(console);
+ deleteDocFromServer(qualifiedDocName);
}
}
- protected static void expectYes(Console console) throws IOException
+ private void pushSrcDocToServer(final String docUri, final Resource srcDoc, final StringSet extensions)
{
- String line = console.readLine();
- if (line == null)
- throw new IOException("console stream closed");
- if (!line.toLowerCase().equals("y") && !line.toLowerCase().equals("yes"))
- throw new RuntimeException("operation aborted by user");
+ if (!getOpts().isDryRun())
+ {
+ log.info("pushing source document [name={}] to server", srcDoc.getName());
+ boolean copyTrans = getOpts().getCopyTrans();
+ ClientResponse<String> putResponse = translationResources.putResource(docUri, srcDoc, extensions, copyTrans);
+ ClientUtility.checkResult(putResponse, uri);
+ }
+ else
+ {
+ log.info("pushing source document [name={}] to server (skipped due to dry run)", srcDoc.getName());
+ }
}
- protected void debug(Object jaxbElement)
+ private void pushTargetDocToServer(final String docUri, LocaleMapping locale, final Resource srcDoc, TranslationsResource targetDoc, final StringSet extensions)
{
- try
+ if (!getOpts().isDryRun())
{
- if (getOpts().isDebugSet())
+ log.info("pushing target document [name={} client-locale={}] to server [locale={}]", new Object[] { srcDoc.getName(), locale.getLocalLocale(), locale.getLocale() });
+ ClientResponse<String> putTransResponse = translationResources.putTranslations(docUri, new LocaleId(locale.getLocale()), targetDoc, extensions, getOpts().getMergeType());
+ ClientUtility.checkResult(putTransResponse, uri);
+ String entity = putTransResponse.getEntity(String.class);
+ if (entity != null && !entity.isEmpty())
{
- StringWriter writer = new StringWriter();
- m.marshal(jaxbElement, writer);
- log.debug("{}", writer);
+ log.warn("{}", entity);
}
}
- catch (JAXBException e)
+ else
+ {
+ log.info("pushing target document [name={} client-locale={}] to server [locale={}] (skipped due to dry run)", new Object[] { srcDoc.getName(), locale.getLocalLocale(), locale.getLocale() });
+ }
+ }
+
+ private void deleteDocFromServer(String qualifiedDocName)
+ {
+ if (!getOpts().isDryRun())
+ {
+ log.info("deleting resource {} from server", qualifiedDocName);
+ String docUri = RestUtil.convertToDocumentURIId(qualifiedDocName);
+ ClientResponse<String> deleteResponse = translationResources.deleteResource(docUri);
+ ClientUtility.checkResult(deleteResponse, uri);
+ }
+ else
{
- log.debug(e.toString(), e);
+ log.info("deleting resource {} from server (skipped due to dry run)", qualifiedDocName);
}
}
View
8 client/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushOptions.java
@@ -1,15 +1,12 @@
package org.zanata.client.commands.push;
-import java.io.File;
import java.util.List;
-import org.zanata.client.commands.ConfigurableProjectOptions;
+import org.zanata.client.commands.PushPullOptions;
-public interface PushOptions extends ConfigurableProjectOptions
+public interface PushOptions extends PushPullOptions
{
public String getSourceLang();
- public File getSrcDir();
- public File getTransDir();
public boolean getPushTrans();
public boolean getCopyTrans();
public boolean getUseSrcOrder();
@@ -18,5 +15,6 @@
public List<String> getIncludes();
public List<String> getExcludes();
public boolean getDefaultExcludes();
+ public boolean getDeleteObsoleteModules();
}
View
23 client/zanata-client-commands/src/main/java/org/zanata/client/config/LocaleList.java
@@ -9,21 +9,34 @@
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
-import org.zanata.rest.dto.DTOUtil;
-
@XmlRootElement(name = "locales")
@XmlType(name = "localesType")
public class LocaleList implements List<LocaleMapping>
{
- // private String mapping;
-
private final List<LocaleMapping> locales = new ArrayList<LocaleMapping>();
@Override
public String toString()
{
- return DTOUtil.toXML(this);
+ StringBuilder sb = new StringBuilder();
+ sb.append('[');
+ for (Iterator<LocaleMapping> iter = locales.iterator(); iter.hasNext();)
+ {
+ LocaleMapping loc = iter.next();
+ sb.append(loc.getLocale());
+ String localLocale = loc.getLocalLocale();
+ if (!localLocale.equals(loc.getLocale()))
+ {
+ sb.append('(');
+ sb.append(localLocale);
+ sb.append(')');
+ }
+ if (iter.hasNext())
+ sb.append(", ");
+ }
+ sb.append(']');
+ return sb.toString();
}
/**
View
4 client/zanata-client-commands/src/test/java/org/zanata/client/commands/DummyResponse.java
@@ -15,12 +15,12 @@
*
* @param <T>
*/
-class DummyResponse<T> extends ClientResponse<T>
+public class DummyResponse<T> extends ClientResponse<T>
{
private final Status status;
private final T entity;
- protected DummyResponse(Status status, T entity)
+ public DummyResponse(Status status, T entity)
{
this.status = status;
this.entity = entity;
View
2 ...ata-client-commands/src/test/java/org/zanata/client/commands/PublicanPullCommandTest.java
@@ -70,7 +70,7 @@ private void publicanPull(boolean exportPot, boolean mapLocale) throws Exception
opts.setProjectVersion(versionSlug);
opts.setDstDir(new File("target/test-output/test2"));
opts.setExportPot(exportPot);
- opts.setProjectConfig("src/test/resources/test2/zanata.xml");
+ opts.setProjectConfig(new File("src/test/resources/test2/zanata.xml"));
OptionsUtil.applyConfigFiles(opts);
if (mapLocale)
{
View
129 ...zanata-client-commands/src/test/java/org/zanata/client/commands/push/PushCommandTest.java
@@ -0,0 +1,129 @@
+package org.zanata.client.commands.push;
+
+import static org.easymock.EasyMock.*;
+
+import java.io.File;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.ws.rs.core.Response.Status;
+
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+import org.jboss.resteasy.client.ClientResponse;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import org.zanata.client.commands.ConfigurableProjectCommand;
+import org.zanata.client.commands.DummyResponse;
+import org.zanata.client.commands.OptionsUtil;
+import org.zanata.client.commands.ZanataCommand;
+import org.zanata.client.config.LocaleList;
+import org.zanata.client.config.LocaleMapping;
+import org.zanata.common.LocaleId;
+import org.zanata.rest.StringSet;
+import org.zanata.rest.client.ITranslationResources;
+import org.zanata.rest.client.ZanataProxyFactory;
+import org.zanata.rest.dto.resource.Resource;
+import org.zanata.rest.dto.resource.ResourceMeta;
+import org.zanata.rest.dto.resource.TranslationsResource;
+
+@Test(groups = "unit-tests")
+public class PushCommandTest
+{
+ IMocksControl control = EasyMock.createControl();
+ ITranslationResources mockTranslationResources = createMock("mockTranslationResources", ITranslationResources.class);
+
+ public PushCommandTest() throws Exception
+ {
+ }
+
+ @Test
+ public void pushSrc() throws Exception
+ {
+ push(false, false);
+ }
+
+ @Test
+ public void pushSrcAndTarget() throws Exception
+ {
+ push(true, false);
+ }
+
+ @Test
+ public void pushSrcAndTargetWithLocaleMapping() throws Exception
+ {
+ push(true, true);
+ }
+
+ @BeforeMethod
+ void beforeMethod()
+ {
+ control.reset();
+ }
+
+ <T> T createMock(String name, Class<T> toMock)
+ {
+ T mock = control.createMock(name, toMock);
+ return mock;
+ }
+
+ private void push(boolean pushTrans, boolean mapLocale) throws Exception
+ {
+ PushOptionsImpl opts = new PushOptionsImpl();
+ opts.setInteractiveMode(false);
+ String projectSlug = "project";
+ opts.setProj(projectSlug);
+ String versionSlug = "1.0";
+ opts.setProjectVersion(versionSlug);
+ opts.setSrcDir(new File("src/test/resources/test1/pot"));
+ opts.setPushTrans(pushTrans);
+ opts.transDir = new File("src/test/resources/test1");
+ opts.setProjectType("podir");
+ opts.copyTrans = true;
+ opts.includes = new ArrayList<String>();
+ opts.excludes = new ArrayList<String>();
+ opts.sourceLang = "en-US";
+ opts.mergeType = "auto";
+ OptionsUtil.applyConfigFiles(opts);
+ LocaleList locales = new LocaleList();
+ if (mapLocale)
+ {
+ locales.add(new LocaleMapping("ja", "ja-JP"));
+ }
+ else
+ {
+ locales.add(new LocaleMapping("ja-JP"));
+ }
+ opts.setLocales(locales);
+
+ List<ResourceMeta> resourceMetaList = new ArrayList<ResourceMeta>();
+ resourceMetaList.add(new ResourceMeta("obsolete"));
+ resourceMetaList.add(new ResourceMeta("RPM"));
+ EasyMock.expect(mockTranslationResources.get(null)).andReturn(new DummyResponse<List<ResourceMeta>>(Status.OK, resourceMetaList));
+
+ final ClientResponse<String> okResponse = new DummyResponse<String>(Status.OK, null);
+ EasyMock.expect(mockTranslationResources.deleteResource("obsolete")).andReturn(okResponse);
+ StringSet extensionSet = new StringSet("gettext;comment");
+ EasyMock.expect(mockTranslationResources.putResource(eq("RPM"), (Resource) notNull(), eq(extensionSet), eq(true))).andReturn(okResponse);
+ EasyMock.expect(mockTranslationResources.putResource(eq("sub,RPM"), (Resource) notNull(), eq(extensionSet), eq(true))).andReturn(okResponse);
+
+ if (pushTrans)
+ {
+ LocaleId expectedLocale;
+ if (mapLocale)
+ expectedLocale = new LocaleId("ja");
+ else
+ expectedLocale = new LocaleId("ja-JP");
+ EasyMock.expect(mockTranslationResources.putTranslations(eq("RPM"), eq(expectedLocale), (TranslationsResource) notNull(), eq(extensionSet), eq("auto"))).andReturn(okResponse);
+ }
+ ZanataProxyFactory mockRequestFactory = EasyMock.createNiceMock(ZanataProxyFactory.class);
+
+ control.replay();
+ ZanataCommand cmd = new PushCommand(opts, mockRequestFactory, mockTranslationResources, new URI("http://example.com/"));
+ cmd.run();
+ control.verify();
+ }
+
+}
View
197 ...zanata-client-commands/src/test/java/org/zanata/client/commands/push/PushOptionsImpl.java
@@ -0,0 +1,197 @@
+/*
+ * Copyright 2011, 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;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.zanata.client.commands.ConfigurableProjectOptionsImpl;
+import org.zanata.client.commands.ZanataCommand;
+
+/**
+ * @author Sean Flanigan <a href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
+ *
+ */
+class PushOptionsImpl extends ConfigurableProjectOptionsImpl implements PushOptions
+{
+
+ List<String> includes;
+ List<String> excludes;
+ boolean defaultExcludes;
+ String mergeType;
+ boolean useSrcOrder;
+ boolean copyTrans;
+ boolean pushTrans;
+ File transDir;
+ File srcDir;
+ String sourceLang;
+
+ @Override
+ public ZanataCommand initCommand()
+ {
+ return new PushCommand(this);
+ }
+
+ @Override
+ public String getCommandName()
+ {
+ return "push";
+ }
+
+ @Override
+ public String getCommandDescription()
+ {
+ return "Pushes source text to a Zanata project version so that it can be translated.";
+ }
+
+ @Override
+ public String getSourceLang()
+ {
+ return sourceLang;
+ }
+
+ @Override
+ public File getSrcDir()
+ {
+ return srcDir;
+ }
+
+ @Override
+ public File getTransDir()
+ {
+ return transDir;
+ }
+
+ @Override
+ public boolean getPushTrans()
+ {
+ return pushTrans;
+ }
+
+ @Override
+ public boolean getCopyTrans()
+ {
+ return copyTrans;
+ }
+
+ @Override
+ public boolean getUseSrcOrder()
+ {
+ return useSrcOrder;
+ }
+
+ @Override
+ public String getMergeType()
+ {
+ return mergeType;
+ }
+
+ @Override
+ public List<String> getIncludes()
+ {
+ return includes;
+ }
+
+ @Override
+ public List<String> getExcludes()
+ {
+ return excludes;
+ }
+
+ @Override
+ public boolean getDefaultExcludes()
+ {
+ return defaultExcludes;
+ }
+
+ /**
+ * @param file
+ */
+ public void setSrcDir(File file)
+ {
+ this.srcDir = file;
+ }
+
+ /**
+ * @param pushTrans the pushTrans to set
+ */
+ public void setPushTrans(boolean pushTrans)
+ {
+ this.pushTrans = pushTrans;
+ }
+
+ @Override
+ public boolean getEnableModules()
+ {
+ // modules are currently only supported by Maven Mojos:
+ return false;
+ }
+
+ @Override
+ public boolean isDryRun()
+ {
+ // not supported yet
+ return false;
+ }
+
+ @Override
+ public boolean isRootModule()
+ {
+ return false;
+ }
+
+ @Override
+ public String getCurrentModule()
+ {
+ return "";
+ }
+