Skip to content

Commit

Permalink
Cut out gwt-dev, only gwt-user remains to remove as strings are factored
Browse files Browse the repository at this point in the history
out to support both new and old packages
  • Loading branch information
niloc132 committed Dec 1, 2018
1 parent 8a46a6c commit a0dfb66
Show file tree
Hide file tree
Showing 11 changed files with 674 additions and 15 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<repositories>
<repository>
<id>vertispan-snapshot-repository</id>
<name>Vertispan Snapshot Repository</name>
<url>https://repo.vertispan.com/gwt-snapshot/</url>
</repository>
</repositories>

<profiles>
<!-- release profile to create sources, javadoc, and sign all artifacts before uploading -->
Expand Down
17 changes: 9 additions & 8 deletions processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
</properties>

<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.8.2</version>
</dependency>

<dependency>
<groupId>com.google.jsilver</groupId>
<artifactId>jsilver</artifactId>
Expand All @@ -38,6 +32,13 @@
<groupId>org.gwtproject.safehtml</groupId>
<artifactId>gwt-safehtml</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.gwtproject.safecss</groupId>
<artifactId>gwt-safecss</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>

<dependency>
Expand All @@ -49,9 +50,9 @@

<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<artifactId>gwt-user</artifactId>
<version>2.8.2</version>
<scope>test</scope>
<!--<scope>test</scope>-->
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.gwtproject.safehtml.apt;

import com.google.gwt.codegen.server.AbortablePrintWriter;
import com.google.gwt.codegen.server.JavaSourceWriterBuilder;
import com.google.gwt.codegen.server.SourceWriter;
import com.squareup.javapoet.ClassName;
import org.gwtproject.safehtml.apt.source.AbortablePrintWriter;
import org.gwtproject.safehtml.apt.source.JavaSourceWriterBuilder;
import org.gwtproject.safehtml.apt.source.SourceWriter;

import java.io.IOException;
import java.io.PrintWriter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package org.gwtproject.safehtml.apt;

import com.google.common.primitives.Primitives;
import com.google.gwt.codegen.server.SourceWriter;
import com.google.gwt.safecss.shared.SafeStyles;
import org.gwtproject.safehtml.apt.source.SourceWriter;
import org.gwtproject.safehtml.shared.SafeHtml;
import org.gwtproject.safehtml.shared.SafeHtmlUtils;
import org.gwtproject.safehtml.shared.SafeUri;
Expand All @@ -32,7 +32,7 @@

/**
* Method body code generator for implementations of
* {@link com.google.gwt.safehtml.client.SafeHtmlTemplates}.
* {@link org.gwtproject.safehtml.client.SafeHtmlTemplates}.
*/
public class SafeHtmlTemplatesImplMethodCreator {

Expand Down Expand Up @@ -189,7 +189,7 @@ private void emitAttributeContextParameterExpression(ParsedHtmlTemplate.HtmlCont
* of the {@link SafeHtml} type.
*
* <p>The template is parsed as a HTML template (see
* {@link com.google.gwt.safehtml.rebind.HtmlTemplateParser}). From the template's parsed form, code is
* {@link HtmlTemplateParser}). From the template's parsed form, code is
* generated that, when executed, will emit an instantiation of the template.
* The generated code appropriately escapes and/or sanitizes template
* parameters such that evaluating the emitted string as HTML in a browser
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2011 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 org.gwtproject.safehtml.apt.source;

import java.io.PrintWriter;

/**
* Wrapper for a {@link PrintWriter} that adds the ability to abort creation
* and an onClose hook
* <p>
* Experimental API - subject to change.
*/
public class AbortablePrintWriter extends PrintWriter {

private boolean isClosed = false;

/**
* Wrap a {@link PrintWriter} instance.
*
* @param pw
* @throws RuntimeException if there are reflection errors accessing the out
* field in pw
*/
public AbortablePrintWriter(PrintWriter pw) {
super(pw);
}

/**
* Abort creation of this output.
*/
public void abort() {
if (!isClosed) {
flush();
super.close();
isClosed = true;
onClose(true);
}
}

@Override
public void close() {
if (!isClosed) {
flush();
super.close();
isClosed = true;
onClose(false);
}
}

/**
* Called exactly once when this {@link PrintWriter} is closed or aborted.
*
* @param aborted
*/
protected void onClose(boolean aborted) {
// Do nothing by default.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* Copyright 2011 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 org.gwtproject.safehtml.apt.source;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* A mechanism to write Java source files.
*
* @see JavaSourceWriterBuilder
* <p>
* Experimental API - subject to change.
*/
public class JavaSourceWriter extends SourceWriterBase {

private static final Pattern PKG_REGEX_BOTH = Pattern.compile("(com\\.google|javax?)\\..*");
private static final Pattern PKG_REGEX_GOOGLE = Pattern.compile("com\\.google\\..*");
private static final Pattern PKG_REGEX_JAVA = Pattern.compile("javax?\\..*");

private final AbortablePrintWriter printWriter;

/**
* @param printWriter
* @param targetPackageName
* @param imports
* @param isClass
* @param classJavaDocComment
* @param annotationDeclarations
* @param targetClassShortName
* @param superClassName
* @param interfaceNames
*/
public JavaSourceWriter(AbortablePrintWriter printWriter, String targetPackageName,
Iterable<String> imports, boolean isClass, String classJavaDocComment,
Iterable<String> annotationDeclarations, String targetClassShortName, String superClassName,
Iterable<String> interfaceNames) {
this.printWriter = printWriter;
if (targetPackageName == null) {
throw new IllegalArgumentException("Cannot supply a null package name to"
+ targetClassShortName);
}
// TODO: support a user-specified file header
if (targetPackageName.length() > 0) {
println("package " + targetPackageName + ";");
}

// Write imports, splitting into com.google, other, and java/javax groups
writeImportGroup(imports, PKG_REGEX_GOOGLE, true);
writeImportGroup(imports, PKG_REGEX_BOTH, false);
writeImportGroup(imports, PKG_REGEX_JAVA, true);

// Write class header
if (classJavaDocComment != null) {
beginJavaDocComment();
print(classJavaDocComment);
endJavaDocComment();
} else {
// beginJavaDocComment adds its own leading newline, make up for it here.
println();
}
for (String annotation : annotationDeclarations) {
println('@' + annotation);
}
if (isClass) {
emitClassDecl(targetClassShortName, superClassName, interfaceNames);
} else {
emitInterfaceDecl(targetClassShortName, superClassName, interfaceNames);
}
println(" {");
indent();
}

@Override
public void abort() {
printWriter.abort();
}

@Override
public void close() {
super.close();
printWriter.close();
}

@Override
protected void writeString(String s) {
printWriter.print(s);
}

private void emitClassDecl(String targetClassShortName,
String superClassName, Iterable<String> interfaceNames) {
print("public class " + targetClassShortName);
if (superClassName != null) {
print(" extends " + superClassName);
}
boolean first = true;
for (String interfaceName : interfaceNames) {
if (first) {
print(" implements ");
first = false;
} else {
print(", ");
}
print(interfaceName);
}
}

private void emitInterfaceDecl(String targetClassShortName,
String superClassName, Iterable<String> interfaceNames) {
if (superClassName != null) {
throw new IllegalArgumentException("Cannot set superclass name "
+ superClassName + " on a interface.");
}
print("public interface " + targetClassShortName);
boolean first = true;
for (String interfaceName : interfaceNames) {
if (first) {
print(" extends ");
first = false;
} else {
print(", ");
}
print(interfaceName);
}
}

/**
* Write a group of imports matching or not matching a regex.
*
* @param imports
* @param regex
* @param includeMatches true to include imports matching the regex, false to
* include only those that don't match
*/
private void writeImportGroup(Iterable<String> imports, Pattern regex, boolean includeMatches) {
boolean firstOfGroup = true;
for (String importEntry : imports) {
Matcher matcher = regex.matcher(importEntry);
if (matcher.matches() == includeMatches) {
if (firstOfGroup) {
println();
firstOfGroup = false;
}
println("import " + importEntry + ";");
}
}
}
}
Loading

0 comments on commit a0dfb66

Please sign in to comment.