Step 3 - First steps with Z2 on Git » History » Version 19

Udo Offermann, 11.09.2012 15:43

1 1 Udo Offermann
h1. First steps with z2 v2.1
3 2 Udo Offermann
[[How_to_install_z2_v21|prev]] :: [[Z2_v21|home]]
4 1 Udo Offermann
5 4 Udo Offermann
h2. Prerequisites
You need a cloned z2-base.core repository as described on the [[How_to_install_z2_v21|previous]] page.
8 13 Udo Offermann
Furthermore you need the "Eclipse-IDE": (one of Galileo, Helios, Indigo or Juno is fine) and the "Egit plug-in:": 
9 4 Udo Offermann
10 1 Udo Offermann
h2. First steps with the z2-environment
12 4 Udo Offermann
As the next step you will learn how to do the first development steps using Eclipse. Please stop the server before you continue because we will now show you how to start it from inside the Eclipse IDE.
13 3 Udo Offermann
14 4 Udo Offermann
We recommend to keep the repositories and workspace close together. So please go back to the "z2-base" directory (@cd ../../..@, if you are still inside the "run/bin" directory) and create a folder called "workspace" - this will be used as the workspace root for Eclipse:
15 3 Udo Offermann
17 6 Udo Offermann
:bin$ cd ../../..
:z2-base$ mkdir workspace
:z2-base$ ls -l
total 0
0 drwxr-xr-x   2 mr_x  staff   68  7 Sep 16:34 workspace
0 drwxr-xr-x  12 mr_x  staff  408  7 Sep 15:11 z2-base.core
24 1 Udo Offermann
Now start Eclipse and choose @.../z2-base/workspace@ as your workspace folder.
We have to add the core repository to the EGit repositories view. Detailed documentation of how-to work with EGit can be found on the "EGit Wiki pages":
29 6 Udo Offermann
On the Git perspective choose "Add an existing local Git repository". In the "Directory" field type in the path to the ".../z2-base" directory. 
30 1 Udo Offermann
After hitting "search" the search results should list the _z2-base.core_ repository, click "finish" and the repositories view should look like this:
31 4 Udo Offermann
> !EGit_repo_view_with_z2-core.png!
34 6 Udo Offermann
Now import the core project from the repository. Right-click the repository, choose "Import projects..." from the context menu and click "next" and then "finish". 
On the Java perspective the "core" project should be now available in the package explorer:
> !z2_core_project_in_package_explorer.png!
38 3 Udo Offermann
39 7 Udo Offermann
The core project contains two launch entries, one for Linux/Mac OS and one for Windows. Right click the one that fits to your OS and choose "Run As >" and "z2_base".
This starts the z2-environment again and opens the z2-gui inside a new window labled "Z2 Home (z2-base v2.1)":
42 8 Udo Offermann
> !z2_gui.png!
43 7 Udo Offermann
44 12 Udo Offermann
From now on you will find the z2-base launch entries in Eclipse "External Tools" (either inside "Run", "External Tools >" or click the "External Tools" button in the toolbar). 
46 9 Udo Offermann
The z2-environment provides an Eclipse plug-in called "Eclipsoid" that enables convenient development of z2 applications. 
Developing modular software requires that the IDE can resolve the dependencies between single projects. 
Either you import all projects into your workspace or you live with the red x-markers indicating that Eclipse cannot compile the Java sources properly. 
The third option is that someone else resolves the dependencies for you - this is what the Eclipsoid does. This way you can checkout and focus on a project subsets while
the Eclipsoid plug-in provides the transitive closure of all required prjects and libraries. 
There are other features provided by the Eclipsoid plug-in that are explained in more details on the [[Eclipsoid]] wiki pages.
52 3 Udo Offermann
h2. Installation of the Eclipsoid plug-in
55 9 Udo Offermann
The z2-environment that you just started contains the update-site for the Eclipsoid plug-in. Open the software update/installation wizard (in Indigo it's located at "Help/Install New Software...") 
and use http://localhost:8080/eclipsoid/update as update-site URL (the field labled "Work with"):
57 3 Udo Offermann
58 9 Udo Offermann
> !Install_Eclipsoid.png!
59 3 Udo Offermann
60 11 Udo Offermann
Please note that the Eclipsoid version will be different because the screenshots are made with an intermediate version of the plug-in.
61 3 Udo Offermann
Complete the installation wizard (you can speed up the installation procedure by deselecting "Contact all update sites during install...") and restart Eclipse. 
Now you should see a new menu entry labled "z2-Environment" and two new icons:
64 14 Udo Offermann
> !Eclipsoid_menu_entries_and_icons.png!
65 13 Udo Offermann
h2. Changing source code and check the result
To change source code, we need an open project in Eclipse. We're going to change the hello-world web application which remains in the samples repository. 
This requires to a) make the Git repository available in EGit, b) import the project into Eclipse and c) change the project and check the result.
The Eclipsoid plug-in simplifies these steps. Since the z2-environment knows the repository landscape, we can ask it to share this knowledge with us. In the new "z2-environment" menu choose the entry labled "z2-Repositories view".
72 1 Udo Offermann
This will open a view like this:
73 14 Udo Offermann
> !z2-Repositories-view.png!
This view lists all repositories known by this system. The Eclipsoid plug-in connects by default to the Eclpsoid web application on http://localhost:8080 which provides a lot of online information about the server. The connection can be customized on the "z2-environment" preference page.
77 16 Udo Offermann
You can see that there are two repositories listed; one called _com.zfabrik.boot.config/systemRepository_ containing the z2 foundation services and one called _environment/samplesRepository_ containing some sample applications including the hellow world web applciation.
78 14 Udo Offermann
Now right-click on the samples repository and choose "Clone Git repository" from the context menu. This will create a clone from next to the core repository inside your z2-base directory. You can check this out by double clicking on the samples repository - please note that the entry now looks like a hypelink with blue text color. Switch back to the java perspective and unfold the "environment/sampleRepository" node and further its "z2-projects" child. Now you will see all projects which are stored inside this repository. Right-click the "com.zfabrik.samples.helloworld" project and choose "Import Project" from the context menu. This does the same as the import project action of the Git repositories perspective, but you don't have to switch the perspectives.
81 17 Udo Offermann
Once the project is imported go to the Java Package Explorer view and drill down to +com.zfabrik.samples.helloworld / java/src.impl / com.zfabrik.samples.helloworld /, open the the class via double click. The result should look like this:
82 14 Udo Offermann
83 15 Udo Offermann
> !HelloWorldServlet_class.png!
84 1 Udo Offermann
85 16 Udo Offermann
You'll see the source code and a lot of red x-markers telling you that Eclipse cannot resolve certain identifiers. If you want you can check the classpath of the Hello World project and indeed there are only three entries: one for the JRE, one for the sources and one called "Eclipsoid: z2-Environment Build Container". This container will resolve the incomplete classpath when it is asked to do so. You can either select the entry "Resolve z2-Project classpaths", click the new icon !z2_resolve_icon.png! or simply hit <Alt+R>. Now all red x-markers should be gone. 
Now we want to change the code; you can change whatever you like, e.g. replace "Hello World!" by "Hello Earth!" and save it. To make this change available, we have to tell the server two things: 1. That it should check for changed sources and 2. that it should - beside all conencted Git repositories - consider our local version as well. From z2 point of view the Eclipse worksapce is a repository as well - it's called the _dev-repository_ because it contains the newest developed stuff. When we ask the z2 server to check for new changes (that's called to _synchronize_ the server), it will find two versions of the hello world project: one inside _environment/samplesRepository_ and one inside the _dev-repository_ which is your Eclipse workspace. So which one should it take? To solve this "conflict" the _dev-repository_ has a switch for each project which can be "armed" and "disarmed". If it's "disarmed" - which is the default - the version in the Git repository will win. If it's "armed" our version in the workspace will win. So we need to "arm" the Hello World project: Right-click the project "com.zfabrik.samples.helloworld" in the Java Package Explorer and choose "Arm z2-Projects":
> !Howto_arm_z2-projects.png!
91 1 Udo Offermann
You will notice that there will be now a green "z" decoration at the upper left edge of the Java icon in the package explorer: !green_z_decoration.png!.
92 17 Udo Offermann
After we specified that the workspace version of the Hello World project should win over the one in the Git repository we can trigger the z2 syncronization: Choose "Sync with z2-environment" from the "z2-environment" menu, click the new z-icon !z2_sync.png! or simply hit <Alt+Y>. You can also switch to the z2-gui and click the "Sync" button. As described before the Eclipsoid plug-in talks to the z2 server via http. In situations where the web server cannot be started, the Eclipsoid web applicaton will not be available. In this case the z2-gui is the only way to trigger a synchronization (except of shutdown/restart). You will also see that the log-messages in the z2-gui log pane has changed and that the server has invalidated and restarted one resource:
93 1 Udo Offermann
94 17 Udo Offermann
09/11 15:34:54 [34]...entRepositoryImpl[800]: Pulled deltas from GitCR environment/samplesRepository (origin=, branch=v2.1, OPTIONAL)  within 56msec
09/11 15:34:54 [34]...entRepositoryImpl[800]: Pulled deltas from GitCR com.zfabrik.boot.config/systemRepository (origin=, branch=v2.1)  within 29msec
09/11 15:34:54 [34]...hronizationRunner[800]: Found 1 invalidation candidate resources
09/11 15:34:54 [34]...hronizationRunner[800]: Invalidated 0 resources
09/11 15:34:54 [31]...ent/webWorker@0.2[800]: 09/11 15:34:54 [19]...stemStateResource[800]: Left system state: environment/webWorkerUp
09/11 15:34:54 [31]...ent/webWorker@0.2[800]: 09/11 15:34:54 [19]...pp.WebAppResource[800]: Stopping Web App (/helloworld): com.zfabrik.samples.helloworld/web
09/11 15:34:54 [31]...ent/webWorker@0.2[800]: 09/11 15:34:54 [19]...worker.WorkerSoul[800]: Invalidated 1 resources
09/11 15:34:54 [31]...ent/webWorker@0.2[800]: 09/11 15:34:54 [19]...pp.WebAppResource[800]: Starting WebApp: com.zfabrik.samples.helloworld/web
09/11 15:34:55 [31]...ent/webWorker@0.2[800]: 09/11 15:34:55 [19]...pp.WebAppResource[800]: Done starting Web App (/helloworld): com.zfabrik.samples.helloworld/web
09/11 15:34:55 [31]...ent/webWorker@0.2[800]: 09/11 15:34:55 [19]...stemStateResource[800]: System state attained: environment/webWorkerUp
09/11 15:34:55 [34]...entRepositoryImpl[800]: Pulled deltas from GitCR com.zfabrik.boot.config/systemRepository (origin=, branch=v2.1)  within 29msec
09/11 15:34:55 [34]...entRepositoryImpl[800]: Pulled deltas from GitCR environment/samplesRepository (origin=, branch=v2.1, OPTIONAL)  within 30msec
108 2 Udo Offermann
109 19 Udo Offermann
Now it's time to check the result: http://localhost:8080/helloworld - voilà! 
You can now repeat these steps a few times: change the source code, hit <Alt+Y> and check the result, so you will get a feeling of how fast developement roundtrips can be!