Skip to content

Commit

Permalink
Merge pull request #1143 from codeborne/shorten-module-names
Browse files Browse the repository at this point in the history
#1142 add parameter `--shortModuleNames` to `play deps` command
  • Loading branch information
asolntsev authored May 22, 2017
2 parents 04115bd + 9ed6053 commit 0187399
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 8 deletions.
8 changes: 7 additions & 1 deletion documentation/commands/cmd-dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
~
~ Synopsis:
~ ~~~~~~~~~
~ play dependencies [app_path] [--verbose] [--debug] [--sync] [--nosync] [--%fwk_id] [--forProd] [--clearcache] [--jpda]
~ play dependencies [app_path] [--verbose] [--debug] [--sync] [--nosync] [--%fwk_id] [--forProd] [--clearcache] [--jpda] [--shortModuleNames]
~
~ Description:
~ ~~~~~~~~~~~~
Expand Down Expand Up @@ -63,3 +63,9 @@
~~ --clearcache:
~ Clear the ivy cache (equivalent to rm -r ~/.ivy2/cache)
~
~~ --shortModuleNames:
~ use short module name without version number.
~ For example, if project depends on module "play-pdf 1.2.3", then
~ * command `play deps` creates folder `modules/pdf-1.2.3`
~ * command `play deps --shortModuleNames` creates folder `modules/pdf`
~ The latter option is probably convenient for configuring IDE
8 changes: 7 additions & 1 deletion framework/pym/play/commands/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def execute(**kargs):

force = "false"
trim = "false"
shortModuleNames = "false"

if args.count('--forceCopy') == 1:
args.remove('--forceCopy')
force = "true"
Expand All @@ -29,11 +31,15 @@ def execute(**kargs):
force = "true"
trim = "true"

if args.count('--shortModuleNames') == 1:
args.remove('--shortModuleNames')
shortModuleNames = "true"

classpath = app.getClasspath()
args_memory = app.java_args_memory(args)
app.jpda_port = app.readConf('jpda.port')

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)]
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)]
if args.count('--verbose'):
args.remove('--verbose')
add_options.append('-Dverbose')
Expand Down
23 changes: 17 additions & 6 deletions framework/src/play/deps/DependenciesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,10 @@ public List<File> retrieve(ResolveReport report) throws Exception {
}

public File install(ArtifactDownloadReport artifact) throws Exception {
Boolean force = "true".equalsIgnoreCase(System.getProperty("play.forcedeps"));
Boolean trim = "true".equalsIgnoreCase(System.getProperty("play.trimdeps"));
boolean force = "true".equalsIgnoreCase(System.getProperty("play.forcedeps"));
boolean trim = "true".equalsIgnoreCase(System.getProperty("play.trimdeps"));
boolean shortModuleNames = "true".equalsIgnoreCase(System.getProperty("play.shortModuleNames"));

try {
File from = artifact.getLocalFile();

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

} else {
// A module
String mName = from.getName();
if (mName.endsWith(".jar") || mName.endsWith(".zip")) {
mName = mName.substring(0, mName.length() - 4);
}
String mName = moduleName(artifact, shortModuleNames);
File to = new File(application, "modules" + File.separator + mName).getCanonicalFile();
new File(application, "modules").mkdir();
Files.delete(to);
Expand Down Expand Up @@ -331,6 +330,18 @@ public File install(ArtifactDownloadReport artifact) throws Exception {
}
}

String moduleName(ArtifactDownloadReport artifact, boolean shortModuleNames) {
if (shortModuleNames) {
return artifact.getName();
}

String mName = artifact.getLocalFile().getName();
if (mName.endsWith(".jar") || mName.endsWith(".zip")) {
mName = mName.substring(0, mName.length() - 4);
}
return mName;
}

private boolean isFrameworkLocal(ArtifactDownloadReport artifact) throws Exception {
String artifactFileName = artifact.getLocalFile().getName();
return new File(framework, "framework/lib/" + artifactFileName).exists()
Expand Down
40 changes: 40 additions & 0 deletions framework/test-src/play/deps/DependenciesManagerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package play.deps;

import org.apache.ivy.core.report.ArtifactDownloadReport;
import org.junit.Test;

import java.io.File;

import static org.junit.Assert.*;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class DependenciesManagerTest {
private DependenciesManager manager = new DependenciesManager(new File("."), new File("."), new File("."));

@Test
public void usesDownloadedZipFileNameWithoutExtensions() {
ArtifactDownloadReport artifact = artifact("pdf", "pdf-1.2.3.zip");
assertEquals("pdf-1.2.3", manager.moduleName(artifact, false));
}

@Test
public void usesDownloadedJarFileNameWithoutExtensions() {
ArtifactDownloadReport artifact = artifact("pdf", "pdf-1.2.3.jar");
assertEquals("pdf-1.2.3", manager.moduleName(artifact, false));
}

@Test
public void shortModuleNames() {
ArtifactDownloadReport artifact = artifact("pdf", "pdf-1.2.3.zip");
assertEquals("pdf", manager.moduleName(artifact, true));
}

private ArtifactDownloadReport artifact(String name, String downloadedFileName) {
ArtifactDownloadReport artifact = mock(ArtifactDownloadReport.class, RETURNS_DEEP_STUBS);
when(artifact.getName()).thenReturn(name);
when(artifact.getLocalFile().getName()).thenReturn(downloadedFileName);
return artifact;
}
}

0 comments on commit 0187399

Please sign in to comment.