Skip to content

Commit

Permalink
Finish swapping to use kotlinc
Browse files Browse the repository at this point in the history
  • Loading branch information
popematt committed Nov 7, 2023
1 parent 68207ba commit 1282cab
Show file tree
Hide file tree
Showing 26 changed files with 98 additions and 77 deletions.
17 changes: 17 additions & 0 deletions THIRD_PARTY_LICENSES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

# ion-java
## Dependency License Report

## Apache License, Version 2.0

**1** **Group:** `org.jetbrains` **Name:** `annotations` **Version:** `13.0`
> - **POM Project URL**: [http://www.jetbrains.org](http://www.jetbrains.org)
> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
**2** **Group:** `org.jetbrains.kotlin` **Name:** `kotlin-stdlib` **Version:** `1.9.0`
> - **POM Project URL**: [https://kotlinlang.org/](https://kotlinlang.org/)
> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
**3** **Group:** `org.jetbrains.kotlin` **Name:** `kotlin-stdlib-common` **Version:** `1.9.0`
> - **POM Project URL**: [https://kotlinlang.org/](https://kotlinlang.org/)
> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
84 changes: 68 additions & 16 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import com.github.jk1.license.filter.LicenseBundleNormalizer
import com.github.jk1.license.render.InventoryMarkdownReportRenderer
import com.github.jk1.license.render.TextReportRenderer
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
import java.net.URI
Expand All @@ -18,7 +21,8 @@ plugins {
// TODO: more static analysis. E.g.:
// id("com.diffplug.spotless") version "6.11.0"

id("com.github.jk1.dependency-license-report") version "2.4"
// Used for generating the third party attribution document
id("com.github.jk1.dependency-license-report") version "2.5"
}

jacoco {
Expand All @@ -30,6 +34,10 @@ repositories {
google()
}

/**
* This is a configuration (like `testImplementation`) so that we can create a class path for
* running the r8 jar.
*/
val r8Classpath = configurations.create("r8Task")

dependencies {
Expand Down Expand Up @@ -67,23 +75,18 @@ sourceSets {
}

licenseReport {
// Because of the current gradle project structure, we must explicitly exclude ion-java-cli, even
// though ion-java does not depend on ion-java-cli. By default, the license report generator includes
// the current project (ion-java) and all its subprojects.
projects = arrayOf(project)
outputDir = "$buildDir/reports/licenses"
renderers = arrayOf(
com.github.jk1.license.render.InventoryMarkdownReportRenderer("THIRD-PARTY-LICENSES.md"),
com.github.jk1.license.render.TextReportRenderer(),
)

renderers = arrayOf(InventoryMarkdownReportRenderer(), TextReportRenderer())
// Dependencies use inconsistent titles for Apache-2.0, so we need to specify mappings
filters = arrayOf(
com.github.jk1.license.filter.LicenseBundleNormalizer(
LicenseBundleNormalizer(
mapOf(
"Apache License, Version 2.0" to "Apache-2.0",
"The Apache License, Version 2.0" to "Apache-2.0",
"The Apache Software License, Version 2.0" to "Apache-2.0",
"BSD Zero Clause License" to "0BSD",
"Eclipse Public License 2.0" to "EPL-2.0",
"Eclipse Public License v. 2.0" to "EPL-2.0",
"GNU General Public License, version 2 with the GNU Classpath Exception" to "GPL-2.0 WITH Classpath-exception-2.0",
"COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0" to "CDDL-1.0"
)
)
)
Expand All @@ -94,7 +97,7 @@ tasks {
options.encoding = "UTF-8"
// 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)
options.release.set(8)
}
withType<KotlinCompile<KotlinJvmOptions>> {
kotlinOptions {
Expand All @@ -107,6 +110,8 @@ tasks {
archiveClassifier.set("original")
}

// Creates a super jar of ion-java and its dependencies where all dependencies are shaded (moved)
// to com.amazon.ion_.shaded
shadowJar {
archiveClassifier.set("shaded")
dependsOn(generateLicenseReport)
Expand All @@ -116,7 +121,13 @@ tasks {
minimize()
}

/**
* The `minifyJar` task uses [R8](https://developer.android.com/build/shrink-code) to create a JAR
* that is smaller than the combined size of ion-java and its dependencies. This is the final JAR
* that is published to maven central.
*/
val minifyJar by register<JavaExec>("minifyJar") {
group = "build"
val rulesPath = file("config/r8/rules.txt")
val inputJarPath = shadowJar.get().outputs.files.singleFile
val outputJarPath = "build/libs/ion-java-$version.jar"
Expand All @@ -128,6 +139,7 @@ tasks {
outputs.file(outputJarPath)
dependsOn(shadowJar)
dependsOn(configurations.runtimeClasspath)
build.get().dependsOn(this)
classpath(r8Classpath)

// These lines tell gradle how to run the task
Expand All @@ -142,8 +154,48 @@ tasks {
)
}

build {
dependsOn(minifyJar)
generateLicenseReport {
doLast {
// We don't want the time in the generated markdown report because that makes it unstable for
// our verification of the THIRD_PARTY_LICENSES file.
val markdownReport = outputs.files.single().walk().single { it.path.endsWith(".md") }
val dateRegex = Regex("^_\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2} \\w+_$")
// Reads the content of the markdown report, replacing the date line with an empty line, and
// trimming extra whitespace from the end of all other lines.
val newMarkdownContent = markdownReport.readLines()
.joinToString("\n") { if (it.matches(dateRegex)) "" else it.trimEnd() }
markdownReport.writeText(newMarkdownContent)
}
}

// Task to check whether the THIRD_PARTY_LICENSES file is still up-to-date.
task("checkThirdPartyLicensesFile") {
val thirdPartyLicensesFileName = "THIRD_PARTY_LICENSES.md"
val thirdPartyLicensesPath = "$rootDir/$thirdPartyLicensesFileName"
check.get().dependsOn(this)
dependsOn(generateLicenseReport)
inputs.file(thirdPartyLicensesPath)
group = "verification"
description = "Verifies that $thirdPartyLicensesFileName is up-to-date."
doLast {
val generatedMarkdownReport = generateLicenseReport.get().outputs.files.single()
.walk().single { it.path.endsWith(".md") }
val generatedMarkdownReportContent = generatedMarkdownReport.readLines()
.filter { it.isNotBlank() }
.joinToString("\n")

val sourceControlledMarkdownReport = File(thirdPartyLicensesPath)
val sourceControlledMarkdownReportContent = sourceControlledMarkdownReport.readLines()
.filter { it.isNotBlank() }
.joinToString("\n")

if (sourceControlledMarkdownReportContent != generatedMarkdownReportContent) {
throw IllegalStateException(
"$thirdPartyLicensesPath is out of date.\n" +
"Please replace the file content with the content of $generatedMarkdownReport."
)
}
}
}

javadoc {
Expand Down
16 changes: 6 additions & 10 deletions src/com/amazon/ion/impl/IonIteratorImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
*/
package com.amazon.ion.impl

import com.amazon.ion.IonList
import com.amazon.ion.IonReader
import com.amazon.ion.IonSexp
import com.amazon.ion.IonStruct
import com.amazon.ion.IonType
import com.amazon.ion.IonValue
import com.amazon.ion.ValueFactory

/**
* An [Iterator] that wraps an [IonReader] and emits [IonValue]s.
*/
internal class IonIteratorImpl(private val _valueFactory: ValueFactory, private val _reader: IonReader) : MutableIterator<IonValue> {

private var _at_eof = false
Expand Down Expand Up @@ -66,9 +66,9 @@ internal class IonIteratorImpl(private val _valueFactory: ValueFactory, private
IonType.SYMBOL -> _valueFactory.newSymbol(_reader.symbolValue())
IonType.BLOB -> _valueFactory.newNullBlob().apply { bytes = _reader.newBytes() }
IonType.CLOB -> _valueFactory.newNullClob().apply { bytes = _reader.newBytes() }

Check warning on line 68 in src/com/amazon/ion/impl/IonIteratorImpl.kt

View check run for this annotation

Codecov / codecov/patch

src/com/amazon/ion/impl/IonIteratorImpl.kt#L67-L68

Added lines #L67 - L68 were not covered by tests
IonType.STRUCT -> _valueFactory.buildStruct { _reader.forEachInContainer { add(fieldNameSymbol, readValue()) } }
IonType.LIST -> _valueFactory.buildList { _reader.forEachInContainer { add(readValue()) } }
IonType.SEXP -> _valueFactory.buildSexp { _reader.forEachInContainer { add(readValue()) } }
IonType.STRUCT -> _valueFactory.newEmptyStruct().apply { _reader.forEachInContainer { add(fieldNameSymbol, readValue()) } }
IonType.LIST -> _valueFactory.newEmptyList().apply { _reader.forEachInContainer { add(readValue()) } }
IonType.SEXP -> _valueFactory.newEmptySexp().apply { _reader.forEachInContainer { add(readValue()) } }
else -> throw IllegalStateException()

Check warning on line 72 in src/com/amazon/ion/impl/IonIteratorImpl.kt

View check run for this annotation

Codecov / codecov/patch

src/com/amazon/ion/impl/IonIteratorImpl.kt#L72

Added line #L72 was not covered by tests
}
}
Expand Down Expand Up @@ -96,8 +96,4 @@ internal class IonIteratorImpl(private val _valueFactory: ValueFactory, private
while (next() != null) { block() }
stepOut()
}

Check warning on line 98 in src/com/amazon/ion/impl/IonIteratorImpl.kt

View check run for this annotation

Codecov / codecov/patch

src/com/amazon/ion/impl/IonIteratorImpl.kt#L97-L98

Added lines #L97 - L98 were not covered by tests

private inline fun ValueFactory.buildList(init: IonList.() -> Unit): IonList = newEmptyList().apply(init)
private inline fun ValueFactory.buildSexp(init: IonSexp.() -> Unit): IonSexp = newEmptySexp().apply(init)
private inline fun ValueFactory.buildStruct(init: IonStruct.() -> Unit): IonStruct = newEmptyStruct().apply(init)
}
1 change: 0 additions & 1 deletion src/com/amazon/ion/impl/IonReaderTreeUserX.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import com.amazon.ion.IonCatalog;
import com.amazon.ion.IonDatagram;
import com.amazon.ion.IonReader;
import com.amazon.ion.IonStruct;
import com.amazon.ion.IonSymbol;
import com.amazon.ion.IonType;
Expand Down
1 change: 0 additions & 1 deletion src/com/amazon/ion/impl/IonWriterUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.amazon.ion.impl;

import static com.amazon.ion.SystemSymbols.ION_SYMBOL_TABLE;
import static com.amazon.ion.SystemSymbols.ION_SYMBOL_TABLE_SID;

import com.amazon.ion.IonCatalog;
import com.amazon.ion.IonException;
Expand Down
1 change: 0 additions & 1 deletion src/com/amazon/ion/impl/LocalSymbolTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import com.amazon.ion.util.IonTextUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down
1 change: 0 additions & 1 deletion src/com/amazon/ion/impl/_Private_IonReaderBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.SequenceInputStream;
import java.util.zip.GZIPInputStream;

import static com.amazon.ion.impl.LocalSymbolTable.DEFAULT_LST_FACTORY;
Expand Down
2 changes: 0 additions & 2 deletions src/com/amazon/ion/impl/bin/IonRawBinaryWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;

/**
Expand Down
4 changes: 1 addition & 3 deletions src/com/amazon/ion/impl/lite/IonSequenceLite.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@

import com.amazon.ion.ContainedValueException;
import com.amazon.ion.IonSequence;
import com.amazon.ion.IonType;
import com.amazon.ion.IonValue;
import com.amazon.ion.IonWriter;
import com.amazon.ion.ValueFactory;
import com.amazon.ion.impl._Private_CurriedValueFactory;
import com.amazon.ion.impl._Private_IonValue;
import java.io.IOException;

import java.lang.reflect.Array;
import java.util.AbstractList;
import java.util.ArrayList;
Expand Down
5 changes: 1 addition & 4 deletions src/com/amazon/ion/impl/lite/IonStructLite.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,17 @@
import com.amazon.ion.IonStruct;
import com.amazon.ion.IonType;
import com.amazon.ion.IonValue;
import com.amazon.ion.IonWriter;
import com.amazon.ion.SymbolToken;
import com.amazon.ion.ValueFactory;
import com.amazon.ion.ValueVisitor;
import com.amazon.ion.impl._Private_CurriedValueFactory;
import com.amazon.ion.util.Equivalence;
import com.amazon.ion.UnknownSymbolException;
import java.io.IOException;

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
Expand Down
7 changes: 1 addition & 6 deletions src/com/amazon/ion/util/JarInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

import com.amazon.ion.IonException;
import com.amazon.ion.Timestamp;

Expand Down
1 change: 0 additions & 1 deletion test/com/amazon/ion/BinaryReaderSystemProcessingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;

import static com.amazon.ion.SystemSymbols.ION_1_0;
import static com.amazon.ion.SystemSymbols.ION_1_0_SID;
Expand Down
2 changes: 0 additions & 2 deletions test/com/amazon/ion/BinaryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

import static com.amazon.ion.SystemSymbols.ION_SYMBOL_TABLE_SID;

import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;

import org.junit.Test;

Expand Down
2 changes: 1 addition & 1 deletion test/com/amazon/ion/BlobTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.amazon.ion;

import static com.amazon.ion.TestUtils.US_ASCII_CHARSET;
import static com.amazon.ion.impl._Private_Utils.encode;

import com.amazon.ion.impl._Private_Utils;
import java.io.IOException;
import java.io.InputStream;
Expand Down
1 change: 0 additions & 1 deletion test/com/amazon/ion/IonTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.amazon.ion.system.IonSystemBuilder;
import com.amazon.ion.system.SimpleCatalog;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
Expand Down
2 changes: 0 additions & 2 deletions test/com/amazon/ion/IonValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;


Expand Down
1 change: 0 additions & 1 deletion test/com/amazon/ion/StructTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.ListIterator;
import java.util.Random;

import com.amazon.ion.system.IonSystemBuilder;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand Down
1 change: 0 additions & 1 deletion test/com/amazon/ion/impl/BinaryWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

package com.amazon.ion.impl;

import com.amazon.ion.IonCatalog;
import com.amazon.ion.IonException;
import com.amazon.ion.IonReader;
import com.amazon.ion.IonType;
Expand Down
8 changes: 0 additions & 8 deletions test/com/amazon/ion/impl/IonReaderBinaryRawStringTest.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
package com.amazon.ion.impl;

import com.amazon.ion.IonReader;
import com.amazon.ion.IonType;
import com.amazon.ion.IonWriter;
import com.amazon.ion.Timestamp;
import com.amazon.ion.system.IonBinaryWriterBuilder;
import com.amazon.ion.system.IonReaderBuilder;
import com.amazon.ion.util.RepeatInputStream;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.SequenceInputStream;
import java.math.BigDecimal;

import static com.amazon.ion.impl._Private_IonConstants.BINARY_VERSION_MARKER_1_0;
import static org.junit.Assert.assertEquals;

public class IonReaderBinaryRawStringTest {
Expand Down
Loading

0 comments on commit 1282cab

Please sign in to comment.