Skip to content

Commit

Permalink
Merge branch 'feat/java-17' into 'develop'
Browse files Browse the repository at this point in the history
OEQ-1595 Migrate to Java 21

See merge request edalex-group/development/oeq/openequella!307
  • Loading branch information
PenghaiZhang committed Dec 21, 2023
2 parents ca0c0ce + e96e740 commit 3cd76db
Show file tree
Hide file tree
Showing 23 changed files with 142 additions and 235 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
- name: Run checks
run: |
npm run check
./sbt headerCheck checkJavaCodeStyle
./sbt headerCheck
# oeq-ts-rest-api has its own ESLint checks seeing the ultimate plan
# is that it's moved to its own stand-alone repo. But so here we need
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export JAVA_HOME="${java/jdk#t\/}"
#export JMX_CONFIG="-Dcom.sun.management.jmxremote.port=8855 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
#export HEAP_CONFIG="-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../"
export CLASSPATH="../learningedge-config:../server/equella-server.jar"
export JAVA_OPTS="${webserver/javaopts} -Xrs -Xms${memory/min} -Xmx${memory/max} -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=false -Djava.awt.headless=true -Djava.io.tmpdir=../server/temp -XX:MaxGCPauseMillis=500 -XX:NewRatio=3 -XX:GCTimeRatio=16 -XX:+DisableExplicitGC -XX:+UseG1GC -XX:CMSInitiatingOccupancyFraction=70 -Dcom.sun.jndi.ldap.connect.pool.timeout=3000000 -Dcom.sun.jndi.ldap.connect.pool.maxsize=200 -Dcom.sun.jndi.ldap.connect.pool.prefsize=20"
export JAVA_OPTS="${webserver/javaopts} -Xrs -Xms${memory/min} -Xmx${memory/max} -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=false -Djava.awt.headless=true -Djava.io.tmpdir=../server/temp -XX:MaxGCPauseMillis=500 -XX:NewRatio=3 -XX:GCTimeRatio=16 -XX:+DisableExplicitGC -XX:+UseG1GC -Dcom.sun.jndi.ldap.connect.pool.timeout=3000000 -Dcom.sun.jndi.ldap.connect.pool.maxsize=200 -Dcom.sun.jndi.ldap.connect.pool.prefsize=20 --add-opens=java.base/java.util=ALL-UNNAMED"

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rem Java options
rem set HEAP_CONFIG=-XX:+HeapDumpOnOutOfMemoryError;-XX:HeapDumpPath=../;
rem set JMX_CONFIG=-Dcom.sun.management.jmxremote.port=8855;-Dcom.sun.management.jmxremote.authenticate=false;-Dcom.sun.management.jmxremote.ssl=false;
set JAVA_ARGS=-Xms${memory/min};-Xmx${memory/max};-Djava.net.preferIPv4Stack=true;-Djava.net.preferIPv6Addresses=false;-Djava.awt.headless=true;-Djava.io.tmpdir=../server/temp;-XX:MaxGCPauseMillis=500;-XX:NewRatio=3;-XX:GCTimeRatio=16;-XX:+DisableExplicitGC;-XX:+UseG1GC;-XX:CMSInitiatingOccupancyFraction=70;-Dcom.sun.jndi.ldap.connect.pool.timeout=3000000;-Dcom.sun.jndi.ldap.connect.pool.maxsize=200;-Dcom.sun.jndi.ldap.connect.pool.prefsize=20
set JAVA_ARGS=-Xms${memory/min};-Xmx${memory/max};-Djava.net.preferIPv4Stack=true;-Djava.net.preferIPv6Addresses=false;-Djava.awt.headless=true;-Djava.io.tmpdir=../server/temp;-XX:MaxGCPauseMillis=500;-XX:NewRatio=3;-XX:GCTimeRatio=16;-XX:+DisableExplicitGC;-XX:+UseG1GC;-Dcom.sun.jndi.ldap.connect.pool.timeout=3000000;-Dcom.sun.jndi.ldap.connect.pool.maxsize=200;-Dcom.sun.jndi.ldap.connect.pool.prefsize=20;--add-opens=java.base/java.util=ALL-UNNAMED
rem Class path
set CLASS_PATH=../learningedge-config;../server/equella-server.jar
rem Display name for the Windows service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private boolean isIgnored(Class<?> decInt) {

class Visitor extends ClassVisitor {
public Visitor() {
super(Opcodes.ASM7);
super(Opcodes.ASM9);
}

String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ private Bootstrap() {

private void run() {
try {
System.setSecurityManager(null);

final URL endpointUrl = new URL(endpointParam);
if (login(endpointUrl)) {
final PluginServiceImpl pluginService =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

public class XStreamSecurityManager {
public static void applyPolicy(XStream xstream) {
XStream.setupDefaultSecurity(xstream);
// Anything you want to be XStream'd needs to be allowed here
xstream.allowTypesByWildcard(
new String[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@

package com.tle.web.endpoint.srw;

import ORG.oclc.os.SRW.*;
import ORG.oclc.os.SRW.QueryResult;
import ORG.oclc.os.SRW.Record;
import ORG.oclc.os.SRW.RecordIterator;
import ORG.oclc.os.SRW.SRWDatabase;
import ORG.oclc.os.SRW.SRWDiagnostic;
import ORG.oclc.os.SRW.TermList;
import com.dytech.devlib.PropBagEx;
import com.tle.beans.entity.Schema;
import com.tle.beans.item.Item;
Expand Down
7 changes: 5 additions & 2 deletions Source/Server/equellaserver/build.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import Path.rebase
import sbt.Package.ManifestAttributes

import java.time.LocalDate
import java.time.format.DateTimeFormatter

javacOptions ++= Seq("--release", "11")

(Compile / resourceDirectory) := baseDirectory.value / "resources"

(Compile / javaSource) := baseDirectory.value / "src"
Expand Down Expand Up @@ -432,6 +431,10 @@ run := {
oldStrategy(x)
}

// In order to work properly with Java 21, Some libraries like Lucene v9 requires flag 'Multi-Release' to
// be true in the manifest file.
assembly / packageOptions += ManifestAttributes("Multi-Release" -> "true")

lazy val collectJars = taskKey[Set[File]]("Collect jars")

collectJars := {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ package com.tle.upgrade.upgraders.apachedaemon
import com.dytech.edge.common.Constants
import com.tle.common.util.ExecUtils
import com.tle.upgrade.upgraders.AbstractUpgrader
import com.tle.upgrade.{LineFileModifier, UpgradeMain, UpgradeResult}
import com.tle.upgrade.upgraders.AbstractUpgrader.{
EQUELLA_SERVER_CONFIG_LINUX,
EQUELLA_SERVER_CONFIG_WINDOWS
}
import com.tle.upgrade.{LineFileModifier, UpgradeResult}
import java.io.File
import scala.util.{Failure, Success, Try}

Expand All @@ -38,10 +42,8 @@ class UpdateApacheDaemon extends AbstractUpgrader {
val PRUNMGR = "prunmgr.exe"
val PRUNSRV = "prunsrv.exe"

val EQUELLA_SERVER_LINUX = "equellaserver"
val EQUELLA_SERVER_CONFIG_LINUX = "equellaserver-config.sh"
val EQUELLA_SERVER_WINDOWS = "equellaserver.bat"
val EQUELLA_SERVER_CONFIG_WINDOWS = "equellaserver-config.bat"
val EQUELLA_SERVER_LINUX = "equellaserver"
val EQUELLA_SERVER_WINDOWS = "equellaserver.bat"

val MANAGER_SERVER_LINUX = "manager"
val MANAGER_SERVER_WINDOWS = "manager.bat"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Licensed to The Apereo Foundation under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* The Apereo Foundation 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 com.tle.upgrade.upgraders.java17

import com.dytech.edge.common.Constants
import com.tle.common.util.ExecUtils
import com.tle.upgrade.{LineFileModifier, UpgradeResult}
import com.tle.upgrade.upgraders.AbstractUpgrader
import com.tle.upgrade.upgraders.AbstractUpgrader.{
EQUELLA_SERVER_CONFIG_LINUX,
EQUELLA_SERVER_CONFIG_WINDOWS
}

import java.io.File
import scala.util.{Failure, Success, Try}

/**
* This upgrade drops JVM option 'CMSInitiatingOccupancyFraction' which is removed in Java 17.
* It also adds JVM option '--add-opens=java.base/java.util=ALL-UNNAMED' as a workaround to support
* some libraries like XStream which is not fully compatible with Java 17 by 12/12/2023.
*/
class UpdateJavaOpts extends AbstractUpgrader {

override def getId: String = "UpdateJavaOpts"

override def isBackwardsCompatible: Boolean = false

override def upgrade(result: UpgradeResult, installDir: File): Unit = {
val managerDir = new File(installDir, Constants.MANAGER_FOLDER)

def update(configFile: String): Unit = {
val updateResult = Try {
new LineFileModifier(new File(managerDir, configFile), result) {
override protected def processLine(line: String): String = {
val RemovedOption =
".*(-XX:CMSInitiatingOccupancyFraction=\\d+).*".r

line match {
case RemovedOption(option) =>
line.replace(option, "--add-opens=java.base/java.util=ALL-UNNAMED")
case _ => line
}
}
}.update()
}

updateResult match {
case Success(_) => result.info("Successfully updated Java options.")
case Failure(error) => result.info(s"Failed to update Java options: ${error.getMessage}")
}
}

ExecUtils.determinePlatform() match {
case ExecUtils.PLATFORM_WIN64 =>
update(EQUELLA_SERVER_CONFIG_WINDOWS)
case ExecUtils.PLATFORM_LINUX64 =>
update(EQUELLA_SERVER_CONFIG_LINUX)
case other => result.info(s"Unsupported OS $other")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.tle.upgrade.upgraders.UpgradeToTomcat7_0_37;
import com.tle.upgrade.upgraders.apachedaemon.UpdateApacheDaemon;
import com.tle.upgrade.upgraders.ffmpeg.AddFfmpegConfig;
import com.tle.upgrade.upgraders.java17.UpdateJavaOpts;
import com.tle.upgrade.upgraders.log4j2.UpdateLog4JConfigFile;
import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -132,7 +133,8 @@ public class UpgradeMain {
new AddPostHib5UpgradeConfig(),
new UpdateLog4JConfigFile(),
new AddFfmpegConfig(),
new UpdateApacheDaemon()
new UpdateApacheDaemon(),
new UpdateJavaOpts()
};

public static void main(String[] args) throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@

@SuppressWarnings("nls")
public abstract class AbstractUpgrader implements Upgrader {
protected static final String CONFIG_FOLDER = "learningedge-config"; // $NON-NLS-1$
protected static final String CONFIG_FOLDER = "learningedge-config";
protected static final String EQUELLA_SERVER_CONFIG_LINUX = "equellaserver-config.sh";
protected static final String EQUELLA_SERVER_CONFIG_WINDOWS = "equellaserver-config.bat";

@Override
public List<UpgradeDepends> getDepends() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.io.Writer;
import java.util.Collection;
import org.fest.swing.annotation.GUITest;
import org.fest.swing.security.NoExitSecurityManager;
import org.testng.ITestContext;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -107,16 +106,13 @@ protected void customisePageContext() {
throw new Error(e);
}

System.setSecurityManager(new NoExitSecurityManager());

admin = new AdminConsoleWindow(context);
admin.launch("contribute");
}

@Override
@AfterClass(alwaysRun = true)
public void finishedClass(ITestContext testContext) throws Exception {
System.setSecurityManager(null);
super.finishedClass(testContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public boolean moderatorCorrect(int row, String moderator) {
public long waitTime() throws ParseException {
WebElement time = driver.findElement(By.xpath("//div[1]/span/abbr[@class='timeago_nosuf']"));
String timeStamp = time.getAttribute("title");
SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM dd, yyyy, hh:mm a");
// Since Java 20, the "NARROW NO-BREAK SPACE" character is used before the AM/PM marker.
SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM dd, yyyy, hh:mm\u202Fa");
dateFormat.setTimeZone(TimeZone.getTimeZone("Australia/Hobart"));
Date d = dateFormat.parse(timeStamp);
return d.getTime();
Expand Down
38 changes: 0 additions & 38 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -64,44 +64,6 @@ lazy val equella = (project in file("."))
UpgradeInstallation,
learningedge_config)

checkJavaCodeStyle := {
import com.etsy.sbt.checkstyle.*
val rootDirectory = (LocalProject("equella") / baseDirectory).value
val rootTargetDirectory = (LocalProject("equella") / target).value
def countErrorNumber: Int = {
val outputFile = new File("target/checkstyle-report.xml")
if (outputFile.exists()) {
val report = scala.xml.XML.loadFile(outputFile)
(report \\ "file" \ "error").length
} else {
throw new FileNotFoundException("checkstyle report is missing")
}
}
// As we will specify where the config file is, the resource file can be null
// We don't want to exit SBT if checkstyle finds any issue, so severityLevel should be None
Checkstyle.checkstyle(
javaSource = rootDirectory,
resources = null,
outputFile = rootTargetDirectory / "checkstyle-report.xml",
configLocation = CheckstyleConfigLocation.File("checkstyle-config.xml"),
xsltTransformations = Some(
Set(CheckstyleXSLTSettings(rootDirectory / "checkstyle-report-template.xml",
rootTargetDirectory / "checkstyle-report.html"))),
severityLevel = None,
streams = streams.value
)
val errorNumber = countErrorNumber
val thresholdNumber = 449
if (errorNumber > thresholdNumber) {
throw new MessageOnlyException(
"Checkstyle error threshold (" + thresholdNumber + ") exceeded with error count of " + errorNumber)
} else if (errorNumber < thresholdNumber) {
throw new MessageOnlyException(
"Checkstyle errors has been reduced. Threshold of " + thresholdNumber + " has been reduced to " +
errorNumber + " please reduce thresholdNumber in build.sbt.")
}
}

// We currently build for Java 8, so let's drop module info files
ThisBuild / assemblyMergeStrategy := {
case PathList("module-info.class") => MergeStrategy.discard
Expand Down
3 changes: 3 additions & 0 deletions checkstyle-config.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<!--
Checkstyle configuration that checks the sun coding conventions from:
Expand Down
Loading

0 comments on commit 3cd76db

Please sign in to comment.