Skip to content
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ classlib.pack.gz
/mavenizer/target/**
**/.shelf/
**/.idea/
/jnode-maven-plugin/target/**
184 changes: 184 additions & 0 deletions jnode-maven-plugin/CONVERSION_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# Conversion of Ant PluginTask to Maven Plugin - Summary

## Overview

Successfully converted the Ant-based `PluginTask` from `builder/src/builder/org/jnode/build/PluginTask.java` to a Maven plugin (`jnode-maven-plugin`).

## What Was Done

### 1. Created Maven Plugin Module Structure
- **Location**: `jnode-maven-plugin/`
- **Packaging**: `maven-plugin`
- **Main Mojo**: `org.jnode.maven.PluginBuildMojo`

### 2. Key Features Implemented

#### Plugin Building
- Reads plugin descriptor XML files from a specified directory
- Parses descriptors using NanoXML (same as Ant version)
- Generates plugin JAR files with OSGi-style manifests
- Supports incremental builds (only rebuilds when sources change)

#### Parallel Processing
- Uses `ThreadPoolExecutor` for concurrent plugin building (same as Ant version)
- Configurable thread pool size (default: 10 threads)
- Configurable queue capacity (default: 500 plugins)

#### Manifest Generation
- Creates OSGi-style manifests with:
- `Bundle-SymbolicName`: Plugin ID
- `Bundle-ManifestVersion`: 2
- `Bundle-Version`: Plugin version

### 3. Dependencies Resolution

**Key Decision**: Used plugin model classes from `mavenizer/src/main/endorsed` instead of `core/src/core/org/jnode/plugin`.

**Rationale**:
- Mavenizer versions are specifically designed for build-time use
- They don't have runtime VM dependencies (no dependencies on `org.jnode.vm.*` packages)
- Already proven to work in the mavenizer project for similar purposes
- Avoids pulling in entire JNode VM classpath

### 4. Configuration Parameters

The Maven plugin supports the following configuration:

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `descriptorsDirectory` | File | Yes | - | Directory containing plugin descriptor XML files |
| `outputDirectory` | File | Yes | `${project.build.directory}/plugins` | Output directory for plugin JARs |
| `tmpDirectory` | File | No | `${project.build.directory}/tmp/plugins` | Temporary directory |
| `pluginDirectory` | File | Yes | - | Directory containing source classes for plugins |
| `libraryAliases` | Map | No | empty | Mapping of library names to actual files |
| `maxThreadCount` | int | No | 10 | Maximum concurrent threads |
| `maxPluginCount` | int | No | 500 | Maximum queued plugins |
| `compressJars` | boolean | No | false | Whether to compress JAR files |

## Comparison: Ant vs Maven

### Ant (Before)
```xml
<taskdef name="plugin" classname="org.jnode.build.PluginTask" classpathref="cp-jnode"/>
<plugin todir="${plugins.dir}" tmpdir="${build.dir}/tmp/plugins" pluginDir="${descriptors.dir}">
<libalias name="jnode-core.jar" alias="${jnode-core.jar}"/>
<descriptors dir="${descriptors.dir}/">
<include name="*.xml"/>
</descriptors>
</plugin>
```

### Maven (After)
```xml
<plugin>
<groupId>org.jnode</groupId>
<artifactId>jnode-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<descriptorsDirectory>${basedir}/descriptors</descriptorsDirectory>
<outputDirectory>${project.build.directory}/plugins</outputDirectory>
<pluginDirectory>${project.build.directory}/classes</pluginDirectory>
<libraryAliases>
<jnode-core.jar>${jnode-core.jar}</jnode-core.jar>
</libraryAliases>
</configuration>
</plugin>
```

## Known Limitations

### 1. Library Export/Exclude Filtering
- **Status**: Partially implemented
- **Description**: The Ant version had complex logic for processing `<export>` and `<exclude>` patterns from library definitions
- **Action Required**: Full implementation pending in the `addLibraryToJar()` method

### 2. Packager Subtasks
- **Status**: Not converted
- **Description**: The Ant version supported a `<packager>` nested element
- **Action Required**: May be added in future versions if needed

### 3. FileSet Processing
- **Status**: Simplified
- **Description**: Ant version used complex FileSet/ZipFileSet processing
- **Current**: Simplified file discovery (scans directory for *.xml files)

## Files Created/Modified

### New Files
- `jnode-maven-plugin/pom.xml` - Maven plugin POM
- `jnode-maven-plugin/src/main/java/org/jnode/maven/PluginBuildMojo.java` - Main Mojo class
- `jnode-maven-plugin/README.md` - Documentation and usage guide

### Modified Files
- `.gitignore` - Added `/jnode-maven-plugin/target/**` to ignore build artifacts

## Build and Usage

### Building the Plugin
```bash
cd jnode-maven-plugin
mvn clean install
```

This installs the plugin in your local Maven repository.

### Using the Plugin
```xml
<build>
<plugins>
<plugin>
<groupId>org.jnode</groupId>
<artifactId>jnode-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build-plugin</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorsDirectory>${basedir}/core/descriptors</descriptorsDirectory>
<outputDirectory>${project.build.directory}/plugins</outputDirectory>
<pluginDirectory>${project.build.directory}/classes</pluginDirectory>
</configuration>
</plugin>
</plugins>
</build>
```

## Testing Status

- [x] Maven plugin compiles successfully
- [x] No compilation errors
- [x] Deprecation warnings noted (SecurityManager, AccessController - these are in the copied plugin model classes)
- [ ] End-to-end testing with actual plugin descriptors (pending)
- [ ] Integration with full JNode Maven build (pending)

## Next Steps

1. **Complete Library Filtering**: Implement full export/exclude pattern matching in `addLibraryToJar()`
2. **Integration Testing**: Test with actual JNode plugin descriptors
3. **Performance Testing**: Compare build times with Ant version
4. **Documentation**: Add more examples and troubleshooting guide
5. **Migration**: Update JNode build to use Maven plugin instead of Ant task

## Security Summary

No security vulnerabilities were introduced in this conversion:
- Uses standard Maven plugin APIs
- File operations use proper Java I/O APIs
- No untrusted user input processed without validation
- Descriptor parsing uses established NanoXML library
- Deprecation warnings in copied plugin model classes are not security issues

## Conclusion

The conversion from Ant PluginTask to Maven plugin was successful. The core functionality has been preserved:
- Plugin descriptor parsing
- JAR generation with manifests
- Parallel building
- Incremental build support

The Maven plugin is ready for integration testing and can be further enhanced with the remaining features as needed.
144 changes: 144 additions & 0 deletions jnode-maven-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# JNode Maven Plugin

This Maven plugin provides the functionality to build JNode plugins, converting the previous Ant-based `PluginTask` to a Maven Mojo.

## Overview

The JNode Maven Plugin (`jnode-maven-plugin`) is used to build JNode plugin JAR files from plugin descriptor XML files. It reads plugin descriptors, processes runtime libraries with export/exclude filters, and generates plugin JARs with appropriate manifests.

## Conversion from Ant

This plugin replaces the Ant `PluginTask` defined in `builder/src/builder/org/jnode/build/PluginTask.java`. The main differences:

### Ant Task (before)
```xml
<taskdef name="plugin" classname="org.jnode.build.PluginTask" classpathref="cp-jnode"/>
<plugin todir="${plugins.dir}" tmpdir="${build.dir}/tmp/plugins" pluginDir="${descriptors.dir}">
<libalias name="jnode-core.jar" alias="${jnode-core.jar}"/>
<!-- more aliases -->
<descriptors dir="${descriptors.dir}/">
<include name="*.xml"/>
<exclude name="*plugin-list.xml"/>
</descriptors>
</plugin>
```

### Maven Plugin (after)
```xml
<plugin>
<groupId>org.jnode</groupId>
<artifactId>jnode-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build-plugin</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorsDirectory>${basedir}/descriptors</descriptorsDirectory>
<outputDirectory>${project.build.directory}/plugins</outputDirectory>
<pluginDirectory>${project.build.directory}/classes</pluginDirectory>
<libraryAliases>
<jnode-core.jar>${jnode-core.jar}</jnode-core.jar>
<!-- more aliases -->
</libraryAliases>
</configuration>
</plugin>
```

## Configuration Parameters

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `descriptorsDirectory` | File | Yes | - | Directory containing plugin descriptor XML files |
| `outputDirectory` | File | Yes | `${project.build.directory}/plugins` | Output directory for generated plugin JAR files |
| `tmpDirectory` | File | No | `${project.build.directory}/tmp/plugins` | Temporary directory for intermediate files |
| `pluginDirectory` | File | Yes | - | Directory containing source classes and resources for plugins |
| `libraryAliases` | Map<String, File> | No | empty | Mapping of library names to actual file locations |
| `maxThreadCount` | int | No | 10 | Maximum number of concurrent threads for building plugins |
| `maxPluginCount` | int | No | 500 | Maximum number of plugins that can be queued |
| `compressJars` | boolean | No | false | Whether to compress the generated JAR files |

## Usage Example

```xml
<build>
<plugins>
<plugin>
<groupId>org.jnode</groupId>
<artifactId>jnode-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<id>build-plugins</id>
<phase>package</phase>
<goals>
<goal>build-plugin</goal>
</goals>
<configuration>
<descriptorsDirectory>${basedir}/core/descriptors</descriptorsDirectory>
<outputDirectory>${project.build.directory}/plugins</outputDirectory>
<pluginDirectory>${project.build.directory}/classes</pluginDirectory>
<libraryAliases>
<jnode-core.jar>${basedir}/core/build/classes</jnode-core.jar>
<jnode-fs.jar>${basedir}/fs/build/classes</jnode-fs.jar>
</libraryAliases>
<maxThreadCount>4</maxThreadCount>
<compressJars>false</compressJars>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
```

## Plugin Descriptor Format

Plugin descriptors are XML files that describe JNode plugins. See [docs/plugins/plugin.md](../../docs/plugins/plugin.md) for detailed documentation on the plugin descriptor format.

Example descriptor:
```xml
<plugin id="org.jnode.example" version="1.0">
<runtime>
<library name="jnode-core.jar">
<export name="org.jnode.example.*"/>
</library>
</runtime>
</plugin>
```

## Building the Plugin

To build the Maven plugin itself:

```bash
cd jnode-maven-plugin
mvn clean install
```

This will install the plugin in your local Maven repository, making it available for use in other JNode projects.

## Key Features

- **Parallel Plugin Building**: Builds multiple plugins concurrently using a thread pool
- **Incremental Builds**: Only rebuilds plugins when descriptors or dependencies have changed
- **Library Aliasing**: Maps logical library names (e.g., `jnode-core.jar`) to actual file locations
- **Manifest Generation**: Automatically generates OSGi-style manifests with Bundle-SymbolicName and Bundle-Version
- **Export/Exclude Filtering**: Processes library export and exclude patterns from plugin descriptors

## Limitations

The current implementation is a direct port of the Ant task and includes:
- Basic library export/exclude filtering (full implementation pending)
- No support for packager subtasks (may be added in future versions)
- Simplified JAR creation compared to the Ant version

## See Also

- [Plugin Documentation](../../docs/plugins/plugin.md) - Details on plugin descriptor format
- [Plugin List Documentation](../../docs/plugins/plugin-list.md) - Information about plugin lists
- Original Ant task: `builder/src/builder/org/jnode/build/PluginTask.java`
Loading