Skip to content

Commit

Permalink
Merge branch 'dependabot/maven/org.apache.maven.plugins-maven-project…
Browse files Browse the repository at this point in the history
…-info-reports-plugin-3.4.5' of github.com:parsingdata/metal into dependabot/maven/org.apache.maven.plugins-maven-project-info-reports-plugin-3.4.5
  • Loading branch information
mvanaken committed Mar 15, 2024
2 parents 53d4084 + 8bad692 commit d09d3e1
Show file tree
Hide file tree
Showing 213 changed files with 2,458 additions and 1,333 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,20 @@ jobs:

- name: Build and deploy with Maven and analyze with Sonar
# Deploy and analyze only the Corretto 11 build
if: matrix.distribution == 'corretto' && matrix.java-version == '11'
if: matrix.distribution == 'corretto' && matrix.java-version == '17'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# The value of sonar.projectKey is generated by Sonar and needs to map to its internal project name
run: mvn -B --update-snapshots -Dmaven.test.failure.ignore=true deploy org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=parsingdata_metal
run: mvn -B --update-snapshots -Dmaven.test.failure.ignore=true package org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=parsingdata_metal

- name: Build and deploy with Maven
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: matrix.distribution == 'corretto' && matrix.java-version == '11'
run: mvn -B --update-snapshots -Dmaven.test.failure.ignore=true deploy

- name: Build with Maven
if: matrix.distribution != 'corretto' || matrix.java-version != '11'
if: matrix.distribution != 'corretto'
run: mvn -B --update-snapshots -Dmaven.test.failure.ignore=true package

- name: Upload Code Coverage to Codecov
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ A Java library for parsing binary data formats, using declarative descriptions.

## Using Metal

Metal releases are available in the central Maven repository. To use the latest (9.0.0) release of Metal, include the following section in the pom.xml under dependencies:
Metal releases are available in the central Maven repository. To use the latest (10.0.0) release of Metal, include the following section in the pom.xml under dependencies:

```xml
<dependency>
<groupId>io.parsingdata</groupId>
<artifactId>metal-core</artifactId>
<version>9.0.0</version>
<version>10.0.0</version>
</dependency>
```

Expand All @@ -37,8 +37,8 @@ Please read the [Authenticating to GitHub Packages](https://docs.github.com/en/p

## License

Copyright 2013-2023 Netherlands Forensic Institute
Copyright 2021-2023 Infix Technologies B.V.
Copyright 2013-2024 Netherlands Forensic Institute
Copyright 2021-2024 Infix Technologies B.V.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
3 changes: 2 additions & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>io.parsingdata</groupId>
<artifactId>metal</artifactId>
<version>10.0.0-SNAPSHOT</version>
<version>11.0.0-SNAPSHOT</version>
</parent>
<artifactId>metal-core</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
Expand All @@ -14,6 +14,7 @@
<connection>scm:git:[email protected]:parsingdata/metal.git</connection>
<developerConnection>scm:git:[email protected]:parsingdata/metal.git</developerConnection>
<url>https://github.com/parsingdata/metal.git</url>
<tag>HEAD</tag>
</scm>

<build>
Expand Down
26 changes: 26 additions & 0 deletions core/src/main/java/io/parsingdata/metal/ImmutableObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.parsingdata.metal;

/**
* When objects are immutable, that means their hash code will stay the same the moment it is created.
* It will improve performance if these objects cache their hash code.
* <p>
* This is a lazy implementation, instead of calculating the hash once within the constructor, to avoid
* performance decrease during parsing. In most implementations the hash code is not actually used/needed.
*/
public abstract class ImmutableObject {

private Integer hashCode;

public abstract int immutableHashCode();

@Override
public abstract boolean equals(final Object obj);

@Override
public int hashCode() {
if (hashCode == null) {
hashCode = immutableHashCode();
}
return hashCode;
}
}
29 changes: 20 additions & 9 deletions core/src/main/java/io/parsingdata/metal/Shorthand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013-2021 Netherlands Forensic Institute
* Copyright 2013-2024 Netherlands Forensic Institute
* Copyright 2021-2024 Infix Technologies B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,7 +54,6 @@
import io.parsingdata.metal.expression.value.FoldRight;
import io.parsingdata.metal.expression.value.Join;
import io.parsingdata.metal.expression.value.Reverse;
import io.parsingdata.metal.expression.value.Scope;
import io.parsingdata.metal.expression.value.SingleValueExpression;
import io.parsingdata.metal.expression.value.UnaryValueExpression;
import io.parsingdata.metal.expression.value.Value;
Expand Down Expand Up @@ -304,14 +304,21 @@ private Shorthand() {}

/** @see Len */ public static ValueExpression len(final ValueExpression operand) { return new Len(operand); }
/** @see Len */ public static SingleValueExpression len(final SingleValueExpression operand) { return last(new Len(operand)); }
/** @see Ref */ public static NameRef ref(final String name) { return ref(name, null); }
/** @see Ref */ public static NameRef ref(final String name, final SingleValueExpression limit) { return new NameRef(name, limit); }
/** @see Ref */ public static DefinitionRef ref(final Token definition) { return ref(definition, null); }
/** @see Ref */ public static DefinitionRef ref(final Token definition, final SingleValueExpression limit) { return new DefinitionRef(definition, limit); }

/** @deprecated Use {@link #ref(SingleValueExpression, String, String...)} or {@link #last(NameRef)} in combination with {@link #ref(String, String...)} if limit is 1, instead. */
public static NameRef ref(final String name, final SingleValueExpression limit) { return new NameRef(limit, name); }
/** @see Ref */ public static NameRef ref(final String name, final String... names) { return new NameRef(name, names); }
/** @see Ref */ public static NameRef ref(final SingleValueExpression limit, final String name, final String... names) { return new NameRef(limit, name, names); }

/** @deprecated Use {@link #ref(SingleValueExpression, Token, Token...)} or {@link #last(DefinitionRef)} in combination with {@link #ref(Token, Token...)} if limit is 1, instead. */
public static DefinitionRef ref(final Token definition, final SingleValueExpression limit) { return new DefinitionRef(limit, definition); }
/** @see Ref */ public static DefinitionRef ref(final Token definition, final Token... definitions) { return new DefinitionRef(definition, definitions); }
/** @see Ref */ public static DefinitionRef ref(final SingleValueExpression limit, final Token definition, final Token... definitions) { return new DefinitionRef(limit, definition, definitions); }

/** @see First */ public static SingleValueExpression first(final ValueExpression operand) { return new First(operand); }
/** @see Last */ public static SingleValueExpression last(final ValueExpression operand) { return new Last(operand); }
/** @see Last */ public static SingleValueExpression last(final NameRef operand) { return new Last(new NameRef(operand.reference, con(1))); }
/** @see Last */ public static SingleValueExpression last(final DefinitionRef operand) { return new Last(new DefinitionRef(operand.reference, con(1))); }
/** @see Last */ public static SingleValueExpression last(final NameRef operand) { return new Last(operand.withLimit(con(1))); }
/** @see Last */ public static SingleValueExpression last(final DefinitionRef operand) { return new Last(operand.withLimit(con(1))); }
/** @see Nth */ public static ValueExpression nth(final ValueExpression values, final ValueExpression indices) { return new Nth(values, indices); }
/** @see Nth */ public static SingleValueExpression nth(final ValueExpression values, final SingleValueExpression index) { return last(new Nth(values, index)); }
/** @see Offset */ public static ValueExpression offset(final ValueExpression operand) { return new Offset(operand); }
Expand Down Expand Up @@ -341,7 +348,11 @@ private Shorthand() {}
public static BinaryValueExpression mapRight(final BiFunction<ValueExpression, ValueExpression, BinaryValueExpression> func, final SingleValueExpression leftExpand, final ValueExpression right) { return func.apply(exp(leftExpand, count(right)), right); }

/** @see Bytes */ public static ValueExpression bytes(final ValueExpression operand) { return new Bytes(operand); }
/** @see Scope */ public static ValueExpression scope(final ValueExpression scopedValueExpression, final SingleValueExpression scopeSize) { return new Scope(scopedValueExpression, scopeSize); }

/** @see Ref */ public static NameRef scope(final NameRef operand) { return scope(operand, con(0)); }
/** @see Ref */ public static NameRef scope(final NameRef operand, final SingleValueExpression scopeSize) { return operand.withScope(scopeSize); }
/** @see Ref */ public static DefinitionRef scope(final DefinitionRef operand) { return scope(operand, con(0)); }
/** @see Ref */ public static DefinitionRef scope(final DefinitionRef operand, final SingleValueExpression scopeSize) { return operand.withScope(scopeSize); }

/** @see And */ public static BinaryLogicalExpression and(final Expression left, final Expression right) { return new And(left, right); }
/** @see Or */ public static BinaryLogicalExpression or(final Expression left, final Expression right) { return new Or(left, right); }
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/io/parsingdata/metal/Trampoline.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013-2021 Netherlands Forensic Institute
* Copyright 2013-2024 Netherlands Forensic Institute
* Copyright 2021-2024 Infix Technologies B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/io/parsingdata/metal/Util.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013-2021 Netherlands Forensic Institute
* Copyright 2013-2024 Netherlands Forensic Institute
* Copyright 2021-2024 Infix Technologies B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/io/parsingdata/metal/data/ByteStream.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013-2021 Netherlands Forensic Institute
* Copyright 2013-2024 Netherlands Forensic Institute
* Copyright 2021-2024 Infix Technologies B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013-2021 Netherlands Forensic Institute
* Copyright 2013-2024 Netherlands Forensic Institute
* Copyright 2021-2024 Infix Technologies B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -64,7 +65,7 @@ public boolean equals(final Object obj) {
}

@Override
public int hashCode() {
public int immutableHashCode() {
return Objects.hash(getClass(), input);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013-2021 Netherlands Forensic Institute
* Copyright 2013-2024 Netherlands Forensic Institute
* Copyright 2021-2024 Infix Technologies B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +18,7 @@
package io.parsingdata.metal.data;

import static java.math.BigInteger.ZERO;
import static java.math.BigInteger.valueOf;

import static io.parsingdata.metal.Trampoline.complete;
import static io.parsingdata.metal.Trampoline.intermediate;
Expand Down Expand Up @@ -79,13 +81,15 @@ private Trampoline<byte[]> getData(final ImmutableList<Value> values, final BigI
if (length.compareTo(ZERO) <= 0) {
return complete(() -> output);
}
if (currentOffset.add(values.head.slice().length).compareTo(offset) <= 0) {
return intermediate(() -> getData(values.tail, currentOffset.add(values.head.slice().length), currentDest, offset, length, output));
final BigInteger nextOffset = currentOffset.add(values.head.slice().length);
if (nextOffset.compareTo(offset) <= 0) {
return intermediate(() -> getData(values.tail, nextOffset, currentDest, offset, length, output));
}
final BigInteger localOffset = offset.subtract(currentOffset).compareTo(ZERO) < 0 ? ZERO : offset.subtract(currentOffset);
final BigInteger toCopy = length.compareTo(values.head.slice().length.subtract(localOffset)) > 0 ? values.head.slice().length.subtract(localOffset) : length;
System.arraycopy(values.head.slice().getData(), localOffset.intValueExact(), output, currentDest.intValueExact(), toCopy.intValueExact());
return intermediate(() -> getData(values.tail, currentOffset.add(values.head.slice().length), currentDest.add(toCopy), offset, length.subtract(toCopy), output));
// The second argument in getData in Slice is a limit. It will return less if the end of slice is reached.
final byte[] data = values.head.slice().getData(localOffset, length);
System.arraycopy(data, 0, output, currentDest.intValueExact(), data.length);
return intermediate(() -> getData(values.tail, nextOffset, currentDest.add(valueOf(data.length)), offset, length.subtract(valueOf(data.length)), output));
}

@Override
Expand All @@ -106,7 +110,7 @@ public boolean equals(final Object obj) {
}

@Override
public int hashCode() {
public int immutableHashCode() {
return Objects.hash(getClass(), values, length);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013-2021 Netherlands Forensic Institute
* Copyright 2013-2024 Netherlands Forensic Institute
* Copyright 2021-2024 Infix Technologies B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -62,7 +63,7 @@ public boolean equals(final Object obj) {
}

@Override
public int hashCode() {
public int immutableHashCode() {
return Objects.hash(getClass(), Arrays.hashCode(data));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013-2021 Netherlands Forensic Institute
* Copyright 2013-2024 Netherlands Forensic Institute
* Copyright 2021-2024 Infix Technologies B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -102,7 +103,7 @@ public boolean equals(Object obj) {
}

@Override
public int hashCode() {
public int immutableHashCode() {
return Objects.hash(getClass(), dataExpression, index, parseState, encoding);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013-2021 Netherlands Forensic Institute
* Copyright 2013-2024 Netherlands Forensic Institute
* Copyright 2021-2024 Infix Technologies B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
12 changes: 7 additions & 5 deletions core/src/main/java/io/parsingdata/metal/data/ImmutableList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013-2021 Netherlands Forensic Institute
* Copyright 2013-2024 Netherlands Forensic Institute
* Copyright 2021-2024 Infix Technologies B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,10 +24,11 @@

import java.util.Objects;

import io.parsingdata.metal.ImmutableObject;
import io.parsingdata.metal.Trampoline;
import io.parsingdata.metal.Util;

public class ImmutableList<T> {
public class ImmutableList<T> extends ImmutableObject {

public final T head;
public final ImmutableList<T> tail;
Expand Down Expand Up @@ -98,13 +100,13 @@ public String toString() {
@Override
public boolean equals(final Object obj) {
return Util.notNullAndSameClass(this, obj)
&& Objects.equals(head, ((ImmutableList)obj).head)
&& Objects.equals(tail, ((ImmutableList)obj).tail);
&& Objects.equals(head, ((ImmutableList<?>)obj).head)
&& Objects.equals(tail, ((ImmutableList<?>)obj).tail);
// The size field is excluded from equals() and hashCode() because it is cached data.
}

@Override
public int hashCode() {
public int immutableHashCode() {
return Objects.hash(getClass(), head, tail);
}

Expand Down
12 changes: 7 additions & 5 deletions core/src/main/java/io/parsingdata/metal/data/ImmutablePair.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013-2021 Netherlands Forensic Institute
* Copyright 2013-2024 Netherlands Forensic Institute
* Copyright 2021-2024 Infix Technologies B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,9 +21,10 @@

import java.util.Objects;

import io.parsingdata.metal.ImmutableObject;
import io.parsingdata.metal.Util;

public class ImmutablePair<L, R> {
public class ImmutablePair<L, R> extends ImmutableObject {

public final L left;
public final R right;
Expand All @@ -40,12 +42,12 @@ public String toString() {
@Override
public boolean equals(final Object obj) {
return Util.notNullAndSameClass(this, obj)
&& Objects.equals(left, ((ImmutablePair)obj).left)
&& Objects.equals(right, ((ImmutablePair)obj).right);
&& Objects.equals(left, ((ImmutablePair<?, ?>)obj).left)
&& Objects.equals(right, ((ImmutablePair<?, ?>)obj).right);
}

@Override
public int hashCode() {
public int immutableHashCode() {
return Objects.hash(getClass(), left, right);
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/main/java/io/parsingdata/metal/data/ParseGraph.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013-2021 Netherlands Forensic Institute
* Copyright 2013-2024 Netherlands Forensic Institute
* Copyright 2021-2024 Infix Technologies B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,11 +24,12 @@
import java.util.Objects;
import java.util.Optional;

import io.parsingdata.metal.ImmutableObject;
import io.parsingdata.metal.Trampoline;
import io.parsingdata.metal.Util;
import io.parsingdata.metal.token.Token;

public class ParseGraph implements ParseItem {
public class ParseGraph extends ImmutableObject implements ParseItem {

public final ParseItem head;
public final ParseGraph tail;
Expand Down Expand Up @@ -143,7 +145,7 @@ public boolean equals(final Object obj) {
}

@Override
public int hashCode() {
public int immutableHashCode() {
return Objects.hash(getClass(), head, tail, branched, definition);
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/io/parsingdata/metal/data/ParseItem.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013-2021 Netherlands Forensic Institute
* Copyright 2013-2024 Netherlands Forensic Institute
* Copyright 2021-2024 Infix Technologies B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit d09d3e1

Please sign in to comment.