use of com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration in project dsl-devkit by dsldevkit.
the class DeployJob method deployCheckConfiguration.
/**
* Creates a new instance of {@link DeployJob}.
*
* @throws DeployException
* a general deployment exception.
*/
private void deployCheckConfiguration() throws DeployException {
List<IFile> checkCfgFiles = getCheckConfigurationFiles();
if (checkCfgFiles.isEmpty()) {
return;
}
if (checkCfgFiles.size() != 1) {
showTooManyCheckConfigurationDialog();
return;
}
IFile file = checkCfgFiles.get(0);
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IPathVariableManager pathMan = workspace.getPathVariableManager();
if (pathMan.validateName(CheckCfgConstants.CHECK_CFG_VAR_NAME).isOK() && pathMan.validateValue(file.getFullPath()).isOK()) {
try {
pathMan.setURIValue(CheckCfgConstants.CHECK_CFG_VAR_NAME, file.getLocationURI());
} catch (CoreException e) {
LOGGER.error(NLS.bind(Messages.DeployJob_CouldNotSetPathVariable, CheckCfgConstants.CHECK_CFG_VAR_NAME));
throw new DeployException(e);
}
} else {
LOGGER.error(NLS.bind(Messages.DeployJob_CouldNotSetPathVariable, CheckCfgConstants.CHECK_CFG_VAR_NAME));
throw new DeployException();
}
XtextResourceSet rs = new XtextResourceSet();
String uriString = pathMan.getURIValue(CheckCfgConstants.CHECK_CFG_VAR_NAME).toString();
URI uri = URI.createURI(uriString, true);
Resource resource = rs.createResource(uri);
try {
resource.load(new FileInputStream(new File(pathMan.getURIValue(CheckCfgConstants.CHECK_CFG_VAR_NAME))), rs.getLoadOptions());
rs.getURIResourceMap().put(uri, resource);
EcoreUtil.resolveAll(resource);
CheckConfiguration checkConfig = (CheckConfiguration) resource.getContents().get(0);
assert checkConfig != null;
} catch (IOException e) {
LOGGER.error(NLS.bind(Messages.DeployJob_ExceptionWhileReadingTheCheckConfigurationFile, uriString), e);
throw new DeployException(e);
}
}
use of com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration in project dsl-devkit by dsldevkit.
the class CheckCfgValidationTest method testDisabledCheckIsNotConfigured.
/**
* Tests {@link CheckCfgJavaValidator#checkDisabledCheckIsNotConfigured(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)}.
* <p>
* A warning is raised if a disabled check has configured parameters.
* </p>
*
* @throws Exception
* if a problem occurred parsing the test model
*/
@Test
public void testDisabledCheckIsNotConfigured() throws Exception {
// NOPMD
CheckConfiguration model = parser.parse(modelUtil.basicModelWithDisabledTest() + " (val = 0)");
helper.assertWarning(model, CheckcfgPackage.Literals.CONFIGURED_CHECK, IssueCodes.DISABLED_CHECK_NOT_CONFIGURED);
}
use of com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration in project dsl-devkit by dsldevkit.
the class CheckCfgTemplateProposalProvider method addCatalogConfigurations.
/**
* Adds the populated check configuration.
*
* @param templateContext
* the template context
* @param context
* the context
* @param acceptor
* the acceptor
*/
@SuppressWarnings("all")
private void addCatalogConfigurations(final TemplateContext templateContext, final ContentAssistContext context, final ITemplateAcceptor acceptor) {
// $NON-NLS-1$
final String templateName = "Add all registered catalogs";
// $NON-NLS-1$
final String templateDescription = "configures all missing catalogs";
final String contextTypeId = templateContext.getContextType().getId();
if (context.getRootModel() instanceof CheckConfiguration) {
final CheckConfiguration conf = (CheckConfiguration) context.getRootModel();
List<IEObjectDescription> allElements = Lists.newArrayList(scopeProvider.getScope(conf, CheckcfgPackage.Literals.CONFIGURED_CATALOG__CATALOG).getAllElements());
StringBuilder builder = new StringBuilder();
for (IEObjectDescription description : allElements) {
if (description.getEObjectOrProxy() instanceof CheckCatalog) {
CheckCatalog catalog = (CheckCatalog) description.getEObjectOrProxy();
if (catalog.eIsProxy()) {
catalog = (CheckCatalog) EcoreUtil.resolve(catalog, conf);
}
if (isCatalogConfigured(conf, catalog)) {
continue;
} else if (allElements.indexOf(description) > 0) {
builder.append(Strings.newLine());
}
final String catalogName = qualifiedNameValueConverter.toString(description.getQualifiedName().toString());
// $NON-NLS-1$ //$NON-NLS-2$
builder.append("catalog ").append(catalogName).append(" {}").append(Strings.newLine());
}
}
if (builder.length() > 0) {
// $NON-NLS-1$
builder.append("${cursor}");
Template t = new Template(templateName, templateDescription, contextTypeId, builder.toString(), true);
TemplateProposal tp = createProposal(t, templateContext, context, images.forConfiguredCatalog(), getRelevance(t));
acceptor.accept(tp);
}
}
}
use of com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration in project dsl-devkit by dsldevkit.
the class CheckConfigurationPropertiesGenerator method generatePropertiesForCatalogsInConfigurableSection.
/**
* Generate properties for languages or legacy catalogs.
*
* @param section
* the section
* @param properties
* the properties
*/
private void generatePropertiesForCatalogsInConfigurableSection(final ConfigurableSection section, final Properties properties) {
String language = null;
EList<ConfiguredCatalog> configuredCatalogs = ECollections.emptyEList();
if (section instanceof CheckConfiguration) {
configuredCatalogs = ((CheckConfiguration) section).getLegacyCatalogConfigurations();
} else if (section instanceof ConfiguredLanguageValidator) {
language = ((ConfiguredLanguageValidator) section).getLanguage();
configuredCatalogs = ((ConfiguredLanguageValidator) section).getCatalogConfigurations();
}
for (ConfiguredCatalog catalog : configuredCatalogs) {
Set<Check> configuredChecks = Sets.newHashSet();
for (ConfiguredCheck configuredCheck : catalog.getCheckConfigurations()) {
generatePropertiesForConfiguredCheck(properties, language, configuredCheck);
configuredChecks.add(configuredCheck.getCheck());
}
for (Check unconfiguredCheck : Sets.difference(Sets.newHashSet(catalog.getCatalog().getAllChecks()), configuredChecks)) {
putInheritedProperties(properties, language, unconfiguredCheck, catalog, ECollections.emptyEList());
}
}
}
use of com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration in project dsl-devkit by dsldevkit.
the class CheckCfgScopeProvider method getScope.
@Override
public IScope getScope(final EObject context, final EReference reference) {
if (reference == CheckcfgPackage.Literals.CONFIGURED_CHECK__CHECK) {
// Note that context object can be either a configured check (if 'optional' keyword has been provided
// so that a new instance is created and the configured catalog does not contain any configured checks
// yet) or a configured catalog (in all other cases)
final ConfiguredCatalog configuredCatalog = EcoreUtil2.getContainerOfType(context, ConfiguredCatalog.class);
if (configuredCatalog == null || configuredCatalog.getCatalog() == null) {
return IScope.NULLSCOPE;
}
CheckCatalog catalog = configuredCatalog.getCatalog();
return Scopes.scopeFor(catalog.getAllChecks(), checkQualifiedNameProvider, IScope.NULLSCOPE);
} else if (reference == CheckcfgPackage.Literals.CONFIGURED_PARAMETER__PARAMETER) {
// a new list of FormalParameters to scope to
EList<FormalParameter> parameters = ECollections.newBasicEList();
final ConfiguredCheck configuredCheck = EcoreUtil2.getContainerOfType(context, ConfiguredCheck.class);
if (configuredCheck != null) {
// add FormalParameter definitions from linked check
parameters.addAll(configuredCheck.getCheck().getFormalParameters());
}
// add inferred FormalParameters (properties)
final CheckConfiguration checkConfiguration = EcoreUtil2.getContainerOfType(context, CheckConfiguration.class);
parameters.addAll(checkConfiguration.getProperties());
return Scopes.scopeFor(parameters, checkQualifiedNameProvider, IScope.NULLSCOPE);
}
return super.getScope(context, reference);
}
Aggregations