Skip to content

Commit

Permalink
[playframework#1007] Introduce the "forceCopy" flag for the dependenc…
Browse files Browse the repository at this point in the history
…ies manager
  • Loading branch information
erwan committed Aug 4, 2011
1 parent 05ed5fc commit 30ec20e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
14 changes: 9 additions & 5 deletions documentation/commands/cmd-dependencies.txt
Expand Up @@ -12,12 +12,12 @@
~
~ Description:
~ ~~~~~~~~~~~~
~ Compute resolve and retrieve project dependencies and install them either
~ in lib/ directory for jar artifacts or in modules/ for Play modules artifacts.
~ Compute resolve and retrieve project dependencies and install them either in
~ lib/ directory for jar artifacts or in modules/ for Play modules artifacts.
~
~ By default the command will not delete unrecognized artifacts. Use the --sync option
~ to keep both lib/ and modules/ directory synchronized with the dependencies management
~ system.
~ By default the command will not delete unrecognized artifacts.
~ Use the --sync option to keep both lib/ and modules/ directory synchronized
~ with the dependencies management system.
~
~ Options:
~ ~~~~~~~~
Expand All @@ -35,6 +35,10 @@
~ Keep lib/ and modules/ directory synced.
~ Delete unknow dependencies.
~
~ --forceCopy:
~ Never create files pointing to the original folder, always copy the folder
~ instead.
~
~ --%fwk_id:
~ Use this ID to run the application (override the default framework ID)
~
7 changes: 6 additions & 1 deletion framework/pym/play/commands/deps.py
Expand Up @@ -21,9 +21,14 @@ def execute(**kargs):
args = kargs.get("args")
play_env = kargs.get("env")

force = "false"
if args.count('--forceCopy') == 1:
args.remove('--forceCopy')
force = "true"

classpath = app.getClasspath()

add_options = ['-Dapplication.path=%s' % (app.path), '-Dframework.path=%s' % (play_env['basedir']), '-Dplay.id=%s' % play_env['id'], '-Dplay.version=%s' % play_env['version']]
add_options = ['-Dapplication.path=%s' % (app.path), '-Dframework.path=%s' % (play_env['basedir']), '-Dplay.id=%s' % play_env['id'], '-Dplay.version=%s' % play_env['version'], '-Dplay.forcedeps=%s' % (force)]
if args.count('--verbose'):
add_options.append('-Dverbose')
if args.count('--sync'):
Expand Down
7 changes: 6 additions & 1 deletion framework/src/play/deps/DependenciesManager.java
Expand Up @@ -191,6 +191,7 @@ public List<File> retrieve(ResolveReport report) throws Exception {
}

public File install(ArtifactDownloadReport artifact) throws Exception {
Boolean force = System.getProperty("play.forcedeps").equals("true");
try {
File from = artifact.getLocalFile();
if (!isPlayModule(artifact)) {
Expand All @@ -208,7 +209,11 @@ public File install(ArtifactDownloadReport artifact) throws Exception {
new File(application, "modules").mkdir();
Files.delete(to);
if (from.isDirectory()) {
IO.writeContent(from.getAbsolutePath(), to);
if (force) {
IO.copyDirectory(from, to);
} else {
IO.writeContent(from.getAbsolutePath(), to);
}
System.out.println("~ \tmodules/" + to.getName() + " -> " + from.getAbsolutePath());
} else {
Files.unzip(from, to);
Expand Down
19 changes: 19 additions & 0 deletions framework/src/play/libs/IO.java
Expand Up @@ -346,4 +346,23 @@ public static void write(InputStream is, File f) {
}
}
}

// If targetLocation does not exist, it will be created.
public static void copyDirectory(File source, File target) {
if (source.isDirectory()) {
if (!target.exists()) {
target.mkdir();
}
for (String child: source.list()) {
copyDirectory(new File(source, child), new File(target, child));
}
} else {
try {
write(new FileInputStream(source), new FileOutputStream(target));
} catch (IOException e) {
throw new UnexpectedException(e);
}
}
}

}

0 comments on commit 30ec20e

Please sign in to comment.