Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

Commit 4c80551

Browse files
committed
Merge pull request #66 from kkkon/proxy_lookup_nonproxy
Proxy lookup nonProxyHosts
2 parents 87c5b2e + c40647a commit 4c80551

7 files changed

Lines changed: 624 additions & 5 deletions

File tree

github-core/src/main/java/com/github/maven/plugins/core/GitHubProjectMojo.java

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.net.URL;
5050
import java.text.MessageFormat;
5151
import java.util.List;
52+
import org.eclipse.egit.github.core.client.IGitHubConstants;
5253

5354
/**
5455
* Base GitHub Mojo class to be extended.
@@ -159,7 +160,7 @@ protected GitHubClient createClient(String host, String userName,
159160
client = createClient();
160161

161162
{
162-
Proxy proxy = getProxy( settings, serverId );
163+
Proxy proxy = getProxy( settings, serverId, host );
163164
if ( null != proxy )
164165
{
165166
try
@@ -404,30 +405,95 @@ protected Server getServer(final Settings settings, final String serverId) {
404405
return null;
405406
}
406407

408+
/**
409+
* Check hostname that matched nonProxy setting
410+
*
411+
* @param proxy Maven Proxy. Must not null
412+
* @param hostname
413+
* @return matching result. true: match nonProxy
414+
*/
415+
protected boolean matchNonProxy( final Proxy proxy, final String hostname )
416+
{
417+
String host = hostname;
418+
419+
if ( null == hostname )
420+
host = IGitHubConstants.HOST_DEFAULT; // IGitHubConstants.HOST_API;
421+
422+
// code from org.apache.maven.plugins.site.AbstractDeployMojo#getProxyInfo
423+
final String nonProxyHosts = proxy.getNonProxyHosts();
424+
if ( null != nonProxyHosts )
425+
{
426+
final String[] nonProxies = nonProxyHosts.split( "(,)|(;)|(\\|)" );
427+
if ( null != nonProxies )
428+
{
429+
for ( final String nonProxyHost : nonProxies )
430+
{
431+
//if ( StringUtils.contains( nonProxyHost, "*" ) )
432+
if ( null != nonProxyHost && nonProxyHost.contains( "*" ) )
433+
{
434+
// Handle wildcard at the end, beginning or middle of the nonProxyHost
435+
final int pos = nonProxyHost.indexOf( '*' );
436+
String nonProxyHostPrefix = nonProxyHost.substring( 0, pos );
437+
String nonProxyHostSuffix = nonProxyHost.substring( pos + 1 );
438+
// prefix*
439+
if ( !StringUtils.isEmpty( nonProxyHostPrefix ) && host.startsWith( nonProxyHostPrefix )
440+
&& StringUtils.isEmpty( nonProxyHostSuffix ) )
441+
{
442+
return true;
443+
}
444+
// *suffix
445+
if ( StringUtils.isEmpty( nonProxyHostPrefix ) && !StringUtils.isEmpty( nonProxyHostSuffix )
446+
&& host.endsWith( nonProxyHostSuffix ) )
447+
{
448+
return true;
449+
}
450+
// prefix*suffix
451+
if ( !StringUtils.isEmpty( nonProxyHostPrefix ) && host.startsWith( nonProxyHostPrefix )
452+
&& !StringUtils.isEmpty( nonProxyHostSuffix ) && host.endsWith( nonProxyHostSuffix ) )
453+
{
454+
return true;
455+
}
456+
}
457+
else if ( host.equals( nonProxyHost ) )
458+
{
459+
return true;
460+
}
461+
}
462+
}
463+
}
464+
465+
return false;
466+
}
467+
407468
/**
408469
* Get proxy from settings
409470
*
410471
* @param settings
411472
* @param serverId
412473
* must be non-null and non-empty
474+
* @param host
475+
* hostname
413476
* @return proxy or null if none matching
414477
*/
415-
protected Proxy getProxy(final Settings settings, final String serverId) {
478+
protected Proxy getProxy(final Settings settings, final String serverId, final String host) {
416479
if (settings == null)
417480
return null;
418481
List<Proxy> proxies = settings.getProxies();
419482
if (proxies == null || proxies.isEmpty())
420483
return null;
421484

422485
// search id match first
423-
if ( serverId != null && serverId.isEmpty() ) {
486+
if ( serverId != null && !serverId.isEmpty() ) {
424487
for (Proxy proxy : proxies) {
425488
if ( proxy.isActive() ) {
426489
final String proxyId = proxy.getId();
427490
if ( proxyId != null && !proxyId.isEmpty() ) {
428491
if ( proxyId.equalsIgnoreCase(serverId) ) {
429492
if ( ( "http".equalsIgnoreCase( proxy.getProtocol() ) || "https".equalsIgnoreCase( proxy.getProtocol() ) ) ) {
430-
return proxy;
493+
if ( matchNonProxy( proxy, host ) )
494+
return null;
495+
else
496+
return proxy;
431497
}
432498
}
433499
}
@@ -440,7 +506,13 @@ protected Proxy getProxy(final Settings settings, final String serverId) {
440506
if ( proxy.isActive() &&
441507
( "http".equalsIgnoreCase( proxy.getProtocol() ) || "https".equalsIgnoreCase( proxy.getProtocol() ) )
442508
)
443-
return proxy;
509+
{
510+
if ( matchNonProxy( proxy, host ) )
511+
return null;
512+
else
513+
return proxy;
514+
}
515+
444516
return null;
445517
}
446518

0 commit comments

Comments
 (0)