| /********************************************************************* |
| * Copyright (c) 2019 The University of York. |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| **********************************************************************/ |
| package org.eclipse.epsilon.executors.evl; |
| |
| import java.util.Collection; |
| import java.util.Set; |
| import org.eclipse.epsilon.executors.AbstractLanguageExecutor; |
| import org.eclipse.epsilon.eol.exceptions.EolRuntimeException; |
| import org.eclipse.epsilon.evl.IEvlModule; |
| import org.eclipse.epsilon.evl.concurrent.EvlModuleParallelAnnotation; |
| import org.eclipse.epsilon.evl.execute.UnsatisfiedConstraint; |
| import org.eclipse.epsilon.evl.execute.context.IEvlContext; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| /** |
| * The EVL executor |
| * @author Horacio Hoyos Rodriguez |
| */ |
| public class EvlExecutor extends AbstractLanguageExecutor implements IEvlExecutor { |
| |
| private static final Logger logger = LoggerFactory.getLogger(EvlExecutor.class); |
| |
| public EvlExecutor() { |
| this(new EvlModuleParallelAnnotation()); |
| } |
| |
| public EvlExecutor(IEvlModule module) { |
| super(module); |
| logger.info("Creating the EvlStandaloneEngine"); |
| } |
| |
| @Override |
| public void postProcess() { |
| logger.info("Retrieving unsatisfied Constraints."); |
| } |
| |
| @Override |
| protected Collection<UnsatisfiedConstraint> executeInternal() throws EolRuntimeException { |
| logger.info("Executing EVL script."); |
| return getModule().execute(); |
| } |
| |
| @Override |
| public void dispose() { |
| logger.info("Disposing engine."); |
| super.dispose(); |
| getResult().clear(); |
| } |
| |
| @Override |
| public IEvlModule getModule() { |
| return (IEvlModule) module; |
| } |
| |
| @SuppressWarnings("unchecked") |
| @Override |
| public Collection<UnsatisfiedConstraint> getResult() { |
| return (Collection<UnsatisfiedConstraint>) result; |
| } |
| |
| /** |
| * Prints the validation results. |
| */ |
| // FIXME Make a nicer print method!, e.g. something like log entries that can be consumed by other APIs |
| @Override |
| public void printResult() { |
| IEvlContext context = getModule().getContext(); |
| Set<UnsatisfiedConstraint> unsatisfiedConstraints = context.getUnsatisfiedConstraints(); |
| int numUnsatisfied = unsatisfiedConstraints.size(); |
| if (numUnsatisfied > 0) { |
| logger.warn(String.format("There %s %s unsatisfied Constraint(s).", |
| numUnsatisfied > 1 ? "were" : "was", |
| numUnsatisfied)); |
| for (UnsatisfiedConstraint uc : unsatisfiedConstraints) { |
| if (uc.getConstraint().isCritique()) { |
| logger.warn(uc.getMessage()); |
| } |
| else { |
| logger.error(uc.getMessage()); |
| } |
| } |
| } |
| else { |
| logger.info("All constraints have been satisfied."); |
| } |
| } |
| |
| } |