• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kit-data-manager / ro-crate-java / #348

15 Apr 2025 08:24AM UTC coverage: 86.955%. First build
#348

Pull #233

github

web-flow
Merge pull request #244 from kit-data-manager/renovate/commons-io-commons-io-2.x

chore(deps): update dependency commons-io:commons-io to v2.19.0
Pull Request #233: Version 2.1.0

521 of 659 new or added lines in 18 files covered. (79.06%)

1873 of 2154 relevant lines covered (86.95%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.0
/src/main/java/edu/kit/datamanager/ro_crate/preview/PreviewGenerator.java
1
package edu.kit.datamanager.ro_crate.preview;
2

3
import java.io.BufferedReader;
4
import java.io.IOException;
5
import java.io.InputStreamReader;
6

7
/**
8
 * Class responsible for the generation of the human-readable representation of
9
 * the metadata. For this to work the nodejs library rochtml has to be
10
 * installed. This can be done using: npm install -g ro-crate-html-js or npm
11
 * install ro-crate-html-js
12
 */
13
public class PreviewGenerator {
×
14

15
    private static final String command = "rochtml";
16

17
    public static boolean isRochtmlAvailable() {
18
        ProcessBuilder builder = new ProcessBuilder();
1✔
19
        // this is the equivalent of "rochtml dir/ro-crate-metadata.json"
20
        // check if we are running on windows or unix
21
        String os = System.getProperty("os.name").toLowerCase();
1✔
22
        if (os.contains("win")) {
1✔
NEW
23
            builder.command("cmd.exe", "/c", command);
×
24

25
        } else {
26
            builder.command("sh", "-c", command);
1✔
27
        }
28
        Process process;
29
        try {
30
            process = builder.start();
1✔
31
            int exitVal = process.waitFor();
1✔
32
            return exitVal == 0;
1✔
NEW
33
        } catch (InterruptedException | IOException ex) {
×
34
        }
NEW
35
        return false;
×
36
    }
37

38
    /**
39
     * The method that from the location of the crate generates the html file.
40
     *
41
     * @param location the location of the crate in the filesystem.
42
     */
43
    public static void generatePreview(String location) {
44
        ProcessBuilder builder = new ProcessBuilder();
1✔
45
        // this is the equivalent of "rochtml dir/ro-crate-metadata.json"
46
        // check if we are running on windows or unix
47
        String os = System.getProperty("os.name").toLowerCase();
1✔
48
        if (os.contains("win")) {
1✔
NEW
49
            builder.command("cmd.exe", "/c", command + " " + location + "/ro-crate-metadata.json");
×
50

51
        } else {
52
            builder.command("sh", "-c", command + " " + location + "/ro-crate-metadata.json");
1✔
53
        }
54

55
        Process process;
56
        try {
57
            process = builder.start();
1✔
58
            StringBuilder output = new StringBuilder();
1✔
59

60
            BufferedReader reader = new BufferedReader(
1✔
61
                    new InputStreamReader(process.getInputStream()));
1✔
62

63
            String line;
64
            while ((line = reader.readLine()) != null) {
1✔
NEW
65
                output.append(line).append("\n");
×
66
            }
67
            reader.close();
1✔
68
            int exitVal = process.waitFor();
1✔
69
            if (exitVal != 0) {
1✔
70
                //abnormal...
NEW
71
                throw new Exception("failed command");
×
72
            }
NEW
73
        } catch (Exception e) {
×
NEW
74
            e.printStackTrace();
×
75
        }
1✔
76
    }
1✔
77
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc