Skip to content

Commit 8ece726

Browse files
author
Talin Joiner
committed
Closure templates release 2014-04-22.
1 parent d96fbe2 commit 8ece726

File tree

1,372 files changed

+313954
-253238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,372 files changed

+313954
-253238
lines changed

README.md

-12
This file was deleted.

build.xml

+11-21
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Author: Neil Sanchala
6060
<mkdir dir="${build.genfiles.dir}" />
6161
<mkdir dir="${build.genfiles.dir}/com/google/template/soy/exprparse" />
6262
<mkdir dir="${build.genfiles.dir}/com/google/template/soy/soyparse" />
63+
<mkdir dir="${build.genfiles.dir}/com/google/template/soy/types/parse" />
6364

6465
<!-- JavaCC compilation. Generated files go into the 'genfiles' directory. -->
6566
<javacc target="${java.src.dir}/com/google/template/soy/exprparse/ExpressionParser.jj"
@@ -71,12 +72,15 @@ Author: Neil Sanchala
7172
<javacc target = "${java.src.dir}/com/google/template/soy/soyparse/TemplateParser.jj"
7273
outputdirectory = "${build.genfiles.dir}/com/google/template/soy/soyparse"
7374
javacchome = "buildtools/javacc" />
75+
<javacc target = "${java.src.dir}/com/google/template/soy/types/parse/TypeParser.jj"
76+
outputdirectory = "${build.genfiles.dir}/com/google/template/soy/types/parse"
77+
javacchome = "buildtools/javacc" />
7478

7579
<!-- Java compilation. -->
7680
<javac srcdir="${java.src.dir}:${build.genfiles.dir}"
7781
destdir="${build.classes.dir}"
78-
source="1.6"
79-
target="1.6"
82+
source="1.7"
83+
target="1.7"
8084
includeAntRuntime="true"
8185
debug="${includeDebugInfo}">
8286
<classpath refid="classpath.path" />
@@ -92,7 +96,7 @@ Author: Neil Sanchala
9296
description="generates soyutils.js and soyutils_usegoog.js.">
9397
<!-- Load a custom ANT task. -->
9498
<taskdef name="gen.escape.directives"
95-
classname="com.google.template.soy.jssrc.internal.GenerateSoyUtilsEscapingDirectiveCode">
99+
classname="com.google.template.soy.shared.internal.GenerateSoyUtilsEscapingDirectiveCode">
96100
<classpath>
97101
<fileset dir="${java.lib.dir}">
98102
<include name="*.jar" />
@@ -111,8 +115,8 @@ Author: Neil Sanchala
111115
<gen.escape.directives>
112116
<input path="${basedir}/javascript/soyutils_usegoog.js"/>
113117
<output path="${build.dir}/javascript/soyutils_usegoog.js"/>
114-
<jsdefined pattern="goog.string.*"/>
115-
<jsdefined pattern="goog.asserts.*"/>
118+
<libdefined pattern="goog.string.*"/>
119+
<libdefined pattern="goog.asserts.*"/>
116120
</gen.escape.directives>
117121
</target>
118122

@@ -189,19 +193,6 @@ Author: Neil Sanchala
189193
</target>
190194

191195

192-
<!-- Target to create a standalone executable SoyToJavaSrcCompilerExperimental.jar. -->
193-
<target name="SoyToJavaSrcCompilerExperimental"
194-
depends="jar"
195-
description="Creates a standalone executable SoyToJavaSrcCompilerExperimental.jar.">
196-
<jar destfile="${build.dir}/SoyToJavaSrcCompilerExperimental.jar" update="true">
197-
<manifest>
198-
<attribute name="Main-Class" value="com.google.template.soy.SoyToJavaSrcCompilerExperimental" />
199-
</manifest>
200-
<zipfileset src="${soy.jar.file}" />
201-
</jar>
202-
</target>
203-
204-
205196
<!-- Target to generate lite javadoc (for API users). -->
206197
<target name="javadoc-lite"
207198
depends="compile"
@@ -215,7 +206,6 @@ Author: Neil Sanchala
215206
<packageset dir="${java.src.dir}">
216207
<include name="com/google/template/soy" />
217208
<include name="com/google/template/soy/data" />
218-
<include name="com/google/template/soy/javasrc" />
219209
<include name="com/google/template/soy/jssrc" />
220210
<include name="com/google/template/soy/msgs" />
221211
<include name="com/google/template/soy/parseinfo" />
@@ -664,8 +654,8 @@ Author: Neil Sanchala
664654
<mkdir dir="${build.testclasses.dir}" />
665655
<javac srcdir="${java.tests.dir}"
666656
destdir="${build.testclasses.dir}"
667-
source="1.6"
668-
target="1.6"
657+
source="1.7"
658+
target="1.7"
669659
includeAntRuntime="false"
670660
debug="${includeDebugInfo}">
671661
<classpath refid="classpath.path" />

examples/delegates0.soy

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// Delegates examples (total 3 files).
1616
// Author: Kai Huang
1717

18-
{namespace soy.examples.delegates}
18+
{namespace soy.examples.delegates autoescape="strict"}
1919

2020

2121
/**
@@ -36,6 +36,6 @@
3636
* @param moo Note: Must list same params for all implementations, even if not all implementations
3737
* use a param.
3838
*/
39-
{deltemplate myDelegates.foo}
39+
{deltemplate myDelegates.foo kind="text"}
4040
myDelegates.foo default.
4141
{/deltemplate}

examples/delegates1.soy

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
// Author: Kai Huang
1717

1818
{delpackage alpha}
19-
{namespace soy.examples.delegates}
19+
{namespace soy.examples.delegates autoescape="strict"}
2020

2121

2222
/**
2323
* Delegate package 'alpha' implementation of 'delegateBoo'.
2424
*/
25-
{deltemplate delegateBoo}
25+
{deltemplate delegateBoo kind="text"}
2626
delegateBoo from delegate package alpha.
2727
{/deltemplate}
2828

@@ -32,6 +32,6 @@
3232
* @param moo Note: Must list same params for all implementations, even if not all implementations
3333
* use a param.
3434
*/
35-
{deltemplate myDelegates.foo}
35+
{deltemplate myDelegates.foo kind="text"}
3636
myDelegates.foo from delegate package alpha (moo = {$moo}).
3737
{/deltemplate}

examples/delegates2.soy

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
// Author: Kai Huang
1717

1818
{delpackage beta}
19-
{namespace soy.examples.delegates}
19+
{namespace soy.examples.delegates autoescape="strict"}
2020

2121

2222
/**
2323
* Delegate package 'beta' implementation of 'delegateBoo'.
2424
*/
25-
{deltemplate delegateBoo}
25+
{deltemplate delegateBoo kind="text"}
2626
delegateBoo from delegate package beta.
2727
{/deltemplate}

java/lib/guava-12.0.jar

-1.71 MB
Binary file not shown.

java/lib/guava-14.0.jar

2.09 MB
Binary file not shown.

java/lib/icu4j-4_8_1_1.jar

-6.95 MB
Binary file not shown.

java/lib/icu4j-51_1.jar

9.52 MB
Binary file not shown.

java/src/com/google/template/soy/GuiceInitializer.java

+37-9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import com.google.inject.Guice;
2020
import com.google.inject.Inject;
2121

22+
import java.util.logging.Level;
23+
import java.util.logging.Logger;
2224

2325
/**
2426
* Helper class to initialize Guice for Soy users that do not use Guice.
@@ -35,30 +37,56 @@
3537
*
3638
* @author Kai Huang
3739
*/
40+
// TODO(gboyer): This class is very unfortunate. Static injection essentially means that whichever
41+
// Injector installed SoyModule last wins, which can cause bewildering errors.
3842
class GuiceInitializer {
43+
private static final Logger LOGGER = Logger.getLogger(GuiceInitializer.class.getName());
3944

45+
/** How many time this has been statically injected. */
46+
private static int initializationCount;
4047

41-
/** Whether the SoyModule has been initialized. */
42-
private static boolean isInitialized = false;
43-
48+
/** Factory created from static injection. */
49+
@Inject
50+
private static SoyFileSet.SoyFileSetFactory soyFileSetFactory = null;
4451

4552
/** Marks that the SoyModule has been initialized. */
4653
@Inject
47-
static void markInitialized() {
48-
isInitialized = true;
54+
static synchronized void markInitialized() {
55+
initializationCount++;
4956
}
5057

51-
5258
/** Initializes the SoyModule if it has not already been initialized. */
53-
static void initializeIfNecessary() {
54-
if (!isInitialized) {
59+
private static synchronized void initializeIfNecessary() {
60+
if (initializationCount == 0) {
5561
// This injector creation has the important side effect of performing static injections.
5662
Guice.createInjector(new SoyModule());
5763
// The injector creation above should have called this class's markInitialized().
58-
if (!isInitialized) {
64+
if (initializationCount == 0) {
5965
throw new AssertionError("Injector creation failed to do static injection.");
6066
}
6167
}
6268
}
6369

70+
/**
71+
* Returns the hacky static-injected SoyFileSetFactory containing bindings from whichever
72+
* injector happened to install SoyModule first.
73+
*/
74+
static synchronized SoyFileSet.SoyFileSetFactory getHackySoyFileSetFactory() {
75+
initializeIfNecessary();
76+
if (initializationCount > 1) {
77+
String message =
78+
"The SoyFileSet.Builder constructor is trying to guess which Injector to use, but"
79+
+ " multiple Injectors have already installed a new SoyModule(). We will essentially"
80+
+ " configure Soy at random, so you get an inconsistent set of plugins or Soy types."
81+
+ " To fix, inject SoyFileSet.Builder (with SoyModule installed) instead of new'ing it.";
82+
LOGGER.log(Level.SEVERE, message, new IllegalStateException(message));
83+
} else {
84+
String message =
85+
"Falling back to statically-injected SoyFileSetFactory; unpredictable behavior is likely."
86+
+ " Instead of constructing a SoyFileSet.Builder directly, either inject it using Guice"
87+
+ " (with SoyModule installed), or call the static SoyFileSet.builder() method.";
88+
LOGGER.log(Level.WARNING, message);
89+
}
90+
return soyFileSetFactory;
91+
}
6492
}

java/src/com/google/template/soy/MainClassUtils.java

+46-12
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020

2121
import com.google.common.base.Function;
2222
import com.google.common.base.Splitter;
23+
import com.google.common.collect.ImmutableSet;
2324
import com.google.common.collect.Lists;
25+
import com.google.common.collect.Sets;
2426
import com.google.inject.Guice;
2527
import com.google.inject.Injector;
2628
import com.google.inject.Module;
2729
import com.google.template.soy.SoyFileSet.Builder;
28-
import com.google.template.soy.base.SoyFileKind;
30+
import com.google.template.soy.base.internal.SoyFileKind;
2931

3032
import org.kohsuke.args4j.CmdLineException;
3133
import org.kohsuke.args4j.CmdLineParser;
@@ -37,10 +39,10 @@
3739
import java.io.File;
3840
import java.util.Collection;
3941
import java.util.List;
42+
import java.util.Set;
4043

4144
import javax.annotation.Nullable;
4245

43-
4446
/**
4547
* Private utils for classes with a main() method.
4648
*
@@ -51,6 +53,7 @@ class MainClassUtils {
5153
private MainClassUtils() {}
5254

5355

56+
5457
/**
5558
* OptionHandler for args4j that handles a boolean.
5659
*
@@ -189,10 +192,9 @@ public static void exitWithError(
189192
System.exit(1);
190193
}
191194

192-
193195
/**
194196
* Creates a Guice injector that includes the SoyModule, a message plugin module, and maybe
195-
* additional plugin modules.
197+
* additional plugin modules, and maybe additional modules.
196198
*
197199
* @param msgPluginModuleName The full class name of the message plugin module. Required.
198200
* @param pluginModuleNames Comma-delimited list of full class names of additional plugin modules
@@ -210,7 +212,7 @@ public static Injector createInjector(
210212
checkArgument(msgPluginModuleName != null && msgPluginModuleName.length() > 0);
211213
guiceModules.add(instantiatePluginModule(msgPluginModuleName));
212214

213-
if (pluginModuleNames != null && pluginModuleNames.length() > 0) {
215+
if (pluginModuleNames != null && !pluginModuleNames.isEmpty()) {
214216
for (String pluginModuleName : Splitter.on(',').split(pluginModuleNames)) {
215217
guiceModules.add(instantiatePluginModule(pluginModuleName));
216218
}
@@ -219,6 +221,29 @@ public static Injector createInjector(
219221
return Guice.createInjector(guiceModules);
220222
}
221223

224+
/**
225+
* Creates a Guice injector that includes the SoyModule, a message plugin module, and maybe
226+
* additional plugin modules, and maybe additional modules.
227+
*
228+
* @param pluginModuleNames Comma-delimited list of full class names of additional plugin modules
229+
* to include. Optional.
230+
* @return A Guice injector that includes the SoyModule, the given message plugin module, and the
231+
* given additional plugin modules (if any).
232+
*/
233+
public static Injector createInjector(@Nullable String pluginModuleNames) {
234+
235+
List<Module> guiceModules = Lists.newArrayListWithCapacity(2);
236+
237+
guiceModules.add(new SoyModule());
238+
239+
if (pluginModuleNames != null && !pluginModuleNames.isEmpty()) {
240+
for (String pluginModuleName : Splitter.on(',').split(pluginModuleNames)) {
241+
guiceModules.add(instantiatePluginModule(pluginModuleName));
242+
}
243+
}
244+
245+
return Guice.createInjector(guiceModules);
246+
}
222247

223248
/**
224249
* Private helper for createInjector().
@@ -253,7 +278,8 @@ private static Module instantiatePluginModule(String moduleName) {
253278
*/
254279
public static void addSoyFilesToBuilder(
255280
Builder sfsBuilder, String inputPrefix, Collection<String> srcs, Collection<String> args,
256-
Collection<String> deps, Function<String, Void> exitWithErrorFn) {
281+
Collection<String> deps, Collection<String> indirectDeps,
282+
Function<String, Void> exitWithErrorFn) {
257283

258284
if (srcs.size() == 0 && args.size() == 0) {
259285
exitWithErrorFn.apply("Must provide list of source Soy files (--srcs).");
@@ -263,16 +289,24 @@ public static void addSoyFilesToBuilder(
263289
"Found source Soy files from --srcs and from args (please use --srcs only).");
264290
}
265291

266-
for (String src : srcs) {
267-
sfsBuilder.addWithKind(new File(inputPrefix + src), SoyFileKind.SRC);
268-
}
269-
// TODO: Maybe stop supporting old style (srcs from command line args) at some point.
270-
for (String src : args) {
292+
// Create Set versions of each of the arguments, and de-dupe. If something is included as
293+
// multiple file kinds, we'll keep the strongest one; a file in both srcs and deps will be a
294+
// src, and one in both deps and indirect_deps will be a dep.
295+
// TODO(gboyer): Maybe stop supporting old style (srcs from command line args) at some point.
296+
Set<String> srcsSet = ImmutableSet.<String>builder().addAll(srcs).addAll(args).build();
297+
Set<String> depsSet = Sets.difference(ImmutableSet.copyOf(deps), srcsSet);
298+
Set<String> indirectDepsSet = Sets.difference(ImmutableSet.copyOf(indirectDeps),
299+
Sets.union(srcsSet, depsSet));
300+
301+
for (String src : srcsSet) {
271302
sfsBuilder.addWithKind(new File(inputPrefix + src), SoyFileKind.SRC);
272303
}
273-
for (String dep : deps) {
304+
for (String dep : depsSet) {
274305
sfsBuilder.addWithKind(new File(inputPrefix + dep), SoyFileKind.DEP);
275306
}
307+
for (String dep : indirectDepsSet) {
308+
sfsBuilder.addWithKind(new File(inputPrefix + dep), SoyFileKind.INDIRECT_DEP);
309+
}
276310
}
277311

278312
}

0 commit comments

Comments
 (0)