Commits

Stephen McKamey committed dc5cde4

minor cleanup; moving back to package stage to pickup static files

Comments (0)

Files changed (7)

duel-staticapps-maven-plugin/pom.xml

 
 	<groupId>org.duelengine</groupId>
 	<artifactId>duel-staticapps-maven-plugin</artifactId>
-	<version>0.8.2</version>
+	<version>0.8.3</version>
 	<packaging>maven-plugin</packaging>
 
 	<name>DUEL Static Apps Maven Plugin</name>

duel-staticapps-maven-plugin/src/main/java/org/duelengine/duel/staticapps/maven/SiteGeneratorMojo.java

 import org.codehaus.plexus.classworlds.realm.ClassRealm;
 import org.duelengine.duel.staticapps.SiteBuilder;
 import org.duelengine.duel.staticapps.SiteConfig;
+import org.duelengine.duel.utils.FileUtil;
 
 /**
  * Generates static app from DUEL-based WAR
  *
  * @goal generate
- * @phase process-classes
+ * @phase package
  */
 public class SiteGeneratorMojo extends AbstractMojo {
 
 			List<URL> runtimeUrls = new ArrayList<URL>(runtimeClasspathElements.size());
 			for (String element : runtimeClasspathElements) {
 				try {
-					URL elementURL = new File(element).toURI().toURL();
+					URL elementURL = FileUtil.getCanonicalFile(element).toURI().toURL();
 					runtimeUrls.add(elementURL);
 					if (realm != null) {
 						realm.addURL(elementURL);

duel-staticapps/example-config.json

 {
-	"targetDir": "target/",
-	"sourceDir": "foo-web/target/foo-web/",
+	"targetDir": "target/www/",
+	"sourceDir": "target/foo-web/",
 	"serverPrefix": "com.example.web.views",
 	"cdnMap": "cdn",
 	"cdnLinksMap": "cdnLinks",
-	"cdnHost": null,
+	"cdnHost": ".",
 	"isDevMode": false,
 	"views": {
 		"index.html":

duel-staticapps/pom.xml

 
 	<groupId>org.duelengine</groupId>
 	<artifactId>duel-staticapps</artifactId>
-	<version>0.8.2</version>
+	<version>0.8.3</version>
 	<packaging>jar</packaging>
 
 	<name>DUEL Static Apps</name>
 	<properties>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 
+		<duel.version>0.8.2</duel.version>
 		<jackson.version>1.9.4</jackson.version>
 		<codec.version>1.6</codec.version>
 		<slf4j.version>1.6.4</slf4j.version>
 		<dependency>
 			<groupId>org.duelengine</groupId>
 			<artifactId>duel-runtime</artifactId>
-			<version>${project.version}</version>
+			<version>${duel.version}</version>
 		</dependency>
 
 		<!-- Jackson JSON runtime -->

duel-staticapps/src/main/java/org/duelengine/duel/staticapps/SiteBuilder.java

 		Map<String, SiteViewPage> views = config.views();
 		if (views != null) {
 			for (String targetPage : views.keySet()) {
-				SiteViewPage view = views.get(targetPage);
-				log.info("source view: "+view.view());
-				log.info("target page: "+targetPage);
+				SiteViewPage sitePage = views.get(targetPage);
+				log.info("Generating: "+sitePage.view()+" => "+targetPage);
 
 				FileWriter writer = null;
 				try {
-				File indexFile = new File(targetDir, targetPage);
-				FileUtil.prepSavePath(indexFile);
+					File targetFile = new File(targetDir, targetPage);
+					FileUtil.prepSavePath(targetFile);
 
-				writer = new FileWriter(indexFile);
+					writer = new FileWriter(targetFile);
 
-				DuelContext context = new DuelContext()
-					.setFormat(formatPrefs)
-					.setLinkInterceptor(linkInterceptor)
-					.setData(view.data())
-					.setOutput(writer);
+					DuelContext context = new DuelContext()
+						.setFormat(formatPrefs)
+						.setLinkInterceptor(linkInterceptor)
+						.setData(sitePage.data())
+						.setOutput(writer);
 
-				Map<String, Object> extras = view.extras();
-				if (extras != null && !extras.isEmpty()) {
-					// ambient client-side data
-					context.putExtras(extras);
-				}
+					Map<String, Object> extras = sitePage.extras();
+					if (extras != null) {
+						// ambient client-side data
+						context.putExtras(extras);
+					}
 
-				log.trace("Generating: "+targetPage);
-				viewClass(config.serverPrefix(), view.view()).newInstance().render(context);
+					viewClass(config.serverPrefix(), sitePage.view()).newInstance().render(context);
 
 				} catch (Exception ex) {
 					log.error(ex.getMessage(), ex);
 			for (String staticFile : staticFiles) {
 				try {
 					copyResource(sourceDir, targetDir, staticFile, staticFile);
+
 				} catch (IOException ex) {
 					log.error(ex.getMessage(), ex);
 				}
 		for (String key : linkCache.keySet()) {
 			try {
 				copyResource(sourceDir, targetDir, key, linkCache.get(key));
+
 			} catch (IOException ex) {
 				log.error(ex.getMessage(), ex);
 			}
 			cdnPath = cdnPath.substring(0, cdnPath.indexOf('#'));
 		}
 
-		File resource = new File(sourceDir, cdnPath);
+		File source = new File(sourceDir, cdnPath);
 		File target = new File(targetDir, cdnPath);
-		if (!resource.exists()) {
+		if (!source.exists()) {
 			// report but still copy the rest
-			log.warn("Resource not found: "+resource.getAbsolutePath());
+			log.warn("Resource not found: "+source.getAbsolutePath());
 			try {
 				if (target.isFile() && target.exists() && target.delete()) {
 					log.info("Deleted existing: "+target.getAbsolutePath());
 			}
 			return;
 		}
-		if (!resource.isFile()) {
+		if (!source.isFile()) {
 			// report but still copy the rest
-			log.warn("Resource not a file: "+resource.getPath());
+			log.warn("Resource not a file: "+source.getPath());
 			try {
 				if (target.isFile() && target.exists() && target.delete()) {
 					log.info("Deleted existing: "+target.getAbsolutePath());
 		}
 
 		log.info("Copying "+path+" as "+cdnPath);
-		FileUtil.copy(resource, target, true, buffer);
+		FileUtil.copy(source, target, true, buffer);
 	}
 
 	/**

duel-staticapps/src/main/java/org/duelengine/duel/staticapps/SiteConfig.java

 
 import org.codehaus.jackson.annotate.JsonIgnoreProperties;
 import org.codehaus.jackson.annotate.JsonProperty;
+import org.duelengine.duel.utils.FileUtil;
 
 @JsonIgnoreProperties(ignoreUnknown=true)
 public class SiteConfig {
 			targetDirFile = null;
 
 		} else {
-			targetDirFile = new File(targetDir);
+			targetDirFile = FileUtil.getCanonicalFile(targetDir);
 		}
 		return this;
 	}
 			sourceDirFile = null;
 
 		} else {
-			sourceDirFile = new File(sourceDir);
+			sourceDirFile = FileUtil.getCanonicalFile(sourceDir);
 		}
 		return this;
 	}

duel-staticapps/src/main/java/org/duelengine/duel/utils/FileUtil.java

 	public static final String SHA1 = "SHA-1";
 	public static final String MD5 = "MD5";
 
+	public static File getCanonicalFile(String path) {
+		if (path == null) {
+			throw new NullPointerException("path");
+		}
+
+		return getCanonicalFile(new File(path));
+	}
+
+	public static File getCanonicalFile(File file) {
+		if (file == null) {
+			throw new NullPointerException("file");
+		}
+
+		try {
+			return file.getCanonicalFile();
+
+		} catch (IOException e) {
+			return file.getAbsoluteFile();
+		}
+	}
+
 	public static void prepSavePath(File file) {
 		if (file == null) {
 			throw new NullPointerException("file");
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.