The code-copy application relies on the local maven repo to generate the required maven / gradle dependencies. To ensure the local repo is updated, compile the original application so the necessary used libraries will be downloaded from maven central.
Open a command prompt and cd to c:\vFunctionLab\oms-tutorial
Checkout the mysql branch
git checkout mysql
Note: If the git is not connected, rename the oms-tutorial folder, clone the public repository and checkout the mysql branch:
cd c:\vFunctionLab
move oms-tutorial oms-tutorial-orig
git clone https://ws@bitbucket.org/vfunction/oms-tutorial.git
cd oms-tutorial
git switch mysql
Pull the latest version from the public git repository:
git pull
Go to the application folder
cd oms-webmvc
Compile using maven:
mvn clean install
You will now use the code-copy application, downloaded with the specification files, to create the baseline code for the extracted services.
Open a command prompt and cd to c:\vFunctionLab\service-specs
Optionally run java -jar code-copy.jar
to see the various arguments and their meaning
Run the following commands:
java -jar code-copy.jar -spec CommonLibrary.json -source ..\oms-tutorial\oms-webmvc -dest ..\oms-services\common
java -jar code-copy.jar -spec OrderController.json -source ..\oms-tutorial\oms-webmvc -dest ..\oms-services\order-controller
java -jar code-copy.jar -spec ProductController.json -source ..\oms-tutorial\oms-webmvc -dest ..\oms-services\product-controller
The inventory-controller has an entry point (InventoryService.fetchInventory()) that is used by product-controller (see the measurement in vFunction analysis page). We will use the -cldest
option to generate a client library for inventory-controller, so product-controller may be able to use it to call this entry point using the same signature as the direct call in the monolith. (Note: if you add this option for services without new entry points, it will be ignored)
java -jar code-copy.jar -spec InventoryController.json -source ..\oms-tutorial\oms-webmvc -dest ..\oms-services\inventory-controller -cldest ..\oms-services\inventory-controller-client
It is recommended to initialize a local git repository for the services so we can track the changes.
First you need to configure a name and e-mail gloabally in git to enable commits
git config --global user.email "[your email]"
git config --global user.name "[your name]"
To initialize a git repository for the services folder, do:
cd c:\vFunctionLab\oms-services
git init
git add --all
git commit -am "code-copy init"
Now you have a git repository for all the services code created by code-copy, without any changes.
In the CMD window, open the services code in VSCode:
code c:\vFunctionLab\oms-services
Note: It may take a few seconds for VSCode to load the extensions and analyze the code.
Alternatively you can just run VSCode from the start menu and open the folder.
Since code-copy generates both maven and gradle build file you will get a notification (bottom right) about which oe to use - you can either choose “Use Maven” or ignore the notification.
VSCode may compile all the Java code and as a result you will get some problems as well as new files.
To ignore the files under the target folders of all the services create a file called .gitignore (under the root of the EXPLORER) and set it contents to:
.vscode/settings.json
*/target/*
Commit the .gitignore file to git either via the command line interface or via VSCode source controler panel.
For more information on how to work with git via VSCode see: https://code.visualstudio.com/docs/sourcecontrol/overview
Code-copy generates a file named TODO.txt in every destination folder specifying a list of todo items based on it’s execution.
Open the TODO.txt files under every folder (common and the three services) - you should only see the general steps. If you see additional issues such as missing jar files or sources then it indicates a problem that needs to be investigated.
vFunction v2.8 and above includes the spotless plugin in the build files by default. This plugin removes redundant imports as well as formats the source code.
Run the following command in each of the services folders (i.e., subfolders of c:\vFunctionLab\oms-services)
mvn spotless:apply
After you run spotless for all services commit the changes by doing:
cd c:\vFunctionLab\oms-services
git commit -am "spotless"
Notes:
When you run spotless on inventory controller, you may get an error due to the version missing from the dependency on spring-data-geode. To fix it, open the pom.xml in a text editor or VSCode (under c:\vFunctionLab\oms-services\inventory-controller) and add version 2.7.18 to the dependency:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-geode</artifactId>
<version>2.7.18</version>
</dependency>
if you don’t want to use spotless, you can remove the spotless plugin from the build files (pom.xml and build.gradle) or add -DskipSpotless
when compiling the services with maven.