Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

release v1.0 #1

Open
wants to merge 26 commits into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4b3aa6f
add getting version
Jul 25, 2019
4959cf6
up jvm target 1.6 -> 1.8 + support packages.config
Jul 25, 2019
d126a68
refactor some tautologies
Jul 25, 2019
1861173
change paths types from String to Path
Jul 26, 2019
c354f03
add JsonAssetsProjectDeserializer with tests
Jul 29, 2019
6e8a088
add NuGetConfigDiscoverer, NuGetConfigDeserializer and tests
Jul 30, 2019
6e3631a
add NuGetConfigDiscovererTest
Jul 30, 2019
99a07c2
remove windows incorrect path from test
Jul 31, 2019
29891ea
rewrite build.gradle to kotlin dsl + remove commons.io
Aug 5, 2019
e7f3f83
replace all paths to user-neutral
Aug 5, 2019
7f5b9b6
change all Path.of to Paths.get
Aug 6, 2019
92cd4ad
add pathToFile for Reference
Aug 7, 2019
cb852b6
remove windows incorrect path
Aug 9, 2019
6ae9691
Create README.md
dtretyakov Aug 9, 2019
c9a2e05
Create LICENSE
dtretyakov Aug 9, 2019
fe68f92
add bintray block
Aug 9, 2019
0fd6166
Add ability to override version number
dtretyakov Aug 12, 2019
705b337
Fix version resolution
dtretyakov Aug 12, 2019
19d2481
change project name + add bintray version
Aug 12, 2019
e0bcfbc
Merge remote-tracking branch 'origin/master'
Aug 12, 2019
53dd320
fix bintray version
Aug 12, 2019
c779f81
add groupId, artifactId and version to maven publication
Aug 12, 2019
b494264
add pom
Aug 12, 2019
0253862
update com.jfrog.bintray plugin 1.8.0 -> 1.8.4
Aug 12, 2019
5fc260f
add explisit supported extensions to MSBuildProjectDeserializer and M…
Aug 15, 2019
037667c
improve README, add distinct() for NuGetConfigDiscoverer.discover and…
Aug 30, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions build.gradle

This file was deleted.

49 changes: 49 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.3.41"
`maven-publish`
}



group = "org.jetbrains"
version = "1.0"

val sourcesJar by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
}

publishing {
publications {
register<MavenPublication>("mavenJava") {
from(components["java"])
artifact(sourcesJar.get())
}
}
}



repositories {
mavenCentral()
}

tasks.withType<Test> {
useTestNG()
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("com.google.code.gson:gson:2.5")
implementation("org.slf4j:slf4j-api:1.7.25")
implementation("org.slf4j:slf4j-simple:1.7.25")

testImplementation("org.testng:testng:6.14.3")
testImplementation("org.jmock:jmock:2.5.1")
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
2 changes: 0 additions & 2 deletions settings.gradle

This file was deleted.

2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rootProject.name = "dotnet-discovery"

28 changes: 28 additions & 0 deletions src/main/kotlin/org/jetbrains/dotnet/common/FileUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.jetbrains.dotnet.common

import java.nio.file.Path

internal fun Path.toNormalizedUnixString(): String = this.normalize().toString().toSystem(true)

internal fun String.toSystem(isUnix: Boolean = !isWindows()): String {
val separators = getSeparators(isUnix)
return this.replace(separators.first, separators.second)
}

internal fun Path.toSystem(isUnix: Boolean = !isWindows()) =
Path.of(this.toString().toSystem(isUnix))


private fun isWindows(): Boolean {
return System.getProperty("os.name").toLowerCase().contains("win")
}

private fun getSeparators(isUnix: Boolean) =
if (isUnix) {
WINDOWS_SEPARATOR to UNIX_SEPARATOR
} else {
UNIX_SEPARATOR to WINDOWS_SEPARATOR
}

private const val WINDOWS_SEPARATOR = "\\"
private const val UNIX_SEPARATOR = "/"
27 changes: 27 additions & 0 deletions src/main/kotlin/org/jetbrains/dotnet/common/XPathReader.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.jetbrains.dotnet.common

import org.w3c.dom.Document
import org.w3c.dom.Element
import org.w3c.dom.NodeList
import javax.xml.xpath.XPathConstants
import javax.xml.xpath.XPathFactory

open class XPathReader {

private val xPath = XPathFactory.newInstance().newXPath()

protected fun getElements(doc: Document, xpath: String): Sequence<Element> = sequence {
val nodes = xPath.evaluate(xpath, doc, XPathConstants.NODESET) as NodeList
for (i in 0 until nodes.length) {
val element = nodes.item(i) as Element
yield(element)
}
}

protected fun getContents(doc: Document, xpath: String): Sequence<String> =
getElements(doc, xpath).map { it.textContent }.filter { !it.isNullOrBlank() }

protected fun getAttributes(doc: Document, xpath: String, attributeName: String): Sequence<String> =
getElements(doc, xpath).map { it.getAttribute(attributeName) }.filter { !it.isNullOrBlank() }

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class XmlDocumentServiceImpl : XmlDocumentService {
} catch (ex: ParserConfigurationException) {
throw IllegalStateException("Error during creating xml document")
}

return docBuilder.newDocument()
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.io.File
import java.io.InputStream
import java.nio.file.Path

class FileStreamFactory(private val baseDirectory: File) : StreamFactory {
override fun tryCreate(path: String): InputStream? {
val file = File(baseDirectory, path)
class FileProjectStreamFactory(private val baseDirectory: File) : ProjectStreamFactory {
override fun tryCreate(path: Path): InputStream? {
val file = baseDirectory.toPath().resolve(path).toFile()
if (!file.exists()) {
LOG.debug("File $path was not found")
return null
Expand Down
3 changes: 0 additions & 3 deletions src/main/kotlin/org/jetbrains/dotnet/discovery/Framework.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package org.jetbrains.dotnet.discovery

import com.google.gson.Gson
import com.google.gson.JsonSyntaxException
import org.jetbrains.dotnet.common.toNormalizedUnixString
import org.jetbrains.dotnet.common.toSystem
import org.jetbrains.dotnet.discovery.data.*
import org.jetbrains.dotnet.discovery.data.Reference.Companion.DEFAULT_VERSION
import org.jetbrains.dotnet.discovery.data.Target
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.nio.file.Path
import java.util.regex.Pattern

class JsonAssetsProjectDeserializer(
private val readerFactory: ReaderFactory,
private val sourceDiscoverer: NuGetConfigDiscoverer? = null
) : SolutionDeserializer {

private val gson: Gson = Gson()

override fun accept(path: Path): Boolean = PathPattern.matcher(path.toNormalizedUnixString()).find()

override fun deserialize(path: Path, projectStreamFactory: ProjectStreamFactory): Solution =
projectStreamFactory.tryCreate(path)?.use { inputStream ->
readerFactory.create(inputStream).use { reader ->
val doc = try {
gson.fromJson(reader, JsonAssetsProjectDto::class.java)
} catch (e : JsonSyntaxException) {
LOG.debug("$path contains invalid json")
return Solution(emptyList())
}

val targets = doc.targets?.keys?.map { Target(it) } ?: emptyList()
val roots : Set<String> = doc.project?.frameworks?.values
?.flatMap {
it.dependencies?.keys ?: emptySet()
}
?.toHashSet() ?: emptySet()

val references = doc.targets?.values
?.flatMap { it.entries }
?.map { (id, pkg) ->
val splinteredId = id.split("/")
val name = splinteredId[0]
val version = splinteredId.getOrNull(1) ?: DEFAULT_VERSION
val dependencies = pkg.dependencies?.entries
?.map { (name, ver) -> Reference(name, ver) } ?: emptyList()

val isRoot = roots.contains(name)
Reference(name, version, dependencies, isRoot)
} ?: emptyList()

val frameworks = doc.project?.frameworks?.keys?.map { Framework(it) } ?: emptyList()

val fullPathToConfig = doc.project?.restore?.projectPath ?: path.toNormalizedUnixString()

val configs = doc.project?.restore?.configs


val sources = sourceDiscoverer?.let { discoverer ->
configs?.asSequence()?.flatMap { discoverer.deserializer.deserialize(Path.of(it.toSystem()), projectStreamFactory) }?.toList()
?: discoverer.discover(path, projectStreamFactory).toList()
} ?: emptyList()

Solution(
listOf(
Project(
fullPathToConfig,
targets = targets,
references = references,
frameworks = frameworks,
sources = sources
)
)
)
}
} ?: Solution(emptyList())


private companion object {
private val LOG: Logger = LoggerFactory.getLogger(JsonAssetsProjectDeserializer::class.java.name)
private val PathPattern: Pattern = Pattern.compile("^(.+[^\\w\\d]|)project\\.assets\\.json$", Pattern.CASE_INSENSITIVE)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.jetbrains.dotnet.discovery

import com.google.gson.annotations.SerializedName

class JsonAssetsProjectDto(
@SerializedName("targets") val targets: Map<String, Map<String, PackageDto>>?,
@SerializedName("project") val project: ProjectDto?
)

class PackageDto(
@SerializedName("dependencies") val dependencies: Map<String, String>?
)

class ProjectDto(
@SerializedName("restore") val restore : RestoreDto?,
@SerializedName("frameworks") val frameworks: Map<String, DependenciesDto>?
)

class DependenciesDto(
@SerializedName("dependencies") val dependencies: Map<String, Any>?
)

class RestoreDto(
@SerializedName("projectPath") val projectPath : String?,
@SerializedName("configFilePaths") val configs : List<String>?
)
Loading