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

mybatis / migrations / #411

pending completion
#411

push

github

web-flow
Update dependency org.assertj:assertj-core to v3.24.2

1775 of 2215 relevant lines covered (80.14%)

0.8 hits per line

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

82.14
/src/main/java/org/apache/ibatis/migration/utils/Util.java
1
/*
2
 *    Copyright 2010-2022 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.FileInputStream;
20
import java.util.Properties;
21

22
public enum Util {
1✔
23
  ;
24

25
  private static final String MIGRATIONS_HOME = "MIGRATIONS_HOME";
26

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

30
  private static final String MIGRATIONS_HOME_PROPERTY = "migrationsHome";
31

32
  private static final String MIGRATIONS_PROPERTIES = "migration.properties";
33

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

46
  public static boolean getPropertyOptionAsBoolean(String key) {
47
    return Boolean.valueOf(getPropertyOption(key));
1✔
48
  }
49

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

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

75
  public static File file(File path, String fileName) {
76
    return new File(path.getAbsolutePath() + File.separator + fileName);
1✔
77
  }
78

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

© 2025 Coveralls, Inc