Skip to content

Commit

Permalink
Manage dependencies for 'play new --with moduleA,moduleB' command
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumebort committed Jan 30, 2011
1 parent 1ba99de commit f72cf6a
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 27 deletions.
2 changes: 1 addition & 1 deletion documentation/manual/ide.textile
Expand Up @@ -76,7 +76,7 @@ h3. Classpath settings
A Play application classpath is built as follows (in this order):

* The **conf/** directory for the application
* The **$PLAY_PATH/framework/play.jar**
* The **$PLAY_PATH/framework/play-$version.jar**
* All JAR files found in your application’s **lib/** directory
* All JAR files found in the **$PLAY_PATH/framework/lib/** directory

Expand Down
26 changes: 15 additions & 11 deletions framework/build.xml
Expand Up @@ -5,20 +5,24 @@
<property name="baseversion" value="master" />

<path id="project.classpath">
<pathelement path="play.jar"/>
<fileset dir=".">
<include name="play-*.jar"/>
</fileset>
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</fileset>
</path>

<target name="clean" description="clean resources">
<delete dir="classes" />
<delete dir="dist" />
<delete dir="tests-results" />
<delete dir="tests-tmp" />
<delete file="play.jar" />
<delete file="src/play/version" />
<delete file="src/play/version" />
<delete includeemptydirs="true">
<fileset dir=".">
<include name="play-*.jar" />
</fileset>
<fileset dir="pym">
<include name="**/*.pyc"/>
</fileset>
Expand Down Expand Up @@ -84,10 +88,10 @@
</javadoc>
</target>

<target name="jar" depends="compile,version,modules" description="create play.jar">
<target name="jar" depends="clean,version,compile,modules" description="create play.jar">
<echo message="${version}" file="src/play/version" />
<echo message="${version}" file="classes/play/version" />
<jar destfile="play.jar" basedir="classes">
<jar destfile="play-${version}.jar" basedir="classes">
<manifest>
<attribute name="Premain-Class" value="play.classloading.HotswapAgent"/>
<attribute name="Can-Redefine-Classes" value="true" />
Expand Down Expand Up @@ -134,7 +138,7 @@
<sysproperty key="play.id" value="${play.id}" />
<sysproperty key="java.endorsed.dirs" value="${basedir}/endorsed" />
<sysproperty key="play.debug" value="true" />
<jvmarg value="-javaagent:${basedir}/play.jar" />
<jvmarg value="-javaagent:${basedir}/play-${version}.jar" />
<jvmarg value="-Xdebug"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.port},server=y,suspend=n"/>
<jvmarg value="${profiler.info.jvmargs.agent}"/>
Expand All @@ -157,7 +161,7 @@
<sysproperty key="play.id" value="${play.id}" />
<sysproperty key="java.endorsed.dirs" value="${basedir}/endorsed" />
<sysproperty key="play.debug" value="true" />
<jvmarg value="-javaagent:${basedir}/play.jar" />
<jvmarg value="-javaagent:${basedir}/play-${version}.jar" />
<jvmarg value="-Xdebug"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.port},server=y,suspend=n"/>
</java>
Expand All @@ -179,7 +183,7 @@
<sysproperty key="application.path" value="${application.path}" />
<sysproperty key="play.id" value="test" />
<sysproperty key="java.endorsed.dirs" value="${basedir}/endorsed" />
<jvmarg value="-javaagent:${basedir}/play.jar" />
<jvmarg value="-javaagent:${basedir}/play-${version}.jar" />
<jvmarg value="-Xdebug"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.port},server=y,suspend=n"/>
</java>
Expand Down Expand Up @@ -276,7 +280,7 @@
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
<jvmarg value="-javaagent:${basedir}/play.jar" />
<jvmarg value="-javaagent:${basedir}/play-${version}.jar" />
<sysproperty key="tests-tmp" value="${basedir}/tests-tmp" />
</junit>
<delete dir="${basedir}/tests-tmp" />
Expand All @@ -293,7 +297,7 @@
</classpath>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
<jvmarg value="-javaagent:${basedir}/play.jar" />
<jvmarg value="-javaagent:${basedir}/play-${version}.jar" />
<sysproperty key="tests-tmp" value="${basedir}/tests-tmp" />
</junit>
<delete dir="${basedir}/tests-tmp" />
Expand Down
4 changes: 2 additions & 2 deletions framework/dependencies.yml
Expand Up @@ -61,9 +61,9 @@ repositories:
- playCore:
type: local
descriptor: "${play.path}/framework/dependencies.yml"
artifact: "${play.path}/framework/play.jar"
artifact: "${play.path}/framework/play-[revision].jar"
contains:
- play -> play $version
- play -> play

- playCoreDependencies:
type: local
Expand Down
4 changes: 2 additions & 2 deletions framework/pym/play/application.py
Expand Up @@ -128,7 +128,7 @@ def getClasspath(self):

# The default
classpath.append(os.path.normpath(os.path.join(self.path, 'conf')))
classpath.append(os.path.normpath(os.path.join(self.play_env["basedir"], 'framework/play.jar')))
classpath.append(os.path.normpath(os.path.join(self.play_env["basedir"], 'framework/play-%s.jar' % self.play_env['version'])))

# The application
if os.path.exists(os.path.join(self.path, 'lib')):
Expand All @@ -153,7 +153,7 @@ def getClasspath(self):
return classpath

def agent_path(self):
return os.path.join(self.play_env["basedir"], 'framework/play.jar')
return os.path.join(self.play_env["basedir"], 'framework/play-%s.jar' % self.play_env['version'])

def cp_args(self):
classpath = self.getClasspath()
Expand Down
24 changes: 18 additions & 6 deletions framework/pym/play/commands/base.py
Expand Up @@ -28,11 +28,12 @@ def execute(**kargs):
app = kargs.get("app")
args = kargs.get("args")
env = kargs.get("env")
cmdloader = kargs.get("cmdloader")

if command == 'id':
id(env)
if command == 'new' or command == 'new,run':
new(app, args, env)
new(app, args, env, cmdloader)
if command == 'clean' or command == 'clean,run':
clean(app)
if command == 'new,run' or command == 'clean,run' or command == 'run':
Expand All @@ -44,7 +45,7 @@ def execute(**kargs):
if command == 'modules':
show_modules(app, args)

def new(app, args, env):
def new(app, args, env, cmdloader=None):
withModules = []
application_name = None
try:
Expand Down Expand Up @@ -96,11 +97,22 @@ def new(app, args, env):
replaceAll(os.path.join(app.path, 'conf/application.conf'), r'%SECRET_KEY%', secretKey())
print "~"

# Configure modules
runDepsAfter = False
for m in md:
mn = m
if mn.find('-') > 0:
mn = mn[:mn.find('-')]
replaceAll(os.path.join(app.path, 'conf/application.conf'), r'# ---- MODULES ----', '# ---- MODULES ----\nmodule.%s=${play.path}/modules/%s' % (mn, m) )
# Check dependencies.yml of the module
depsYaml = os.path.join(env["basedir"], 'modules/%s/conf/dependencies.yml' % m)
if os.path.exists(depsYaml):
deps = open(depsYaml).read()
try:
moduleDefinition = re.search(r'self:\s*(.*)\s*', deps).group(1)
replaceAll(os.path.join(app.path, 'conf/dependencies.yml'), r'- play\n', '- play\n - %s\n' % moduleDefinition )
runDepsAfter = True
except Exception:
pass

if runDepsAfter:
cmdloader.commands['dependencies'].execute(command='dependencies', app=app, args=['--sync'], env=env, cmdloader=cmdloader)

print "~ OK, the application is created."
print "~ Start it with : play run %s" % sys.argv[2]
Expand Down
4 changes: 3 additions & 1 deletion framework/pym/play/commands/eclipse.py
Expand Up @@ -52,7 +52,7 @@ def execute(**kargs):
shutil.copytree(os.path.join(play_env["basedir"], 'resources/eclipse/.settings'), dotSettings)
replaceAll(dotProject, r'%PROJECT_NAME%', application_name)

playJarPath = os.path.join(play_env["basedir"], 'framework','play.jar')
playJarPath = os.path.join(play_env["basedir"], 'framework', 'framework/play-%s.jar' % self.play_env['version'])
playSourcePath = os.path.dirname(playJarPath)
if os.name == 'nt':
playSourcePath=playSourcePath.replace('\\','/').capitalize()
Expand Down Expand Up @@ -103,11 +103,13 @@ def execute(**kargs):
replaceAll(os.path.join(app.path, 'eclipse/debug.launch'), r'%PLAY_BASE%', play_env["basedir"])
replaceAll(os.path.join(app.path, 'eclipse/debug.launch'), r'%PLAY_ID%', play_env["id"])
replaceAll(os.path.join(app.path, 'eclipse/debug.launch'), r'%JPDA_PORT%', str(app.jpda_port))
replaceAll(os.path.join(app.path, 'eclipse/debug.launch'), r'%PLAY_VERSION%', play_env["version"])

replaceAll(os.path.join(app.path, 'eclipse/test.launch'), r'%PROJECT_NAME%', application_name)
replaceAll(os.path.join(app.path, 'eclipse/test.launch'), r'%PLAY_BASE%', play_env["basedir"])
replaceAll(os.path.join(app.path, 'eclipse/test.launch'), r'%PLAY_ID%', play_env["id"])
replaceAll(os.path.join(app.path, 'eclipse/test.launch'), r'%JPDA_PORT%', str(app.jpda_port))
replaceAll(os.path.join(app.path, 'eclipse/test.launch'), r'%PLAY_VERSION%', play_env["version"])

replaceAll(os.path.join(app.path, 'eclipse/connect.launch'), r'%PROJECT_NAME%', application_name)
replaceAll(os.path.join(app.path, 'eclipse/connect.launch'), r'%JPDA_PORT%', str(app.jpda_port))
Expand Down
1 change: 1 addition & 0 deletions framework/pym/play/commands/intellij.py
Expand Up @@ -25,6 +25,7 @@ def execute(**kargs):
cpXML = ""

replaceAll(imlFile, r'%PLAYHOME%', play_env["basedir"].replace('\\', '/'))
replaceAll(imlFile, r'%PLAYVERSION%', play_env["version"].replace('\\', '/'))

if len(modules):
lXML = ""
Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/deps/DependenciesManager.java
Expand Up @@ -192,7 +192,7 @@ public List<File> retrieve(ResolveReport report) throws Exception {

public File install(ArtifactDownloadReport artifact) throws Exception {
try {
File from = artifact.getLocalFile().getCanonicalFile();
File from = artifact.getLocalFile();
if (!isPlayModule(artifact)) {
File to = new File(application, "lib" + File.separator + from.getName()).getCanonicalFile();
new File(application, "lib").mkdir();
Expand Down
4 changes: 4 additions & 0 deletions modules/crud/conf/dependencies.yml
@@ -0,0 +1,4 @@
self: play -> crud $version

require:
- play
4 changes: 4 additions & 0 deletions modules/secure/conf/dependencies.yml
@@ -0,0 +1,4 @@
self: play -> secure $version

require:
- play
2 changes: 1 addition & 1 deletion resources/eclipse/debug.launch
Expand Up @@ -15,6 +15,6 @@
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="play.server.Server"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="%PROJECT_NAME%"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xdebug -Xrunjdwp:transport=dt_socket,address=%JPDA_PORT%,server=y,suspend=n -Dplay.debug=yes -Dplay.id=%PLAY_ID% -Dapplication.path=&quot;${project_loc:%PROJECT_NAME%}&quot; -Djava.endorsed.dirs=&quot;%PLAY_BASE%/framework/endorsed&quot; -javaagent:&quot;%PLAY_BASE%/framework/play.jar&quot;"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xdebug -Xrunjdwp:transport=dt_socket,address=%JPDA_PORT%,server=y,suspend=n -Dplay.debug=yes -Dplay.id=%PLAY_ID% -Dapplication.path=&quot;${project_loc:%PROJECT_NAME%}&quot; -Djava.endorsed.dirs=&quot;%PLAY_BASE%/framework/endorsed&quot; -javaagent:&quot;%PLAY_BASE%/framework/play-%PLAY_VERSION%.jar&quot;"/>
</launchConfiguration>

2 changes: 1 addition & 1 deletion resources/eclipse/test.launch
Expand Up @@ -16,6 +16,6 @@
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="play.server.Server"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="%PROJECT_NAME%"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xdebug -Xrunjdwp:transport=dt_socket,address=%JPDA_PORT%,server=y,suspend=n -Dplay.debug=yes -Dplay.id=test -Dapplication.path=&quot;${project_loc:%PROJECT_NAME%}&quot; -Djava.endorsed.dirs=&quot;%PLAY_BASE%/framework/endorsed&quot; -javaagent:&quot;%PLAY_BASE%/framework/play.jar&quot;"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xdebug -Xrunjdwp:transport=dt_socket,address=%JPDA_PORT%,server=y,suspend=n -Dplay.debug=yes -Dplay.id=test -Dapplication.path=&quot;${project_loc:%PROJECT_NAME%}&quot; -Djava.endorsed.dirs=&quot;%PLAY_BASE%/framework/endorsed&quot; -javaagent:&quot;%PLAY_BASE%/framework/play-%PLAY_VERSION%.jar&quot;"/>
</launchConfiguration>

2 changes: 1 addition & 1 deletion resources/idea/imlTemplate.xml
Expand Up @@ -33,7 +33,7 @@
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://%PLAYHOME%/framework/play.jar!/" />
<root url="jar://%PLAYHOME%/framework/play-%PLAYVERSION%.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
Expand Down

0 comments on commit f72cf6a

Please sign in to comment.