Skip to content

Commit 05cdd63

Browse files
Merge pull request diffblue#523 from diffblue/cleanup/entry-point-detection-json
Use camelCase for JSON property names
2 parents 30dc0d0 + 71b74bd commit 05cdd63

10 files changed

+139
-101
lines changed

driver/mkbench.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def _find_java_binaries(start_path, java_binaries):
3838
def _read_info_of_class_files(class_files, configuration, cmdline):
3939

4040
assert isinstance(class_files, list) and all(isinstance(s, str) for s in class_files)
41-
class_list_json_file = configuration["collected_classes_path"]
41+
class_list_json_file = configuration["collectedClassesPath"]
4242
with open(class_list_json_file, "w") as ofile:
4343
ofile.write(json.dumps(class_files, sort_keys=True, indent=4))
44-
class_info_json_file = configuration["collected_classes_info_path"]
44+
class_info_json_file = configuration["collectedClassesInfoPath"]
4545

4646
os_command = (
4747
analyser.get_java_class_info_tool_pathname() +
@@ -141,7 +141,7 @@ def collect_java_binaries(cmdline):
141141
with utility.PushCwd(classes_temp_dir):
142142
os.system("jar cf \"" + java_binaries.jar_file + "\" .")
143143

144-
entry_points_file = configuration["detected_entry_points_path"]
144+
entry_points_file = configuration["detectedEntryPointsPath"]
145145
if not os.path.exists(entry_points_file):
146146
print("WARNING: Unable to find any detected entry points. No analysis will be run.")
147147
return
@@ -154,12 +154,12 @@ def collect_java_binaries(cmdline):
154154

155155
# Loop over all our detected entry points and create a folder for each.
156156
class_paths = [p for p in java_binaries.classpath_jar_files + java_libraries.classpath_jar_files + library_directories]
157-
for ep_data in ep_config["entry_points"]:
157+
for ep_data in ep_config["entryPoints"]:
158158

159159
method_data = ep_data["method"]
160160

161161
# We don't add the descriptor here as it's not recognized (and makes folder names too long).
162-
fully_qualified_method = ep_data["class_name"] + "." + method_data["name"]
162+
fully_qualified_method = ep_data["className"] + "." + method_data["name"]
163163

164164
# Try to make sure the folder name isn't invalid.
165165
folder_name = fully_qualified_method.replace(os.path.sep, '.')

driver/run.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -213,31 +213,31 @@ def prepare_scan(cmdline):
213213
configuration = json.load(config_file)
214214
file_name = os.path.basename(config_file.name)
215215

216-
if not configuration["detected_entry_points_path"]:
217-
configuration["detected_entry_points_path"] = \
216+
if not configuration["detectedEntryPointsPath"]:
217+
configuration["detectedEntryPointsPath"] = \
218218
os.path.join(cmdline.common_dir, "detected_entry_points.json")
219219

220-
if not configuration["di_configuration_path"]:
221-
configuration["di_configuration_path"] = \
220+
if not configuration["diConfigurationPath"]:
221+
configuration["diConfigurationPath"] = \
222222
os.path.join(cmdline.common_dir, "di_configuration.json")
223223

224-
if not configuration["collected_classes_path"]:
225-
configuration["collected_classes_path"] = \
224+
if not configuration["collectedClassesPath"]:
225+
configuration["collectedClassesPath"] = \
226226
os.path.join(cmdline.common_dir, "collected_classes.json")
227227

228-
if not configuration["collected_classes_info_path"]:
229-
configuration["collected_classes_info_path"] = \
228+
if not configuration["collectedClassesInfoPath"]:
229+
configuration["collectedClassesInfoPath"] = \
230230
os.path.join(cmdline.common_dir, "collected_classes_info.json")
231231

232232
# If we have an entry point coming in, just replace all rules.
233233
if cmdline.entry_point:
234234
class_name, method_name = cmdline.entry_point.rsplit('.', 1)
235-
configuration["pattern_group"] = \
235+
configuration["patternGroup"] = \
236236
[{
237237
"id": "General",
238238
"patterns": [{
239-
"method_pattern": {"names": [re.escape(method_name)]},
240-
"class_pattern": {"names": [re.escape(class_name)]}
239+
"methodPattern": {"names": [re.escape(method_name)]},
240+
"classPattern": {"names": [re.escape(class_name)]}
241241
}]
242242
}]
243243

src/java-class-info/default_config.json

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"collected_classes_path": "",
3-
"collected_classes_info_path": "",
4-
"detected_entry_points_path": "",
5-
"di_configuration_path": "",
6-
"pattern_group": [
2+
"collectedClassesPath": "",
3+
"collectedClassesInfoPath": "",
4+
"detectedEntryPointsPath": "",
5+
"diConfigurationPath": "",
6+
"patternGroup": [
77
{
88
"id": "Spring MVC",
99
"patterns": [
1010
{
11-
"method_pattern":
11+
"methodPattern":
1212
{
1313
"annotations": ["org.springframework.web.bind.annotation.RequestMapping",
1414
"org.springframework.web.bind.annotation.PostMapping",
@@ -19,10 +19,10 @@
1919
}
2020
},
2121
{
22-
"class_pattern": {
22+
"classPattern": {
2323
"implements": ["org.springframework.web.servlet.mvc.Controller"]
2424
},
25-
"method_pattern": {
25+
"methodPattern": {
2626
"arguments": ["javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse"],
2727
"returns": ["org.springframework.web.servlet.ModelAndView"]
2828
}
@@ -33,12 +33,12 @@
3333
"id": "JWS",
3434
"patterns": [
3535
{
36-
"class_pattern": {
36+
"classPattern": {
3737
"annotations": ["javax.jws.WebService"]
3838
}
3939
},
4040
{
41-
"method_pattern": {
41+
"methodPattern": {
4242
"annotations": ["javax.jws.WebMethod"]
4343
}
4444
}
@@ -48,7 +48,7 @@
4848
"id": "Java WS RS",
4949
"patterns": [
5050
{
51-
"method_pattern": {
51+
"methodPattern": {
5252
"annotations": ["javax.ws.rs.OPTIONS",
5353
"javax.ws.rs.POST",
5454
"javax.ws.rs.PUT",
@@ -64,7 +64,7 @@
6464
"id": "Alfresco",
6565
"patterns": [
6666
{
67-
"method_pattern": {
67+
"methodPattern": {
6868
"annotations": [
6969
"org.alfresco.web.app.servlet.ajax.InvokeCommand",
7070
"org.alfresco.web.app.servlet.ajax.GetCommand"
@@ -77,21 +77,21 @@
7777
"id": "Sakai",
7878
"patterns": [
7979
{
80-
"class_pattern": {
80+
"classPattern": {
8181
"extends": ["org.sakaiproject.cheftool.VelocityPortletPaneledAction"]
8282
},
83-
"method_pattern": {
83+
"methodPattern": {
8484
"arguments": [
8585
"org.sakaiproject.cheftool.RunData",
8686
"org.sakaiproject.cheftool.Context"
8787
]
8888
}
8989
},
9090
{
91-
"class_pattern": {
91+
"classPattern": {
9292
"extends": ["org.sakaiproject.cheftool.VelocityPortletPaneledAction"]
9393
},
94-
"method_pattern": {
94+
"methodPattern": {
9595
"arguments": ["org.sakaiproject.cheftool.RunData"]
9696
}
9797
}
@@ -101,12 +101,12 @@
101101
"id": "Javax Servlet",
102102
"patterns": [
103103
{
104-
"class_pattern": {
104+
"classPattern": {
105105
"extends": [
106106
"javax.servlet.http.HttpServlet"
107107
]
108108
},
109-
"method_pattern": {
109+
"methodPattern": {
110110
"names": [
111111
"doDelete",
112112
"doGet",
@@ -124,7 +124,7 @@
124124
"id": "GWT",
125125
"patterns": [
126126
{
127-
"class_pattern": {
127+
"classPattern": {
128128
"implements": [
129129
"com.google.gwt.user.client.rpc.RemoteService"
130130
]
@@ -136,22 +136,22 @@
136136
"id": "Play!",
137137
"patterns": [
138138
{
139-
"class_pattern": {
139+
"classPattern": {
140140
"extends": [
141141
"play.mvc.Controller"
142142
]
143143
},
144-
"method_pattern": {
144+
"methodPattern": {
145145
"returns": ["play.mvc.Result"]
146146
}
147147
},
148148
{
149-
"class_pattern": {
149+
"classPattern": {
150150
"extends": [
151151
"play.mvc.Action", "play.mvc.Action.Simple"
152152
]
153153
},
154-
"method_pattern": {
154+
"methodPattern": {
155155
"names": ["call"],
156156
"arguments": ["play.mvc.Http.Context"]
157157
}
@@ -162,10 +162,10 @@
162162
"id": "Struts",
163163
"patterns": [
164164
{
165-
"class_pattern": {
165+
"classPattern": {
166166
"extends": ["com.opensymphony.xwork2.ActionSupport"]
167167
},
168-
"method_pattern": {
168+
"methodPattern": {
169169
"names": ["execute"],
170170
"returns": ["java.lang.String"]
171171
}

src/java-class-info/default_config.schema.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
{
22
"additionalProperties": false,
33
"properties": {
4-
"collected_classes_path": {
4+
"collectedClassesPath": {
55
"type": "string",
66
"description": "Path to the collected_classes.json that is used to drive class file detection.",
77
"default": ""
88
},
99

10-
"collected_classes_info_path": {
10+
"collectedClassesInfoPath": {
1111
"type": "string",
1212
"description": "Path where the results of class file detection should be saved.",
1313
"default": ""
1414
},
1515

16-
"detected_entry_points_path": {
16+
"detectedEntryPointsPath": {
1717
"type": "string",
1818
"description": "Path where the results of automatic entry point detection should be saved.",
1919
"default": ""
2020
},
2121

22-
"di_configuration_path": {
22+
"diConfigurationPath": {
2323
"type": "string",
2424
"description": "Path where the output of the DI metadata harvesting result is output.",
2525
"default": ""
2626
},
2727

28-
"pattern_group": {
28+
"patternGroup": {
2929
"type": "array",
3030
"description": "A pattern group is a set of class and method patterns that when considered together are used by a certain framework or technique to signify a website / web service entry-point.",
3131
"items": {
@@ -45,7 +45,7 @@
4545
"additionalProperties": false,
4646
"properties": {
4747

48-
"method_pattern": {
48+
"methodPattern": {
4949
"type": "object",
5050
"description": "The selection of patterns a method must match to be considered an entry-point.",
5151
"additionalProperties": false,
@@ -85,7 +85,7 @@
8585
}
8686
},
8787

88-
"class_pattern": {
88+
"classPattern": {
8989
"type": "object",
9090
"description": "The selection of patterns a class must match to be considered an entry-point. If a method pattern is not stated, then all methods in a class will be matched.",
9191
"additionalProperties": false,

src/java-class-info/detected_entry_points.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class detected_entry_pointst
2020
class json_namest
2121
{
2222
public:
23-
static constexpr const char *entry_points = "entry_points";
23+
static constexpr const char *entry_points = "entryPoints";
2424
};
2525
};
2626

src/java-class-info/entry_point.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class entry_pointt
2424
static constexpr const char *signature = "signature";
2525
static constexpr const char *type = "type";
2626
static constexpr const char *arguments = "arguments";
27-
static constexpr const char *return_type = "return_type";
28-
static constexpr const char *class_name = "class_name";
27+
static constexpr const char *return_type = "returnType";
28+
static constexpr const char *class_name = "className";
2929
static constexpr const char *method = "method";
3030
};
3131

src/java-class-info/generation_configuration.cpp

+51-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,67 @@
22

33
#include "generation_configuration.h"
44
#include <boost/assign.hpp>
5+
#include <boost/filesystem.hpp>
56
#include <list>
7+
#include <sstream>
68
#include <util/json.h>
79

810
generation_configurationt::generation_configurationt(const jsont &json)
911
{
1012
detected_entry_points_path =
1113
json[json_namest::detected_entry_points_path].value;
14+
for(const jsont &element : json[json_namest::pattern_group].array)
15+
{
16+
pattern_group.emplace_back(element);
17+
}
18+
if(!pattern_group.empty())
19+
{
20+
if(detected_entry_points_path.empty())
21+
{
22+
std::stringstream error;
23+
error << "The configuration file contained pattern groups but not a "
24+
<< json_namest::detected_entry_points_path << " element.";
25+
errors.push_back(error.str());
26+
}
27+
else if(boost::filesystem::is_directory(detected_entry_points_path))
28+
{
29+
std::stringstream error;
30+
error << "The output path '" << detected_entry_points_path
31+
<< "' references an existing directory.";
32+
errors.push_back(error.str());
33+
}
34+
}
35+
1236
collected_classes_info_path =
1337
json[json_namest::collected_classes_info_path].value;
14-
collected_classes_path = json[json_namest::collected_classes_path].value;
15-
di_configuration_path = json[json_namest::di_configuration_path].value;
38+
if(collected_classes_info_path.empty())
39+
{
40+
std::stringstream error;
41+
error << "The configuration file did not contain a "
42+
<< json_namest::collected_classes_info_path << " element.";
43+
}
44+
else if(boost::filesystem::is_directory(collected_classes_info_path))
45+
{
46+
std::stringstream error;
47+
error << "The output path '" << collected_classes_info_path
48+
<< "' references an existing directory.";
49+
}
1650

17-
for(const jsont &element : json[json_namest::pattern_group].array)
51+
collected_classes_path = json[json_namest::collected_classes_path].value;
52+
if(collected_classes_path.empty())
1853
{
19-
pattern_group.emplace_back(element);
54+
std::stringstream error;
55+
error << "The configuration file did not contain a "
56+
<< json_namest::collected_classes_path << " element.";
57+
errors.push_back(error.str());
58+
}
59+
else if(!boost::filesystem::is_regular_file(collected_classes_path))
60+
{
61+
std::stringstream error;
62+
error << "The input file '" << collected_classes_path
63+
<< "' does not exist.";
64+
errors.push_back(error.str());
2065
}
66+
67+
di_configuration_path = json[json_namest::di_configuration_path].value;
2168
}

0 commit comments

Comments
 (0)