Play with laFabrique's samples
First of all, make sure that you have correctly installed a JDK version 1.7 or above. To check, please type :
>javac -version javac version "1.7.0_02"
As laFabrique compiles code, a JDK is mandatory. If it is not the case edit your system path, like "export PATH=/usr/java/jdk1.7.0_02/bin:$PATH" for Linux or "set PATH=c:\Program Files\Java\jdk1.7.0_02\bin;%PATH%" for Windows.
Run the samples
Go inside the download page to get "laFabSample.zip". When you have it, Unzip it in any directory, now it is ready to be used. Samples can be executed with laFabrique command lines. To see all the available samples, type the following command :
>sample help
> ------------------------------------------------------------------------------- @@ @@@@@@ @@ @@@@ @@ @@ @@@@@@ @@ @@@@@ @@ @@ @@@@ @@ .@@@@ @@@@@ @@ @@@@@ @@@@@ @@ @@ @@ @@ @@@ @@ @@@@@ @@@@@ .@.@@@ @@@@@@ .@@@ @@.@@@ @@@@@@@@@ @@@@@@ @@ @@@@@ @@ @@ @@@@@ @@ @@ @@ @@@@@ @@ @@ @@@ @@ @@ @@ @@ @@ @ @@ @@@@@ @@ @@@@@@ @@ @@ @@@ @@@@@@ @@ .@ @@ @@ @@ @@ @@@@@@. @@ @@ @@ @@ @@ @@ @@ @@ @ @@ @@ @@ @@ .@ @@ @@ @@ @@ @@ @@ @@@@@@ @@ @@@@@@ @@@@@@ @@@@@@ @@@@@@ @@ .@ @@ @@@@@@ @@ @@@@@ @@ @@ @@ @@ @@ @@ @@ @@ @@@ @@ @@ @@ .@ @@ @@ @@ @@ @@@ @@ @@ ------------------------------------------------------------------------------- Version : 0.0.1 by CapCaval.org About: It shows a sample of application with several type of commands. ------------------------------------------------------------------------------- Properties : -> String name : Keep persitent the greeted name. Commands : => addMulti : add an array of number int[] numberArray : Array of number to multiply. => getCountryOfCity : Get the country of a bug city. Ex of use: ./laFabS ample City.London City city : Enum value of City => multiply : multiply several numbers int[] numberArray : Array of number => add : add two number int firstNumber : First Number int secondNumber : Secondnumber Number => greet : Keep persitent and Greet the given name String name : Name to be greeted
This is an exemple of what a laFabrique application is. To use it, you have the choice of several commands. For instance you can perform an addition with the following command :
>./Sample add 1 2
> 3
As you can see below, the sample source code stands in one file, you can notice as well that the 5 commands are quite simple. This file is available inside at : "laFaSample/01_src/sample/Sample.java". The quantity of technical line of code is low as to 2 inside the main method and some annotations, all the rest is only made of domain source code.
package sample; import org.capcaval.lafabrique.application.ApplicationTools; import org.capcaval.lafabrique.application.annotations.AppInformation; import org.capcaval.lafabrique.application.annotations.AppProperty; import org.capcaval.lafabrique.commandline.Command; import org.capcaval.lafabrique.commandline.CommandParam; import org.capcaval.lafabrique.common.CommandResult; @AppInformation ( about= {"It shows a sample of application with several type of commands."}) public class Sample{ public enum Country{ France, GreatBritain, USA}; public enum City{ Paris, London, NewYork}; @AppProperty(comment = "Keep persitent the greeted name.", persistence = true) private String name; public static void main(String[] args) { CommandResult r = ApplicationTools.runApplication(Sample.class, args); System.out.println(r.toString()); } // laFab convert the parameter and also the return value // it does handle primitive and basic classes. @Command(desc="add two number") public Integer add( @CommandParam(name="firstNumber", desc="First Number") int a, @CommandParam(name="secondNumber", desc="Secondnumber Number") int b){ return a+b; } // laFab does also handle multiple parameters @Command(desc="multiply several numbers") public int multiply( @CommandParam(name="numberArray", desc="Array of number") int... numberArray){ // beware to initialize with 1 and not zero // otherwise the result shall always be zero. int returnedValue = 1; for(int val : numberArray){ returnedValue = returnedValue * val; } return returnedValue; } // laFab does also handle array @Command(desc="add an array of number") public Integer addMulti( @CommandParam(name="numberArray", desc="Array of number to multiply.") int[] numberArray){ int returnedValue = 0; for(int val : numberArray){ returnedValue = returnedValue + val; } return returnedValue; } // laFab does also handle enum. @Command(desc="Get the country of a bug city. Ex of use: ./laFabSample City.London") public Country getCountryOfCity( @CommandParam(name="city", desc="Enum value of City") City city){ Country country = Country.France; if(city == City.London){ country = Country.GreatBritain; } else if(city == City.NewYork){ country = Country.USA; } return country; } // laFab provides the use of properties @Command(desc="Keep persitent and Greet the given name") public String greet( @CommandParam(name="name", desc="Name to be greeted") String name){ this.name = name; return "Hello " + this.name + "!"; } // laFab provides the use of persistent properties @Command(desc="Greet with the last persitent name") public String greet(){ return "Hello " + this.name + "!"; } }
Modify the sample
The sample is ready to be modify with any text editor. As the building tools is included inside laFabrique, all you need to do next is to use the build command, this way :
>./laFab build
The build command follows the project description inside the file "00_prj/prj/laFabSample.java". See below its content.
package prj; import org.capcaval.lafabrique.project.Project; public class laFabSample extends Project{ @Override public void defineProject(){ name("laFabSample"); version("0.0.1"); author("CapCaval.org"); url("http://capcaval.org"); lib("laFabrique.jar"); script.add("Sample", "sample.Sample"); pack.name("laFabSample.zip"); pack.source(true); pack.bin(true); pack.proj(true); } }
Play inside Eclipse IDE
The project can be used inside eclipse. To do so just launch the following command :
>./laFab updateEclipseProject
[laFabrique] INFO : Default project is : laFabSample [laFabrique] INFO : Update Eclipse project named laFabSample [laFabrique] INFO : Eclipse project updated successfully.