Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Get rid of all uses of Mako in pants.

Mako is platform-dependent, leading to deployment headaches.
Instead we now use mustache, whose python bindings (pystache)
are pure python.
  • Loading branch information...
commit e28afe768eed4d1b50d7817e1de2eb2b9d0b46bd 1 parent 49d7950
Benjy authored
Showing with 295 additions and 265 deletions.
  1. +1 −1  3rdparty/python/BUILD
  2. BIN  3rdparty/python/pystache-0.5.3-py2.6.egg
  3. +2 −1  pants
  4. +2 −2 src/python/twitter/pants/BUILD
  5. +20 −2 src/python/twitter/pants/ant/lib.py
  6. +21 −18 src/python/twitter/pants/base/generator.py
  7. +1 −1  src/python/twitter/pants/pants_doc/doc_builder.py
  8. +1 −1  src/python/twitter/pants/pants_doc/templates/{doc.mk → doc.mustache}
  9. +18 −18 src/python/twitter/pants/tasks/eclipse/templates/{classpath-3.7.mk → classpath-3.7.mustache}
  10. +3 −3 src/python/twitter/pants/tasks/eclipse/templates/{debug-launcher-3.7.mk → debug-launcher-3.7.mustache}
  11. +3 −3 src/python/twitter/pants/tasks/eclipse/templates/{factorypath-3.7.mk → factorypath-3.7.mustache}
  12. +20 −19 src/python/twitter/pants/tasks/eclipse/templates/{project-3.7.mk → project-3.7.mustache}
  13. +11 −10 src/python/twitter/pants/tasks/eclipse/templates/{pydevproject-3.7.mk → pydevproject-3.7.mustache}
  14. +20 −14 src/python/twitter/pants/tasks/eclipse_gen.py
  15. +1 −1  src/python/twitter/pants/tasks/ide_gen.py
  16. +41 −40 src/python/twitter/pants/tasks/idea/templates/{module-11.mk → module-11.mustache}
  17. +25 −25 src/python/twitter/pants/tasks/idea/templates/{project-11.mk → project-11.mustache}
  18. +5 −2 src/python/twitter/pants/tasks/idea_gen.py
  19. +3 −3 src/python/twitter/pants/tasks/ivy_resolve.py
  20. +60 −64 src/python/twitter/pants/tasks/ivy_resolve/{ivy.mk → ivy.mustache}
  21. +8 −8 src/python/twitter/pants/tasks/jar_publish.py
  22. +11 −11 src/python/twitter/pants/tasks/jar_publish/{ivysettings.mk → ivysettings.mustache}
  23. +18 −18 src/python/twitter/pants/tasks/jar_publish/{pom.mk → pom.mustache}
View
2  3rdparty/python/BUILD
@@ -147,7 +147,7 @@ python_library(
python_library(
name = 'pystache',
- dependencies = [egg('pystache-0.3.1-py2.6.egg')])
+ dependencies = [egg('pystache-0.5.3-py2.6.egg')])
python_library(
name = 'lxml',
View
BIN  3rdparty/python/pystache-0.5.3-py2.6.egg
Binary file not shown
View
3  pants
@@ -22,11 +22,12 @@ PANTS_EXE=$MY_DIR/src/python/twitter/pants/bin/pants_exe.py
MAKO_EGG=$MY_DIR/3rdparty/python/Mako-0.4.0-py2.6.egg
MARKDOWN_EGG=$MY_DIR/3rdparty/python/Markdown-2.1.1-py2.6.egg
PYGMENTS_EGG=$MY_DIR/3rdparty/python/Pygments-1.4-py2.6.egg
+PYSTACHE_EGG=$MY_DIR/3rdparty/python/pystache-0.5.3-py2.6.egg
PYTHON_DAEMON_EGG=$MY_DIR/3rdparty/python/python_daemon-1.6-py2.6.egg
function run_pants_bare() {
source $VIRTUAL_PYTHON/bin/activate
- PYTHONPATH=$MAKO_EGG:$MARKDOWN_EGG:$PYGMENTS_EGG:$PYTHON_DAEMON_EGG:$MY_DIR/src/python python $PANTS_EXE "$@"
+ PYTHONPATH=$MAKO_EGG:$MARKDOWN_EGG:$PYGMENTS_EGG:$PYSTACHE_EGG:$PYTHON_DAEMON_EGG:$MY_DIR/src/python python $PANTS_EXE "$@"
deactivate
}
View
4 src/python/twitter/pants/BUILD
@@ -27,11 +27,11 @@ python_library(
name = 'pants-deps',
dependencies = [
python_requirement('elementtree'),
- python_requirement('mako'),
+ python_requirement('mako'), # TODO: Remove after getting rid of the doc command.
python_requirement('markdown'),
- python_requirement('psutil'),
python_requirement('pygments'),
python_requirement('pylint', version_filter=pylint_build_filter),
+ python_requirement('pystache'),
python_requirement('pytest'),
python_requirement('python_daemon'),
]
View
22 src/python/twitter/pants/ant/lib.py
@@ -22,9 +22,10 @@
import subprocess
import traceback
+from mako.template import Template
+
from twitter.pants import has_jvm_targets, is_jvm
from twitter.pants.ant import bang
-from twitter.pants.base.generator import Generator
from twitter.pants.base.builder import Builder
from twitter.pants.targets import (
JarDependency,
@@ -53,7 +54,7 @@ def generate_ivy(cls, root_dir, output_filename, target):
def _generate(cls, root_dir, template, template_data, output_filename):
with open(output_filename, 'w') as output:
template_path = os.path.join(_TEMPLATE_BASEDIR, '%s.mk' % template)
- generator = Generator(pkgutil.get_data(__name__, template_path),
+ generator = MakoGenerator(pkgutil.get_data(__name__, template_path),
root_dir = root_dir, lib = template_data)
generator.write(output)
@@ -196,3 +197,20 @@ def _resolve_targets(self, targets, name = None):
return bang.extract_target(targets, name)
else:
return foil
+
+class MakoGenerator(object):
+ """Generates pants intermediary output files using a configured mako template."""
+
+ _module_directory = '/tmp/pants-%s' % os.environ['USER']
+
+ def __init__(self, template_text, **template_data):
+ self._template = Template(text = template_text,
+ module_directory = MakoGenerator._module_directory)
+ self.template_data = template_data
+
+ def write(self, stream):
+ """Applies the template to the template data and writes the result to the given file-like
+ stream."""
+
+ stream.write(self._template.render(**self.template_data))
+
View
39 src/python/twitter/pants/base/generator.py
@@ -16,24 +16,30 @@
from __future__ import print_function
-import sys
-
-class PantsBootstrapError(ImportError):
- pass
+import pprint
+import pystache
-try:
- from mako.template import Template
-except ImportError:
- raise PantsBootstrapError("Could not properly bootstrap Pants because Mako is missing!")
-import os
-import pprint
+def _expand(map):
+ # Add has_foo for each foo in the map that evaluates to true.
+ # Mustache needs this, especially in cases where foo is a list.
+ # Note: if the original map contains has_foo, it will take precedence over our synthetic has_foo.
+ def set_to_map(x):
+ # Pystache can't handle sets, so we convert to maps of key->True.
+ if isinstance(x, set):
+ return dict([(k, True) for k in x])
+ else:
+ return x
+ items = [(key, set_to_map(val)) for (key, val) in map.items()]
+ ret = dict([('has_' + key, True) for (key, val) in items if val])
+ ret.update(dict(items))
+ return ret
class TemplateData(dict):
- """Encapsulates data for a mako template as a property-addressable read-only map-like struct."""
+ """Encapsulates data for a mustache template as a property-addressable read-only map-like struct."""
def __init__(self, **kwargs):
- dict.__init__(self, kwargs)
+ dict.__init__(self, _expand(kwargs))
def extend(self, **kwargs):
"""Returns a new TemplateData with this template's data overlayed by the key value pairs
@@ -56,17 +62,14 @@ def __str__(self):
return 'TemplateData(%s)' % pprint.pformat(self)
class Generator(object):
- """Generates pants intermediary output files using a configured mako template."""
-
- _module_directory = '/tmp/pants-%s' % os.environ['USER']
+ """Generates pants intermediary output files using a configured mustache template."""
def __init__(self, template_text, **template_data):
- self._template = Template(text = template_text,
- module_directory = Generator._module_directory)
+ self._template = pystache.parse(unicode(template_text))
self.template_data = template_data
def write(self, stream):
"""Applies the template to the template data and writes the result to the given file-like
stream."""
+ stream.write(pystache.render(self._template, self.template_data))
- stream.write(self._template.render(**self.template_data))
View
2  src/python/twitter/pants/pants_doc/doc_builder.py
@@ -38,7 +38,7 @@ def __init__(self, root_dir):
self.root_dir = root_dir
def build(self, targets, _):
- template_path = os.path.join(_TEMPLATE_BASEDIR, 'doc.mk')
+ template_path = os.path.join(_TEMPLATE_BASEDIR, 'doc.mustache')
template = pkgutil.get_data(__name__, template_path)
for target in targets:
assert is_doc(target), 'DocBuilder can only build DocTargets, given %s' % str(target)
View
2  src/python/twitter/pants/pants_doc/templates/doc.mk → ...on/twitter/pants/pants_doc/templates/doc.mustache
@@ -1,4 +1,4 @@
<html>
<body>
-${text}
+{{text}}
</body>
View
36 ...er/pants/tasks/eclipse/templates/classpath-3.7.mk → ...ts/tasks/eclipse/templates/classpath-3.7.mustache
@@ -20,32 +20,32 @@ limitations under the License.
<!-- generated by pants! -->
<classpath>
- % if classpath.has_scala:
+ {{#classpath.has_scala}}
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
- % endif
+ {{/classpath.has_scala}}
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- % for sourcepath in classpath.sourcepaths:
+ {{#classpath.sourcepaths}}
<classpathentry kind="src"
- path="${sourcepath.base}"
- % if sourcepath.includes:
- including="${'|'.join(sourcepath.includes)}"
- % endif
- % if sourcepath.excludes:
- excluding="${'|'.join(sourcepath.excludes)}"
- % endif
+ path="{{base}}"
+ {{#joined_includes}}
+ including="{{.}}"
+ {{/joined_includes}}
+ {{#joined_excludes}}
+ excluding="{{.}}"
+ {{/joined_excludes}}
/>
- % endfor
+ {{/classpath.sourcepaths}}
- % for jar, source_jar in classpath.libs:
+ {{#classpath.libs}}
<classpathentry kind="lib"
- path="${jar}"
- % if source_jar:
- sourcepath="${source_jar}"
- % endif
+ path="{{jar}}"
+ {{#source_jar}}
+ sourcepath="{{.}}"
+ {{/source_jar}}
/>
- % endfor
+ {{/classpath.libs}}
- <classpathentry kind="output" path="${classpath.outdir}"/>
+ <classpathentry kind="output" path="{{classpath.outdir}}"/>
</classpath>
View
6 ...nts/tasks/eclipse/templates/debug-launcher-3.7.mk → ...sks/eclipse/templates/debug-launcher-3.7.mustache
@@ -21,7 +21,7 @@ limitations under the License.
<!-- generated by pants! -->
<launchConfiguration type="org.eclipse.jdt.launching.remoteJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
- <listEntry value="/${project.name}"/>
+ <listEntry value="/{{project.name}}"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
@@ -32,9 +32,9 @@ limitations under the License.
<booleanAttribute key="org.eclipse.jdt.launching.ALLOW_TERMINATE" value="true"/>
<mapAttribute key="org.eclipse.jdt.launching.CONNECT_MAP">
<mapEntry key="hostname" value="localhost"/>
- <mapEntry key="port" value="${project.debug_port}"/>
+ <mapEntry key="port" value="{{project.debug_port}}"/>
</mapAttribute>
- <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="${project.name}"/>
+ <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="{{project.name}}"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_CONNECTOR_ID"
value="org.eclipse.jdt.launching.socketAttachConnector"/>
</launchConfiguration>
View
6 .../pants/tasks/eclipse/templates/factorypath-3.7.mk → .../tasks/eclipse/templates/factorypath-3.7.mustache
@@ -20,9 +20,9 @@ limitations under the License.
<!-- generated by pants! -->
<factorypath>
- % for jarpath in factorypath.jarpaths:
- <factorypathentry kind="WKSPJAR" id="/${factorypath.project_name}/${jarpath}"
+ {{#factorypath.jarpaths}}
+ <factorypathentry kind="WKSPJAR" id="/{{factorypath.project_name}}/{{.}}"
enabled="true"
runInBatchMode="false"/>
- % endfor
+ {{/factorypath.jarpaths}}
</factorypath>
View
39 ...tter/pants/tasks/eclipse/templates/project-3.7.mk → ...ants/tasks/eclipse/templates/project-3.7.mustache
@@ -20,55 +20,56 @@ limitations under the License.
<!-- generated by pants! -->
<projectDescription>
- <name>${project.name}</name>
+ <name>{{project.name}}</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
- ## For whatever reason in a mixed scala/java project, the only jvm builder must be the scala
- ## builder circa eclipse 3.6
- % if project.has_scala:
+ {{! For whatever reason in a mixed scala/java project, the only jvm builder must be the scala
+ builder circa eclipse 3.6}}
+ {{#project.has_scala}}
<buildCommand>
<name>org.scala-ide.sdt.core.scalabuilder</name>
<arguments>
</arguments>
</buildCommand>
- % else:
+ {{/project.has_scala}}
+ {{^project.has_scala}}
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
- % endif
- % if project.has_python:
+ {{/project.has_scala}}
+ {{#project.has_python}}
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
- % endif
+ {{/project.has_python}}
</buildSpec>
<natures>
- % if project.has_scala:
+ {{#project.has_scala}}
<nature>org.scala-ide.sdt.core.scalanature</nature>
- % endif
+ {{/project.has_scala}}
<nature>org.eclipse.jdt.core.javanature</nature>
- % if project.has_python:
+ {{#project.has_python}}
<nature>org.python.pydev.pythonNature</nature>
- % endif
+ {{/project.has_python}}
</natures>
- % if project.source_bases:
+ {{#project.has_source_bases}}
<linkedResources>
- % for source_base, id in project.source_bases:
+ {{#project.source_bases}}
<link>
- <name>${id}</name>
- ## TODO(John Sirois): What does 2 mean? - find out and document.
+ <name>{{id}}</name>
+ {{! TODO(John Sirois): What does 2 mean? - find out and document.}}
<type>2</type>
- <location>${source_base}</location>
+ <location>{{path}}</location>
</link>
- % endfor
+ {{/project.source_bases}}
</linkedResources>
- % endif
+ {{/project.has_source_bases}}
</projectDescription>
View
21 ...pants/tasks/eclipse/templates/pydevproject-3.7.mk → ...tasks/eclipse/templates/pydevproject-3.7.mustache
@@ -21,18 +21,19 @@ limitations under the License.
<!-- generated by pants! -->
<pydev_project>
- ## TODO(John Sirois): support python project setups with interpreter of choice
+ {{! TODO(John Sirois): support python project setups with interpreter of choice.}}
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.6</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
- % for sourcepath in project.pythonpaths:
- % if sourcepath.includes:
- % for include in sourcepath.includes:
- <path>/${project.name}/${sourcepath.base}/${include}</path>
- % endfor
- % else:
- <path>/${project.name}/${sourcepath.base}</path>
- % endif
- % endfor
+ {{#project.pythonpaths}}
+ {{#has_includes}}
+ {{#includes}}
+ <path>/{{project.name}}/{{base}}/{{.}}</path>
+ {{/includes}}
+ {{/has_includes}}
+ {{^has_includes}}
+ <path>/{{project.name}}/{{base}}</path>
+ {{/has_includes}}
+ {{/project.pythonpaths}}
</pydev_pathproperty>
</pydev_project>
View
34 src/python/twitter/pants/tasks/eclipse_gen.py
@@ -15,7 +15,6 @@
# ==================================================================================================
import os
import pkgutil
-import shutil
from collections import defaultdict
@@ -26,6 +25,7 @@
from twitter.pants.base.generator import TemplateData, Generator
from twitter.pants.tasks.ide_gen import IdeGen
+
__author__ = 'John Sirois'
@@ -62,11 +62,11 @@ def __init__(self, context):
IdeGen.__init__(self, context)
eclipse_version = _VERSIONS[context.options.eclipse_gen_version]
- self.project_template = os.path.join(_TEMPLATE_BASEDIR, 'project-%s.mk' % eclipse_version)
- self.classpath_template = os.path.join(_TEMPLATE_BASEDIR, 'classpath-%s.mk' % eclipse_version)
- self.apt_template = os.path.join(_TEMPLATE_BASEDIR, 'factorypath-%s.mk' % eclipse_version)
- self.pydev_template = os.path.join(_TEMPLATE_BASEDIR, 'pydevproject-%s.mk' % eclipse_version)
- self.debug_template = os.path.join(_TEMPLATE_BASEDIR, 'debug-launcher-%s.mk' % eclipse_version)
+ self.project_template = os.path.join(_TEMPLATE_BASEDIR, 'project-%s.mustache' % eclipse_version)
+ self.classpath_template = os.path.join(_TEMPLATE_BASEDIR, 'classpath-%s.mustache' % eclipse_version)
+ self.apt_template = os.path.join(_TEMPLATE_BASEDIR, 'factorypath-%s.mustache' % eclipse_version)
+ self.pydev_template = os.path.join(_TEMPLATE_BASEDIR, 'pydevproject-%s.mustache' % eclipse_version)
+ self.debug_template = os.path.join(_TEMPLATE_BASEDIR, 'debug-launcher-%s.mustache' % eclipse_version)
self.project_filename = os.path.join(self.cwd, '.project')
self.classpath_filename = os.path.join(self.cwd, '.classpath')
@@ -81,19 +81,24 @@ def base_path(source_set):
return os.path.join(source_set.root_dir, source_set.source_base)
source_bases = {}
+ def add_source_base(path, id):
+ source_bases[path] = id
+
for source_set in project.sources:
- source_bases[base_path(source_set)] = linked_folder_id(source_set.source_base)
+ add_source_base(base_path(source_set), linked_folder_id(source_set.source_base))
if project.has_python:
for source_set in project.py_sources:
- source_bases[base_path(source_set)] = linked_folder_id(source_set.source_base)
+ add_source_base(base_path(source_set), linked_folder_id(source_set.source_base))
for source_set in project.py_libs:
- source_bases[base_path(source_set)] = linked_folder_id(source_set.source_base)
+ add_source_base(base_path(source_set), linked_folder_id(source_set.source_base))
def create_source_template(base, includes=None, excludes=None):
return TemplateData(
base=source_bases[base],
includes=includes or [],
excludes=excludes or [],
+ joined_includes = '|'.join(includes) if includes else '',
+ joined_excludes = '|'.join(excludes) if excludes else '',
)
def create_sourcepath(base, sources):
@@ -115,11 +120,12 @@ def normalize_path_pattern(path):
lib_path = source_set.path if source_set.path.endswith('.egg') else '%s/' % source_set.path
pythonpaths.append(create_source_template(base_path(source_set), includes=[lib_path]))
+ source_bases_list = [{'path': path, 'id': id} for (path, id) in source_bases.items()]
configured_project = TemplateData(
name=self.project_name,
has_python=project.has_python,
has_scala=project.has_scala and not project.skip_scala,
- source_bases=source_bases.items(),
+ source_bases=source_bases_list,
pythonpaths=pythonpaths,
debug_port=project.debug_port,
)
@@ -137,9 +143,9 @@ def add_jarlibs(classpath_entries):
for classpath_entry in classpath_entries:
jar = classpath_entry.jar
source_jar = classpath_entry.source_jar
- libs.append((
- os.path.relpath(jar, self.cwd),
- os.path.relpath(source_jar, self.cwd) if source_jar else None
+ libs.append(TemplateData(
+ jar=os.path.relpath(jar, self.cwd),
+ source_jar=os.path.relpath(source_jar, self.cwd) if source_jar else None
))
add_jarlibs(project.internal_jars)
add_jarlibs(project.external_jars)
@@ -174,7 +180,7 @@ def add_jarlibs(classpath_entries):
# The easiest way to make sure eclipse sees all annotation processors is to put all libs on
# the apt factorypath - this does not seem to hurt eclipse performance in any noticeable way.
- jarpaths=libs
+ jarpaths=["('%s', %s)" % (lib.jar, "'%s'" % lib.source_jar if lib.source_jar else 'None') for lib in libs]
)
with open(self.apt_filename, 'w') as output:
Generator(pkgutil.get_data(__name__, self.apt_template),
View
2  src/python/twitter/pants/tasks/ide_gen.py
@@ -315,7 +315,7 @@ def extract_resource_extensions(resources):
_, ext = os.path.splitext(resource)
yield ext
- def __init__(self, name, has_python, skip_java, skip_scala, root_dir,
+ def __init__(self, name,has_python, skip_java, skip_scala, root_dir,
checkstyle_suppression_files, debug_port, targets, transitive):
"""Creates a new, unconfigured, Project based at root_dir and comprised of the sources visible
to the given targets."""
View
81 ...n/twitter/pants/tasks/idea/templates/module-11.mk → ...ter/pants/tasks/idea/templates/module-11.mustache
@@ -21,90 +21,91 @@ limitations under the License.
<!-- generated by pants! -->
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
- % if module.has_python:
+ {{#module.has_python}}
<facet type="Python" name="Python"/>
- % endif
+ {{/module.has_python}}
- % if module.has_scala:
+ {{#module.has_scala}}
<facet type="scala" name="Scala">
<configuration>
<option name="compilerLibraryLevel" value="Project"/>
<option name="compilerLibraryName" value="scala"/>
</configuration>
</facet>
- % endif
+ {{/module.has_scala}}
- % if module.has_bash:
+ {{#module.has_bash}}
<facet type="bash" name="BashSupport"/>
- % endif
+ {{/module.has_bash}}
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output/>
- <content url="file://${module.root_dir}">
+ <content url="file://{{module.root_dir}}">
<excludeFolder url="file://$MODULE_DIR$/external-libs" />
<excludeFolder url="file://$MODULE_DIR$/external-libsources" />
<excludeFolder url="file://$MODULE_DIR$/internal-libs" />
<excludeFolder url="file://$MODULE_DIR$/internal-libsources" />
</content>
- % for content_root in module.content_roots:
- <content url="file://${module.root_dir}/${content_root.path}">
- % for sources in content_root.sources:
- % if sources.package_prefix:
- <sourceFolder url="file://${module.root_dir}/${sources.path}"
- isTestSource="${sources.is_test}"
- packagePrefix="${sources.package_prefix}"/>
- % else:
- <sourceFolder url="file://${module.root_dir}/${sources.path}"
- isTestSource="${sources.is_test}"/>
- % endif
- % endfor
- % for exclude_path in content_root.exclude_paths:
- <excludeFolder url="file://${module.root_dir}/${exclude_path}"/>
- % endfor
+ {{#module.content_roots}}
+ <content url="file://{{module.root_dir}}/{{path}}">
+ {{#sources}}
+ {{#package_prefix}}
+ <sourceFolder url="file://{{module.root_dir}}/{{path}}"
+ isTestSource="{{is_test}}"
+ packagePrefix="{{.}}"/>
+ {{/package_prefix}}
+ {{^package_prefix}}
+ <sourceFolder url="file://{{module.root_dir}}/{{path}}"
+ isTestSource="{{is_test}}"/>
+ {{/package_prefix}}
+ {{/sources}}
+ {{#exclude_paths}}
+ <excludeFolder url="file://{{module.root_dir}}/{{.}}"/>
+ {{/exclude_paths}}
</content>
- % endfor
+ {{/module.content_roots}}
<orderEntry type="inheritedJdk"/>
<orderEntry type="sourceFolder" forTests="false"/>
- % if module.has_scala:
+ {{#module.has_scala}}
<orderEntry type="library" name="scala" level="project"/>
- % endif
+ {{/module.has_scala}}
<orderEntry type="module-library">
<library name="internal">
<CLASSES>
- % for jar in module.internal_jars:
- <root url="jar://${jar}!/" />
- % endfor
+ {{#module.internal_jars}}
+ <root url="jar://{{.}}!/" />
+ {{/module.internal_jars}}
</CLASSES>
<JAVADOC />
<SOURCES>
- % for source_jar in module.internal_source_jars:
- <root url="jar://${source_jar}!/" />
- % endfor
+ {{#module.internal_source_jars}}
+ <root url="jar://{{.}}!/" />
+ {{/module.internal_source_jars}}
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="external">
<CLASSES>
- % for jar in module.external_jars:
- <root url="jar://${jar}!/" />
- % endfor
+ {{#module.external_jars}}
+ <root url="jar://{{.}}!/" />
+ {{/module.external_jars}}
</CLASSES>
<JAVADOC />
<SOURCES>
- % for source_jar in module.external_source_jars:
- <root url="jar://${source_jar}!/" />
- % endfor
+ {{#module.external_source_jars}}
+ <root url="jar://{{.}}!/" />
+ {{/module.external_source_jars}}
</SOURCES>
</library>
</orderEntry>
</component>
-% for component in module.extra_components:
- ${component}
+{{#module.extra_components}}
+ {{{.}}}
-% endfor
+{{/module.extra_components}}
</module>
View
50 .../twitter/pants/tasks/idea/templates/project-11.mk → ...er/pants/tasks/idea/templates/project-11.mustache
@@ -24,23 +24,23 @@ limitations under the License.
<option name="DEFAULT_COMPILER" value="Javac"/>
<resourceExtensions/>
<wildcardResourcePatterns>
- % for extension in project.resource_extensions:
- <entry name="?*${extension}"/>
- % endfor
+ {{#project.resource_extensions}}
+ <entry name="?*{{.}}"/>
+ {{/project.resource_extensions}}
</wildcardResourcePatterns>
<annotationProcessing enabled="false" useClasspath="true"/>
</component>
<component name="JavacSettings">
- <option name="ADDITIONAL_OPTIONS_STRING" value="-encoding ${project.java_encoding}" />
+ <option name="ADDITIONAL_OPTIONS_STRING" value="-encoding {{project.java_encoding}}" />
</component>
<component name="ProjectModuleManager">
<modules>
- % for module in project.modules:
- <module fileurl="file://${module.path}"
- filepath="${module.path}"/>
- % endfor
+ {{#project.modules}}
+ <module fileurl="file://{{path}}"
+ filepath="{{path}}"/>
+ {{/project.modules}}
</modules>
</component>
@@ -49,58 +49,58 @@ limitations under the License.
languageLevel="JDK_1_6"
project-jdk-name="1.6"
project-jdk-type="JavaSDK">
- <output url="file://${project.outdir}"/>
+ <output url="file://{{project.outdir}}"/>
</component>
<component name="ProjectRunConfigurationManager">
- <configuration default="false" name="Debug on port ${project.debug_port}"
+ <configuration default="false" name="Debug on port {{project.debug_port}}"
type="Remote"
factoryName="Remote">
<option name="USE_SOCKET_TRANSPORT" value="true" />
<option name="SERVER_MODE" value="false" />
<option name="SHMEM_ADDRESS" value="javadebug" />
<option name="HOST" value="localhost" />
- <option name="PORT" value="${project.debug_port}" />
+ <option name="PORT" value="{{project.debug_port}}" />
<method />
</configuration>
</component>
- % if project.has_scala:
+ {{#project.has_scala}}
<component name="ScalacSettings">
- <option name="USE_FSC" value="${str(project.scala.fsc).lower()}"/>
+ <option name="USE_FSC" value="{{#project.scala.fsc}}true{{/project.scala.fsc}}{{^project.scala.fsc}}false{{/project.scala.fsc}}"/>
</component>
<component name="libraryTable">
<library name="scala">
<CLASSES>
- % for path in project.scala_compiler_classpath:
- <root url="jar://${path}!/"/>
- % endfor
+ {{#project.scala_compiler_classpath}}
+ <root url="jar://{{.}}!/"/>
+ {{/project.scala_compiler_classpath}}
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
- % endif
+ {{/project.has_scala}}
<component name="VcsDirectoryMappings">
- <mapping directory="${project.root_dir}" vcs="Git"/>
+ <mapping directory="{{project.root_dir}}" vcs="Git"/>
</component>
<component name="CheckStyle-IDEA">
<option name="configuration">
<map>
- <entry key="active-configuration" value="file://${project.root_dir}/build-support/checkstyle/coding_style.xml:Twitter CheckStyle rules." />
+ <entry key="active-configuration" value="file://{{project.root_dir}}/build-support/checkstyle/coding_style.xml:Twitter CheckStyle rules." />
<entry key="check-test-classes" value="test" />
<entry key="location-0" value="CLASSPATH:/sun_checks.xml:The default CheckStyle rules." />
- <entry key="location-1" value="file://${project.root_dir}/build-support/checkstyle/coding_style.xml:Twitter CheckStyle rules." />
- <entry key="property-1.checkstyle.suppression.files" value="${project.checkstyle_suppression_files}"/>
- <entry key="thirdparty-classpath" value="${project.checkstyle_classpath}" />
+ <entry key="location-1" value="file://{{project.root_dir}}/build-support/checkstyle/coding_style.xml:Twitter CheckStyle rules." />
+ <entry key="property-1.checkstyle.suppression.files" value="{{project.checkstyle_suppression_files}}"/>
+ <entry key="thirdparty-classpath" value="{{project.checkstyle_classpath}}" />
</map>
</option>
</component>
-% for component in project.extra_components:
- ${component}
+{{#project.extra_components}}
+ {{{.}}}
-% endfor
+{{/project.extra_components}}
</project>
View
7 src/python/twitter/pants/tasks/idea_gen.py
@@ -26,6 +26,7 @@
from twitter.pants.base.generator import TemplateData, Generator
from twitter.pants.tasks.ide_gen import IdeGen, Project
+
__author__ = 'John Sirois'
@@ -85,8 +86,8 @@ def __init__(self, context):
self.java_encoding = context.options.idea_gen_java_encoding
idea_version = _VERSIONS[context.options.idea_gen_version]
- self.project_template = os.path.join(_TEMPLATE_BASEDIR, 'project-%s.mk' % idea_version)
- self.module_template = os.path.join(_TEMPLATE_BASEDIR, 'module-%s.mk' % idea_version)
+ self.project_template = os.path.join(_TEMPLATE_BASEDIR, 'project-%s.mustache' % idea_version)
+ self.module_template = os.path.join(_TEMPLATE_BASEDIR, 'module-%s.mustache' % idea_version)
self.project_filename = os.path.join(self.cwd, '%s.ipr' % self.project_name)
self.module_filename = os.path.join(self.work_dir, '%s.iml' % self.project_name)
@@ -145,6 +146,8 @@ def create_content_root(source_set):
extra_components = [],
)
+ existing_project_components = None
+ existing_module_components = None
if not self.nomerge:
# Grab the existing components, which may include customized ones.
existing_project_components = self._parse_xml_component_elements(self.project_filename)
View
6 src/python/twitter/pants/tasks/ivy_resolve.py
@@ -80,7 +80,7 @@ def __init__(self, context):
self._profile = context.config.get('ivy-resolve', 'profile')
- self._template_path = os.path.join('ivy_resolve', 'ivy.mk')
+ self._template_path = os.path.join('ivy_resolve', 'ivy.mustache')
self._work_dir = context.config.get('ivy-resolve', 'workdir')
self._classpath_file = os.path.join(self._work_dir, 'classpath')
@@ -197,8 +197,8 @@ def _generate_ivy(self, jars, excludes, ivyxml):
safe_mkdir(os.path.dirname(ivyxml))
with open(ivyxml, 'w') as output:
generator = Generator(pkgutil.get_data(__name__, self._template_path),
- root_dir = get_buildroot(),
- lib = template_data)
+ root_dir = get_buildroot(),
+ lib = template_data)
generator.write(output)
def _generate_ivy_report(self):
View
124 src/python/twitter/pants/tasks/ivy_resolve/ivy.mk → ...thon/twitter/pants/tasks/ivy_resolve/ivy.mustache
@@ -24,10 +24,10 @@ limitations under the License.
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"
xmlns:m="http://ant.apache.org/ivy/maven">
- <info organisation="${lib.org}" module="${lib.module}"
- % if lib.version:
- revision="${lib.version}"
- % endif
+ <info organisation="{{lib.org}}" module="{{lib.module}}"
+ {{#lib.version}}
+ revision="{{lib.version}}"
+ {{/lib.version}}
/>
<configurations defaultconfmapping="default->default(compile),runtime();sources->sources;docs->@,javadoc">
@@ -39,80 +39,76 @@ limitations under the License.
<conf name="provided" description="provided by target environment"/>
</configurations>
- % if lib.publications:
+ {{#lib.has_publications}}
<publications>
<artifact conf="default" type="jar" ext="jar"/>
<artifact conf="default" type="pom" ext="pom"/>
- % if 'sources' in lib.publications:
+ {{#lib.publications.sources}}
<artifact conf="sources" type="source" m:classifier="sources" ext="jar"/>
- % endif
- % if 'docs' in lib.publications:
+ {{/lib.publications.sources}}
+ {{#lib.publications.docs}}
<artifact conf="docs" type="doc" m:classifier="javadoc" ext="jar"/>
- % endif
- % if 'changelog' in lib.publications:
+ {{/lib.publications.docs}}
+ {{#lib.publications.changelog}}
<artifact conf="changelog" type="CHANGELOG" m:classifier="CHANGELOG" ext="txt"/>
- % endif
+ {{/lib.publications.changelog}}
</publications>
- % endif
+ {{/lib.has_publications}}
- % if lib.dependencies:
+ {{#lib.has_dependencies}}
<dependencies>
- % for dependency in lib.dependencies:
- <dependency org="${dependency.org}"
- name="${dependency.module}"
- rev="${dependency.version}"
- % if dependency.force:
+ {{#lib.dependencies}}
+ <dependency org="{{org}}"
+ name="{{module}}"
+ rev="{{version}}"
+ {{#force}}
force="true"
- % endif
- conf="${dependency.configurations}"
- % if not dependency.transitive:
+ {{/force}}
+ conf="{{configurations}}"
+ {{^transitive}}
transitive="false"
- % endif
+ {{/transitive}}
>
- % if dependency.artifacts:
- % for artifact in dependency.artifacts:
+ {{#artifacts}}
<artifact
- % if artifact.name:
- name="${artifact.name}"
- % endif
- % if artifact.ext:
- ext="${artifact.ext}"
- % endif
- % if artifact.url:
- url="${artifact.url}"
- % endif
- % if artifact.type_:
- type="${artifact.type_}"
- % endif
- % if artifact.classifier:
- m:classifier="${artifact.classifier}"
- % endif
- % if artifact.conf:
- conf="${artifact.conf}"
- % endif
+ {{#name}}
+ name="{{name}}"
+ {{/name}}
+ {{#ext}}
+ ext="{{ext}}"
+ {{/ext}}
+ {{#url}}
+ url="{{url}}"
+ {{/url}}
+ {{#type_}}
+ type="{{type_}}"
+ {{/type_}}
+ {{#classifier}}
+ m:classifier="{{classifier}}"
+ {{/classifier}}
+ {{#conf}}
+ conf="{{conf}}"
+ {{/conf}}
/>
- % endfor
- % endif
- % if dependency.excludes:
- % for exclude in dependency.excludes:
- % if exclude.name:
- <exclude matcher="exactOrRegexp" org="${exclude.org}" module="${exclude.name}"/>
- % else:
- <exclude matcher="exactOrRegexp" org="${exclude.org}"/>
- % endif
- % endfor
- % endif
+ {{/artifacts}}
+ {{#excludes}}
+ {{#name}}
+ <exclude matcher="exactOrRegexp" org="{{org}}" module="{{name}}"/>
+ {{/name}}
+ {{^name}}
+ <exclude matcher="exactOrRegexp" org="{{org}}"/>
+ {{/name}}
+ {{/excludes}}
</dependency>
- % endfor
- % if lib.excludes:
- % for exclude in lib.excludes:
- % if exclude.name:
- <exclude matcher="exactOrRegexp" org="${exclude.org}" module="${exclude.name}"/>
- % else:
- <exclude matcher="exactOrRegexp" org="${exclude.org}"/>
- % endif
- % endfor
- % endif
+ {{/lib.dependencies}}
+ {{#lib.excludes}}
+ {{#name}}
+ <exclude matcher="exactOrRegexp" org="{{org}}" module="{{name}}"/>
+ {{/name}}
+ {{^name}}
+ <exclude matcher="exactOrRegexp" org="{{org}}"/>
+ {{/name}}
+ {{/lib.excludes}}
</dependencies>
- % endif
+ {{/lib.has_dependencies}}
</ivy-module>
View
16 src/python/twitter/pants/tasks/jar_publish.py
@@ -230,7 +230,7 @@ def internaldep(self, jar_dependency):
class IvyWriter(DependencyWriter):
def __init__(self, get_db):
- super(IvyWriter, self).__init__(get_db, os.path.join('ivy_resolve', 'ivy.mk'))
+ super(IvyWriter, self).__init__(get_db, os.path.join('ivy_resolve', 'ivy.mustache'))
def templateargs(self, target_jar, confs=None):
return dict(lib=target_jar.extend(
@@ -666,14 +666,14 @@ def check_result(self, cmd, result, failuremsg=None):
raise TaskError(failuremsg or '%s failed with exit code %d' % (' '.join(cmd), result))
def generate_ivysettings(self, publishedjars, publish_local=None):
- template = pkgutil.get_data(__name__, os.path.join('jar_publish', 'ivysettings.mk'))
+ template = pkgutil.get_data(__name__, os.path.join('jar_publish', 'ivysettings.mustache'))
with safe_open(os.path.join(self.outdir, 'ivysettings.xml'), 'w') as wrapper:
generator = Generator(template,
- ivysettings=self.ivysettings,
- dir=self.outdir,
- cachedir=self.cachedir,
- published=[TemplateData(org=jar.org, name=jar.name)
- for jar in publishedjars],
- publish_local=publish_local)
+ ivysettings=self.ivysettings,
+ dir=self.outdir,
+ cachedir=self.cachedir,
+ published=[TemplateData(org=jar.org, name=jar.name)
+ for jar in publishedjars],
+ publish_local=publish_local)
generator.write(wrapper)
return wrapper.name
View
22 ...on/twitter/pants/tasks/jar_publish/ivysettings.mk → ...tter/pants/tasks/jar_publish/ivysettings.mustache
@@ -25,29 +25,29 @@ limitations under the License.
<!-- generated by pants! -->
<ivysettings>
- <include file="${ivysettings}"/>
+ <include file="{{ivysettings}}"/>
<caches>
- <cache name="__pants_publish_cache__" basedir="${cachedir}" useOrigin="true"/>
+ <cache name="__pants_publish_cache__" basedir="{{cachedir}}" useOrigin="true"/>
</caches>
<resolvers>
<filesystem name="__pants_publish_repo__" local="true" cache="__pants_publish_cache__">
- <ivy pattern="${dir}/[organisation]/[module]/ivy-[revision].xml" />
- <artifact pattern="${dir}/[organisation]/[module]/[artifact]-[revision](-[classifier]).[ext]"/>
+ <ivy pattern="{{dir}}/[organisation]/[module]/ivy-[revision].xml" />
+ <artifact pattern="{{dir}}/[organisation]/[module]/[artifact]-[revision](-[classifier]).[ext]"/>
</filesystem>
- % if publish_local:
+ {{#publish_local}}
<filesystem name="publish_local" transactional="false" local="true" m2compatible="true">
- <ivy pattern="${publish_local}/[organisation]/[module]/[revision]/ivy-[revision].xml" />
- <artifact pattern="${publish_local}/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"/>
+ <ivy pattern="{{publish_local}}/[organisation]/[module]/[revision]/ivy-[revision].xml" />
+ <artifact pattern="{{publish_local}}/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"/>
</filesystem>
- % endif
+ {{/publish_local}}
</resolvers>
<modules>
- % for artifact in published:
- <module organisation="${artifact.org}" name="${artifact.name}"
+ {{#published}}
+ <module organisation="{{org}}" name="{{name}}"
resolver="__pants_publish_repo__"/>
- % endfor
+ {{/published}}
</modules>
</ivysettings>
View
36 src/python/twitter/pants/tasks/jar_publish/pom.mk → ...thon/twitter/pants/tasks/jar_publish/pom.mustache
@@ -24,31 +24,31 @@ limitations under the License.
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
- <groupId>${artifact.org}</groupId>
- <artifactId>${artifact.name}</artifactId>
+ <groupId>{{artifact.org}}</groupId>
+ <artifactId>{{artifact.name}}</artifactId>
<packaging>jar</packaging>
- <version>${artifact.rev}</version>
+ <version>{{artifact.rev}}</version>
- % if artifact.dependencies:
+ {{#artifact.has_dependencies}}
<dependencies>
- % for dependency in artifact.dependencies:
+ {{#artifact.dependencies}}
<dependency>
- <groupId>${dependency.org}</groupId>
- <artifactId>${dependency.name}</artifactId>
- <version>${dependency.rev}</version>
- <scope>${dependency.scope}</scope>
- % if dependency.excludes:
+ <groupId>{{org}}</groupId>
+ <artifactId>{{name}}</artifactId>
+ <version>{{rev}}</version>
+ <scope>{{scope}}</scope>
+ {{#has_excludes}}
<exclusions>
- % for exclude in dependency.excludes:
+ {{#excludes}}
<exclusion>
- <groupId>${exclude.org}</groupId>
- <artifactId>${exclude.name}</artifactId>
+ <groupId>{{org}}</groupId>
+ <artifactId>{{name}}</artifactId>
</exclusion>
- % endfor
+ {{/excludes}}
</exclusions>
- % endif
+ {{/has_excludes}}
</dependency>
- % endfor
+ {{/artifact.dependencies}}
</dependencies>
- % endif
-</project>
+</project>
Please sign in to comment.
Something went wrong with that request. Please try again.