Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Map Configuration Support

  • Loading branch information...
commit aeb5fe2d282075e05110a6eb1dba0a85b92dc5cb 1 parent 692d6bb
@rbackhouse rbackhouse authored
View
2  org.dojotoolkit.optimizer.amd.rhinoast/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Rhinoast
Bundle-SymbolicName: org.dojotoolkit.optimizer.amd.rhinoast
-Bundle-Version: 0.3.6
+Bundle-Version: 0.4.3
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.dojotoolkit.optimizer
Import-Package: org.dojotoolkit.json,
View
BIN  ...mizer.amd.rhinoast/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizer$AstVisitor.class
Binary file not shown
View
BIN  ...optimizer.amd.rhinoast/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizer$Module.class
Binary file not shown
View
BIN  ...oolkit.optimizer.amd.rhinoast/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizer.class
Binary file not shown
View
50 ...kit.optimizer.amd.rhinoast/src/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizer.java
@@ -79,6 +79,7 @@ protected JSAnalysisDataImpl _getAnalysisData(String[] modules, JSAnalysisData[]
Map<String, Object> pkgs = new HashMap<String, Object>();
cfg.put("pkgs", pkgs);
cfg.put("paths", new HashMap<String, Object>());
+ cfg.put("map", new HashMap<String, Object>());
cfg.put("baseUrl", "");
for (String key : fullConfig.keySet()) {
if (key.equals("packages")) {
@@ -155,6 +156,7 @@ protected JSAnalysisDataImpl _getAnalysisData(String[] modules, JSAnalysisData[]
if (moduleId.indexOf('!') != -1) {
moduleId = moduleId.substring(0, moduleId.indexOf('!'));
}
+ moduleId = expand(moduleId, new Stack<String>(), cfg);
Module m = moduleMap.get(moduleId);
buildDependencyList(m, moduleMap, dependencies, seen);
scanForCircularDependencies(m, new Stack<String>(), moduleMap);
@@ -177,7 +179,7 @@ private static String join(List<String> l, char separator) {
private static void splice(List<String> l, int index, int howMany, String toInsert) {
for (int i = index; i < howMany; i++) {
- l.remove(i);
+ l.remove(index);
}
l.add(index, toInsert);
}
@@ -195,7 +197,42 @@ private static String normalize(String path) {
return null;
}
}
-
+
+ private static int countSegments(String path) {
+ int count = 0;
+ for (int i = 0; i < path.length(); i++) {
+ if (path.charAt(i) == '/') {
+ count++;
+ }
+ }
+ return count;
+ }
+
+ private static String findMapping(String path, String depId, Map<String, Object> config) {
+ Map<String, Object> map = (Map<String, Object>)config.get("map");
+ String mapping = null;
+ int segmentCount = -1;
+ for (String key : map.keySet()) {
+ if (depId.startsWith(key)) {
+ int foundSegmentCount = countSegments(key);
+ if (foundSegmentCount > segmentCount) {
+ Map<String, Object> mapEntry = (Map<String, Object>)map.get(key);
+ if (mapEntry != null && mapEntry.containsKey(path)) {
+ mapping = (String)mapEntry.get(path);
+ segmentCount = foundSegmentCount;
+ }
+ }
+ }
+ }
+ if (mapping == null) {
+ Map<String, Object> mapEntry = (Map<String, Object>)map.get("*");
+ if (mapEntry != null && mapEntry.containsKey(path)) {
+ mapping = (String)mapEntry.get(path);
+ }
+ }
+ return mapping;
+ }
+
private static String idToUrl(String path, Map<String, Object> config) {
List<String> segments = new ArrayList<String>(Arrays.asList(path.split("/")));
Map<String, Object> paths = (Map<String, Object>)config.get("paths");
@@ -246,6 +283,15 @@ private static String expand(String path, List<String> pathStack, Map<String, Ob
return (String)((Map<String, Object>)packages.get(pkgName)).get("name") + '/' + (String)((Map<String, Object>)packages.get(pkgName)).get("main");
}
}
+ List<String> segments = new ArrayList<String>(Arrays.asList(path.split("/")));
+ for (int i = segments.size(); i >= 0; i--) {
+ String parent = join(segments.subList(0, i), '/');
+ String mapping = findMapping(parent, getParentId(pathStack), config);
+ if (mapping != null) {
+ splice(segments, 0, i, mapping);
+ return join(segments, '/');
+ }
+ }
return path;
}
View
2  org.dojotoolkit.optimizer.amd/META-INF/MANIFEST.MF
@@ -2,4 +2,4 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: AMD Optimizer
Bundle-SymbolicName: org.dojotoolkit.optimizer.amd;singleton:=true
-Bundle-Version: 0.4.0
+Bundle-Version: 0.4.3
View
43 org.dojotoolkit.optimizer.amd/loader/amd/zazl.js
@@ -88,9 +88,51 @@ var define;
return pkgs[pkgName].name + '/' + pkgs[pkgName].main;
}
}
+
+ var segments = path.split("/");
+ for (var i = segments.length; i >= 0; i--) {
+ var parent = segments.slice(0, i).join("/");
+ var mapping = findMapping(parent, _getCurrentId());
+ if (mapping) {
+ segments.splice(0, i, mapping);
+ return segments.join("/");
+ }
+ }
+
return path;
};
+ function countSegments(path) {
+ var count = 0;
+ for (var i = 0; i < path.length; i++) {
+ if (path.charAt(i) === '/') {
+ count++;
+ }
+ }
+ return count;
+ };
+
+ function findMapping(path, depId) {
+ var mapping;
+ var segmentCount = -1;
+ for (var id in cfg.map) {
+ if (depId.indexOf(id) === 0) {
+ var foundSegmentCount = countSegments(id);
+ if (foundSegmentCount > segmentCount) {
+ var mapEntry = cfg.map[id];
+ if (mapEntry[path] !== undefined) {
+ mapping = mapEntry[path];
+ segmentCount = foundSegmentCount;
+ }
+ }
+ }
+ }
+ if (mapping === undefined && cfg.map["*"] !== undefined && cfg.map["*"][path] !== undefined) {
+ mapping = cfg.map["*"][path];
+ }
+ return mapping;
+ };
+
function _idToUrl(path) {
var segments = path.split("/");
for (var i = segments.length; i >= 0; i--) {
@@ -510,6 +552,7 @@ var define;
cfg.scanCJSRequires = cfg.scanCJSRequires || false;
cfg.debug = cfg.debug || false;
cfg.config = cfg.config || {};
+ cfg.map = cfg.map || {};
}
};
View
1  org.dojotoolkit.optimizer.amd/optimizer/amd/AMDAnalyzer.js
@@ -109,6 +109,7 @@ AMDAnalyzer.prototype = {
if (m.match(".+!")) {
m = m.substring(0, m.indexOf('!'));
}
+ m = astwalker.expand(m, [], this.config);
var module = this.moduleMap.get(m);
this._buildDependencyList(module, dependencyList, seen);
this._scanForCircularDependencies(module, []);
View
42 org.dojotoolkit.optimizer.amd/optimizer/amd/astwalker.js
@@ -14,6 +14,37 @@ function getParentId(pathStack) {
return pathStack.length > 0 ? pathStack[pathStack.length-1] : "";
};
+function countSegments(path) {
+ var count = 0;
+ for (var i = 0; i < path.length; i++) {
+ if (path.charAt(i) === '/') {
+ count++;
+ }
+ }
+ return count;
+};
+
+function findMapping(path, depId, cfg) {
+ var mapping;
+ var segmentCount = -1;
+ for (var id in cfg.map) {
+ if (depId.indexOf(id) === 0) {
+ var foundSegmentCount = countSegments(id);
+ if (foundSegmentCount > segmentCount) {
+ var mapEntry = cfg.map[id];
+ if (mapEntry[path] !== undefined) {
+ mapping = mapEntry[path];
+ segmentCount = foundSegmentCount;
+ }
+ }
+ }
+ }
+ if (mapping === undefined && cfg.map["*"] !== undefined && cfg.map["*"][path] !== undefined) {
+ mapping = cfg.map["*"][path];
+ }
+ return mapping;
+};
+
function idToUrl(path, config) {
var segments = path.split("/");
for (var i = segments.length; i >= 0; i--) {
@@ -76,6 +107,17 @@ function expand(path, pathStack, config) {
return config.pkgs[pkgName].name + '/' + config.pkgs[pkgName].main;
}
}
+
+ var segments = path.split("/");
+ for (var i = segments.length; i >= 0; i--) {
+ var parent = segments.slice(0, i).join("/");
+ var mapping = findMapping(parent, getParentId(pathStack), config);
+ if (mapping) {
+ segments.splice(0, i, mapping);
+ return segments.join("/");
+ }
+ }
+
return path;
};
Please sign in to comment.
Something went wrong with that request. Please try again.