Skip to content
Permalink
Browse files

[#781] Load dependencies in order of the dependencies.yml file. depre…

…cate modules loading from applciation.conf
  • Loading branch information...
Igmar Palsenberg authored and Notalifeform committed Jan 16, 2013
1 parent 6e2781b commit d3f2984669d383d1bbe35d08bcebdab19f0417b6
@@ -283,12 +283,26 @@
<echo message="*****************" />
</target>

<target name="check-dependencies-file">
<available file="${testAppPath}/conf/dependencies.yml" property="dependencies.present"/>
</target>

<target name="do-deps" depends="check-dependencies-file" if="dependencies.present">
<exec executable="${basedir}/../play${playExtension}" failonerror="false" spawn="false">
<arg value="deps"/>
<arg value="${testAppPath}"/>
</exec>
</target>

<target name="play-test">
<antcall target="do-deps">
<param name="testAppPath" value="${testAppPath}"/>
</antcall>
<echo message="play auto-test ${testAppPath} (wait)" />
<exec executable="${basedir}/../play${playExtension}" failonerror="true">
<arg value="auto-test"/>
<arg value="${testAppPath}"/>
</exec>
<arg value="auto-test"/>
<arg value="${testAppPath}"/>
</exec>
<available file="${testAppPath}/test-result/result.passed" property="${testAppPath}testPassed" />
<fail message="Last test has failed ! (Check results in file://${testAppPath}/test-result)">
<condition>
@@ -207,8 +207,7 @@ def new(app, args, play_env):
os.mkdir(os.path.join(app.path, 'src/play/modules/%s' % application_name))

print "~ OK, the module is created."
print "~ Start using it by adding this line in the application.conf modules list: "
print "~ module.%s=%s" % (application_name, os.path.normpath(app.path))
print "~ Start using it by adding it to the dependencies.yml of your project, as decribed in the documentation."
print "~"
print "~ Have fun!"
print "~"
@@ -15,6 +15,7 @@
import play.cache.Cache;
import play.classloading.ApplicationClasses;
import play.classloading.ApplicationClassloader;
import play.deps.DependenciesManager;
import play.exceptions.PlayException;
import play.exceptions.UnexpectedException;
import play.libs.IO;
@@ -706,48 +707,45 @@ public static void loadModules() {
}
}
}
for (Object key : configuration.keySet()) {
String pName = key.toString();
if (pName.startsWith("module.")) {
Logger.warn("Declaring modules in application.conf is deprecated. Use dependencies.yml instead (%s)", pName);
String moduleName = pName.substring(7);
File modulePath = new File(configuration.getProperty(pName));
if (!modulePath.isAbsolute()) {
modulePath = new File(applicationPath, configuration.getProperty(pName));
}
if (!modulePath.exists() || !modulePath.isDirectory()) {
Logger.error("Module %s will not be loaded because %s does not exist", moduleName, modulePath.getAbsolutePath());
} else {
addModule(moduleName, modulePath);
}
}
}

// Load modules from modules/ directory
File localModules = Play.getFile("modules");
if (localModules.exists() && localModules.isDirectory()) {
for (File module : localModules.listFiles()) {
String moduleName = module.getName();
if (moduleName.startsWith(".")) {
Logger.info("Module %s is ignored, name starts with a dot", moduleName);
continue;
// Load modules from modules/ directory, but get the order from the dependencies.yml file
// .listFiles() returns items in an OS dependant sequence, which is bad
// See #781
// the yaml parser wants play.version as an environment variable
System.setProperty("play.version", Play.version);
DependenciesManager dm = new DependenciesManager(applicationPath, frameworkPath, null);

File localModules = Play.getFile("modules");
List<String> modules = new ArrayList<String>();
if (localModules.exists() && localModules.isDirectory()) {
try {
modules = dm.retrieveModules();
} catch (Exception e) {
throw new UnexpectedException("There was a problem parsing dependencies.yml");

}
for (Iterator iter = modules.iterator(); iter.hasNext();) {
String moduleName = (String) iter.next();

File module = new File(localModules, moduleName);

if (moduleName.contains("-")) {
moduleName = moduleName.substring(0, moduleName.indexOf("-"));
}

if (module.isDirectory()) {
addModule(moduleName, module);
} else {
File modulePath = new File(IO.readContentAsString(module).trim());
if (!modulePath.exists() || !modulePath.isDirectory()) {
Logger.error("Module %s will not be loaded because %s does not exist", moduleName, modulePath.getAbsolutePath());
} else {
addModule(moduleName, modulePath);
}
}
}
}
if (moduleName.contains("-")) {
moduleName = moduleName.substring(0, moduleName.indexOf("-"));
}
if (module.isDirectory()) {
addModule(moduleName, module);
} else {
File modulePath = new File(IO.readContentAsString(module).trim());
if (!modulePath.exists() || !modulePath.isDirectory()) {
Logger.error("Module %s will not be loaded because %s does not exist", moduleName, modulePath.getAbsolutePath());
} else {
addModule(moduleName, modulePath);
}

}
}
}
// Auto add special modules
if (Play.runningInTestMode()) {
addModule("_testrunner", new File(Play.frameworkPath, "modules/testrunner"));
@@ -156,6 +156,39 @@ public boolean problems() {
return false;
}

public List<String> retrieveModules() throws Exception {
ModuleDescriptorParserRegistry.getInstance().addParser(new YamlParser());
File ivyModule = new File(application, "conf/dependencies.yml");
ResolveReport report;
List<String> modules = new ArrayList<String>();

System.setProperty("play.path", framework.getAbsolutePath());
Ivy ivy = configure();

ResolveEngine resolveEngine = ivy.getResolveEngine();
ResolveOptions resolveOptions = new ResolveOptions();
resolveOptions.setConfs(new String[]{"default"});
resolveOptions.setArtifactFilter(FilterHelper.getArtifactTypeFilter(new String[]{"jar", "bundle", "source"}));

report = resolveEngine.resolve(ivyModule.toURI().toURL(), resolveOptions);

for (Iterator iter = report.getDependencies().iterator(); iter.hasNext(); ) {
IvyNode node = (IvyNode) iter.next();
if (node.isLoaded()) {
ArtifactDownloadReport[] adr = report.getArtifactsReports(node.getResolvedId());
for (ArtifactDownloadReport artifact : adr) {
if (artifact.getLocalFile() != null) {
if (isPlayModule(artifact) || !isFrameworkLocal(artifact)) {
modules.add(artifact.getLocalFile().getName());
}
}
}
}
}

return modules;
}

public List<File> retrieve(ResolveReport report) throws Exception {

// Track missing artifacts
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file provides limited functionalities for system without Python.
If Python is available, the play command is recommended over this build file.
Usage:
Example 1:
export PLAY_PATH=/home/user/play
ant run
Sets play path to the environment variable PLAY_PATH and then runs play with target run.
Example 2:
ant run -Dplay.path=/home/user/play
Gives the play path to the ant as command line property.
Example 3:
build.xml:
...
<property name="play.path" value="/home/user/play"/>
...
ant run
Sets the play path to the build.xml directly.
-->
<project basedir=".">

<property environment="env"/>
<property name="play.path" value="${env.PLAY_PATH}"/>
<import file="${play.path}/resources/application-build.xml"/>
</project>
@@ -26,16 +26,6 @@ application.mode=dev
#
application.secret=u21t9xqags2k4p2rb7e56xw72z9sttyrl0yvtr2f060ywlpycbqj5lvbpdsmaula


# Additional modules
# ~~~~~
# A module is another play! application. Add a line for each module you want
# to add to your application. Modules path are either absolutes or relative to
# the application root.
#
module.crud=${play.path}/modules/crud


# i18n
# ~~~~~
# Define locales used by your application.
@@ -134,4 +124,4 @@ db=fs
%test.db=mem
%test.application.superadmin=test
%test.application.superadminpwd=test
%test.application.mode=dev
%test.application.mode=dev
@@ -0,0 +1,5 @@
# Application dependencies

require:
- play
- crud
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file provides limited functionalities for system without Python.
If Python is available, the play command is recommended over this build file.
Usage:
Example 1:
export PLAY_PATH=/home/user/play
ant run
Sets play path to the environment variable PLAY_PATH and then runs play with target run.
Example 2:
ant run -Dplay.path=/home/user/play
Gives the play path to the ant as command line property.
Example 3:
build.xml:
...
<property name="play.path" value="/home/user/play"/>
...
ant run
Sets the play path to the build.xml directly.
-->
<project basedir=".">

<property environment="env"/>
<property name="play.path" value="${env.PLAY_PATH}"/>
<import file="${play.path}/resources/application-build.xml"/>

<target name="test" depends="clean,jar" description="">
<echo message="test 123" />
</target>

</project>
@@ -20,15 +20,6 @@ application.mode=dev
#
application.secret=w55izhmwgf2diaqkggip21fu90lq6zjnzoetmrn8grjarijjhan3asa874djvqq5

# Additional modules
# ~~~~~
# A module is another play! application. Add a line for each module you want
# to add to your application. Modules path are either absolutes or relative to
# the application root.
#
#module.ecss=${play.path}/modules/ecss
module.crud=${play.path}/modules/crud

# i18n
# ~~~~~
# Define locales used by your application.
@@ -0,0 +1,5 @@
# Application dependencies

require:
- play
- crud
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file provides limited functionalities for system without Python.
If Python is available, the play command is recommended over this build file.
Usage:
Example 1:
export PLAY_PATH=/home/user/play
ant run
Sets play path to the environment variable PLAY_PATH and then runs play with target run.
Example 2:
ant run -Dplay.path=/home/user/play
Gives the play path to the ant as command line property.
Example 3:
build.xml:
...
<property name="play.path" value="/home/user/play"/>
...
ant run
Sets the play path to the build.xml directly.
-->
<project basedir=".">

<property environment="env"/>
<property name="play.path" value="${env.PLAY_PATH}"/>
<import file="${play.path}/resources/application-build.xml"/>

<target name="test" depends="clean,jar" description="">
<echo message="test 123" />
</target>

</project>
@@ -20,21 +20,6 @@ application.mode=dev
# If you deploy your application to several instances be sure to use the same key !
application.secret=s1kwayg211q9v4387pvarbmyqnht7hrl54d34lsz0yh9btb117br293a25trz31o

# Additional modules
# ~~~~~
# A module is another play! application. Add a line for each module you want
# to add to your application. Modules path are either absolutes or relative to
# the application root.

# Import the crud module
module.crud=${play.path}/modules/crud

# Import the secure module
module.secure=${play.path}/modules/secure

# Import the cobertura module in test mode
#%test.module.cobertura=${play.path}/modules/cobertura

# i18n
# ~~~~~
# Define locales used by your application.
@@ -0,0 +1,6 @@
# Application dependencies

require:
- play
- crud
- secure

0 comments on commit d3f2984

Please sign in to comment.
You can’t perform that action at this time.