Search in sources :

Example 6 with ChainedProperties

use of org.kie.internal.utils.ChainedProperties in project droolsjbpm-integration by kiegroup.

the class AbstractDMNValidationAwareMojo method computeDMNProfiles.

protected List<DMNProfile> computeDMNProfiles() throws MojoExecutionException {
    ClassLoader classLoader = ClassLoaderUtil.findDefaultClassLoader();
    ChainedProperties chainedProperties = ChainedProperties.getChainedProperties(classLoader);
    List<KieModuleModel> kieModules = new ArrayList<>();
    for (Path p : resourcesPaths()) {
        try (Stream<Path> walk = Files.walk(p)) {
            List<Path> collect = walk.filter(f -> f.toString().endsWith("kmodule.xml")).collect(Collectors.toList());
            for (Path k : collect) {
                kieModules.add(KieModuleModelImpl.fromXML(k.toFile()));
            }
        } catch (Exception e) {
            throw new MojoExecutionException("Failed executing AbstractDMNValidationAwareMojo while computing DMNProfile(s)", e);
        }
    }
    for (KieModuleModel kmm : kieModules) {
        Properties ps = new Properties();
        ps.putAll(kmm.getConfigurationProperties());
        chainedProperties.addProperties(ps);
    }
    List<DMNProfile> dmnProfiles = new ArrayList<>();
    dmnProfiles.addAll(DMNAssemblerService.getDefaultDMNProfiles(chainedProperties));
    try {
        Map<String, String> dmnProfileProperties = new HashMap<>();
        chainedProperties.mapStartsWith(dmnProfileProperties, DMNAssemblerService.DMN_PROFILE_PREFIX, false);
        for (Map.Entry<String, String> dmnProfileProperty : dmnProfileProperties.entrySet()) {
            DMNProfile dmnProfile = (DMNProfile) classLoader.loadClass(dmnProfileProperty.getValue()).newInstance();
            dmnProfiles.add(dmnProfile);
        }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new MojoExecutionException("Failed executing AbstractDMNValidationAwareMojo while computing DMNProfile(s)", e);
    }
    return dmnProfiles;
}
Also used : Path(java.nio.file.Path) ResourceTypePackage(org.kie.api.internal.io.ResourceTypePackage) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) Arrays(java.util.Arrays) DMNMessage(org.kie.dmn.api.core.DMNMessage) ClassLoaderUtil(org.kie.dmn.feel.util.ClassLoaderUtil) HashMap(java.util.HashMap) Parameter(org.apache.maven.plugins.annotations.Parameter) ResourceType(org.kie.api.io.ResourceType) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Level(org.kie.api.builder.Message.Level) DMNModel(org.kie.dmn.api.core.DMNModel) Validation(org.kie.dmn.validation.DMNValidator.Validation) Map(java.util.Map) KiePackage(org.kie.api.definition.KiePackage) DMNAssemblerService(org.kie.dmn.core.assembler.DMNAssemblerService) Path(java.nio.file.Path) DMNProfile(org.kie.dmn.core.compiler.DMNProfile) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) KieModuleModelImpl(org.drools.compiler.kproject.models.KieModuleModelImpl) InternalDMNDTAnalyser(org.kie.dmn.validation.dtanalysis.InternalDMNDTAnalyser) Properties(java.util.Properties) Files(java.nio.file.Files) Collection(java.util.Collection) Set(java.util.Set) ChainedProperties(org.kie.internal.utils.ChainedProperties) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Collectors(java.util.stream.Collectors) File(java.io.File) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Consumer(java.util.function.Consumer) List(java.util.List) Stream(java.util.stream.Stream) Resource(org.apache.maven.model.Resource) KieModuleModel(org.kie.api.builder.model.KieModuleModel) ExecModelMode.modelParameterEnabled(org.kie.maven.plugin.ExecModelMode.modelParameterEnabled) InternalDMNDTAnalyserFactory(org.kie.dmn.validation.dtanalysis.InternalDMNDTAnalyserFactory) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Properties(java.util.Properties) ChainedProperties(org.kie.internal.utils.ChainedProperties) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) KieModuleModel(org.kie.api.builder.model.KieModuleModel) ChainedProperties(org.kie.internal.utils.ChainedProperties) HashMap(java.util.HashMap) Map(java.util.Map) DMNProfile(org.kie.dmn.core.compiler.DMNProfile)

Example 7 with ChainedProperties

use of org.kie.internal.utils.ChainedProperties in project drools by kiegroup.

the class ClassLevel method findJavaVersion.

private static void findJavaVersion(ClassLoader classLoader) {
    ChainedProperties chainedProperties = ChainedProperties.getChainedProperties(classLoader);
    if (chainedProperties.getProperty("drools.dialect.java", null) == null) {
        chainedProperties = ChainedProperties.getChainedProperties(ClassGenerator.class.getClassLoader());
    }
    javaVersion = findJavaVersion(chainedProperties);
}
Also used : ChainedProperties(org.kie.internal.utils.ChainedProperties)

Example 8 with ChainedProperties

use of org.kie.internal.utils.ChainedProperties in project drools by kiegroup.

the class DMNAssemblerService method getDMNProfiles.

protected List<DMNProfile> getDMNProfiles(KnowledgeBuilderImpl kbuilderImpl) {
    ChainedProperties chainedProperties = kbuilderImpl.getBuilderConfiguration().getChainedProperties();
    List<DMNProfile> dmnProfiles = new ArrayList<>();
    dmnProfiles.addAll(getDefaultDMNProfiles(chainedProperties));
    Map<String, String> dmnProfileProperties = new HashMap<>();
    chainedProperties.mapStartsWith(dmnProfileProperties, DMN_PROFILE_PREFIX, false);
    if (!dmnProfileProperties.isEmpty()) {
        try {
            for (Map.Entry<String, String> dmnProfileProperty : dmnProfileProperties.entrySet()) {
                DMNProfile dmnProfile = (DMNProfile) kbuilderImpl.getRootClassLoader().loadClass(dmnProfileProperty.getValue()).newInstance();
                dmnProfiles.add(dmnProfile);
            }
            return dmnProfiles;
        } catch (Exception e) {
            kbuilderImpl.addBuilderResult(new DMNKnowledgeBuilderError(ResultSeverity.WARNING, "Trying to load a non-existing Kie DMN profile " + e.getLocalizedMessage()));
            logger.error("Trying to load a non-existing Kie DMN profile {}", e.getLocalizedMessage(), e);
            kbuilderImpl.addBuilderResult(new DMNKnowledgeBuilderError(ResultSeverity.WARNING, "DMN Compiler configuration contained errors, will fall-back using empty-configuration compiler."));
            logger.warn("DMN Compiler configuration contained errors, will fall-back using empty-configuration compiler.");
        }
    }
    return dmnProfiles;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ChainedProperties(org.kie.internal.utils.ChainedProperties) DMNKnowledgeBuilderError(org.kie.dmn.core.impl.DMNKnowledgeBuilderError) HashMap(java.util.HashMap) Map(java.util.Map) DMNProfile(org.kie.dmn.core.compiler.DMNProfile) ExtendedDMNProfile(org.kie.dmn.core.compiler.profiles.ExtendedDMNProfile)

Example 9 with ChainedProperties

use of org.kie.internal.utils.ChainedProperties in project jbpm by kiegroup.

the class EmailDeadlinesBaseTest method setup.

public void setup() {
    final ChainedProperties props = ChainedProperties.getChainedProperties("email.conf", ClassLoaderUtil.getClassLoader(null, getClass(), false));
    wiser = new Wiser();
    wiser.setHostname(props.getProperty("mail.smtp.host", "localhost"));
    wiser.setPort(Integer.parseInt(props.getProperty("mail.smtp.port", "2345")));
    wiser.start();
    try {
        Thread.sleep(1000);
    } catch (Throwable t) {
    // Do nothing
    }
}
Also used : Wiser(org.subethamail.wiser.Wiser) ChainedProperties(org.kie.internal.utils.ChainedProperties)

Aggregations

ChainedProperties (org.kie.internal.utils.ChainedProperties)9 Wiser (org.subethamail.wiser.Wiser)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Before (org.junit.Before)3 DMNProfile (org.kie.dmn.core.compiler.DMNProfile)3 List (java.util.List)2 Properties (java.util.Properties)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)2 ResourceType (org.kie.api.io.ResourceType)2 DMNModel (org.kie.dmn.api.core.DMNModel)2 DMNAssemblerService (org.kie.dmn.core.assembler.DMNAssemblerService)2 ClassLoaderUtil (org.kie.dmn.feel.util.ClassLoaderUtil)2 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1