You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vs...@apache.org on 2005/12/01 01:44:19 UTC
svn commit: r350086 - in
/maven/plugins/trunk/maven-project-info-reports-plugin: pom.xml
src/main/java/org/apache/maven/report/projectinfo/LicenseReport.java
Author: vsiveton
Date: Wed Nov 30 16:44:15 2005
New Revision: 350086
URL: http://svn.apache.org/viewcvs?rev=350086&view=rev
Log:
PR:MNG-1704
Submitted By: Jochen Wiedmann
Reviewed By: Vincent Siveton
Applied, with changes. Thanks, Jochen.
Avoid a NPE for proxy.getNonProxyHosts(), format code, add documentation.
Modified:
maven/plugins/trunk/maven-project-info-reports-plugin/pom.xml
maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/LicenseReport.java
Modified: maven/plugins/trunk/maven-project-info-reports-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-project-info-reports-plugin/pom.xml?rev=350086&r1=350085&r2=350086&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/pom.xml Wed Nov 30 16:44:15 2005
@@ -103,5 +103,10 @@
<artifactId>maven-scm-provider-cvs</artifactId>
<version>1.0-alpha-2</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-settings</artifactId>
+ <version>2.0</version>
+ </dependency>
</dependencies>
</project>
Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/LicenseReport.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/LicenseReport.java?rev=350086&r1=350085&r2=350086&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/LicenseReport.java (original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/LicenseReport.java Wed Nov 30 16:44:15 2005
@@ -21,6 +21,8 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
+import org.apache.maven.settings.Proxy;
+import org.apache.maven.settings.Settings;
import org.codehaus.doxia.sink.Sink;
import org.codehaus.doxia.site.renderer.SiteRenderer;
import org.codehaus.plexus.i18n.I18N;
@@ -30,12 +32,15 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.net.Authenticator;
import java.net.MalformedURLException;
+import java.net.PasswordAuthentication;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
+import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -76,6 +81,15 @@
private MavenProject project;
/**
+ * The Maven Settings.
+ *
+ * @parameter default-value="${settings}"
+ * @required
+ * @readonly
+ */
+ private Settings settings;
+
+ /**
* Whether the system is currently offline.
*
* @parameter expression="${settings.offline}"
@@ -144,7 +158,7 @@
{
if ( !offline )
{
- LicenseRenderer r = new LicenseRenderer( getSink(), getProject(), i18n, locale );
+ LicenseRenderer r = new LicenseRenderer( getSink(), getProject(), i18n, locale, settings );
r.render();
}
@@ -167,16 +181,20 @@
{
private MavenProject project;
+ private Settings settings;
+
private I18N i18n;
private Locale locale;
- public LicenseRenderer( Sink sink, MavenProject project, I18N i18n, Locale locale )
+ public LicenseRenderer( Sink sink, MavenProject project, I18N i18n, Locale locale, Settings settings )
{
super( sink );
this.project = project;
+ this.settings = settings;
+
this.i18n = i18n;
this.locale = locale;
@@ -280,22 +298,7 @@
}
}
- InputStream in = null;
- try
- {
- in = licenseUrl.openStream();
- // All licenses are supposed in English...
- licenseContent = IOUtil.toString( in, "ISO-8859-1" );
- }
- catch ( IOException e )
- {
- throw new MissingResourceException( "Can't read the url [" + url + "] : " + e.getMessage(),
- null, null );
- }
- finally
- {
- IOUtil.close( in );
- }
+ licenseContent = getLicenseInputStream( licenseUrl );
// TODO: we should check for a text/html mime type instead, and possibly use a html parser to do this a bit more cleanly/reliably.
String licenseContentLC = licenseContent.toLowerCase();
@@ -324,6 +327,78 @@
endSection();
}
+
+ /**
+ * Get the content of the license Url
+ *
+ * @param licenseUrl
+ * @return the content of the licenseUrl
+ */
+ private String getLicenseInputStream( URL licenseUrl )
+ {
+ String scheme = licenseUrl.getProtocol();
+ if ( !"file".equals( scheme ) )
+ {
+ Proxy proxy = settings.getActiveProxy();
+ if ( proxy != null )
+ {
+ if ( "http".equals( scheme ) || "https".equals( scheme ) )
+ {
+ scheme = "http.";
+ }
+ else if ( "ftp".equals( scheme ) )
+ {
+ scheme = "ftp.";
+ }
+ else
+ {
+ scheme = "";
+ }
+
+ String host = proxy.getHost();
+ if ( !StringUtils.isEmpty( host ) )
+ {
+ Properties p = System.getProperties();
+ p.put( scheme + "proxySet", "true" );
+ p.put( scheme + "proxyHost", host );
+ p.put( scheme + "proxyPort", String.valueOf( proxy.getPort() ) );
+ if ( !StringUtils.isEmpty( proxy.getNonProxyHosts() ) )
+ {
+ p.put( scheme + "nonProxyHosts", proxy.getNonProxyHosts() );
+ }
+
+ final String userName = proxy.getUsername();
+ if ( !StringUtils.isEmpty( userName ) )
+ {
+ final String pwd = StringUtils.isEmpty( proxy.getPassword() ) ? "" : proxy.getPassword();
+ Authenticator.setDefault( new Authenticator()
+ {
+ protected PasswordAuthentication getPasswordAuthentication()
+ {
+ return new PasswordAuthentication( userName, pwd.toCharArray() );
+ }
+ } );
+ }
+ }
+ }
+ }
+
+ InputStream in = null;
+ try
+ {
+ in = licenseUrl.openStream();
+ // All licenses are supposed in English...
+ return IOUtil.toString( in, "ISO-8859-1" );
+ }
+ catch ( IOException e )
+ {
+ throw new MissingResourceException( "Can't read the url [" + licenseUrl + "] : " + e.getMessage(), null, null );
+ }
+ finally
+ {
+ IOUtil.close( in );
+ }
+ }
}
private static URL baseURL( URL aUrl )
@@ -341,10 +416,8 @@
throw new AssertionError( e );
}
}
- else
- {
- return aUrl;
- }
+
+ return aUrl;
}
private static String replaceRelativeLinks( String html, String baseURL )