-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from tamada/plainfile
単なるファイルを扱う PlainFileDataSource を追加した.
- Loading branch information
Showing
15 changed files
with
204 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/github/kunai/source/PlainFileDataSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.github.kunai.source; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.stream.Stream; | ||
|
||
import com.github.kunai.entries.ClassName; | ||
import com.github.kunai.entries.Entry; | ||
import com.github.kunai.entries.PathEntry; | ||
|
||
public class PlainFileDataSource extends AbstractDataSource implements PathResolver{ | ||
private Path path; | ||
|
||
public PlainFileDataSource(Path path){ | ||
this.path = path; | ||
} | ||
|
||
@Override | ||
public Stream<Entry> stream() { | ||
return Stream.of(new PathEntry(path, this)); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
// do nothing. | ||
} | ||
|
||
@Override | ||
public InputStream openStream(Path path) throws IOException { | ||
return Files.newInputStream(path); | ||
} | ||
|
||
@Override | ||
public ClassName parseClassName(Path path) { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/com/github/kunai/source/factories/PlainFileDataSourceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.github.kunai.source.factories; | ||
|
||
import java.nio.file.FileSystem; | ||
import java.nio.file.Path; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
|
||
import com.github.kunai.entries.KunaiException; | ||
import com.github.kunai.source.DataSource; | ||
import com.github.kunai.source.PlainFileDataSource; | ||
|
||
class PlainFileDataSourceFactory implements DataSourceFactory{ | ||
public PlainFileDataSourceFactory(){ | ||
} | ||
|
||
@Override | ||
public boolean isTarget(Path path, FileSystem system, BasicFileAttributes attributes){ | ||
return attributes.isRegularFile(); | ||
} | ||
|
||
@Override | ||
public DataSource build(Path path, FileSystem system) throws KunaiException{ | ||
return new PlainFileDataSource(path); | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
src/main/java/com/github/kunai/translators/NullTranslator.java
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
src/main/java/com/github/kunai/translators/Translator.java
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
src/test/java/com/github/kunai/source/AbstractDataSourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.github.kunai.source; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import java.nio.file.Paths; | ||
|
||
import org.junit.Test; | ||
|
||
public class AbstractDataSourceTest{ | ||
@Test | ||
public void testBasic() throws Exception{ | ||
try(PlainFileDataSource source = new PlainFileDataSource(Paths.get("target/test-classes/dummy.class/emptyfile"))){ | ||
assertThat(source.getStartIndex("/hoge.class"), is(1)); | ||
assertThat(source.getStartIndex("hoge.class"), is(0)); | ||
assertThat(source.trimName("/hoge.class", 1, 5), is("hoge")); | ||
assertThat(source.trimName("aaa", -1, 1), is("aaa")); | ||
assertThat(source.trimName("aaa", 2, 1), is("aaa")); | ||
assertThat(source.trimName("aaa", 0, 1), is("a")); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/test/java/com/github/kunai/source/factories/ClassFileDataSourceFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.github.kunai.source.factories; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.github.kunai.entries.ClassName; | ||
import com.github.kunai.entries.Entry; | ||
import com.github.kunai.source.DataSource; | ||
|
||
public class ClassFileDataSourceFactoryTest { | ||
private Path path; | ||
private Path dummyPath; | ||
private ClassFileDataSourceFactory factory = new ClassFileDataSourceFactory(); | ||
|
||
@Before | ||
public void setUp(){ | ||
path = Paths.get("target/test-classes/hello/target/classes/sample/hello/HelloWorld.class"); | ||
dummyPath = Paths.get("target/test-classes/dummy.class"); | ||
} | ||
|
||
@Test | ||
public void testBasic() throws Exception{ | ||
assertThat(factory.isTarget(path), is(true)); | ||
assertThat(factory.isTarget(dummyPath), is(false)); | ||
|
||
DataSource source = factory.build(new File(path.toString())); | ||
Entry[] entries = source.stream().toArray(size -> new Entry[size]); | ||
|
||
assertThat(entries.length, is(1)); | ||
assertThat(entries[0].className(), is(new ClassName("sample.hello.HelloWorld"))); | ||
assertThat(entries[0].isClass(), is(true)); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/test/java/com/github/kunai/source/factories/DefaultDataSourceFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/test/java/com/github/kunai/source/factories/PlainFileDataSourceFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.github.kunai.source.factories; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.nullValue; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.github.kunai.entries.Entry; | ||
import com.github.kunai.source.DataSource; | ||
|
||
public class PlainFileDataSourceFactoryTest { | ||
private Path path; | ||
private Path dummyPath; | ||
private DataSourceFactory factory = new PlainFileDataSourceFactory(); | ||
|
||
@Before | ||
public void setUp(){ | ||
path = Paths.get("target/test-classes/hello/target/classes/sample/hello/HelloWorld.class"); | ||
dummyPath = Paths.get("target/test-classes/dummy.class"); | ||
} | ||
|
||
@Test | ||
public void testBasic() throws Exception{ | ||
assertThat(factory.isTarget(path), is(true)); | ||
assertThat(factory.isTarget(dummyPath), is(false)); | ||
|
||
DataSource source = factory.build(new File(path.toString())); | ||
Entry[] entries = source.stream().toArray(size -> new Entry[size]); | ||
|
||
assertThat(entries.length, is(1)); | ||
assertThat(entries[0].endsWith(".class"), is(true)); | ||
assertThat(entries[0].loadFrom(), is(path.toUri())); | ||
assertThat(entries[0].className(), is(nullValue())); | ||
assertThat(entries[0].isClass(), is(true)); | ||
assertThat(entries[0].toString(), is(String.format("%s <%s>", path.toUri(), path))); | ||
} | ||
} |