Skip to content

Commit 5debd35

Browse files
committed
Add FamixJavaFoldersImporter
Add a class to generate models and import them from a list of java project folders
1 parent 83038d2 commit 5debd35

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
"
2+
I am a class that will take as input a collection of folders containing java code and I'll parse the projects with VerveineJ and import the resulting models.
3+
4+
For VerveineJ, for now I can get it in two way:
5+
- Through a setting to target an existing VerveineJ folder
6+
- By downloading the latest version of VerveineJ
7+
8+
This is brittle because the version of VerveineJ might not be compatible with the famix version currently in the image. We should think of a way to improve this.
9+
10+
In order to use me you can do:
11+
12+
```st
13+
14+
FamixJavaFoldersImporter importFolder: aFileReference.
15+
16+
""or""
17+
18+
FamixFolderJavaImporter importFolder: aFileReference
19+
```
20+
21+
In the future it might be nice to add ways to import projects of other languages.
22+
"
23+
Class {
24+
#name : #FamixJavaFoldersImporter,
25+
#superclass : #Object,
26+
#instVars : [
27+
'folders'
28+
],
29+
#classVars : [
30+
'VerveineJPath'
31+
],
32+
#category : #'Moose-Importers'
33+
}
34+
35+
{ #category : #accessing }
36+
FamixJavaFoldersImporter class >> defaultVerveineJDirectory [
37+
38+
^ FileSystem workingDirectory / 'VerveineJ'
39+
]
40+
41+
{ #category : #actions }
42+
FamixJavaFoldersImporter class >> importFolder: aFileReference [
43+
44+
^ self importFolders: { aFileReference }
45+
]
46+
47+
{ #category : #actions }
48+
FamixJavaFoldersImporter class >> importFolders: aCollection [
49+
50+
^ self new
51+
folders: aCollection;
52+
import
53+
]
54+
55+
{ #category : #settings }
56+
FamixJavaFoldersImporter class >> importSettingsOn: aBuilder [
57+
58+
<systemsettings>
59+
(aBuilder setting: #verveineJPath)
60+
parent: #moose;
61+
type: #FilePathEncoder;
62+
default: self verveineJPath;
63+
label: 'VerveineJ path for FamixJavaFolderImporter';
64+
description: 'If you wish to use your own version of verveineJ through FamixJavaFolderImporter you can specify your own path to it..';
65+
target: self
66+
]
67+
68+
{ #category : #accessing }
69+
FamixJavaFoldersImporter class >> verveineJPath [
70+
71+
^ VerveineJPath ifNil: [ VerveineJPath := self defaultVerveineJDirectory ]
72+
]
73+
74+
{ #category : #accessing }
75+
FamixJavaFoldersImporter class >> verveineJPath: anObject [
76+
77+
VerveineJPath := anObject
78+
]
79+
80+
{ #category : #initialization }
81+
FamixJavaFoldersImporter >> ensureVerveineJ [
82+
83+
self verveineJScript ifAbsent: [
84+
"For now we take the latest VerveineJ. Probably we could have a better way to download VerveinJ by selecting a version that is compatible with the current Famix. But I don't know how to do that for now."
85+
IceGitClone new
86+
location: self verveineJPath;
87+
url: 'https://github.com/moosetechnology/VerveineJ.git';
88+
execute.
89+
90+
self verveineJScript ifAbsent: [ self error: 'Cannot download verveineJ.' ] ]
91+
]
92+
93+
{ #category : #accessing }
94+
FamixJavaFoldersImporter >> folders [
95+
96+
^ folders
97+
]
98+
99+
{ #category : #accessing }
100+
FamixJavaFoldersImporter >> folders: anObject [
101+
102+
folders := anObject
103+
]
104+
105+
{ #category : #actions }
106+
FamixJavaFoldersImporter >> generateJsonOfProjects [
107+
108+
folders
109+
do: [ :folder |
110+
LibC runCommand: ('{1} -o {2} -format json {3}' format: {
111+
self verveineJScript pathString asComment.
112+
(self jsonForFolder: folder).
113+
folder pathString asComment }) ]
114+
displayingProgress: [ :folder | folder pathString ]
115+
]
116+
117+
{ #category : #actions }
118+
FamixJavaFoldersImporter >> import [
119+
120+
self ensureVerveineJ.
121+
122+
self generateJsonOfProjects.
123+
124+
self importModels
125+
]
126+
127+
{ #category : #actions }
128+
FamixJavaFoldersImporter >> importModels [
129+
130+
folders
131+
do: [ :folder |
132+
| json importer model |
133+
json := (self jsonForFolder: folder) asFileReference.
134+
importer := FamixAbstractFileImporter importerFor: json.
135+
136+
model := (importer findPossibleModelClassIn: MooseModel possibleModelsToImportFromFiles forFile: json) new.
137+
138+
importer new
139+
model: model;
140+
inputFile: json;
141+
run.
142+
143+
model
144+
name: folder basename;
145+
install ]
146+
displayingProgress: [ :folder | folder basename ]
147+
]
148+
149+
{ #category : #actions }
150+
FamixJavaFoldersImporter >> jsonForFolder: folder [
151+
152+
^ folder basename , '.json'
153+
]
154+
155+
{ #category : #accessing }
156+
FamixJavaFoldersImporter >> verveineJPath [
157+
158+
^ self class verveineJPath
159+
]
160+
161+
{ #category : #accessing }
162+
FamixJavaFoldersImporter >> verveineJScript [
163+
"Manage windows later?"
164+
165+
^ self verveineJPath / 'verveinej.sh'
166+
]

0 commit comments

Comments
 (0)