-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
86 changed files
with
171 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
buildSrc/src/main/kotlin/ru/surfstudio/android/build/GradlePropertiesManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package ru.surfstudio.android.build | ||
|
||
import org.gradle.api.GradleException | ||
import ru.surfstudio.android.build.exceptions.CantReadFileException | ||
import ru.surfstudio.android.build.exceptions.NoPropertyDefinedInFileException | ||
import ru.surfstudio.android.build.utils.EMPTY_STRING | ||
import java.io.File | ||
import java.io.FileInputStream | ||
import java.util.* | ||
|
||
const val GRADLE_PROPERTIES_FILE_PATH = "mirror.properties" | ||
const val MIRROR_COMPONENT_NAME = "surf.mirrorComponentName" | ||
|
||
/** | ||
* Loading properties and caching them from [GRADLE_PROPERTIES_FILE_PATH] | ||
* Created for loading only once during settings.gradle execute and then use everywhere | ||
*/ | ||
object GradlePropertiesManager { | ||
private var componentMirrorName: String = EMPTY_STRING | ||
|
||
init { | ||
loadMirrorComponentName() | ||
} | ||
|
||
/** | ||
* get current mirror component name | ||
* | ||
* @return component mirror name | ||
*/ | ||
fun getMirrorComponentName(): String { | ||
return componentMirrorName | ||
} | ||
|
||
/** | ||
* check if current component is mirror | ||
* | ||
* @return true if mirror | ||
*/ | ||
fun isCurrentComponentAMirror() = componentMirrorName != EMPTY_STRING | ||
|
||
/** | ||
* gets component mirror name as property from file [GRADLE_PROPERTIES_FILE_PATH] | ||
* if there is no such file then current repository is not mirror | ||
*/ | ||
private fun loadMirrorComponentName() { | ||
val props = Properties() | ||
val propFile = File(GRADLE_PROPERTIES_FILE_PATH) | ||
if (!propFile.exists()) return | ||
if (propFile.canRead()) { | ||
props.load(FileInputStream(propFile)) | ||
if (props.containsKey(MIRROR_COMPONENT_NAME)) { | ||
componentMirrorName = props[MIRROR_COMPONENT_NAME] as String | ||
} else { | ||
throw NoPropertyDefinedInFileException(MIRROR_COMPONENT_NAME, GRADLE_PROPERTIES_FILE_PATH) | ||
} | ||
} else { | ||
throw CantReadFileException(GRADLE_PROPERTIES_FILE_PATH) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
buildSrc/src/main/kotlin/ru/surfstudio/android/build/exceptions/CantReadFileException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ru.surfstudio.android.build.exceptions | ||
|
||
import org.gradle.api.GradleException | ||
|
||
class CantReadFileException(fileName: String) : GradleException( | ||
"Can`t read file $fileName" | ||
) |
10 changes: 10 additions & 0 deletions
10
...rc/main/kotlin/ru/surfstudio/android/build/exceptions/NoPropertyDefinedInFileException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ru.surfstudio.android.build.exceptions | ||
|
||
import org.gradle.api.GradleException | ||
|
||
class NoPropertyDefinedInFileException ( | ||
propertyName: String, | ||
fileName: String | ||
) : GradleException( | ||
"No property $propertyName found in file $fileName" | ||
) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.