Package org.kie.api.builder

Examples of org.kie.api.builder.KieFileSystem


            fos.close();
        } catch ( IOException e ) {
            throw new RuntimeException( e );
        }

        KieFileSystem kfs = ks.newKieFileSystem();
        kfs.writePomXML( getPom( releaseId ) );
        kfs.write( "src/main/java/org/kie/test/Bean.java",
                   createJavaSourceInPackage() );

        KieBuilder kieBuilder1 = ks.newKieBuilder( kfs );
        Assert.assertTrue( kieBuilder1.buildAll().getResults().getMessages().isEmpty() );
        InternalKieModule kieModule = (InternalKieModule) kieBuilder1.getKieModule();

        MavenRepository.getMavenRepository().deployArtifact( releaseId,
                                                             kieModule,
                                                             pomFile );

        //Build a second KieModule, depends on the first KieModule jar which we have deployed into Maven
        ReleaseId releaseId2 = ks.newReleaseId( "org.kie",
                                                "metadata-test-using-pom",
                                                "1.0-SNAPSHOT" );
        String pomText2 = getPom( releaseId2,
                                  releaseId );
        File pomFile2 = new File( System.getProperty( "java.io.tmpdir" ),
                                  MavenRepository.toFileName( releaseId2, null ) + ".pom" );
        try {
            FileOutputStream fos = new FileOutputStream( pomFile2 );
            fos.write( pomText2.getBytes() );
            fos.flush();
            fos.close();
        } catch ( IOException e ) {
            throw new RuntimeException( e );
        }

        //Try building the second KieModule
        KieServices kieServices = KieServices.Factory.get();
        KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
        InputStream is = new FileInputStream( pomFile2 );
        KieModuleModel kproj2 = ks.newKieModuleModel();

        kieFileSystem.write( "pom.xml",
                             KieServices.Factory.get().getResources().newInputStreamResource( is ) );
        kieFileSystem.writeKModuleXML( kproj2.toXML() );
        kieFileSystem.write( "src/main/resources/rule.drl",
                             createDRLWithImport( "rule1" ) );
        KieBuilder kieBuilder = kieServices.newKieBuilder( kieFileSystem );
        kieBuilder.buildAll();
        assertTrue( kieBuilder.getResults().getMessages().isEmpty() );
    }
View Full Code Here


                "then\n" +
                "end\n";

        KieServices ks = KieServices.Factory.get();

        KieFileSystem kfs = ks.newKieFileSystem()
                .write("src/main/resources/r1.drl", drl1)
                .write("src/main/resources/r2.drl", drl2);

        KieBuilder kieBuilder = ks.newKieBuilder( kfs ).buildAll();

        assertEquals(2, getRuleNames(kieBuilder).get("org.kie.scanner").size());

        kfs.delete("src/main/resources/r2.drl");

        IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();

        assertEquals(1, getRuleNames(kieBuilder).get("org.kie.scanner").size());
    }
View Full Code Here

        KieServices ks = KieServices.Factory.get();

        //Malformed POM - No Version information
        ReleaseId releaseId = ks.newReleaseId( "org.kie", "incremental-test-with-invalid pom", "" );

        KieFileSystem kfs = createKieFileSystemWithKProject( ks );
        kfs.writePomXML( getPom( releaseId ) );

        //Valid
        String drl1 =
                "rule R1 when\n" +
                        "   $s : String()\n" +
                        "then\n" +
                        "end\n";

        //Invalid
        String drl2 =
                "rule R2 when\n" +
                        "   $s : Strin( )\n" +
                        "then\n" +
                        "end\n";

        //Write Rule 1 - No DRL errors, but POM is in error
        kfs.write( "src/main/resources/KBase1/r1.drl", drl1 );
        KieBuilder kieBuilder = ks.newKieBuilder( kfs ).buildAll();
        assertEquals( 1,
                kieBuilder.getResults().getMessages( org.kie.api.builder.Message.Level.ERROR ).size() );

        //Add file with error - expect 1 "added" error message
        kfs.write( "src/main/resources/KBase1/r2.drl", drl2 );
        IncrementalResults addResults = ( (InternalKieBuilder) kieBuilder ).createFileSet( "src/main/resources/KBase1/r2.drl" ).build();

        assertEquals( 1, addResults.getAddedMessages().size() );
        assertEquals( 0, addResults.getRemovedMessages().size() );
    }
View Full Code Here

    public void testKieModuleMetaDataInMemoryWithJavaClassDefaultPackage() throws Exception {
        final KieServices ks = KieServices.Factory.get();
        final ReleaseId releaseId = ks.newReleaseId( "org.kie", "javaDefaultPackage", "1.0-SNAPSHOT" );
        final KieModuleModel kproj = ks.newKieModuleModel();

        final KieFileSystem kfs = ks.newKieFileSystem();
        kfs.writeKModuleXML( kproj.toXML() )
                .writePomXML( generatePomXml( releaseId ) )
                .write( "src/main/java/test/Bean.java", createJavaSource() );

        final KieBuilder kieBuilder = ks.newKieBuilder( kfs );
        final List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
View Full Code Here

    @Test
    public void testGetPackageNames() {
        final KieServices ks = KieServices.Factory.get();

        final KieFileSystem kfs = ks.newKieFileSystem();
        kfs.write( "src/main/resources/test.drl",
                   "package org.test declare Bean end" );

        final KieBuilder kieBuilder = ks.newKieBuilder( kfs );
        final List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
        assertTrue( messages.isEmpty() );
View Full Code Here

    @Test
    public void testGetRuleNames() {
        final KieServices ks = KieServices.Factory.get();

        final KieFileSystem kfs = ks.newKieFileSystem();
        kfs.write( "src/main/resources/test1.drl",
                   "package org.test\n" +
                           "rule A\n" +
                           " when\n" +
                           "then\n" +
                           "end\n" +
                           "rule B\n" +
                           " when\n" +
                           "then\n" +
                           "end\n" );
        kfs.write( "src/main/resources/test2.drl",
                   "package org.test\n" +
                           "rule C\n" +
                           " when\n" +
                           "then\n" +
                           "end\n" );
View Full Code Here

        // According to https://bugzilla.redhat.com/show_bug.cgi?id=1049674#c2 the below is the minimal POM required to use KieMavenPlugin.
        // However when we attempt to retrieve meta-data about the classes in the KieModule some are not accessible. IDK whether the minimal
        // POM is correct; or whether KieModuleMetaData needs to ignore certain classes (e.g. if a transient dependency is optional?!?)
        final KieServices ks = KieServices.Factory.get();

        final KieFileSystem kfs = ks.newKieFileSystem();
        kfs.write( "pom.xml",
                   "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                           + "<project xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
                           + "<modelVersion>4.0.0</modelVersion>"
                           + "<groupId>org.kie</groupId>"
                           + "<artifactId>plugin-test</artifactId>"
                           + "<version>1.0</version>"
                           + "<packaging>kjar</packaging>"
                           + "<dependencies>"
                           + "<dependency>"
                           + "<groupId>org.drools</groupId>"
                           + "<artifactId>drools-compiler</artifactId>"
                           + "<version>6.1.0-SNAPSHOT</version>"
                           + "</dependency>"
                           + "</dependencies>"
                           + "<build>"
                           + "<plugins>"
                           + "<plugin>"
                           + "<groupId>org.kie</groupId>"
                           + "<artifactId>kie-maven-plugin</artifactId>"
                           + "<version>6.1.0-SNAPSHOT</version>"
                           + "<extensions>true</extensions>"
                           + "</plugin>"
                           + "</plugins>"
                           + "</build>"
                           + "</project>" );

        kfs.write("/src/main/resources/META-INF/kmodule.xml",
                  "<kmodule xmlns=\"http://jboss.org/kie/6.0.0/kmodule\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>");

        final KieBuilder kieBuilder = ks.newKieBuilder( kfs );
        final List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
        assertTrue( messages.isEmpty() );
View Full Code Here

                "  @role(event)\n" +
                "end";

        KieServices ks = KieServices.Factory.get();

        KieFileSystem kfs = ks.newKieFileSystem()
                .write( "src/main/java/org/drools/compiler/Bean.java", declaration )
                .write( "src/main/resources/bean1.drl", drl );

        final KieBuilder kieBuilder = ks.newKieBuilder( kfs );
        final KieModule kieModule = kieBuilder.buildAll().getKieModule();
View Full Code Here

                "  @role(event)\n" +
                "end";

        KieServices ks = KieServices.Factory.get();

        KieFileSystem kfs = ks.newKieFileSystem()
                .write( "src/main/java/org/drools/compiler/Bean.java", declaration )
                .write( "src/main/resources/bean1.drl", drl );

        final KieBuilder kieBuilder = ks.newKieBuilder( kfs );
        final KieModule kieModule = kieBuilder.buildAll().getKieModule();
View Full Code Here

                "  @role(event)\n" +
                "end";

        KieServices ks = KieServices.Factory.get();

        KieFileSystem kfs = ks.newKieFileSystem()
                .write( "src/main/java/org/drools/compiler/Bean.java", declaration )
                .write( "src/main/resources/bean1.drl", drl );

        final KieBuilder kieBuilder = ks.newKieBuilder( kfs );
        final KieModule kieModule = kieBuilder.buildAll().getKieModule();
View Full Code Here

TOP

Related Classes of org.kie.api.builder.KieFileSystem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.