Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RUN mvn dependency:go-offline -B || true

# Copy source code
COPY treebase-core/src treebase-core/src
COPY treebase-core/lib treebase-core/lib
COPY treebase-web/src treebase-web/src
COPY treebase-web/lib treebase-web/lib
COPY oai-pmh_data_provider oai-pmh_data_provider
Expand Down Expand Up @@ -45,8 +46,13 @@ COPY --from=builder /build/treebase-web/target/treebase-web.war /usr/local/tomca
RUN curl -o /usr/local/tomcat/lib/postgresql.jar \
https://jdbc.postgresql.org/download/postgresql-42.7.7.jar

# Create a directory for Mesquite (placeholder)
RUN mkdir -p /usr/local/mesquite
# Create a directory for Mesquite and copy the headless Mesquite library
# The treebase-core/lib folder contains the headless Mesquite distribution with:
# - mesquite/ - Mesquite core classes
# - headless/ - Headless AWT implementation
# - com/apple/ - Apple API stubs (required by Mesquite even on non-Mac platforms)
# - Other supporting libraries
COPY --from=builder /build/treebase-core/lib /usr/local/mesquite

# Set environment variables for Tomcat
# Java 17 compatibility flags based on GitHub Actions workflow
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ RUN curl -o /usr/local/tomcat/lib/postgresql.jar \
https://jdbc.postgresql.org/download/postgresql-42.7.7.jar

# Create Mesquite directory placeholder
# Note: In development mode, the entrypoint script will copy
# the Mesquite library from the mounted /app/treebase-core/lib
RUN mkdir -p /usr/local/mesquite

# Set up environment variables
Expand Down
15 changes: 15 additions & 0 deletions docker/entrypoint-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ if [ -d "WEB-INF/dtd" ]; then
ls -la /tmp/dtd/
fi

# Copy Mesquite library files from the mounted source directory
# The treebase-core/lib folder contains the headless Mesquite distribution with:
# - mesquite/ - Mesquite core classes
# - headless/ - Headless AWT implementation
# - com/apple/ - Apple API stubs (required by Mesquite even on non-Mac platforms)
# - Other supporting libraries
if [ -d "/app/treebase-core/lib" ]; then
echo "Copying Mesquite library to /usr/local/mesquite..."
cp -r /app/treebase-core/lib/* /usr/local/mesquite/
echo "Mesquite library installed."
else
echo "WARNING: Mesquite library not found at /app/treebase-core/lib"
echo "Nexus file parsing may not work correctly."
fi

echo "Setup complete! Starting Tomcat..."
echo "========================================"
echo "JSP files are mounted from: ./treebase-web/src/main/webapp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,48 @@ private void setCurrentTreeTaxa(Taxa pNewCurrentTreeTaxa) {
mCurrentTreeTaxa = pNewCurrentTreeTaxa;
}

/**
* Initialize Mesquite in headless mode. This method sets the necessary flags
* and handles exceptions that may occur during initialization.
*
* @param args Command line arguments to pass to Mesquite.main()
* @throws RuntimeException if Mesquite fails to initialize and mesquiteTrunk is null
*/
private static void initializeMesquiteHeadless(String[] args) {
// Set headless mode before initializing Mesquite to prevent GUI window creation
// Also set suppressAllWindows to skip all window operations
MesquiteWindow.headless = true;
MesquiteWindow.suppressAllWindows = true;

try {
Mesquite.main(args);
setInitMesquite(true);
LOGGER.info("Mesquite initialization completed successfully");
} catch (NullPointerException e) {
// NPE may occur during headless initialization when window creation fails
// Check if mesquiteTrunk was still initialized despite the exception
handleMesquiteInitException(e);
} catch (RuntimeException e) {
// RuntimeException (including HeadlessException) may occur during initialization
handleMesquiteInitException(e);
}
}

/**
* Handle exceptions during Mesquite initialization.
* If mesquiteTrunk is available, log warning and continue.
* If mesquiteTrunk is null, throw RuntimeException.
*/
private static void handleMesquiteInitException(Exception e) {
if (MesquiteTrunk.mesquiteTrunk != null) {
LOGGER.warn("Mesquite initialization threw exception but trunk is available: " + e.getMessage());
setInitMesquite(true);
} else {
LOGGER.error("Mesquite initialization failed: " + e.getMessage(), e);
throw new RuntimeException("Failed to initialize Mesquite for NEXUS parsing", e);
}
}

/**
*
* @see org.cipres.treebase.domain.nexus.NexusParserConverter#processLoadFile(java.util.Collection,
Expand All @@ -200,10 +242,7 @@ public void processLoadFile(

synchronized (MesquiteConverter.class) {
if (!isInitMesquite()) {
// Set headless mode before initializing Mesquite to prevent GUI window creation
MesquiteWindow.headless = true;
Mesquite.main(new String[] {"-w"});
setInitMesquite(true);
initializeMesquiteHeadless(new String[] {"-w"});
}
}

Expand Down Expand Up @@ -233,10 +272,7 @@ public void parseOneFile(File pFile, Study pStudy, NexusDataSet pDataSet) {
// make sure no two calls can fight each other:
synchronized (MesquiteConverter.class) {
if (!isInitMesquite()) {
// Set headless mode before initializing Mesquite to prevent GUI window creation
MesquiteWindow.headless = true;
Mesquite.main(new String[] {"-w", "-b"});
setInitMesquite(true);
initializeMesquiteHeadless(new String[] {"-w", "-b"});
}
}

Expand Down