<commit_before>Configure your application
==========================

Introduction to application.conf
--------------------------------

By convention Ninja will look for a configuration file at "conf/application.conf".

application.conf is a simple properties file with keys and values. "#" is a comment.

    # an arbitrary content
    application.name=Ninja demo application
    application.cookie.prefix=NINJA

Like any other Ninja file it is encoded in Utf-8. Make sure your editor reads and
saves the file in the correct encoding. 

Ninja properties can do much more than traditional Java properties. For instance
it is possible to reference other properties by their name and combine them.

    serverName=http://myserver.com
    serverPort=80
    fullServerName=${serverName}:${serverPort}
    
fullServerName references the previously set values of the keys and will return "http://myserver.com:80".

Inside your application you can use class NinjaProperties to get the properties.

    NinjaProperties.get("fullServerName")            # will return "http://myserver.com:80"

The properties are read and managed by the excellent Apache Configurations library. Please
refer to [their manual](http://commons.apache.org/configuration/) for even more information on advanced usage.


Configuring the modes
---------------------
Ninja uses three predefined modes (test, dev, prod as defined in NinjaConstant.java). You can set the
modes by setting a Java system property called "ninja.mode".

    On the command line:
    > java -Dninja.mode=dev
    
    Or programmatically:
    System.setProperty(NinjaConstant.MODE_KEY, NinjaConstant.MODE_DEV)

Just make sure that you set the system property early so that Ninja knows its mode from the very beginning.


This modes are handy if you want to define different properties for different environments.
You may want to use database1 when running tests and database2 when developing.

Ninja supports that use case by using a mode prefix prior to your property key.

    database.name=database_production   # will be used when no mode is set (or prod)
    %dev.database.name=database_test    # will be used when running in dev mode
    %test.database.name=database_test   # will be used when running in test mode

The convention is to use a "%" and the name of the mode followed by ".".


External configuration for deployment
-------------------------------------

When running on a server you may want to use a completely different configuration.
This can be accomplished by using the setting a Java system property:

    java -Dninja.external.configuration=production.conf
<commit_msg>Improved doc.<commit_after>Configure your application
==========================

Introduction to application.conf
--------------------------------

By convention Ninja will look for a configuration file at "conf/application.conf".

application.conf is a simple properties file with keys and values. "#" is a comment.

<pre class="prettyprint">
    # an arbitrary content
    application.name=Ninja demo application
    application.cookie.prefix=NINJA
</pre>

Like any other Ninja file it is encoded in Utf-8. Make sure your editor reads and
saves the file in the correct encoding. 

Ninja properties can do much more than traditional Java properties. For instance
it is possible to reference other properties by their name and combine them.

<pre class="prettyprint">
    serverName=myserver.com
    serverPort=80
    fullServerName=${serverName}:${serverPort}
</pre>
    
fullServerName references the previously set values of the keys and will return myserver.com:80.

Inside your application there are two ways to get the properties. 

First way is to use NinjaProperties.get(...). You have to inject NinjaProperties first, then you
can use all sorts of functions to retrieve properties.

<pre class="prettyprint">
    @Inject 
    NinjaProperties ninjaProperties;
    
    public void myMethod() {
        String value = ninjaProperties.get("fullServerName")
        ... do even more...
    }
</pre>

The second way to get properties is to inject them via @Named("fullServerName").

<pre class="prettyprint">
    /** An arbitrary constructor */
    @Inject
    ApplicataionController(@Named("fullServerName") String fullServerName) {
        ... do something ...
    }
</pre>

The properties are read and managed by the excellent Apache Configurations library. Please
refer to [their manual](http://commons.apache.org/configuration/) for even more information on advanced usage.


Configuring the modes
---------------------
Ninja uses three predefined modes (test, dev and prod as defined in NinjaConstant.java). You can set the
modes by setting a Java system property called "ninja.mode".

<pre class="prettyprint">
    On the command line:
    > java -Dninja.mode=dev
    
    Or programmatically:
    System.setProperty(NinjaConstant.MODE_KEY, NinjaConstant.MODE_DEV)
</pre>

Just make sure that you set the system property early so that Ninja knows its mode from the very beginning.


This modes are handy if you want to define different properties for different environments.
You may want to use database1 when running tests and database2 when developing.

Ninja supports that use case by using a mode prefix prior to your property key.

<pre class="prettyprint">
    database.name=database_production   # will be used when no mode is set (or prod)
    %dev.database.name=database_test    # will be used when running in dev mode
    %test.database.name=database_test   # will be used when running in test mode
</pre>

The convention is to use a "%" and the name of the mode followed by ".".


External configuration for deployment
-------------------------------------

When running on a server you may want to use a completely different configuration.
This can be accomplished by using the setting a Java system property:

<pre class="prettyprint">
    java -Dninja.external.configuration=production.conf
</pre>

{'fraction_non_alphanumeric': 0.09746686797517196, 'fraction_numerical': 0.00268411340379131, 'mean_word_length': 3.4525765496639282, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6648937', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1438, 'n_words': 706}