File: brltty-properties.gradle

package info (click to toggle)
brltty 6.9-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 44,828 kB
  • sloc: ansic: 154,246; java: 13,514; sh: 9,934; xml: 5,672; tcl: 2,679; makefile: 2,346; awk: 713; lisp: 366; python: 321; ml: 301
file content (79 lines) | stat: -rw-r--r-- 2,152 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def propertyFiles = [
  config: "config.properties",
  native: "native.properties",
]

void normalizeFileProperty (Properties properties, String name) {
  properties[name] = rootProject.file(properties[name])
}

void normalizeDirectoryProperty (Properties properties, String name) {
  normalizeFileProperty(properties, name)
  properties[name] = properties[name].absolutePath
}

void normalizeSubdirectoryProperty (Properties properties, String subdirectoryName) {
  def directoryName = subdirectoryName.replaceAll(/Subdirectory$/, "Directory")
  properties[directoryName] = properties.rootDirectory + File.separator + properties[subdirectoryName]
}

void normalizeListProperty (Properties properties, String name) {
  properties[name] = properties[name].split(',').collect{it as String}
}

Properties loadPropertiesFromFile (String path) {
  def properties = new Properties()
  def file = rootProject.file(path)

  if (file.exists()) {
    new FileInputStream(file).withStream { stream ->
      new InputStreamReader(stream, "UTF-8").withReader { reader ->
        properties.load(reader)
      }
    }
  }

  def directoryProperties = []
  def subdirectoryProperties = []
  def fileProperties = []
  def listProperties = []

  properties.propertyNames().each { name ->
    if (name.endsWith("Directory")) {
      directoryProperties += name
    } else if (name.endsWith("Subdirectory")) {
      subdirectoryProperties += name
    } else if (name.endsWith("File")) {
      fileProperties += name
    } else if (name.endsWith("List")) {
      listProperties += name
    }
  }

  directoryProperties.each { name ->
    normalizeDirectoryProperty(properties, name)
  }

  subdirectoryProperties.each { name ->
    normalizeSubdirectoryProperty(properties, name)
  }

  fileProperties.each { name ->
    normalizeFileProperty(properties, name)
  }

  listProperties.each { name ->
    normalizeListProperty(properties, name)
  }

  return properties
}

propertyFiles.keySet().each { name ->
  def path = propertyFiles[name]
  brltty[name] = loadPropertiesFromFile(path)
}

brltty.loadProperties = { String filePath ->
  loadPropertiesFromFile(filePath)
}