7738a4aa3ff6937e0737b3a149beb74ccdb781f5
1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Doxygen XML to Neo4j
19 # neo_doxygen project_name xml_output_dir [neo4j_url]
23 # Convert a Doxygen XML output into a model in Neo4j that is readable by the
28 # * project_name: The internal name of the project. Must the same name as the
29 # one specified to the `nx` tool.
31 # * xml_output_dir: The directory where the XML documents generated by Doxygen
34 # * neo4j_url: The URL of the instance of Neo4j to use.
35 # `http://localhost:7474` by default.
41 # An importation task.
43 var client
: Neo4jClient
44 var model
: ProjectGraph is noinit
46 # How many operation can be executed in one batch?
47 private var batch_max_size
= 1000
49 # Generate a graph from the specified project model.
53 # * `name`: project name.
54 # * `dir`: Doxygen XML output directory path.
55 fun put_project
(name
: String, dir
: String) do
56 model
= new ProjectGraph(name
)
57 # TODO Let the user select the language.
58 var reader
= new CompoundFileReader(model
, new JavaSource)
59 # Queue for sub-directories.
60 var directories
= new Array[String]
62 if dir
.length
> 1 and dir
.chars
.last
== "/" then
63 dir
= dir
.substring
(0, dir
.length
- 1)
68 if path
.file_stat
.is_dir
then
69 directories
.push
(path
)
70 else if f
.has_suffix
(".xml") and f
!= "index.xml" then
71 print
"Processing {path}..."
75 if directories
.length
<= 0 then break
83 var nodes
= model
.all_nodes
84 print
("Saving {nodes.length} nodes...")
86 var edges
= model
.all_edges
87 print
("Saving {edges.length} edges...")
91 # Save `neo_entities` in the database using batch mode.
92 private fun push_all
(neo_entities
: Collection[NeoEntity]) do
93 var batch
= new NeoBatch(client
)
94 var len
= neo_entities
.length
98 for nentity
in neo_entities
do
99 batch
.save_entity
(nentity
)
100 if i
== batch_max_size
then
102 sum
+= batch_max_size
103 print
("\t{sum * 100 / len}% done.")
104 batch
= new NeoBatch(client
)
113 # Execute `batch` and check for errors.
115 # Abort if `batch.execute` returns errors.
116 private fun do_batch
(batch
: NeoBatch) do
117 var errors
= batch
.execute
118 if not errors
.is_empty
then
119 for e
in errors
do sys
.stderr
.write
("{sys.program_name}: {e}\n")
125 if args
.length
!= 2 and args
.length
!= 3 then
126 stderr
.write
("Usage: {sys.program_name} project_name xml_output_dir [neo4j_url]\n")
129 var url
= "http://localhost:7474"
130 if args
.length
>= 3 then
134 var neo
= new NeoDoxygen(new Neo4jClient(url
))
135 neo
.put_project
(args
[0], args
[1])