When using an API within a project, it can happen that the API developer introduces some breaking changes. This means that your project wouldn't run properly anymore until you updated these changes within your code manually.
The aim of this project is to automatically generate transformation rules, which can be loaded into Pharo and propose you code changes in order to stay up to date with any API.
APIEvolutionMiner is an existing tool that mines a project history to detect API changes. This tool is also capable of producing static analyzer rules that detect an old API usage in source code.
Although the tool was proven to work well it was never used for two reasons:
- At the time when it was developed Pharo didn't have a nice UI for reporting critics generated by the rules.
- You had to setup APIEvolutionMiner by yourself and manually recover the rules.
While the first issue is mitigated by QualityAssistant, the second one is solved by this project.
This project uses the APIEvolutionMiner for mining the revision history of any SmalltalkHub repository. Furthermore, it uses the rules generated by the APIEvolutionMiner and converts them into useful rewrite rules.
This conversion is done by generating sub-classes of RBTransformationRule. It respects also rules containing wildcards for objects or containing keyword messages.
However, there is a limitation if the number of arguments doesn't match. In this case the AEMTransformRulesGenerator cannot generate a rewrite rule, because there is a lack of information. It will simply skip these rules.
The resulting Smalltalk package file (AEMTransformRules.st
) can be filed-in into your Pharo VM. Then, you can open the built-in Critic Browser for viewing the API changes. Below you can find an example of viewing the rules for Roassal2 within Critic Browser:
-
Clone this repository into your preferred directory.
-
Run the script
Get-AEMRules.sh
with any SmalltalkHub repository as argument (replace the link of GraphET2 with our desired project):$ ./Get-AEMRules.sh http://www.smalltalkhub.com/mc/ObjectProfile/GraphET2/main
-
The script will generate all the files in the following directory:
~/AEMTransformRules/AEMRules-{your_project_name}
-
Create a new folder for the APIEvolutionMiner and project files.
-
Download the APIEvolutionMiner-Jet Pharo image from here: https://ci.inria.fr/rmod/view/MinedRules/job/APIEvolutionMiner-Jet/lastSuccessfulBuild/artifact/APIEvolutionMiner-Jet.zip
curl --silent --insecure -o APIEvolutionMiner-Jet.zip https://ci.inria.fr/rmod/view/MinedRules/job/APIEvolutionMiner-Jet/lastSuccessfulBuild/artifact/APIEvolutionMiner-Jet.zip unzip -o APIEvolutionMiner-Jet.zip
-
Download latest Pharo VM here: http://get.pharo.org/vm or just use your existing Pharo VM (be aware, the APIEvolutionMiner needs the PharoV20.sources).
curl --silent get.pharo.org/vm | bash
-
Create the following sub-folders and files:
mkdir latestMczFiles mkdir latestSourceCodeChanges touch ourMczFiles
-
Open the Pharo-UI with the
APIEvolutionMiner-Jet.image
and download the latest MCZ-files for your desired SmalltalkHub project (replace the links and names of GraphET2 with our desired project). This step should write into the previously created fileourMczFiles
and folderlatestMczFiles
. Attention: For a large project, this step can take a long time and downloads several MBs data.AEMRepositoryDownloader downloaLatestMczsFor: 'http://www.smalltalkhub.com/mc/ObjectProfile/GraphET2/main'.
-
Now import the ring history. This will close the UI, but it's okay. This step should generate the file
latestDataset
and write into the previously created folderlatestSourceCodeChanges
. Depending on the size of the project, this step needs more than the usual memory size. If it crashes due to memory, just add the following line to the VMPharo.ini
:AddressSpaceLimit=1536
(update the number of memory according to your project).AEMRepositoryDownloader importToRingHistoryAndExportAssociations.
-
Copy the file
latestDataset
and rename the copy todataset
:cp -u latestDataset dataset
-
Copy the folder
latestSourceCodeChanges
and rename the copy tosourceCodeChanges
:mkdir sourceCodeChanges cp -r latestSourceCodeChanges/* sourceCodeChanges
-
Open the Pharo-UI with the
APIEvolutionMiner-Jet.image
again and file-in the following file: -
Then execute the following code within the Workspace:
```smalltalk
AEMSystemHistoryImporter loadSystemHistory: 'GraphET2'.
AEMTransformRulesGenerator new generateRBTransformationRules: ((AEMEvidenceRanking new systemHistory: ((AEMReport exportOneOneRules) systemHistory)) oneOneRules).
(RPackageOrganizer default packageNamed: #AEMTransformRules) fileOut.
```
-
The code above should have created the following files in your directory:
- rules.csv (containing the APIEvolutionMiner rules)
- AEMTransformRules.st (containing the RBTransformationRules, which can be directly used with Critic-Browser)
- PharoDebug.log:
Error: can't find EOCD position
- Solution:
- Go into folder
latestMczFiles
- Sort .mcz (actually ZIP archives) by file-size
- Delete (remember the names) all files with file-size of 0 or 1 KB (corrupted, you can try to open them with your ZIP application to test them)
- Go back to one folder above. Remove the deleted packages from the list in file
ourMczFiles
. - Finally, just run the Bash script with the same repository as input again.
- Go into folder
- Solution:
- Integrate the code into a CI service
- Debug the command
AEMRepositoryDownloader importToRingHistoryAndExportAssociations.
since it crashes very often (especially for bigger projects/APIs) - Update AEM in order to run at least on Pharo 4 (currently it needs still Pharo 2)
- http://homepages.dcc.ufmg.br/~mtov/pub/2014_csmrwcre_apievolutionminer.pdf
- http://rmod.lille.inria.fr/web/software/APIEvolutionMiner
- http://smalltalkhub.com/#!/~andrehora/APIEvolutionMiner
- https://ci.inria.fr/rmod/view/MinedRules/job/APIEvolutionMiner/lastSuccessfulBuild/consoleFull
- https://ci.inria.fr/rmod/view/MinedRules/job/Roassal-Monitoring/lastSuccessfulBuild/consoleFull
- https://ci.inria.fr/rmod/view/MinedRules/job/Roassal-APIEvolutionMiner/lastSuccessfulBuild/consoleFull
- https://ci.inria.fr/rmod/view/MinedRules/job/Moose-Report/lastSuccessfulBuild/consoleFull
- https://ci.inria.fr/pharo-contribution/view/Helper/job/JobTemplate/
- http://www.smalltalkhub.com/#!/~ObjectProfile/GraphET2
- http://www.smalltalkhub.com/mc/ObjectProfile/GraphET2/main
- http://www.smalltalkhub.com/#!/~ObjectProfile/Roassal2
- http://www.smalltalkhub.com/mc/ObjectProfile/Roassal2/main