Java Code Examples for org.eclipse.aether.DefaultRepositorySystemSession#setOffline()
The following examples show how to use
org.eclipse.aether.DefaultRepositorySystemSession#setOffline() .
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: MavenSettingsReader.java From spring-init with Apache License 2.0 | 6 votes |
public static void applySettings(MavenSettings settings, DefaultRepositorySystemSession session) { if (settings.getLocalRepository() != null) { try { session.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance(session, new LocalRepository(settings.getLocalRepository()))); } catch (NoLocalRepositoryManagerException e) { throw new IllegalStateException( "Cannot set local repository to " + settings.getLocalRepository(), e); } } session.setOffline(settings.getOffline()); session.setMirrorSelector(settings.getMirrorSelector()); session.setAuthenticationSelector(settings.getAuthenticationSelector()); session.setProxySelector(settings.getProxySelector()); }
Example 2
Source File: AetherFactories.java From spring-cloud-contract with Apache License 2.0 | 6 votes |
public static RepositorySystemSession newSession(RepositorySystem system, boolean workOffline) { DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); session.setOffline(workOffline); if (!workOffline) { session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS); } session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_WARN); String localRepositoryDirectory = localRepositoryDirectory(workOffline); if (log.isDebugEnabled()) { log.debug("Local Repository Directory set to [" + localRepositoryDirectory + "]. Work offline: [" + workOffline + "]"); } LocalRepository localRepo = new LocalRepository(localRepositoryDirectory); session.setLocalRepositoryManager( system.newLocalRepositoryManager(session, localRepo)); return session; }
Example 3
Source File: MavenSettingsReader.java From spring-cloud-function with Apache License 2.0 | 6 votes |
public static void applySettings(MavenSettings settings, DefaultRepositorySystemSession session) { if (settings.getLocalRepository() != null) { try { session.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance(session, new LocalRepository(settings.getLocalRepository()))); } catch (NoLocalRepositoryManagerException e) { throw new IllegalStateException( "Cannot set local repository to " + settings.getLocalRepository(), e); } } session.setOffline(settings.getOffline()); session.setMirrorSelector(settings.getMirrorSelector()); session.setAuthenticationSelector(settings.getAuthenticationSelector()); session.setProxySelector(settings.getProxySelector()); }
Example 4
Source File: Util.java From galleon with Apache License 2.0 | 5 votes |
public static RepositorySystemSession newRepositorySession(final RepositorySystem repoSystem, Path path, RepositoryListener listener, ProxySelector proxySelector, boolean offline) { final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); session.setRepositoryListener(listener); session.setOffline(offline); final LocalRepository localRepo = new LocalRepository(path.toString()); session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo)); if (proxySelector != null) { session.setProxySelector(proxySelector); } return session; }
Example 5
Source File: MavenArtifactResolver.java From spring-cloud-deployer with Apache License 2.0 | 5 votes |
private DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system, String localRepoPath) { DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); LocalRepository localRepo = new LocalRepository(localRepoPath); session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo)); session.setOffline(this.properties.isOffline()); session.setUpdatePolicy(this.properties.getUpdatePolicy()); session.setChecksumPolicy(this.properties.getChecksumPolicy()); if (this.properties.isEnableRepositoryListener()) { session.setRepositoryListener(new LoggingRepositoryListener()); } if (this.properties.getConnectTimeout() != null) { session.setConfigProperty(ConfigurationProperties.CONNECT_TIMEOUT, this.properties.getConnectTimeout()); } if (this.properties.getRequestTimeout() != null) { session.setConfigProperty(ConfigurationProperties.REQUEST_TIMEOUT, this.properties.getRequestTimeout()); } if (isProxyEnabled()) { DefaultProxySelector proxySelector = new DefaultProxySelector(); Proxy proxy = new Proxy(this.properties.getProxy().getProtocol(), this.properties.getProxy().getHost(), this.properties.getProxy().getPort(), this.proxyAuthentication); proxySelector.add(proxy, this.properties.getProxy().getNonProxyHosts()); session.setProxySelector(proxySelector); } // wagon configs for (Entry<String, MavenProperties.RemoteRepository> entry : this.properties.getRemoteRepositories().entrySet()) { session.setConfigProperty("aether.connector.wagon.config." + entry.getKey(), entry.getValue().getWagon()); } return session; }
Example 6
Source File: MavenContainer.java From furnace with Eclipse Public License 1.0 | 5 votes |
public DefaultRepositorySystemSession setupRepoSession(final RepositorySystem repoSystem, final Settings settings) { DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); session.setOffline(false); Proxy activeProxy = settings.getActiveProxy(); if (activeProxy != null) { DefaultProxySelector dps = new DefaultProxySelector(); dps.add(convertFromMavenProxy(activeProxy), activeProxy.getNonProxyHosts()); session.setProxySelector(dps); } final DefaultMirrorSelector mirrorSelector = createMirrorSelector(settings); final LazyAuthenticationSelector authSelector = createAuthSelector(settings, mirrorSelector); session.setMirrorSelector(mirrorSelector); session.setAuthenticationSelector(authSelector); LocalRepository localRepo = new LocalRepository(new File(settings.getLocalRepository())); session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo)); session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_IGNORE); session.setCache(new DefaultRepositoryCache()); boolean cacheNotFoundArtifacts = true; boolean cacheTransferErrors = true; session.setResolutionErrorPolicy(new SimpleResolutionErrorPolicy(cacheNotFoundArtifacts, cacheTransferErrors)); session.setWorkspaceReader(new ClasspathWorkspaceReader()); if (Boolean.getBoolean("org.apache.maven.log_transfer")) { session.setTransferListener(new JULMavenTransferListener()); } return session; }
Example 7
Source File: Utils.java From gate-core with GNU Lesser General Public License v3.0 | 4 votes |
public static DefaultRepositorySystemSession getRepositorySession(RepositorySystem repoSystem, WorkspaceReader workspace) { DefaultRepositorySystemSession repoSystemSession = MavenRepositorySystemUtils.newSession(); String repoLocation = System.getProperty("user.home") + File.separator + ".m2" + File.separator + "repository/"; ChainedProxySelector proxySelector = new ChainedProxySelector(); try { Settings effectiveSettings = loadMavenSettings(); if(effectiveSettings.getLocalRepository() != null) { repoLocation = effectiveSettings.getLocalRepository(); } List<Mirror> mirrors = effectiveSettings.getMirrors(); if(!mirrors.isEmpty()) { DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector(); for (Mirror mirror : mirrors) mirrorSelector.add( String.valueOf(mirror.getId()), mirror.getUrl(), mirror.getLayout(), false, mirror.getMirrorOf(), mirror.getMirrorOfLayouts()); repoSystemSession.setMirrorSelector(mirrorSelector); } List<Server> servers = effectiveSettings.getServers(); if(!servers.isEmpty()) { DefaultAuthenticationSelector selector = new DefaultAuthenticationSelector(); for (Server server : servers) { AuthenticationBuilder auth = new AuthenticationBuilder(); auth.addUsername(server.getUsername()).addPassword(PASSWORD_DECRYPTER.decrypt(server.getPassword())); auth.addPrivateKey(server.getPrivateKey(), PASSWORD_DECRYPTER.decrypt(server.getPassphrase())); selector.add(server.getId(), auth.build()); } repoSystemSession.setAuthenticationSelector(new ConservativeAuthenticationSelector(selector)); } // extract any proxies configured in the settings - we need to pass these // on so that any repositories declared in a dependency POM file can be // accessed through the proxy too. List<org.apache.maven.settings.Proxy> proxies = effectiveSettings.getProxies().stream().filter((p) -> p.isActive()) .collect(Collectors.toList()); if(!proxies.isEmpty()) { DefaultProxySelector defaultSelector = new DefaultProxySelector(); for (org.apache.maven.settings.Proxy proxy : proxies) { defaultSelector.add( new Proxy(proxy.getProtocol(), proxy.getHost(), proxy.getPort(), new AuthenticationBuilder().addUsername(proxy.getUsername()) .addPassword(PASSWORD_DECRYPTER.decrypt(proxy.getPassword())).build()), proxy.getNonProxyHosts()); } proxySelector.addSelector(defaultSelector); } // pass through the "offline" setting repoSystemSession.setOffline(effectiveSettings.isOffline()); } catch(SettingsBuildingException | SecDispatcherException | RuntimeException e) { log.warn( "Unable to load Maven settings, using default repository location, and no mirrors, proxy or authentication settings.", e); } LocalRepository localRepo = new LocalRepository(repoLocation); log.debug("Using local repository at: " + repoLocation); repoSystemSession.setLocalRepositoryManager(repoSystem .newLocalRepositoryManager(repoSystemSession, localRepo)); //repoSystemSession.setWorkspaceReader(new SimpleMavenCache(new File("repo"))); if (workspace != null) repoSystemSession.setWorkspaceReader(workspace); // try JRE proxies after any configured in settings proxySelector.addSelector(new JreProxySelector()); // set proxy selector for any repositories discovered in dependency poms repoSystemSession.setProxySelector(proxySelector); return repoSystemSession; }