Search in sources :

Example 56 with ReleaseId

use of org.kie.api.builder.ReleaseId in project drools by kiegroup.

the class ClasspathKieProjectTest method checkPomProperties.

private void checkPomProperties(final String pomProperties, final String expectedGroupId, final String expectedVersion) {
    Assertions.assertThat(pomProperties).isNotNull();
    final ReleaseId actualReleaseId = ReleaseIdImpl.fromPropertiesString(pomProperties);
    Assertions.assertThat(actualReleaseId.getGroupId()).isEqualTo(expectedGroupId);
    Assertions.assertThat(actualReleaseId.getVersion()).isEqualTo(expectedVersion);
}
Also used : ReleaseId(org.kie.api.builder.ReleaseId)

Example 57 with ReleaseId

use of org.kie.api.builder.ReleaseId in project drools by kiegroup.

the class KieProjectRuntimeModulesTest method createModuleAndFindResources.

@Test
public void createModuleAndFindResources() throws IOException, ClassNotFoundException, InterruptedException {
    createKieModule("fol4", false);
    ReleaseId releaseId = KieServices.Factory.get().newReleaseId("fol4", "art1", "1.0-SNAPSHOT");
    KieContainer kieContainer = KieServices.Factory.get().newKieContainer(releaseId);
    assertNotNull(kieContainer);
    InputStream is = kieContainer.getClassLoader().getResourceAsStream("/META-INF/beans.xml");
    assertNotNull(is);
    byte[] bytesFromStream = readBytesFromInputStream(is);
    Enumeration<URL> foundResources = kieContainer.getClassLoader().getResources("/META-INF/beans.xml");
    assertNotNull(foundResources);
    List<URL> resourcesAsList = Collections.list(foundResources);
    assertNotNull(resourcesAsList);
    assertEquals(1, resourcesAsList.size());
    URL resourceUrl = resourcesAsList.get(0);
    byte[] bytesFromURL = readBytesFromInputStream(resourceUrl.openStream());
    assertTrue(Arrays.equals(bytesFromStream, bytesFromURL));
    String url = resourceUrl.toString();
    assertNotNull(url);
    assertEquals("mfs:/META-INF/beans.xml", url);
    String file = resourceUrl.getFile();
    assertNotNull(file);
    assertEquals("/META-INF/beans.xml", file);
}
Also used : IoUtils.readBytesFromInputStream(org.drools.core.util.IoUtils.readBytesFromInputStream) InputStream(java.io.InputStream) ReleaseId(org.kie.api.builder.ReleaseId) URL(java.net.URL) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 58 with ReleaseId

use of org.kie.api.builder.ReleaseId in project drools by kiegroup.

the class KieBuilderImpl method buildAll.

public KieBuilder buildAll(BiFunction<InternalKieModule, ClassLoader, KieModuleKieProject> kprojectSupplier, Predicate<String> classFilter) {
    PomModel pomModel = init();
    // kModuleModel will be null if a provided pom.xml or kmodule.xml is invalid
    if (!isBuilt() && kModuleModel != null) {
        trgMfs = new MemoryFileSystem();
        writePomAndKModule();
        addKBasesFilesToTrg();
        markSource();
        MemoryKieModule memoryKieModule = new MemoryKieModule(adapt(releaseId), kModuleModel, trgMfs);
        if (kieDependencies != null && !kieDependencies.isEmpty()) {
            for (KieModule kieModule : kieDependencies) {
                memoryKieModule.addKieDependency((InternalKieModule) kieModule);
            }
        }
        if (pomModel != null) {
            memoryKieModule.setPomModel(pomModel);
        }
        KieModuleKieProject kProject = kprojectSupplier.apply(memoryKieModule, classLoader);
        for (ReleaseId unresolvedDep : memoryKieModule.getUnresolvedDependencies()) {
            results.addMessage(Level.ERROR, "pom.xml", "Unresolved dependency " + unresolvedDep);
        }
        List<String> pmmlFileNames = getPmmlFileNames(srcMfs);
        if (pmmlFileNames != null && !pmmlFileNames.isEmpty()) {
            buildPMMLPojos(pmmlFileNames, kProject);
        }
        compileJavaClasses(kProject.getClassLoader(), classFilter);
        buildKieProject(results, kProject, trgMfs);
        kModule = kProject.getInternalKieModule();
    }
    return this;
}
Also used : MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) PomModel(org.appformer.maven.support.PomModel) AFReleaseId(org.appformer.maven.support.AFReleaseId) ReleaseId(org.kie.api.builder.ReleaseId) KieModule(org.kie.api.builder.KieModule)

Example 59 with ReleaseId

use of org.kie.api.builder.ReleaseId in project drools by kiegroup.

the class KieContainerImpl method updateDependencyToVersion.

public Results updateDependencyToVersion(ReleaseId currentReleaseId, ReleaseId newReleaseId) {
    ReleaseId installedReleaseId = getReleaseId();
    if (currentReleaseId.getGroupId().equals(installedReleaseId.getGroupId()) && currentReleaseId.getArtifactId().equals(installedReleaseId.getArtifactId())) {
        // upgrading the kProject itself: taking the kmodule from there
        return updateToVersion(newReleaseId);
    }
    checkNotClasspathKieProject();
    // upgrading a transitive dependency: taking the kmodule from the krepo
    // if the new and the current release are equal (a snapshot) check if there is an older version with the same releaseId
    InternalKieModule currentKM = currentReleaseId.equals(newReleaseId) ? (InternalKieModule) ((KieRepositoryImpl) kr).getOldKieModule(currentReleaseId) : (InternalKieModule) kr.getKieModule(currentReleaseId);
    return update(currentKM, newReleaseId);
}
Also used : ReleaseId(org.kie.api.builder.ReleaseId)

Example 60 with ReleaseId

use of org.kie.api.builder.ReleaseId in project drools by kiegroup.

the class KieModuleKieProject method updateToModule.

public Map<String, KieBaseModel> updateToModule(InternalKieModule updatedKieModule) {
    Map<String, KieBaseModel> oldKieBaseModels = new HashMap<String, KieBaseModel>();
    oldKieBaseModels.putAll(kBaseModels);
    this.kieModules = null;
    this.kJarFromKBaseName.clear();
    ReleaseId currentReleaseId = this.kieModule.getReleaseId();
    ReleaseId updatingReleaseId = updatedKieModule.getReleaseId();
    if (currentReleaseId.getGroupId().equals(updatingReleaseId.getGroupId()) && currentReleaseId.getArtifactId().equals(updatingReleaseId.getArtifactId())) {
        this.kieModule = updatedKieModule;
    } else if (this.kieModule.getKieDependencies().keySet().contains(updatingReleaseId)) {
        this.kieModule.addKieDependency(updatedKieModule);
    }
    synchronized (this) {
        cleanIndex();
        // this might override class definitions, not sure we can do it any other way though
        init();
        // reset resource provider so it will serve resources from updated kmodule
        this.cl.setResourceProvider(kieModule.createResourceProvider());
    }
    return oldKieBaseModels;
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) HashMap(java.util.HashMap) ReleaseId(org.kie.api.builder.ReleaseId)

Aggregations

ReleaseId (org.kie.api.builder.ReleaseId)273 Test (org.junit.Test)219 KieServices (org.kie.api.KieServices)214 KieContainer (org.kie.api.runtime.KieContainer)176 KieSession (org.kie.api.runtime.KieSession)137 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)117 KieModule (org.kie.api.builder.KieModule)84 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)73 KieFileSystem (org.kie.api.builder.KieFileSystem)64 KieModuleModel (org.kie.api.builder.model.KieModuleModel)40 KieBuilder (org.kie.api.builder.KieBuilder)34 ArrayList (java.util.ArrayList)32 Message (org.drools.compiler.Message)32 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)27 Resource (org.kie.api.io.Resource)23 Results (org.kie.api.builder.Results)20 KieBaseModel (org.kie.api.builder.model.KieBaseModel)20 InternalKieScanner (org.drools.compiler.kie.builder.impl.InternalKieScanner)18 KieScanner (org.kie.api.builder.KieScanner)18 IncrementalResults (org.kie.internal.builder.IncrementalResults)18