xp-framework/xp-framework — pull request #231 by thekid (2013-02-03 16:53:38+00:00)
Title: Composed modules

This pull request is my first idea how to implement xp-framework/rfc#263 and be more or less compatible to the current module approach.

Essence
--
Every module is a class loader which has one or more delegate class loaders. The "root" delegate is the first class path element and has no name. Modules may be *extended* by other modules. By extending such a - previously loaded - module, the class loader the module stems from gets added to the parent module as delegate named after the module's name. From this point on, when asked to load classes, package or resources, not only the root delegate, but also the named extended delegate is asked.

Example
--
This module.xp file inside `src/main/php` describes the XP Framework's core module:

```php
module xp-framework/core(5.9.0-dev) {
}
```

The module instance's root delegate now points to the `src/main/php` location. The unittests are located in `src/test/php` and its module then extends the above module by using the following declaration:

```php
module tests extends xp-framework/core provides net.xp_framework.unittest, modules {
}
```

The class loader is not added to the default class loader's list, instead the "xp-framework/core" module now contains an additional delegate named `tests`, which provides only classes from the packages `net.xp_framework.unittest` and `modules`.

Discovery
--
The command line `-v` switch shows the modules. Example output:

```sh
$ xp -v
XP 5.9.0-dev { PHP 5.5.0alpha3 & ZE 2.5.0-dev } @ Windows NT LWKA-BN286R1 6.1 build 7601 (Windows 7 Business Edition Service Pack 1) i586
Copyright (c) 2001-2013 the XP group
Module@[
**: FileSystemCL<...\home\friebe\core\src\main\php\>
net.xp_framework.unittest: FileSystemCL<...\home\friebe\core\src\test\php\>
modules: FileSystemCL<...\home\friebe\core\src\test\php\>
net.xp_framework.unittest: FileSystemCL<...\home\friebe\core\src\test\resources\>
]
Module@[
xp.compiler: FileSystemCL<...\home\friebe\compiler\src\main\php\>
net.xp_lang.tests: FileSystemCL<...\home\friebe\compiler\src\test\php\>
]
FileSystemCL<...\home\friebe\>
```