forked from thorntail/thorntail
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SWARM-1173] properly propagate Maven repo policies (thorntail#425)
Motivation ---------- Maven repository policies weren't properly propagated (they were ignored) when converting Maven objects to Aether objects. The defaults were used every time. One of the implications was that the build was slower as all declared repositories were checked for new SNAPSHOTs (even if user disabled that). Modifications ------------- Both snapshot and release policies are properly propagted when creating the Aether remote repositories. Result ------ Maven plugin no longer tries to download SNAPSHOTs from Maven Central (or any other repository which has SNAPSHOTs disabled)
- Loading branch information
1 parent
ecc87d7
commit 422c8d0
Showing
2 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
plugin/src/test/java/org/wildfly/swarm/plugin/maven/MavenArtifactResolvingHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright 2017 Red Hat, Inc, and individual 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. | ||
*/ | ||
package org.wildfly.swarm.plugin.maven; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.maven.artifact.repository.ArtifactRepository; | ||
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; | ||
import org.apache.maven.artifact.repository.MavenArtifactRepository; | ||
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; | ||
import org.eclipse.aether.RepositorySystemSession; | ||
import org.eclipse.aether.repository.MirrorSelector; | ||
import org.eclipse.aether.repository.ProxySelector; | ||
import org.eclipse.aether.repository.RemoteRepository; | ||
import org.eclipse.aether.repository.RepositoryPolicy; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
public class MavenArtifactResolvingHelperTest { | ||
|
||
@Test | ||
// SWARM-1173: swarm-plugin trying to download SNAPSHOTs from Maven Central | ||
public void propagateRepositoryPolicies() { | ||
RepositorySystemSession sessionMock = Mockito.mock(RepositorySystemSession.class); | ||
MirrorSelector mirrorSelectorMock = Mockito.mock(MirrorSelector.class); | ||
Mockito.when(sessionMock.getMirrorSelector()).thenReturn(mirrorSelectorMock); | ||
ProxySelector proxySelectorMock = Mockito.mock(ProxySelector.class); | ||
Mockito.when(sessionMock.getProxySelector()).thenReturn(proxySelectorMock); | ||
|
||
MavenArtifactResolvingHelper artifactResolverHelper = new MavenArtifactResolvingHelper(null, null, sessionMock, null); | ||
ArtifactRepositoryPolicy testSnapshotPolicy = new ArtifactRepositoryPolicy(false, "hourly", "warn"); | ||
ArtifactRepositoryPolicy testReleasesPolicy = new ArtifactRepositoryPolicy(true, "never", "warn"); | ||
ArtifactRepository testingRepo = new MavenArtifactRepository("testing-repo", "http://testing-repo.org", new DefaultRepositoryLayout(), testSnapshotPolicy, testReleasesPolicy); | ||
artifactResolverHelper.remoteRepository(testingRepo); | ||
|
||
List<RemoteRepository> remoteRepos = artifactResolverHelper.getRemoteRepositories(); | ||
|
||
Assert.assertTrue("Remote repositories " + remoteRepos + " do not contain expected testing repo " + testingRepo, | ||
remoteRepos.stream().anyMatch( | ||
remoteRepo -> { | ||
RepositoryPolicy snapshotsPolicy = remoteRepo.getPolicy(true); | ||
RepositoryPolicy releasesPolicy = remoteRepo.getPolicy(false); | ||
return remoteRepo.getId().equals(testingRepo.getId()) && | ||
!snapshotsPolicy.isEnabled() && | ||
snapshotsPolicy.getUpdatePolicy().equals(testSnapshotPolicy.getUpdatePolicy()) && | ||
snapshotsPolicy.getChecksumPolicy().equals(testSnapshotPolicy.getChecksumPolicy()) && | ||
releasesPolicy.isEnabled() && | ||
releasesPolicy.getUpdatePolicy().equals(testReleasesPolicy.getUpdatePolicy()) && | ||
releasesPolicy.getChecksumPolicy().equals(testReleasesPolicy.getChecksumPolicy()); | ||
}) | ||
); | ||
} | ||
|
||
} |