Skip to content

Commit

Permalink
fix: check for output folder before download
Browse files Browse the repository at this point in the history
  • Loading branch information
PranavPurwar committed Mar 8, 2023
1 parent f81119c commit 20d59a5
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (repository != null) {
println("Cannot find artifact.")
}
```

NOTE: If you only want to download the artifact, you can use the `downloadTo` method instead.
For downloading an artifact with all of its dependencies, you can do
```kt
val output = File("<directory to download artifact>")
Expand Down
2 changes: 1 addition & 1 deletion lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ publishing {
create<MavenPublication>("maven") {
groupId = "org.cosmic.ide"
artifactId = "dependency-resolver"
version = "1.0.0"
version = "1.0.1"

from(components["java"])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import java.io.File
import java.io.InputStream
import java.net.URL
import javax.xml.parsers.DocumentBuilderFactory
import org.w3c.dom.Element

data class Artifact(
val groupId: String,
Expand All @@ -25,11 +24,12 @@ data class Artifact(
}

fun downloadArtifact(output: File) {
output.mkdirs()
val artifacts = resolve()
artifacts.add(this)

val latestDeps =
artifacts.groupBy { it.groupId to it.artifactId }.values.map { it.maxBy { it.version } }
artifacts.groupBy { it.groupId to it.artifactId }.values.map { artifact -> artifact.maxBy { it.version } }

latestDeps.forEach { art ->
if (art.version.isNotEmpty() && art.repository != null) {
Expand All @@ -39,8 +39,7 @@ data class Artifact(
}

fun resolve(): MutableList<Artifact> {
val pom = getPOM()
if (pom == null) return mutableListOf()
val pom = getPOM() ?: return mutableListOf()
val deps = pom.resolvePOM()
val artifacts = mutableListOf<Artifact>()
deps.forEach { dep ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface Repository {

fun checkExists(groupId: String, artifactId: String, version: String): Boolean {
val repository = getURL()
val dependencyUrl = if (!version.isEmpty())
val dependencyUrl = if (version.isNotEmpty())

"$repository/${groupId.replace(".", "/")}/$artifactId/$version/$artifactId-$version.jar"
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fun InputStream.resolvePOM(): List<Artifact> {
val doc = builder.parse(this)

val dependencies = doc.getElementsByTagName("dependencies").item(0) as Element?
if (dependencies == null) return artifacts
?: return artifacts
val dependencyElements = dependencies.getElementsByTagName("dependency")
for (i in 0 until dependencyElements.length) {
val dependencyElement = dependencyElements.item(i) as Element
Expand Down
8 changes: 8 additions & 0 deletions local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Wed Mar 01 20:18:29 IST 2023
sdk.dir=/Users/palakpurwar/Android/sdk

0 comments on commit 20d59a5

Please sign in to comment.