Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added rules-path option to configuration #54

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ private static Options createOptions(final Set<String> availableRuleIDs) {
.addRequiredOption("r", "rules", true,
"Supported rules for reverse engineering: " + String.join(", ", availableRuleIDs));

options.addOption("x", "rules-directory", true, "Path to the directory with additional project specific rules.");

options.addOption("h", "help", false, "Print this help message.");

return options;
Expand Down Expand Up @@ -99,6 +101,16 @@ public Object start(final IApplicationContext context) throws Exception {
return -1;
}

try {
configuration.setRulesFolder(URI.createFileURI(URI.decode(Paths.get(cmd.getOptionValue("x"))
.toAbsolutePath()
.normalize()
.toString())));
} catch (final InvalidPathException e) {
System.err.println("Invalid rules path: " + e.getMessage());
return -1;
}

// Enable all discoverers, in case a selected rule depends on them.
// TODO: This is unnecessary once rule dependencies are in place
final ServiceConfiguration<Discoverer> discovererConfig = configuration.getConfig(Discoverer.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class RetrieverConfigurationImpl extends AbstractComposedJobConfiguration
private static final String CONFIG_PREFIX = "org.palladiosimulator.retriever.core.configuration.";
public static final String RULE_ENGINE_INPUT_PATH = "input.path";
public static final String RULE_ENGINE_OUTPUT_PATH = CONFIG_PREFIX + "output.path";
public static final String RULE_ENGINE_RULES_PATH = CONFIG_PREFIX + "rules.path";
public static final String RULE_ENGINE_SELECTED_RULES = CONFIG_PREFIX + "rules";
public static final String RULE_ENGINE_SELECTED_ANALYSTS = CONFIG_PREFIX + "analysts";
public static final String RULE_ENGINE_SELECTED_DISCOVERERS = CONFIG_PREFIX + "discoverers";
Expand All @@ -36,6 +37,7 @@ public class RetrieverConfigurationImpl extends AbstractComposedJobConfiguration

private /* not final */ URI inputFolder;
private /* not final */ URI outputFolder;
private /* not final */ URI rulesFolder;

private final Map<Class<? extends Service>, ServiceConfiguration<? extends Service>> serviceConfigs;

Expand Down Expand Up @@ -99,6 +101,9 @@ public void applyAttributeMap(final Map<String, Object> attributeMap) {
if (attributeMap.get(RULE_ENGINE_OUTPUT_PATH) != null) {
this.setOutputFolder(URI.createURI((String) attributeMap.get(RULE_ENGINE_OUTPUT_PATH)));
}
if (attributeMap.get(RULE_ENGINE_RULES_PATH) != null) {
this.setRulesFolder(URI.createURI((String) attributeMap.get(RULE_ENGINE_RULES_PATH)));
}

for (final ServiceConfiguration<? extends Service> serviceConfig : this.serviceConfigs.values()) {
serviceConfig.applyAttributeMap(attributeMap);
Expand All @@ -120,6 +125,11 @@ public URI getOutputFolder() {
return this.outputFolder;
}

@Override
public URI getRulesFolder() {
return this.rulesFolder;
}

@Override
public void setInputFolder(final URI inputFolder) {
this.inputFolder = inputFolder;
Expand All @@ -130,6 +140,11 @@ public void setOutputFolder(final URI outputFolder) {
this.outputFolder = outputFolder;
}

@Override
public void setRulesFolder(final URI rulesFolder) {
this.rulesFolder = rulesFolder;
}

@Override
public <T extends Service> ServiceConfiguration<T> getConfig(final Class<T> serviceClass) {
// serviceConfig only contains legal mappings
Expand All @@ -143,6 +158,7 @@ public Map<String, Object> toMap() {

result.put(RULE_ENGINE_INPUT_PATH, this.getInputFolder());
result.put(RULE_ENGINE_OUTPUT_PATH, this.getOutputFolder());
result.put(RULE_ENGINE_RULES_PATH, this.getRulesFolder());

for (final ServiceConfiguration<? extends Service> serviceConfig : this.serviceConfigs.values()) {
result.putAll(serviceConfig.toMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public interface RetrieverConfiguration extends ExtendableJobConfiguration {

void setOutputFolder(URI createFileURI);

URI getRulesFolder();

void setRulesFolder(URI createFileURI);

<T extends Service> ServiceConfiguration<T> getConfig(Class<T> serviceClass);

}