Skip to content

Commit

Permalink
Add immutables library (#740)
Browse files Browse the repository at this point in the history
This PR introduces the Immutables library:

https://immutables.github.io/

This library is widely used in Iceberg and many other projects. The ability to define immutable components in an easy way, without struggling with the nitty-gritty details (getters, builders, equals, hashCode, toString, etc.) is a nice productivity boost and improves code correctness by enforcing immutability by default. Unlike Java records, collections in immutable values are immutable as well. Immutable value also have extensive support for builders, which removes a lot of manual duplicated boilerplate code.

This PR only adds the library, it is effectively a re-incarnation of #282.
  • Loading branch information
snazy authored Jan 14, 2025
1 parent 9578c14 commit 8aa8fc3
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ hadoop = "3.4.1"
iceberg = "1.7.1"
junit = "5.11.4"
quarkus = "3.17.6"
immutables = "2.10.1"
picocli = "4.7.6"
slf4j = "2.0.16"
swagger = "1.6.14"
Expand Down Expand Up @@ -54,6 +55,9 @@ hadoop-client-api = { module = "org.apache.hadoop:hadoop-client-api", version.re
hadoop-client-runtime = { module = "org.apache.hadoop:hadoop-client-runtime", version.ref = "hadoop" }
hadoop-common = { module = "org.apache.hadoop:hadoop-common", version.ref = "hadoop" }
hadoop-hdfs-client = { module = "org.apache.hadoop:hadoop-hdfs-client", version.ref = "hadoop" }
immutables-builder = { module = "org.immutables:builder", version.ref = "immutables" }
immutables-value-annotations = { module = "org.immutables:value-annotations", version.ref = "immutables" }
immutables-value-processor = { module = "org.immutables:value-processor", version.ref = "immutables" }
iceberg-bom = { module = "org.apache.iceberg:iceberg-bom", version.ref = "iceberg" }
jackson-bom = { module = "com.fasterxml.jackson:jackson-bom", version = "2.18.2" }
jakarta-annotation-api = { module = "jakarta.annotation:jakarta.annotation-api", version = "3.0.0" }
Expand Down
1 change: 1 addition & 0 deletions gradle/projects.main.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ polaris-eclipselink=extension/persistence/eclipselink
polaris-jpa-model=extension/persistence/jpa-model
polaris-tests=integration-tests
aggregated-license-report=aggregated-license-report
polaris-immutables=tools/immutables
polaris-container-spec-helper=tools/container-spec-helper
polaris-version=tools/version

Expand Down
32 changes: 32 additions & 0 deletions tools/immutables/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

plugins { id("polaris-client") }

val processor by configurations.creating

processor.extendsFrom(configurations.api.get())

dependencies {
api(libs.immutables.builder)
api(libs.immutables.value.annotations)

processor(libs.immutables.value.processor)
processor(project)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.polaris.immutables;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import org.immutables.value.Value;

/**
* A <a href="http://immutables.github.io/style.html#custom-immutable-annotation">Custom
* {@code @Value.Immutable}</a> with a project-wide common style.
*/
@Documented
@Target(ElementType.TYPE)
@Value.Style(
defaults = @Value.Immutable(lazyhash = true),
forceJacksonPropertyNames = false,
clearBuilder = true,
depluralize = true,
toBuilder = "toBuilder",
get = {"get*", "is*"})
public @interface PolarisImmutable {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

org.apache.polaris.immutables.PolarisImmutable
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

javax.annotation.Nullable
javax.annotation.CheckReturnValue;
javax.annotation.Nullable;
javax.annotation.ParametersAreNonnullByDefault;
javax.annotation.concurrent.Immutable;
javax.annotation.concurrent.NotThreadSafe;

0 comments on commit 8aa8fc3

Please sign in to comment.