Skip to content

Commit

Permalink
Merge pull request #2 from tamada/initial_release
Browse files Browse the repository at this point in the history
最初のリリースをマージする.
  • Loading branch information
tamada committed Jan 19, 2017
2 parents 078fff2 + 1ce9030 commit b11c558
Show file tree
Hide file tree
Showing 64 changed files with 1,560 additions and 289 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: java
jdk:
- oraclejdk8

env:
secure: "FEVnbx67LZNZEswG4BAs0pgHnLGifjFXYF3I2Ljt7HuW3JUzfzXJB6kl/pJy83Uig2QRrIeEKghsEJsa8D1TnwrWaWUH+PRTXqGnPe3FxWl6lCwh/oWVBLgj6pPAh/0LKpsw5hcw6ZZ590+3yHffvr3s8i1qKSbZGflf7UH3E07c1QHEM2qi8+rjSvuIjOt+ynSS44t6Jiewmc2iAY+J/eBbbLSkgevXo4tpUHhgsEtWqbCHmeKxoXMZX0ty8n+DmzVaZhrr6RCEkyfNIINvuwB2MldHuwCIsunZBTXPZViE8esSxiPPXwef7OwAsYaMzNCSdhmv7j3Gb1uMqCxqG4WpRfSzr+aeK9CcuPmdYXGODiN6MRcHwb/4/wf0F9Axg7vdAIB+fKUTkGDTV3/fwOLjuLcrss9v4uLot9p57t5HdmQ0zLDvIQCtCdlJgjpNssxb13peE8TD4JoD0opTCu9FQoC+gdwyTOkLK4aKTFFr8SNeiL6lx+0DsH8xaICm4BO1CMV/moRBOt6KChIgode7gUlDP2wm34/9EcapVoCaNSDPXHbYw0hPyHlBw59SAihomuEKGPPxX/bUABWzp5vJfSdKQlETNd1oiaEAGR2GnUl6RMYGVk7/uq2U+nAi7PYD0oXOHoMdr/yK7GGq/hR43bTeic514B+J1S5ronY="

after_success:
- mvn -DrepoToken=$COVERALLS_TOKEN clean test jacoco:report coveralls:report

23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
[![Build Status](https://travis-ci.org/tamada/kunai2.svg?branch=master)](https://travis-ci.org/tamada/kunai2)
[![Coverage Status](https://coveralls.io/repos/github/tamada/kunai2/badge.svg?branch=master)](https://coveralls.io/github/tamada/kunai2?branch=master)
[![codebeat badge](https://codebeat.co/badges/2f934b12-6c8e-439a-81e9-694b89789374)](https://codebeat.co/projects/github-com-tamada-kunai2)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=flat)](https://github.com/tamada/9rules/blob/master/LICENSE)

# kunai2
Kunai for Java 8

This tool is to read/store class files from/to directories, jar file, and war files.
[kunai](https://github.com/tamada/kunai) is same tool, however, kunai is for Java 7 or before.
Kunai2 implemented for Java 8 and used streaming API.

## Simply use.

### Reading

```java
Path path = Paths.get("target/source");
DataSource source = new DefaultDataSourceFactory().build(path);
source.stream();
// some operation for stream.
```

### Storing
119 changes: 59 additions & 60 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>5.0.4</version>
<version>5.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -31,7 +31,7 @@
</dependencies>

<build>
<sourceDirectory>src/main/java</sourceDirectory>
<sourceDirectory>src/main/java</sourceDirectory>

<resources>
<resource>
Expand All @@ -53,36 +53,34 @@

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-publish-plugin</artifactId>
<version>1.1</version>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<encoding>utf-8</encoding>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.5</version>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.2.0</version>
<configuration>
<inputEncoding>utf-8</inputEncoding>
<outputEncoding>utf-8</outputEncoding>
<locales>en</locales>
<sourceEncoding>utf-8</sourceEncoding>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-module-markdown</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>com.github.stephenc.wagon</groupId>
<artifactId>wagon-gitsite</artifactId>
<version>0.4.1</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
Expand Down Expand Up @@ -111,14 +109,49 @@
<configuration>
<archive>
<manifest>
<mainClass>com.github.kunai.Main</mainClass>
<mainClass>com.github.kunai.Demo</mainClass>
<addClasspath>true</addClasspath>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-publish-plugin</artifactId>
<version>1.1</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.5</version>
<configuration>
<inputEncoding>utf-8</inputEncoding>
<outputEncoding>utf-8</outputEncoding>
<locales>en</locales>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-module-markdown</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>com.github.stephenc.wagon</groupId>
<artifactId>wagon-gitsite</artifactId>
<version>0.4.1</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand All @@ -139,22 +172,10 @@
<version>2.8.1</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>utf-8</encoding>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>${jacocoArgs}</argLine>
</configuration>
</plugin>

<plugin>
Expand All @@ -169,28 +190,6 @@
</configuration>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
<executions>
<execution>
<id>prepare-agent</id>
<phase>test-compile</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/github/kunai/Demo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.github.kunai;

import java.nio.file.Paths;

import com.github.kunai.sink.DataSink;
import com.github.kunai.sink.factories.DataSinkFactoryBuilder;
import com.github.kunai.source.DataSource;
import com.github.kunai.source.factories.DefaultDataSourceFactory;

public class Demo {
public Demo(String[] args) throws Exception{
copy(args[0], args[1]);
}

private void copy(String from, String to) throws Exception{
try(DataSource source = new DefaultDataSourceFactory().build(Paths.get(from));
DataSink sink = new DataSinkFactoryBuilder().create(Paths.get(to))){
copy(source, sink);
}
}

private void copy(DataSource source, DataSink sink) throws Exception{
sink.consume(source);
}

public static final void main(String[] args) throws Exception{
new Demo(args);
}
}
52 changes: 0 additions & 52 deletions src/main/java/com/github/kunai/Main.java

This file was deleted.

15 changes: 1 addition & 14 deletions src/main/java/com/github/kunai/entries/ClassName.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
package com.github.kunai.entries;

import java.nio.file.Path;


public class ClassName extends Name{
private static final long serialVersionUID = -1305904437135129418L;

public ClassName(String name){
super(name);
}

public static ClassName parse(Path path){
String name = path.toString();
if(name.startsWith("/")){
int lastIndex = name.length();
lastIndex = lastIndex - ".class".length();
name = name.substring(1, lastIndex);
}
return new ClassName(name.replace('/', '.'));
super(name.replace('/', '.'));
}
}
19 changes: 16 additions & 3 deletions src/main/java/com/github/kunai/entries/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.file.Path;

public interface Entry {
public InputStream getInputStream() throws IOException;
InputStream openStream() throws IOException;

public ClassName getClassName();
ClassName className();

public boolean isName(String name);
default boolean isClass(){
String name = path().toString();
return name.endsWith(".class");
}

boolean isName(String name);

default URI loadFrom(){
return path().toUri();
}

Path path();
}
13 changes: 8 additions & 5 deletions src/main/java/com/github/kunai/entries/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ public Name(String name){
this.name = name;
}

String name(){
return name;
}

@Override
public boolean equals(Object o){
if(o instanceof Name){
return Objects.equals(name, ((Name)o).name);
}
return false;
public boolean equals(Object other){
return other instanceof Name
&& Objects.equals(name,
((Name)other).name);
}

@Override
Expand Down
Loading

0 comments on commit b11c558

Please sign in to comment.