-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Scope of Change
Module dependency support will be added to the XP Framework. Modules as defined in RFC #220 are a group of types and resources with added metadata and optional initialization code.
Rationale
Take for example an application that someone has written using the XP Framework and wants to make it available for the public to use. This application uses a certain version of the framework (or a range, such as "5.9-SERIES"), but also depends on a certain module which is not part of the framework but the app's author himself has written and made
available as a separate download. The following questions arise:
- How is the dependency on the library tracked?
- How is the framework version verified?
Functionality
At the moment, this would probably be accomplished by checking the framework version comparing against xp::version() and then verifying the dependencies are loaded using module reflection, maybe checking against an annotation. This would be a possible implementation:
<?php
module imaging(1.0.0) {
private static $dependencies= array(
'parellels' => '1.0.5'
'core' => '5.9*'
);
static function __static() {
foreach (self::$dependencies as $module => $constraint) {
$version= Module::forName($module)->getVersion();
$l= strlen($constraint)- 1;
if ('*' === $constraint{$l}) {
$result= version_compare($version, substr($constraint, 0, -1), 'ge');
} else if ('+' === $constraint{$l}) {
$result= version_compare($version, substr($constraint, 0, -1), 'gt');
} else {
$result= version_compare($version, $constraint, 'eq');
}
if (!$result) throw new IllegalStateException('Dependency '.$module.'('.$constraint.') not met');
}
}
}
?>This RFC will standardize this procedure.
Defining dependencies
Dependencies are expressed via requires statement containing a list of dependencies:
<?php
module imaging(0.1.1) requires parallels(1.0.5), core(5.9.0*) {
}
?>The following rules apply for the dependency version:
5.9.0+=> must be greater than 5.9.05.9.0*=> must be greater than or equal to 5.9.05.9.0=> must be equal to 5.9.0
Reflection
<?php
$module= Module::forName('imaging');
$dependencies= $module->getDependencies(); // array('parallels' => '1.0.5', 'core' => '5.9.0*')
?>Security considerations
Speed impact
Dependencies
RFC #220
Related documents
- http://xp-framework.net/rfc/contrib/rfc0204-modules.diff
Alternative implementation - http://openjdk.java.net/projects/modules/
Java Modules @ OpenJDK - http://openjdk.java.net/projects/modules/samplerepo/
Online repository - http://www.javabeat.net/articles/print.php?article_id=101
Introduction to Java Module System in Java 7.0 - http://mediacast.sun.com/users/sundelabassee/media/J1Ag_Modularity.pdf
Modularity in Java OSGi and/or JSR 277 - http://blogs.sun.com/abuckley/resource/Devoxx2008-ModularityInJava.pdf
Modularity in Java - Devoxx 2008