summaryrefslogtreecommitdiff
path: root/app/build.gradle
blob: db928f0b93286745f2bda2696a920363a71f13c1 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
apply plugin: 'android'
//import org.ajoberstar.grgit.*

android {
  compileSdkVersion 21
  buildToolsVersion "21.1.2"

  signingConfigs {
    release {
      storeFile project.hasProperty('storeFileProperty') ? file(storeFileProperty) : null
      storePassword project.hasProperty('storePasswordProperty') ?  storePasswordProperty : ""
      keyAlias project.hasProperty('keyAliasProperty') ?  keyAliasProperty : ""
      keyPassword project.hasProperty('keyPasswordProperty') ?  keyPasswordProperty : ""
    }
  }

  buildTypes {
    release {
      //runProguard true
      if(signingConfigs.contains(release))
	signingConfig signingConfigs.release.isSigningReady() ? signingConfigs.release : signingConfigs.debug
    }
  }

  lintOptions {
    abortOnError false
  }

  sourceSets {
    main {
      assets.srcDirs = ['assets', 'ovpnlibs/assets']
      jniLibs.srcDirs = ['ovpnlibs/jniLibs']
      jni.srcDirs = [] //disable automatic ndk-build
    }
    debug {
      assets.srcDirs = ['src/debug/assets']
    }
  }
}

dependencies {
  androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.2.1'
  compile 'com.jakewharton:butterknife:6.0.0+'
  provided 'com.squareup.dagger:dagger-compiler:1.2.2+'
  compile 'com.github.pedrovgs:renderers:1.3+'
  compile 'com.intellij:annotations:12.0'
  compile 'com.google.code.gson:gson:2+'
}

def processFileInplace(file, Closure processText) {
  def text = file.text
  file.write(processText(text))
}


task checkoutStrippedIcsOpenVPN ( type: Copy )  {
  println "checkoutStrippedIcsOpenVPN"
  //FIXME Checkout ics-openvpn-stripped from branch "ics-openvpn-upstream"
  //grgit = Grgit.open(project.file('../'))
  
  from '../../bitmask_android_tmp/ics-openvpn-stripped'
  into '../ics-openvpn-stripped'
}

task copyIcsOpenVPNClasses( type: Copy ) {
  println "copyIcsOpenVPNClasses"
  from ('../ics-openvpn-stripped/main/') {
    include '**/*.java'

    includeEmptyDirs = false
    
    filter {
      line -> line.replaceAll('de.blinkt.openvpn.R', 'se.leap.bitmaskclient.R')
    }
    filter {
      line -> line.replaceAll('de.blinkt.openvpn.BuildConfig', 'se.leap.bitmaskclient.BuildConfig')
    }
    filter {      
      line -> line.replace('package de.blinkt.openvpn;', 'package de.blinkt.openvpn;\n\nimport se.leap.bitmaskclient.R;')
    }
  } into '.'
}

task copyIcsOpenVPNXml( type: Copy )  {
  println "copyIcsOpenVPNXml"
  from ('../ics-openvpn-stripped/main/') {
    include '**/strings.xml'
    include '**/log_*.xml'
    include '**/vpnstatus.xml'
    include '**/styles.xml'
    include '**/dimens.xml'
    include '**/refs.xml'
    include '**/colours.xml'    
    include '**/logmenu.xml'
    include '**/white_rect.xml'
    includeEmptyDirs = false
    
    rename 'strings.xml', 'strings-icsopenvpn.xml'
    filter {
      line -> line.replaceAll('.*name="app".*', '')
    }
  } into '.'
}

task copyIcsOpenVPNImages( type: Copy ) {
  println "copyIcsOpenVPNImages"
  from ('../ics-openvpn-stripped/main/') {
    include '**/ic_filter*.png'
    include '**/ic_delete*.png'
    include '**/ic_share*.png'
    include '**/ic_close*.png'
    include '**/ic_edit*.png'

    includeEmptyDirs = false
  } into '.'
}

task copyIcsOpenVPNFiles( type: Copy, dependsOn: 'checkoutStrippedIcsOpenVPN' ) {
  println "copyIcsOpenVPNFiles"
  copyIcsOpenVPNClasses.execute()
  copyIcsOpenVPNXml.execute()
  copyIcsOpenVPNImages.execute()
}

// thanks to http://pleac.sourceforge.net/pleac_groovy/fileaccess.html
task removeDuplicatedStrings( dependsOn: 'copyIcsOpenVPNFiles' ) {
  println "removeDuplicatedStrings"
  new File('.').eachFileRecurse {
    if(it.name.equals('strings.xml')) {
      def ics_openvpn_file = file(it.absolutePath.replace('strings.xml', 'strings-icsopenvpn.xml'))
      if(ics_openvpn_file.exists()) {
	def ics_openvpn_strings_names = (new XmlParser()).parse(ics_openvpn_file)
	def current_file = it
      
	ics_openvpn_strings_names.string.each {
	  processFileInplace(current_file) { text ->
	    text.replaceAll('.*name=\"' + it.attribute('name') + '\".*(\n)*.*string>.*\n+', '')
	  }
	}
      }
    }
  }
}

task mergeUntranslatable( type: Copy, dependsOn: 'removeDuplicatedStrings') {
  println "mergeUntranslatable"
  from ('../ics-openvpn-stripped/main/') {
    include '**/untranslatable.xml'
    rename 'untranslatable.xml', 'untranslatable-icsopenvpn.xml'
  } into '.'
  def bitmask_untranslatable = file('src/main/res/values/untranslatable.xml')
  def ics_openvpn_untranslatable = new File(bitmask_untranslatable.path.replace('untranslatable.xml', 'untranslatable-icsopenvpn.xml'))
  ics_openvpn_untranslatable.createNewFile()
  def string_continuation = false;
  ics_openvpn_untranslatable.eachLine { text ->
    if(text.contains('string name=')) {
      if(!bitmask_untranslatable.text.contains(text))
	bitmask_untranslatable << text
	if(text.contains('</string>'))
	  string_continuation = true
    }
    else if(string_continuation) {
      bitmask_untranslatable << text
    }
    
    if(text.contains('</string>')) {
      string_continuation = false
      bitmask_untranslatable << System.getProperty("line.separator")
    }
  }
  
  bitmask_untranslatable.write(bitmask_untranslatable.text.replaceAll("</resources>", ""))
  bitmask_untranslatable << "</resources>"

  delete ics_openvpn_untranslatable
}

task updateIcsOpenVpn( type: Copy, dependsOn: 'mergeUntranslatable') {
  from('../ics-openvpn-stripped/') {
    include 'openvpn/**/*'
    include 'openssl/**/*'    
    include 'lzo/**/**'
    include 'jni/**/*'
    include 'misc/**/*'
    include 'ovpn3/**/*'
    include 'snappy/**/*'

  } into './'
}

task buildNative ( type: Exec ) {
  println "buildNative"
  commandLine 'sh', 'misc/build-native.sh', 'USE_BREAKPAD=0', '-j 8'
}

preBuild.dependsOn buildNative