Skip to content

Commit 12744e0

Browse files
committed
Improved structure of generated feature models
1 parent e77a5f6 commit 12744e0

7 files changed

Lines changed: 223 additions & 78 deletions

File tree

Resources/taxonomy.feature_model

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Security_Features
2-
Access_Control
2+
Access_Control
33
Authentication
44
Credentials
55
One_Time_Password
@@ -38,7 +38,7 @@ Security_Features
3838
Message_Authentication
3939
Digital_Watermarking
4040
Steganography
41-
Security_Monitoring
41+
Security_Monitoring
4242
Logging
4343
Automated_Response
4444
History_Maintenance
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Feature:
2+
def __init__(self, name, parent):
3+
self.name = name
4+
self.parent = parent
5+
self.sub_features = []
6+
if parent is not None:
7+
parent.sub_features.append(self)
8+
9+
# Searches in the feature tree for a feature with the given name
10+
def dfs(self, name):
11+
stack = [self]
12+
while len(stack) > 0:
13+
feature = stack.pop()
14+
if feature.name == name:
15+
return feature
16+
stack.extend(feature.sub_features)
17+
18+
def __str__(self):
19+
return "Feature: " + self.name
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import os
2+
3+
from SecurityKeywordsBasedSearchTool.SecFeatFinder.Feature import Feature
4+
5+
6+
def add_to_fm(fm, taxonomy, feature_name, tag):
7+
taxo_feature = taxonomy.dfs(feature_name)
8+
9+
feature = taxo_feature
10+
parents = [feature]
11+
while feature.parent is not None:
12+
feature = feature.parent
13+
parents.append(feature)
14+
15+
if parents.pop().name == fm.name:
16+
for feature in reversed(parents):
17+
exists = False
18+
for proposal in fm.sub_features:
19+
if proposal.name == feature.name:
20+
fm = proposal
21+
exists = True
22+
break
23+
if not exists:
24+
fm = Feature(feature.name, fm)
25+
return Feature(tag, fm)
26+
27+
28+
def create_feature_model_file(repo_dir, custom_features, library_features, fm):
29+
# Save the feature model structure
30+
feature_model_path = os.path.join(repo_dir, ".feature-model")
31+
with open(feature_model_path, "w") as file:
32+
indentation = 0
33+
save_feature_model(fm, file, indentation)
34+
print(f".feature-model file created at: {feature_model_path}")
35+
36+
37+
def read_feature_model(file):
38+
with open(file, "r") as f:
39+
depths = {-1: 0}
40+
stack = []
41+
for line in f.readlines():
42+
indentation = 0
43+
for c in line:
44+
if c == '\t':
45+
indentation += 4
46+
elif c == ' ':
47+
indentation += 1
48+
else:
49+
break
50+
name = line.strip()
51+
52+
stack_depth = len(stack) - 1
53+
if indentation in depths.keys():
54+
new_feature_depth = depths[indentation]
55+
else:
56+
new_feature_depth = len(stack)
57+
depths[indentation] = new_feature_depth
58+
59+
while new_feature_depth <= stack_depth:
60+
stack.pop()
61+
stack_depth -= 1
62+
63+
if len(stack) > 0:
64+
parent = stack[len(stack) - 1]
65+
else:
66+
parent = None
67+
68+
feature = Feature(name, parent)
69+
stack.append(feature)
70+
return stack[0]
71+
72+
73+
def save_feature_model(fm, file, indentation):
74+
file.write("\t" * indentation + fm.name + "\n")
75+
for child in fm.sub_features:
76+
save_feature_model(child, file, indentation + 1)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
import subprocess
3+
4+
5+
def clone_repository(repo_link):
6+
"""Clone the repository into a 'repos' directory with the project name."""
7+
# Extract project name from the repo URL
8+
project_name = os.path.basename(repo_link).replace(".git", "")
9+
repos_dir = os.path.join(os.getcwd(), "repos")
10+
project_dir = os.path.join(repos_dir, project_name)
11+
# Create the 'repos' directory if it doesn't exist
12+
os.makedirs(repos_dir, exist_ok=True)
13+
if os.path.exists(project_dir):
14+
print(f"Repository '{project_name}' already exists in 'repos'.")
15+
else:
16+
try:
17+
subprocess.run(["git", "clone", repo_link, project_dir],
18+
check=True)
19+
print(f"Cloned '{project_name}' into 'repos'.")
20+
except subprocess.CalledProcessError as e:
21+
raise RuntimeError(f"Failed to clone repository: {e}")
22+
return project_dir, project_name

SecurityKeywordsBasedSearchTool/SecFeatFinder/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)