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

jiangxincode / ApkToolBoxGUI / #1137

23 Aug 2025 02:52AM UTC coverage: 2.94% (-0.01%) from 2.954%
#1137

push

jiangxincode
bugfix: cannot cancel immediately

0 of 47 new or added lines in 3 files covered. (0.0%)

2 existing lines in 2 files now uncovered.

236 of 8026 relevant lines covered (2.94%)

0.03 hits per line

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

0.0
/src/main/java/edu/jiangxin/apktoolbox/utils/RevealFileUtils.java
1
package edu.jiangxin.apktoolbox.utils;
2

3
import org.apache.logging.log4j.LogManager;
4
import org.apache.logging.log4j.Logger;
5

6
import java.awt.*;
7
import java.io.File;
8
import java.io.IOException;
9
import java.util.Arrays;
10
import java.util.List;
11

12
/**
13
 * Cross-platform helper for revealing a file or folder in the native file-manager.
14
 */
15
public final class RevealFileUtils {
NEW
16
    private static final Logger logger = LogManager.getLogger(RevealFileUtils.class.getSimpleName());
×
17

18
    private RevealFileUtils() {}
19

20
    /**
21
     * Opens the system file-manager and highlights the supplied file or folder.
22
     *
23
     * @param file the file or folder to reveal
24
     * @throws IOException if the file does not exist or the platform command fails
25
     */
26
    public static void revealFile(File file) {
NEW
27
        if (file == null) {
×
NEW
28
            logger.error("revealFile failed: file is null");
×
NEW
29
            return;
×
30
        }
NEW
31
        if (!file.exists()) {
×
NEW
32
            logger.error("revealFile failed: file does not exist: {}", file.getPath());
×
NEW
33
            return;
×
34
        }
35

NEW
36
        String os   = System.getProperty("os.name").toLowerCase();
×
NEW
37
        String path = file.getAbsolutePath();
×
38

39
        List<String> cmd;
40

41
        //https://stackoverflow.com/questions/32314645/java-processbuilder-command-arguments-with-spaces-and-double-quotes-fails
42
        //TODO: test with spaces and special characters in path
43

NEW
44
        if (os.contains("win")) {
×
45
            // Pass the whole flag as one token, already quoted.
NEW
46
            cmd = Arrays.asList("explorer.exe", "/select", path);
×
47

NEW
48
        } else if (os.contains("mac")) {
×
NEW
49
            cmd = Arrays.asList("open", "-R", path);   // open handles quoting internally
×
50

51
        } else {
52
            // Linux – DBus interface wants file:// URI, properly encoded
NEW
53
            String uri = "file://" + file.toURI().getRawPath();
×
NEW
54
            if (file.isDirectory()) {
×
55
                // Fallback: simply open the directory
NEW
56
                cmd = Arrays.asList("xdg-open", path);
×
57
            } else {
NEW
58
                cmd = Arrays.asList(
×
59
                        "dbus-send",
60
                        "--session",
61
                        "--dest=org.freedesktop.FileManager1",
62
                        "--type=method_call",
63
                        "/org/freedesktop/FileManager1",
64
                        "org.freedesktop.FileManager1.ShowItems",
65
                        "array:string:\"" + uri + "\"",
66
                        "string:\"\""
67
                );
68
            }
69
        }
NEW
70
        logger.info("revealFile cmd: {}", cmd);
×
71

72
        try {
NEW
73
            new ProcessBuilder(cmd).start();
×
NEW
74
        } catch (IOException e) {
×
NEW
75
            logger.error("revealFile failed: {}", e.getMessage());
×
NEW
76
        }
×
NEW
77
    }
×
78

79
    public static void revealDirectory(File file) {
NEW
80
        if (file == null) {
×
NEW
81
            logger.error("revealDirectory failed: file is null");
×
NEW
82
            return;
×
83
        }
NEW
84
        if (!file.exists()) {
×
NEW
85
            logger.error("revealDirectory failed: file does not exist: {}", file.getPath());
×
NEW
86
            return;
×
87
        }
NEW
88
        if (file.isDirectory()) {
×
89
            try {
NEW
90
                Desktop.getDesktop().open(file);
×
NEW
91
            } catch (IOException e) {
×
NEW
92
                logger.error("revealDirectory failed: {}", e.getMessage());
×
NEW
93
            }
×
94
        }
NEW
95
    }
×
96
}
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