diff --git a/compat/maven-embedder/pom.xml b/compat/maven-embedder/pom.xml index 377955a9ac..e791bd0c1f 100644 --- a/compat/maven-embedder/pom.xml +++ b/compat/maven-embedder/pom.xml @@ -176,7 +176,6 @@ under the License. com.google.jimfs jimfs - 1.3.0 test diff --git a/impl/maven-cli/pom.xml b/impl/maven-cli/pom.xml index 6ce70f20c3..bd8c0b61de 100644 --- a/impl/maven-cli/pom.xml +++ b/impl/maven-cli/pom.xml @@ -92,7 +92,6 @@ under the License. com.google.jimfs jimfs - 1.3.0 test diff --git a/impl/maven-impl/pom.xml b/impl/maven-impl/pom.xml index 72ab7cfe38..533c285082 100644 --- a/impl/maven-impl/pom.xml +++ b/impl/maven-impl/pom.xml @@ -164,6 +164,11 @@ under the License. maven-resolver-transport-apache test + + com.google.jimfs + jimfs + test + diff --git a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelInterpolator.java b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelInterpolator.java index c15e34380c..ced2d1598c 100644 --- a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelInterpolator.java +++ b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelInterpolator.java @@ -184,8 +184,12 @@ public class DefaultModelInterpolator implements ModelInterpolator { } } } + // un-prefixed model reflection + String value = projectProperty(model, projectDir, expression, false); // user properties - String value = request.getUserProperties().get(expression); + if (value == null) { + value = request.getUserProperties().get(expression); + } // model properties if (value == null) { value = model.getProperties().get(expression); @@ -198,11 +202,7 @@ public class DefaultModelInterpolator implements ModelInterpolator { if (value == null) { value = request.getSystemProperties().get("env." + expression); } - if (value != null) { - return value; - } - // model reflection - return projectProperty(model, projectDir, expression, false); + return value; } String projectProperty(Model model, Path projectDir, String subExpr, boolean prefixed) { @@ -223,7 +223,7 @@ public class DefaultModelInterpolator implements ModelInterpolator { } else if (prefixed && subExpr.startsWith("baseUri.")) { try { Object value = ReflectionValueExtractor.evaluate( - subExpr, projectDir.toAbsolutePath().toUri(), false); + subExpr, projectDir.toAbsolutePath().toUri(), true); if (value != null) { return value.toString(); } @@ -234,8 +234,8 @@ public class DefaultModelInterpolator implements ModelInterpolator { return rootLocator.findMandatoryRoot(projectDir).toString(); } else if (prefixed && subExpr.startsWith("rootDirectory.")) { try { - Object value = ReflectionValueExtractor.evaluate( - subExpr, projectDir.toAbsolutePath().toUri(), false); + Object value = + ReflectionValueExtractor.evaluate(subExpr, rootLocator.findMandatoryRoot(projectDir), true); if (value != null) { return value.toString(); } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/DefaultModelInterpolatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/DefaultModelInterpolatorTest.java new file mode 100644 index 0000000000..beae5c686a --- /dev/null +++ b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/DefaultModelInterpolatorTest.java @@ -0,0 +1,606 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.maven.internal.impl.model; + +import java.nio.file.FileSystem; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.TimeZone; +import java.util.concurrent.atomic.AtomicReference; + +import com.google.common.jimfs.Configuration; +import com.google.common.jimfs.Jimfs; +import org.apache.maven.api.Session; +import org.apache.maven.api.di.Priority; +import org.apache.maven.api.di.Provides; +import org.apache.maven.api.model.Build; +import org.apache.maven.api.model.Dependency; +import org.apache.maven.api.model.Model; +import org.apache.maven.api.model.Organization; +import org.apache.maven.api.model.Repository; +import org.apache.maven.api.model.Resource; +import org.apache.maven.api.model.Scm; +import org.apache.maven.api.services.Lookup; +import org.apache.maven.api.services.ModelBuilderRequest; +import org.apache.maven.api.services.model.ModelInterpolator; +import org.apache.maven.api.services.model.RootLocator; +import org.apache.maven.internal.impl.model.profile.SimpleProblemCollector; +import org.apache.maven.internal.impl.standalone.ApiRunner; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + */ +class DefaultModelInterpolatorTest { + + Map context; + ModelInterpolator interpolator; + Session session; + AtomicReference rootDirectory; // used in TestRootLocator below + + @BeforeEach + public void setUp() { + context = new HashMap<>(); + context.put("basedir", "myBasedir"); + context.put("anotherdir", "anotherBasedir"); + context.put("project.baseUri", "myBaseUri"); + + session = ApiRunner.createSession(injector -> { + injector.bindInstance(DefaultModelInterpolatorTest.class, this); + }); + interpolator = session.getService(Lookup.class).lookup(DefaultModelInterpolator.class); + } + + protected void assertProblemFree(SimpleProblemCollector collector) { + assertEquals(0, collector.getErrors().size(), "Expected no errors"); + assertEquals(0, collector.getWarnings().size(), "Expected no warnings"); + assertEquals(0, collector.getFatals().size(), "Expected no fatals"); + } + + @SuppressWarnings("SameParameterValue") + protected void assertCollectorState( + int numFatals, int numErrors, int numWarnings, SimpleProblemCollector collector) { + assertEquals(numErrors, collector.getErrors().size(), "Errors"); + assertEquals(numWarnings, collector.getWarnings().size(), "Warnings"); + assertEquals(numFatals, collector.getFatals().size(), "Fatals"); + } + + private ModelBuilderRequest.ModelBuilderRequestBuilder createModelBuildingRequest(Map p) { + ModelBuilderRequest.ModelBuilderRequestBuilder config = ModelBuilderRequest.builder() + .session(session) + .requestType(ModelBuilderRequest.RequestType.BUILD_PROJECT); + if (p != null) { + config.systemProperties(p); + } + return config; + } + + @Test + public void testDefaultBuildTimestampFormatShouldFormatTimeIn24HourFormat() { + Calendar cal = Calendar.getInstance(); + cal.setTimeZone(MavenBuildTimestamp.DEFAULT_BUILD_TIME_ZONE); + cal.set(Calendar.HOUR, 12); + cal.set(Calendar.AM_PM, Calendar.AM); + + // just to make sure all the bases are covered... + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 16); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.YEAR, 1976); + cal.set(Calendar.MONTH, Calendar.NOVEMBER); + cal.set(Calendar.DATE, 11); + + Date firstTestDate = cal.getTime(); + + cal.set(Calendar.HOUR, 11); + cal.set(Calendar.AM_PM, Calendar.PM); + + // just to make sure all the bases are covered... + cal.set(Calendar.HOUR_OF_DAY, 23); + + Date secondTestDate = cal.getTime(); + + SimpleDateFormat format = new SimpleDateFormat(MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT); + format.setTimeZone(MavenBuildTimestamp.DEFAULT_BUILD_TIME_ZONE); + assertEquals("1976-11-11T00:16:00Z", format.format(firstTestDate)); + assertEquals("1976-11-11T23:16:00Z", format.format(secondTestDate)); + } + + @Test + public void testDefaultBuildTimestampFormatWithLocalTimeZoneMidnightRollover() { + Calendar cal = Calendar.getInstance(); + cal.setTimeZone(TimeZone.getTimeZone("Europe/Berlin")); + + cal.set(Calendar.HOUR_OF_DAY, 1); + cal.set(Calendar.MINUTE, 16); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.YEAR, 2014); + cal.set(Calendar.MONTH, Calendar.JUNE); + cal.set(Calendar.DATE, 16); + + Date firstTestDate = cal.getTime(); + + cal.set(Calendar.MONTH, Calendar.NOVEMBER); + + Date secondTestDate = cal.getTime(); + + SimpleDateFormat format = new SimpleDateFormat(MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT); + format.setTimeZone(MavenBuildTimestamp.DEFAULT_BUILD_TIME_ZONE); + assertEquals("2014-06-15T23:16:00Z", format.format(firstTestDate)); + assertEquals("2014-11-16T00:16:00Z", format.format(secondTestDate)); + } + + @Test + public void testShouldNotThrowExceptionOnReferenceToNonExistentValue() throws Exception { + Scm scm = Scm.newBuilder().connection("${test}/somepath").build(); + Model model = Model.newBuilder().scm(scm).build(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( + model, Paths.get("."), createModelBuildingRequest(context).build(), collector); + + assertProblemFree(collector); + assertEquals("${test}/somepath", out.getScm().getConnection()); + } + + @Test + public void testShouldThrowExceptionOnRecursiveScmConnectionReference() throws Exception { + Scm scm = Scm.newBuilder() + .connection("${project.scm.connection}/somepath") + .build(); + Model model = Model.newBuilder().scm(scm).build(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + interpolator.interpolateModel( + model, (Path) null, createModelBuildingRequest(context).build(), collector); + assertCollectorState(0, 1, 0, collector); + } + + @Test + public void testShouldNotThrowExceptionOnReferenceToValueContainingNakedExpression() throws Exception { + Scm scm = Scm.newBuilder().connection("${test}/somepath").build(); + Map props = new HashMap<>(); + props.put("test", "test"); + Model model = Model.newBuilder().scm(scm).properties(props).build(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( + model, Paths.get("."), createModelBuildingRequest(context).build(), collector); + + assertProblemFree(collector); + + assertEquals("test/somepath", out.getScm().getConnection()); + } + + @Test + void shouldInterpolateOrganizationNameCorrectly() throws Exception { + String orgName = "MyCo"; + + Model model = Model.newBuilder() + .name("${project.organization.name} Tools") + .organization(Organization.newBuilder().name(orgName).build()) + .build(); + + Model out = interpolator.interpolateModel( + model, Paths.get("."), createModelBuildingRequest(context).build(), new SimpleProblemCollector()); + + assertEquals(orgName + " Tools", out.getName()); + } + + @Test + public void shouldInterpolateDependencyVersionToSetSameAsProjectVersion() throws Exception { + Model model = Model.newBuilder() + .version("3.8.1") + .dependencies(Collections.singletonList( + Dependency.newBuilder().version("${project.version}").build())) + .build(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( + model, Paths.get("."), createModelBuildingRequest(context).build(), collector); + assertCollectorState(0, 0, 0, collector); + + assertEquals("3.8.1", (out.getDependencies().get(0)).getVersion()); + } + + @Test + public void testShouldNotInterpolateDependencyVersionWithInvalidReference() throws Exception { + Model model = Model.newBuilder() + .version("3.8.1") + .dependencies(Collections.singletonList( + Dependency.newBuilder().version("${something}").build())) + .build(); + + /* + // This is the desired behaviour, however there are too many crappy poms in the repo and an issue with the + // timing of executing the interpolation + + try + { + new RegexBasedModelInterpolator().interpolate( model, context ); + fail( "Should have failed to interpolate with invalid reference" ); + } + catch ( ModelInterpolationException expected ) + { + assertTrue( true ); + } + */ + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( + model, Paths.get("."), createModelBuildingRequest(context).build(), collector); + assertProblemFree(collector); + + assertEquals("${something}", (out.getDependencies().get(0)).getVersion()); + } + + @Test + public void testTwoReferences() throws Exception { + Model model = Model.newBuilder() + .version("3.8.1") + .artifactId("foo") + .dependencies(Collections.singletonList(Dependency.newBuilder() + .version("${project.artifactId}-${project.version}") + .build())) + .build(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( + model, Paths.get("."), createModelBuildingRequest(context).build(), collector); + assertCollectorState(0, 0, 0, collector); + + assertEquals("foo-3.8.1", (out.getDependencies().get(0)).getVersion()); + } + + @Test + public void testProperty() throws Exception { + Model model = Model.newBuilder() + .version("3.8.1") + .artifactId("foo") + .repositories(Collections.singletonList(Repository.newBuilder() + .url("file://localhost/${anotherdir}/temp-repo") + .build())) + .build(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( + model, + Paths.get("projectBasedir"), + createModelBuildingRequest(context).build(), + collector); + assertProblemFree(collector); + + assertEquals( + "file://localhost/anotherBasedir/temp-repo", + (out.getRepositories().get(0)).getUrl()); + } + + @Test + public void testBasedirUnx() throws Exception { + FileSystem fs = Jimfs.newFileSystem(Configuration.unix()); + Path projectBasedir = fs.getPath("projectBasedir"); + + Model model = Model.newBuilder() + .version("3.8.1") + .artifactId("foo") + .repositories(Collections.singletonList( + Repository.newBuilder().url("${basedir}/temp-repo").build())) + .build(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( + model, projectBasedir, createModelBuildingRequest(context).build(), collector); + assertProblemFree(collector); + + assertEquals( + projectBasedir.toAbsolutePath() + "/temp-repo", + (out.getRepositories().get(0)).getUrl()); + } + + @Test + public void testBasedirWin() throws Exception { + FileSystem fs = Jimfs.newFileSystem(Configuration.windows()); + Path projectBasedir = fs.getPath("projectBasedir"); + + Model model = Model.newBuilder() + .version("3.8.1") + .artifactId("foo") + .repositories(Collections.singletonList( + Repository.newBuilder().url("${basedir}/temp-repo").build())) + .build(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( + model, projectBasedir, createModelBuildingRequest(context).build(), collector); + assertProblemFree(collector); + + assertEquals( + projectBasedir.toAbsolutePath() + "/temp-repo", + (out.getRepositories().get(0)).getUrl()); + } + + @Test + public void testBaseUri() throws Exception { + Path projectBasedir = Paths.get("projectBasedir"); + + Model model = Model.newBuilder() + .version("3.8.1") + .artifactId("foo") + .repositories(Collections.singletonList(Repository.newBuilder() + .url("${project.baseUri}/temp-repo") + .build())) + .build(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( + model, projectBasedir, createModelBuildingRequest(context).build(), collector); + assertProblemFree(collector); + + assertEquals( + projectBasedir.resolve("temp-repo").toUri().toString(), + (out.getRepositories().get(0)).getUrl()); + } + + @Test + void testRootDirectory() throws Exception { + Path rootDirectory = Paths.get("myRootDirectory"); + + Model model = Model.newBuilder() + .version("3.8.1") + .artifactId("foo") + .repositories(Collections.singletonList(Repository.newBuilder() + .url("file:${project.rootDirectory}/temp-repo") + .build())) + .build(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( + model, rootDirectory, createModelBuildingRequest(context).build(), collector); + assertProblemFree(collector); + + assertEquals("file:myRootDirectory/temp-repo", (out.getRepositories().get(0)).getUrl()); + } + + @Test + void testRootDirectoryWithUri() throws Exception { + Path rootDirectory = Paths.get("myRootDirectory"); + + Model model = Model.newBuilder() + .version("3.8.1") + .artifactId("foo") + .repositories(Collections.singletonList(Repository.newBuilder() + .url("${project.rootDirectory.uri}/temp-repo") + .build())) + .build(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( + model, rootDirectory, createModelBuildingRequest(context).build(), collector); + assertProblemFree(collector); + + assertEquals( + rootDirectory.resolve("temp-repo").toUri().toString(), + (out.getRepositories().get(0)).getUrl()); + } + + @Test + void testRootDirectoryWithNull() throws Exception { + Path projectDirectory = Paths.get("myProjectDirectory"); + this.rootDirectory = new AtomicReference<>(null); + + Model model = Model.newBuilder() + .version("3.8.1") + .artifactId("foo") + .repositories(Collections.singletonList(Repository.newBuilder() + .url("file:///${project.rootDirectory}/temp-repo") + .build())) + .build(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + IllegalStateException e = assertThrows( + IllegalStateException.class, + () -> interpolator.interpolateModel( + model, + projectDirectory, + createModelBuildingRequest(context).build(), + collector)); + + assertEquals(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE, e.getMessage()); + } + + @Test + public void testEnvars() throws Exception { + context.put("env.HOME", "/path/to/home"); + + Map modelProperties = new HashMap<>(); + modelProperties.put("outputDirectory", "${env.HOME}"); + + Model model = Model.newBuilder().properties(modelProperties).build(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( + model, Paths.get("."), createModelBuildingRequest(context).build(), collector); + assertProblemFree(collector); + + assertEquals("/path/to/home", out.getProperties().get("outputDirectory")); + } + + @Test + public void envarExpressionThatEvaluatesToNullReturnsTheLiteralString() throws Exception { + + Map modelProperties = new HashMap<>(); + modelProperties.put("outputDirectory", "${env.DOES_NOT_EXIST}"); + + Model model = Model.newBuilder().properties(modelProperties).build(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( + model, Paths.get("."), createModelBuildingRequest(context).build(), collector); + assertProblemFree(collector); + + assertEquals(out.getProperties().get("outputDirectory"), "${env.DOES_NOT_EXIST}"); + } + + @Test + public void expressionThatEvaluatesToNullReturnsTheLiteralString() throws Exception { + Map modelProperties = new HashMap<>(); + modelProperties.put("outputDirectory", "${DOES_NOT_EXIST}"); + + Model model = Model.newBuilder().properties(modelProperties).build(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( + model, Paths.get("."), createModelBuildingRequest(context).build(), collector); + assertProblemFree(collector); + + assertEquals("${DOES_NOT_EXIST}", out.getProperties().get("outputDirectory")); + } + + @Test + public void shouldInterpolateSourceDirectoryReferencedFromResourceDirectoryCorrectly() throws Exception { + Model model = Model.newBuilder() + .build(Build.newBuilder() + .sourceDirectory("correct") + .resources(List.of(Resource.newBuilder() + .directory("${project.build.sourceDirectory}") + .build())) + .build()) + .build(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( + model, (Path) null, createModelBuildingRequest(context).build(), collector); + assertCollectorState(0, 0, 0, collector); + + List outResources = out.getBuild().getResources(); + Iterator resIt = outResources.iterator(); + + assertEquals(model.getBuild().getSourceDirectory(), resIt.next().getDirectory()); + } + + @Test + public void shouldInterpolateUnprefixedBasedirExpression() throws Exception { + Path basedir = Paths.get("/test/path"); + Model model = Model.newBuilder() + .dependencies(Collections.singletonList(Dependency.newBuilder() + .systemPath("${basedir}/artifact.jar") + .build())) + .build(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model result = interpolator.interpolateModel( + model, basedir, createModelBuildingRequest(context).build(), collector); + assertProblemFree(collector); + + List rDeps = result.getDependencies(); + assertNotNull(rDeps); + assertEquals(1, rDeps.size()); + assertEquals( + basedir.resolve("artifact.jar").toAbsolutePath(), + Paths.get(rDeps.get(0).getSystemPath()).toAbsolutePath()); + } + + @Test + public void testRecursiveExpressionCycleNPE() throws Exception { + Map props = new HashMap<>(); + props.put("aa", "${bb}"); + props.put("bb", "${aa}"); + + Model model = Model.newBuilder().properties(props).build(); + + SimpleProblemCollector collector = new SimpleProblemCollector(); + + ModelBuilderRequest request = createModelBuildingRequest(Map.of()).build(); + interpolator.interpolateModel(model, null, request, collector); + + assertCollectorState(0, 2, 0, collector); + assertTrue(collector.getErrors().get(0).contains("recursive variable reference")); + } + + @Test + public void testRecursiveExpressionCycleBaseDir() throws Exception { + Map props = new HashMap<>(); + props.put("basedir", "${basedir}"); + ModelBuilderRequest request = createModelBuildingRequest(Map.of()).build(); + + Model model = Model.newBuilder().properties(props).build(); + + SimpleProblemCollector collector = new SimpleProblemCollector(); + ModelInterpolator interpolator = this.interpolator; + interpolator.interpolateModel(model, null, request, collector); + + assertCollectorState(0, 1, 0, collector); + assertEquals( + "recursive variable reference: basedir", collector.getErrors().get(0)); + } + + @Test + void shouldIgnorePropertiesWithPomPrefix() throws Exception { + final String orgName = "MyCo"; + final String uninterpolatedName = "${pom.organization.name} Tools"; + + Model model = Model.newBuilder() + .name(uninterpolatedName) + .organization(Organization.newBuilder().name(orgName).build()) + .build(); + + SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( + model, + null, + createModelBuildingRequest(context).build(), + // .validationLevel(ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_4_0), + collector); + + assertCollectorState(0, 0, 0, collector); + assertEquals(uninterpolatedName, out.getName()); + } + + @Provides + @Priority(10) + @SuppressWarnings("unused") + RootLocator testRootLocator() { + return new RootLocator() { + @Override + public Path findRoot(Path basedir) { + return rootDirectory != null ? rootDirectory.get() : basedir; + } + + @Override + public Path findMandatoryRoot(Path basedir) { + return Optional.ofNullable(findRoot(basedir)) + .orElseThrow(() -> new IllegalStateException(getNoRootMessage())); + } + }; + } +} diff --git a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/MavenBuildTimestampTest.java b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/MavenBuildTimestampTest.java new file mode 100644 index 0000000000..d19d32f45a --- /dev/null +++ b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/MavenBuildTimestampTest.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.maven.internal.impl.model; + +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +class MavenBuildTimestampTest { + @Test + void testMavenBuildTimestampUsesUTC() { + Map interpolationProperties = new HashMap<>(); + interpolationProperties.put("maven.build.timestamp.format", "yyyyMMdd'T'HHmm'Z'"); + MavenBuildTimestamp timestamp = new MavenBuildTimestamp(Instant.now(), interpolationProperties); + String formattedTimestamp = timestamp.formattedTimestamp(); + assertTrue(formattedTimestamp.endsWith("Z"), "We expect the UTC marker at the end of the timestamp."); + } +} diff --git a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/SimpleProblemCollector.java b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/SimpleProblemCollector.java index ecf45df50c..fb9b1977cf 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/SimpleProblemCollector.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/SimpleProblemCollector.java @@ -105,17 +105,22 @@ public class SimpleProblemCollector implements ModelProblemCollector { throw new UnsupportedOperationException(); } + public List getFatals() { + return getForLevel(ModelProblem.Severity.FATAL); + } + public List getErrors() { - return problems.stream() - .filter(p -> p.getSeverity() == ModelProblem.Severity.ERROR) - .map(p -> p.getMessage()) - .toList(); + return getForLevel(ModelProblem.Severity.ERROR); } public List getWarnings() { + return getForLevel(ModelProblem.Severity.WARNING); + } + + private List getForLevel(BuilderProblem.Severity severity) { return problems.stream() - .filter(p -> p.getSeverity() == ModelProblem.Severity.WARNING) - .map(p -> p.getMessage()) + .filter(p -> p.getSeverity() == severity) + .map(BuilderProblem::getMessage) .toList(); } } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/standalone/ApiRunner.java b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/standalone/ApiRunner.java index e4f6b092a6..7eba766de2 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/standalone/ApiRunner.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/standalone/ApiRunner.java @@ -29,6 +29,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Consumer; import java.util.stream.Collectors; import org.apache.maven.api.Artifact; @@ -64,7 +65,6 @@ import org.apache.maven.internal.impl.resolver.scopes.Maven4ScopeManagerConfigur import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.impl.RemoteRepositoryManager; import org.eclipse.aether.internal.impl.scope.ScopeManagerImpl; import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.LocalRepositoryManager; @@ -75,10 +75,21 @@ public class ApiRunner { * Create a new session. */ public static Session createSession() { + return createSession(null); + } + + /** + * Create a new session. + */ + public static Session createSession(Consumer injectorConsumer) { Injector injector = Injector.create(); injector.bindInstance(Injector.class, injector); injector.bindImplicit(ApiRunner.class); + injector.bindImplicit(RepositorySystemSupplier.class); injector.discover(ApiRunner.class.getClassLoader()); + if (injectorConsumer != null) { + injectorConsumer.accept(injector); + } Session session = injector.getInstance(Session.class); SessionScope scope = new SessionScope(); scope.enter(); @@ -286,24 +297,6 @@ public class ApiRunner { }; } - @Provides - @SuppressWarnings("unused") - static RepositorySystemSupplier newRepositorySystemSupplier() { - return new RepositorySystemSupplier(); - } - - @Provides - @SuppressWarnings("unused") - static RepositorySystem newRepositorySystem(RepositorySystemSupplier repositorySystemSupplier) { - return repositorySystemSupplier.getRepositorySystem(); - } - - @Provides - @SuppressWarnings("unused") - static RemoteRepositoryManager newRemoteRepositoryManager(RepositorySystemSupplier repositorySystemSupplier) { - return repositorySystemSupplier.getRemoteRepositoryManager(); - } - @Provides @SuppressWarnings("unused") static Session newSession(RepositorySystem system, Lookup lookup) { @@ -313,6 +306,10 @@ public class ApiRunner { // Java System properties System.getProperties().forEach((k, v) -> properties.put(k.toString(), v.toString())); + // Do not allow user settings to interfere with our unit tests + // TODO: remove that when this go more public + properties.put("user.home", "target"); + // SettingsDecrypter settingsDecrypter = // (SettingsDecrypter)Objects.requireNonNull(this.createSettingsDecrypter(preBoot)); // new DefaultProfileSelector(List.of( diff --git a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/standalone/RepositorySystemSupplier.java b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/standalone/RepositorySystemSupplier.java index 11c3083bc4..0d1423a7a3 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/standalone/RepositorySystemSupplier.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/standalone/RepositorySystemSupplier.java @@ -18,46 +18,11 @@ */ package org.apache.maven.internal.impl.standalone; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Supplier; -import org.apache.maven.api.services.ModelBuilder; -import org.apache.maven.internal.impl.DefaultModelUrlNormalizer; -import org.apache.maven.internal.impl.DefaultModelVersionParser; -import org.apache.maven.internal.impl.DefaultModelXmlFactory; -import org.apache.maven.internal.impl.DefaultPluginConfigurationExpander; -import org.apache.maven.internal.impl.DefaultSuperPomProvider; -import org.apache.maven.internal.impl.DefaultUrlNormalizer; -import org.apache.maven.internal.impl.model.DefaultDependencyManagementImporter; -import org.apache.maven.internal.impl.model.DefaultDependencyManagementInjector; -import org.apache.maven.internal.impl.model.DefaultInheritanceAssembler; -import org.apache.maven.internal.impl.model.DefaultInterpolator; -import org.apache.maven.internal.impl.model.DefaultModelBuilder; -import org.apache.maven.internal.impl.model.DefaultModelCacheFactory; -import org.apache.maven.internal.impl.model.DefaultModelInterpolator; -import org.apache.maven.internal.impl.model.DefaultModelNormalizer; -import org.apache.maven.internal.impl.model.DefaultModelPathTranslator; -import org.apache.maven.internal.impl.model.DefaultModelProcessor; -import org.apache.maven.internal.impl.model.DefaultModelValidator; -import org.apache.maven.internal.impl.model.DefaultPathTranslator; -import org.apache.maven.internal.impl.model.DefaultPluginManagementInjector; -import org.apache.maven.internal.impl.model.DefaultProfileInjector; -import org.apache.maven.internal.impl.model.DefaultProfileSelector; -import org.apache.maven.internal.impl.model.rootlocator.DefaultRootLocator; -import org.apache.maven.internal.impl.resolver.DefaultArtifactDescriptorReader; -import org.apache.maven.internal.impl.resolver.DefaultModelResolver; -import org.apache.maven.internal.impl.resolver.DefaultVersionRangeResolver; -import org.apache.maven.internal.impl.resolver.DefaultVersionResolver; -import org.apache.maven.internal.impl.resolver.MavenArtifactRelocationSource; -import org.apache.maven.internal.impl.resolver.PluginsMetadataGeneratorFactory; -import org.apache.maven.internal.impl.resolver.SnapshotMetadataGeneratorFactory; -import org.apache.maven.internal.impl.resolver.VersionsMetadataGeneratorFactory; -import org.apache.maven.internal.impl.resolver.relocation.DistributionManagementArtifactRelocationSource; -import org.apache.maven.internal.impl.resolver.relocation.UserPropertiesArtifactRelocationSource; +import org.apache.maven.api.annotations.Nullable; +import org.apache.maven.api.di.Named; +import org.apache.maven.api.di.Provides; import org.eclipse.aether.RepositoryListener; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory; @@ -79,34 +44,7 @@ import org.eclipse.aether.impl.UpdateCheckManager; import org.eclipse.aether.impl.UpdatePolicyAnalyzer; import org.eclipse.aether.impl.VersionRangeResolver; import org.eclipse.aether.impl.VersionResolver; -import org.eclipse.aether.internal.impl.DefaultArtifactPredicateFactory; -import org.eclipse.aether.internal.impl.DefaultArtifactResolver; -import org.eclipse.aether.internal.impl.DefaultChecksumPolicyProvider; -import org.eclipse.aether.internal.impl.DefaultChecksumProcessor; -import org.eclipse.aether.internal.impl.DefaultDeployer; -import org.eclipse.aether.internal.impl.DefaultInstaller; -import org.eclipse.aether.internal.impl.DefaultLocalPathComposer; -import org.eclipse.aether.internal.impl.DefaultLocalPathPrefixComposerFactory; -import org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider; -import org.eclipse.aether.internal.impl.DefaultMetadataResolver; -import org.eclipse.aether.internal.impl.DefaultOfflineController; -import org.eclipse.aether.internal.impl.DefaultPathProcessor; -import org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager; -import org.eclipse.aether.internal.impl.DefaultRepositoryConnectorProvider; -import org.eclipse.aether.internal.impl.DefaultRepositoryEventDispatcher; -import org.eclipse.aether.internal.impl.DefaultRepositoryLayoutProvider; -import org.eclipse.aether.internal.impl.DefaultRepositorySystem; -import org.eclipse.aether.internal.impl.DefaultRepositorySystemLifecycle; -import org.eclipse.aether.internal.impl.DefaultTrackingFileManager; -import org.eclipse.aether.internal.impl.DefaultTransporterProvider; -import org.eclipse.aether.internal.impl.DefaultUpdateCheckManager; -import org.eclipse.aether.internal.impl.DefaultUpdatePolicyAnalyzer; -import org.eclipse.aether.internal.impl.EnhancedLocalRepositoryManagerFactory; -import org.eclipse.aether.internal.impl.LocalPathComposer; -import org.eclipse.aether.internal.impl.LocalPathPrefixComposerFactory; -import org.eclipse.aether.internal.impl.Maven2RepositoryLayoutFactory; -import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; -import org.eclipse.aether.internal.impl.TrackingFileManager; +import org.eclipse.aether.internal.impl.*; import org.eclipse.aether.internal.impl.checksum.DefaultChecksumAlgorithmFactorySelector; import org.eclipse.aether.internal.impl.checksum.Md5ChecksumAlgorithmFactory; import org.eclipse.aether.internal.impl.checksum.Sha1ChecksumAlgorithmFactory; @@ -122,7 +60,6 @@ import org.eclipse.aether.internal.impl.collect.df.DfDependencyCollector; import org.eclipse.aether.internal.impl.filter.DefaultRemoteRepositoryFilterManager; import org.eclipse.aether.internal.impl.filter.GroupIdRemoteRepositoryFilterSource; import org.eclipse.aether.internal.impl.filter.PrefixesRemoteRepositoryFilterSource; -import org.eclipse.aether.internal.impl.resolution.TrustedChecksumsArtifactResolverPostProcessor; import org.eclipse.aether.internal.impl.synccontext.DefaultSyncContextFactory; import org.eclipse.aether.internal.impl.synccontext.named.NameMapper; import org.eclipse.aether.internal.impl.synccontext.named.NameMappers; @@ -159,942 +96,460 @@ import org.eclipse.aether.spi.resolution.ArtifactResolverPostProcessor; import org.eclipse.aether.spi.synccontext.SyncContextFactory; import org.eclipse.aether.transport.apache.ApacheTransporterFactory; import org.eclipse.aether.transport.file.FileTransporterFactory; -import org.eclipse.aether.util.version.GenericVersionScheme; -import org.eclipse.aether.version.VersionScheme; /** - * A simple memorizing {@link Supplier} of {@link RepositorySystem} instance, that on first call - * supplies lazily constructed instance, and on each subsequent call same instance. Hence, this instance should be - * thrown away immediately once repository system was created and there is no need for more instances. If new - * repository system instance needed, new instance of this class must be created. For proper shut down of returned - * repository system instance(s) use {@link RepositorySystem#shutdown()} method on supplied instance(s). - *

- * Since Resolver 2.0 this class offers access to various components via public getters, and allows even partial object - * graph construction. - *

- * Extend this class {@code createXXX()} methods and override to customize, if needed. The contract of this class makes - * sure that these (potentially overridden) methods are invoked only once, and instance created by those methods are - * memorized and kept as long as supplier instance is kept open. - *

- * This class is not thread safe and must be used from one thread only, while the constructed {@link RepositorySystem} - * is thread safe. - *

- * Important: Given the instance of supplier memorizes the supplier {@link RepositorySystem} instance it supplies, - * their lifecycle is shared as well: once supplied repository system is shut-down, this instance becomes closed as - * well. Any subsequent {@code getXXX} method invocation attempt will fail with {@link IllegalStateException}. + * DI Bridge for Maven Resolver */ -public class RepositorySystemSupplier implements Supplier { - private final AtomicBoolean closed = new AtomicBoolean(false); +@SuppressWarnings("unused") +public class RepositorySystemSupplier { - public RepositorySystemSupplier() {} - - private void checkClosed() { - if (closed.get()) { - throw new IllegalStateException("Supplier is closed"); - } + @Provides + static MetadataResolver newMetadataResolver( + RepositoryEventDispatcher repositoryEventDispatcher, + UpdateCheckManager updateCheckManager, + RepositoryConnectorProvider repositoryConnectorProvider, + RemoteRepositoryManager remoteRepositoryManager, + SyncContextFactory syncContextFactory, + OfflineController offlineController, + RemoteRepositoryFilterManager remoteRepositoryFilterManager, + PathProcessor pathProcessor) { + return new DefaultMetadataResolver( + repositoryEventDispatcher, + updateCheckManager, + repositoryConnectorProvider, + remoteRepositoryManager, + syncContextFactory, + offlineController, + remoteRepositoryFilterManager, + pathProcessor); } - private PathProcessor pathProcessor; - - public final PathProcessor getPathProcessor() { - checkClosed(); - if (pathProcessor == null) { - pathProcessor = createPathProcessor(); - } - return pathProcessor; + @Provides + static RepositoryEventDispatcher newRepositoryEventDispatcher(@Nullable Map listeners) { + return new DefaultRepositoryEventDispatcher(listeners != null ? listeners : Map.of()); } - protected PathProcessor createPathProcessor() { - return new DefaultPathProcessor(); + @Provides + static UpdateCheckManager newUpdateCheckManager( + TrackingFileManager trackingFileManager, + UpdatePolicyAnalyzer updatePolicyAnalyzer, + PathProcessor pathProcessor) { + return new DefaultUpdateCheckManager(trackingFileManager, updatePolicyAnalyzer, pathProcessor); } - private ChecksumProcessor checksumProcessor; - - public final ChecksumProcessor getChecksumProcessor() { - checkClosed(); - if (checksumProcessor == null) { - checksumProcessor = createChecksumProcessor(); - } - return checksumProcessor; - } - - protected ChecksumProcessor createChecksumProcessor() { - return new DefaultChecksumProcessor(getPathProcessor()); - } - - private TrackingFileManager trackingFileManager; - - public final TrackingFileManager getTrackingFileManager() { - checkClosed(); - if (trackingFileManager == null) { - trackingFileManager = createTrackingFileManager(); - } - return trackingFileManager; - } - - protected TrackingFileManager createTrackingFileManager() { + @Provides + static TrackingFileManager newTrackingFileManager() { return new DefaultTrackingFileManager(); } - private LocalPathComposer localPathComposer; - - public final LocalPathComposer getLocalPathComposer() { - checkClosed(); - if (localPathComposer == null) { - localPathComposer = createLocalPathComposer(); - } - return localPathComposer; - } - - protected LocalPathComposer createLocalPathComposer() { - return new DefaultLocalPathComposer(); - } - - private LocalPathPrefixComposerFactory localPathPrefixComposerFactory; - - public final LocalPathPrefixComposerFactory getLocalPathPrefixComposerFactory() { - checkClosed(); - if (localPathPrefixComposerFactory == null) { - localPathPrefixComposerFactory = createLocalPathPrefixComposerFactory(); - } - return localPathPrefixComposerFactory; - } - - protected LocalPathPrefixComposerFactory createLocalPathPrefixComposerFactory() { - return new DefaultLocalPathPrefixComposerFactory(); - } - - private RepositorySystemLifecycle repositorySystemLifecycle; - - public final RepositorySystemLifecycle getRepositorySystemLifecycle() { - checkClosed(); - if (repositorySystemLifecycle == null) { - repositorySystemLifecycle = createRepositorySystemLifecycle(); - repositorySystemLifecycle.addOnSystemEndedHandler(() -> closed.set(true)); - } - return repositorySystemLifecycle; - } - - protected RepositorySystemLifecycle createRepositorySystemLifecycle() { - return new DefaultRepositorySystemLifecycle(); - } - - private OfflineController offlineController; - - public final OfflineController getOfflineController() { - checkClosed(); - if (offlineController == null) { - offlineController = createOfflineController(); - } - return offlineController; - } - - protected OfflineController createOfflineController() { - return new DefaultOfflineController(); - } - - private UpdatePolicyAnalyzer updatePolicyAnalyzer; - - public final UpdatePolicyAnalyzer getUpdatePolicyAnalyzer() { - checkClosed(); - if (updatePolicyAnalyzer == null) { - updatePolicyAnalyzer = createUpdatePolicyAnalyzer(); - } - return updatePolicyAnalyzer; - } - - protected UpdatePolicyAnalyzer createUpdatePolicyAnalyzer() { + @Provides + static UpdatePolicyAnalyzer newUpdatePolicyAnalyzer() { return new DefaultUpdatePolicyAnalyzer(); } - private ChecksumPolicyProvider checksumPolicyProvider; - - public final ChecksumPolicyProvider getChecksumPolicyProvider() { - checkClosed(); - if (checksumPolicyProvider == null) { - checksumPolicyProvider = createChecksumPolicyProvider(); - } - return checksumPolicyProvider; + @Provides + static RepositoryConnectorProvider newRepositoryConnectorProvider( + Map connectorFactories, + RemoteRepositoryFilterManager remoteRepositoryFilterManager) { + return new DefaultRepositoryConnectorProvider(connectorFactories, remoteRepositoryFilterManager); } - protected ChecksumPolicyProvider createChecksumPolicyProvider() { + @Named("basic") + @Provides + static BasicRepositoryConnectorFactory newBasicRepositoryConnectorFactory( + TransporterProvider transporterProvider, + RepositoryLayoutProvider layoutProvider, + ChecksumPolicyProvider checksumPolicyProvider, + ChecksumProcessor checksumProcessor, + Map providedChecksumsSources) { + return new BasicRepositoryConnectorFactory( + transporterProvider, + layoutProvider, + checksumPolicyProvider, + checksumProcessor, + providedChecksumsSources); + } + + @Provides + static RepositoryLayoutProvider newRepositoryLayoutProvider(Map layoutFactories) { + return new DefaultRepositoryLayoutProvider(layoutFactories); + } + + @Provides + @Named(Maven2RepositoryLayoutFactory.NAME) + static Maven2RepositoryLayoutFactory newMaven2RepositoryLayoutFactory( + ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector, + ArtifactPredicateFactory artifactPredicateFactory) { + return new Maven2RepositoryLayoutFactory(checksumAlgorithmFactorySelector, artifactPredicateFactory); + } + + @Provides + static SyncContextFactory newSyncContextFactory(NamedLockFactoryAdapterFactory namedLockFactoryAdapterFactory) { + return new DefaultSyncContextFactory(namedLockFactoryAdapterFactory); + } + + @Provides + static OfflineController newOfflineController() { + return new DefaultOfflineController(); + } + + @Provides + static RemoteRepositoryFilterManager newRemoteRepositoryFilterManager( + Map sources) { + return new DefaultRemoteRepositoryFilterManager(sources); + } + + @Provides + @Named(GroupIdRemoteRepositoryFilterSource.NAME) + static GroupIdRemoteRepositoryFilterSource newGroupIdRemoteRepositoryFilterSource( + RepositorySystemLifecycle repositorySystemLifecycle) { + return new GroupIdRemoteRepositoryFilterSource(repositorySystemLifecycle); + } + + @Provides + @Named(PrefixesRemoteRepositoryFilterSource.NAME) + static PrefixesRemoteRepositoryFilterSource newPrefixesRemoteRepositoryFilterSource( + RepositoryLayoutProvider repositoryLayoutProvider) { + return new PrefixesRemoteRepositoryFilterSource(repositoryLayoutProvider); + } + + @Provides + static PathProcessor newPathProcessor() { + return new DefaultPathProcessor(); + } + + @Provides + static RepositorySystem newRepositorySystem( + VersionResolver versionResolver, + VersionRangeResolver versionRangeResolver, + ArtifactResolver artifactResolver, + MetadataResolver metadataResolver, + ArtifactDescriptorReader artifactDescriptorReader, + DependencyCollector dependencyCollector, + Installer installer, + Deployer deployer, + LocalRepositoryProvider localRepositoryProvider, + SyncContextFactory syncContextFactory, + RemoteRepositoryManager remoteRepositoryManager, + RepositorySystemLifecycle repositorySystemLifecycle, + @Nullable Map artifactDecoratorFactories) { + return new DefaultRepositorySystem( + versionResolver, + versionRangeResolver, + artifactResolver, + metadataResolver, + artifactDescriptorReader, + dependencyCollector, + installer, + deployer, + localRepositoryProvider, + syncContextFactory, + remoteRepositoryManager, + repositorySystemLifecycle, + artifactDecoratorFactories != null ? artifactDecoratorFactories : Map.of()); + } + + @Provides + static RemoteRepositoryManager newRemoteRepositoryManager( + UpdatePolicyAnalyzer updatePolicyAnalyzer, ChecksumPolicyProvider checksumPolicyProvider) { + return new DefaultRemoteRepositoryManager(updatePolicyAnalyzer, checksumPolicyProvider); + } + + @Provides + static ChecksumPolicyProvider newChecksumPolicyProvider() { return new DefaultChecksumPolicyProvider(); } - private UpdateCheckManager updateCheckManager; - - public final UpdateCheckManager getUpdateCheckManager() { - checkClosed(); - if (updateCheckManager == null) { - updateCheckManager = createUpdateCheckManager(); - } - return updateCheckManager; + @Provides + static NamedLockFactoryAdapterFactory newNamedLockFactoryAdapterFactory( + Map factories, + Map nameMappers, + RepositorySystemLifecycle lifecycle) { + return new NamedLockFactoryAdapterFactoryImpl(factories, nameMappers, lifecycle); } - protected UpdateCheckManager createUpdateCheckManager() { - return new DefaultUpdateCheckManager(getTrackingFileManager(), getUpdatePolicyAnalyzer(), getPathProcessor()); + @Provides + @Named(FileLockNamedLockFactory.NAME) + static FileLockNamedLockFactory newFileLockNamedLockFactory() { + return new FileLockNamedLockFactory(); } - private Map namedLockFactories; - - public final Map getNamedLockFactories() { - checkClosed(); - if (namedLockFactories == null) { - namedLockFactories = createNamedLockFactories(); - } - return namedLockFactories; + @Provides + @Named(LocalReadWriteLockNamedLockFactory.NAME) + static LocalReadWriteLockNamedLockFactory newLocalReadWriteLockNamedLockFactory() { + return new LocalReadWriteLockNamedLockFactory(); } - protected Map createNamedLockFactories() { - HashMap result = new HashMap<>(); - result.put(NoopNamedLockFactory.NAME, new NoopNamedLockFactory()); - result.put(LocalReadWriteLockNamedLockFactory.NAME, new LocalReadWriteLockNamedLockFactory()); - result.put(LocalSemaphoreNamedLockFactory.NAME, new LocalSemaphoreNamedLockFactory()); - result.put(FileLockNamedLockFactory.NAME, new FileLockNamedLockFactory()); - return result; + @Provides + @Named(LocalSemaphoreNamedLockFactory.NAME) + static LocalSemaphoreNamedLockFactory newLocalSemaphoreNamedLockFactory() { + return new LocalSemaphoreNamedLockFactory(); } - private Map nameMappers; - - public final Map getNameMappers() { - checkClosed(); - if (nameMappers == null) { - nameMappers = createNameMappers(); - } - return nameMappers; + @Provides + @Named(NoopNamedLockFactory.NAME) + static NoopNamedLockFactory newNoopNamedLockFactory() { + return new NoopNamedLockFactory(); } - protected Map createNameMappers() { - HashMap result = new HashMap<>(); - result.put(NameMappers.STATIC_NAME, NameMappers.staticNameMapper()); - result.put(NameMappers.GAV_NAME, NameMappers.gavNameMapper()); - result.put(NameMappers.DISCRIMINATING_NAME, NameMappers.discriminatingNameMapper()); - result.put(NameMappers.FILE_GAV_NAME, NameMappers.fileGavNameMapper()); - result.put(NameMappers.FILE_HGAV_NAME, NameMappers.fileHashingGavNameMapper()); - return result; + @Provides + @Named(NameMappers.STATIC_NAME) + static NameMapper staticNameMapper() { + return NameMappers.staticNameMapper(); } - private NamedLockFactoryAdapterFactory namedLockFactoryAdapterFactory; - - public final NamedLockFactoryAdapterFactory getNamedLockFactoryAdapterFactory() { - checkClosed(); - if (namedLockFactoryAdapterFactory == null) { - namedLockFactoryAdapterFactory = createNamedLockFactoryAdapterFactory(); - } - return namedLockFactoryAdapterFactory; + @Provides + @Named(NameMappers.GAV_NAME) + static NameMapper gavNameMapper() { + return NameMappers.gavNameMapper(); } - protected NamedLockFactoryAdapterFactory createNamedLockFactoryAdapterFactory() { - return new NamedLockFactoryAdapterFactoryImpl( - getNamedLockFactories(), getNameMappers(), getRepositorySystemLifecycle()); + @Provides + @Named(NameMappers.DISCRIMINATING_NAME) + static NameMapper discriminatingNameMapper() { + return NameMappers.discriminatingNameMapper(); } - private SyncContextFactory syncContextFactory; - - public final SyncContextFactory getSyncContextFactory() { - checkClosed(); - if (syncContextFactory == null) { - syncContextFactory = createSyncContextFactory(); - } - return syncContextFactory; + @Provides + @Named(NameMappers.FILE_GAV_NAME) + static NameMapper fileGavNameMapper() { + return NameMappers.fileGavNameMapper(); } - protected SyncContextFactory createSyncContextFactory() { - return new DefaultSyncContextFactory(getNamedLockFactoryAdapterFactory()); + @Provides + @Named(NameMappers.FILE_HGAV_NAME) + static NameMapper fileHashingGavNameMapper() { + return NameMappers.fileHashingGavNameMapper(); } - private Map checksumAlgorithmFactories; - - public final Map getChecksumAlgorithmFactories() { - checkClosed(); - if (checksumAlgorithmFactories == null) { - checksumAlgorithmFactories = createChecksumAlgorithmFactories(); - } - return checksumAlgorithmFactories; + @Provides + static RepositorySystemLifecycle newRepositorySystemLifecycle() { + return new DefaultRepositorySystemLifecycle(); } - protected Map createChecksumAlgorithmFactories() { - HashMap result = new HashMap<>(); - result.put(Sha512ChecksumAlgorithmFactory.NAME, new Sha512ChecksumAlgorithmFactory()); - result.put(Sha256ChecksumAlgorithmFactory.NAME, new Sha256ChecksumAlgorithmFactory()); - result.put(Sha1ChecksumAlgorithmFactory.NAME, new Sha1ChecksumAlgorithmFactory()); - result.put(Md5ChecksumAlgorithmFactory.NAME, new Md5ChecksumAlgorithmFactory()); - return result; - } - - private ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector; - - public final ChecksumAlgorithmFactorySelector getChecksumAlgorithmFactorySelector() { - checkClosed(); - if (checksumAlgorithmFactorySelector == null) { - checksumAlgorithmFactorySelector = createChecksumAlgorithmFactorySelector(); - } - return checksumAlgorithmFactorySelector; - } - - protected ChecksumAlgorithmFactorySelector createChecksumAlgorithmFactorySelector() { - return new DefaultChecksumAlgorithmFactorySelector(getChecksumAlgorithmFactories()); - } - - private ArtifactPredicateFactory artifactPredicateFactory; - - public final ArtifactPredicateFactory getArtifactPredicateFactory() { - checkClosed(); - if (artifactPredicateFactory == null) { - artifactPredicateFactory = createArtifactPredicateFactory(); - } - return artifactPredicateFactory; - } - - protected ArtifactPredicateFactory createArtifactPredicateFactory() { - return new DefaultArtifactPredicateFactory(getChecksumAlgorithmFactorySelector()); - } - - private Map repositoryLayoutFactories; - - public final Map getRepositoryLayoutFactories() { - checkClosed(); - if (repositoryLayoutFactories == null) { - repositoryLayoutFactories = createRepositoryLayoutFactories(); - } - return repositoryLayoutFactories; - } - - protected Map createRepositoryLayoutFactories() { - HashMap result = new HashMap<>(); - result.put( - Maven2RepositoryLayoutFactory.NAME, - new Maven2RepositoryLayoutFactory( - getChecksumAlgorithmFactorySelector(), getArtifactPredicateFactory())); - return result; - } - - private RepositoryLayoutProvider repositoryLayoutProvider; - - public final RepositoryLayoutProvider getRepositoryLayoutProvider() { - checkClosed(); - if (repositoryLayoutProvider == null) { - repositoryLayoutProvider = createRepositoryLayoutProvider(); - } - return repositoryLayoutProvider; - } - - protected RepositoryLayoutProvider createRepositoryLayoutProvider() { - return new DefaultRepositoryLayoutProvider(getRepositoryLayoutFactories()); - } - - private LocalRepositoryProvider localRepositoryProvider; - - public final LocalRepositoryProvider getLocalRepositoryProvider() { - checkClosed(); - if (localRepositoryProvider == null) { - localRepositoryProvider = createLocalRepositoryProvider(); - } - return localRepositoryProvider; - } - - protected LocalRepositoryProvider createLocalRepositoryProvider() { - LocalPathComposer localPathComposer = getLocalPathComposer(); - HashMap localRepositoryProviders = new HashMap<>(2); - localRepositoryProviders.put( - SimpleLocalRepositoryManagerFactory.NAME, new SimpleLocalRepositoryManagerFactory(localPathComposer)); - localRepositoryProviders.put( - EnhancedLocalRepositoryManagerFactory.NAME, - new EnhancedLocalRepositoryManagerFactory( - localPathComposer, getTrackingFileManager(), getLocalPathPrefixComposerFactory())); - return new DefaultLocalRepositoryProvider(localRepositoryProviders); - } - - private RemoteRepositoryManager remoteRepositoryManager; - - public final RemoteRepositoryManager getRemoteRepositoryManager() { - checkClosed(); - if (remoteRepositoryManager == null) { - remoteRepositoryManager = createRemoteRepositoryManager(); - } - return remoteRepositoryManager; - } - - protected RemoteRepositoryManager createRemoteRepositoryManager() { - return new DefaultRemoteRepositoryManager(getUpdatePolicyAnalyzer(), getChecksumPolicyProvider()); - } - - private Map remoteRepositoryFilterSources; - - public final Map getRemoteRepositoryFilterSources() { - checkClosed(); - if (remoteRepositoryFilterSources == null) { - remoteRepositoryFilterSources = createRemoteRepositoryFilterSources(); - } - return remoteRepositoryFilterSources; - } - - protected Map createRemoteRepositoryFilterSources() { - HashMap result = new HashMap<>(); - result.put( - GroupIdRemoteRepositoryFilterSource.NAME, - new GroupIdRemoteRepositoryFilterSource(getRepositorySystemLifecycle())); - result.put( - PrefixesRemoteRepositoryFilterSource.NAME, - new PrefixesRemoteRepositoryFilterSource(getRepositoryLayoutProvider())); - return result; - } - - private RemoteRepositoryFilterManager remoteRepositoryFilterManager; - - public final RemoteRepositoryFilterManager getRemoteRepositoryFilterManager() { - checkClosed(); - if (remoteRepositoryFilterManager == null) { - remoteRepositoryFilterManager = createRemoteRepositoryFilterManager(); - } - return remoteRepositoryFilterManager; - } - - protected RemoteRepositoryFilterManager createRemoteRepositoryFilterManager() { - return new DefaultRemoteRepositoryFilterManager(getRemoteRepositoryFilterSources()); - } - - private Map repositoryListeners; - - public final Map getRepositoryListeners() { - checkClosed(); - if (repositoryListeners == null) { - repositoryListeners = createRepositoryListeners(); - } - return repositoryListeners; - } - - protected Map createRepositoryListeners() { - return new HashMap<>(); - } - - private RepositoryEventDispatcher repositoryEventDispatcher; - - public final RepositoryEventDispatcher getRepositoryEventDispatcher() { - checkClosed(); - if (repositoryEventDispatcher == null) { - repositoryEventDispatcher = createRepositoryEventDispatcher(); - } - return repositoryEventDispatcher; - } - - protected RepositoryEventDispatcher createRepositoryEventDispatcher() { - return new DefaultRepositoryEventDispatcher(getRepositoryListeners()); - } - - private Map trustedChecksumsSources; - - public final Map getTrustedChecksumsSources() { - checkClosed(); - if (trustedChecksumsSources == null) { - trustedChecksumsSources = createTrustedChecksumsSources(); - } - return trustedChecksumsSources; - } - - protected Map createTrustedChecksumsSources() { - HashMap result = new HashMap<>(); - result.put( - SparseDirectoryTrustedChecksumsSource.NAME, - new SparseDirectoryTrustedChecksumsSource(getChecksumProcessor(), getLocalPathComposer())); - result.put( - SummaryFileTrustedChecksumsSource.NAME, - new SummaryFileTrustedChecksumsSource(getLocalPathComposer(), getRepositorySystemLifecycle())); - return result; - } - - private Map providedChecksumsSources; - - public final Map getProvidedChecksumsSources() { - checkClosed(); - if (providedChecksumsSources == null) { - providedChecksumsSources = createProvidedChecksumsSources(); - } - return providedChecksumsSources; - } - - protected Map createProvidedChecksumsSources() { - HashMap result = new HashMap<>(); - result.put( - TrustedToProvidedChecksumsSourceAdapter.NAME, - new TrustedToProvidedChecksumsSourceAdapter(getTrustedChecksumsSources())); - return result; - } - - private Map checksumExtractorStrategies; - - public final Map getChecksumExtractorStrategies() { - checkClosed(); - if (checksumExtractorStrategies == null) { - checksumExtractorStrategies = createChecksumExtractorStrategies(); - } - return checksumExtractorStrategies; - } - - protected Map createChecksumExtractorStrategies() { - HashMap result = new HashMap<>(); - result.put(XChecksumExtractor.NAME, new XChecksumExtractor()); - result.put(Nx2ChecksumExtractor.NAME, new Nx2ChecksumExtractor()); - return result; - } - - private ChecksumExtractor checksumExtractor; - - public final ChecksumExtractor getChecksumExtractor() { - checkClosed(); - if (checksumExtractor == null) { - checksumExtractor = createChecksumExtractor(); - } - return checksumExtractor; - } - - protected ChecksumExtractor createChecksumExtractor() { - return new DefaultChecksumExtractor(getChecksumExtractorStrategies()); - } - - private Map transporterFactories; - - public final Map getTransporterFactories() { - checkClosed(); - if (transporterFactories == null) { - transporterFactories = createTransporterFactories(); - } - return transporterFactories; - } - - protected Map createTransporterFactories() { - HashMap result = new HashMap<>(); - result.put(FileTransporterFactory.NAME, new FileTransporterFactory()); - result.put( - ApacheTransporterFactory.NAME, - new ApacheTransporterFactory(getChecksumExtractor(), getPathProcessor())); - return result; - } - - private TransporterProvider transporterProvider; - - public final TransporterProvider getTransporterProvider() { - checkClosed(); - if (transporterProvider == null) { - transporterProvider = createTransporterProvider(); - } - return transporterProvider; - } - - protected TransporterProvider createTransporterProvider() { - return new DefaultTransporterProvider(getTransporterFactories()); - } - - private BasicRepositoryConnectorFactory basicRepositoryConnectorFactory; - - public final BasicRepositoryConnectorFactory getBasicRepositoryConnectorFactory() { - checkClosed(); - if (basicRepositoryConnectorFactory == null) { - basicRepositoryConnectorFactory = createBasicRepositoryConnectorFactory(); - } - return basicRepositoryConnectorFactory; - } - - protected BasicRepositoryConnectorFactory createBasicRepositoryConnectorFactory() { - return new BasicRepositoryConnectorFactory( - getTransporterProvider(), - getRepositoryLayoutProvider(), - getChecksumPolicyProvider(), - getChecksumProcessor(), - getProvidedChecksumsSources()); - } - - private Map repositoryConnectorFactories; - - public final Map getRepositoryConnectorFactories() { - checkClosed(); - if (repositoryConnectorFactories == null) { - repositoryConnectorFactories = createRepositoryConnectorFactories(); - } - return repositoryConnectorFactories; - } - - protected Map createRepositoryConnectorFactories() { - HashMap result = new HashMap<>(); - result.put(BasicRepositoryConnectorFactory.NAME, getBasicRepositoryConnectorFactory()); - return result; - } - - private RepositoryConnectorProvider repositoryConnectorProvider; - - public final RepositoryConnectorProvider getRepositoryConnectorProvider() { - checkClosed(); - if (repositoryConnectorProvider == null) { - repositoryConnectorProvider = createRepositoryConnectorProvider(); - } - return repositoryConnectorProvider; - } - - protected RepositoryConnectorProvider createRepositoryConnectorProvider() { - return new DefaultRepositoryConnectorProvider( - getRepositoryConnectorFactories(), getRemoteRepositoryFilterManager()); - } - - private Installer installer; - - public final Installer getInstaller() { - checkClosed(); - if (installer == null) { - installer = createInstaller(); - } - return installer; - } - - protected Installer createInstaller() { - return new DefaultInstaller( - getPathProcessor(), - getRepositoryEventDispatcher(), - getArtifactGeneratorFactories(), - getMetadataGeneratorFactories(), - getSyncContextFactory()); - } - - private Deployer deployer; - - public final Deployer getDeployer() { - checkClosed(); - if (deployer == null) { - deployer = createDeployer(); - } - return deployer; - } - - protected Deployer createDeployer() { - return new DefaultDeployer( - getPathProcessor(), - getRepositoryEventDispatcher(), - getRepositoryConnectorProvider(), - getRemoteRepositoryManager(), - getUpdateCheckManager(), - getArtifactGeneratorFactories(), - getMetadataGeneratorFactories(), - getSyncContextFactory(), - getOfflineController()); - } - - private Map dependencyCollectorDelegates; - - public final Map getDependencyCollectorDelegates() { - checkClosed(); - if (dependencyCollectorDelegates == null) { - dependencyCollectorDelegates = createDependencyCollectorDelegates(); - } - return dependencyCollectorDelegates; - } - - protected Map createDependencyCollectorDelegates() { - RemoteRepositoryManager remoteRepositoryManager = getRemoteRepositoryManager(); - ArtifactDescriptorReader artifactDescriptorReader = getArtifactDescriptorReader(); - VersionRangeResolver versionRangeResolver = getVersionRangeResolver(); - HashMap result = new HashMap<>(); - result.put( - DfDependencyCollector.NAME, - new DfDependencyCollector( - remoteRepositoryManager, - artifactDescriptorReader, - versionRangeResolver, - getArtifactDecoratorFactories())); - result.put( - BfDependencyCollector.NAME, - new BfDependencyCollector( - remoteRepositoryManager, - artifactDescriptorReader, - versionRangeResolver, - getArtifactDecoratorFactories())); - return result; - } - - private DependencyCollector dependencyCollector; - - public final DependencyCollector getDependencyCollector() { - checkClosed(); - if (dependencyCollector == null) { - dependencyCollector = createDependencyCollector(); - } - return dependencyCollector; - } - - protected DependencyCollector createDependencyCollector() { - return new DefaultDependencyCollector(getDependencyCollectorDelegates()); - } - - private Map artifactResolverPostProcessors; - - public final Map getArtifactResolverPostProcessors() { - checkClosed(); - if (artifactResolverPostProcessors == null) { - artifactResolverPostProcessors = createArtifactResolverPostProcessors(); - } - return artifactResolverPostProcessors; - } - - protected Map createArtifactResolverPostProcessors() { - HashMap result = new HashMap<>(); - result.put( - TrustedChecksumsArtifactResolverPostProcessor.NAME, - new TrustedChecksumsArtifactResolverPostProcessor( - getChecksumAlgorithmFactorySelector(), getTrustedChecksumsSources())); - return result; - } - - private ArtifactResolver artifactResolver; - - public final ArtifactResolver getArtifactResolver() { - checkClosed(); - if (artifactResolver == null) { - artifactResolver = createArtifactResolver(); - } - return artifactResolver; - } - - protected ArtifactResolver createArtifactResolver() { + @Provides + static ArtifactResolver newArtifactResolver( + PathProcessor pathProcessor, + RepositoryEventDispatcher repositoryEventDispatcher, + VersionResolver versionResolver, + UpdateCheckManager updateCheckManager, + RepositoryConnectorProvider repositoryConnectorProvider, + RemoteRepositoryManager remoteRepositoryManager, + SyncContextFactory syncContextFactory, + OfflineController offlineController, + Map artifactResolverPostProcessors, + RemoteRepositoryFilterManager remoteRepositoryFilterManager) { return new DefaultArtifactResolver( - getPathProcessor(), - getRepositoryEventDispatcher(), - getVersionResolver(), - getUpdateCheckManager(), - getRepositoryConnectorProvider(), - getRemoteRepositoryManager(), - getSyncContextFactory(), - getOfflineController(), - getArtifactResolverPostProcessors(), - getRemoteRepositoryFilterManager()); + pathProcessor, + repositoryEventDispatcher, + versionResolver, + updateCheckManager, + repositoryConnectorProvider, + remoteRepositoryManager, + syncContextFactory, + offlineController, + artifactResolverPostProcessors, + remoteRepositoryFilterManager); } - private MetadataResolver metadataResolver; - - public final MetadataResolver getMetadataResolver() { - checkClosed(); - if (metadataResolver == null) { - metadataResolver = createMetadataResolver(); - } - return metadataResolver; + @Provides + static DependencyCollector newDependencyCollector(Map delegates) { + return new DefaultDependencyCollector(delegates); } - protected MetadataResolver createMetadataResolver() { - return new DefaultMetadataResolver( - getRepositoryEventDispatcher(), - getUpdateCheckManager(), - getRepositoryConnectorProvider(), - getRemoteRepositoryManager(), - getSyncContextFactory(), - getOfflineController(), - getRemoteRepositoryFilterManager(), - getPathProcessor()); + @Provides + @Named(BfDependencyCollector.NAME) + static BfDependencyCollector newBfDependencyCollector( + RemoteRepositoryManager remoteRepositoryManager, + ArtifactDescriptorReader artifactDescriptorReader, + VersionRangeResolver versionRangeResolver, + @Nullable Map artifactDecoratorFactories) { + return new BfDependencyCollector( + remoteRepositoryManager, + artifactDescriptorReader, + versionRangeResolver, + artifactDecoratorFactories != null ? artifactDecoratorFactories : Map.of()); } - private VersionScheme versionScheme; - - public final VersionScheme getVersionScheme() { - checkClosed(); - if (versionScheme == null) { - versionScheme = createVersionScheme(); - } - return versionScheme; + @Provides + @Named(DfDependencyCollector.NAME) + static DfDependencyCollector newDfDependencyCollector( + RemoteRepositoryManager remoteRepositoryManager, + ArtifactDescriptorReader artifactDescriptorReader, + VersionRangeResolver versionRangeResolver, + @Nullable Map artifactDecoratorFactories) { + return new DfDependencyCollector( + remoteRepositoryManager, + artifactDescriptorReader, + versionRangeResolver, + artifactDecoratorFactories != null ? artifactDecoratorFactories : Map.of()); } - protected VersionScheme createVersionScheme() { - return new GenericVersionScheme(); + @Provides + static Installer newInstaller( + PathProcessor pathProcessor, + RepositoryEventDispatcher repositoryEventDispatcher, + @Nullable Map artifactFactories, + Map metadataFactories, + SyncContextFactory syncContextFactory) { + return new DefaultInstaller( + pathProcessor, + repositoryEventDispatcher, + artifactFactories != null ? artifactFactories : Map.of(), + metadataFactories, + syncContextFactory); } - private Map artifactGeneratorFactories; - - public final Map getArtifactGeneratorFactories() { - checkClosed(); - if (artifactGeneratorFactories == null) { - artifactGeneratorFactories = createArtifactGeneratorFactories(); - } - return artifactGeneratorFactories; + @Provides + static Deployer newDeployer( + PathProcessor pathProcessor, + RepositoryEventDispatcher repositoryEventDispatcher, + RepositoryConnectorProvider repositoryConnectorProvider, + RemoteRepositoryManager remoteRepositoryManager, + UpdateCheckManager updateCheckManager, + @Nullable Map artifactFactories, + Map metadataFactories, + SyncContextFactory syncContextFactory, + OfflineController offlineController) { + return new DefaultDeployer( + pathProcessor, + repositoryEventDispatcher, + repositoryConnectorProvider, + remoteRepositoryManager, + updateCheckManager, + artifactFactories != null ? artifactFactories : Map.of(), + metadataFactories, + syncContextFactory, + offlineController); } - protected Map createArtifactGeneratorFactories() { - // by default none, this is extension point - return new HashMap<>(); + @Provides + static LocalRepositoryProvider newLocalRepositoryProvider( + Map localRepositoryManagerFactories) { + return new DefaultLocalRepositoryProvider(localRepositoryManagerFactories); } - private Map artifactDecoratorFactories; - - public final Map getArtifactDecoratorFactories() { - checkClosed(); - if (artifactDecoratorFactories == null) { - artifactDecoratorFactories = createArtifactDecoratorFactories(); - } - return artifactDecoratorFactories; + @Provides + @Named(EnhancedLocalRepositoryManagerFactory.NAME) + static EnhancedLocalRepositoryManagerFactory newEnhancedLocalRepositoryManagerFactory( + LocalPathComposer localPathComposer, + TrackingFileManager trackingFileManager, + LocalPathPrefixComposerFactory localPathPrefixComposerFactory) { + return new EnhancedLocalRepositoryManagerFactory( + localPathComposer, trackingFileManager, localPathPrefixComposerFactory); } - protected Map createArtifactDecoratorFactories() { - // by default none, this is extension point - return new HashMap<>(); + @Provides + @Named(SimpleLocalRepositoryManagerFactory.NAME) + static SimpleLocalRepositoryManagerFactory newSimpleLocalRepositoryManagerFactory( + LocalPathComposer localPathComposer) { + return new SimpleLocalRepositoryManagerFactory(localPathComposer); } - // Maven provided - - private Map metadataGeneratorFactories; - - public final Map getMetadataGeneratorFactories() { - checkClosed(); - if (metadataGeneratorFactories == null) { - metadataGeneratorFactories = createMetadataGeneratorFactories(); - } - return metadataGeneratorFactories; + @Provides + static LocalPathComposer newLocalPathComposer() { + return new DefaultLocalPathComposer(); } - protected Map createMetadataGeneratorFactories() { - // from maven-resolver-provider - HashMap result = new HashMap<>(); - result.put(PluginsMetadataGeneratorFactory.NAME, new PluginsMetadataGeneratorFactory()); - result.put(VersionsMetadataGeneratorFactory.NAME, new VersionsMetadataGeneratorFactory()); - result.put(SnapshotMetadataGeneratorFactory.NAME, new SnapshotMetadataGeneratorFactory()); - return result; + @Provides + static LocalPathPrefixComposerFactory newLocalPathPrefixComposerFactory() { + return new DefaultLocalPathPrefixComposerFactory(); } - private LinkedHashMap artifactRelocationSources; - - public final LinkedHashMap getMavenArtifactRelocationSources() { - checkClosed(); - if (artifactRelocationSources == null) { - artifactRelocationSources = createMavenArtifactRelocationSources(); - } - return artifactRelocationSources; + @Provides + static TransporterProvider newTransportProvider(Map transporterFactories) { + return new DefaultTransporterProvider(transporterFactories); } - protected LinkedHashMap createMavenArtifactRelocationSources() { - // from maven-resolver-provider - LinkedHashMap result = new LinkedHashMap<>(); - result.put(UserPropertiesArtifactRelocationSource.NAME, new UserPropertiesArtifactRelocationSource()); - result.put( - DistributionManagementArtifactRelocationSource.NAME, - new DistributionManagementArtifactRelocationSource()); - return result; + @Provides + @Named(FileTransporterFactory.NAME) + static FileTransporterFactory newFileTransporterFactory() { + return new FileTransporterFactory(); } - private ArtifactDescriptorReader artifactDescriptorReader; - - public final ArtifactDescriptorReader getArtifactDescriptorReader() { - checkClosed(); - if (artifactDescriptorReader == null) { - artifactDescriptorReader = createArtifactDescriptorReader(); - } - return artifactDescriptorReader; + @Provides + @Named(ApacheTransporterFactory.NAME) + static ApacheTransporterFactory newApacheTransporterFactory( + ChecksumExtractor checksumExtractor, PathProcessor pathProcessor) { + return new ApacheTransporterFactory(checksumExtractor, pathProcessor); } - protected ArtifactDescriptorReader createArtifactDescriptorReader() { - // from maven-resolver-provider - return new DefaultArtifactDescriptorReader( - getVersionResolver(), - getArtifactResolver(), - getModelBuilder(), - getRepositoryEventDispatcher(), - getMavenArtifactRelocationSources()); + @Provides + static ChecksumProcessor newChecksumProcessor(PathProcessor pathProcessor) { + return new DefaultChecksumProcessor(pathProcessor); } - private VersionResolver versionResolver; - - public final VersionResolver getVersionResolver() { - checkClosed(); - if (versionResolver == null) { - versionResolver = createVersionResolver(); - } - return versionResolver; + @Provides + static ChecksumExtractor newChecksumExtractor(Map strategies) { + return new DefaultChecksumExtractor(strategies); } - protected VersionResolver createVersionResolver() { - // from maven-resolver-provider - return new DefaultVersionResolver( - getMetadataResolver(), getSyncContextFactory(), getRepositoryEventDispatcher()); + @Provides + @Named(Nx2ChecksumExtractor.NAME) + static Nx2ChecksumExtractor newNx2ChecksumExtractor() { + return new Nx2ChecksumExtractor(); } - private VersionRangeResolver versionRangeResolver; - - public final VersionRangeResolver getVersionRangeResolver() { - checkClosed(); - if (versionRangeResolver == null) { - versionRangeResolver = createVersionRangeResolver(); - } - return versionRangeResolver; + @Provides + @Named(XChecksumExtractor.NAME) + static XChecksumExtractor newXChecksumExtractor() { + return new XChecksumExtractor(); } - protected VersionRangeResolver createVersionRangeResolver() { - // from maven-resolver-provider - return new DefaultVersionRangeResolver( - getMetadataResolver(), getSyncContextFactory(), getRepositoryEventDispatcher(), getVersionScheme()); + @Provides + @Named(TrustedToProvidedChecksumsSourceAdapter.NAME) + static TrustedToProvidedChecksumsSourceAdapter newTrustedToProvidedChecksumsSourceAdapter( + Map trustedChecksumsSources) { + return new TrustedToProvidedChecksumsSourceAdapter(trustedChecksumsSources); } - private ModelBuilder modelBuilder; - - public final ModelBuilder getModelBuilder() { - checkClosed(); - if (modelBuilder == null) { - modelBuilder = createModelBuilder(); - } - return modelBuilder; + @Provides + @Named(SparseDirectoryTrustedChecksumsSource.NAME) + static SparseDirectoryTrustedChecksumsSource newSparseDirectoryTrustedChecksumsSource( + ChecksumProcessor checksumProcessor, LocalPathComposer localPathComposer) { + return new SparseDirectoryTrustedChecksumsSource(checksumProcessor, localPathComposer); } - protected ModelBuilder createModelBuilder() { - // from maven-model-builder - DefaultModelProcessor modelProcessor = new DefaultModelProcessor(new DefaultModelXmlFactory(), List.of()); - return new DefaultModelBuilder( - modelProcessor, - new DefaultModelValidator(), - new DefaultModelNormalizer(), - new DefaultModelInterpolator( - new DefaultPathTranslator(), - new DefaultUrlNormalizer(), - new DefaultRootLocator(), - new DefaultInterpolator()), - new DefaultModelPathTranslator(new DefaultPathTranslator()), - new DefaultModelUrlNormalizer(new DefaultUrlNormalizer()), - new DefaultSuperPomProvider(modelProcessor), - new DefaultInheritanceAssembler(), - new DefaultProfileSelector(), - new DefaultProfileInjector(), - new DefaultPluginManagementInjector(), - new DefaultDependencyManagementInjector(), - new DefaultDependencyManagementImporter(), - new DefaultPluginConfigurationExpander(), - new DefaultModelVersionParser(getVersionScheme()), - List.of(), - new DefaultModelCacheFactory(), - new DefaultModelResolver(), - new DefaultInterpolator(), - new DefaultPathTranslator(), - new DefaultRootLocator()); + @Provides + @Named(SummaryFileTrustedChecksumsSource.NAME) + static SummaryFileTrustedChecksumsSource newSummaryFileTrustedChecksumsSource( + LocalPathComposer localPathComposer, RepositorySystemLifecycle repositorySystemLifecycle) { + return new SummaryFileTrustedChecksumsSource(localPathComposer, repositorySystemLifecycle); } - private RepositorySystem repositorySystem; - - public final RepositorySystem getRepositorySystem() { - checkClosed(); - if (repositorySystem == null) { - repositorySystem = createRepositorySystem(); - } - return repositorySystem; + @Provides + static ChecksumAlgorithmFactorySelector newChecksumAlgorithmFactorySelector( + Map factories) { + return new DefaultChecksumAlgorithmFactorySelector(factories); } - protected RepositorySystem createRepositorySystem() { - return new DefaultRepositorySystem( - getVersionResolver(), - getVersionRangeResolver(), - getArtifactResolver(), - getMetadataResolver(), - getArtifactDescriptorReader(), - getDependencyCollector(), - getInstaller(), - getDeployer(), - getLocalRepositoryProvider(), - getSyncContextFactory(), - getRemoteRepositoryManager(), - getRepositorySystemLifecycle(), - getArtifactDecoratorFactories()); + @Provides + @Named(Md5ChecksumAlgorithmFactory.NAME) + static Md5ChecksumAlgorithmFactory newMd5ChecksumAlgorithmFactory() { + return new Md5ChecksumAlgorithmFactory(); } - @Override - public RepositorySystem get() { - return getRepositorySystem(); + @Provides + @Named(Sha1ChecksumAlgorithmFactory.NAME) + static Sha1ChecksumAlgorithmFactory newSh1ChecksumAlgorithmFactory() { + return new Sha1ChecksumAlgorithmFactory(); + } + + @Provides + @Named(Sha256ChecksumAlgorithmFactory.NAME) + static Sha256ChecksumAlgorithmFactory newSh256ChecksumAlgorithmFactory() { + return new Sha256ChecksumAlgorithmFactory(); + } + + @Provides + @Named(Sha512ChecksumAlgorithmFactory.NAME) + static Sha512ChecksumAlgorithmFactory newSh512ChecksumAlgorithmFactory() { + return new Sha512ChecksumAlgorithmFactory(); + } + + @Provides + static ArtifactPredicateFactory newArtifactPredicateFactory( + ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector) { + return new DefaultArtifactPredicateFactory(checksumAlgorithmFactorySelector); } } diff --git a/pom.xml b/pom.xml index 868fe30aeb..a8d7205dc9 100644 --- a/pom.xml +++ b/pom.xml @@ -648,6 +648,11 @@ under the License. byte-buddy ${byteBuddyVersion} + + com.google.jimfs + jimfs + 1.3.0 +