Author: vsiveton Date: Mon Jul 14 14:52:05 2008 New Revision: 676750 URL: http://svn.apache.org/viewvc?rev=676750&view=rev Log: o r676627 doesn't take care of user proxy o moved LicenseReport#getLicenseInputStream() to a new utility class
Added: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ProjectInfoReportUtils.java (with props) Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/LicenseReport.java maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/LicenseReport.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/LicenseReport.java?rev=676750&r1=676749&r2=676750&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 Mon Jul 14 14:52:05 2008 @@ -24,23 +24,17 @@ import org.apache.maven.model.License; import org.apache.maven.project.MavenProject; import org.apache.maven.reporting.AbstractMavenReportRenderer; -import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Settings; import org.codehaus.plexus.i18n.I18N; -import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; 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.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -236,7 +230,8 @@ String licenseContent = null; try { - licenseContent = getLicenseInputStream( licenseUrl ); + // All licenses are supposed in English... + licenseContent = ProjectInfoReportUtils.getInputStream( licenseUrl, settings, "ISO-8859-1" ); } catch ( IOException e ) { @@ -275,76 +270,6 @@ endSection(); } - /** - * Get the content of the license Url - * - * @param licenseUrl - * @return the content of the licenseUrl - * @throws IOException - */ - private String getLicenseInputStream( URL licenseUrl ) - throws IOException - { - 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.setProperty( scheme + "proxySet", "true" ); - p.setProperty( scheme + "proxyHost", host ); - p.setProperty( scheme + "proxyPort", String.valueOf( proxy.getPort() ) ); - if ( !StringUtils.isEmpty( proxy.getNonProxyHosts() ) ) - { - p.setProperty( 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" ); - } - finally - { - IOUtil.close( in ); - } - } - private static URL baseURL( URL aUrl ) { String urlTxt = aUrl.toExternalForm(); Added: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ProjectInfoReportUtils.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ProjectInfoReportUtils.java?rev=676750&view=auto ============================================================================== --- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ProjectInfoReportUtils.java (added) +++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ProjectInfoReportUtils.java Mon Jul 14 14:52:05 2008 @@ -0,0 +1,115 @@ +package org.apache.maven.report.projectinfo; + +import java.io.IOException; +import java.io.InputStream; +import java.net.Authenticator; +import java.net.PasswordAuthentication; +import java.net.URL; +import java.util.Properties; + +import org.apache.maven.settings.Proxy; +import org.apache.maven.settings.Settings; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.StringUtils; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +/** + * Utilities methods. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a> + * @version $Id$ + * @since 2.1 + */ +public class ProjectInfoReportUtils +{ + /** + * Get the input stream from an URL + * + * @param url not null + * @param settings not null to handle proxy settings + * @return the inputstream found + * @throws IOException if any + */ + public static String getInputStream( URL url, Settings settings, String encoding ) + throws IOException + { + String scheme = url.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.setProperty( scheme + "proxySet", "true" ); + p.setProperty( scheme + "proxyHost", host ); + p.setProperty( scheme + "proxyPort", String.valueOf( proxy.getPort() ) ); + if ( !StringUtils.isEmpty( proxy.getNonProxyHosts() ) ) + { + p.setProperty( 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() + { + /** [EMAIL PROTECTED] */ + protected PasswordAuthentication getPasswordAuthentication() + { + return new PasswordAuthentication( userName, pwd.toCharArray() ); + } + } ); + } + } + } + } + + InputStream in = null; + try + { + in = url.openStream(); + + return IOUtil.toString( in, encoding ); + } + finally + { + IOUtil.close( in ); + } + } +} + Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ProjectInfoReportUtils.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ProjectInfoReportUtils.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java?rev=676750&r1=676749&r2=676750&view=diff ============================================================================== --- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java (original) +++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java Mon Jul 14 14:52:05 2008 @@ -49,11 +49,13 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.report.projectinfo.ProjectInfoReportUtils; import org.apache.maven.report.projectinfo.dependencies.Dependencies; import org.apache.maven.report.projectinfo.dependencies.DependenciesReportConfiguration; import org.apache.maven.report.projectinfo.dependencies.ArtifactUtils; import org.apache.maven.report.projectinfo.dependencies.RepositoryUtils; import org.apache.maven.reporting.AbstractMavenReportRenderer; +import org.apache.maven.settings.Settings; import org.apache.maven.shared.dependency.tree.DependencyNode; import org.apache.maven.shared.jar.JarData; import org.codehaus.plexus.i18n.I18N; @@ -97,6 +99,8 @@ private final Log log; + private final Settings settings; + private final RepositoryUtils repoUtils; /** @@ -159,7 +163,7 @@ * @param remoteRepositories * @param localRepository */ - public DependenciesRenderer( Sink sink, Locale locale, I18N i18n, Log log, Dependencies dependencies, + public DependenciesRenderer( Sink sink, Locale locale, I18N i18n, Log log, Settings settings, Dependencies dependencies, DependencyNode dependencyTreeNode, DependenciesReportConfiguration config, RepositoryUtils repoUtils, MavenProjectBuilder mavenProjectBuilder, List remoteRepositories, ArtifactRepository localRepository ) @@ -169,6 +173,7 @@ this.locale = locale; this.i18n = i18n; this.log = log; + this.settings = settings; this.dependencies = dependencies; this.dependencyTreeNode = dependencyTreeNode; this.repoUtils = repoUtils; @@ -599,7 +604,7 @@ try { URL repoUrl = new URL( repo.getUrl() ); - if ( repoUrl.openStream() == null ) + if ( ProjectInfoReportUtils.getInputStream( repoUrl, settings, "ISO-8859-1" ) == null ) { log.warn( "The repository url '" + repoUrl + "' has no stream - Repository '" + repo.getId() + "' will be blacklisted." ); @@ -607,7 +612,7 @@ repoUrlBlackListed.add( repo.getUrl() ); } } - catch ( Exception e ) + catch ( IOException e ) { log.warn( "The repository url '" + repo.getUrl() + "' is invalid - Repository '" + repo.getId() + "' will be blacklisted." );