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

mybatis / migrations / 717

23 May 2025 05:07PM UTC coverage: 80.917% (+0.04%) from 80.873%
717

push

github

web-flow
Merge pull request #448 from harawata/use-nio

Use NIO to make modernizer happy

692 of 986 branches covered (70.18%)

20 of 28 new or added lines in 11 files covered. (71.43%)

1836 of 2269 relevant lines covered (80.92%)

0.81 hits per line

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

89.29
/src/main/java/org/apache/ibatis/migration/utils/Util.java
1
/*
2
 *    Copyright 2010-2025 the original author or authors.
3
 *
4
 *    Licensed under the Apache License, Version 2.0 (the "License");
5
 *    you may not use this file except in compliance with the License.
6
 *    You may obtain a copy of the License at
7
 *
8
 *       https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *    Unless required by applicable law or agreed to in writing, software
11
 *    distributed under the License is distributed on an "AS IS" BASIS,
12
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *    See the License for the specific language governing permissions and
14
 *    limitations under the License.
15
 */
16
package org.apache.ibatis.migration.utils;
17

18
import java.io.File;
19
import java.io.InputStream;
20
import java.nio.file.Files;
21
import java.nio.file.Path;
22
import java.util.Properties;
23

24
public enum Util {
1✔
25
  ;
26

27
  private static final String MIGRATIONS_HOME = "MIGRATIONS_HOME";
28

29
  /* TODO: remove in the next major release */
30
  private static final String MIGRATIONS_HOME_PROPERTY_DEPRECATED = "migrationHome";
31

32
  private static final String MIGRATIONS_HOME_PROPERTY = "migrationsHome";
33

34
  private static final String MIGRATIONS_PROPERTIES = "migration.properties";
35

36
  public static String migrationsHome() {
37
    String migrationsHome = System.getenv(MIGRATIONS_HOME);
1✔
38
    // Check if there is a system property
39
    if (migrationsHome == null) {
1!
40
      migrationsHome = System.getProperty(MIGRATIONS_HOME_PROPERTY);
1✔
41
      if (migrationsHome == null) {
1✔
42
        migrationsHome = System.getProperty(MIGRATIONS_HOME_PROPERTY_DEPRECATED);
1✔
43
      }
44
    }
45
    return migrationsHome;
1✔
46
  }
47

48
  public static boolean getPropertyOptionAsBoolean(String key) {
49
    return Boolean.parseBoolean(getPropertyOption(key));
1✔
50
  }
51

52
  /**
53
   * @param key
54
   *          of the property.
55
   *
56
   * @return The value <code>null</code> if the property file does not exist or the <code>key</code> does not exist.
57
   */
58
  public static String getPropertyOption(String key) {
59
    String migrationsHome = migrationsHome();
1✔
60
    if (migrationsHome == null || migrationsHome.isEmpty()) {
1!
61
      return null;
1✔
62
    }
63
    Properties properties = new Properties();
1✔
64
    String path = migrationsHome + File.separator + MIGRATIONS_PROPERTIES;
1✔
NEW
65
    try (InputStream stream = Files.newInputStream(Path.of(path))) {
×
66
      properties.load(stream);
×
67
      return properties.getProperty(key);
×
68
    } catch (Exception e) {
1✔
69
      return null;
1✔
70
    }
71
  }
72

73
  public static boolean isOption(String arg) {
74
    return arg.startsWith("--") && !arg.trim().endsWith("=");
1✔
75
  }
76

77
  public static File file(File path, String fileName) {
78
    return Path.of(path.getAbsolutePath() + File.separator + fileName).toFile();
1✔
79
  }
80

81
  public static String horizontalLine(String caption, int length) {
82
    StringBuilder builder = new StringBuilder();
1✔
83
    builder.append("==========");
1✔
84
    if (caption.length() > 0) {
1✔
85
      caption = " " + caption + " ";
1✔
86
      builder.append(caption);
1✔
87
    }
88
    for (int i = 0; i < length - caption.length() - 10; i++) {
1✔
89
      builder.append("=");
1✔
90
    }
91
    return builder.toString();
1✔
92
  }
93
}
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