Search in sources :

Example 11 with KiePath

use of org.kie.memorycompiler.resources.KiePath in project drools by kiegroup.

the class DiskResourceReader method getModifiedResourcesSinceLastMark.

public Collection<String> getModifiedResourcesSinceLastMark() {
    Set<String> modifiedResources = new HashSet<String>();
    Map<KiePath, Integer> newHashing = hashFiles();
    for (Map.Entry<KiePath, Integer> entry : newHashing.entrySet()) {
        Integer oldHashing = filesHashing.get(entry.getKey());
        if (oldHashing == null || !oldHashing.equals(entry.getValue())) {
            modifiedResources.add(entry.getKey().asString());
        }
    }
    for (KiePath oldFile : filesHashing.keySet()) {
        if (!newHashing.containsKey(oldFile)) {
            modifiedResources.add(oldFile.asString());
        }
    }
    return modifiedResources;
}
Also used : KiePath(org.kie.memorycompiler.resources.KiePath) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 12 with KiePath

use of org.kie.memorycompiler.resources.KiePath in project drools by kiegroup.

the class ModelWriter method writeModel.

public Result writeModel(MemoryFileSystem srcMfs, Collection<PackageSources> packageSources) {
    List<GeneratedFile> generatedFiles = new ArrayList<>();
    List<String> modelFiles = new ArrayList<>();
    for (PackageSources pkgSources : packageSources) {
        pkgSources.collectGeneratedFiles(generatedFiles);
        modelFiles.addAll(pkgSources.getModelNames());
    }
    List<String> sourceFiles = new ArrayList<>();
    for (GeneratedFile generatedFile : generatedFiles) {
        KiePath path = basePath.resolve(generatedFile.getKiePath());
        sourceFiles.add(path.asString());
        srcMfs.write(path, generatedFile.getData());
    }
    return new Result(sourceFiles, modelFiles);
}
Also used : ArrayList(java.util.ArrayList) KiePath(org.kie.memorycompiler.resources.KiePath)

Example 13 with KiePath

use of org.kie.memorycompiler.resources.KiePath in project drools by kiegroup.

the class KieMemoryCompiler method compileNoLoad.

/**
 * Compile the given sources and returns the generated byte codes.
 * Additional compiler settings can be provided using JavaCompilerSettings
 *
 * @param classNameSourceMap
 * @param classLoader
 * @param compilerSettings
 * @return
 */
public static Map<String, byte[]> compileNoLoad(Map<String, String> classNameSourceMap, ClassLoader classLoader, JavaCompilerSettings compilerSettings, JavaConfiguration.CompilerType compilerType) {
    MemoryResourceReader reader = new MemoryResourceReader();
    MemoryResourceStore store = new MemoryResourceStore();
    String[] classNames = new String[classNameSourceMap.size()];
    int i = 0;
    for (Map.Entry<String, String> entry : classNameSourceMap.entrySet()) {
        classNames[i] = toJavaSource(entry.getKey());
        reader.add(classNames[i], entry.getValue().getBytes());
        i++;
    }
    JavaConfiguration javaConfiguration = new JavaConfiguration();
    javaConfiguration.setCompiler(compilerType);
    javaConfiguration.setJavaLanguageLevel(findJavaVersion());
    JavaCompiler compiler = JavaCompilerFactory.loadCompiler(javaConfiguration);
    CompilationResult res = compilerSettings == null ? compiler.compile(classNames, reader, store, classLoader) : compiler.compile(classNames, reader, store, classLoader, compilerSettings);
    if (res.getErrors().length > 0) {
        throw new KieMemoryCompilerException(Arrays.toString(res.getErrors()));
    }
    Map<String, byte[]> toReturn = new HashMap<>();
    for (Map.Entry<KiePath, byte[]> entry : store.getResources().entrySet()) {
        toReturn.put(toClassName(entry.getKey().asString()), entry.getValue());
    }
    return toReturn;
}
Also used : HashMap(java.util.HashMap) MemoryResourceStore(org.kie.memorycompiler.resources.MemoryResourceStore) MemoryResourceReader(org.kie.memorycompiler.resources.MemoryResourceReader) KiePath(org.kie.memorycompiler.resources.KiePath) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

KiePath (org.kie.memorycompiler.resources.KiePath)13 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 File (org.drools.compiler.compiler.io.File)2 Folder (org.drools.compiler.compiler.io.Folder)2 MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)2 CompilationProblem (org.kie.memorycompiler.CompilationProblem)2 CompilationResult (org.kie.memorycompiler.CompilationResult)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 URLDecoder (java.net.URLDecoder)1 Collection (java.util.Collection)1 List (java.util.List)1 Locale (java.util.Locale)1 StringTokenizer (java.util.StringTokenizer)1