org.apache.maven.settings.Mirror Java Examples
The following examples show how to use
org.apache.maven.settings.Mirror.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RepositoryPreferences.java From netbeans with Apache License 2.0 | 6 votes |
/** * if the repository has a mirror, then create a repositoryinfo object for it.. */ private RepositoryInfo getMirrorInfo(RepositoryInfo info, MirrorSelector selector, Settings settings) { RemoteRepository original = new RemoteRepository.Builder(info.getId(), /* XXX do we even support any other layout?*/"default", info.getRepositoryUrl()).build(); RemoteRepository mirror = selector.getMirror(original); if (mirror != null) { try { String name = mirror.getId(); //#213078 need to lookup name for mirror for (Mirror m : settings.getMirrors()) { if (m.getId() != null && m.getId().equals(mirror.getId())) { name = m.getName(); break; } } RepositoryInfo toret = new RepositoryInfo(mirror.getId(), name, null, mirror.getUrl()); toret.setMirrorStrategy(RepositoryInfo.MirrorStrategy.NONE); return toret; } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); } } return null; }
Example #2
Source File: JDOMSettingsConverter.java From pom-manipulation-ext with Apache License 2.0 | 6 votes |
/** * Method updateMirror. * @param mirror * @param counter * @param element */ protected void updateMirror( final Mirror mirror, final IndentationCounter counter, final Element element ) { final IndentationCounter innerCount = new IndentationCounter( counter.getDepth() + 1 ); findAndReplaceSimpleElement( innerCount, element, "mirrorOf", mirror.getMirrorOf(), null ); findAndReplaceSimpleElement( innerCount, element, "name", mirror.getName(), null ); findAndReplaceSimpleElement( innerCount, element, "url", mirror.getUrl(), null ); if ( element.getNamespace().getURI().equals( "http://maven.apache.org/SETTINGS/1.1.0" ) ) { findAndReplaceSimpleElement( innerCount, element, "layout", mirror.getLayout(), null ); findAndReplaceSimpleElement( innerCount, element, "mirrorOfLayouts", mirror.getMirrorOfLayouts(), "default,legacy" ); } findAndReplaceSimpleElement( innerCount, element, "id", mirror.getId(), "default" ); }
Example #3
Source File: MavenPluginRepository.java From BIMserver with GNU Affero General Public License v3.0 | 6 votes |
private DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system, File localRepoFile, Settings settings) { DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); if (!settings.getMirrors().isEmpty()) { DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector(); for (Mirror mirror : settings.getMirrors()) { mirrorSelector.add(mirror.getId(), mirror.getUrl(), "default", true, mirror.getMirrorOf(), "*"); } session.setMirrorSelector(mirrorSelector); } session.setProxySelector(proxySelector); LocalRepository localRepo = new LocalRepository(localRepoFile); session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo)); return session; }
Example #4
Source File: MavenSettings.java From spring-init with Apache License 2.0 | 5 votes |
private MirrorSelector createMirrorSelector(Settings settings) { DefaultMirrorSelector selector = new DefaultMirrorSelector(); for (Mirror mirror : settings.getMirrors()) { selector.add(mirror.getId(), mirror.getUrl(), mirror.getLayout(), false, mirror.getMirrorOf(), mirror.getMirrorOfLayouts()); } return selector; }
Example #5
Source File: MavenSettings.java From spring-cloud-function with Apache License 2.0 | 5 votes |
private MirrorSelector createMirrorSelector(Settings settings) { DefaultMirrorSelector selector = new DefaultMirrorSelector(); for (Mirror mirror : settings.getMirrors()) { selector.add(mirror.getId(), mirror.getUrl(), mirror.getLayout(), false, mirror.getMirrorOf(), mirror.getMirrorOfLayouts()); } return selector; }
Example #6
Source File: WrapperMojo.java From takari-maven-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Determine the repository URL to download wrapper and maven from. */ private String getRepoUrl() { // default String result = DEFAULT_DOWNLOAD_BASE_URL; // user property has precedence if (!isNullOrEmpty(downloadBaseUrl)) { result = downloadBaseUrl; getLog().debug("Setting repo URL from property."); } // adapt to also support MVNW_REPOURL as supported by mvnw scripts from maven-wrapper String mvnwRepoUrl = System.getenv("MVNW_REPOURL"); if (!isNullOrEmpty(mvnwRepoUrl)) { result = mvnwRepoUrl; getLog().debug("Setting repo URL from environment variable."); } // otherwise mirror from settings else if (settings.getMirrors() != null && settings.getMirrors().size() > 0) { for (Mirror current : settings.getMirrors()) { if ("*".equals(current.getMirrorOf())) { result = current.getUrl(); break; } } getLog().debug("Setting repo URL from mirror in settings file."); } getLog().debug("Determined repo URL to use as " + result); return result; }
Example #7
Source File: MavenContainer.java From furnace with Eclipse Public License 1.0 | 5 votes |
private DefaultMirrorSelector createMirrorSelector(Settings settings) { final DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector(); final List<Mirror> mirrors = settings.getMirrors(); if (mirrors != null) { for (Mirror mirror : mirrors) { mirrorSelector.add(mirror.getId(), mirror.getUrl(), mirror.getLayout(), false, mirror.getMirrorOf(), mirror.getMirrorOfLayouts()); } } return mirrorSelector; }
Example #8
Source File: MavenRepositories.java From furnace with Eclipse Public License 1.0 | 5 votes |
static Optional<String> getCentralMirrorURL(Settings settings) { return settings.getMirrors().stream() .filter(m -> "central".equals(m.getMirrorOf()) || "*".equals(m.getMirrorOf()) || MAVEN_CENTRAL_REPO.equals(m.getMirrorOf())) .map(Mirror::getUrl) .findFirst(); }
Example #9
Source File: RepositoryPreferencesTest.java From netbeans with Apache License 2.0 | 4 votes |
/** created in attempt of reproducing issue http://netbeans.org/bugzilla/show_bug.cgi?id=214980 */ public void testGetMirrorRepositoryInfos() throws Exception { Mirror mirror = new Mirror(); mirror.setId("mirror"); mirror.setMirrorOf("*"); mirror.setUrl("http://localhost"); mirror.setName("mirror repository"); try { EmbedderFactory.getOnlineEmbedder().getSettings().addMirror(mirror); RepositoryPreferences rp = RepositoryPreferences.getInstance(); assertEquals("[local, mirror]", rp.getRepositoryInfos().toString()); RepositoryInfo m = rp.getRepositoryInfoById("mirror"); assertTrue(m.isMirror()); assertEquals("[central]", m.getMirroredRepositories().toString()); //add a repository rp.addTransientRepository(1, "eclipselink", "Repository for library Library[eclipselink]", "http://ftp.ing.umu.se/mirror/eclipse/rt/eclipselink/maven.repo", RepositoryInfo.MirrorStrategy.ALL); assertEquals("[local, mirror]", rp.getRepositoryInfos().toString()); m = rp.getRepositoryInfoById("mirror"); assertTrue(m.isMirror()); assertEquals("[eclipselink]", m.getMirroredRepositories().toString()); //add the same repository again.. rp.addTransientRepository(1, "eclipselink", "Repository for library Library[eclipselink]", "http://ftp.ing.umu.se/mirror/eclipse/rt/eclipselink/maven.repo", RepositoryInfo.MirrorStrategy.ALL); assertEquals("[local, mirror]", rp.getRepositoryInfos().toString()); m = rp.getRepositoryInfoById("mirror"); assertTrue(m.isMirror()); assertEquals("[eclipselink]", m.getMirroredRepositories().toString()); //add as non-transient repository now.. RepositoryInfo ii = new RepositoryInfo("eclipselink", "Repository for library Library[eclipselink]", null, "http://ftp.ing.umu.se/mirror/eclipse/rt/eclipselink/maven.repo"); rp.addOrModifyRepositoryInfo(ii); //in this case mirror is not used and direct reference is used.. assertEquals("[local, eclipselink]", rp.getRepositoryInfos().toString()); //remove and mirror should show up again.. rp.removeRepositoryInfo(ii); assertEquals("[local, mirror]", rp.getRepositoryInfos().toString()); m = rp.getRepositoryInfoById("mirror"); assertTrue(m.isMirror()); assertEquals("[eclipselink]", m.getMirroredRepositories().toString()); //add central now.. should have 2 mirrored repositories.. rp.addTransientRepository(1, "central", "central", "http://repo1.maven.org/maven2", RepositoryInfo.MirrorStrategy.ALL); assertEquals("[local, mirror]", rp.getRepositoryInfos().toString()); m = rp.getRepositoryInfoById("mirror"); assertTrue(m.isMirror()); assertEquals("[eclipselink, central]", m.getMirroredRepositories().toString()); //add central AGAIN and AGAIN.. should have still just 2 mirrored repositories.. rp.addTransientRepository(2, "central", "central", "http://repo1.maven.org/maven2", RepositoryInfo.MirrorStrategy.ALL); rp.addTransientRepository(3, "central", "central", "http://repo1.maven.org/maven2", RepositoryInfo.MirrorStrategy.ALL); rp.addTransientRepository(4, "central", "central", "http://repo1.maven.org/maven2", RepositoryInfo.MirrorStrategy.ALL); assertEquals("[local, mirror]", rp.getRepositoryInfos().toString()); m = rp.getRepositoryInfoById("mirror"); assertTrue(m.isMirror()); assertEquals("[eclipselink, central]", m.getMirroredRepositories().toString()); //try adding slightly modified transient repositories.. rp.addTransientRepository(3, "central", "central", "http://repo1.maven.org/maven2/", RepositoryInfo.MirrorStrategy.ALL); rp.addTransientRepository(2, "central", "central rep", "http://repo1.maven.org/maven2", RepositoryInfo.MirrorStrategy.ALL); rp.addTransientRepository(2, "eclipselink", "Repository for library Library", "http://ftp.ing.umu.se/mirror/eclipse/rt/eclipselink/maven.repo", RepositoryInfo.MirrorStrategy.ALL); assertEquals("[local, mirror]", rp.getRepositoryInfos().toString()); m = rp.getRepositoryInfoById("mirror"); assertTrue(m.isMirror()); assertEquals("[eclipselink, central]", m.getMirroredRepositories().toString()); } finally { EmbedderFactory.getOnlineEmbedder().getSettings().removeMirror(mirror); } }
Example #10
Source File: MavenLocationExpander.java From pom-manipulation-ext with Apache License 2.0 | 4 votes |
private void addRequestRepositoriesTo( final Set<Location> locs, final List<ArtifactRepository> artifactRepositories, final Settings settings, final MirrorSelector mirrorSelector ) throws MalformedURLException { if ( artifactRepositories != null ) { for ( final ArtifactRepository repo : artifactRepositories ) { // TODO: Authentication via memory password manager. String id = repo.getId(); String url = repo.getUrl(); if ( url.startsWith( "file:" ) ) { locs.add( new SimpleLocation( id, url ) ); } else { final List<Mirror> mirrors = settings.getMirrors(); if ( mirrors != null ) { final Mirror mirror = mirrorSelector == null ? null : mirrorSelector.getMirror( repo, mirrors ); if ( mirror != null ) { id = mirror.getId(); url = mirror.getUrl(); } } final ArtifactRepositoryPolicy releases = repo.getReleases(); final ArtifactRepositoryPolicy snapshots = repo.getSnapshots(); SimpleHttpLocation addition = new SimpleHttpLocation( id, url, snapshots != null && snapshots.isEnabled(), releases == null || releases.isEnabled(), true, false, null ); addition.setAttribute(Location.CONNECTION_TIMEOUT_SECONDS, 60); locs.add (addition); } } } }
Example #11
Source File: MavenLocationExpander.java From pom-manipulation-ext with Apache License 2.0 | 4 votes |
private void addSettingsProfileRepositoriesTo( final Set<Location> locs, final Settings settings, final List<String> activeProfiles, final MirrorSelector mirrorSelector ) throws MalformedURLException { if ( settings != null ) { final Map<String, Profile> profiles = settings.getProfilesAsMap(); if ( profiles != null && activeProfiles != null && !activeProfiles.isEmpty() ) { final LinkedHashSet<String> active = new LinkedHashSet<>( activeProfiles ); final List<String> settingsActiveProfiles = settings.getActiveProfiles(); if ( settingsActiveProfiles != null && !settingsActiveProfiles.isEmpty() ) { active.addAll( settingsActiveProfiles ); } for ( final String profileId : active ) { final Profile profile = profiles.get( profileId ); if ( profile != null ) { final List<Repository> repositories = profile.getRepositories(); if ( repositories != null ) { final List<Mirror> mirrors = settings.getMirrors(); final ArtifactRepositoryLayout layout = new DefaultRepositoryLayout(); for ( final Repository repo : repositories ) { String id = repo.getId(); String url = repo.getUrl(); if ( mirrors != null ) { final ArtifactRepositoryPolicy snapshots = convertPolicy( repo.getSnapshots() ); final ArtifactRepositoryPolicy releases = convertPolicy( repo.getReleases() ); final MavenArtifactRepository arepo = new MavenArtifactRepository( id, url, layout, snapshots, releases ); final Mirror mirror = mirrorSelector == null ? null : mirrorSelector.getMirror( arepo, mirrors ); if ( mirror != null ) { id = mirror.getId(); url = mirror.getUrl(); } SimpleHttpLocation addition = new SimpleHttpLocation( id, url, snapshots.isEnabled(), releases.isEnabled(), true, false, null ); addition.setAttribute(Location.CONNECTION_TIMEOUT_SECONDS, 60); locs.add (addition); } } } } } } } }
Example #12
Source File: SettingsIO.java From pom-manipulation-ext with Apache License 2.0 | 4 votes |
public void update( Settings settings, File settingsFile ) throws ManipulationException { try { Settings defaultSettings = new Settings(); if ( settingsFile.exists() ) { DefaultSettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest(); settingsRequest.setGlobalSettingsFile( settingsFile ); defaultSettings = settingsBuilder.build( settingsRequest ).getEffectiveSettings(); } for ( Profile profile : settings.getProfiles() ) { defaultSettings.getProfiles().removeIf( profile1 -> profile1.getId().equals( profile.getId() ) ); defaultSettings.addProfile( profile ); } for ( String activeProfile : settings.getActiveProfiles() ) { defaultSettings.getActiveProfiles().removeIf( s -> s.equals( activeProfile ) ); defaultSettings.addActiveProfile( activeProfile ); } for ( Mirror mirror : settings.getMirrors() ) { defaultSettings.addMirror( mirror ); } for ( Proxy proxy : settings.getProxies() ) { defaultSettings.addProxy( proxy ); } for ( Server server : settings.getServers() ) { defaultSettings.addServer( server ); } for ( String pluginGroup : settings.getPluginGroups() ) { defaultSettings.addPluginGroup( pluginGroup ); } if ( settings.getLocalRepository() != null ) { defaultSettings.setLocalRepository( settings.getLocalRepository() ); } write( defaultSettings, settingsFile ); } catch ( SettingsBuildingException e ) { throw new ManipulationException( "Failed to build existing settings.xml for repo removal backup.", settingsFile, e.getMessage(), e ); } }
Example #13
Source File: MavenLocationExpanderTest.java From pom-manipulation-ext with Apache License 2.0 | 4 votes |
@Test public void mirrorAdjustsLocationURLs() throws Exception { final Mirror mirror = new Mirror(); mirror.setId( "test-mirror" ); mirror.setMirrorOf( "*" ); mirror.setUrl( "http://nowhere.com" ); final ArtifactRepositoryLayout layout = new DefaultRepositoryLayout(); final ArtifactRepositoryPolicy snapshots = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN ); final ArtifactRepositoryPolicy releases = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN ); final File localRepo = File.createTempFile( "local.repo.", ".dir" ); localRepo.deleteOnExit(); final ArtifactRepository local = new MavenArtifactRepository( "local", localRepo.toURI() .toString(), layout, snapshots, releases ); final ArtifactRepository remote = new MavenArtifactRepository( "remote", "http:///repo.maven.apache.org/maven2", layout, snapshots, releases ); final Settings settings = new Settings(); settings.addMirror( mirror ); final MavenLocationExpander ex = new MavenLocationExpander( Collections.<Location> emptyList(), Collections.<ArtifactRepository> singletonList( remote ), local, new DefaultMirrorSelector(), settings, Collections.<String> emptyList() ); final List<Location> result = ex.expand( MavenLocationExpander.EXPANSION_TARGET ); assertThat( result.size(), equalTo( 2 ) ); final Iterator<Location> iterator = result.iterator(); Location loc = iterator.next(); assertThat( loc.getName(), equalTo( local.getId() ) ); assertThat( loc.getUri(), equalTo( local.getUrl() ) ); loc = iterator.next(); assertThat( loc.getName(), equalTo( mirror.getId() ) ); assertThat( loc.getUri(), equalTo( mirror.getUrl() ) ); }