Skip to content
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

Add transitive dependency resolution #101

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ public void runLayersFromApiWithFlatRepository() {
.resolve(Resolvers.local()
.withLocalRepo("flat", Paths.get("target/repositories/flat").toAbsolutePath(), "flat"))
.layer("log")
.withModule("org.apache.logging.log4j:log4j-api:2.14.0")
.withModule("org.apache.logging.log4j:log4j-core:2.14.0")
.withModule("org.moditect.layrry.it:it-logconfig:1.0.0")
.withModule("org.apache.logging.log4j:log4j-api:2.14.0")
.withModule("org.apache.logging.log4j:log4j-core:2.14.0")
.withModule("org.moditect.layrry.it:it-logconfig:1.0.0")
.layer("foo")
.withParent("log")
.withModule("org.moditect.layrry.it:it-greeter:1.0.0")
.withModule("org.moditect.layrry.it:it-foo:1.0.0")
.withParent("log")
.withModule("org.moditect.layrry.it:it-greeter:1.0.0")
.withModule("org.moditect.layrry.it:it-foo:1.0.0")
.layer("bar")
.withParent("log")
.withModule("org.moditect.layrry.it:it-greeter:2.0.0")
.withModule("org.moditect.layrry.it:it-bar:1.0.0")
.withParent("log")
.withModule("org.moditect.layrry.it:it-greeter:2.0.0")
.withModule("org.moditect.layrry.it:it-bar:1.0.0")
.layer("app")
.withParent("foo")
.withParent("bar")
.withModule("org.moditect.layrry.it:it-app:1.0.0")
.withParent("foo")
.withParent("bar")
.withModule("org.moditect.layrry.it:it-app:1.0.0")
.build();

layers.run("org.moditect.layrry.it.app/org.moditect.layrry.it.app.App", "Alice");
Expand Down Expand Up @@ -114,4 +114,22 @@ public void runLayersFromTomlWithFlatRepository() throws Exception {

assertOutput();
}

@Test
public void runLayersFromYamlWithtransitivity() throws Exception {
LayrryLauncher.launch("--layers-config",
Path.of("src", "test", "resources", "layers-transitivity.yml").toAbsolutePath().toString(),
"Alice");

assertOutput();
}

@Test
public void runLayersFromTomlWithtransitivity() throws Exception {
LayrryLauncher.launch("--layers-config",
Path.of("src", "test", "resources", "layers-transitivity.toml").toAbsolutePath().toString(),
"Alice");

assertOutput();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# Copyright 2020 The ModiTect authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

[resolve]
useTransitivity = true

[layers.log]
modules = [
"org.apache.logging.log4j:log4j-core:2.14.0",
"org.moditect.layrry.it:it-logconfig:1.0.0"]
[layers.foo]
parents = ["log"]
modules = [
"org.moditect.layrry.it:it-foo:1.0.0"]
[layers.bar]
parents = ["log"]
modules = [
"org.moditect.layrry.it:it-bar:1.0.0"]
[layers.app]
parents = ["foo", "bar"]
modules = ["org.moditect.layrry.it:it-app:1.0.0"]
[main]
module = "org.moditect.layrry.it.app"
class = "org.moditect.layrry.it.app.App"
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Copyright 2020 The ModiTect authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

resolve:
useTransitivity: true

layers:
log:
modules:
- "org.apache.logging.log4j:log4j-core:2.14.0"
- "org.moditect.layrry.it:it-logconfig:1.0.0"
foo:
parents:
- "log"
modules:
- "org.moditect.layrry.it:it-foo:1.0.0"
bar:
parents:
- "log"
modules:
- "org.moditect.layrry.it:it-bar:1.0.0"
app:
parents:
- "foo"
- "bar"
modules:
- "org.moditect.layrry.it:it-app:1.0.0"
main:
module: org.moditect.layrry.it.app
class: org.moditect.layrry.it.app.App
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ private static void readResolve(LayersConfig config, TomlTable table) {
resolve.setRemote((Boolean) table.getOrDefault("remote", true));
resolve.setWorkOffline((Boolean) table.getOrDefault("workOffline", false));
resolve.setUseMavenCentral((Boolean) table.getOrDefault("useMavenCentral", true));
resolve.setUseTransitivity((Boolean) table.getOrDefault("useTransitivity", false));
resolve.setFromFile((String) table.get("fromFile"));
readRepositories(resolve, (TomlTable) table.get("localRepositories"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class Resolve {
private boolean remote = true;
private boolean workOffline = false;
private boolean useMavenCentral = true;
private boolean useTransitivity = false;
private String fromFile;

public Map<String, Repository> getLocalRepositories() {
Expand Down Expand Up @@ -58,6 +59,14 @@ public void setUseMavenCentral(boolean useMavenCentral) {
this.useMavenCentral = useMavenCentral;
}

public boolean isUseTransitivity() {
return useTransitivity;
}

public void setUseTransitivity(boolean useTransitivity) {
this.useTransitivity = useTransitivity;
}

public String getFromFile() {
return fromFile;
}
Expand All @@ -71,6 +80,7 @@ public String toString() {
return "Resolve [remote=" + remote +
", workOffline=" + workOffline +
", useMavenCentral=" + useMavenCentral +
", useTransitivity=" + useTransitivity +
", fromFile=" + fromFile +
", localRepositories=" + localRepositories + "]";
}
Expand Down
20 changes: 14 additions & 6 deletions layrry-core/src/main/java/org/moditect/layrry/RemoteResolve.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public interface RemoteResolve {
* Sets whether to consult any repositories Maven (Maven local and remote); defaults to true.
*
* @param enabled Whether to consult any repositories Maven (Maven local and remote); defaults to true.
* @return Modified instance of {@code RemoteMaven}
* @return Modified instance of {@code RemoteResolve}
*/
RemoteResolve enabled(boolean enabled);

/**
* Configures this {@link org.moditect.layrry.internal.resolver.RemoteResolve} from the specified file
* Configures this {@link RemoteResolve} from the specified file
*
* @param file The file the {@link org.moditect.layrry.internal.resolver.RemoteResolve} should be configured from
* @return Modified instance of {@code RemoteMaven}
* @param file The file the {@link RemoteResolve} should be configured from
* @return Modified instance of {@code RemoteResolve}
* @throws IllegalArgumentException
* If the file is not specified, is a directory, or does not exist
* @throws InvalidConfigurationFileException
Expand All @@ -48,15 +48,23 @@ public interface RemoteResolve {
* This method is able to override the value defined in settings.xml if loaded later.
*
* @param workOffline Whether to consult any remote Maven Repository in resolution; defaults to false.
* @return Modified instance of {@code RemoteMaven}
* @return Modified instance of {@code RemoteResolve}
*/
RemoteResolve workOffline(boolean workOffline);

/**
* Sets whether to consult the Maven Central Repository in resolution; defaults to true.
*
* @param useMavenCentral Whether to consult the Maven Central Repository in resolution; defaults to true.
* @return Modified instance of {@code RemoteMaven}
* @return Modified instance of {@code RemoteResolve}
*/
RemoteResolve withMavenCentralRepo(boolean useMavenCentral);

/**
* Sets whether to resolve transitive dependencies or not; defaults to false.
*
* @param useTransitivity Whether to resolve transitive dependencies or not; defaults to false.
* @return Modified instance of {@code RemoteResolve}
*/
RemoteResolve withTransitivity(boolean useTransitivity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private Layers configureResolve(LayersConfig layersConfig, Path layersConfigDir,
remote.enabled(resolve.isRemote());
remote.workOffline(resolve.isWorkOffline());
remote.withMavenCentralRepo(resolve.isUseMavenCentral());
remote.withTransitivity(resolve.isUseTransitivity());
String fromFilePath = resolve.getFromFile();
if (fromFilePath != null && !fromFilePath.isEmpty()) {
remote.fromFile(layersConfigDir.resolve(resolve.getFromFile()).toAbsolutePath());
Expand Down
Loading