Skip to content

Commit

Permalink
Merge pull request #10 from itohro/master
Browse files Browse the repository at this point in the history
Bug fixes.
  • Loading branch information
motlin committed May 9, 2016
2 parents 70de923 + a354eda commit 5a924bc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
24 changes: 20 additions & 4 deletions src/main/java/org/eclipse/collections/tools/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
Expand All @@ -28,20 +30,34 @@ public class Converter
{
private static final ImmutableList<String> FILE_SCOPE = Lists.immutable.of(".java", ".xml", "gradle", ".groovy", ".scala", ".kt", ".rb", ".clj");
private static final ImmutableMap<String, String> CONVERSION_MAP = Maps.immutable.with(
"com\\.gs", "org\\.eclipse",
"com\\.gs\\.collections", "org\\.eclipse\\.collections",
"com\\.goldmansachs", "org\\.eclipse\\.collections",
"gs-collections", "eclipse-collections");
public static final Charset DEFAULT_ENCODING = Charset.forName("UTF-8");
private static Charset endoding = DEFAULT_ENCODING;

public static void main(String... args)
{
if (args.length != 1)
if (args.length < 1)
{
System.out.println("Usage: gsc-ec-converter <PATH_TO_PROJECT>");
System.out.println("Usage: gsc-ec-converter <PATH_TO_PROJECT> [File encoding]");
System.exit(1);
}
String path = args[0];
if (Files.exists(Paths.get(path)))
{
if (args.length == 2)
{
try
{
endoding = Charset.forName(args[1]);
}
catch (IllegalCharsetNameException | UnsupportedCharsetException e)
{
System.out.println("Invalid file encoding is passed: " + args[1]);
System.exit(1);
}
}
System.out.println("Running Eclipse Collections Converter against " + path + ".");
Converter.convert(path);
System.out.println("Done!");
Expand All @@ -64,7 +80,7 @@ private static void convert(String path)
try
{
boolean[] fileChanged = {false};
List<String> replacedLines = Files.lines(file, Charset.defaultCharset()).map(line -> {
List<String> replacedLines = Files.lines(file, endoding).map(line -> {
String newLine = Converter.replaceMatching(line);
fileChanged[0] = fileChanged[0] || !newLine.equals(line);
return newLine;
Expand Down
18 changes: 16 additions & 2 deletions src/test/java/org/eclipse/collections/tools/ConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void main() throws Exception
Assert.assertEquals(3, pomFile.countWith(String::contains, "eclipse-collections"));

MutableList<String> javaFile = ListAdapter.adapt(Files.readAllLines(Paths.get(this.testDir + "/src/main/java/TestClass.java")));
Assert.assertEquals(0, javaFile.countWith(String::contains, "com.gs"));
Assert.assertEquals(1, javaFile.countWith(String::contains, "com.gs"));
Assert.assertEquals(2, javaFile.countWith(String::contains, "org.eclipse"));

MutableList<String> ignoredFile = ListAdapter.adapt(Files.readAllLines(Paths.get(this.testDir + "/.ignored/should_not_be_read")));
Expand All @@ -78,7 +78,7 @@ public void main() throws Exception
}

@Test
public void invalidArg()
public void invalidArg1()
{
try
{
Expand All @@ -91,6 +91,20 @@ public void invalidArg()
}
}

@Test
public void invalidArg2()
{
try
{
Converter.main(this.testDir.getAbsolutePath(), "nonExistingEncoding");
Assert.fail("Converter should fail for non existing encoding");
}
catch (RuntimeException e)
{
Assert.assertEquals(1, ExitMock.getInstance().getStatus());
}
}

@Test
public void invalidPath()
{
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/source/src/main/java/TestClass.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import com.gs.collections.api.list.MutableList;
import com.gs.collections.impl.factory.Lists;
import com.gs.somepackage.api.SomeApi;

public class TestClass
{
Expand Down

0 comments on commit 5a924bc

Please sign in to comment.