Skip to content

Commit

Permalink
Update JDT to 3.33.0 (#35)
Browse files Browse the repository at this point in the history
Use JDT jars from maven central rather than packaging our own.

Related to gwtproject/gwt#10026
  • Loading branch information
vegegoku authored Feb 12, 2025
1 parent 96d2da9 commit 1b06a1a
Show file tree
Hide file tree
Showing 37 changed files with 146 additions and 111 deletions.
Binary file added lib/eclipse/3.33.0/ecj-3.33.0-sources.jar
Binary file not shown.
Binary file added lib/eclipse/3.33.0/ecj-3.33.0.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added lib/eclipse/3.33.0/org.eclipse.osgi-3.18.300.jar
Binary file not shown.
Binary file not shown.
Binary file added lib/eclipse/3.33.0/org.eclipse.text-3.12.300.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added lib/eclipse/3.33.0/osgi.annotation-8.0.1.jar
Binary file not shown.
21 changes: 12 additions & 9 deletions lib/eclipse/README.jdt-upgrade
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
IMPORTANT NOTE WHEN UPGRADING THE JDT.

The digital signature on the jdt jar file needs to be removed by removing the following files
from the jar:
/META-INF/*.RSA
/META-INF/*.SF
Starting from JDT 3.33.0 we no longer need to repackage the JDT jar, instead we make a jar list that reflect the same
dependency that we get from a maven build.

In order to obtain this list of jars, we build a maven project that depends on the newer version of eclipse JDT and copy
the dependencies from there, then we remove any signature files from those jars to prepare then for packaging with gwt
this process is done by executing the script "update-jdt.py" :

for example, to update jdt to version 3.33.0 we run the command:

python3 update-jdt.py 3.33.0

This should copy all jdt dependencies and source to the new version folder.

Failure to do so will cause the open-source build process to file with an obscure error (e.g. rmic
failing).

Also move the jdtCompilerAdapter.jar out of the jdt jar file and rename it to reflect the
version. E.g. if the jdt jar file was named org.eclipse.jdt.core-3.8.2.v20120814-155456.jar,
rename the jdtCompilerAdapter.jar to jdtCompilerAdapter-3.8.2.v20120814-155456.jar
18 changes: 18 additions & 0 deletions lib/eclipse/dep-grab/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.gwtproject</groupId>
<artifactId>dep-grab</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>${jdt.version}</version>
</dependency>
</dependencies>
</project>
218 changes: 116 additions & 102 deletions lib/eclipse/update-jdt.py
Original file line number Diff line number Diff line change
@@ -1,103 +1,117 @@
#!/usr/bin/python2.4
# update-jdt.py
#
# This script is used to massage a JDT jar from Eclipse
# for inclusion in the GWT tools repository.
# It strips out files that are not needed and adds a version.txt
# file.
#
# Run it as:
#
# python update-jdt.py jarfile sourcefile

import re
#!/usr/bin/env python3
"""
Usage: ./update-jdt.py <jdt version>
This script does the following:
1) Runs Maven to copy dependencies (and sources) into a temporary directory ("./temp")
2) Cleans/creates the output directory (whose name is given by the jdt version parameter)
3) Copies all JAR files (and only JARs) from the temp directory to the output directory,
preserving the subdirectory structure.
4) Removes signature files (META-INF/*.SF and META-INF/*.RSA) from each copied JAR (using the zip command)
5) Removes the temporary directory
"""

import os
import sys
import zipfile

# White listing
jarWhitelist = [
"about.html",
"org/eclipse/jdt/core/compiler",
"org/eclipse/jdt/internal/compiler",
"org/eclipse/jdt/internal/core/util"
]

def whitelistAllows(filename):
for start in jarWhitelist:
if filename.startswith(start):
return True
return False


# Parse arguments
if len(sys.argv) != 3:
print "Usage: python update-jdt.py org.eclipse.jdt.core_N.N.N.v_NNN_RNNx.jar org.eclipse.jdt.core.source_N.N.N.v_NNN_RNNx.jar"
sys.exit(1)

jdtjar = sys.argv[1]
srcjar = sys.argv[2]

print "JDT jar: " + jdtjar
print "source jar: " + srcjar


# extract versions from the names, and make sure they match
versionOfJarPattern = re.compile(r"org\.eclipse\.jdt\.core(\.source)?_(.*)\.jar")
def versionOfJar(jarname):
match = versionOfJarPattern.match(jarname)
if match == None:
return ""
else:
return match.group(2)

version = versionOfJar(jdtjar)
srcversion = versionOfJar(srcjar)

if version == None or srcversion == None:
print "Cannot determine the version number of these jars."
sys.exit(2)

if version != srcversion:
print "The version of the two jars is inconsistent (" + version1 + " vs. " + version2
sys.exit(2)

print "long version: " + version

shortVersionPattern = re.compile(r"([0-9]+\.[0-9]+\.[0-9]+)\.v.*")
shortVersion = shortVersionPattern.match(version).group(1)

print "short version: " + shortVersion



# build jars for GWT
def filterjar(injarname, outjarname):
print "writing " + outjarname + "..."

outzip = zipfile.ZipFile(outjarname, mode='w')
inzip = zipfile.ZipFile(injarname, mode='r')

for info in inzip.infolist():
if whitelistAllows(info.filename):
data = inzip.read(info.filename)
outinfo = zipfile.ZipInfo(filename=info.filename,
date_time=info.date_time)
outinfo.external_attr = 0600 << 16L #fixup permissions
outinfo.compress_type = zipfile.ZIP_DEFLATED
outzip.writestr(outinfo, data)

inzip.close()
outzip.close()

jdtforgwt = "jdt-" + shortVersion + ".jar"
srcforgwt = "jdt-" + shortVersion + "-src.zip"

filterjar(jdtjar, jdtforgwt)
filterjar(srcjar, srcforgwt)


# add version.txt
jdtzip = zipfile.ZipFile(jdtforgwt, "a")
jdtzip.writestr(zipfile.ZipInfo(filename="org/eclipse/jdt/version.txt"),
"version " + version + "\n")
jdtzip.close()
import shutil
import subprocess

def run_maven_commands(jdt_version, input_dir):
"""
Run the Maven commands to copy the dependencies and sources into the temporary directory.
"""
maven_cmd = [
"mvn", "-f", "./dep-grab/pom.xml",
"dependency:copy-dependencies",
f"-Djdt.version={jdt_version}",
f"-DoutputDirectory=.{input_dir}"
]
print("Running Maven to copy dependencies...")
subprocess.run(maven_cmd, check=True)

maven_cmd_sources = maven_cmd + ["-Dclassifier=sources"]
print("Running Maven to copy sources...")
subprocess.run(maven_cmd_sources, check=True)


def clean_output_directory(output_dir):
"""
Remove the output directory if it exists and then create it.
"""
print(f"Cleaning/creating output directory: {output_dir}")
if os.path.exists(output_dir):
shutil.rmtree(output_dir)
os.makedirs(output_dir, exist_ok=True)


def copy_jars(input_dir, output_dir):
"""
Walk the input directory (which is "./temp"), and copy any file ending with .jar to the
output directory preserving the directory structure.
"""
print(f"Copying JAR files from: {input_dir} to: {output_dir}")
for root, _, files in os.walk(input_dir):
for filename in files:
if filename.lower().endswith('.jar'):
src = os.path.join(root, filename)
# Get relative path from input_dir to maintain the structure.
rel_path = os.path.relpath(src, input_dir)
dest = os.path.join(output_dir, rel_path)
os.makedirs(os.path.dirname(dest), exist_ok=True)
shutil.copy2(src, dest)


def remove_signature_files(output_dir):
"""
For each jar file in the output directory, run 'zip -d' to remove META-INF/*.SF and META-INF/*.RSA.
"""
print("Removing signature files (*.SF, *.RSA) from copied JARs...")
for root, _, files in os.walk(output_dir):
for filename in files:
if filename.lower().endswith('.jar'):
jar_path = os.path.join(root, filename)
print(f"Cleaning {jar_path}")
# Call zip -d to delete the signature files.
# Any errors (for example, if the jar does not contain those files) are ignored.
try:
subprocess.run(
["zip", "-d", jar_path, "META-INF/*.SF", "META-INF/*.RSA"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
check=True
)
except subprocess.CalledProcessError:
# If the zip command fails, we ignore the error.
pass


def main():
# Verify that the required parameter is provided.
if len(sys.argv) < 2:
print("Usage: {} <jdt version>".format(sys.argv[0]))
sys.exit(1)

# In the original bash script, the only parameter is used as the JDT version as well as the output directory.
jdt_version = sys.argv[1]
input_dir = "./temp"
output_dir = sys.argv[1]

# 1) Run Maven commands to copy dependencies and sources.
run_maven_commands(jdt_version, input_dir)

# 2) Clean (or create) the output directory.
clean_output_directory(output_dir)

# 3) Copy all jar files from the temporary input directory to the output directory.
copy_jars(input_dir, output_dir)

# 4) Remove the signature files from the copied jars.
remove_signature_files(output_dir)

# 5) Remove the temporary input directory.
shutil.rmtree(input_dir, ignore_errors=True)

print(f"Done! Cleaned JARs are in: {output_dir}")

if __name__ == '__main__':
main()

0 comments on commit 1b06a1a

Please sign in to comment.