Skip to content

Commit

Permalink
Can work with commons-io:commons-io:2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
valery1707 committed Jan 28, 2019
1 parent 5105e1c commit c65856b
Show file tree
Hide file tree
Showing 15 changed files with 446 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Change log for releases.

# SNAPSHOT

* Can work with `commons-io:commons-io:2.4`

# 0.1.3

* Propagate `kaitai_compiler` messages as part of plugin's error message
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
68 changes: 68 additions & 0 deletions src/it/lib-commons-io_24-exist/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>4.0.0</modelVersion>

<groupId>name.valery1707.kaitai.it</groupId>
<artifactId>it-source-exists</artifactId>
<version>1.0-SNAPSHOT</version>

<description>Use case: source directory with KaiTai templates exists and compiled</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<!--KaiTai-->
<dependency>
<groupId>io.kaitai</groupId>
<artifactId>kaitai-struct-runtime</artifactId>
<version>0.8</version>
</dependency>

<!--Test-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
78 changes: 78 additions & 0 deletions src/it/lib-commons-io_24-exist/src/main/resources/kaitai/ico.ksy
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
meta:
id: ico
title: Microsoft Windows icon file
file-extension: ico
endian: le
license: CC0-1.0
doc: |
Microsoft Windows uses specific file format to store applications
icons - ICO. This is a container that contains one or more image
files (effectively, DIB parts of BMP files or full PNG files are
contained inside).
doc-ref: https://msdn.microsoft.com/en-us/library/ms997538.aspx
seq:
- id: magic
contents: [0, 0, 1, 0]
- id: num_images
-orig-id: idCount
type: u2
doc: Number of images contained in this file
- id: images
-orig-id: idEntries
type: icon_dir_entry
repeat: expr
repeat-expr: num_images
types:
icon_dir_entry:
-orig-id: ICONDIRENTRY
seq:
- id: width
-orig-id: bWidth
type: u1
doc: Width of image, px
- id: height
-orig-id: bHeight
type: u1
doc: Height of image, px
- id: num_colors
-orig-id: bColorCount
type: u1
doc: |
Number of colors in palette of the image or 0 if image has
no palette (i.e. RGB, RGBA, etc)
- id: reserved
-orig-id: bReserved
contents: [0]
- id: num_planes
-orig-id: wPlanes
type: u2
doc: Number of color planes
- id: bpp
-orig-id: wBitCount
type: u2
doc: Bits per pixel in the image
- id: len_img
-orig-id: dwBytesInRes
type: u4
doc: Size of the image data
- id: ofs_img
-orig-id: dwImageOffset
type: u4
doc: Absolute offset of the image data start in the file
instances:
img:
pos: ofs_img
size: len_img
doc: |
Raw image data. Use `is_png` to determine whether this is an
embedded PNG file (true) or a DIB bitmap (false) and call a
relevant parser, if needed to parse image data further.
png_header:
pos: ofs_img
size: 8
doc: |
Pre-reads first 8 bytes of the image to determine if it's an
embedded PNG file.
is_png:
value: png_header == [137, 80, 78, 71, 13, 10, 26, 10]
doc: True if this image is in PNG format.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package name.valery1707.kaitai.it;

import io.kaitai.struct.ByteBufferKaitaiStream;
import io.kaitai.struct.KaitaiStream;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class KaitaiIcoTest {
private KaitaiStream getResourceAsStream(String resource) {
try (
InputStream in = getClass().getResourceAsStream(resource);
ByteArrayOutputStream out = new ByteArrayOutputStream();
) {
byte[] buffer = new byte[1024 * 8];
int len;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
out.flush();
return new ByteBufferKaitaiStream(out.toByteArray());
} catch (IOException e) {
throw new IllegalStateException(String.format(
"Fail to load data from resource: %s"
, resource
)
, e
);
}
}

@Test
public void test() {
Ico ico = new Ico(getResourceAsStream("/document.ico"));
assertThat(ico).isNotNull();

assertThat(ico.magic()).isNotNull().hasSize(4).containsExactly(0, 0, 1, 0);

assertThat(ico.images()).isNotNull().hasSize(23).hasSize(ico.numImages());

assertThat(ico.images().get(0)).isNotNull();
assertThat(ico.images().get(0).img()).isNotNull().hasSize(816).startsWith(40, 0, 0, 0, 48);
}
}
Binary file not shown.
17 changes: 17 additions & 0 deletions src/it/lib-commons-io_24-exist/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
String log = new File(basedir, "build.log").text
File target = new File(basedir, "target");
File kaitaiCache = target.toPath().parent.parent.parent.resolve("local-repo/.cache/kaitai").toFile()
File targetTemplate = target.toPath().resolve("classes/kaitai/ico.ksy").toFile()
File generated = new File(target, "generated-sources");
File generatedParser = generated.toPath().resolve("kaitai/src/name/valery1707/kaitai/it/Ico.java").toFile()

assert log.contains("KaiTai distribution: Prepare cache directory")
assert log.contains("KaiTai distribution: Downloading")
assert log.contains("KaiTai distribution: Extracting")
assert log.contains("kaitai-struct-compiler")
assert log.contains("[INFO] BUILD SUCCESS")
assert kaitaiCache.exists() && kaitaiCache.renameTo(kaitaiCache.toPath().resolveSibling(target.parentFile.name).toFile())
assert target.exists()
assert targetTemplate.exists()
assert generated.exists()
assert generatedParser.exists() && generatedParser.isFile()
1 change: 1 addition & 0 deletions src/it/lib-commons-io_24-failed/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.buildResult=failure
68 changes: 68 additions & 0 deletions src/it/lib-commons-io_24-failed/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>4.0.0</modelVersion>

<groupId>name.valery1707.kaitai.it</groupId>
<artifactId>it-source-failed</artifactId>
<version>1.0-SNAPSHOT</version>

<description>Use case: source directory with KaiTai templates exists but templates contains error(s)</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<!--KaiTai-->
<dependency>
<groupId>io.kaitai</groupId>
<artifactId>kaitai-struct-runtime</artifactId>
<version>0.8</version>
</dependency>

<!--Test-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
12 changes: 12 additions & 0 deletions src/it/lib-commons-io_24-failed/src/main/resources/kaitai/demo.ksy
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
meta:
id: demo
file-extension: demo
endian: le
seq:
- id: header
type: header
types:
header:
seq:
- id: Magic
contents: 'DEMO'
78 changes: 78 additions & 0 deletions src/it/lib-commons-io_24-failed/src/main/resources/kaitai/ico.ksy
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
meta:
id: ico
title: Microsoft Windows icon file
file-extension: ico
endian: le
license: CC0-1.0
doc: |
Microsoft Windows uses specific file format to store applications
icons - ICO. This is a container that contains one or more image
files (effectively, DIB parts of BMP files or full PNG files are
contained inside).
doc-ref: https://msdn.microsoft.com/en-us/library/ms997538.aspx
seq:
- id: magic
contents: [0, 0, 1, 0]
- id: num_images
-orig-id: idCount
type: u2
doc: Number of images contained in this file
- id: images
-orig-id: idEntries
type: icon_dir_entry
repeat: expr
repeat-expr: num_images
types:
icon_dir_entry:
-orig-id: ICONDIRENTRY
seq:
- id: width
-orig-id: bWidth
type: u1
doc: Width of image, px
- id: height
-orig-id: bHeight
type: u1
doc: Height of image, px
- id: num_colors
-orig-id: bColorCount
type: u1
doc: |
Number of colors in palette of the image or 0 if image has
no palette (i.e. RGB, RGBA, etc)
- id: reserved
-orig-id: bReserved
contents: [0]
- id: num_planes
-orig-id: wPlanes
type: u2
doc: Number of color planes
- id: bpp
-orig-id: wBitCount
type: u2
doc: Bits per pixel in the image
- id: len_img
-orig-id: dwBytesInRes
type: u4
doc: Size of the image data
- id: ofs_img
-orig-id: dwImageOffset
type: u4
doc: Absolute offset of the image data start in the file
instances:
img:
pos: ofs_img
size: len_img
doc: |
Raw image data. Use `is_png` to determine whether this is an
embedded PNG file (true) or a DIB bitmap (false) and call a
relevant parser, if needed to parse image data further.
png_header:
pos: ofs_img
size: 8
doc: |
Pre-reads first 8 bytes of the image to determine if it's an
embedded PNG file.
is_png:
value: png_header == [137, 80, 78, 71, 13, 10, 26, 10]
doc: True if this image is in PNG format.
Loading

0 comments on commit c65856b

Please sign in to comment.