Skip to content

Commit

Permalink
#504 generate the app/app.js while we're generating the index-dev.htm…
Browse files Browse the repository at this point in the history
…l and load source code first before the look at the target/hawtio-web/ directory - so we no longer have to keep messing around copying stuff about; disabled grunt
  • Loading branch information
jstrachan committed Nov 15, 2013
1 parent b0518e8 commit f9dc904
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 71 deletions.
138 changes: 80 additions & 58 deletions hawtio-web/pom.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>io.hawt</groupId>
<artifactId>project</artifactId>
Expand Down Expand Up @@ -251,7 +252,7 @@
<artifactId>activemq-jaas</artifactId>
<version>${activemq-version}</version>
<scope>test</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
Expand Down Expand Up @@ -370,26 +371,26 @@
*/debug/**
</packagingExcludes>
<failOnMissingWebXml>false</failOnMissingWebXml>
<!--
TODO disabled using archiveClasses for https://github.com/hawtio/hawtio/issues/403
until we can figure out how to get the war to work inside OSGi again
<!--
TODO disabled using archiveClasses for https://github.com/hawtio/hawtio/issues/403
until we can figure out how to get the war to work inside OSGi again
<archiveClasses>true</archiveClasses>
-->
<archiveClasses>true</archiveClasses>
-->
<archive>
<manifestFile>${basedir}/target/classes/META-INF/MANIFEST.MF</manifestFile>
</archive>
<!--
<webResources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</webResources>
-->
<!--
<webResources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</webResources>
-->
</configuration>
</plugin>

Expand Down Expand Up @@ -429,43 +430,6 @@
</dependencies>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin-version}</version>
<executions>
<execution>
<id>npm-install</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${npm-executable}</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>typescript-compile</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${grunt-executable}</executable>
<arguments>
<argument>--webapp_outdir</argument>
<argument>${webapp-outdir}</argument>
<argument>--webapp_port</argument>
<argument>${jettyPort}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>


<!--
<plugin>
Expand Down Expand Up @@ -501,12 +465,27 @@
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-version}</version>
<configuration>
<webAppSourceDirectory>${project.build.directory}/${project.name}-${project.version}</webAppSourceDirectory>
<webAppConfig>
<contextPath>${context}</contextPath>
    <baseResource implementation="org.eclipse.jetty.util.resource.ResourceCollection">
      <resourcesAsCSV>${basedir}/src/main/webapp,${project.build.directory}/${project.name}-${project.version}</resourcesAsCSV>
    </baseResource><!--
<resources>${basedir}/src/main/webapp,${project.build.directory}/${project.name}-${project.version}</resources>
-->
<!--
<baseResource implementation="org.eclipse.jetty.util.resource.ResourceCollection">
<resources>${basedir}/src/main/webapp,${project.build.directory}/${project.name}-${project.version}
</resources>
</baseResource>
-->
</webAppConfig>
<scanIntervalSeconds>0</scanIntervalSeconds>
<useTestScope>true</useTestScope>
<!--
<webAppConfig>
<contextPath>${context}</contextPath>
</webAppConfig>
-->
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>${jettyPort}</port>
Expand Down Expand Up @@ -741,8 +720,8 @@
<!-- copy the images from the eclipse plugin -->
<copy todir="${basedir}/src/main/webapp/img/camel" overwrite="true">
<fileset dir="${basedir}/../../../fuseide/plugins/org.fusesource.ide.camel.model/icons">
<include name="*24.png" />
<include name="*15.png" />
<include name="*24.png"/>
<include name="*15.png"/>
</fileset>
</copy>
</target>
Expand Down Expand Up @@ -867,6 +846,49 @@
<id>release</id>
</profile>

<profile>
<id>grunt</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin-version}</version>
<executions>
<execution>
<id>npm-install</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${npm-executable}</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>typescript-compile</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${grunt-executable}</executable>
<arguments>
<argument>--webapp_outdir</argument>
<argument>${webapp-outdir}</argument>
<argument>--webapp_port</argument>
<argument>${jettyPort}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>jasmine-test</id>
<activation>
Expand Down
88 changes: 75 additions & 13 deletions hawtio-web/src/test/java/io/hawt/web/tool/GenerateDevFiles.java
Expand Up @@ -21,6 +21,7 @@
import io.hawt.util.IOHelper;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
Expand All @@ -35,8 +36,10 @@ public class GenerateDevFiles {
private final String baseDir;
private final File sourceDir;
private final File outputDir;
private final File appSourceDir;
private Set<String> jsFiles = new TreeSet<String>();
private String devIndexHtml = "index-dev.html";
private String appJsFile = "app/app.js";
private List<String> jsFileList;

public static void main(String[] args) {
Expand All @@ -56,14 +59,40 @@ public GenerateDevFiles(String outputDir) {
this.outputDir = new File(outputDir);
this.baseDir = System.getProperty("basedir", ".");
sourceDir = new File(new File(baseDir), "src/main/webapp");
appSourceDir = new File(sourceDir, "app");
}

public String getDevIndexHtml() {
return devIndexHtml;
}

public void setDevIndexHtml(String devIndexHtml) {
this.devIndexHtml = devIndexHtml;
}

public String getAppJsFile() {
return appJsFile;
}

public void setAppJsFile(String appJsFile) {
this.appJsFile = appJsFile;
}

public File getOutputDir() {
return outputDir;
}

public File getSourceDir() {
return sourceDir;
}

/**
* Performs all the code generation
*/
public void run() throws IOException {
// lets iterate through finding a list of all the required JS pluginFolders
File appSourceDir = new File(sourceDir, "app");

assertDirectoryExists(appSourceDir, "source directory");
directoryExists(appSourceDir, "source directory");
File[] pluginFolders = appSourceDir.listFiles();
if (pluginFolders != null) {
for (File pluginFolder : pluginFolders) {
Expand All @@ -76,6 +105,7 @@ public void run() throws IOException {
}
reorderFiles();
generateDevIndexHtml();
generateAppJS();
}

protected void reorderFiles() {
Expand All @@ -98,23 +128,49 @@ protected void reorderFiles() {
jsFileList.addAll(jsFiles);
}

public static void assertDirectoryExists(File appSourceDir, String kind) {
if (!appSourceDir.exists()) {
throw new IllegalStateException("No " + kind + " at: " + appSourceDir.getAbsolutePath());
protected void generateAppJS() throws IOException {
File outputFile = createOutputFile(appJsFile);
outputFile.getParentFile().mkdirs();
FileWriter writer = new FileWriter(outputFile);
try {
for (String jsFileName : jsFileList) {
File jsFile = new File(sourceDir, jsFileName);
fileExists(jsFile);
String js = IOHelper.readFully(jsFile);
writer.write(js);
writer.write("\n");
}
} finally {
writer.close();
}
if (!appSourceDir.isDirectory()) {
throw new IllegalStateException(kind + " is not a directory! " + appSourceDir.getAbsolutePath());
}


/**
* Ensures the given directory exists or throws an exception
*/
public static void directoryExists(File dir, String kind) {
if (!dir.exists()) {
throw new IllegalStateException("No " + kind + " at: " + dir.getAbsolutePath());
}
if (!dir.isDirectory()) {
throw new IllegalStateException(kind + " is not a directory! " + dir.getAbsolutePath());
}
}

/**
* Asserts that a file exists and is a file
*/
public static void fileExists(File file) {
if (!file.exists() || !file.isFile()) {
throw new IllegalStateException("File does not exist " + file.getAbsolutePath());
}
}

protected void generateDevIndexHtml() throws IOException {
File indexHtml = new File(sourceDir, "index.html");
if (!indexHtml.exists() || !indexHtml.isFile()) {
throw new IllegalStateException("Source does not exist " + indexHtml.getAbsolutePath());
}
outputDir.mkdirs();
assertDirectoryExists(outputDir, "output directory");
File outputFile = new File(outputDir, devIndexHtml);
fileExists(indexHtml);
File outputFile = createOutputFile(devIndexHtml);

String html = IOHelper.readFully(indexHtml);
// TODO using a regex would be a little more resilient
Expand All @@ -132,6 +188,12 @@ protected void generateDevIndexHtml() throws IOException {
System.out.println("Generated developer file " + outputFile.getAbsolutePath());
}

protected File createOutputFile(String outputFileName) {
outputDir.mkdirs();
directoryExists(outputDir, "output directory");
return new File(outputDir, outputFileName);
}

protected void addScriptTags(StringBuilder buffer) {
for (String jsFile : jsFileList) {
buffer.append("<script type=\"text/javascript\" src=\"");
Expand Down

0 comments on commit f9dc904

Please sign in to comment.