-
Notifications
You must be signed in to change notification settings - Fork 127
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
#1386: Get latest eo-runtime
dependency version from Maven
#1407
Conversation
…n from Maven Cenral feat(objectionary#1386): get runtime depenedncy from maven feat(objectionary#1386): cache runtime maven dependency feat(objectionary#1386): fix all linter mistakes
@mximp Can you take a look, please? |
/** | ||
* Hardcoded dependency. | ||
*/ | ||
static final Unchecked<Dependency> HARDCODED = DcsWithRuntime.dependency("0.28.10"); |
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.
@volodya-lombrozo why do we hardcode the version? Can't we pass it via constructor?
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.
Actually it's not used anywhere within the class - must be moved out.
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.
@mximp done. I've remove the static field at all. I've used it in tests previously.
* The dependencies source. | ||
* Dependency downloaded by HTTP from Maven Central. | ||
*/ | ||
static final Unchecked<Dependency> FROM_MAVEN = fromMaven(); |
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.
@volodya-lombrozo Can we make it private?
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.
@mximp done.
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.
@volodya-lombrozo please check comments above
* @param delegate Dependencies delegate. | ||
* @param source Runtime dependency source. | ||
*/ | ||
DcsWithRuntime(final Dependencies delegate, final Unchecked<Dependency> source) { |
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.
@volodya-lombrozo what is the point of supplying runtime dependency to add? I believe the whole idea of this class is to download it from Maven Central in case it's missing in delegate, am I right?
Maybe we can rename the class to DcsRuntimeCentral
to make it clear and get rid of two-args constructor?
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.
@mximp You miss one point here. The idea of the class is not to download dependency from Maven Central. The idea the class is to add eo-runtime
dependency to the collection of other dependencies. Moreover, we don't have to add eo-runtime
dependency if it is already present in the collection. By that reason, we can have different sources where we can get eo-runtime
dependency:
- hardcoded - we used hardcoded version previously
0.28.10
. - maven central - we are using it now
Of course, we can remove the constructor and hardcode only maven central, but it could be useful for the future testing to have additional constructor in order to "mock" source, because getting of "eo-runtime" dependency by http is a quite expensive .
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.
@volodya-lombrozo got it. I believe better name for hardcoded
would be fixed
or supplied
. Please check renaming suggestions for better readability.
* @param delegate Dependencies delegate. | ||
* @param source Runtime dependency source. | ||
*/ | ||
DcsWithRuntime(final Dependencies delegate, final Unchecked<Dependency> source) { |
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.
@volodya-lombrozo got it. I believe better name for hardcoded
would be fixed
or supplied
. Please check renaming suggestions for better readability.
* The main constructor. | ||
* Runtime dependency source. | ||
*/ | ||
private final Unchecked<Dependency> source; |
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.
@volodya-lombrozo let's rename to fixed
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.
@mximp renamed to supplied
.
* | ||
* @return Runtime dependency from Maven Central. | ||
*/ | ||
private static Unchecked<Dependency> fromMaven() { |
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.
@volodya-lombrozo let's rename to download
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.
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.
@mximp renamed to mavenDependency
* The dependencies source. | ||
* Dependency downloaded by HTTP from Maven Central. | ||
*/ | ||
private static final Unchecked<Dependency> FROM_MAVEN = fromMaven(); |
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.
@volodya-lombrozo let's rename to dynamic
. Also static methods should be called via class name.
So this would look like this:
private static final Unchecked<Dependency> DYNAMIC = DcsWithRuntime.download()
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.
@volodya-lombrozo Actually you can use Sticky here from Cactoos lib and get rid of static method.
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.
@mximp I'm already using Sticky
class:
private static Unchecked<Dependency> dependency(final String version) {
return new Unchecked<>(
new Sticky<>(
() -> {
final Dependency dependency = new Dependency();
dependency.setGroupId("org.eolang");
dependency.setArtifactId("eo-runtime");
dependency.setVersion(version);
dependency.setClassifier("");
return dependency;
}
)
);
}
I can't declare field as Sticky
, because in that case I have to deal with Exception
handling.
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.
@mximp also I can't get rid of the static method, because I wanna leave private static final Unchecked<Dependency> FROM_MAVEN
as a static field in order to increase speed of the tests. (when we have a static field, the method will be called only ~2 times, if you make it as a simple object field - the download will be happened each time when you create a new DcsWithRuntime
object > 10 times)
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.
@volodya-lombrozo I just mean why do we need the method dependency
. It just creates an object and used only in one place - we can inline it:
private static final Unchecked<Dependency> MAVEN_DEPENDENCY = new Unchecked<>(
new Sticky<>(() -> {
final Dependency dependency = new Dependency();
dependency.setGroupId("org.eolang");
dependency.setArtifactId("eo-runtime");
dependency.setVersion(version);
dependency.setClassifier("");
return dependency;
})
);
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.
@volodya-lombrozo corrected inlining:
private static final Unchecked<Dependency> MAVEN_DEPENDENCY =
new Unchecked<>(
new Sticky<>(() -> {
final Dependency dependency = new Dependency();
dependency.setGroupId("org.eolang");
dependency.setArtifactId("eo-runtime");
dependency.setVersion(
new XMLDocument(
new URL(
String.format(
"https://repo.maven.apache.org/maven2/%s/maven-metadata.xml",
"org/eolang/eo-runtime"
)
)
).xpath("//latest/text()").get(0)
);
dependency.setClassifier("");
return dependency;
})
);
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.
@mximp I got your idea. It has several advantages:
- we don't create extra methods
- we reduce total number of lines
On the other hand, that approach:
- creates lots of code that is placed above fields declarations and constructors (it's confusing to see a lot of code even before declaring variables).
- looks like a solid piece of code that do several things at once: (1) Creates dependency (2) Downloads latest version of library from maven. (3) Creates
Sticky
object. (some sort of violation of the principle of single responsibility)
I prefer using small methods and classes for achieving granularity and better code readability. But I can be mistaken, of course. Especially in "better code readability".
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.
@volodya-lombrozo I believe the biggest advantage of the inlined version is that I can see the whole logic of defining MAVEN_DEPENDENCY
in front of me: that it's sticky (i.e. cached), which URL used and that latest version is extracted. It's only several lines of code and I don't need to jump around the methods.
Regarding SRP, in this case I think we need to look at it a bit broader: we just extract version from Maven Central. I would probably agree that dealing with URL and parsing XML for a version might be a distinguishable bit of functionality but in this case making it to be a separate method doesn't provide any benefits: we just spread logic across multiple places.
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.
@yegor256 what is the better way?
@yegor256 take a look, please. |
@rultor merge |
Get latest
eo-runtime
dependency version from Maven.Closes: #1386