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

Commit

Permalink
Merge branch 'master' of github.com:zanata/zanata
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesni committed Aug 9, 2011
2 parents c52e143 + f3a57b9 commit fc465b1
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract class AbstractPushStrategy
private StringSet extensions;
private String fileExtension;

public abstract Set<String> findDocNames(File srcDir, List<String> includes, List<String> excludes) throws IOException;
public abstract Set<String> findDocNames(File srcDir, List<String> includes, List<String> excludes, boolean includeDefaultExclude) throws IOException;

public abstract Resource loadSrcDoc(File sourceDir, String docName) throws IOException;

Expand All @@ -54,7 +54,7 @@ public AbstractPushStrategy(StringSet extensions, String fileExtension)
this.fileExtension = fileExtension;
}

public String[] getSrcFiles(File srcDir, List<String> includes, List<String> excludes, boolean excludeLocalFileName)
public String[] getSrcFiles(File srcDir, List<String> includes, List<String> excludes, boolean excludeLocalFileName, boolean includeDefaultExclude)
{
includes.add("**/*" + fileExtension);
if (excludeLocalFileName)
Expand All @@ -63,6 +63,12 @@ public String[] getSrcFiles(File srcDir, List<String> includes, List<String> exc
}

DirectoryScanner dirScanner = new DirectoryScanner();

if (includeDefaultExclude)
{
dirScanner.addDefaultExcludes();
}

dirScanner.setBasedir(srcDir);
dirScanner.setCaseSensitive(false);
dirScanner.setExcludes((String[]) excludes.toArray(new String[excludes.size()]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public GettextDirStrategy()
super(new StringSet("comment;gettext"), ".pot");
}

public Set<String> findDocNames(File srcDir, List<String> includes, List<String> excludes) throws IOException
public Set<String> findDocNames(File srcDir, List<String> includes, List<String> excludes, boolean includeDefaultExclude) throws IOException
{
Set<String> localDocNames = new HashSet<String>();

// populate localDocNames by looking in pot directory
String[] srcFiles = getSrcFiles(srcDir, includes, excludes, false);
String[] srcFiles = getSrcFiles(srcDir, includes, excludes, false, includeDefaultExclude);

for (String potName : srcFiles)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public PropertiesStrategy()
}

@Override
public Set<String> findDocNames(File srcDir, List<String> includes, List<String> excludes) throws IOException
public Set<String> findDocNames(File srcDir, List<String> includes, List<String> excludes, boolean includeDefaultExclude) throws IOException
{
Set<String> localDocNames = new HashSet<String>();

String[] files = getSrcFiles(srcDir, includes, excludes, true);
String[] files = getSrcFiles(srcDir, includes, excludes, true, includeDefaultExclude);

for (String relativeFilePath : files)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void run() throws Exception
// NB we don't load all the docs into a HashMap, because that would waste
// memory

Set<String> localDocNames = strat.findDocNames(sourceDir, opts.getIncludes(), opts.getExcludes());
Set<String> localDocNames = strat.findDocNames(sourceDir, opts.getIncludes(), opts.getExcludes(), opts.getDefaultexclude());
for (String docName : localDocNames)
{
log.info("Source file to be uploaded: {}", docName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public XliffStrategy()
}

@Override
public Set<String> findDocNames(File srcDir, List<String> includes, List<String> excludes) throws IOException
public Set<String> findDocNames(File srcDir, List<String> includes, List<String> excludes, boolean includeDefaultExclude) throws IOException
{
sourceFiles = new HashSet<String>();
Set<String> localDocNames = new HashSet<String>();

String[] files = getSrcFiles(srcDir, includes, excludes, true);
String[] files = getSrcFiles(srcDir, includes, excludes, true, includeDefaultExclude);

for (String relativeFilePath : files)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public XmlStrategy()
}

@Override
public Set<String> findDocNames(File srcDir, List<String> includes, List<String> excludes) throws IOException
public Set<String> findDocNames(File srcDir, List<String> includes, List<String> excludes, boolean includeDefaultExclude) throws IOException
{
Set<String> localDocNames = new HashSet<String>();

String[] files = getSrcFiles(srcDir, includes, excludes, true);
String[] files = getSrcFiles(srcDir, includes, excludes, true, includeDefaultExclude);

for (String relativeFilePath : files)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ public void findDocNamesTest() throws IOException
// EasyMock.expect(mockPushOption.getIncludes()).andReturn(include);
EasyMock.expect(mockPushOption.getLocales()).andReturn(locales).anyTimes();
EasyMock.expect(mockPushOption.getSourceLang()).andReturn("en-US").anyTimes();
EasyMock.expect(mockPushOption.getDefaultexclude()).andReturn(true).anyTimes();

xliffStrategy.setPushOptions(mockPushOption);
EasyMock.replay(mockPushOption);

Set<String> localDocNames = xliffStrategy.findDocNames(sourceDir, include, new ArrayList<String>());
Set<String> localDocNames = xliffStrategy.findDocNames(sourceDir, include, new ArrayList<String>(), mockPushOption.getDefaultexclude());

control.verify();
for (String docName : localDocNames)
Expand All @@ -88,11 +89,12 @@ public void loadSrcDocTest() throws IOException
EasyMock.expect(mockPushOption.getTransDir()).andReturn(sourceDir).anyTimes();
EasyMock.expect(mockPushOption.getLocales()).andReturn(locales).anyTimes();
EasyMock.expect(mockPushOption.getSourceLang()).andReturn("en-US").anyTimes();
EasyMock.expect(mockPushOption.getDefaultexclude()).andReturn(true).anyTimes();

xliffStrategy.setPushOptions(mockPushOption);
EasyMock.replay(mockPushOption);

Set<String> localDocNames = xliffStrategy.findDocNames(sourceDir, include, new ArrayList<String>());
Set<String> localDocNames = xliffStrategy.findDocNames(sourceDir, include, new ArrayList<String>(), mockPushOption.getDefaultexclude());
List<Resource> resourceList = new ArrayList<Resource>();
for (String docName : localDocNames)
{
Expand Down Expand Up @@ -134,6 +136,7 @@ public void loadSrcDocTestWithExcludeFileOption() throws IOException
EasyMock.expect(mockPushOption.getTransDir()).andReturn(sourceDir).anyTimes();
EasyMock.expect(mockPushOption.getLocales()).andReturn(locales).anyTimes();
EasyMock.expect(mockPushOption.getSourceLang()).andReturn("en-US").anyTimes();
EasyMock.expect(mockPushOption.getDefaultexclude()).andReturn(true).anyTimes();

List<String> exclude = new ArrayList<String>();
exclude.add("**/*StringResource*");
Expand All @@ -142,7 +145,7 @@ public void loadSrcDocTestWithExcludeFileOption() throws IOException
xliffStrategy.setPushOptions(mockPushOption);
EasyMock.replay(mockPushOption);

Set<String> localDocNames = xliffStrategy.findDocNames(sourceDir, include, exclude);
Set<String> localDocNames = xliffStrategy.findDocNames(sourceDir, include, exclude, mockPushOption.getDefaultexclude());
List<Resource> resourceList = new ArrayList<Resource>();
for (String docName : localDocNames)
{
Expand Down Expand Up @@ -184,6 +187,7 @@ public void loadSrcDocTestWithExcludeOption() throws IOException
EasyMock.expect(mockPushOption.getTransDir()).andReturn(sourceDir).anyTimes();
EasyMock.expect(mockPushOption.getLocales()).andReturn(locales).anyTimes();
EasyMock.expect(mockPushOption.getSourceLang()).andReturn("en-US").anyTimes();
EasyMock.expect(mockPushOption.getDefaultexclude()).andReturn(true).anyTimes();

List<String> exclude = new ArrayList<String>();
exclude.add("**/dir2/*");
Expand All @@ -192,7 +196,7 @@ public void loadSrcDocTestWithExcludeOption() throws IOException
xliffStrategy.setPushOptions(mockPushOption);
EasyMock.replay(mockPushOption);

Set<String> localDocNames = xliffStrategy.findDocNames(sourceDir, include, exclude);
Set<String> localDocNames = xliffStrategy.findDocNames(sourceDir, include, exclude, mockPushOption.getDefaultexclude());
List<Resource> resourceList = new ArrayList<Resource>();
for (String docName : localDocNames)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.tools.ant.DirectoryScanner;
import org.zanata.client.commands.push.PushCommand;
import org.zanata.client.commands.push.PushOptions;

Expand Down Expand Up @@ -181,17 +180,10 @@ public List<String> getExcludes()
{
String[] excludeList = StringUtils.split(excludes, ",");
List<String> list = new ArrayList<String>();

if (excludeList != null && excludeList.length > 0)
{
Collections.addAll(list, excludeList);
}

if (getDefaultexclude())
{
Collections.addAll(list, DirectoryScanner.getDefaultExcludes());
}

return list;
}

Expand Down

0 comments on commit fc465b1

Please sign in to comment.