Commits

Stephen McKamey  committed ae1e595

adding output of child links map

  • Participants
  • Parent commits 37df71a

Comments (0)

Files changed (5)

File merge-builder/src/main/java/org/duelengine/merge/BuildManager.java

 
 	private final Map<String, String> hashLookup = new LinkedHashMap<String, String>();
 	private final Map<String, List<String>> dependencyMap = new LinkedHashMap<String, List<String>>();
+	private final Map<String, List<String>> childLinkMap = new LinkedHashMap<String, List<String>>();
 	private final Map<String, Compactor> compactors;
 	private final Settings settings;
 	private final Stack<String> dependencyChain = new Stack<String>();
 		}
 
 		writeCompactionMap();
+		writeChildLinksMap();
 	}
 
 	private boolean isHashCalculated(String path) {
 		}
 	}
 
+	public void addChildLink(String path, String child) {
+		List<String> children = childLinkMap.get(path);
+		if (children == null) {
+			children = new ArrayList<String>();
+			childLinkMap.put(path, children);
+		}
+		children.add(child);
+	}
+
+	public List<String> getChildLinks(String path) {
+		List<String> children = childLinkMap.get(path);
+		if (children == null) {
+			children = Collections.emptyList();
+		}
+		return children;
+	}
+
 	public void addDependency(String path, String child) {
 		List<String> children = dependencyMap.get(path);
 		if (children == null) {
 			writer.close();
 		}
 	}
-	
+
 	private void writeCompactionMap(Appendable output)
 			throws IOException {
 
 		}
 	}
 
+	private void writeChildLinksMap()
+			throws IOException {
+
+		File cdnLinksFile = settings.getCDNLinksFile();
+
+		cdnLinksFile.getParentFile().mkdirs();
+
+		FileWriter writer = new FileWriter(cdnLinksFile, false);
+		try {
+			writeChildLinksMap(writer);
+
+		} finally {
+			writer.flush();
+			writer.close();
+		}
+	}
+
+	private void writeChildLinksMap(Appendable output)
+			throws IOException {
+
+		// generate output
+		for (String key : childLinkMap.keySet()) {
+			List<String> children = childLinkMap.get(key);
+
+			boolean needsDelim = false;
+			StringBuilder buffer = new StringBuilder();
+			for (String child : children) {
+				if (needsDelim) {
+					buffer.append(NEWLINE);
+				} else {
+					needsDelim = true;
+				}
+
+				buffer.append(child);
+			}
+
+			output
+				.append(key)
+				.append('=')
+				.append(escapePropertyValue(buffer.toString()))
+				.append(NEWLINE);
+		}
+	}
+
 	/**
 	 * http://download.oracle.com/javase/6/docs/api/java/util/Properties.html#load(java.io.Reader)
 	 * @param value

File merge-builder/src/main/java/org/duelengine/merge/CSSCompactor.java

 
 import java.io.File;
 import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
 
 import org.cssless.css.codegen.CodeGenSettings;
 import org.cssless.css.compiler.CssCompiler;
 			source,
 			target,
 			this.settings,
-			new LinkInterceptorCssFilter(manager, getContextPath(path)));
-	}
-
-	private URI getContextPath(String path) {
-		try {
-			return new URI(path);
-
-		} catch (URISyntaxException ex) {
-			return null;
-		}
+			new LinkInterceptorCssFilter(manager, path));
 	}
 }

File merge-builder/src/main/java/org/duelengine/merge/LinkInterceptorCssFilter.java

 
 import java.io.IOException;
 import java.net.URI;
+import java.net.URISyntaxException;
 
-import org.cssless.css.ast.*;
+import org.cssless.css.ast.ContainerNode;
+import org.cssless.css.ast.CssNode;
+import org.cssless.css.ast.CssNodeType;
+import org.cssless.css.ast.FunctionNode;
+import org.cssless.css.ast.StringNode;
+import org.cssless.css.ast.ValueNode;
 import org.cssless.css.codegen.CssFilter;
 import org.cssless.css.parsing.CssLexer;
 import org.slf4j.Logger;
 
 	private final Logger log = LoggerFactory.getLogger(LinkInterceptorCssFilter.class);
 	private final BuildManager manager;
-	private final URI context;
+	private final String path;
 
-	public LinkInterceptorCssFilter(BuildManager manager, URI context) {
+	public LinkInterceptorCssFilter(BuildManager manager, String path) {
 		this.manager = manager;
-		this.context = context;
+		this.path = path;
 	}
 	
 	@Override
 			children.getChildren().add(new ValueNode(value));
 		}
 
-		// zero or one child here
+		// zero or one child at this point
 		for (CssNode child : children.getChildren()) {
 			if (child instanceof ValueNode) {
 				ValueNode valNode = ((ValueNode)child);
 				}
 
 				String suffix = "";
-				if (val.charAt(0) != '/' && context != null) {
-					// resolve relative URLs and isolate the path part
-					URI uri = context.resolve(val);
-					if (uri.getHost() == null && uri.getScheme() == null) {
-						val = uri.getPath();
-						if (uri.getQuery() != null) {
-							suffix += '?'+uri.getQuery();
-						}
-						if (uri.getFragment() != null) {
-							suffix += '#'+uri.getFragment();
+				if (val.charAt(0) != '/') {
+					URI context = getContextPath(path);
+					if (context != null) {
+						// resolve relative URLs and isolate the path part
+						URI uri = context.resolve(val);
+						if (uri.getHost() == null && uri.getScheme() == null) {
+							val = uri.getPath();
+							if (uri.getQuery() != null) {
+								suffix += '?'+uri.getQuery();
+							}
+							if (uri.getFragment() != null) {
+								suffix += '#'+uri.getFragment();
+							}
 						}
 					}
 				}
 
+				manager.addChildLink(this.path, val);
+
 				manager.ensureProcessed(val);
 
 				String valHash = manager.getProcessedPath(val);
 		
 		return node;
 	}
+
+	private URI getContextPath(String path) {
+		try {
+			return new URI(path);
+
+		} catch (URISyntaxException ex) {
+			return null;
+		}
+	}
 }

File merge-builder/src/main/java/org/duelengine/merge/Settings.java

 	private static final String[] EMPTY = new String[0];
 	private static final String DEFAULT_CDN_ROOT = "/cdn/";
 	private static final String DEFAULT_MAP_FILE = "cdn.properties";
+	private static final String DEFAULT_LINKS_FILE = "cdnLinks.properties";
 
 	private File cdnMapFile;
+	private File cdnLinksFile;
 	private String cdnRoot = DEFAULT_CDN_ROOT;
 	private File targetDir;
 	private File sourceDir;
 		this.cdnMapFile = new File(value);
 	}
 
+	public File getCDNLinksFile() {
+		if (this.cdnLinksFile == null) {
+			return new File(this.getTargetDir(), DEFAULT_LINKS_FILE);
+		}
+
+		return this.cdnLinksFile;
+	}
+
+	public void setCDNLinksFile(String value) {
+		if (value == null || value.isEmpty()) {
+			this.cdnLinksFile = null;
+			return;
+		}
+
+		value = value.replace('\\', '/');
+		if (!value.startsWith("/")) {
+			value = '/'+value;
+		}
+		this.cdnLinksFile = new File(value);
+	}
+
 	public String getCDNRoot() {
 		return this.cdnRoot;
 	}

File merge-maven-plugin/src/main/java/org/duelengine/merge/maven/MergeMojo.java

 	/**
 	 * File name of the generated resource map.
 	 * 
-	 * @parameter default-value="cdn.properties"
+	 * @parameter default-value="/cdn.properties"
 	 */
 	private String cdnMapFile;
 
 	/**
+	 * File name of the generated resource map.
+	 * 
+	 * @parameter default-value="/cdnLinks.properties"
+	 */
+	private String cdnLinksFile;
+
+	/**
 	 * List of additional file extensions to hash and copy directly into CDN.
 	 * 
 	 * @parameter default-value=""
 	public void execute()
 		throws MojoExecutionException {
 
+		if (!this.cdnMapFile.startsWith("/")) {
+			this.cdnMapFile = '/'+this.cdnMapFile;
+		}
+
+		if (!this.cdnLinksFile.startsWith("/")) {
+			this.cdnLinksFile = '/'+this.cdnLinksFile;
+		}
+
 		Settings settings = new Settings();
 		settings.setSourceDir(this.webappDir);
 		settings.setTargetDir(this.outputDir);
 		settings.setCDNMapFile(this.resourcesDir+this.cdnMapFile);
+		settings.setCDNLinksFile(this.resourcesDir+this.cdnLinksFile);
 		settings.setCDNRoot(this.cdnRoot);
 		settings.setExtensionList(this.cdnFiles);
 
 		log.info("\tsourceDir="+settings.getSourceDir());
 		log.info("\ttargetDir="+settings.getTargetDir());
 		log.info("\tcdnMapFile="+settings.getCDNMapFile());
+		log.info("\tcdnLinksFile="+settings.getCDNLinksFile());
 		log.info("\tcdnRoot="+settings.getCDNRoot());
 		log.info("\tcdnFiles="+Arrays.toString(settings.getExtensions()));