Skip to content

Commit

Permalink
Apply Palladio Clean Up rules
Browse files Browse the repository at this point in the history
  • Loading branch information
FloBoJa committed Jan 12, 2024
1 parent 590f5e2 commit 1f74c4c
Show file tree
Hide file tree
Showing 175 changed files with 2,859 additions and 2,761 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public class RetrieverApplication implements IApplication {

private static Options createOptions(Set<String> availableRuleIDs) {
private static Options createOptions(final Set<String> availableRuleIDs) {
final Options options = new Options();
options
.addRequiredOption("i", "input-directory", true,
Expand All @@ -54,10 +54,10 @@ private static void printHelp(final Options options) {
}

@Override
public Object start(IApplicationContext context) throws Exception {
public Object start(final IApplicationContext context) throws Exception {

Set<Rule> availableRules = new RuleCollection().getServices();
Set<String> availableRuleIDs = availableRules.stream()
final Set<Rule> availableRules = new RuleCollection().getServices();
final Set<String> availableRuleIDs = availableRules.stream()
.map(Rule::getID)
.collect(Collectors.toSet());

Expand All @@ -77,7 +77,7 @@ public Object start(IApplicationContext context) throws Exception {
printHelp(options);
}

RetrieverConfiguration configuration = new RetrieverConfigurationImpl();
final RetrieverConfiguration configuration = new RetrieverConfigurationImpl();

try {
configuration.setInputFolder(URI.createFileURI(URI.decode(Paths.get(cmd.getOptionValue("i"))
Expand All @@ -101,25 +101,25 @@ public Object start(IApplicationContext context) throws Exception {

// Enable all discoverers, in case a selected rule depends on them.
// TODO: This is unnecessary once rule dependencies are in place
ServiceConfiguration<Discoverer> discovererConfig = configuration.getConfig(Discoverer.class);
for (Discoverer discoverer : new DiscovererCollection().getServices()) {
final ServiceConfiguration<Discoverer> discovererConfig = configuration.getConfig(Discoverer.class);
for (final Discoverer discoverer : new DiscovererCollection().getServices()) {
discovererConfig.select(discoverer);
}

ServiceConfiguration<Rule> ruleConfig = configuration.getConfig(Rule.class);
final ServiceConfiguration<Rule> ruleConfig = configuration.getConfig(Rule.class);
// Extract and check rules
Set<String> requestedRuleIDs = Arrays.stream(cmd.getOptionValue("r")
final Set<String> requestedRuleIDs = Arrays.stream(cmd.getOptionValue("r")
.split(","))
.map(String::strip)
.collect(Collectors.toSet());
Set<Rule> rules = availableRules.stream()
final Set<Rule> rules = availableRules.stream()
.filter(x -> requestedRuleIDs.contains(x.getID()))
.collect(Collectors.toSet());
if (rules.isEmpty()) {
System.err.println("Invalid rules: " + cmd.getOptionValue("r"));
return -1;
}
for (Rule rule : rules) {
for (final Rule rule : rules) {
ruleConfig.select(rule);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,47 +45,47 @@ public RetrieverConfigurationImpl() {
this(new HashMap<>());
}

public RetrieverConfigurationImpl(Map<String, Object> attributes) {
public RetrieverConfigurationImpl(final Map<String, Object> attributes) {
this.attributes = Objects.requireNonNull(attributes);
this.serviceConfigs = new HashMap<>();

ServiceCollection<Discoverer> discovererCollection = null;
try {
discovererCollection = new DiscovererCollection();
} catch (CoreException e) {
} catch (final CoreException e) {
LOG.error("Exception occurred while discovering discoverers!");
discovererCollection = new EmptyCollection<>();
}
ServiceConfiguration<Discoverer> discovererConfig = new ServiceConfiguration<>(discovererCollection,
final ServiceConfiguration<Discoverer> discovererConfig = new ServiceConfiguration<>(discovererCollection,
RULE_ENGINE_SELECTED_DISCOVERERS, RULE_ENGINE_DISCOVERER_CONFIG_PREFIX);
serviceConfigs.put(Discoverer.class, discovererConfig);
this.serviceConfigs.put(Discoverer.class, discovererConfig);

ServiceCollection<Rule> ruleCollection = null;
try {
ruleCollection = new RuleCollection();
} catch (CoreException e) {
} catch (final CoreException e) {
LOG.error("Exception occurred while discovering rules!");
ruleCollection = new EmptyCollection<>();
}
ServiceConfiguration<Rule> ruleConfig = new ServiceConfiguration<>(ruleCollection, RULE_ENGINE_SELECTED_RULES,
RULE_ENGINE_RULE_CONFIG_PREFIX);
final ServiceConfiguration<Rule> ruleConfig = new ServiceConfiguration<>(ruleCollection,
RULE_ENGINE_SELECTED_RULES, RULE_ENGINE_RULE_CONFIG_PREFIX);
ruleConfig.addDependencyProvider(discovererConfig);
serviceConfigs.put(Rule.class, ruleConfig);
this.serviceConfigs.put(Rule.class, ruleConfig);

ServiceCollection<Analyst> analystCollection = null;
try {
analystCollection = new AnalystCollection();
} catch (CoreException e) {
} catch (final CoreException e) {
LOG.error("Exception occurred while discovering analysts!");
analystCollection = new EmptyCollection<>();
}
ServiceConfiguration<Analyst> analystConfig = new ServiceConfiguration<>(analystCollection,
final ServiceConfiguration<Analyst> analystConfig = new ServiceConfiguration<>(analystCollection,
RULE_ENGINE_SELECTED_ANALYSTS, RULE_ENGINE_ANALYST_CONFIG_PREFIX);
analystConfig.addDependencyProvider(discovererConfig);
analystConfig.addDependencyProvider(ruleConfig);
serviceConfigs.put(Analyst.class, analystConfig);
this.serviceConfigs.put(Analyst.class, analystConfig);

applyAttributeMap(attributes);
this.applyAttributeMap(attributes);
}

public void applyAttributeMap(final Map<String, Object> attributeMap) {
Expand All @@ -94,57 +94,57 @@ public void applyAttributeMap(final Map<String, Object> attributeMap) {
}

if (attributeMap.get(RULE_ENGINE_INPUT_PATH) != null) {
setInputFolder(URI.createURI((String) attributeMap.get(RULE_ENGINE_INPUT_PATH)));
this.setInputFolder(URI.createURI((String) attributeMap.get(RULE_ENGINE_INPUT_PATH)));
}
if (attributeMap.get(RULE_ENGINE_OUTPUT_PATH) != null) {
setOutputFolder(URI.createURI((String) attributeMap.get(RULE_ENGINE_OUTPUT_PATH)));
this.setOutputFolder(URI.createURI((String) attributeMap.get(RULE_ENGINE_OUTPUT_PATH)));
}

for (ServiceConfiguration<? extends Service> serviceConfig : serviceConfigs.values()) {
for (final ServiceConfiguration<? extends Service> serviceConfig : this.serviceConfigs.values()) {
serviceConfig.applyAttributeMap(attributeMap);
}
}

@Override
public Map<String, Object> getAttributes() {
return attributes;
return this.attributes;
}

@Override
public URI getInputFolder() {
return inputFolder;
return this.inputFolder;
}

@Override
public URI getOutputFolder() {
return outputFolder;
return this.outputFolder;
}

@Override
public void setInputFolder(URI inputFolder) {
public void setInputFolder(final URI inputFolder) {
this.inputFolder = inputFolder;
}

@Override
public void setOutputFolder(URI outputFolder) {
public void setOutputFolder(final URI outputFolder) {
this.outputFolder = outputFolder;
}

@Override
public <T extends Service> ServiceConfiguration<T> getConfig(Class<T> serviceClass) {
public <T extends Service> ServiceConfiguration<T> getConfig(final Class<T> serviceClass) {
// serviceConfig only contains legal mappings
@SuppressWarnings("unchecked")
ServiceConfiguration<T> serviceConfig = (ServiceConfiguration<T>) serviceConfigs.get(serviceClass);
final ServiceConfiguration<T> serviceConfig = (ServiceConfiguration<T>) this.serviceConfigs.get(serviceClass);
return serviceConfig;
}

public Map<String, Object> toMap() {
final Map<String, Object> result = new HashMap<>();

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

for (ServiceConfiguration<? extends Service> serviceConfig : serviceConfigs.values()) {
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 @@ -16,14 +16,14 @@ public class RetrieverWorkflowConfiguration extends AbstractWorkflowBasedRunConf

@Override
public void setDefaults() {
configuration = new RetrieverConfigurationImpl();
this.configuration = new RetrieverConfigurationImpl();
}

public RetrieverConfiguration getRetrieverConfiguration() {
return configuration;
return this.configuration;
}

public void setRetrieverConfiguration(RetrieverConfiguration configuration) {
public void setRetrieverConfiguration(final RetrieverConfiguration configuration) {
this.configuration = configuration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ public class RetrieverConfigurationDelegate
extends AbstractWorkflowBasedLaunchConfigurationDelegate<RetrieverWorkflowConfiguration, Workflow> {

@Override
protected IJob createWorkflowJob(RetrieverWorkflowConfiguration config, ILaunch launch) throws CoreException {
protected IJob createWorkflowJob(final RetrieverWorkflowConfiguration config, final ILaunch launch)
throws CoreException {
return new RetrieverJob(config.getRetrieverConfiguration());
}

@Override
protected RetrieverWorkflowConfiguration deriveConfiguration(ILaunchConfiguration configuration, String mode)
throws CoreException {
protected RetrieverWorkflowConfiguration deriveConfiguration(final ILaunchConfiguration configuration,
final String mode) throws CoreException {

final RetrieverWorkflowConfiguration analyzerConfiguration = new RetrieverWorkflowConfiguration();
analyzerConfiguration.setRetrieverConfiguration(new RetrieverConfigurationImpl(configuration.getAttributes()));
Expand Down
Loading

0 comments on commit 1f74c4c

Please sign in to comment.