Skip to content

Commit

Permalink
[playframework#781] simplify loading module, got rid of the moduleOrd…
Browse files Browse the repository at this point in the history
…er.conf which is useless and instead use the depencies.yml which already define the right order
  • Loading branch information
pepite authored and xael-fry committed Mar 12, 2014
1 parent 412ea99 commit c7fc5e9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 40 deletions.
2 changes: 1 addition & 1 deletion framework/src/play/Play.java
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ public static void loadModules() {
try {
modules = dm.retrieveModules();
} catch (Exception e) {
Logger.error("There was a problem parsing "+ DependenciesManager.MODULE_ORDER_CONF +" (module will not be loaded in order of the dependencies.yml)", e);
Logger.error("There was a problem parsing depencies.yml (module will not be loaded in order of the dependencies.yml)", e);
// Load module without considering the dependencies.yml order
modules = Arrays.asList(localModules.list());
}
Expand Down
44 changes: 10 additions & 34 deletions framework/src/play/deps/DependenciesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import play.libs.IO;

public class DependenciesManager {
public static final String MODULE_ORDER_CONF = "modulesOrder.conf";


public static void main(String[] args) throws Exception {

// Paths
Expand Down Expand Up @@ -160,30 +159,17 @@ public boolean problems() {
return false;
}

public List<String> retrieveModules()
throws Exception {
List<String> modules = new ArrayList<String>();

File file = new File(application + "/conf", MODULE_ORDER_CONF);
FileInputStream in = new FileInputStream(file);
Properties modulesOrderConfiguration = new Properties();
modulesOrderConfiguration.load(in);

String value = null;
Long key = 1L;

while ((value = modulesOrderConfiguration.getProperty(key.toString())) != null) {
modules.add(value);
key++;
}

in.close();
return modules;
// Retrieve the list of modules in the order they were defined in the dependencies.yml.
public List<String> retrieveModules() throws Exception {
File ivyModule = new File(application, "conf/dependencies.yml");
if(!ivyModule.exists()) {
return new ArrayList<String>();
}
return YamlParser.getOrderedModuleList(ivyModule);
}

public List<File> retrieve(ResolveReport report) throws Exception {
Properties modulesOrderConfiguration = new Properties();


// Track missing artifacts
List<ArtifactDownloadReport> missing = new ArrayList<ArtifactDownloadReport>();

Expand All @@ -205,30 +191,20 @@ public List<File> retrieve(ResolveReport report) throws Exception {
if (mName.endsWith(".jar") || mName.endsWith(".zip")) {
mName = mName.substring(0, mName.length() - 4);
}
modulesOrderConfiguration.setProperty(String.valueOf(modulesOrderConfiguration.size() + 1), mName);
}
}
}
}
}
}

// 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
// Save order in file to be able to retrieve it

// Create directory if not exist
File modulesDir = new File(application, "modules");
if(!modulesDir.exists()){
modulesDir.mkdir();
}

File file = new File(application + "/conf", MODULE_ORDER_CONF);
FileOutputStream fOut = new FileOutputStream(file);
modulesOrderConfiguration.store(fOut, "Modules orders : this file is automatically generated by Play dependencies. Do not directly modify it");
fOut.close();


if (!missing.isEmpty()) {
System.out.println("~");
System.out.println("~ WARNING: Some dependencies could not be downloaded (use --verbose for details),");
Expand Down
46 changes: 41 additions & 5 deletions framework/src/play/deps/YamlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.FileInputStream;
import java.net.URL;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -134,11 +136,11 @@ public ModuleDescriptorParser getParser() {
}
}
HashMap extraAttributesMap = null;
if(m.groupCount() == 4 && m.group(4) != null && !m.group(4).trim().isEmpty()){
// dependency has a classifier
extraAttributesMap = new HashMap();
extraAttributesMap.put("classifier", m.group(4).trim());
}
if(m.groupCount() == 4 && m.group(4) != null && !m.group(4).trim().isEmpty()){
// dependency has a classifier
extraAttributesMap = new HashMap();
extraAttributesMap.put("classifier", m.group(4).trim());
}

ModuleRevisionId depId = ModuleRevisionId.newInstance(m.group(1), m.group(2), m.group(3), extraAttributesMap);

Expand Down Expand Up @@ -237,4 +239,38 @@ <T> T get(Map data, String key, Class<T> type, T defaultValue) {
}
return o;
}

public static List<String> getOrderedModuleList(File file) throws Oops {
Yaml yaml = new Yaml();
Object o = null;

// Try to parse the yaml
try {
o = yaml.load(new FileInputStream(file));
} catch (Exception e) {
throw new Oops(e.toString().replace("\n", "\n~ \t"));
}

// We expect a Map here
if (!(o instanceof Map)) {
throw new Oops("Unexpected format -> " + o);
}

Map data = (Map) o;
ModuleRevisionId id = null;



if (data.containsKey("require")) {
if (data.get("require") instanceof List) {

List dependencies = (List) data.get("require");
// filter out play
dependencies.remove("play");
System.out.println("loading modules " + dependencies);
return dependencies;
}
}
return new ArrayList<String>();
}
}

0 comments on commit c7fc5e9

Please sign in to comment.