Skip to content

Commit

Permalink
apacheGH-39214: [Java] Support reproducible build
Browse files Browse the repository at this point in the history
  • Loading branch information
jbonofre committed Jan 2, 2024
1 parent 2f63ab9 commit cb22662
Show file tree
Hide file tree
Showing 26 changed files with 146 additions and 56 deletions.
21 changes: 10 additions & 11 deletions dev/release/01-prepare-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,17 @@ def test_version_pre_tag
end

Dir.glob("java/**/pom.xml") do |path|
version = "<version>#{@snapshot_version}</version>"
lines = File.readlines(path, chomp: true)
target_lines = lines.grep(/#{Regexp.escape(version)}/)
hunks = []
target_lines.each do |line|
new_line = line.gsub(@snapshot_version) do
@release_version
hunks = generate_hunks(File.readlines(path, chomp: true)) do |line|
if line.include?("<version>#{@snapshot_version}</version>")
new_line = line.gsub(@snapshot_version) do
@release_version
end
[line, new_line]
elsif line.include?("<project.build.outputTimestamp>")
[line, normalize_pom_xml_output_timestamp(line)]
else
[nil, nil]
end
hunks << [
"-#{line}",
"+#{new_line}",
]
end
expected_changes << {hunks: hunks, path: path}
end
Expand Down
53 changes: 17 additions & 36 deletions dev/release/post-11-bump-versions-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,37 +244,19 @@ def test_version_post_tag
end

import_path = "github.com/apache/arrow/go/v#{@snapshot_major_version}"
hunks = []
if release_type == :major
lines = File.readlines(path, chomp: true)
target_lines = lines.each_with_index.select do |line, i|
line.include?(import_path)
end
next if target_lines.empty?
n_context_lines = 3 # The default of Git's diff.context
target_hunks = [[target_lines.first[0]]]
previous_i = target_lines.first[1]
target_lines[1..-1].each do |line, i|
if i - previous_i < n_context_lines
target_hunks.last << line
else
target_hunks << [line]
end
previous_i = i
end
target_hunks.each do |lines|
hunk = []
lines.each do |line,|
hunk << "-#{line}"
end
lines.each do |line|
hunks = generate_hunks(File.readlines(path, chomp: true)) do |line|
if line.include?(import_path)
new_line = line.gsub("v#{@snapshot_major_version}") do
"v#{@next_major_version}"
end
hunk << "+#{new_line}"
[line, new_line]
else
[nil, nil]
end
hunks << hunk
end
else
hunks = []
end
if path == "go/parquet/writer_properties.go"
hunks << [
Expand All @@ -287,18 +269,17 @@ def test_version_post_tag
end

Dir.glob("java/**/pom.xml") do |path|
version = "<version>#{@snapshot_version}</version>"
lines = File.readlines(path, chomp: true)
target_lines = lines.grep(/#{Regexp.escape(version)}/)
hunks = []
target_lines.each do |line|
new_line = line.gsub(@snapshot_version) do
@next_snapshot_version
hunks = generate_hunks(File.readlines(path, chomp: true)) do |line|
if line.include?("<version>#{@snapshot_version}</version>")
new_line = line.gsub(@snapshot_version) do
@next_snapshot_version
end
[line, new_line]
elsif line.include?("<project.build.outputTimestamp>")
[line, normalize_pom_xml_output_timestamp(line)]
else
[nil, nil]
end
hunks << [
"-#{line}",
"+#{new_line}",
]
end
expected_changes << {hunks: hunks, path: path}
end
Expand Down
47 changes: 46 additions & 1 deletion dev/release/test-helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,60 @@ def parse_patch(patch)
when /\A@@/
in_hunk = true
diffs.last[:hunks] << []
when /\A[-+]/
when /\A-/
next unless in_hunk
diffs.last[:hunks].last << line.chomp
when /\A\+/
next unless in_hunk
diffs.last[:hunks].last << normalize_added_line(line.chomp)
end
end
diffs.sort_by do |diff|
diff[:path]
end
end

def generate_hunks(lines)
git_diff_context = 3 # The default of Git's diff.context
max_lines_for_same_hunk = git_diff_context * 2 + 1
previous_i = nil
grouped_change_blocks = []
lines.each_with_index do |line, i|
deleted, added = yield(line)
next if deleted.nil? and added.nil?
if previous_i.nil? or (i - previous_i) > max_lines_for_same_hunk
grouped_change_blocks << []
end
if i - 1 != previous_i
grouped_change_blocks.last << []
end
grouped_change_blocks.last.last << [deleted, added]
previous_i = i
end
grouped_change_blocks.collect do |change_blocks|
hunk = []
change_blocks.each do |continuous_changes|
continuous_changes.each do |deleted, _|
hunk << "-#{deleted}" if deleted
end
continuous_changes.each do |_, added|
hunk << "+#{added}" if added
end
end
hunk
end
end

def normalize_pom_xml_output_timestamp(line)
line.gsub(/<project\.build\.outputTimestamp>.+?</) do
"<project.build.outputTimestamp>2023-12-13T00:00:00Z<"
end
end

def normalize_added_line(line)
normalize_pom_xml_output_timestamp(line)
end

end

module VersionDetectable
Expand Down
4 changes: 4 additions & 0 deletions java/adapter/avro/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<description>(Contrib/Experimental) A library for converting Avro data to Arrow data.</description>
<url>http://maven.apache.org</url>

<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
</properties>

<dependencies>

<!-- https://mvnrepository.com/artifact/org.apache.arrow/arrow-memory-core -->
Expand Down
4 changes: 4 additions & 0 deletions java/adapter/jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<description>(Contrib/Experimental)A library for converting JDBC data to Arrow data.</description>
<url>http://maven.apache.org</url>

<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
</properties>

<dependencies>

<!-- https://mvnrepository.com/artifact/org.apache.arrow/arrow-memory-core -->
Expand Down
4 changes: 4 additions & 0 deletions java/algorithm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<name>Arrow Algorithms</name>
<description>(Experimental/Contrib) A collection of algorithms for working with ValueVectors.</description>

<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.arrow</groupId>
Expand Down
4 changes: 3 additions & 1 deletion java/bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
<version>18</version>
<version>31</version>
</parent>

<groupId>org.apache.arrow</groupId>
Expand All @@ -26,6 +26,7 @@
<description>Arrow Bill of Materials</description>

<properties>
<minimalMavenBuildVersion>3.5.0</minimalMavenBuildVersion>
<arrow.vector.classifier/>
</properties>

Expand Down Expand Up @@ -145,4 +146,5 @@
</dependencies>

</dependencyManagement>

</project>
1 change: 1 addition & 0 deletions java/c/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<description>Java implementation of C Data Interface</description>
<packaging>jar</packaging>
<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
<arrow.c.jni.dist.dir>./build</arrow.c.jni.dist.dir>
</properties>

Expand Down
4 changes: 4 additions & 0 deletions java/compression/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<name>Arrow Compression</name>
<description>(Experimental/Contrib) A library for working with the compression/decompression of Arrow data.</description>

<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.arrow</groupId>
Expand Down
1 change: 1 addition & 0 deletions java/dataset/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<description>Java implementation of Arrow Dataset API/Framework</description>
<packaging>jar</packaging>
<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
<arrow.cpp.build.dir>../../../cpp/release-build/</arrow.cpp.build.dir>
<protobuf.version>2.5.0</protobuf.version>
<parquet.version>1.11.0</parquet.version>
Expand Down
3 changes: 2 additions & 1 deletion java/flight/flight-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<packaging>jar</packaging>

<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
<forkCount>1</forkCount>
</properties>

Expand Down Expand Up @@ -287,7 +288,7 @@
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<version>3.2.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
Expand Down
1 change: 1 addition & 0 deletions java/flight/flight-grpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<packaging>jar</packaging>

<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
<forkCount>1</forkCount>
</properties>

Expand Down
6 changes: 5 additions & 1 deletion java/flight/flight-integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<description>Integration tests for Flight RPC.</description>
<packaging>jar</packaging>

<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.arrow</groupId>
Expand Down Expand Up @@ -60,7 +64,7 @@
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<version>3.2.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
Expand Down
1 change: 1 addition & 0 deletions java/flight/flight-sql-jdbc-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<url>https://arrow.apache.org</url>

<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
<org.apache.arrow.flight.name>${project.parent.groupId}:${project.parent.artifactId}</org.apache.arrow.flight.name>
<org.apache.arrow.flight.version>${project.parent.version}</org.apache.arrow.flight.version>
<org.apache.arrow.flight.jdbc-driver.name>${project.name}</org.apache.arrow.flight.jdbc-driver.name>
Expand Down
4 changes: 4 additions & 0 deletions java/flight/flight-sql-jdbc-driver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<packaging>jar</packaging>
<url>https://arrow.apache.org</url>

<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
</properties>

<dependencies>
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-core -->
<dependency>
Expand Down
1 change: 1 addition & 0 deletions java/flight/flight-sql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<packaging>jar</packaging>

<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
<forkCount>1</forkCount>
</properties>

Expand Down
4 changes: 4 additions & 0 deletions java/format/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<name>Arrow Format</name>
<description>Generated Java files from the IPC Flatbuffer definitions.</description>

<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
</properties>

<dependencies>
<dependency>
<groupId>com.google.flatbuffers</groupId>
Expand Down
1 change: 1 addition & 0 deletions java/gandiva/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<name>Arrow Gandiva</name>
<description>Java wrappers around the native Gandiva SQL expression compiler.</description>
<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<protobuf.version>3.25.1</protobuf.version>
Expand Down
3 changes: 2 additions & 1 deletion java/maven/module-info-compiler-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</prerequisites>

<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
<maven.version>3.3.9</maven.version>
</properties>

Expand Down Expand Up @@ -84,7 +85,7 @@
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<version>3.2.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions java/memory/memory-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
<name>Arrow Memory - Core</name>
<description>Core off-heap memory management libraries for Arrow ValueVectors.</description>

<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
</properties>

<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
Expand Down
4 changes: 4 additions & 0 deletions java/memory/memory-netty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<name>Arrow Memory - Netty</name>
<description>Netty allocator and utils for allocating memory in Arrow</description>

<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.arrow</groupId>
Expand Down
3 changes: 3 additions & 0 deletions java/memory/memory-unsafe/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<name>Arrow Memory - Unsafe</name>
<description>Allocator and utils for allocating memory in Arrow based on sun.misc.Unsafe</description>

<properties>
<project.build.outputTimestamp>2023-12-13T00:00:00Z</project.build.outputTimestamp>
</properties>

<dependencies>
<dependency>
Expand Down
Loading

0 comments on commit cb22662

Please sign in to comment.