Skip to content

Commit

Permalink
round 1 of parser update. Not quite done, but checking-in since Im pa…
Browse files Browse the repository at this point in the history
…ranoid
  • Loading branch information
client9 committed Apr 6, 2010
1 parent b6862b1 commit 91f6765
Show file tree
Hide file tree
Showing 9 changed files with 1,151 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .gitignore
Expand Up @@ -4,9 +4,14 @@ dist/env-js.*.jar
*~
rhino/build
jshost
htmlparser/gwt*
htmlparser/gwt-*
htmlparser/html5
htmlparser/build

htmlparser/gwt2/htmlparser-*
htmlparser/gwt2/gwt-*-
htmlparser/gwt2/war

local_settings.js
java_pid*

Expand Down
45 changes: 45 additions & 0 deletions htmlparser/gwt2/build.sh
@@ -0,0 +1,45 @@
#!/bin/sh

#
# Autodownload Parser
#
#
PARSER=htmlparser-1.2.1
PARSER_ZIP="${PARSER}.zip"

if [ ! -d "${PARSER}" ]; then
wget "http://about.validator.nu/htmlparser/${PARSER_ZIP}"
unzip ${PARSER_ZIP}
fi

#
# Autodownload GWT
#
#
GWT=gwt-2.0.3
GWT_ZIP="${GWT}.zip"

if [ ! -d "${GWT}" ]; then
wget "http://google-web-toolkit.googlecode.com/files/${GWT_ZIP}"
unzip ${GWT_ZIP}
fi

echo "Starting get compile..."
CP="./src:./${PARSER}/src:./${PARSER}/super:./${GWT}/gwt-user.jar:./${GWT}/gwt-dev.jar"

# Compile a new GWT linker. Very simple to Single Script Linker but
# removes all the "bootstrap" and client (real browser) onScriptLoad
# events, etc.
javac -cp ${CP} src/com/envjs/gwt/linker/ServerSingleScriptLinker.java

java \
-Xmx256M \
-cp "${CP}" \
com.google.gwt.dev.Compiler \
-logLevel ERROR \
-style PRETTY \
-draftCompile \
nu.validator.htmlparser.HtmlParser;

echo "DONE"

11 changes: 11 additions & 0 deletions htmlparser/gwt2/clean.sh
@@ -0,0 +1,11 @@
#!/bin/sh

echo "Cleaning up non-git files"
rm -rf gwt-*
rm -rf htmlparser-*
rm -rf war

find . -name '*~' | xargs rm -f
find . -name '*.class' | xargs rm -f


174 changes: 174 additions & 0 deletions htmlparser/gwt2/src/com/envjs/gwt/linker/ServerSingleScriptLinker.java
@@ -0,0 +1,174 @@
/*
* Copyright 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.envjs.gwt.linker;

import com.google.gwt.core.ext.LinkerContext;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.linker.ArtifactSet;
import com.google.gwt.core.ext.linker.CompilationResult;
import com.google.gwt.core.ext.linker.EmittedArtifact;
import com.google.gwt.core.ext.linker.LinkerOrder;
import com.google.gwt.core.ext.linker.LinkerOrder.Order;
import com.google.gwt.core.ext.linker.impl.SelectionScriptLinker;
import com.google.gwt.dev.About;
import com.google.gwt.dev.util.DefaultTextOutput;

import java.util.Collection;
import java.util.Set;

/**
* A Linker for producing a single JavaScript file from a GWT module. The use of
* this Linker requires that the module has exactly one distinct compilation
* result.
*/
@LinkerOrder(Order.PRIMARY)
public class ServerSingleScriptLinker extends SelectionScriptLinker {
@Override
public String getDescription() {
return "Server Single Script";
}

@Override
public ArtifactSet link(TreeLogger logger, LinkerContext context,
ArtifactSet artifacts) throws UnableToCompleteException {
ArtifactSet toReturn = new ArtifactSet(artifacts);

toReturn.add(emitSelectionScript(logger, context, artifacts));

return toReturn;
}

@Override
protected Collection<EmittedArtifact> doEmitCompilation(TreeLogger logger,
LinkerContext context, CompilationResult result)
throws UnableToCompleteException {
if (result.getJavaScript().length != 1) {
logger.branch(TreeLogger.ERROR,
"The module must not have multiple fragments when using the "
+ getDescription() + " Linker.", null);
throw new UnableToCompleteException();
}
return super.doEmitCompilation(logger, context, result);
}

@Override
protected EmittedArtifact emitSelectionScript(TreeLogger logger,
LinkerContext context, ArtifactSet artifacts)
throws UnableToCompleteException {

DefaultTextOutput out = new DefaultTextOutput(true);

// Emit the selection script.
/*
String bootstrap = generateSelectionScript(logger, context, artifacts);
bootstrap = context.optimizeJavaScript(logger, bootstrap);
out.print(bootstrap);
out.newlineOpt();
*/

// Emit the module's JS a closure.
out.print("var $_window = this;");
out.newlineOpt();
out.print("(function () {");
out.newlineOpt();
out.print("var $gwt_version = \"" + About.getGwtVersionNum() + "\";");
out.newlineOpt();
out.print("var $wnd = $_window;");
out.newlineOpt();
out.print("var $doc = $wnd.document;");
out.newlineOpt();
out.print("var $moduleName, $moduleBase;");
out.newlineOpt();
out.print("var $stats = $wnd.__gwtStatsEvent ? function(a) {$wnd.__gwtStatsEvent(a)} : null;");
out.newlineOpt();

// Find the single CompilationResult
Set<CompilationResult> results = artifacts.find(CompilationResult.class);
if (results.size() != 1) {
logger.log(TreeLogger.ERROR,
"The module must have exactly one distinct"
+ " permutation when using the " + getDescription() + " Linker.",
null);
throw new UnableToCompleteException();
}
CompilationResult result = results.iterator().next();

out.print("var $strongName = '" + result.getStrongName() + "';");
out.newlineOpt();

String[] js = result.getJavaScript();
if (js.length != 1) {
logger.log(TreeLogger.ERROR,
"The module must not have multiple fragments when using the "
+ getDescription() + " Linker.", null);
throw new UnableToCompleteException();
}

out.print(js[0]);

// Generate the call to tell the bootstrap code that we're ready to go.
out.newlineOpt();

// the original code setup an "onScriptLoad" event.
// Here we just do it
out.print("gwtOnLoad();");

out.newlineOpt();
out.print("})();");
out.newlineOpt();

return emitString(logger, out.toString(), context.getModuleName()
+ ".nocache.js");
}

/**
* Unimplemented. Normally required by
* {@link #doEmitCompilation(TreeLogger, LinkerContext, CompilationResult)}.
*/
@Override
protected String getCompilationExtension(TreeLogger logger,
LinkerContext context) throws UnableToCompleteException {
throw new UnableToCompleteException();
}

/**
* Unimplemented. Normally required by
* {@link #doEmitCompilation(TreeLogger, LinkerContext, CompilationResult)}.
*/
@Override
protected String getModulePrefix(TreeLogger logger, LinkerContext context,
String strongName) throws UnableToCompleteException {
throw new UnableToCompleteException();
}

/**
* Unimplemented. Normally required by
* {@link #doEmitCompilation(TreeLogger, LinkerContext, CompilationResult)}.
*/
@Override
protected String getModuleSuffix(TreeLogger logger, LinkerContext context)
throws UnableToCompleteException {
throw new UnableToCompleteException();
}

@Override
protected String getSelectionScriptTemplate(TreeLogger logger,
LinkerContext context) throws UnableToCompleteException {
throw new UnableToCompleteException();
}

}
24 changes: 24 additions & 0 deletions htmlparser/gwt2/src/nu/validator/htmlparser/HtmlParser.gwt.xml
@@ -0,0 +1,24 @@
<module>
<inherits name="com.google.gwt.core.Core"/>
<inherits name="com.google.gwt.user.User"/>
<super-source path="translatable"/>
<source path="annotation"/>
<source path="common"/>
<source path="impl"/>
<source path="gwt"/>
<entry-point class="nu.validator.htmlparser.gwt.HtmlParserModule"/>

<!--
add our linker, which doesn't have all the client script loading junk
-->

<define-linker name="sssl" class="com.envjs.gwt.linker.ServerSingleScriptLinker" />
<add-linker name="sssl" />

<!--
envjs
set GWT 2.0 to use a single 'user agent'
-->
<set-property name="user.agent" value="gecko" />

</module>

0 comments on commit 91f6765

Please sign in to comment.