Author: tchemit Date: 2010-06-19 14:14:08 +0200 (Sat, 19 Jun 2010) New Revision: 722 Url: http://nuiton.org/repositories/revision/maven-helper-plugin/722 Log: improve and finalize checkAutocontainer mojo Added: trunk/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java Removed: trunk/src/main/java/org/nuiton/helper/plugin/CheckCentralSafePlugin.java Copied: trunk/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java (from rev 721, trunk/src/main/java/org/nuiton/helper/plugin/CheckCentralSafePlugin.java) =================================================================== --- trunk/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java (rev 0) +++ trunk/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java 2010-06-19 12:14:08 UTC (rev 722) @@ -0,0 +1,522 @@ +/* + * #%L + * Maven helper plugin + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.helper.plugin; + + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.ArtifactUtils; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.manager.WagonManager; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.apache.maven.settings.Proxy; +import org.apache.maven.wagon.ConnectionException; +import org.apache.maven.wagon.Wagon; +import org.apache.maven.wagon.authentication.AuthenticationInfo; +import org.apache.maven.wagon.observers.Debug; +import org.apache.maven.wagon.proxy.ProxyInfo; +import org.apache.maven.wagon.repository.Repository; +import org.codehaus.plexus.util.StringUtils; +import org.nuiton.plugin.AbstractPlugin; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +/** + * Check all dependencies are in central repository. + * + * @author tchemit <chemit@codelutin.com> + * @goal check-auto-container + * @phase validate + * @requiresProject true + * @requiresOnline true + * @requiresDependencyResolution runtime + * @since 1.2.5 + */ +public class CheckAutoContainerPlugin extends AbstractPlugin { + + /** + * Map of remote repositories to use. + * <p/> + * Keys are repository id and Values are repository url. + * + * @parameter + * @since 1.2.5 + */ + protected Map<String, String> repositories; + + /** + * A flag to add as maven central remote repository http://repo1.maven.org/maven2 + * to {@link #repositories}. + * + * @parameter expression="${addMavenCentral}" default-value="false" + * @since 1.2.5 + */ + protected boolean addMavenCentral; + + /** + * A flag to fail if project is not central safe. + * + * @parameter expression="${helper.failIfNotSafe}" default-value="false" + * @since 1.2.5 + */ + protected boolean failIfNotSafe; + + /** + * A flag to activate verbose mode. + * + * @parameter expression="${helper.verbose}" default-value="${maven.verbose}" + * @since 1.2.5 + */ + protected boolean verbose; + + /** + * Project. + * + * @parameter default-value="${project}" + * @required + * @readonly + * @since 1.2.5 + */ + protected MavenProject project; + + /** + * The projects in the reactor (used to detected sibling dependencies). + * + * @parameter expression="${reactorProjects}" + * @readonly + * @since 1.2.5 + */ + protected List<?> reactorProjects; + + /** + * Active proxy from settings. + * + * @parameter default-value="${settings.activeProxy}" + * @required + * @readonly + * @since 1.2.5 + */ + protected Proxy proxy; + + /** + * Local Repository. + * + * @parameter expression="${localRepository}" + * @required + * @readonly + * @since 1.2.5 + */ + protected ArtifactRepository localRepository; + + /** + * @component + * @readonly + * @since 1.2.5 + */ + protected ArtifactRepositoryFactory artifactRepositoryFactory; + + /** + * Artifact Factory component. + * + * @component + * @readonly + * @since 1.2.5 + */ + protected ArtifactFactory factory; + + /** + * @component + * @readonly + * @since 1.2.5 + */ + protected ArtifactResolver resolver; + + /** + * @component + * @readonly + * @since 1.2.5 + */ + protected WagonManager wagonManager; + + /** + * Authorized Remote Repositories. + * + * @since 1.2.5 + */ + private List<ArtifactRepository> safeRepositories; + + /** + * List of artifacts to treate. + * + * @since 1.2.5 + */ + private List<Artifact> artifacts; + + /** + * Dictionnary of already resolved artifacts (keys are repository url and + * values are list of artifact ids). + * + * @since 1.2.5 + */ + private static Map<String, List<String>> resolved; + + public static final String MAVEN_CENTRAL_ID = "maven-central"; + + public static final String MAVEN_CENTRAL_URL = "http://repo1.maven.org/maven2/"; + + @Override + public MavenProject getProject() { + return project; + } + + @Override + public void setProject(MavenProject project) { + this.project = project; + } + + @Override + public boolean isVerbose() { + return verbose; + } + + @Override + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + @Override + public void init() throws Exception { + + Log log = getLog(); + + if (log.isDebugEnabled()) { + + // always be verbose in debug mode + setVerbose(true); + } + + safeRepositories = createSafeRepositories(); + + artifacts = prepareArtifacts(); + + if (isVerbose()) { + log.info(artifacts.size() + " detected dependencies : "); + for (Object artifact : artifacts) { + log.info(" - " + artifact); + } + } + } + + @Override + protected boolean checkSkip() { + + if (artifacts.isEmpty()) { + getLog().info("Project has no dependecy."); + return false; + } + + if (repositories.isEmpty()) { + getLog().info("No repository defined."); + return false; + } + return super.checkSkip(); + } + + @Override + protected void doAction() throws Exception { + + Log log = getLog(); + + log.info(artifacts.size() + " dependencies to check."); + + for (ArtifactRepository repository : safeRepositories) { + + if (artifacts.isEmpty()) { + + // no more artifacts to check + continue; + } + + String url = repository.getUrl(); + + List<String> ids = getRepositoryCache(url); + Wagon wagon = getWagon(repository); + try { + if (verbose) { + log.info("Use repository " + url); + } + List<Artifact> found = checkDependency(repository, wagon, ids); + String message; + if (found.isEmpty()) { + message = "No artifact resolved by the repository " + url; + } else { + message = found.size() + " artifact(s) resolved by repository " + url; + } + log.info(message); + artifacts.removeAll(found); + + } finally { + disconnect(wagon); + } + } + + boolean safe = artifacts.isEmpty(); + + if (safe) { + log.info("All dependencies are safe."); + return; + } + + log.warn("There is " + artifacts.size() + " unsafe dependencie(s) :"); + for (Object artifact : artifacts) { + log.warn(" - " + artifact); + } + if (failIfNotSafe) { + throw new MojoFailureException("There is still some unsafe dependencies."); + } + } + + protected List<ArtifactRepository> createSafeRepositories() { + List<ArtifactRepository> safeRepositories = new ArrayList<ArtifactRepository>(); + + ArtifactRepositoryLayout repositoryLayout = new DefaultRepositoryLayout(); + if (repositories == null) { + repositories = new TreeMap<String, String>(); + } + List<String> ids = new ArrayList<String>(repositories.keySet()); + if (addMavenCentral) { + + ids.add(0, MAVEN_CENTRAL_ID); + repositories.put(MAVEN_CENTRAL_ID, MAVEN_CENTRAL_URL); + } + + for (String id : ids) { + String url = repositories.get(id); + url = url.trim(); + + ArtifactRepository repo; + repo = artifactRepositoryFactory.createDeploymentArtifactRepository( + String.valueOf(id), + url, + repositoryLayout, true); + + getLog().info("Will use repository " + repo.getUrl()); + safeRepositories.add(repo); + } + return safeRepositories; + } + + protected List<Artifact> prepareArtifacts() { + + List<Artifact> result = new ArrayList<Artifact>(); + + List<String> siblings = new ArrayList<String>(); + + for (Object o : reactorProjects) { + MavenProject m = (MavenProject) o; + siblings.add(getArtifactId(m.getArtifact())); + } + + // treate classic dependencies + for (Object o : project.getArtifacts()) { + Artifact a = (Artifact) o; + Artifact artifact = acceptArtifact(a, siblings); + if (artifact != null) { + result.add(a); + } + } + + // treate also plugin dependencies + for (Object o : project.getPluginArtifacts()) { + Artifact a = (Artifact) o; + Artifact artifact = acceptArtifact(a, siblings); + if (artifact != null) { + result.add(a); + } + } + return result; + } + + protected Artifact acceptArtifact(Artifact a, List<String> siblings) { + String id = getArtifactId(a); + + if (siblings.contains(id)) { + + // skip a sibling dependency + if (verbose) { + getLog().info("Skip sibling dependency : " + id); + } + return null; + } + + if (a.isSnapshot()) { + + // skip snapshot + getLog().warn("Skip SNAPSHOT dependency : " + id); + return null; + } + + Artifact artifact = ArtifactUtils.copyArtifact(a); + + // force artifact not to be treated + artifact.setResolved(false); + + // will treate this artifact + return artifact; + } + + private List<Artifact> checkDependency(ArtifactRepository repo, + Wagon wagon, + List<String> ids) throws Exception { + Log log = getLog(); + List<Artifact> result = new ArrayList<Artifact>(); + String url = repo.getUrl(); + + for (Artifact artifact : artifacts) { + if (log.isDebugEnabled()) { + log.debug(" - check artifact : " + artifact); + } + String id = getArtifactId(artifact); + + boolean resolved; + boolean inCache = ids.contains(id); + if (inCache) { + + // already resolved + resolved = true; + } else { + + // first time resolving this artifact + Artifact copyArtifact = ArtifactUtils.copyArtifact(artifact); + + String path = url + "/" + repo.pathOf(copyArtifact); + + resolved = wagon.resourceExists(StringUtils.replace(path, repo.getUrl(), "")); + } + + if (resolved) { + + if (verbose) { + log.info(" - [ resolved ] " + artifact + (inCache ? " (from cache)" : "")); + } + result.add(artifact); + ids.add(id); + } else { + if (log.isDebugEnabled()) { + log.debug(" - [unresolved] " + artifact); + } + } + } + return result; + } + + protected String getArtifactId(Artifact artifact) { + String id = artifact.getGroupId() + ":" + + artifact.getArtifactId() + ":" + + artifact.getVersion(); + return id; + } + + protected List<String> getRepositoryCache(String url) { + if (resolved == null) { + resolved = new TreeMap<String, List<String>>(); + } + List<String> ids = resolved.get(url); + if (ids == null) { + ids = new ArrayList<String>(); + resolved.put(url, ids); + } + return ids; + } + + + protected Wagon getWagon(ArtifactRepository repo) throws Exception { + + Repository repository = new Repository(repo.getId(), repo.getUrl()); + Wagon wagon = wagonManager.getWagon(repository); + + wagon.setTimeout(1000); + + if (getLog().isDebugEnabled()) { + Debug debug = new Debug(); + + wagon.addSessionListener(debug); + wagon.addTransferListener(debug); + } + + // FIXME when upgrading to maven 3.x : this must be changed. + AuthenticationInfo auth = wagonManager.getAuthenticationInfo(repo.getId()); + + ProxyInfo proxyInfo = getProxyInfo(); + if (proxyInfo != null) { + wagon.connect(repository, auth, proxyInfo); + } else { + wagon.connect(repository, auth); + } + + return wagon; + } + + protected void disconnect(Wagon wagon) { + try { + wagon.disconnect(); + } + catch (ConnectionException e) { + Log log = getLog(); + if (log.isDebugEnabled()) { + log.error("Error disconnecting wagon - ignored", e); + } else { + log.error("Error disconnecting wagon - ignored"); + } + } + } + + protected ProxyInfo getProxyInfo() { + ProxyInfo proxyInfo = null; + if (proxy != null && !StringUtils.isEmpty(proxy.getHost())) { + + proxyInfo = new ProxyInfo(); + proxyInfo.setHost(proxy.getHost()); + proxyInfo.setType(proxy.getProtocol()); + proxyInfo.setPort(proxy.getPort()); + proxyInfo.setNonProxyHosts(proxy.getNonProxyHosts()); + proxyInfo.setUserName(proxy.getUsername()); + proxyInfo.setPassword(proxy.getPassword()); + } + + return proxyInfo; + } + +} \ No newline at end of file Property changes on: trunk/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Deleted: trunk/src/main/java/org/nuiton/helper/plugin/CheckCentralSafePlugin.java =================================================================== --- trunk/src/main/java/org/nuiton/helper/plugin/CheckCentralSafePlugin.java 2010-06-19 00:41:12 UTC (rev 721) +++ trunk/src/main/java/org/nuiton/helper/plugin/CheckCentralSafePlugin.java 2010-06-19 12:14:08 UTC (rev 722) @@ -1,473 +0,0 @@ -/* - * #%L - * Maven helper plugin - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.helper.plugin; - - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.ArtifactUtils; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.manager.WagonConfigurationException; -import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; -import org.apache.maven.artifact.resolver.ArtifactResolver; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugin.logging.Log; -import org.apache.maven.project.MavenProject; -import org.apache.maven.settings.Proxy; -import org.apache.maven.wagon.ConnectionException; -import org.apache.maven.wagon.TransferFailedException; -import org.apache.maven.wagon.UnsupportedProtocolException; -import org.apache.maven.wagon.Wagon; -import org.apache.maven.wagon.authentication.AuthenticationException; -import org.apache.maven.wagon.authentication.AuthenticationInfo; -import org.apache.maven.wagon.authorization.AuthorizationException; -import org.apache.maven.wagon.observers.Debug; -import org.apache.maven.wagon.proxy.ProxyInfo; -import org.apache.maven.wagon.repository.Repository; -import org.codehaus.plexus.util.StringUtils; -import org.nuiton.plugin.AbstractPlugin; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Check all dependencies are in central repository. - * - * @author tchemit <chemit@codelutin.com> - * @goal check-central-safe - * @phase verify - * @requiresProject true - * @requiresOnline true - * @requiresDependencyResolution runtime - * @since 1.2.5 - */ -public class CheckCentralSafePlugin extends AbstractPlugin { - - /** - * Project. - * - * @parameter default-value="${project}" - * @required - * @readonly - * @since 1.1.0 - */ - protected MavenProject project; - - /** - * Active proxy from settings. - * - * @parameter default-value="${settings.activeProxy}" - * @required - * @readonly - * @since 1.1.0 - */ - protected Proxy proxy; - - /** - * A flag to activate verbose mode. - * - * @parameter expression="${helper.verbose}" default-value="${maven.verbose}" - * @since 1.1.0 - */ - protected boolean verbose; - - /** - * A flag to fail if project is not central safe. - * - * @parameter expression="${helper.failIfNotSafe}" default-value="false" - * @since 1.1.0 - */ - protected boolean failIfNotSafe; - - /** - * A flag to execute only once the mojo. - * <p/> - * <b>Note:</b> By default, value is {@code true} since it is not necessary - * to inject twice secrets in session. - * - * @parameter expression="${helper.runOnce}" default-value="true" - * @since 1.1.0 - */ - protected boolean runOnce; - - /** - * Local Repository. - * - * @parameter expression="${localRepository}" - * @required - * @readonly - * @since 1.0.0 - */ - protected ArtifactRepository localRepository; - - /** - * @component - * @readonly - */ - protected ArtifactRepositoryFactory artifactRepositoryFactory; - - /** - * Artifact Factory component. - * - * @component - * @readonly - */ - protected ArtifactFactory factory; - - /** - * @component - * @readonly - */ - protected ArtifactResolver resolver; - - /** - * @component - * @readonly - */ - protected WagonManager wagonManager; - - /** - * Authorized Remote Repository. - * - * @since 1.0.0 - */ - protected List<ArtifactRepository> safeRepositories; - - /** - * Map of extra remote Repositories. Keys are repository id and Values are repository url. - * - * @parameter - * @since 1.0.0 - */ - protected Map<String, String> extraRepositories; - - /** - * Dependencies of the project. - * - * @parameter expression="${project.artifacts}" - * @required - * @readonly - * @since 1.1.0 - */ - protected Set<?> artifacts; - - @Override - public boolean checkSkip() { - if (runOnce) { - - // compute the unique key refering to parameters of plugin - - StringBuilder buffer = new StringBuilder("check-central-safe##"); - buffer.append(project.getArtifactId()); - - // check if plugin was already done. - - String key = buffer.toString(); - - if (verbose) { - getLog().info("check if already done for key : " + key); - } - Object value = project.getProperties().get(key); - if (value != null) { - // ok was already done - getLog().info("Goal was already executed, will skip goal."); - return false; - } - long timestamp = System.nanoTime(); - project.getProperties().put(key, timestamp + ""); - if (verbose) { - getLog().info("Adding cache key " + key + - " with timestamp " + timestamp); - } - } - return true; - } - - @Override - public void init() throws Exception { - - Log log = getLog(); - - if (log.isDebugEnabled()) { - - // always be verbose in debug mode - setVerbose(true); - } - - safeRepositories = new ArrayList<ArtifactRepository>(); - - ArtifactRepositoryLayout repositoryLayout = new DefaultRepositoryLayout(); - - List<String> ids = new ArrayList<String>(extraRepositories.keySet()); - ids.add(0, "central"); - extraRepositories.put("central", "http://repo1.maven.org/maven2/"); - - for (String id : ids) { - String url = extraRepositories.get(id); - url = url.trim(); - - ArtifactRepository remoteRepo = artifactRepositoryFactory.createDeploymentArtifactRepository( - String.valueOf(id), - url, - repositoryLayout, true); - - log.info("Will use Repository " + remoteRepo.getUrl()); - safeRepositories.add(remoteRepo); - } - - // resolve also plugins - artifacts.addAll(project.getPluginArtifacts()); - - for (Iterator<?> iterator = artifacts.iterator(); iterator.hasNext();) { - Artifact artifact = (Artifact) iterator.next(); - - if (artifact.isSnapshot()) { - - log.warn("Remove snapshot dependency : " + artifact); - iterator.remove(); - } - - if (project.getArtifactId().equals(artifact.getArtifactId()) && - project.getGroupId().equals(artifact.getGroupId()) && - project.getVersion().equals(artifact.getVersion())) { - - if (log.isDebugEnabled()) { - log.debug("Skip artifact of the project : " + artifact); - } - iterator.remove(); - continue; - } - - // let says the artifact is NOT resolved - artifact.setResolved(false); - } - - if (isVerbose()) { - log.info("Detected artifacts : "); - for (Object artifact : artifacts) { - log.info(" - " + artifact); - - } - } - } - - @Override - protected void doAction() throws Exception { - - Log log = getLog(); - - checkDependenciesOnCentral(); - - boolean safe = artifacts.isEmpty(); - - if (safe) { - log.info("All dependencies are central safe."); - return; - } - - log.warn("There is " + artifacts.size() + " none central safe dependencie(s) :"); - for (Object artifact : artifacts) { - log.warn(" - " + artifact); - } - if (failIfNotSafe) { - throw new MojoFailureException("There is still some none central safe artifacts"); - } - } - - protected void checkDependenciesOnCentral() throws Exception { - - Log log = getLog(); - - for (ArtifactRepository repository : safeRepositories) { - - Wagon wagon = getWagon(repository); - try { - if (verbose) { - log.info("Will use repository " + repository.getUrl()); - } - - for (Iterator<?> itr = artifacts.iterator(); itr.hasNext();) { - Artifact artifact = (Artifact) itr.next(); - - if (verbose) { - log.info("check artifact : " + artifact); - } - - boolean resolved = - dependencyExistsInRepo(wagon, repository, artifact); - - if (resolved) { - artifact.setResolved(true); - - itr.remove(); - log.info(artifact + " resolved by " + repository.getUrl()); - } else { - if (log.isDebugEnabled()) { - log.debug("artifact was not resolved by " + repository.getUrl()); - } - } - } - } finally { - if (log.isDebugEnabled()) { - log.debug("Will disconnect wagon : " + wagon); - } - disconnect(wagon); - } - } - } - - @Override - public MavenProject getProject() { - return project; - } - - @Override - public void setProject(MavenProject project) { - this.project = project; - } - - @Override - public boolean isVerbose() { - return verbose; - } - - @Override - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - public void setRunOnce(boolean runOnce) { - this.runOnce = runOnce; - } - - protected boolean dependencyExistsInRepo(Wagon wagon, - ArtifactRepository repo, - Artifact artifact) { - - Log log = getLog(); - - if (!artifact.isSnapshot()) { - } - try { - - Artifact copyArtifact = ArtifactUtils.copyArtifact(artifact); - - String path = repo.getUrl() + "/" + repo.pathOf(copyArtifact); - - return wagon.resourceExists(StringUtils.replace(path, repo.getUrl(), "")); - } catch (TransferFailedException e) { - if (log.isDebugEnabled()) { - log.error("Unable to determine if resource " + artifact + " exists in " + repo.getUrl(), e); - } else { - log.error("Unable to determine if resource " + artifact + " exists in " + repo.getUrl()); - } - return false; - } catch (AuthorizationException e) { - if (log.isDebugEnabled()) { - log.error("Unable to connect to: " + repo.getUrl(), e); - } else { - log.error("Unable to connect to: " + repo.getUrl()); - } - return false; - } catch (AbstractMethodError e) { - log.error("Wagon " + wagon.getClass().getName() + " does not support the resourceExists method"); - return false; - } finally { - disconnect(wagon); - } - } - - - protected Wagon getWagon(ArtifactRepository repo) throws WagonConfigurationException, UnsupportedProtocolException, AuthenticationException, ConnectionException { - - Repository repository = new Repository(repo.getId(), repo.getUrl()); - Wagon wagon = wagonManager.getWagon(repository); - - wagon.setTimeout(1000); - - if (getLog().isDebugEnabled()) { - Debug debug = new Debug(); - - wagon.addSessionListener(debug); - wagon.addTransferListener(debug); - } - - // FIXME when upgrading to maven 3.x : this must be changed. - AuthenticationInfo auth = wagonManager.getAuthenticationInfo(repo.getId()); - - ProxyInfo proxyInfo = getProxyInfo(); - if (proxyInfo != null) { - wagon.connect(repository, auth, proxyInfo); - } else { - wagon.connect(repository, auth); - } - - return wagon; - } - - protected void disconnect(Wagon wagon) { - try { - wagon.disconnect(); - } - catch (ConnectionException e) { - Log log = getLog(); - if (log.isDebugEnabled()) { - log.error("Error disconnecting wagon - ignored", e); - } else { - log.error("Error disconnecting wagon - ignored"); - } - } - } - - /** - * Convenience method to map a <code>Proxy</code> object from the user system settings to a <code>ProxyInfo</code> - * object. - * - * @return a proxyInfo object instanced or null if no active proxy is define in the settings.xml - */ - private ProxyInfo getProxyInfo() { - ProxyInfo proxyInfo = null; - if (proxy != null && !StringUtils.isEmpty(proxy.getHost())) { - - proxyInfo = new ProxyInfo(); - proxyInfo.setHost(proxy.getHost()); - proxyInfo.setType(proxy.getProtocol()); - proxyInfo.setPort(proxy.getPort()); - proxyInfo.setNonProxyHosts(proxy.getNonProxyHosts()); - proxyInfo.setUserName(proxy.getUsername()); - proxyInfo.setPassword(proxy.getPassword()); - } - - return proxyInfo; - } - -} \ No newline at end of file