Skip to content

Commit 0187399

Browse files
authored
Merge pull request #1143 from codeborne/shorten-module-names
#1142 add parameter `--shortModuleNames` to `play deps` command
2 parents 04115bd + 9ed6053 commit 0187399

File tree

4 files changed

+71
-8
lines changed

4 files changed

+71
-8
lines changed

documentation/commands/cmd-dependencies.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
~
99
~ Synopsis:
1010
~ ~~~~~~~~~
11-
~ play dependencies [app_path] [--verbose] [--debug] [--sync] [--nosync] [--%fwk_id] [--forProd] [--clearcache] [--jpda]
11+
~ play dependencies [app_path] [--verbose] [--debug] [--sync] [--nosync] [--%fwk_id] [--forProd] [--clearcache] [--jpda] [--shortModuleNames]
1212
~
1313
~ Description:
1414
~ ~~~~~~~~~~~~
@@ -63,3 +63,9 @@
6363
~~ --clearcache:
6464
~ Clear the ivy cache (equivalent to rm -r ~/.ivy2/cache)
6565
~
66+
~~ --shortModuleNames:
67+
~ use short module name without version number.
68+
~ For example, if project depends on module "play-pdf 1.2.3", then
69+
~ * command `play deps` creates folder `modules/pdf-1.2.3`
70+
~ * command `play deps --shortModuleNames` creates folder `modules/pdf`
71+
~ The latter option is probably convenient for configuring IDE

framework/pym/play/commands/deps.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def execute(**kargs):
2020

2121
force = "false"
2222
trim = "false"
23+
shortModuleNames = "false"
24+
2325
if args.count('--forceCopy') == 1:
2426
args.remove('--forceCopy')
2527
force = "true"
@@ -29,11 +31,15 @@ def execute(**kargs):
2931
force = "true"
3032
trim = "true"
3133

34+
if args.count('--shortModuleNames') == 1:
35+
args.remove('--shortModuleNames')
36+
shortModuleNames = "true"
37+
3238
classpath = app.getClasspath()
3339
args_memory = app.java_args_memory(args)
3440
app.jpda_port = app.readConf('jpda.port')
3541

36-
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), '-Dplay.trimdeps=%s' % (trim)]
42+
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), '-Dplay.trimdeps=%s' % (trim), '-Dplay.shortModuleNames=%s' % (shortModuleNames)]
3743
if args.count('--verbose'):
3844
args.remove('--verbose')
3945
add_options.append('-Dverbose')

framework/src/play/deps/DependenciesManager.java

+17-6
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,10 @@ public List<File> retrieve(ResolveReport report) throws Exception {
273273
}
274274

275275
public File install(ArtifactDownloadReport artifact) throws Exception {
276-
Boolean force = "true".equalsIgnoreCase(System.getProperty("play.forcedeps"));
277-
Boolean trim = "true".equalsIgnoreCase(System.getProperty("play.trimdeps"));
276+
boolean force = "true".equalsIgnoreCase(System.getProperty("play.forcedeps"));
277+
boolean trim = "true".equalsIgnoreCase(System.getProperty("play.trimdeps"));
278+
boolean shortModuleNames = "true".equalsIgnoreCase(System.getProperty("play.shortModuleNames"));
279+
278280
try {
279281
File from = artifact.getLocalFile();
280282

@@ -298,10 +300,7 @@ public File install(ArtifactDownloadReport artifact) throws Exception {
298300

299301
} else {
300302
// A module
301-
String mName = from.getName();
302-
if (mName.endsWith(".jar") || mName.endsWith(".zip")) {
303-
mName = mName.substring(0, mName.length() - 4);
304-
}
303+
String mName = moduleName(artifact, shortModuleNames);
305304
File to = new File(application, "modules" + File.separator + mName).getCanonicalFile();
306305
new File(application, "modules").mkdir();
307306
Files.delete(to);
@@ -331,6 +330,18 @@ public File install(ArtifactDownloadReport artifact) throws Exception {
331330
}
332331
}
333332

333+
String moduleName(ArtifactDownloadReport artifact, boolean shortModuleNames) {
334+
if (shortModuleNames) {
335+
return artifact.getName();
336+
}
337+
338+
String mName = artifact.getLocalFile().getName();
339+
if (mName.endsWith(".jar") || mName.endsWith(".zip")) {
340+
mName = mName.substring(0, mName.length() - 4);
341+
}
342+
return mName;
343+
}
344+
334345
private boolean isFrameworkLocal(ArtifactDownloadReport artifact) throws Exception {
335346
String artifactFileName = artifact.getLocalFile().getName();
336347
return new File(framework, "framework/lib/" + artifactFileName).exists()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package play.deps;
2+
3+
import org.apache.ivy.core.report.ArtifactDownloadReport;
4+
import org.junit.Test;
5+
6+
import java.io.File;
7+
8+
import static org.junit.Assert.*;
9+
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
10+
import static org.mockito.Mockito.mock;
11+
import static org.mockito.Mockito.when;
12+
13+
public class DependenciesManagerTest {
14+
private DependenciesManager manager = new DependenciesManager(new File("."), new File("."), new File("."));
15+
16+
@Test
17+
public void usesDownloadedZipFileNameWithoutExtensions() {
18+
ArtifactDownloadReport artifact = artifact("pdf", "pdf-1.2.3.zip");
19+
assertEquals("pdf-1.2.3", manager.moduleName(artifact, false));
20+
}
21+
22+
@Test
23+
public void usesDownloadedJarFileNameWithoutExtensions() {
24+
ArtifactDownloadReport artifact = artifact("pdf", "pdf-1.2.3.jar");
25+
assertEquals("pdf-1.2.3", manager.moduleName(artifact, false));
26+
}
27+
28+
@Test
29+
public void shortModuleNames() {
30+
ArtifactDownloadReport artifact = artifact("pdf", "pdf-1.2.3.zip");
31+
assertEquals("pdf", manager.moduleName(artifact, true));
32+
}
33+
34+
private ArtifactDownloadReport artifact(String name, String downloadedFileName) {
35+
ArtifactDownloadReport artifact = mock(ArtifactDownloadReport.class, RETURNS_DEEP_STUBS);
36+
when(artifact.getName()).thenReturn(name);
37+
when(artifact.getLocalFile().getName()).thenReturn(downloadedFileName);
38+
return artifact;
39+
}
40+
}

0 commit comments

Comments
 (0)