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
check for potential wrong src dir in podir project
  • Loading branch information
Patrick Huang committed Aug 21, 2014
1 parent 8e05950 commit 31319e5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Expand Up @@ -47,6 +47,13 @@ public abstract class AbstractGettextPushStrategy extends AbstractPushStrategy {
public AbstractGettextPushStrategy() {
super(new StringSet("comment;gettext"), ".pot");
}
/**
* check for podir project type and source file start with pot/ could
* potentially be wrong.
*/
protected void checkSrcFileNames(String projectType, String[] srcFiles,
boolean isInteractive) {
}

public Set<String> findDocNames(File srcDir, ImmutableList<String> includes,
ImmutableList<String> excludes, boolean useDefaultExclude,
Expand All @@ -64,6 +71,8 @@ public Set<String> findDocNames(File srcDir, ImmutableList<String> includes,
String docName = removeExtension(potName);
localDocNames.add(docName);
}
checkSrcFileNames(getOpts().getProjectType(), srcFiles,
getOpts().isInteractiveMode());
return localDocNames;
}

Expand Down
Expand Up @@ -26,6 +26,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zanata.client.commands.InteractiveableFromConsole;
import org.zanata.client.commands.gettext.PublicanUtil;
import org.zanata.client.config.LocaleMapping;

Expand Down Expand Up @@ -57,6 +58,39 @@ List<LocaleMapping> findLocales() {
return locales;
}

@Override
protected void checkSrcFileNames(String projectType, String[] srcFiles,
boolean isInteractive) {

boolean potentialProblem = checkForPotPrefix(srcFiles);
if (potentialProblem) {
String warningMsg =
"Found source file path starting with pot, perhaps you want to set source directory to pot?";
InteractiveableFromConsole console =
new InteractiveableFromConsole();
log.warn(warningMsg);
if (isInteractive) {
console.printfln(warningMsg);
console.printf(
"Are you sure source directory [%s] is correct (y/n)?",
getOpts().getSrcDir());
console.expectYes();
}
}
}

private boolean checkForPotPrefix(String[] srcFiles) {
for (String src : srcFiles) {
boolean potentialProblem =
new File(src).getPath()
.startsWith("pot" + File.separator);
if (potentialProblem) {
return true;
}
}
return false;
}

@Override
File getTransFile(LocaleMapping locale, String docName) {
File localeDir =
Expand All @@ -65,4 +99,6 @@ File getTransFile(LocaleMapping locale, String docName) {
return transFile;
}



}

0 comments on commit 31319e5

Please sign in to comment.