Skip to content

Commit bcf3838

Browse files
committed
refactoring o project structure, added plugins for maven and gradle as sbuprojects
1 parent 8709b00 commit bcf3838

File tree

217 files changed

+2170
-209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

217 files changed

+2170
-209
lines changed

README.md

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,24 @@ For instance I have been very actively using the framework in [the ZX-Poly emula
1818
Change log
1919
===========
2020
- **1.3.0-SNAPSHOT**
21-
- __Fixed issue [#16 NullPointerException when referencing a JBBPCustomFieldTypeProcessor parsed field"](https://github.com/raydac/java-binary-block-parser/issues/16), many thanks to @use-sparingly for the bug report__
22-
- created [Maven plugin](https://github.com/raydac/jbbp-maven-plugin) to generate Java class sources (1.6+) from JBBP scripts
21+
- __Fixed issue [#16 NullPointerException when referencing a JBBPCustomFieldTypeProcessor parsed field"](https://github.com/raydac/java-binary-block-parser/issues/16), many thanks to @use-sparingly for the bug report__
22+
- added Maven plugin to auto-generate Java classes (1.6+) from JBBP scripts
23+
- added Gradle plugin to auto-generate Java classes (1.6+) from JBBP scripts
2324
- added extra byte array reading writing methods with byte order support into JBBPBitInputStream and JBBPBitOutputStream
2425
- added converter of compiled parser data into Java class sources (1.6+)
2526
- added method to read unsigned short values as char [] into JBBPBitInputStream
2627
- Class version target has been changed to Java 1.6
2728
- fixed compatibiity of tests with Java 1.6
2829
- Minor refactoring
29-
30+
3031
- **1.2.1 (28-JUL-2016)**
3132
- __Fixed issue [#10 "assertArrayLength throws exception in multi-thread"](https://github.com/raydac/java-binary-block-parser/issues/10), many thanks to @sky4star for the bug report.__
3233
- minor refactoring
3334

3435
- **1.2.0 (10-JUN-2015)**
3536
- Refactoring
3637
- Improved tree of JBBP exceptions
37-
- Fixed NPE in JBBPTextWriter for String field mapped to byte array
38+
- Fixed NPE in JBBPTextWriter for String field mapped to byte array
3839
- Added support of custom field types through JBBPCustomFieldTypeProcessor
3940
- Added JBBPCustomFieldTypeProcessorAggregator, auxiliary class to join several JBBPCustomFieldTypeProcessors
4041
- Fixed JBBPTextWriter, added support of logging for JBBPAbstractField objects
@@ -50,11 +51,11 @@ Change log
5051
- Fixed static fields including in mapping processes if class has marked by default Bin annotation
5152
- Added flag JBBPParser#FLAG_SKIP_REMAINING_FIELDS_IF_EOF to ignore remaining fields during parsing if EOF without exception
5253
- Added flag JBBPMapper#FLAG_IGNORE_MISSING_VALUES to ignore mapping for values which are not found in parsed source
53-
- Added new auxiliary methods in JBBPUtils
54+
- Added new auxiliary methods in JBBPUtils
5455

5556
- **1.0 (08-AUG-2014)**
56-
- The Initial version
57-
57+
- The Initial version
58+
5859
# Maven dependency
5960
The Framework has been published in the Maven Central and can be easily added as a dependency
6061
```
@@ -64,7 +65,7 @@ The Framework has been published in the Maven Central and can be easily added as
6465
<version>1.2.1</version>
6566
</dependency>
6667
```
67-
the precompiled library jar, javadoc and sources also can be downloaded directly from [the Maven central.](http://search.maven.org/#browse|808871750)
68+
the precompiled library jar, javadoc and sources also can be downloaded directly from [the Maven central.](http://search.maven.org/#browse|808871750)
6869

6970
# Hello world
7071
The Framework is very easy in use because it has only two main classes for its functionality com.igormaznitsa.jbbp.JBBPParser (for data parsing) and com.igormaznitsa.jbbp.io.JBBPOut (for binary block writing), both of them work over low-level IO classes com.igormaznitsa.jbbp.io.JBBPBitInputStream and com.igormaznitsa.jbbp.io.JBBPBitOutputStream which are the core for the framework.
@@ -81,27 +82,27 @@ Parsed parsedBits = JBBPParser.prepare("bit:1 [_] parsed;").parse(new byte[]{1,2
8182
```
8283

8384
# More compex example with features added as of 1.1.0
84-
The Example shows how to parse a byte written in non-standard MSB0 order (Java has LSB0 bit order) to bit fields, print its values and pack fields back
85+
The Example shows how to parse a byte written in non-standard MSB0 order (Java has LSB0 bit order) to bit fields, print its values and pack fields back
8586
```Java
8687
class Flags {
8788
@Bin(outOrder = 1, name = "f1", type = BinType.BIT, outBitNumber = JBBPBitNumber.BITS_1, comment = "It's flag one") byte flag1;
8889
@Bin(outOrder = 2, name = "f2", type = BinType.BIT, outBitNumber = JBBPBitNumber.BITS_2, comment = "It's second flag") byte flag2;
8990
@Bin(outOrder = 3, name = "f3", type = BinType.BIT, outBitNumber = JBBPBitNumber.BITS_1, comment = "It's 3th flag") byte flag3;
9091
@Bin(outOrder = 4, name = "f4", type = BinType.BIT, outBitNumber = JBBPBitNumber.BITS_4, comment = "It's 4th flag") byte flag4;
9192
}
92-
93+
9394
final int data = 0b10101010;
9495
Flags parsed = JBBPParser.prepare("bit:1 f1; bit:2 f2; bit:1 f3; bit:4 f4;", JBBPBitOrder.MSB0).parse(new byte[]{(byte)data}).mapTo(Flags.class);
9596
assertEquals(1,parsed.flag1);
9697
assertEquals(2,parsed.flag2);
9798
assertEquals(0,parsed.flag3);
9899
assertEquals(5,parsed.flag4);
99-
100+
100101
System.out.println(new JBBPTextWriter().Bin(parsed).Close().toString());
101-
102+
102103
assertEquals(data, JBBPOut.BeginBin(JBBPBitOrder.MSB0).Bin(parsed).End().toByteArray()[0] & 0xFF);
103104
```
104-
The Example will print in console the text below
105+
The Example will print in console the text below
105106
```
106107
;--------------------------------------------------------------------------------
107108
; START : Flags
@@ -136,7 +137,7 @@ The Framework provides support for arrays and structures. Just keep in mind that
136137
it is possible to define processors for own custom data types, for instance you can take a look at [case processing three byte unsigned integer types](https://github.com/raydac/java-binary-block-parser/blob/master/src/test/java/com/igormaznitsa/jbbp/it/CustomThreeByteIntegerTypeTest.java).
137138

138139
### Float and Double types
139-
The Parser doesn't support Java float and double types out of the box. But it can be implemented through custom type processor. [there is written example and test and the code can be copy pasted](https://github.com/raydac/java-binary-block-parser/blob/master/src/test/java/com/igormaznitsa/jbbp/it/FloatAndDoubleTypesTest.java).
140+
The Parser doesn't support Java float and double types out of the box. But it can be implemented through custom type processor. [there is written example and test and the code can be copy pasted](https://github.com/raydac/java-binary-block-parser/blob/master/src/test/java/com/igormaznitsa/jbbp/it/FloatAndDoubleTypesTest.java).
140141

141142
## Variable fields
142143
If you have some data which structure is variable then you can use the `var` type for defined field and process reading of the data manually with custom [JBBPVarFieldProcessor](https://github.com/raydac/java-binary-block-parser/blob/master/src/main/java/com/igormaznitsa/jbbp/JBBPVarFieldProcessor.java) instance.
@@ -170,7 +171,7 @@ Expressions are used for calculation of length of arrays and allow brackets and
170171
- Arithmetic operators: +,-,%,*,/,%
171172
- Bit operators: &,|,^,~
172173
- Shift operators: <<,>>,>>>
173-
- Brackets: (, )
174+
- Brackets: (, )
174175

175176
Inside expression you can use integer numbers and named field values through their names (if you use fields from the same structure) or paths. Keep in your mind that you can't use array fields or fields placed inside structure arrays.
176177
```
@@ -182,7 +183,7 @@ int field1;
182183
```
183184

184185
# Commentaries
185-
You can use commentaries inside a parser script, the parser supports the only comment format and recognizes as commentaries all text after '//' till the end of line.
186+
You can use commentaries inside a parser script, the parser supports the only comment format and recognizes as commentaries all text after '//' till the end of line.
186187
```
187188
int;
188189
// hello commentaries
@@ -193,7 +194,7 @@ You can use commentaries inside a parser script, the parser supports the only co
193194
Inside expression you can use field names and field paths, also you can use the special macros '$$' which represents the current input stream byte counter, all fields started with '$' will be recognized by the parser as special user defined variables and it will be requesting them from special user defined provider. If the array size contains the only '_' symbol then the field or structure will not have defined size and whole stream will be read.
194195

195196
# How to get result of parsing
196-
The Result of parsing is an instance of com.igormaznitsa.jbbp.model.JBBPFieldStruct class which represents the root invisible structure for the parsed data and you can use its inside methods to find desired fields for their names, paths or classes. All Fields are successors of com.igormaznitsa.jbbp.model.JBBPAbstractField class. To increase comfort, it is easier to use mapping to classes when the mapper automaticaly places values to fields of a Java class.
197+
The Result of parsing is an instance of com.igormaznitsa.jbbp.model.JBBPFieldStruct class which represents the root invisible structure for the parsed data and you can use its inside methods to find desired fields for their names, paths or classes. All Fields are successors of com.igormaznitsa.jbbp.model.JBBPAbstractField class. To increase comfort, it is easier to use mapping to classes when the mapper automaticaly places values to fields of a Java class.
197198

198199
# Example
199200
The Example below shows how to parse a PNG file with the JBBP parser (the example taken from tests)
@@ -213,17 +214,17 @@ final InputStream pngStream = getResourceAsInputStream("picture.png");
213214
);
214215

215216
final JBBPFieldStruct result = pngParser.parse(pngStream);
216-
217+
217218
assertEquals(0x89504E470D0A1A0AL,result.findFieldForNameAndType("header",JBBPFieldLong.class).getAsLong());
218-
219+
219220
final JBBPFieldArrayStruct chunks = result.findFieldForNameAndType("chunk", JBBPFieldArrayStruct.class);
220-
221-
221+
222+
222223
final String [] chunkNames = new String[]{"IHDR","gAMA","bKGD","pHYs","tIME","tEXt","IDAT","IEND"};
223224
final int [] chunkSizes = new int[]{0x0D, 0x04, 0x06, 0x09, 0x07, 0x19, 0x0E5F, 0x00};
224-
225+
225226
assertEquals(chunkNames.length,chunks.size());
226-
227+
227228
for(int i=0;i<chunks.size();i++){
228229
assertChunk(chunkNames[i], chunkSizes[i], (JBBPFieldStruct)chunks.getElementAt(i));
229230
}
@@ -232,7 +233,7 @@ final InputStream pngStream = getResourceAsInputStream("picture.png");
232233
closeResource(pngStream);
233234
}
234235
```
235-
Also it is possible to map parsed packet to class fields
236+
Also it is possible to map parsed packet to class fields
236237
```Java
237238
final JBBPParser pngParser = JBBPParser.prepare(
238239
"long header;"
@@ -256,22 +257,22 @@ final JBBPParser pngParser = JBBPParser.prepare(
256257
long header;
257258
Chunk [] chunk;
258259
}
259-
260+
260261
final Png png = pngParser.parse(pngStream).mapTo(Png.class);
261262
```
262-
The Example from tests shows how to parse a tcp frame wrapped in a network frame
263+
The Example from tests shows how to parse a tcp frame wrapped in a network frame
263264
```Java
264265
final JBBPParser tcpParser = JBBPParser.prepare(
265266
"skip:34; // skip bytes till the frame\n"
266267
+ "ushort SourcePort;"
267268
+ "ushort DestinationPort;"
268269
+ "int SequenceNumber;"
269270
+ "int AcknowledgementNumber;"
270-
271+
271272
+ "bit:1 NONCE;"
272273
+ "bit:3 RESERVED;"
273274
+ "bit:4 HLEN;"
274-
275+
275276
+ "bit:1 FIN;"
276277
+ "bit:1 SYN;"
277278
+ "bit:1 RST;"
@@ -280,7 +281,7 @@ final JBBPParser tcpParser = JBBPParser.prepare(
280281
+ "bit:1 URG;"
281282
+ "bit:1 ECNECHO;"
282283
+ "bit:1 CWR;"
283-
284+
284285
+ "ushort WindowSize;"
285286
+ "ushort TCPCheckSum;"
286287
+ "ushort UrgentPointer;"
@@ -298,11 +299,11 @@ No, `@Bin` annotations in classes are used only for mapping and data writing, bu
298299
No problems! The Parser works over com.igormaznitsa.jbbp.io.BitInputStream class which can be used directly and allows read bits, bytes, count bytes and align data from a stream.
299300

300301
## I want to make a bin block instead of parsing!
301-
The Framework contains a special helper as the class com.igormaznitsa.jbbp.io.JBBPOut which allows to build bin blocks with some kind of DSL
302+
The Framework contains a special helper as the class com.igormaznitsa.jbbp.io.JBBPOut which allows to build bin blocks with some kind of DSL
302303
```Java
303304
import static com.igormaznitsa.jbbp.io.JBBPOut.*;
304305
...
305-
final byte [] array =
306+
final byte [] array =
306307
BeginBin().
307308
Bit(1, 2, 3, 0).
308309
Bit(true, false, true).

changelog.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ Change log
33

44
1.3.0
55
- fixed NPE when referencing a JBBPCustomFieldTypeProcessor parsed field
6-
- created [Maven plugin](https://github.com/raydac/jbbp-maven-plugin) to generate Java class sources (1.6+) from JBBP scripts
6+
- added Maven plugin to auto-generate Java classes (1.6+) from JBBP scripts
7+
- added Gradle plugin to auto-generate Java classes (1.6+) from JBBP scripts
78
- added extra byte array reading writing methods with byte order support into JBBPBitInputStream and JBBPBitOutputStream
89
- added converter of compiled parser data into Java class sources (1.6+)
910
- added method to read unsigned short values as char [] into JBBPBitInputStream
@@ -14,7 +15,7 @@ Change log
1415
1.2.0
1516
- Refactoring
1617
- Improved tree of JBBP exceptions
17-
- Fixed NPE in JBBPTextWriter for String field mapped to byte array
18+
- Fixed NPE in JBBPTextWriter for String field mapped to byte array
1819
- Added support of custom field types through JBBPCustomFieldTypeProcessor
1920
- Added JBBPCustomFieldTypeProcessorAggregator, auxiliary class to join several JBBPCustomFieldTypeProcessors
2021
- Fixed JBBPTextWriter, added support of logging for JBBPAbstractField objects
@@ -29,8 +30,8 @@ Change log
2930
- Fixed read byte counter, now it counts only fully processed bytes, if only several bits have been read from byte then the byte will not be counted until whole read
3031
- Fixed static fields including in mapping processes if class has marked by default Bin annotation
3132
- Added flag JBBPParser#FLAG_SKIP_REMAINING_FIELDS_IF_EOF to ignore remaining fields during parsing if EOF without exception
32-
- Added flag JBBPMapper#FLAG_IGNORE_MISSING_VALUES to ignore mapping for values which are not found in parsed source
33+
- Added flag JBBPMapper#FLAG_IGNORE_MISSING_VALUES to ignore mapping for values which are not found in parsed source
3334
- Added new auxiliary methods in JBBPUtils
3435

3536
1.0
36-
- The Initial version
37+
- The Initial version

jbbp-gradle/build.gradle

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def jbbpVersion = project.hasProperty('jbbp_version') ? project.getProperty('jbbp_version') : "1.3.0-SNAPSHOT"
2+
3+
group = 'com.igormaznitsa'
4+
version = jbbpVersion
5+
6+
apply plugin: 'groovy'
7+
apply plugin: 'maven'
8+
9+
sourceCompatibility = 1.6
10+
11+
dependencies {
12+
compile gradleApi()
13+
14+
testCompile 'junit:junit:4.12'
15+
}
16+
17+
repositories {
18+
mavenCentral()
19+
mavenLocal()
20+
}
21+
22+
dependencies {
23+
compile "com.igormaznitsa:jbbp:"+jbbpVersion
24+
}

jbbp-gradle/pom.xml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>com.igormaznitsa</groupId>
8+
<artifactId>jbbp-main-pom</artifactId>
9+
<version>1.3.0-SNAPSHOT</version>
10+
<relativePath>../pom.xml</relativePath>
11+
</parent>
12+
13+
<artifactId>jbbp-gradle-plugin</artifactId>
14+
<packaging>pom</packaging>
15+
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<artifactId>maven-clean-plugin</artifactId>
20+
<version>3.0.0</version>
21+
<configuration>
22+
<filesets>
23+
<fileset>
24+
<directory>${project.basedir}/gradle</directory>
25+
<followSymlinks>false</followSymlinks>
26+
</fileset>
27+
<fileset>
28+
<directory>${project.basedir}</directory>
29+
<includes>
30+
<include>gradlew</include>
31+
<include>gradlew.bat</include>
32+
</includes>
33+
<followSymlinks>false</followSymlinks>
34+
</fileset>
35+
<fileset>
36+
<directory>${project.basedir}/downloaded</directory>
37+
<followSymlinks>false</followSymlinks>
38+
</fileset>
39+
<fileset>
40+
<directory>${project.basedir}/build</directory>
41+
<followSymlinks>false</followSymlinks>
42+
</fileset>
43+
<fileset>
44+
<directory>${project.basedir}/out</directory>
45+
<followSymlinks>false</followSymlinks>
46+
</fileset>
47+
</filesets>
48+
</configuration>
49+
</plugin>
50+
<plugin>
51+
<groupId>org.codehaus.mojo</groupId>
52+
<artifactId>properties-maven-plugin</artifactId>
53+
<version>1.0.0</version>
54+
<executions>
55+
<execution>
56+
<goals>
57+
<goal>set-system-properties</goal>
58+
</goals>
59+
<configuration>
60+
<properties>
61+
<property>
62+
<name>gradle.prop.jbbp_plugin_version</name>
63+
<value>${project.version}</value>
64+
</property>
65+
</properties>
66+
</configuration>
67+
</execution>
68+
</executions>
69+
</plugin>
70+
<plugin>
71+
<groupId>org.fortasoft</groupId>
72+
<artifactId>gradle-maven-plugin</artifactId>
73+
<version>1.0.8</version>
74+
<configuration>
75+
<gradleVersion>4.1</gradleVersion>
76+
<tasks>
77+
<task>clean</task>
78+
<task>build</task>
79+
</tasks>
80+
</configuration>
81+
<executions>
82+
<execution>
83+
<phase>compile</phase>
84+
<goals>
85+
<goal>invoke</goal>
86+
</goals>
87+
</execution>
88+
</executions>
89+
</plugin>
90+
</plugins>
91+
</build>
92+
93+
</project>

jbbp-gradle/settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'jbbp-gradle-plugin'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.igormaznitsa.jbbp.gradle;
2+
3+
import org.gradle.api.Plugin;
4+
import org.gradle.api.Project;
5+
import org.gradle.api.Task;
6+
7+
import java.util.Set;
8+
9+
public class JBBPPlugin implements Plugin<Project> {
10+
11+
@Override
12+
public void apply(Project project) {
13+
project.getTasks().create("jbbp", JBBPTask.class);
14+
}
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.igormaznitsa.jbbp.gradle;
2+
3+
import org.gradle.api.DefaultTask;
4+
import org.gradle.api.file.FileTree;
5+
import org.gradle.api.file.FileVisitDetails;
6+
import org.gradle.api.file.FileVisitor;
7+
import org.gradle.api.file.SourceDirectorySet;
8+
import org.gradle.api.tasks.*;
9+
import org.gradle.api.tasks.incremental.IncrementalTaskInputs;
10+
import org.gradle.language.base.internal.tasks.SimpleStaleClassCleaner;
11+
import org.gradle.language.base.internal.tasks.StaleClassCleaner;
12+
13+
import java.io.File;
14+
15+
public class JBBPTask extends DefaultTask {
16+
17+
@TaskAction
18+
public void execute(){
19+
this.getInputs()
20+
}
21+
22+
}

0 commit comments

Comments
 (0)