Skip to content

Commit 05d076b

Browse files
release: 0.1.1 (#150)
- Add extraction of Kotlin libraries - Add support of home symbol and relative paths for specifying repos path
1 parent 5e8bb0a commit 05d076b

File tree

15 files changed

+200
-21
lines changed

15 files changed

+200
-21
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ buildConfig {
3636
buildConfigField 'String', 'PROFILE_URL', 'https://sourcerer.io/'
3737

3838
// App version.
39-
buildConfigField 'int', 'VERSION_CODE', '3'
40-
buildConfigField 'String', 'VERSION', '0.1.0'
39+
buildConfigField 'int', 'VERSION_CODE', '4'
40+
buildConfigField 'String', 'VERSION', '0.1.1'
4141

4242
// Logging.
4343
buildConfigField 'String', 'ENV', project.hasProperty('env') ? env : 'production'

src/main/kotlin/app/Logger.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ object Logger {
9393
}
9494

9595
private fun configLevelValue() : Int {
96-
val a = mapOf("trace" to TRACE, "debug" to DEBUG, "info" to INFO, "warn" to WARN, "error" to ERROR)
96+
val a = mapOf("trace" to TRACE, "debug" to DEBUG, "info" to INFO,
97+
"warn" to WARN, "error" to ERROR)
9798
return a.getValue(BuildConfig.LOG_LEVEL)
9899
}
99100

src/main/kotlin/app/Main.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import app.utils.CommandConfig
1111
import app.utils.CommandAdd
1212
import app.utils.CommandList
1313
import app.utils.CommandRemove
14+
import app.utils.FileHelper.toPath
1415
import app.utils.Options
1516
import app.utils.PasswordHelper
1617
import app.utils.RepoHelper
@@ -75,9 +76,9 @@ class Main(argv: Array<String>) {
7576
}
7677

7778
private fun doAdd(commandAdd: CommandAdd) {
78-
val path = commandAdd.path
79+
val path = commandAdd.path?.toPath()
7980
if (path != null && RepoHelper.isValidRepo(path)) {
80-
val localRepo = LocalRepo(path)
81+
val localRepo = LocalRepo(path.toString())
8182
localRepo.hashAllContributors = commandAdd.hashAll
8283
configurator.addLocalRepoPersistent(localRepo)
8384
configurator.saveToFile()

src/main/kotlin/app/config/FileConfigurator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class FileConfigurator : Configurator {
212212

213213
try {
214214
loadConfig = Files.newBufferedReader(FileHelper
215-
.getPath(CONFIG_FILE_NAME)).use {
215+
.toPath(CONFIG_FILE_NAME)).use {
216216
mapper.readValue(it, Config::class.java)
217217
}
218218
} catch (e: IOException) {
@@ -241,7 +241,7 @@ class FileConfigurator : Configurator {
241241
*/
242242
override fun saveToFile() {
243243
try {
244-
Files.newBufferedWriter(FileHelper.getPath(CONFIG_FILE_NAME)).use {
244+
Files.newBufferedWriter(FileHelper.toPath(CONFIG_FILE_NAME)).use {
245245
mapper.writeValue(it, persistent)
246246
}
247247
} catch (e: IOException) {

src/main/kotlin/app/extractors/Extractor.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Extractor : ExtractorInterface {
2828
in GoExtractor.FILE_EXTS -> GoExtractor()
2929
in ObjectiveCExtractor.FILE_EXTS -> ObjectiveCExtractor()
3030
in SwiftExtractor.FILE_EXTS -> SwiftExtractor()
31+
in KotlinExtractor.FILE_EXTS -> KotlinExtractor()
3132
else -> CommonExtractor()
3233
}
3334
}

src/main/kotlin/app/extractors/JavaExtractor.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ class JavaExtractor : ExtractorInterface {
7979
override fun tokenize(line: String): List<String> {
8080
val importRegex = Regex("""^(.*import)\s[^\n]*""")
8181
val commentRegex = Regex("""^([^\n]*//)[^\n]*""")
82+
val packageRegex = Regex("""^(.*package)\s[^\n]*""")
8283
var newLine = importRegex.replace(line, "")
8384
newLine = commentRegex.replace(newLine, "")
85+
newLine = packageRegex.replace(newLine, "")
8486
return super.tokenize(newLine)
8587
}
8688

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2017 Sourcerer Inc. All Rights Reserved.
2+
// Author: Liubov Yaronskaya ([email protected])
3+
4+
package app.extractors
5+
6+
import app.model.CommitStats
7+
import app.model.DiffFile
8+
9+
class KotlinExtractor : ExtractorInterface {
10+
companion object {
11+
val LANGUAGE_NAME = "kotlin"
12+
val FILE_EXTS = listOf("kt")
13+
val LIBRARIES = ExtractorInterface.getLibraries(LANGUAGE_NAME)
14+
val evaluator by lazy {
15+
ExtractorInterface.getLibraryClassifier(LANGUAGE_NAME)
16+
}
17+
}
18+
19+
override fun extract(files: List<DiffFile>): List<CommitStats> {
20+
files.map { file -> file.language = LANGUAGE_NAME }
21+
return super.extract(files)
22+
}
23+
24+
override fun extractImports(fileContent: List<String>): List<String> {
25+
val imports = mutableSetOf<String>()
26+
27+
val regex = Regex("""import\s+(\w+[.\w+]*)""")
28+
fileContent.forEach {
29+
val res = regex.find(it)
30+
if (res != null) {
31+
val importedName = res.groupValues[1]
32+
LIBRARIES.forEach { library ->
33+
if (importedName.startsWith(library)) {
34+
imports.add(library)
35+
}
36+
}
37+
}
38+
}
39+
40+
return imports.toList()
41+
}
42+
43+
override fun tokenize(line: String): List<String> {
44+
val importRegex = Regex("""^(.*import)\s[^\n]*""")
45+
val commentRegex = Regex("""^([^\n]*//)[^\n]*""")
46+
val packageRegex = Regex("""^(.*package)\s[^\n]*""")
47+
var newLine = importRegex.replace(line, "")
48+
newLine = commentRegex.replace(newLine, "")
49+
newLine = packageRegex.replace(newLine, "")
50+
return super.tokenize(newLine)
51+
}
52+
53+
override fun getLineLibraries(line: String,
54+
fileLibraries: List<String>): List<String> {
55+
56+
return super.getLineLibraries(line, fileLibraries, evaluator, LANGUAGE_NAME)
57+
}
58+
}

src/main/kotlin/app/hashers/CodeLongevity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class CodeLongevity(private val serverRepo: Repo,
151151
catch(e: Exception) { throw Exception("No branch") }
152152

153153
val df = DiffFormatter(DisabledOutputStream.INSTANCE)
154-
val dataPath = FileHelper.getPath(serverRepo.rehash, "longevity")
154+
val dataPath = FileHelper.toPath(serverRepo.rehash, "longevity")
155155

156156
init {
157157
df.setRepository(repo)

src/main/kotlin/app/hashers/RepoHasher.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import app.config.Configurator
99
import app.model.Author
1010
import app.model.LocalRepo
1111
import app.model.Repo
12+
import app.utils.FileHelper.toPath
1213
import app.utils.HashingException
1314
import app.utils.RepoHelper
1415
import org.eclipse.jgit.api.Git
@@ -17,11 +18,11 @@ import java.io.IOException
1718
import kotlin.collections.HashSet
1819

1920
class RepoHasher(private val localRepo: LocalRepo, private val api: Api,
20-
private val configurator: Configurator) {
21+
private val configurator: Configurator) {
2122
var serverRepo: Repo = Repo()
2223

2324
init {
24-
if (!RepoHelper.isValidRepo(localRepo.path)) {
25+
if (!RepoHelper.isValidRepo(localRepo.path.toPath())) {
2526
throw IllegalArgumentException("Invalid repo $localRepo")
2627
}
2728
}

src/main/kotlin/app/ui/AddRepoState.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import app.Logger
77
import app.api.Api
88
import app.config.Configurator
99
import app.model.LocalRepo
10+
import app.utils.FileHelper.toPath
1011
import app.utils.RepoHelper
1112
import app.utils.UiHelper
1213

@@ -28,12 +29,13 @@ class AddRepoState constructor(private val context: Context,
2829
if (configurator.getLocalRepos().isEmpty()) {
2930
Logger.print("Add at least one valid repository.")
3031
} else {
31-
break // User finished to add repos.
32+
break // User finished to add repos.
3233
}
3334
} else {
34-
if (RepoHelper.isValidRepo(pathString)) {
35-
Logger.print("Added git repository at $pathString.")
36-
val localRepo = LocalRepo(pathString)
35+
val path = pathString.toPath()
36+
if (RepoHelper.isValidRepo(path)) {
37+
Logger.print("Added git repository at $path.")
38+
val localRepo = LocalRepo(path.toString())
3739
localRepo.hashAllContributors = UiHelper.confirm("Do you "
3840
+ "want to hash commits of all contributors?",
3941
defaultIsYes = true)

0 commit comments

Comments
 (0)