-
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
#1361 Add eo-runtime dependency even if foreign dependencies are absent #1357
Changes from 5 commits
0e81929
3666441
d769ab8
240ae69
94c70fd
9413b25
ecd365d
3f528df
b1cc4a9
208a4d6
f9d9509
f95826d
ed02290
9ec81d7
cc433b6
8ee1651
8046a05
e46aa73
7ec79c9
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016-2022 Objectionary.com | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.eolang.maven; | ||
|
||
import org.apache.maven.model.Dependency; | ||
|
||
/** | ||
* RuntimeDependency is a class for keeping and getting the last eo-runtime dependency. | ||
* | ||
* @since 0.28.11 | ||
*/ | ||
final class EoRuntimeDependency { | ||
/** | ||
* EO runtime dependency group. | ||
*/ | ||
private final String group; | ||
|
||
/** | ||
* EO runtime dependency artifact name. | ||
*/ | ||
private final String artifact; | ||
|
||
/** | ||
* EO runtime dependency version. | ||
*/ | ||
private final String version; | ||
|
||
/** | ||
* Default constructor. | ||
*/ | ||
EoRuntimeDependency() { | ||
this("0.28.10"); | ||
} | ||
|
||
/** | ||
* Constructor with version. | ||
* | ||
* @param version Version of the eo-runtime library | ||
*/ | ||
EoRuntimeDependency(final String version) { | ||
this("org.eolang", "eo-runtime", version); | ||
} | ||
|
||
/** | ||
* The main constructor. | ||
* | ||
* @param group Dependency group | ||
* @param artifact Dependency artifact name | ||
* @param version Dependency version | ||
*/ | ||
EoRuntimeDependency(final String group, final String artifact, final String version) { | ||
this.group = group; | ||
this.artifact = artifact; | ||
this.version = version; | ||
} | ||
|
||
/** | ||
* Compares current dependency with other dependency. | ||
* | ||
* @param other Other dependency | ||
* @return True if other dependency is the eo-runtime dependency | ||
*/ | ||
boolean same(final Dependency other) { | ||
return this.group.equals(other.getGroupId()) | ||
&& this.artifact.equals(other.getArtifactId()); | ||
} | ||
|
||
/** | ||
* Converts EoRuntimeDependency to Maven Dependency. | ||
* | ||
* @return Maven Dependency | ||
*/ | ||
Dependency dependency() { | ||
final Dependency dependency = new Dependency(); | ||
dependency.setGroupId(this.group); | ||
dependency.setArtifactId(this.artifact); | ||
dependency.setVersion(this.version); | ||
dependency.setClassifier(""); | ||
return dependency; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,7 @@ private Collection<Dependency> deps() throws IOException { | |
tojo.set(AssembleMojo.ATTR_JAR, coords); | ||
} | ||
this.checkConflicts(deps); | ||
ResolveMojo.addRuntimeDependency(deps); | ||
return deps.stream() | ||
.map(ResolveMojo.Wrap::new) | ||
.sorted() | ||
|
@@ -202,6 +203,30 @@ private Collection<Dependency> deps() throws IOException { | |
.collect(Collectors.toList()); | ||
} | ||
|
||
/** | ||
* Check if runtime dependency is absent. | ||
* @param deps Dependencies | ||
* @todo #1361:90min Hardcoded version of EoRuntimeDependency. | ||
* See the EoRuntimeDependency constructor for more info. | ||
* It's much better to determine the version of the runtime library | ||
* dynamically. For example, we can fetch the latest version by http | ||
* or from config files. | ||
*/ | ||
private static void addRuntimeDependency(final Collection<Dependency> deps) { | ||
if (deps.stream().noneMatch(ResolveMojo::isRuntimeDependency)) { | ||
deps.add(new EoRuntimeDependency().dependency()); | ||
} | ||
} | ||
|
||
/** | ||
* Check if dependency is runtime dependency. | ||
* @param dependency Dependency | ||
* @return True if dependency is runtime dependency | ||
*/ | ||
private static boolean isRuntimeDependency(final Dependency dependency) { | ||
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. @volodya-lombrozo This can be inlined. I believe no need in separate static method. 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. Done |
||
return new EoRuntimeDependency().same(dependency); | ||
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. @volodya-lombrozo May we create only one instance of 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. Done |
||
} | ||
|
||
/** | ||
* Check dependencies for conflicts. | ||
* @param deps Dependencies | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016-2022 Objectionary.com | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.eolang.maven; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Deque; | ||
import java.util.LinkedList; | ||
import java.util.function.BiConsumer; | ||
import org.apache.maven.model.Dependency; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
|
||
/** | ||
* The class for emulating of Maven Central repository. | ||
* | ||
* @since 0.28.11 | ||
*/ | ||
final class MockMavenCentral implements BiConsumer<Dependency, Path> { | ||
|
||
/** | ||
* All saved dependencies. | ||
*/ | ||
private final Deque<Dependency> dependencies; | ||
|
||
/** | ||
* All paths where dependencies were saved. | ||
*/ | ||
private final Deque<Path> paths; | ||
|
||
/** | ||
* Default constructor with predefined containers. | ||
*/ | ||
MockMavenCentral() { | ||
this(new LinkedList<>(), new LinkedList<>()); | ||
} | ||
|
||
/** | ||
* The main constructor. | ||
* | ||
* @param dependencies Dependencies container | ||
* @param paths Paths container | ||
*/ | ||
private MockMavenCentral( | ||
final Deque<Dependency> dependencies, | ||
final Deque<Path> paths | ||
) { | ||
this.dependencies = dependencies; | ||
this.paths = paths; | ||
} | ||
|
||
@Override | ||
public void accept(final Dependency dependency, final Path path) { | ||
this.dependencies.addLast(dependency); | ||
this.paths.addLast(path); | ||
} | ||
|
||
/** | ||
* The method check the last saved dependency. | ||
* | ||
* @param dependency Expected dependency that was downloaded the last | ||
* @param path Expected path where we saved the last dependency | ||
*/ | ||
void assertLastDownloadedDependencyAndPathEquals(final Dependency dependency, final Path path) { | ||
MatcherAssert.assertThat(this.dependencies, Matchers.not(Matchers.empty())); | ||
MatcherAssert.assertThat(this.paths, Matchers.not(Matchers.empty())); | ||
final Dependency dep = this.dependencies.getLast(); | ||
final Path actual = this.paths.getLast(); | ||
MatcherAssert.assertThat(true, Matchers.is(dependenciesEquals(dep, dependency))); | ||
MatcherAssert.assertThat(actual, Matchers.equalTo(path)); | ||
} | ||
|
||
/** | ||
* The method checks if dependencies container is empty. | ||
* | ||
* @return True if at least one dependency was accepted | ||
*/ | ||
boolean isNotEmpty() { | ||
return !this.dependencies.isEmpty(); | ||
} | ||
|
||
/** | ||
* Compare dependency fields. | ||
* | ||
* @param expected Expected dependency | ||
* @param actual Actual dependency | ||
* @return True if the main properties are equal | ||
*/ | ||
private static boolean dependenciesEquals( | ||
final Dependency expected, | ||
final Dependency actual | ||
) { | ||
return theSameMainInformation(expected, actual) | ||
&& theSameTypeAndClassifier(expected, actual); | ||
} | ||
|
||
/** | ||
* Compare dependency fields. | ||
* | ||
* @param expected Expected dependency | ||
* @param actual Actual dependency | ||
* @return True if group, artifact and version are the same | ||
*/ | ||
private static boolean theSameMainInformation( | ||
final Dependency expected, | ||
final Dependency actual | ||
) { | ||
return actual.getGroupId().equals(expected.getGroupId()) | ||
&& actual.getArtifactId().equals(expected.getArtifactId()) | ||
&& actual.getVersion().equals(expected.getVersion()); | ||
} | ||
|
||
/** | ||
* Compare dependency fields. | ||
* | ||
* @param expected Expected dependency | ||
* @param actual Actual dependency | ||
* @return True of type and classifier the same | ||
*/ | ||
private static boolean theSameTypeAndClassifier( | ||
final Dependency expected, | ||
final Dependency actual | ||
) { | ||
return actual.getType().equals(expected.getType()) | ||
&& actual.getClassifier().equals(expected.getClassifier()); | ||
} | ||
} |
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 check this out: https://www.yegor256.com/2015/12/08/temporal-coupling-between-method-calls.html
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.
In order to obrain the issue I had to add a few private static classes. Please, take a look at
AllDependencies
andUniqueDependencies
classes.