diff --git a/pom.xml b/pom.xml
index ea9d1135e8..6cd63535bf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -101,6 +101,7 @@
versions-maven-pluginversions-model-reportversions-model
+ versions-model-core-extensionsversions-test
@@ -177,6 +178,12 @@
maven-compat${mavenVersion}
+
+ org.apache.maven
+ maven-embedder
+ ${mavenVersion}
+ provided
+ org.apache.maven.enforcer
diff --git a/versions-common/pom.xml b/versions-common/pom.xml
index 6276a72d71..f6e1188af0 100644
--- a/versions-common/pom.xml
+++ b/versions-common/pom.xml
@@ -23,6 +23,11 @@
versions-model${project.version}
+
+ org.codehaus.mojo.versions
+ versions-model-core-extensions
+ ${project.version}
+ org.apache.maven
@@ -50,6 +55,10 @@
org.apache.mavenmaven-settings
+
+ org.apache.maven
+ maven-embedder
+ com.fasterxml.woodstoxwoodstox-core
diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java
index d3844285c1..9a75757bf4 100644
--- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java
+++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java
@@ -1,22 +1,18 @@
package org.codehaus.mojo.versions.api;
/*
- * 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
+ * Copyright MojoHaus and Contributors
+ * 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
+ * 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.
+ * 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.
*/
import java.io.BufferedInputStream;
@@ -45,6 +41,7 @@
import java.util.concurrent.Future;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
@@ -89,6 +86,7 @@
import org.eclipse.aether.resolution.VersionRangeRequest;
import org.eclipse.aether.resolution.VersionRangeResolutionException;
+import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.Optional.empty;
import static java.util.Optional.of;
@@ -172,12 +170,35 @@ public Log getLog() {
public ArtifactVersions lookupArtifactVersions(
Artifact artifact, VersionRange versionRange, boolean usePluginRepositories)
throws VersionRetrievalException {
+ return lookupArtifactVersions(artifact, versionRange, usePluginRepositories, !usePluginRepositories);
+ }
+
+ @Override
+ public ArtifactVersions lookupArtifactVersions(
+ Artifact artifact, VersionRange versionRange, boolean usePluginRepositories, boolean useProjectRepositories)
+ throws VersionRetrievalException {
try {
Collection ignoredVersions = getIgnoredVersions(artifact);
if (!ignoredVersions.isEmpty() && getLog().isDebugEnabled()) {
getLog().debug("Found ignored versions: "
+ ignoredVersions.stream().map(IgnoreVersion::toString).collect(Collectors.joining(", ")));
}
+
+ final List repositories;
+ if (usePluginRepositories && !useProjectRepositories) {
+ repositories = mavenSession.getCurrentProject().getRemotePluginRepositories();
+ } else if (!usePluginRepositories && useProjectRepositories) {
+ repositories = mavenSession.getCurrentProject().getRemoteProjectRepositories();
+ } else if (usePluginRepositories) {
+ repositories = Stream.concat(
+ mavenSession.getCurrentProject().getRemoteProjectRepositories().stream(),
+ mavenSession.getCurrentProject().getRemotePluginRepositories().stream())
+ .distinct()
+ .collect(Collectors.toList());
+ } else {
+ // testing?
+ repositories = emptyList();
+ }
return new ArtifactVersions(
artifact,
aetherRepositorySystem
@@ -191,13 +212,7 @@ public ArtifactVersions lookupArtifactVersions(
.findFirst()
.map(Restriction::toString))
.orElse("(,)")),
- usePluginRepositories
- ? mavenSession
- .getCurrentProject()
- .getRemotePluginRepositories()
- : mavenSession
- .getCurrentProject()
- .getRemoteProjectRepositories(),
+ repositories,
"lookupArtifactVersions"))
.getVersions()
.stream()
@@ -428,16 +443,20 @@ public ArtifactVersion createArtifactVersion(String version) {
return DefaultArtifactVersionCache.of(version);
}
- @Override
public Map lookupDependenciesUpdates(
- Set dependencies, boolean usePluginRepositories, boolean allowSnapshots)
+ Set dependencies,
+ boolean usePluginRepositories,
+ boolean useProjectRepositories,
+ boolean allowSnapshots)
throws VersionRetrievalException {
ExecutorService executor = Executors.newFixedThreadPool(LOOKUP_PARALLEL_THREADS);
try {
Map dependencyUpdates = new TreeMap<>(DependencyComparator.INSTANCE);
List>> futures = dependencies.stream()
.map(dependency -> executor.submit(() -> new ImmutablePair<>(
- dependency, lookupDependencyUpdates(dependency, usePluginRepositories, allowSnapshots))))
+ dependency,
+ lookupDependencyUpdates(
+ dependency, usePluginRepositories, useProjectRepositories, allowSnapshots))))
.collect(Collectors.toList());
for (Future extends Pair> details : futures) {
Pair pair = details.get();
@@ -453,12 +472,22 @@ dependency, lookupDependencyUpdates(dependency, usePluginRepositories, allowSnap
}
}
+ @Override
+ public Map lookupDependenciesUpdates(
+ Set dependencies, boolean usePluginRepositories, boolean allowSnapshots)
+ throws VersionRetrievalException {
+ return lookupDependenciesUpdates(dependencies, usePluginRepositories, !usePluginRepositories, allowSnapshots);
+ }
+
@Override
public ArtifactVersions lookupDependencyUpdates(
- Dependency dependency, boolean usePluginRepositories, boolean allowSnapshots)
+ Dependency dependency,
+ boolean usePluginRepositories,
+ boolean useProjectRepositories,
+ boolean allowSnapshots)
throws VersionRetrievalException {
- ArtifactVersions allVersions =
- lookupArtifactVersions(createDependencyArtifact(dependency), usePluginRepositories);
+ ArtifactVersions allVersions = lookupArtifactVersions(
+ createDependencyArtifact(dependency), null, usePluginRepositories, useProjectRepositories);
return new ArtifactVersions(
allVersions.getArtifact(),
Arrays.stream(allVersions.getAllUpdates(allowSnapshots)).collect(Collectors.toList()),
diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/VersionsHelper.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/VersionsHelper.java
index d10b4e0d92..0c3e2347e0 100644
--- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/VersionsHelper.java
+++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/VersionsHelper.java
@@ -1,22 +1,18 @@
package org.codehaus.mojo.versions.api;
/*
- * 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
+ * Copyright MojoHaus and Contributors
+ * 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
+ * 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.
+ * 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.
*/
import java.util.Collection;
@@ -152,7 +148,7 @@ Artifact createDependencyArtifact(
* The resulting {@link ArtifactVersions} instance will contain all versions, including snapshots.
*
* @param artifact The artifact to look for versions of.
- * @param usePluginRepositories true will consult the pluginRepositories, while false will
+ * @param usePluginRepositories {@code true} will consult the pluginRepositories, while {@code false} will
* consult the repositories for normal dependencies.
* @return The details of the available artifact versions.
* @throws VersionRetrievalException thrown if version resolution fails
@@ -167,7 +163,24 @@ ArtifactVersions lookupArtifactVersions(Artifact artifact, boolean usePluginRepo
* The resulting {@link ArtifactVersions} instance will contain all versions, including snapshots.
*
* @param artifact The artifact to look for versions of.
- * @param versionRange versionRange to restrict the search
+ * @param versionRange versionRange to restrict the search, may be {@code null}
+ * @param usePluginRepositories {@code true} will consult the pluginRepositories
+ * @param useProjectRepositories {@code true} will consult regular project repositories
+ * @return The details of the available artifact versions.
+ * @throws VersionRetrievalException thrown if version resolution fails
+ * @since 2.15.0
+ */
+ ArtifactVersions lookupArtifactVersions(
+ Artifact artifact, VersionRange versionRange, boolean usePluginRepositories, boolean useProjectRepositories)
+ throws VersionRetrievalException;
+
+ /**
+ * Looks up the versions of the specified artifact that are available in either the local repository, or the
+ * appropriate remote repositories.
+ * The resulting {@link ArtifactVersions} instance will contain all versions, including snapshots.
+ *
+ * @param artifact The artifact to look for versions of.
+ * @param versionRange versionRange to restrict the search, may be {@code null}
* @param usePluginRepositories true will consult the pluginRepositories, while false will
* consult the repositories for normal dependencies.
* @return The details of the available artifact versions.
@@ -190,18 +203,39 @@ Map lookupDependenciesUpdates(
Set dependencies, boolean usePluginRepositories, boolean allowSnapshots)
throws VersionRetrievalException;
+ /**
+ * Returns a map of all possible updates per dependency. The lookup is done in parallel using
+ * {@code LOOKUP_PARALLEL_THREADS} threads.
+ *
+ * @param dependencies The set of {@link Dependency} instances to look up.
+ * @param usePluginRepositories Search the plugin repositories.
+ * @param useProjectRepositories whether to use regular project repositories
+ * @param allowSnapshots whether snapshots should be included
+ * @return map containing the ArtifactVersions object per dependency
+ */
+ Map lookupDependenciesUpdates(
+ Set dependencies,
+ boolean usePluginRepositories,
+ boolean useProjectRepositories,
+ boolean allowSnapshots)
+ throws VersionRetrievalException;
+
/**
* Creates an {@link org.codehaus.mojo.versions.api.ArtifactVersions} instance from a dependency.
*
* @param dependency The dependency.
* @param usePluginRepositories Search the plugin repositories.
+ * @param useProjectRepositories whether to use regular project repositories
* @param allowSnapshots whether snapshots should be included
* @return The details of updates to the dependency.
* @throws VersionRetrievalException thrown if version resolution fails
* @since 1.0-beta-1
*/
ArtifactVersions lookupDependencyUpdates(
- Dependency dependency, boolean usePluginRepositories, boolean allowSnapshots)
+ Dependency dependency,
+ boolean usePluginRepositories,
+ boolean useProjectRepositories,
+ boolean allowSnapshots)
throws VersionRetrievalException;
/**
diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/filtering/DependencyFilter.java b/versions-common/src/main/java/org/codehaus/mojo/versions/filtering/DependencyFilter.java
index 4af2a4fbfa..d2808a0a76 100644
--- a/versions-common/src/main/java/org/codehaus/mojo/versions/filtering/DependencyFilter.java
+++ b/versions-common/src/main/java/org/codehaus/mojo/versions/filtering/DependencyFilter.java
@@ -1,22 +1,18 @@
package org.codehaus.mojo.versions.filtering;
/*
- * 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
+ * Copyright MojoHaus and Contributors
+ * 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
+ * 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.
+ * 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.
*/
import java.util.Collection;
@@ -66,10 +62,14 @@ public Set removingFrom(Collection dependencies) {
return filterBy(dependencies, not(this::matchersMatch));
}
- private boolean matchersMatch(Dependency dependency) {
+ public boolean matchersMatch(Dependency dependency) {
return matchers.stream().anyMatch(m -> m.test(dependency));
}
+ public boolean matchersDontMatch(Dependency dependency) {
+ return !matchersMatch(dependency);
+ }
+
private TreeSet filterBy(Collection dependencies, Predicate predicate) {
return dependencies.stream()
.filter(predicate)
diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/utils/CoreExtensionUtils.java b/versions-common/src/main/java/org/codehaus/mojo/versions/utils/CoreExtensionUtils.java
new file mode 100644
index 0000000000..94525b2277
--- /dev/null
+++ b/versions-common/src/main/java/org/codehaus/mojo/versions/utils/CoreExtensionUtils.java
@@ -0,0 +1,64 @@
+package org.codehaus.mojo.versions.utils;
+
+/*
+ * Copyright MojoHaus and Contributors
+ *
+ * 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.
+ */
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.stream.Stream;
+
+import org.apache.maven.cli.internal.extension.model.io.xpp3.CoreExtensionsXpp3Reader;
+import org.apache.maven.model.Extension;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+/**
+ * Utilities for reading and handling core extensions.
+ *
+ * @author Andrzej Jarmoniuk
+ * @since 2.15.0
+ */
+public final class CoreExtensionUtils {
+ /**
+ * Reads the core extensions (not build extensions) configured for the given project
+ * from the {@code ${project}/.mvn/extensions.xml} file.
+ *
+ * @param project {@link MavenProject} instance
+ * @return stream of core extensions defined in the {@code ${project}/.mvn/extensions.xml} file
+ * @throws IOException thrown if a file I/O operation fails
+ * @throws XmlPullParserException thrown if the file cannot be parsed
+ * @since 2.15.0
+ */
+ public static Stream getCoreExtensions(MavenProject project) throws IOException, XmlPullParserException {
+ Path extensionsFile = project.getBasedir().toPath().resolve(".mvn/extensions.xml");
+ if (!Files.isRegularFile(extensionsFile)) {
+ return Stream.empty();
+ }
+
+ try (Reader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(extensionsFile)))) {
+ return new CoreExtensionsXpp3Reader()
+ .read(reader).getExtensions().stream().map(ex -> ExtensionBuilder.newBuilder()
+ .withGroupId(ex.getGroupId())
+ .withArtifactId(ex.getArtifactId())
+ .withVersion(ex.getVersion())
+ .build());
+ }
+ }
+}
diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/utils/DependencyBuilder.java b/versions-common/src/main/java/org/codehaus/mojo/versions/utils/DependencyBuilder.java
index 58ca87c2ff..6574f4b557 100644
--- a/versions-common/src/main/java/org/codehaus/mojo/versions/utils/DependencyBuilder.java
+++ b/versions-common/src/main/java/org/codehaus/mojo/versions/utils/DependencyBuilder.java
@@ -1,24 +1,20 @@
+package org.codehaus.mojo.versions.utils;
+
/*
- * 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
+ * Copyright MojoHaus and Contributors
+ * 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
+ * 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.
+ * 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.codehaus.mojo.versions.utils;
-
import java.util.Optional;
import org.apache.maven.model.Dependency;
@@ -136,7 +132,9 @@ public static DependencyBuilder newBuilder() {
* @param artifactId artifactId of the dependency
* @param version version of the dependency
* @return new instance of {@linkplain Dependency}
+ * @deprecated please use the {@link #newBuilder()} method instead
*/
+ @Deprecated
public static Dependency dependencyWith(String groupId, String artifactId, String version) {
return newBuilder()
.withGroupId(groupId)
@@ -154,7 +152,9 @@ public static Dependency dependencyWith(String groupId, String artifactId, Strin
* @param classifier classifier of the dependency
* @param scope scope of the dependency
* @return new instance of {@linkplain Dependency}
+ * @deprecated please use the {@link #newBuilder()} method instead
*/
+ @Deprecated
public static Dependency dependencyWith(
String groupId, String artifactId, String version, String type, String classifier, String scope) {
return newBuilder()
diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/utils/ExtensionBuilder.java b/versions-common/src/main/java/org/codehaus/mojo/versions/utils/ExtensionBuilder.java
new file mode 100644
index 0000000000..7d763606d2
--- /dev/null
+++ b/versions-common/src/main/java/org/codehaus/mojo/versions/utils/ExtensionBuilder.java
@@ -0,0 +1,103 @@
+package org.codehaus.mojo.versions.utils;
+
+/*
+ * Copyright MojoHaus and Contributors
+ *
+ * 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.
+ */
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Extension;
+import org.apache.maven.model.InputLocation;
+
+import static java.util.Optional.empty;
+import static java.util.Optional.ofNullable;
+
+/**
+ * Builder class for {@linkplain Extension}
+ */
+@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
+public class ExtensionBuilder {
+ private Optional groupId = empty();
+ private Optional artifactId = empty();
+ private Optional version = empty();
+ private Map
+
The default location for the Core Extensions descriptor file is ${maven.projectBasedir}/.mvn/extensions.xml
+ ]]>
+
+
+
+ package
+ org.apache.maven.cli.internal.extension.model
+
+
+
+
+
+ CoreExtensions
+ Extensions to load.
+ 1.0.0+
+
+
+ extensions
+ A set of build extensions to use from this project.
+ 1.0.0+
+
+ CoreExtension
+ *
+
+
+
+
+
+ CoreExtension
+ Describes a build extension to utilise.
+ 1.0.0+
+
+
+ groupId
+ The group ID of the extension's artifact.
+ 1.0.0+
+ true
+ String
+
+
+ artifactId
+ The artifact ID of the extension.
+ 1.0.0+
+ true
+ String
+
+
+ version
+ The version of the extension.
+ 1.0.0+
+ true
+ String
+
+
+ classLoadingStrategy
+ The class loading strategy: 'self-first' (the default), 'parent-first' (loads classes from the parent, then from the extension) or 'plugin' (follows the rules from extensions defined as plugins).
+ 1.1.0+
+ self-first
+ false
+ String
+
+
+
+
+ 1.0.0+
+
+ ::}, never {@code null}.
+ */
+ public String getId()
+ {
+ StringBuilder id = new StringBuilder( 128 );
+
+ id.append( ( getGroupId() == null ) ? "[unknown-group-id]" : getGroupId() );
+ id.append( ":" );
+ id.append( ( getArtifactId() == null ) ? "[unknown-artifact-id]" : getArtifactId() );
+ id.append( ":" );
+ id.append( ( getVersion() == null ) ? "[unknown-version]" : getVersion() );
+
+ return id.toString();
+ }
+ ]]>
+
+
+
+
+
+
diff --git a/versions-test/src/main/java/org/codehaus/mojo/versions/utils/MockUtils.java b/versions-test/src/main/java/org/codehaus/mojo/versions/utils/MockUtils.java
index 92a1d0cab7..e08b9322ab 100644
--- a/versions-test/src/main/java/org/codehaus/mojo/versions/utils/MockUtils.java
+++ b/versions-test/src/main/java/org/codehaus/mojo/versions/utils/MockUtils.java
@@ -1,24 +1,20 @@
+package org.codehaus.mojo.versions.utils;
+
/*
- * 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
+ * Copyright MojoHaus and Contributors
+ * 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
+ * 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.
+ * 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.codehaus.mojo.versions.utils;
-
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
@@ -152,11 +148,22 @@ public static RepositorySystem mockRepositorySystem() {
* @return mocked {@link MavenSession}
*/
public static MavenSession mockMavenSession() {
+ MavenProject project = mock(MavenProject.class);
+ when(project.getRemotePluginRepositories()).thenReturn(emptyList());
+ when(project.getRemoteProjectRepositories()).thenReturn(emptyList());
+ return mockMavenSession(project);
+ }
+
+ /**
+ * Creates a very simple mock of {@link MavenSession}
+ * by providing only a non-{@code null} implementation of its {@link MavenSession#getRepositorySession()} method.
+ * @param project {@link MavenProject} to link to
+ * @return mocked {@link MavenSession}
+ */
+ public static MavenSession mockMavenSession(MavenProject project) {
MavenSession session = mock(MavenSession.class);
when(session.getRepositorySession()).thenReturn(mock(RepositorySystemSession.class));
- when(session.getCurrentProject()).thenReturn(mock(MavenProject.class));
- when(session.getCurrentProject().getRemotePluginRepositories()).thenReturn(emptyList());
- when(session.getCurrentProject().getRemoteProjectRepositories()).thenReturn(emptyList());
+ when(session.getCurrentProject()).thenReturn(project);
return session;
}
}