-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for globs in probe.resolvers.intellij.repositories
config
#285
Changes from all commits
0cf9f75
4a5ef3b
aab9a1c
88413db
8319647
cf8b83f
b5f6fa7
b7f601c
c6c43a4
93ce1ec
dd834df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,8 +1,14 @@ | ||||||
package org.virtuslab.ideprobe.dependencies | ||||||
|
||||||
import java.nio.file.Paths | ||||||
|
||||||
import scala.annotation.tailrec | ||||||
|
||||||
import org.virtuslab.ideprobe.IntelliJFixture | ||||||
import org.virtuslab.ideprobe.config.DependenciesConfig | ||||||
|
||||||
import org.virtuslab.ideprobe.Extensions.PathExtension | ||||||
|
||||||
trait IntelliJResolver { | ||||||
def community: DependencyResolver[IntelliJVersion] | ||||||
def ultimate: DependencyResolver[IntelliJVersion] | ||||||
|
@@ -37,9 +43,54 @@ case class IntelliJPatternResolver(pattern: String) extends IntelliJResolver { | |||||
"version" -> version.releaseOrBuild, | ||||||
"release" -> version.release.getOrElse("snapshot-release") | ||||||
) | ||||||
val replaced = replacements.foldLeft(pattern) { case (path, (pattern, replacement)) => | ||||||
val replacedBeforeResolvingGlobs = replacements.foldLeft(pattern) { case (path, (pattern, replacement)) => | ||||||
path.replace(s"[$pattern]", replacement) | ||||||
} | ||||||
val replaced = | ||||||
if (replacedBeforeResolvingGlobs.startsWith("file:")) | ||||||
resolveGlobsInPattern(replacedBeforeResolvingGlobs) | ||||||
else | ||||||
replacedBeforeResolvingGlobs | ||||||
|
||||||
Dependency(replaced) | ||||||
} | ||||||
|
||||||
private def resolveGlobsInPattern(pathPattern: String): String = | ||||||
replaceGlobsWithExistingDirectories(List(pathPattern), pathPattern).head | ||||||
|
||||||
// Solution below assumes that each * character is used to mark one part of the path (one atomic directory), | ||||||
// for example: "file:///home/.cache/ides/com.jetbrains.intellij.idea/ideaIC/[revision]/*/ideaIC-[revision]/". | ||||||
// Wildcard character should NOT be used as the last element of the pattern - to avoid ambiguous results. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm technically, ambiguous results can also happen when wildcard is somewhere inside the path as well, right? Maybe sth like:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, if the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh okay... so let's break down all cases:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Answered in PMs but short answers below:
yes
no -
where first one is directory and second one - a
no - |
||||||
// Works only for files in local filesystem. | ||||||
@tailrec | ||||||
private def replaceGlobsWithExistingDirectories(paths: List[String], originalPattern: String): List[String] = | ||||||
if (paths.exists(pathMightBeValidResource(_, originalPattern))) | ||||||
paths.filter(pathMightBeValidResource(_, originalPattern)) | ||||||
else | ||||||
replaceGlobsWithExistingDirectories(paths.flatMap(replaceFirstFoundWildcardWithDirectories), originalPattern) | ||||||
|
||||||
private def pathMightBeValidResource(candidatePath: String, originalPattern: String): Boolean = | ||||||
!candidatePath.contains('*') && // below - make sure that candidatePath's last path element is same as in pattern | ||||||
candidatePath.substring(candidatePath.lastIndexOf('/')) == originalPattern.substring( | ||||||
originalPattern.lastIndexOf('/') | ||||||
) && Paths.get(candidatePath.replace("file:", "")).exists | ||||||
|
||||||
private def replaceFirstFoundWildcardWithDirectories(path: String): List[String] = { | ||||||
def removeLastFileSeparator(path: String): String = if (path.endsWith("/")) path.init else path | ||||||
|
||||||
val pathUntilWildcard = Paths.get(path.substring(0, path.indexOf('*')).replace("file:", "")) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay... so a ready library for globs wasn't an adequate solution here? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not manage to test these libraries yet. Wanted to have a working solution first. I'm not sure if we need them here. Suggested docs https://docs.oracle.com/javase/tutorial/essential/io/find.html don't seem helpful to me in this case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, leaving up to your judgement |
||||||
val stringPathAfterWildcard = path.substring(path.indexOf('*') + 1) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you use split for that? It allows to specify limit of splits. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, but then I would have to use three
If you think that would be better than current solution, I can do that. Let me know, what do you think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, let's do this. It is same number of lines, but 2 substring calls with some index offset are more complex for reading and understanding than a simple split. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a problem connected to replacing I would suggest to switch back to previous logic:
to be sure that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be sure, just use regex as expected There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, but the thing is - I don't want java String's method to treat the |
||||||
|
||||||
if (pathUntilWildcard.exists) { | ||||||
pathUntilWildcard | ||||||
.directChildren() | ||||||
.map { replaced => | ||||||
(if (path.startsWith("file:")) "file:" else "") + removeLastFileSeparator( | ||||||
replaced.toString | ||||||
) + stringPathAfterWildcard | ||||||
} | ||||||
} else { | ||||||
Nil | ||||||
} | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:benissimo: the doc