Skip to content

Commit

Permalink
Merge branch 'master' into use-kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
popematt authored Aug 1, 2023
2 parents 2dee83b + 3e8f8e2 commit aa6839b
Show file tree
Hide file tree
Showing 13 changed files with 344 additions and 104 deletions.
34 changes: 0 additions & 34 deletions .github/workflows/PR-content-check.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -49,7 +49,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -63,4 +63,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
10 changes: 4 additions & 6 deletions .github/workflows/ion-java-performance-regression-detector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@

name: Ion Java performance regression detector

on: [pull_request]
on:
pull_request:
paths:
- 'src/*'

jobs:
PR-Content-Check:
uses: amazon-ion/ion-java/.github/workflows/PR-content-check.yml@master

detect-regression:
name: Detect Regression
needs: PR-Content-Check
if: ${{ needs.PR-Content-Check.outputs.result == 'pass' }}
runs-on: ubuntu-latest

steps:
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/ion-test-driver.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
name: ion-test-driver

on: [pull_request]
on:
pull_request:
paths:
- 'src/*'

jobs:
PR-Content-Check:
uses: amazon-ion/ion-java/.github/workflows/PR-content-check.yml@master

ion-test-driver:
runs-on: ubuntu-latest
needs: PR-Content-Check
if: ${{ needs.PR-Content-Check.outputs.result == 'pass' }}
steps:
- name: Checkout ion-java
uses: actions/checkout@master
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
strategy:
matrix:
include:
- java: 8
upload_reports: true
- java: 11
upload_reports: true
- java: 17
fail-fast: false
steps:
- uses: actions/checkout@v2
Expand All @@ -34,6 +34,10 @@ jobs:
uses: codecov/codecov-action@v3
with:
files: build/reports/jacoco/test/jacocoTestReport.xml
- uses: actions/upload-artifact@v3
with:
name: spotbugs-report
path: build/reports/spotbugs/

check-version:
# Ensures that the version is not a release (i.e. -SNAPSHOT) or if it is a release version,
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ jobs:
runs-on: ubuntu-latest
needs: check-version
if: ${{ needs.check-version.outputs.should_create_draft == 'true' }}
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- name: Create a draft release
Expand Down
19 changes: 2 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,8 @@ For detailed walkthroughs of git submodule usage, see the

### Depending on the Library

To start using `ion-java` in your code with Maven, insert the following
dependency into your project's `pom.xml`:

```xml
<dependency>
<groupId>com.amazon.ion</groupId>
<artifactId>ion-java</artifactId>
<version>1.10.0</version>
</dependency>
```

For Gradle (Kotlin DSL), use:
```kotlin
dependencies {
implementation("com.amazon.ion:ion-java:1.10.0")
}
```
To start using `ion-java` in your code, refer to [`ion-java` on Maven Central](https://central.sonatype.com/artifact/com.amazon.ion/ion-java)
to find snippets for adding a dependency on the latest version of the library using your favorite build tool.

#### Legacy group id

Expand Down
15 changes: 7 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ group = "com.amazon.ion"
// and so that any tool can access the version without having to do any special parsing.
version = File(project.rootDir.path + "/project.version").readLines().single()
description = "A Java implementation of the Amazon Ion data notation."
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8

val isReleaseVersion: Boolean = !version.toString().endsWith("SNAPSHOT")
val generatedResourcesDir = "${buildDir}/generated/main/resources"
Expand Down Expand Up @@ -92,7 +90,9 @@ licenseReport {
tasks {
withType<JavaCompile> {
options.encoding = "UTF-8"
// In Java 9+ we can use `release` but for now we're still building with JDK 8, 11
// Because we set the `release` option, you can no longer build ion-java using JDK 8. However, we continue to
// emit JDK 8 compatible classes due to widespread use of this library with JDK 8.
options.release.set(8)
}

jar {
Expand Down Expand Up @@ -138,6 +138,8 @@ tasks {
this as StandardJavadocDocletOptions
addBooleanOption("Xdoclint:none", true)
addStringOption("Xmaxwarns", "1") // best we can do is limit warnings to 1
// Stops jquery from being included as a bundled dependency
this.noIndex(true)
}
}

Expand All @@ -148,9 +150,6 @@ tasks {
spotbugsMain {
val spotbugsBaselineFile = "$rootDir/config/spotbugs/baseline.xml"

// CI=true means we're in a CI workflow
// https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
val ciWorkflow = System.getenv()["CI"].toBoolean()
val baselining = project.hasProperty("baseline") // e.g. `./gradlew :spotbugsMain -Pbaseline`

if (!baselining) {
Expand All @@ -159,9 +158,9 @@ tasks {

// The plugin only prints to console when no reports are configured
// See: https://github.com/spotbugs/spotbugs-gradle-plugin/issues/172
if (!ciWorkflow && !baselining) {
if (!baselining) {
reports.create("html").required.set(true)
} else if (baselining) {
} else {
// Note this path succeeds :spotbugsMain because *of course it does*
ignoreFailures = true
reports.create("xml") {
Expand Down
2 changes: 1 addition & 1 deletion project.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.0
1.10.3-SNAPSHOT
26 changes: 22 additions & 4 deletions src/com/amazon/ion/impl/IonReaderTextRawTokensX.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.amazon.ion.impl.UnifiedSavePointManagerX.SavePoint;
import com.amazon.ion.util.IonTextUtils;
import java.io.IOException;
import java.util.ArrayList;

/**
* Tokenizer for the Ion text parser in IonTextIterator. This
Expand Down Expand Up @@ -107,6 +108,10 @@ public Appendable append(char c) throws IOException
*/
private int _base64_prefetch_stack;

// This value was chosen somewhat arbitrarily; it can/should be changed if it is found to be insufficient.
private static final int CONTAINER_STACK_INITIAL_CAPACITY = 16;
// Used for tracking terminator characters when skipping a container
private final ArrayList<Integer> containerSkipTerminatorStack = new ArrayList<>(CONTAINER_STACK_INITIAL_CAPACITY);

/**
* IonTokenReader constructor requires a UnifiedInputStream
Expand Down Expand Up @@ -1206,6 +1211,11 @@ protected void skip_over_sexp() throws IOException
private void skip_over_container(int terminator) throws IOException
{
assert( terminator == '}' || terminator == ']' || terminator == ')' );

// In theory, this should be empty at the start and end of every call to this
// method, but we'll clear it here anyway just in case.
containerSkipTerminatorStack.clear();

int c;

for (;;) {
Expand All @@ -1217,7 +1227,12 @@ private void skip_over_container(int terminator) throws IOException
case ']':
case ')':
if (c == terminator) { // no point is checking this on every char
return;
if (containerSkipTerminatorStack.isEmpty()) {
return;
} else {
// Pop one off the stack to continue
terminator = containerSkipTerminatorStack.remove(containerSkipTerminatorStack.size() - 1);
}
}
break;
case '"':
Expand All @@ -1233,10 +1248,12 @@ private void skip_over_container(int terminator) throws IOException
}
break;
case '(':
skip_over_container(')');
containerSkipTerminatorStack.add(terminator);
terminator = ')';
break;
case '[':
skip_over_container(']');
containerSkipTerminatorStack.add(terminator);
terminator = ']';
break;
case '{':
// this consumes lobs as well since the double
Expand Down Expand Up @@ -1273,7 +1290,8 @@ else if (c == '}') {
}
else {
unread_char(c);
skip_over_container('}');
containerSkipTerminatorStack.add(terminator);
terminator = '}';
}
break;
default:
Expand Down
33 changes: 10 additions & 23 deletions src/com/amazon/ion/impl/bin/IonRawBinaryWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,23 +308,20 @@ private static class PatchPoint
public final long oldPosition;
/** length of the data being patched out.*/
public final int oldLength;
/** position of the patch buffer where the length data is stored. */
public final long patchPosition;
/** length of the data to be patched in.*/
public final int patchLength;
/** size of the container data or annotations.*/
public final long length;

public PatchPoint(final long oldPosition, final int oldLength, final long patchPosition, final int patchLength)
public PatchPoint(final long oldPosition, final int oldLength, final long patchLength)
{
this.oldPosition = oldPosition;
this.oldLength = oldLength;
this.patchPosition = patchPosition;
this.patchLength = patchLength;
this.length = patchLength;
}

@Override
public String toString()
{
return "(PP old::(" + oldPosition + " " + oldLength + ") patch::(" + patchPosition + " " + patchLength + ")";
return "(PP old::(" + oldPosition + " " + oldLength + ") patch::(" + length + ")";
}
}

Expand Down Expand Up @@ -490,7 +487,6 @@ public String toString()
private final PreallocationMode preallocationMode;
private final boolean isFloatBinary32Enabled;
private final WriteBuffer buffer;
private final WriteBuffer patchBuffer;
private final PatchList patchPoints;
private final _Private_RecyclingStack<ContainerInfo> containers;
private int depth;
Expand Down Expand Up @@ -525,7 +521,6 @@ public String toString()
this.preallocationMode = preallocationMode;
this.isFloatBinary32Enabled = isFloatBinary32Enabled;
this.buffer = new WriteBuffer(allocator);
this.patchBuffer = new WriteBuffer(allocator);
this.patchPoints = new PatchList();
this.containers = new _Private_RecyclingStack<ContainerInfo>(
10,
Expand Down Expand Up @@ -699,10 +694,9 @@ private void pushContainer(final ContainerType type)

private void addPatchPoint(final long position, final int oldLength, final long value)
{
// record the size in a patch buffer
final long patchPosition = patchBuffer.position();
final int patchLength = patchBuffer.writeVarUInt(value);
final PatchPoint patch = new PatchPoint(position, oldLength, patchPosition, patchLength);
// record the length of the patch
final int patchLength = WriteBuffer.varUIntLength(value);
final PatchPoint patch = new PatchPoint(position, oldLength, value);
if (containers.isEmpty())
{
// not nested, just append to the root list
Expand Down Expand Up @@ -1489,12 +1483,7 @@ public void writeBytes(byte[] data, int offset, int length) throws IOException
/*package*/ void truncate(long position)
{
buffer.truncate(position);
// TODO decide if it is worth making this faster than O(N)
final PatchPoint patch = patchPoints.truncate(position);
if (patch != null)
{
patchBuffer.truncate(patch.patchPosition);
}
patchPoints.truncate(position);
}

public void flush() throws IOException {}
Expand Down Expand Up @@ -1525,7 +1514,7 @@ public void finish() throws IOException
buffer.writeTo(out, bufferPosition, bufferLength);

// write out the patch
patchBuffer.writeTo(out, patch.patchPosition, patch.patchLength);
WriteBuffer.writeVarUIntTo(out, patch.length);

// skip over the preallocated varuint field
bufferPosition = patch.oldPosition;
Expand All @@ -1534,7 +1523,6 @@ public void finish() throws IOException
buffer.writeTo(out, bufferPosition, buffer.position() - bufferPosition);
}
patchPoints.clear();
patchBuffer.reset();
buffer.reset();

if (streamFlushMode == StreamFlushMode.FLUSH)
Expand Down Expand Up @@ -1564,7 +1552,6 @@ public void close() throws IOException

// release all of our blocks -- these should never throw
buffer.close();
patchBuffer.close();
allocator.close();
utf8StringEncoder.close();
}
Expand Down
Loading

0 comments on commit aa6839b

Please sign in to comment.