Search in sources :

Example 1 with CheckConfiguration

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);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI) FileInputStream(java.io.FileInputStream) CheckConfiguration(com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration) IPathVariableManager(org.eclipse.core.resources.IPathVariableManager) CoreException(org.eclipse.core.runtime.CoreException) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IWorkspace(org.eclipse.core.resources.IWorkspace) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 2 with CheckConfiguration

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);
}
Also used : CheckConfiguration(com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration) Test(org.junit.Test)

Example 3 with CheckConfiguration

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);
        }
    }
}
Also used : TemplateProposal(org.eclipse.jface.text.templates.TemplateProposal) CheckConfiguration(com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Template(org.eclipse.jface.text.templates.Template)

Example 4 with CheckConfiguration

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());
        }
    }
}
Also used : CheckConfiguration(com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration) ConfiguredCatalog(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog) ConfiguredLanguageValidator(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredLanguageValidator) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck) Check(com.avaloq.tools.ddk.check.check.Check) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)

Example 5 with CheckConfiguration

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);
}
Also used : CheckConfiguration(com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration) ConfiguredCatalog(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog) EList(org.eclipse.emf.common.util.EList) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog)

Aggregations

CheckConfiguration (com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration)5 CheckCatalog (com.avaloq.tools.ddk.check.check.CheckCatalog)2 ConfiguredCatalog (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog)2 ConfiguredCheck (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)2 Check (com.avaloq.tools.ddk.check.check.Check)1 ConfiguredLanguageValidator (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredLanguageValidator)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 IFile (org.eclipse.core.resources.IFile)1 IPathVariableManager (org.eclipse.core.resources.IPathVariableManager)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 CoreException (org.eclipse.core.runtime.CoreException)1 EList (org.eclipse.emf.common.util.EList)1 URI (org.eclipse.emf.common.util.URI)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 Template (org.eclipse.jface.text.templates.Template)1 TemplateProposal (org.eclipse.jface.text.templates.TemplateProposal)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1