Skip to content
peter50216 edited this page Apr 19, 2014 · 16 revisions

This page covers the advanced topics for Greed, like template definition, hidden config keys, custom renderers.

A word for the configuration format

Greed uses a 3rd-party config library typesafe-config. It's a very powerful config library with a flexible DSL for the users. For advanced config file writing, refer to its documentation and the default.conf in Greed.

Miscellaneous configurations

Each of Greed's configuration key corresponds to a class in the source file, which is kind of like ORM mapping, and is a new feature in the backend of 2.0. I'll point to the class in each of the following section for you to better understand the configuration semantics.

Logging

Class: greed.conf.schema.LoggingConfig

Greed has a mechanism for logging, which is turned off by default.

You can turn it on by setting greed.logging.logLevel = INFO and it will log to the Logs directory under your workspace by default. You can also see the logs from the java console, when the arena starts. The way to enable the console is through java control panel, usually. Java Web Start Console Setting

Template definition

Class: greed.conf.schema.TemplateConfig

Greed gives the users power to define their own templates, according to the following schema. Let's continue with the templateDef config key and start with an example.

greed.language.java.templateDef {
  unittest {
    overwrite = skip
    templateFile = builtin(unittest/junit.java.tmpl)
    outputKey = UnitTestCode
    outputFile = "${Contest.Name}/${Problem.Name}-WrongName"
    transformers = [ empty-block, cont-blank-line ]
    dependencies = [ key(a) | testcode ]

    afterFileGen {
      execute = mv
      arguments = [ "${GeneratedFileName}", "${Contest.Name}/${Problem.Name}Test.java" ]
      timeout = 3
    }
    options {
      key = value
    }
  }
}

This example may look somewhat stupid, because it gives the output a wrong name and then rename it. But it covers all the possible keys of a template def.

  • overwrite, available options are force, backup, skip.

    • These options are only useful when the file already exists and is different with the current output.
    • If set to skip, Greed will skip the file if already exists.
    • If set to backup, the file will be backed-up before overwriting.
    • If set to force, the file will be overwritten directly.
    • However, if user click Regenerate code in the UI, skip will upgrade to backup to ease the testing of custom template.
  • templateFile specify the path to the template file use by the template engine to render to the output.
    If the path is surrounded by builtin(), this template is located in the distributed jar of Greed, in greed.jar:/templates.

  • If outputKey is set, the rendered output will be bound to a key, in this case UnitTestCode, and available for the later templates (in the templates sequence) to use as a key in their template files. Note this does not conflict with outputFile.

  • outputFile and [ outputFileName, outputFileExtension ] conflict with each other and must not be set at the same time! Or Greed will raise an error of config exception. The former set the whole name while the latter specify the two parts of the file name separately.

  • transformers specify a list of actions to transform the code after the code is generated. Right now there're only two available.

    • empty-block removes empty cutting block (surrounded by cutBegin and cutEnd) to cleanup the output code.
    • cont-blank-line merges continuous blank lines to single one blank line.
  • dependencies, see below.

  • afterFileGen, see below.

  • options, see below.

Template dependencies

Class: greed.conf.schema.TemplateDependencyConfig

Template dependencies is an array of dependency items, which forms AND relations, meaning these dependencies must be all satisfied. Each dependency item can be several dependency def concatenated with |, forming OR relations. In summary, dependencies definition is a CNF expression.

There're two types of invidivdual dependency def:

  • key(xxx): Requires the key must be available before this template is generated
  • tmpl-name: Declares a direct dependency to template tmpl-name, which requires tmpl-name must be generated first

It's possible the dependencies cannot infer a possible generating order (cyclic graph!), then greed will report an error.

Template after generation action

Class: greed.conf.schema.CommandConfig

afterFileGen defines an external command executed after the file is generated (no output file, no action!). You can specify any scripts or programs to run. The timeout, whose unit is seconds, if set, the program will be killed unless it ends before the timeout. If not set, it's implicit no timeout, meaning the program will not be killed.

There're a lot of cool usage of this feature, like open the problem statement in the browser, or open the source code directly in editor.

Template options

Template options is a raw map from string to string which is options that are specific to the template. Raw means if will not be OR-mapped. This enables tweaking template through configurations and without copying and modify the template file.

The values inside this section are of the format: key = value. Inside the template, you call them as ${key} to insert custom text or in an if condition like: ${if Options.key} which would be false if the option key does not exist or is set to the string false.

Many of the templates included by default come with template options which will be described in the next section.

Variables and model

You have seen a lot of ${key} in the config, this data will be substituted and rendered by the template engine (or the config library, and they're different). To see which keys are available, read the section about key-values in the next tutorial.

Template file and engine

This part is basically the details of the template engine, and is covered separately in another page Play with templates.

If you're interested in customizing your own template, go ahead!

Template options for provided templates

problem-desc options

The problem-desc template is the template used for the problem statement. It has the following options:

Option key Available values Default Description
theme light, dark, blue, low-contrast light A color theme for the HTML.
gridArrays false, true false If true, Show String[] argument values in examples using multiple lines and making them look like a grid when possible.
showDefinition false, java, cpp, python, csharp (same as current language) Show problem definition section (arguments, signature) using the specified language. false hides the section.
favIcon URL or path to an image or false topcoder's favicon The favicon icon for the tab in web browser, use false to hide it.
customStyle false, path to .css file false (advanced) If false it does nothing. Else the problem statement HTML will include the specified .css file.
noDefaultStyle false, true false (advanced) If true no style will be included, only the file specified by customStyle will be included.

For example, try the following:

greed.shared.templateDef.problem-desc {
    options {
        theme = darkgray
        gridArrays = true
    }
}

As a result, the problem statement for problem TBlocks will change from this: default-TBlocks.html to this: darkgray-grid-TBlocks.html

filetest options

option allowed values default Description
runMultipleProcesses false, true false If true, c++ tester will run each test case in a different process. Allows it to detect runtime errors and to have a clean global state in each execution.

test options

option allowed values default Description
runMultipleProcesses false, true false If true, c++ tester will run each test case in a different process. Allows it to detect runtime errors and to have a clean global state in each execution.
cpp11 false, true false If true, c++ tester will use some new c++11 for saving the test cases in the file, for example initializer syntax to initialize std::vector arguments..

dualcolor-test options

Detailed in its readme.md