Skip to content

Commit

Permalink
add spotless for kotlin files
Browse files Browse the repository at this point in the history
  • Loading branch information
yigit committed Oct 10, 2019
1 parent c2a712c commit fbff16d
Show file tree
Hide file tree
Showing 67 changed files with 1,150 additions and 178 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
key: v1-dependencies-{{ checksum "build.gradle" }}

# run tests!
- run: ./gradlew test
- run: ./gradlew spotlessCheck test
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.birbit.artifactfinder

import com.birbit.artifactfinder.maven.MavenFetcher
Expand All @@ -10,10 +26,10 @@ import com.birbit.artifactfinder.parser.Jar
import com.birbit.artifactfinder.vo.Artifactory
import com.birbit.artifactfinder.vo.Artifactory.GOOGLE
import com.birbit.artifactfinder.worker.distributeJobs
import java.io.File
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.withContext
import java.io.File

class ArtifactFinder(
private val db: File
Expand Down Expand Up @@ -134,4 +150,4 @@ class ArtifactFinder(
}
model.sync()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.birbit.artifactfinder

import com.birbit.artifactfinder.vo.Artifactory.MAVEN
Expand Down Expand Up @@ -46,4 +62,4 @@ val EXTERNAL_SOURCES = FetcherSource(
)
) + RETROFIT

)
)
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.birbit.artifactfinder

import com.birbit.artifactfinder.vo.Artifactory
Expand Down
31 changes: 23 additions & 8 deletions artifactfinder/src/main/kotlin/com/birbit/artifactfinder/Main.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.birbit.artifactfinder

import java.io.File
Expand All @@ -6,8 +22,7 @@ import java.nio.channels.FileChannel
import java.nio.file.StandardOpenOption
import java.util.Locale


internal enum class Action(vararg val names:String) {
internal enum class Action(vararg val names: String) {
TRAVERSE_GMAVEN("gmaven"),
DOWNLOAD_ARTIFACTS("download"),
TRAVERSE_EXTERNAL("external")
Expand Down Expand Up @@ -35,9 +50,9 @@ private fun usage(args: Array<out String>, exception: Throwable?) {
System.exit(1)
}

private fun parseArgs(args: Array<out String>) : CmdlineArgs {
var action : Action? = null
var db : File? = null
private fun parseArgs(args: Array<out String>): CmdlineArgs {
var action: Action? = null
var db: File? = null
repeat(args.size / 2) {
val type = args[it * 2]
val value = args[it * 2 + 1]
Expand Down Expand Up @@ -81,19 +96,19 @@ private fun parseArgs(args: Array<out String>) : CmdlineArgs {
suspend fun main(vararg args: String) {
val cmd = try {
parseArgs(args)
} catch (e:Throwable) {
} catch (e: Throwable) {
usage(args, e)
null
} ?: return
println(cmd)
try {
ensureSingleton()
when(cmd.action) {
when (cmd.action) {
Action.TRAVERSE_GMAVEN -> ArtifactFinder(cmd.db).indexGMaven()
Action.TRAVERSE_EXTERNAL -> ArtifactFinder(cmd.db).indexExternalArtifacts()
Action.DOWNLOAD_ARTIFACTS -> ArtifactFinder(cmd.db).fetchArtifacts()
}
} catch (ex : Throwable) {
} catch (ex: Throwable) {
ex.printStackTrace()
System.exit(1)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
/*
* Copyright 2019 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.birbit.artifactfinder

import com.birbit.artifactfinder.model.Version


object VersionSelector {
/**
* Current version selection logic:
Expand Down Expand Up @@ -91,4 +106,4 @@ private class Counters {
val LIMIT_BETA = 1
val LIMIT_ALPHA = 1
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.birbit.artifactfinder.worker

import kotlinx.coroutines.CancellationException
Expand Down Expand Up @@ -30,7 +46,7 @@ suspend fun <T : Any, R> distributeJobs(
consumer = consumer
)

private fun log(msg:Any?) {
private fun log(msg: Any?) {
println("[JQ][${Thread.currentThread().name}]: $msg")
}

Expand All @@ -52,8 +68,7 @@ suspend fun <T : Any, R> distributeJobs(
throw AbortFlowException()
}
}
} catch (abort : AbortFlowException) {

} catch (abort: AbortFlowException) {
} finally {
distributionChannel.close()
log("distributionChannel DONE")
Expand All @@ -75,7 +90,7 @@ suspend fun <T : Any, R> distributeJobs(
}
} catch (closed: ClosedReceiveChannelException) {
log("worker $workerId done")
} catch (th : Throwable) {
} catch (th: Throwable) {
log("worker has thrown exception ${th.message}")
}
}
Expand All @@ -85,4 +100,4 @@ suspend fun <T : Any, R> distributeJobs(
return@withContext results
}

private class AbortFlowException : CancellationException()
private class AbortFlowException : CancellationException()
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
/*
* Copyright 2019 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.birbit.artifactfinder

import com.birbit.artifactfinder.maven.MavenFetcher
import com.birbit.artifactfinder.maven.vo.ArtifactType
import com.birbit.artifactfinder.vo.Artifactory
import com.birbit.artifactfinder.model.ArtifactFinderModel
import com.birbit.artifactfinder.parser.Aar
import com.birbit.artifactfinder.parser.CodeSourceParser
import com.birbit.artifactfinder.parser.Jar
import com.birbit.artifactfinder.vo.Artifactory
import java.io.File
import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import java.io.File

@RunWith(JUnit4::class)
class PlaygroundTest {
Expand Down Expand Up @@ -43,4 +59,4 @@ class PlaygroundTest {
val src = CodeSourceParser.parse(codeSource)
println(src)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.birbit.artifactfinder

import com.birbit.artifactfinder.VersionSelector.selectVersions
Expand Down Expand Up @@ -141,7 +157,6 @@ class VersionSelectorTest {
)
}


companion object {
val V_1_0_0 = Version.fromString("1.0.0")!!
val V_1_1_0 = Version.fromString("1.1.0")!!
Expand All @@ -153,6 +168,5 @@ class VersionSelectorTest {
val V_1_1_0_beta02 = Version.fromString("1.1.0-beta02")!!
val V_1_1_0_rc01 = Version.fromString("1.1.0-rc01")!!
val V_1_1_0_rc02 = Version.fromString("1.1.0-rc02")!!

}
}
}
18 changes: 14 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.ktor_version = "1.2.4"
ext.ktlint_version = '0.34.0'
ext.libs = [
junit : "junit:junit:4.12",
truth : "com.google.truth:truth:1.0",
Expand All @@ -23,8 +24,6 @@ buildscript {
xerial : 'org.xerial:sqlite-jdbc:3.28.0',
ktor : "io.ktor:ktor-server-netty:$ktor_version",
okHttpLogger : "com.squareup.okhttp3:logging-interceptor:4.2.1"


]
repositories {
google()
Expand All @@ -47,13 +46,24 @@ buildscript {
}
}

plugins {
id 'com.diffplug.gradle.spotless' version '3.25.0'
}

allprojects {
repositories {
google()
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
subprojects {
apply plugin: 'com.diffplug.gradle.spotless'
spotless {
kotlin {
target 'src/**/*.kt'
ktlint(ktlint_version).userData(['disabled_rules':'no-wildcard-imports'])
licenseHeaderFile project.rootProject.file('scripts/copyright.kt')
}
}
}
18 changes: 17 additions & 1 deletion core/src/main/kotlin/com/birbit/artifactfinder/parser/vo/Info.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.birbit.artifactfinder.parser.vo

/**
Expand Down Expand Up @@ -38,4 +54,4 @@ data class ParsedMethodInfo(
data class InnerClassInfo(
val parent: ParsedClassInfo,
val classInfo: ParsedClassInfo
)
)
Loading

0 comments on commit fbff16d

Please sign in to comment.