<commit_before>---
layout: getting-started
title: Getting Started
permalink: /getting-started/
---

### Getting source and building ###

Soon you'll be able to grab builds from our CI server or Maven Central.
But for now you'll want to build yourself (which is pretty easy).

Get the source, both for the JUniversal translator and JSimple libraries:

    git clone https://github.com/juniversal/juniversal.git
    git clone https://github.com/juniversal/jsimple.git

Build the translator.   The `gradlew` Gradle wrapper downloads Gradle automatically---no need to install any build tools.
However, note that the translator uses Java 8.  So you'll have to install Java 8, if you don't already have it, and use for
running Gradle everywhere below.

    cd juniversal
    ./gradlew build install        [Linux/Mac/Cygwin]
    gradlew build install          [Windows]

`install` above means to copy the built stuff to your local Maven repository directory (`<home directory>/.m2` by default), where subsequent build steps will find it.

Next build the Gradle plugins:

    cd juniversal/build-tool-plugins/juniversal-gradle-plugins
    ./gradlew build install        [Linux/Mac/Cygwin]
    gradlew build install          [Windows]

Build the JSimple Java libraries and translate them to C#:

    cd jsimple
    ./gradlew build build install javaToCSharp   [Linux/Mac/Cygwin]
    gradlew build install javaToCSharp           [Windows]

Optionally, you can build all the JSimple C# projects by opening `jsimple/c#/jsimple.sln` in Visual Studio.
But you can also build them by just pointing directly, from your app's own Visual Studio file, to the JSimple modules you use.

### Our running example  ###

As a running example, say you're working on Acme Corp's spiffy new mobile app.  You've got an MVC design & figure the acme-model.jar model component (which may include persistent state, business logic, and client/server comms) is a good one to try make cross platform with JUniversal.

You probably start with a directory layout like:

    acme-app/acme-model/src/main/java                   [Java source]
    acme-app/acme-model/src/test/java                   [Java JUnit tests source]

Maven directory conventions are used in this example, but that's not required or anything.

### Running the translators on your code--Gradle plugins ###

The easiest way to run the translators is with our Gradle plugins.   Add the following to `acme-model`'s `build.gradle` file to JUniversal-enable it:

	buildscript {
	    repositories {
	        mavenLocal()
	    }

	    dependencies {
	        classpath group: 'org.juniversal', name: 'juniversal-gradle-plugins', version: '0.8-SNAPSHOT'
	    }
	}

    apply plugin: 'javaToCSharp'

	javaToCSharp {
	}

`mavenLocal()` above means to look in the local Maven repository directory, which is where the JUniversal stuff was copied when built above.

To invoke the translator then run:

    gradle javaToCSharp

It will translate the main and (if present) test source.   JUnit tests are changed to NUnit in C# (see below).

To also translate to Objective-C, include this in your `build.gradle` file:

    apply plugin: 'javaToObjectiveC'

    javaToObjectiveC {
    }

Download j2objc from http://github.com/google/j2objc/releases and set the `J2OBJC_HOME` environement variable to point to the j2objc distro, so our Gradle plugin can find it.   Then run `gradle javaToObjectiveC` to translate to objective C via `j2objc`.

For fun, you can even translate to C++ if you want to see the current state of our work in progress C++ translator:

    apply plugin: 'javaToCPlusPlus'

    javaToCPlusPlus {
    }

Run `gradle javaToCPlusPlus` to do the translation.   You'll see a lot of C++ code get generated, but it's only partially baked at this point, so don't expect it to work.

We'll write up more later about using j2objc and JUniversal, but the rest of this doc will just cover C#.

### Running the translators on your code--command line ###

To run the translator directly, do 

    java -jar juniversal/juniversal-translator/build/libs juniversal-translator-0.8-SNAPSHOT.jar -o <output-directory> -l <target-language> [-classpath <classpath>] [-sourcepath <sourcepath>] <java-project-directories-to-translate>...

For example, to transate the main acme-model source:

    java -jar juniversal/juniversal-translator/build/libs juniversal-translator-0.8-SNAPSHOT.jar -o acme-app/acme-model/c# -l c# -classpath jsimple/jsimple-util/build/libs/jsimple-util-0.8-SNAPSHOT.jar acme-app/acme-model/src/main/java

And the test source:

    java -jar juniversal/juniversal-translator/build/libs juniversal-translator-0.8-SNAPSHOT.jar -o acme-app/acme-model/c# -l c# -classpath jsimple/jsimple-util/build/libs/jsimple-util-0.8-SNAPSHOT.jar -sourcepath acme-app/acme-model/src/main/java  acme-app/acme-model/src/test/java

### Fixing up your code to be translator friendly ###

It's important to understand that the translator just handles the Java language proper along with a few core runtime primitives integrated with the language, like String and StringBuilder.

For library calls, you'll want to switch them to JSimple libraries or potentially something else of your choosing.  So don't use java.util.HashMap; use jsimple.util.HashMap instead (which is pretty much the same, based on Apache Harmony, so normally an easy switch).   See the JSimple Javadoc for more info on what's all included.<commit_msg>Updated getting started doc since jsimple libraries are now in the libraries directory<commit_after>---
layout: getting-started
title: Getting Started
permalink: /getting-started/
---

### Getting source and building ###

Soon you'll be able to grab builds from our CI server or Maven Central.
But for now you'll want to build yourself (which is pretty easy).

Get the source, both for the JUniversal translator and JSimple libraries:

    git clone https://github.com/juniversal/juniversal.git
    git clone https://github.com/juniversal/jsimple.git

Build the translator.   The `gradlew` Gradle wrapper downloads Gradle automatically---no need to install any build tools.
However, note that the translator uses Java 8.  So you'll have to install Java 8, if you don't already have it, and use for
running Gradle everywhere below.

    cd juniversal
    ./gradlew build install        [Linux/Mac/Cygwin]
    gradlew build install          [Windows]

`install` above means to copy the built stuff to your local Maven repository directory (`<home directory>/.m2` by default), where subsequent build steps will find it.

Next build the Gradle plugins:

    cd juniversal/build-tool-plugins/juniversal-gradle-plugins
    ./gradlew build install        [Linux/Mac/Cygwin]
    gradlew build install          [Windows]

Build the JSimple Java libraries and translate them to C#:

    cd jsimple
    ./gradlew build build install javaToCSharp   [Linux/Mac/Cygwin]
    gradlew build install javaToCSharp           [Windows]

Optionally, you can build all the JSimple C# projects by opening `jsimple/c#/jsimple.sln` in Visual Studio.
But you can also build them by just pointing directly, from your app's own Visual Studio file, to the JSimple modules you use.

### Our running example  ###

As a running example, say you're working on Acme Corp's spiffy new mobile app.  You've got an MVC design & figure the acme-model.jar model component (which may include persistent state, business logic, and client/server comms) is a good one to try make cross platform with JUniversal.

You probably start with a directory layout like:

    acme-app/acme-model/src/main/java                   [Java source]
    acme-app/acme-model/src/test/java                   [Java JUnit tests source]

Maven directory conventions are used in this example, but that's not required or anything.

### Running the translators on your code--Gradle plugins ###

The easiest way to run the translators is with our Gradle plugins.   Add the following to `acme-model`'s `build.gradle` file to JUniversal-enable it:

	buildscript {
	    repositories {
	        mavenLocal()
	    }

	    dependencies {
	        classpath group: 'org.juniversal', name: 'juniversal-gradle-plugins', version: '0.8-SNAPSHOT'
	    }
	}

    apply plugin: 'javaToCSharp'

	javaToCSharp {
	}

`mavenLocal()` above means to look in the local Maven repository directory, which is where the JUniversal stuff was copied when built above.

To invoke the translator then run:

    gradle javaToCSharp

It will translate the main and (if present) test source.   JUnit tests are changed to NUnit in C# (see below).

To also translate to Objective-C, include this in your `build.gradle` file:

    apply plugin: 'javaToObjectiveC'

    javaToObjectiveC {
    }

Download j2objc from http://github.com/google/j2objc/releases and set the `J2OBJC_HOME` environement variable to point to the j2objc distro, so our Gradle plugin can find it.   Then run `gradle javaToObjectiveC` to translate to objective C via `j2objc`.

For fun, you can even translate to C++ if you want to see the current state of our work in progress C++ translator:

    apply plugin: 'javaToCPlusPlus'

    javaToCPlusPlus {
    }

Run `gradle javaToCPlusPlus` to do the translation.   You'll see a lot of C++ code get generated, but it's only partially baked at this point, so don't expect it to work.

We'll write up more later about using j2objc and JUniversal, but the rest of this doc will just cover C#.

### Running the translators on your code--command line ###

To run the translator directly, do 

    java -jar juniversal/juniversal-translator/build/libs juniversal-translator-0.8-SNAPSHOT.jar -o <output-directory> -l <target-language> [-classpath <classpath>] [-sourcepath <sourcepath>] <java-project-directories-to-translate>...

For example, to transate the main acme-model source:

    java -jar juniversal/juniversal-translator/build/libs juniversal-translator-0.8-SNAPSHOT.jar -o acme-app/acme-model/c# -l c# -classpath jsimple/libraries/jsimple-util/build/libs/jsimple-util-0.8-SNAPSHOT.jar acme-app/acme-model/src/main/java

And the test source:

    java -jar juniversal/juniversal-translator/build/libs juniversal-translator-0.8-SNAPSHOT.jar -o acme-app/acme-model/c# -l c# -classpath jsimple/libraries/jsimple-util/build/libs/jsimple-util-0.8-SNAPSHOT.jar -sourcepath acme-app/acme-model/src/main/java  acme-app/acme-model/src/test/java

### Fixing up your code to be translator friendly ###

It's important to understand that the translator just handles the Java language proper along with a few core runtime primitives integrated with the language, like String and StringBuilder.

For library calls, you'll want to switch them to JSimple libraries or potentially something else of your choosing.  So don't use java.util.HashMap; use jsimple.util.HashMap instead (which is pretty much the same, based on Apache Harmony, so normally an easy switch).   See the JSimple Javadoc for more info on what's all included.
{'fraction_non_alphanumeric': 0.0771264472604613, 'fraction_numerical': 0.0038289725590299937, 'mean_word_length': 3.654221467967756, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '628190', 'n_tokens_mistral': 3331, 'n_tokens_neox': 3088, 'n_words': 1325}