diff --git a/MODULE_SYSTEM.md b/MODULE_SYSTEM.md new file mode 100644 index 000000000..92d05eed3 --- /dev/null +++ b/MODULE_SYSTEM.md @@ -0,0 +1,170 @@ +# Java Module System (JPMS) for ODF Toolkit + +## Overview + +The ODF Toolkit has been extended with Java Module System (JPMS) support. All artifacts (JARs and WARs) are now configured as Java modules. + +## Modules + +### 1. `org.odftoolkit.odfdom` + +The main module for ODFDOM - the core API for ODF documents. + +**Exported Packages:** +- `org.odftoolkit.odfdom` - Core API +- `org.odftoolkit.odfdom.doc.*` - Document Layer (high-level API) +- `org.odftoolkit.odfdom.pkg.*` - Package Layer +- `org.odftoolkit.odfdom.type` - Data types +- `org.odftoolkit.odfdom.changes` - Collaboration API +- `org.odftoolkit.odfdom.dom.*` - DOM Layer (for advanced users) + +**Not Exported:** +- `org.odftoolkit.odfdom.incubator.*` - Experimental APIs (explicitly marked as "Incubator Status") + +### 2. `org.odftoolkit.odfvalidator` + +The Validator module for ODF validation. + +**Exported Packages:** +- `org.odftoolkit.odfvalidator` - Validator API + +**Dependencies:** +- `org.odftoolkit.odfdom` - Requires ODFDOM + +### 3. `org.odftoolkit.odfxsltrunner` + +The XSLT Runner module for XSLT transformations in ODF documents. + +**Exported Packages:** +- `org.odftoolkit.odfxsltrunner` - XSLT Runner API + +**Dependencies:** +- `org.odftoolkit.odfdom` - Requires ODFDOM + +## Usage + +### As Modules (Java 9+) + +```java +module com.example.myapp { + requires org.odftoolkit.odfdom; + requires org.odftoolkit.odfvalidator; // optional + requires org.odftoolkit.odfxsltrunner; // optional +} +``` + +### On the Module Path + +```bash +java --module-path lib/odfdom-java-0.14.0.jar \ + --module org.odftoolkit.odfdom +``` + +### On the Classpath (Backward Compatibility) + +The modules continue to work on the classpath for Java 8+ applications: + +```bash +java -cp lib/odfdom-java-0.14.0.jar:lib/other.jar MyApp +``` + +## Validation + +### Automatic Validation + +Run the validation script: + +**Linux/macOS:** +```bash +chmod +x src/site/validate-modules.sh +./src/site/validate-modules.sh +``` + +**Windows:** +```cmd +src\site\validate-modules.bat +``` + +### Manual Validation + +#### 1. Check Compilation +```bash +mvn clean compile +``` + +#### 2. Analyze Module Dependencies +```bash +jdeps --module-path odfdom/target/classes \ + --add-modules org.odftoolkit.odfdom \ + --list-deps \ + odfdom/target/odfdom-java-*.jar +``` + +#### 3. Generate Module Graph +```bash +jdeps --module-path odfdom/target/classes \ + --dot-output module-graph.dot \ + odfdom/target/odfdom-java-*.jar + +# Visualize with Graphviz +dot -Tpng module-graph.dot -o module-graph.png +``` + +#### 4. Check JAR Contents +```bash +jar tf odfdom/target/odfdom-java-*.jar | grep module-info +``` + +## Known Issues and Solutions + +### Automatic Modules + +Many dependencies do not yet have a `module-info.java` and are treated as "automatic modules". Module names are derived from JAR file names: + +- `xercesImpl-2.12.2.jar` → `xerces.impl` +- `commons-validator-1.10.1.jar` → `commons.validator` +- `jena-core-5.6.0.jar` → `org.apache.jena.core` + +### Reflection Access + +If frameworks need to access internal classes via reflection, corresponding `opens` directives have been added: + +```java +opens org.odftoolkit.odfdom.pkg.rdfa to org.apache.jena.core; +``` + +### WAR Deployment + +The Validator is provided as a WAR file. Modern servlet containers (Tomcat 10+, Jetty 11+) support modules in WARs. For older containers, classpath mode continues to work. + +## Migration from Existing Code + +### Before (Classpath) +```java +import org.odftoolkit.odfdom.doc.OdfTextDocument; +// ... +``` + +### After (Module Path) +```java +module myapp { + requires org.odftoolkit.odfdom; +} + +import org.odftoolkit.odfdom.doc.OdfTextDocument; +// ... (code remains the same!) +``` + +**Important:** The code itself does not need to be changed! Only the `module-info.java` needs to be added. + +## Additional Information + +- [Java Platform Module System (JEP 261)](https://openjdk.java.net/projects/jigsaw/spec/) +- [The State of the Module System](https://openjdk.java.net/projects/jigsaw/spec/sotms/) +- [Maven Guide to Java Modules](https://maven.apache.org/guides/mini/guide-multiple-modules.html) + +## Support + +For questions or issues: +- GitHub Issues: https://github.com/tdf/odftoolkit/issues +- Mailing List: dev@odftoolkit.org diff --git a/odfdom/pom.xml b/odfdom/pom.xml index c8f4e9f1b..ed2d52b21 100644 --- a/odfdom/pom.xml +++ b/odfdom/pom.xml @@ -111,6 +111,9 @@ ${project.basedir}/target/odf/generation/**/*.java + @@ -207,6 +210,10 @@ **/integrationtest/PerformanceIT.java + + + + false @@ -322,6 +329,10 @@ ${project.version} org.odftoolkit.odfdom.pkg.DefaultErrorHandler + + + + false @@ -577,6 +588,10 @@ 1 test + + + + false diff --git a/odfdom/src/main/java/module-info.java b/odfdom/src/main/java/module-info.java new file mode 100644 index 000000000..be40d654f --- /dev/null +++ b/odfdom/src/main/java/module-info.java @@ -0,0 +1,127 @@ +/** + * ********************************************************************** + * + *

DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER + * + *

Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved. Copyright 2018-2026 + * The Document Foundation. All rights reserved. + * + *

Use is subject to license terms. + * + *

Licensed 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. You can also obtain a copy of the License at + * http://odftoolkit.org/docs/license.txt + * + *

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. + * + *

********************************************************************** + */ + +/** + * ODFDOM - OpenDocument Format DOM API + * + *

This module provides the core ODFDOM API for creating, accessing and manipulating Open + * Document Format (ODF) documents. + * + *

The main entry points are: + * + *

    + *
  • {@link org.odftoolkit.odfdom.doc OdfDocument classes} - High-level document API + *
  • {@link org.odftoolkit.odfdom.pkg OdfPackage} - Package-level access + *
  • {@link org.odftoolkit.odfdom.dom OdfSchemaDocument} - DOM-level access + *
  • {@link org.odftoolkit.odfdom.changes CollabTextDocument} - Collaboration API + *
+ * + * @moduleGraph + * @since 0.14.0 + */ +module org.odftoolkit.odfdom { + // ============================================================================ + // PUBLIC API EXPORTS - Stable, documented APIs for external use + // ============================================================================ + + // Core API + exports org.odftoolkit.odfdom; + + // Document Layer - High-level document API (stable) + exports org.odftoolkit.odfdom.doc; + exports org.odftoolkit.odfdom.doc.table; + exports org.odftoolkit.odfdom.doc.presentation; + + // Package Layer - Package-level access (stable) + exports org.odftoolkit.odfdom.pkg; + exports org.odftoolkit.odfdom.pkg.manifest; + exports org.odftoolkit.odfdom.pkg.rdfa; + + // Type System - Data types (stable) + exports org.odftoolkit.odfdom.type; + + // Changes API - Collaboration API (stable) + exports org.odftoolkit.odfdom.changes; + + // DOM Layer - Schema-based DOM access (for advanced users) + exports org.odftoolkit.odfdom.dom; + exports org.odftoolkit.odfdom.dom.style; + exports org.odftoolkit.odfdom.dom.element; + // Note: org.odftoolkit.odfdom.dom.attribute contains only subpackages, not exported directly + // Subpackages like org.odftoolkit.odfdom.dom.attribute.text are accessible via parent package + exports org.odftoolkit.odfdom.dom.rdfa; + + // ============================================================================ + // OPENS - For reflection access (frameworks, serialization, etc.) + // ============================================================================ + + // Open for Apache Jena (RDF processing) + opens org.odftoolkit.odfdom.pkg.rdfa to + org.apache.jena.core; + + // Open for XML processing frameworks that use reflection + opens org.odftoolkit.odfdom.pkg to + java.xml; + + // ============================================================================ + // REQUIRES - Module dependencies + // ============================================================================ + + // Java Platform Modules + requires java.base; + requires java.desktop; // for javax.xml.* + requires java.logging; + requires java.xml; + requires java.xml.crypto; // for digital signatures + + // Automatic Modules (JARs without module-info.java) + // Note: Module names are derived from JAR file names or Automatic-Module-Name manifest attribute + // Maven compiler plugin automatically places dependencies on module path when module-info.java + // exists + requires xercesImpl; // xerces:xercesImpl (xercesImpl-2.12.2.jar -> xercesImpl, derived from + // filename) + requires serializer; // xalan:serializer (serializer-2.7.3.jar -> serializer) - confirmed working + requires org.apache.jena.core; // org.apache.jena:jena-core (has Automatic-Module-Name) + requires java.rdfa; // net.rootdev:java-rdfa (java-rdfa-1.0.0-BETA1.jar -> java.rdfa) - confirmed + // working + requires org.apache + .commons + .validator; // commons-validator:commons-validator (has Automatic-Module-Name) + requires org.apache + .commons + .compress; // org.apache.commons:commons-compress (has Automatic-Module-Name) + requires org.apache.commons.lang3; // org.apache.commons:commons-lang3 (has Automatic-Module-Name) + requires org.json; // org.json:json (has Automatic-Module-Name) + requires org.bouncycastle.provider; // org.bouncycastle:bcprov-jdk18on (has Automatic-Module-Name) + + // Optional dependencies (may not be present at runtime) + requires static org.slf4j; // org.slf4j:slf4j-api (has Automatic-Module-Name: org.slf4j) + +// ============================================================================ +// SERVICES - Service provider interfaces (if any) +// ============================================================================ + +// Currently no services defined +} diff --git a/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/GRDDLTest.java b/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/GRDDLTest.java index b91ff6755..9a6c11ad7 100644 --- a/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/GRDDLTest.java +++ b/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/GRDDLTest.java @@ -39,7 +39,7 @@ import javax.xml.transform.stream.StreamResult; import junit.framework.TestCase; import org.apache.jena.rdf.model.Model; -import org.apache.jena.rdf.model.test.ModelTestBase; +import org.apache.jena.rdf.model.ModelFactory; import org.junit.Assert; import org.junit.Test; import org.odftoolkit.odfdom.doc.OdfDocument; @@ -47,14 +47,18 @@ import org.odftoolkit.odfdom.utils.ResourceUtilities; import org.xml.sax.InputSource; -public class GRDDLTest extends ModelTestBase { +public class GRDDLTest extends TestCase { private static final Logger LOG = Logger.getLogger(GRDDLTest.class.getName()); private static final String SIMPLE_ODT = "test_rdfmeta.odt"; public GRDDLTest(String name) { super(name); - // TODO: Auto-generated constructor stub + } + + /** Creates an in-memory RDF model. Replaces the ModelTestBase.createMemModel() method. */ + protected Model createMemModel() { + return ModelFactory.createDefaultModel(); } /** diff --git a/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/RDFMetadataTest.java b/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/RDFMetadataTest.java index 44b2c6304..103cf4000 100644 --- a/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/RDFMetadataTest.java +++ b/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/RDFMetadataTest.java @@ -28,7 +28,6 @@ import javax.xml.xpath.XPathConstants; import junit.framework.TestCase; import org.apache.jena.rdf.model.Model; -import org.apache.jena.rdf.model.test.ModelTestBase; import org.junit.Test; import org.odftoolkit.odfdom.doc.OdfDocument; import org.odftoolkit.odfdom.doc.OdfTextDocument; @@ -37,14 +36,13 @@ import org.odftoolkit.odfdom.dom.rdfa.BookmarkRDFMetadataExtractor; import org.odftoolkit.odfdom.utils.ResourceUtilities; -public class RDFMetadataTest extends ModelTestBase { +public class RDFMetadataTest extends TestCase { private static final Logger LOG = Logger.getLogger(RDFMetadataTest.class.getName()); private static final String SIMPLE_ODT = "test_rdfmeta.odt"; public RDFMetadataTest(String name) { super(name); - // TODO Auto-generated constructor stub } @Test @@ -95,9 +93,7 @@ public void testGetRDFMetaFromGRDDLXSLT() throws Exception { // http://docs.oasis-open.org/ns/office/1.2/meta/pkg#Document) // duplicated = 1; m3 = m1.intersection(m2); - LOG.info( - "RDF Model - intersection of in-content metadata of root & embedded document:\n" - + m2); + LOG.info("RDF Model - intersection of in-content metadata of root & embedded document:\n" + m2); // TestCase.assertEquals(duplicated, m3.size()); // TestCase.assertEquals(size1 + size2 - duplicated, m.size()); diff --git a/pom.xml b/pom.xml index d4e468672..a13a80934 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,9 @@ 17 17 + + + false ${basedir}/target/release ${release.dir}/${project.version}/binaries @@ -384,11 +387,36 @@ google-java-format 5.1 + + + + + com.google.googlejavaformat + google-java-format + 1.33.0 + + + com.cosium.code + google-java-format + + + - + + + + + ${gcf.skip} + @@ -648,6 +676,7 @@ .travis.yml CHANGES.txt CODE_OF_CONDUCT.md + MODULE_SYSTEM.md **/README.md DEPENDENCIES docs/**/* diff --git a/src/site/validate-modules.bat b/src/site/validate-modules.bat new file mode 100644 index 000000000..d9fc74bd5 --- /dev/null +++ b/src/site/validate-modules.bat @@ -0,0 +1,205 @@ +@echo off +REM validate-modules.bat +REM +REM Validates the Java Module System (JPMS) implementation for ODF Toolkit +REM Windows batch script version +REM +REM Run this script from the project root directory. + +REM Change to project root directory +cd /d "%~dp0\..\.." + +setlocal enabledelayedexpansion + +set ERRORS=0 +set WARNINGS=0 + +REM Create build directory for logs if it doesn't exist +if not exist "target" mkdir "target" +if not exist "target\validation-logs" mkdir "target\validation-logs" +set LOG_DIR=target\validation-logs + +echo ========================================== +echo ODF Toolkit Module System Validation +echo ========================================== +echo. + +REM Check if Java 17+ is available +echo 1. Checking Java version... +java -version >nul 2>&1 +if errorlevel 1 ( + echo [ERROR] Java is not installed or not in PATH + set /a ERRORS+=1 + goto :check_maven +) +echo [OK] Java found +java -version +echo. + +:check_maven +REM Check if Maven is available +echo 2. Checking Maven... +where mvn >nul 2>&1 +if errorlevel 1 ( + echo [ERROR] Maven is not installed or not in PATH + set /a ERRORS+=1 + goto :check_modules +) +echo [OK] Maven found ^(executable exists^) +REM Skip version display to avoid hanging - version will be shown during compilation +echo. + +:check_modules +REM Check if module-info.java files exist +echo 3. Checking module-info.java files... +set MISSING_FILES=0 + +if exist "odfdom\src\main\java\module-info.java" ( + echo [OK] Found: odfdom\src\main\java\module-info.java +) else ( + echo [ERROR] Missing: odfdom\src\main\java\module-info.java + set /a ERRORS+=1 + set /a MISSING_FILES+=1 +) + +if exist "validator\src\main\java\module-info.java" ( + echo [OK] Found: validator\src\main\java\module-info.java +) else ( + echo [ERROR] Missing: validator\src\main\java\module-info.java + set /a ERRORS+=1 + set /a MISSING_FILES+=1 +) + +if exist "xslt-runner\src\main\java\module-info.java" ( + echo [OK] Found: xslt-runner\src\main\java\module-info.java +) else ( + echo [ERROR] Missing: xslt-runner\src\main\java\module-info.java + set /a ERRORS+=1 + set /a MISSING_FILES+=1 +) + +if !MISSING_FILES!==0 ( + echo [OK] All module-info.java files are present +) +echo. + +REM Compile the project +echo 4. Compiling project with module support... +echo Log file: %CD%\%LOG_DIR%\maven-compile.log +call mvn clean compile -DskipTests > %LOG_DIR%\maven-compile.log 2>&1 +set COMPILE_RESULT=%ERRORLEVEL% +type %LOG_DIR%\maven-compile.log +if !COMPILE_RESULT! neq 0 ( + echo [ERROR] Compilation FAILED + echo Full log available at: %LOG_DIR%\maven-compile.log + set /a ERRORS+=1 +) else ( + echo [OK] Compilation successful +) +echo. + +REM Run tests +echo 5. Running tests... +echo Log file: %CD%\%LOG_DIR%\maven-test.log +call mvn test > %LOG_DIR%\maven-test.log 2>&1 +set TEST_RESULT=%ERRORLEVEL% +type %LOG_DIR%\maven-test.log +if !TEST_RESULT! neq 0 ( + echo [WARNING] Some tests failed + echo Full log available at: %LOG_DIR%\maven-test.log + set /a WARNINGS+=1 +) else ( + echo [OK] All tests passed +) +echo. + +REM Package the modules +echo 6. Packaging modules... +echo Log file: %CD%\%LOG_DIR%\maven-package.log +call mvn package -DskipTests > %LOG_DIR%\maven-package.log 2>&1 +set PACKAGE_RESULT=%ERRORLEVEL% +type %LOG_DIR%\maven-package.log +if !PACKAGE_RESULT! neq 0 ( + echo [ERROR] Packaging FAILED + echo Full log available at: %LOG_DIR%\maven-package.log + set /a ERRORS+=1 +) else ( + echo [OK] Packaging successful +) +echo. + +REM Verify JAR files contain module-info.class +echo 7. Verifying module-info.class in JAR files... +set JAR_CHECKED=0 +set JAR_WITH_MODULE=0 + +for %%f in (odfdom\target\odfdom-java-*-SNAPSHOT.jar) do ( + if exist "%%f" ( + set /a JAR_CHECKED+=1 + jar tf "%%f" 2>nul | findstr /C:"module-info.class" >nul + if errorlevel 1 ( + echo [ERROR] %%~nxf does NOT contain module-info.class + set /a ERRORS+=1 + ) else ( + echo [OK] %%~nxf contains module-info.class + set /a JAR_WITH_MODULE+=1 + ) + ) +) + +for %%f in (xslt-runner\target\xslt-runner-*-SNAPSHOT.jar) do ( + if exist "%%f" ( + set /a JAR_CHECKED+=1 + jar tf "%%f" 2>nul | findstr /C:"module-info.class" >nul + if errorlevel 1 ( + echo [ERROR] %%~nxf does NOT contain module-info.class + set /a ERRORS+=1 + ) else ( + echo [OK] %%~nxf contains module-info.class + set /a JAR_WITH_MODULE+=1 + ) + ) +) + +if !JAR_CHECKED!==0 ( + echo [WARNING] No JAR files found to check (package first) + set /a WARNINGS+=1 +) else if !JAR_WITH_MODULE!==!JAR_CHECKED! ( + echo [OK] All JAR files contain module-info.class +) +echo. + +REM List all log files +echo ========================================== +echo Log Files: +echo ========================================== +echo Compilation log: %CD%\%LOG_DIR%\maven-compile.log +echo Test log: %CD%\%LOG_DIR%\maven-test.log +echo Package log: %CD%\%LOG_DIR%\maven-package.log +echo. + +REM Final Summary +echo ========================================== +if !ERRORS!==0 if !WARNINGS!==0 ( + echo [SUCCESS] VALIDATION SUCCESSFUL + echo All checks passed! + echo ========================================== + endlocal + exit /b 0 +) else if !ERRORS!==0 ( + echo [WARNING] VALIDATION COMPLETED WITH WARNINGS + echo Errors: !ERRORS!, Warnings: !WARNINGS! + echo Module system is functional, but some optional checks had issues + echo ========================================== + endlocal + exit /b 0 +) else ( + echo [ERROR] VALIDATION FAILED + echo Errors: !ERRORS!, Warnings: !WARNINGS! + echo Please fix the errors above and run validation again + echo ========================================== + endlocal + exit /b 1 +) + +endlocal diff --git a/src/site/validate-modules.sh b/src/site/validate-modules.sh new file mode 100644 index 000000000..4c397782e --- /dev/null +++ b/src/site/validate-modules.sh @@ -0,0 +1,219 @@ +#!/bin/bash +# validate-modules.sh +# +# Validates the Java Module System (JPMS) implementation for ODF Toolkit +# +# This script performs various checks to ensure the module-info.java files +# are correctly configured and the modules can be compiled and used. +# +# Run this script from the project root directory. + +# Change to project root directory (where this script is located) +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" +cd "$PROJECT_ROOT" + +# Don't exit on error - we want to collect all errors and show a summary +# set -e # Exit on error + +# Create build directory for logs if it doesn't exist +LOG_DIR="target/validation-logs" +mkdir -p "$LOG_DIR" + +# Error tracking +ERRORS=0 +WARNINGS=0 + +echo "==========================================" +echo "ODF Toolkit Module System Validation" +echo "==========================================" +echo "" + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Check if Java 17+ is available +echo -e "${BLUE}1. Checking Java version...${NC}" +if ! command -v java &> /dev/null; then + echo -e "${RED}✗ ERROR: Java is not installed or not in PATH${NC}" + ERRORS=$((ERRORS + 1)) +else + JAVA_VERSION=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1) + if [ "$JAVA_VERSION" -lt 17 ]; then + echo -e "${RED}✗ ERROR: Java 17 or higher is required. Found: Java $JAVA_VERSION${NC}" + ERRORS=$((ERRORS + 1)) + else + echo -e "${GREEN}✓ Java version OK: $(java -version 2>&1 | head -n 1)${NC}" + fi +fi +echo "" + +# Check if Maven is available +echo -e "${BLUE}2. Checking Maven...${NC}" +if ! command -v mvn &> /dev/null; then + echo -e "${RED}✗ ERROR: Maven is not installed or not in PATH${NC}" + ERRORS=$((ERRORS + 1)) +else + echo -e "${GREEN}✓ Maven found: $(mvn -version | head -n 1)${NC}" +fi +echo "" + +# Check if module-info.java files exist +echo -e "${BLUE}3. Checking module-info.java files...${NC}" +MODULE_FILES=( + "odfdom/src/main/java/module-info.java" + "validator/src/main/java/module-info.java" + "xslt-runner/src/main/java/module-info.java" +) + +MISSING_FILES=0 +for file in "${MODULE_FILES[@]}"; do + if [ -f "$file" ]; then + echo -e "${GREEN}✓ Found: $file${NC}" + else + echo -e "${RED}✗ Missing: $file${NC}" + MISSING_FILES=$((MISSING_FILES + 1)) + ERRORS=$((ERRORS + 1)) + fi +done +if [ $MISSING_FILES -eq 0 ]; then + echo -e "${GREEN} All module-info.java files are present${NC}" +fi +echo "" + +# Compile the project +echo -e "${BLUE}4. Compiling project with module support...${NC}" +echo -e "${YELLOW} Log file: $(pwd)/$LOG_DIR/maven-compile.log${NC}" +if mvn clean compile -DskipTests 2>&1 | tee "$LOG_DIR/maven-compile.log"; then + echo -e "${GREEN}✓ Compilation successful${NC}" +else + echo -e "${RED}✗ Compilation FAILED${NC}" + echo -e "${YELLOW} Full log available at: $LOG_DIR/maven-compile.log${NC}" + ERRORS=$((ERRORS + 1)) +fi +echo "" + +# Run tests +echo -e "${BLUE}5. Running tests...${NC}" +echo -e "${YELLOW} Log file: $(pwd)/$LOG_DIR/maven-test.log${NC}" +if mvn test 2>&1 | tee "$LOG_DIR/maven-test.log"; then + echo -e "${GREEN}✓ All tests passed${NC}" +else + echo -e "${YELLOW}⚠ Some tests failed${NC}" + echo -e "${YELLOW} Full log available at: $LOG_DIR/maven-test.log${NC}" + WARNINGS=$((WARNINGS + 1)) +fi +echo "" + +# Analyze module dependencies with jdeps +echo -e "${BLUE}6. Analyzing module dependencies with jdeps...${NC}" + +# Check if jdeps is available +if ! command -v jdeps &> /dev/null; then + echo -e "${YELLOW}⚠ jdeps not found, skipping dependency analysis${NC}" + echo -e "${YELLOW} Install JDK to get jdeps tool${NC}" + WARNINGS=$((WARNINGS + 1)) +else + JAR_FOUND=0 + + # Analyze ODFDOM module + for jar_file in odfdom/target/odfdom-java-*-SNAPSHOT.jar; do + if [ -f "$jar_file" ]; then + JAR_FOUND=1 + echo "Analyzing ODFDOM module: $(basename "$jar_file")" + if jdeps --module-path odfdom/target/classes \ + --add-modules org.odftoolkit.odfdom \ + --list-deps \ + "$jar_file" 2>&1 | head -30; then + echo -e "${GREEN} ✓ Dependency analysis successful${NC}" + else + echo -e "${YELLOW} ⚠ Dependency analysis had issues${NC}" + WARNINGS=$((WARNINGS + 1)) + fi + break + fi + done + + if [ $JAR_FOUND -eq 0 ]; then + echo -e "${YELLOW}⚠ ODFDOM JAR not found (package first)${NC}" + fi +fi +echo "" + +# Package the modules +echo -e "${BLUE}7. Packaging modules...${NC}" +echo -e "${YELLOW} Log file: $(pwd)/$LOG_DIR/maven-package.log${NC}" +if mvn package -DskipTests 2>&1 | tee "$LOG_DIR/maven-package.log"; then + echo -e "${GREEN}✓ Packaging successful${NC}" +else + echo -e "${RED}✗ Packaging FAILED${NC}" + echo -e "${YELLOW} Full log available at: $LOG_DIR/maven-package.log${NC}" + ERRORS=$((ERRORS + 1)) +fi +echo "" + +# Verify JAR files contain module-info.class +echo -e "${BLUE}8. Verifying module-info.class in JAR files...${NC}" +JAR_FILES=( + "odfdom/target/odfdom-java-*-SNAPSHOT.jar" + "xslt-runner/target/xslt-runner-*-SNAPSHOT.jar" +) + +JAR_CHECKED=0 +JAR_WITH_MODULE=0 +for jar_pattern in "${JAR_FILES[@]}"; do + for jar_file in $jar_pattern; do + if [ -f "$jar_file" ]; then + JAR_CHECKED=$((JAR_CHECKED + 1)) + if jar tf "$jar_file" 2>/dev/null | grep -q "module-info.class"; then + echo -e "${GREEN}✓ $(basename "$jar_file") contains module-info.class${NC}" + JAR_WITH_MODULE=$((JAR_WITH_MODULE + 1)) + else + echo -e "${RED}✗ $(basename "$jar_file") does NOT contain module-info.class${NC}" + ERRORS=$((ERRORS + 1)) + fi + fi + done +done + +if [ $JAR_CHECKED -eq 0 ]; then + echo -e "${YELLOW}⚠ No JAR files found to check (package first)${NC}" + WARNINGS=$((WARNINGS + 1)) +elif [ $JAR_WITH_MODULE -eq $JAR_CHECKED ]; then + echo -e "${GREEN} All JAR files contain module-info.class${NC}" +fi +echo "" + +# List all log files +echo "==========================================" +echo -e "${BLUE}Log Files:${NC}" +echo "==========================================" +echo -e "${YELLOW} Compilation log: $(pwd)/$LOG_DIR/maven-compile.log${NC}" +echo -e "${YELLOW} Test log: $(pwd)/$LOG_DIR/maven-test.log${NC}" +echo -e "${YELLOW} Package log: $(pwd)/$LOG_DIR/maven-package.log${NC}" +echo "" + +# Final Summary +echo "==========================================" +if [ $ERRORS -eq 0 ] && [ $WARNINGS -eq 0 ]; then + echo -e "${GREEN}✓ VALIDATION SUCCESSFUL${NC}" + echo -e "${GREEN} All checks passed!${NC}" + echo "==========================================" + exit 0 +elif [ $ERRORS -eq 0 ]; then + echo -e "${YELLOW}⚠ VALIDATION COMPLETED WITH WARNINGS${NC}" + echo -e "${YELLOW} Errors: $ERRORS, Warnings: $WARNINGS${NC}" + echo -e "${GREEN} Module system is functional, but some optional checks had issues${NC}" + echo "==========================================" + exit 0 +else + echo -e "${RED}✗ VALIDATION FAILED${NC}" + echo -e "${RED} Errors: $ERRORS, Warnings: $WARNINGS${NC}" + echo -e "${RED} Please fix the errors above and run validation again${NC}" + echo "==========================================" + exit 1 +fi diff --git a/validator/pom.xml b/validator/pom.xml index 62c9e3605..7060632ca 100644 --- a/validator/pom.xml +++ b/validator/pom.xml @@ -64,6 +64,13 @@ junit test + + + javax.servlet + javax.servlet-api + 4.0.1 + test + UTF-8 @@ -140,6 +147,10 @@ **/IntegrationTest.java **/ITJarTest.java + + + + false
@@ -226,7 +237,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 2.22.2 + 3.2.5 ${failsafeArgLine} @@ -239,6 +250,10 @@ ${project.version} org.odftoolkit.odfdom.pkg.DefaultErrorHandler + + + + false @@ -282,7 +297,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 2.22.2 + 3.2.5 integration-tests diff --git a/validator/src/main/java/module-info.java b/validator/src/main/java/module-info.java new file mode 100644 index 000000000..e47b9ac1b --- /dev/null +++ b/validator/src/main/java/module-info.java @@ -0,0 +1,80 @@ +/** + * ********************************************************************** + * + *

DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER + * + *

Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved. Copyright 2018-2026 + * The Document Foundation. All rights reserved. + * + *

Use is subject to license terms. + * + *

Licensed 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. You can also obtain a copy of the License at + * http://odftoolkit.org/docs/license.txt + * + *

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. + * + *

********************************************************************** + */ + +/** + * ODF Validator - OpenDocument Format Validation Tool + * + *

This module provides validation functionality for Open Document Format (ODF) files. It can be + * used as a command-line tool or deployed as a WAR file in a servlet container. + * + *

Main entry point: {@link org.odftoolkit.odfvalidator.Main} + * + * @moduleGraph + * @since 0.14.0 + */ +module org.odftoolkit.odfvalidator { + // ============================================================================ + // PUBLIC API EXPORTS + // ============================================================================ + + exports org.odftoolkit.odfvalidator; + + // ============================================================================ + // OPENS - For servlet containers and reflection-based frameworks + // ============================================================================ + + // Open for servlet containers and XML processing frameworks (WAR deployment) + // Servlet APIs are provided by the container at runtime + opens org.odftoolkit.odfvalidator to + java.xml; + + // ============================================================================ + // REQUIRES - Module dependencies + // ============================================================================ + + // Java Platform Modules + requires java.base; + requires java.desktop; // for javax.xml.* + requires java.logging; + requires java.xml; + + // ODFDOM module + requires org.odftoolkit.odfdom; + + // Automatic Modules (JARs without module-info.java) + requires org.apache + .commons + .fileupload; // commons-fileupload:commons-fileupload (has Automatic-Module-Name) + requires msv.core; // net.java.dev.msv:msv-core (msv-core-*.jar -> msv.core) + requires isorelax + .jaxp + .bridge + .ILM; // org.jopendocument:isorelax-jaxp-bridge-ILM (isorelax-jaxp-bridge-ILM-*.jar -> + // isorelax.jaxp.bridge.ILM) + requires xercesImpl; // xerces:xercesImpl (xercesImpl-*.jar -> xercesImpl) + +// Note: Servlet APIs are provided by the servlet container at runtime (WAR deployment) +// No compile-time dependency needed - servlet classes are available from the container +} diff --git a/xslt-runner/src/main/java/module-info.java b/xslt-runner/src/main/java/module-info.java new file mode 100644 index 000000000..f3c280ccf --- /dev/null +++ b/xslt-runner/src/main/java/module-info.java @@ -0,0 +1,58 @@ +/** + * ********************************************************************** + * + *

DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER + * + *

Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved. Copyright 2018-2026 + * The Document Foundation. All rights reserved. + * + *

Use is subject to license terms. + * + *

Licensed 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. You can also obtain a copy of the License at + * http://odftoolkit.org/docs/license.txt + * + *

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. + * + *

********************************************************************** + */ + +/** + * ODF XSLT Runner - XSLT Transformation Tool for ODF Documents + * + *

This module provides functionality to apply XSLT stylesheets to XML streams included in ODF + * packages without extracting them from the package. + * + *

Main entry point: {@link org.odftoolkit.odfxsltrunner.Main} + * + * @moduleGraph + * @since 0.14.0 + */ +module org.odftoolkit.odfxsltrunner { + // ============================================================================ + // PUBLIC API EXPORTS + // ============================================================================ + + exports org.odftoolkit.odfxsltrunner; + + // ============================================================================ + // REQUIRES - Module dependencies + // ============================================================================ + + // Java Platform Modules + requires java.base; + requires java.logging; + requires java.xml; + + // ODFDOM module + requires org.odftoolkit.odfdom; + + // Automatic Modules (JARs without module-info.java) + requires Saxon.HE; // net.sf.saxon:Saxon-HE (Saxon-HE-*.jar -> Saxon.HE) +}