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);
}
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);
}
Aggregations