Search in sources :

Example 1 with ResourceType

use of io.automatiko.engine.api.io.ResourceType in project automatiko-engine by automatiko-io.

the class ProcessCodegen method ofPath.

public static ProcessCodegen ofPath(List<String> dependencies, Path... paths) throws IOException {
    List<Process> allProcesses = new ArrayList<>();
    for (String dependency : dependencies) {
        File file = new File(dependency);
        if (file.isDirectory()) {
            try (Stream<Path> filesStream = Files.walk(file.toPath())) {
                List<File> files = filesStream.filter(p -> SUPPORTED_BPMN_EXTENSIONS.stream().anyMatch(p.toString()::endsWith) || SUPPORTED_SW_EXTENSIONS.keySet().stream().anyMatch(p.toString()::endsWith)).map(Path::toFile).collect(Collectors.toList());
                allProcesses.addAll(parseProcesses(files, true));
            }
        } else {
            try (ZipFile zipFile = new ZipFile(dependency)) {
                Enumeration<? extends ZipEntry> entries = zipFile.entries();
                while (entries.hasMoreElements()) {
                    ZipEntry entry = entries.nextElement();
                    ResourceType resourceType = determineResourceType(entry.getName());
                    if (SUPPORTED_BPMN_EXTENSIONS.stream().anyMatch(entry.getName()::endsWith)) {
                        InternalResource resource = new ByteArrayResource(readBytesFromInputStream(zipFile.getInputStream(entry)));
                        resource.setResourceType(resourceType);
                        resource.setSourcePath(entry.getName());
                        allProcesses.addAll(parseProcessFile(resource));
                    }
                }
            } catch (IOException e) {
            }
        }
    }
    for (Path path : paths) {
        Path srcPath = Paths.get(path.toString());
        try (Stream<Path> filesStream = Files.walk(srcPath)) {
            List<File> files = filesStream.filter(p -> SUPPORTED_BPMN_EXTENSIONS.stream().anyMatch(p.toString()::endsWith) || SUPPORTED_SW_EXTENSIONS.keySet().stream().anyMatch(p.toString()::endsWith)).map(Path::toFile).collect(Collectors.toList());
            allProcesses.addAll(parseProcesses(files, false));
        }
    }
    return ofProcesses(allProcesses);
}
Also used : Path(java.nio.file.Path) InternalResource(io.automatiko.engine.services.io.InternalResource) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) Process(io.automatiko.engine.api.definition.process.Process) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) ResourceType.determineResourceType(io.automatiko.engine.api.io.ResourceType.determineResourceType) ResourceType(io.automatiko.engine.api.io.ResourceType) ByteArrayResource(io.automatiko.engine.services.io.ByteArrayResource) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) ZipFile(java.util.zip.ZipFile) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile) File(java.io.File)

Example 2 with ResourceType

use of io.automatiko.engine.api.io.ResourceType in project automatiko-engine by automatiko-io.

the class ProcessCodegen method ofJar.

public static ProcessCodegen ofJar(List<String> dependencies, Path... jarPaths) {
    List<Process> processes = new ArrayList<>();
    for (Path jarPath : jarPaths) {
        try (ZipFile zipFile = new ZipFile(jarPath.toFile())) {
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                ResourceType resourceType = determineResourceType(entry.getName());
                if (SUPPORTED_BPMN_EXTENSIONS.stream().anyMatch(entry.getName()::endsWith)) {
                    InternalResource resource = new ByteArrayResource(readBytesFromInputStream(zipFile.getInputStream(entry)));
                    resource.setResourceType(resourceType);
                    resource.setSourcePath(entry.getName());
                    processes.addAll(parseProcessFile(resource));
                }
            }
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
    for (String dependency : dependencies) {
        try (ZipFile zipFile = new ZipFile(dependency)) {
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                ResourceType resourceType = determineResourceType(entry.getName());
                if (SUPPORTED_BPMN_EXTENSIONS.stream().anyMatch(entry.getName()::endsWith)) {
                    InternalResource resource = new ByteArrayResource(readBytesFromInputStream(zipFile.getInputStream(entry)));
                    resource.setResourceType(resourceType);
                    resource.setSourcePath(entry.getName());
                    processes.addAll(parseProcessFile(resource));
                }
            }
        } catch (IOException e) {
        }
    }
    return ofProcesses(processes);
}
Also used : Path(java.nio.file.Path) InternalResource(io.automatiko.engine.services.io.InternalResource) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) Process(io.automatiko.engine.api.definition.process.Process) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) ResourceType.determineResourceType(io.automatiko.engine.api.io.ResourceType.determineResourceType) ResourceType(io.automatiko.engine.api.io.ResourceType) UncheckedIOException(java.io.UncheckedIOException) ByteArrayResource(io.automatiko.engine.services.io.ByteArrayResource) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile)

Aggregations

Process (io.automatiko.engine.api.definition.process.Process)2 WorkflowProcess (io.automatiko.engine.api.definition.process.WorkflowProcess)2 ResourceType (io.automatiko.engine.api.io.ResourceType)2 ResourceType.determineResourceType (io.automatiko.engine.api.io.ResourceType.determineResourceType)2 ByteArrayResource (io.automatiko.engine.services.io.ByteArrayResource)2 InternalResource (io.automatiko.engine.services.io.InternalResource)2 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 ZipEntry (java.util.zip.ZipEntry)2 ZipFile (java.util.zip.ZipFile)2 GeneratedFile (io.automatiko.engine.codegen.GeneratedFile)1 File (java.io.File)1