Author: mfortun Date: 2011-08-19 10:22:52 +0200 (Fri, 19 Aug 2011) New Revision: 1177 Url: http://nuiton.org/repositories/revision/wikitty/1177 Log: *deploy jar completed, thanks to tchemit Added: trunk/wp-maven-plugin/src/it/ trunk/wp-maven-plugin/src/it/deploy-jar/ trunk/wp-maven-plugin/src/it/deploy-jar/file/ trunk/wp-maven-plugin/src/it/deploy-jar/file/invoker.properties trunk/wp-maven-plugin/src/it/deploy-jar/file/pom.xml trunk/wp-maven-plugin/src/it/deploy-jar/file/verify.groovy trunk/wp-maven-plugin/src/it/settings.xml Removed: trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/DeployUtil.java Modified: trunk/wp-maven-plugin/pom.xml trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/WPDeployJarMojo.java Modified: trunk/wp-maven-plugin/pom.xml =================================================================== --- trunk/wp-maven-plugin/pom.xml 2011-08-18 16:20:39 UTC (rev 1176) +++ trunk/wp-maven-plugin/pom.xml 2011-08-19 08:22:52 UTC (rev 1177) @@ -188,8 +188,8 @@ <id>run-its</id> <activation> <property> - <name>performRelease</name> - <value>true</value> + <name>maven.test.skip</name> + <value>!true</value> </property> </activation> <build> @@ -199,8 +199,12 @@ <artifactId>maven-invoker-plugin</artifactId> <configuration> <postBuildHookScript>verify</postBuildHookScript> - <localRepositoryPath>${basedir}/target/local-repo + <localRepositoryPath> + ${basedir}/target/local-repo </localRepositoryPath> + <pomIncludes> + <include>deploy-jar/*/pom.xml</include> + </pomIncludes> <settingsFile>src/it/settings.xml</settingsFile> <cloneProjectsTo>${project.build.directory}/its</cloneProjectsTo> <debug>${maven.verbose}</debug> Added: trunk/wp-maven-plugin/src/it/deploy-jar/file/invoker.properties =================================================================== --- trunk/wp-maven-plugin/src/it/deploy-jar/file/invoker.properties (rev 0) +++ trunk/wp-maven-plugin/src/it/deploy-jar/file/invoker.properties 2011-08-19 08:22:52 UTC (rev 1177) @@ -0,0 +1,7 @@ + +# A comma or space separated list of goals/phases to execute, may +# specify an empty list to execute the default goal of the IT project +invoker.goals=clean verify + +# Possible values are "fail-fast" (default), "fail-at-end" and "fail-never" +invoker.failureBehavior=fail-at-end Added: trunk/wp-maven-plugin/src/it/deploy-jar/file/pom.xml =================================================================== --- trunk/wp-maven-plugin/src/it/deploy-jar/file/pom.xml (rev 0) +++ trunk/wp-maven-plugin/src/it/deploy-jar/file/pom.xml 2011-08-19 08:22:52 UTC (rev 1177) @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> + + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <groupId>org.nuiton.wikitty.plugin.test</groupId> + <artifactId>deploy-jar-file</artifactId> + <version>1.0</version> + + <properties> + + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + + </properties> + + <build> + + <pluginManagement> + <plugins> + <plugin> + <groupId>org.nuiton.wikitty</groupId> + <artifactId>wp-maven-plugin</artifactId> + <version>@pom.version@</version> + </plugin> + </plugins> + </pluginManagement> + + <plugins> + <plugin> + <groupId>org.nuiton.wikitty</groupId> + <artifactId>wp-maven-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>deploy-jar</goal> + </goals> + <phase>verify</phase> + <configuration> + <applicationName>test</applicationName> + <wikittyServiceUrl>?</wikittyServiceUrl> + <serverId>serverFile</serverId> + <serverUrl>file://${basedir}/target/remote</serverUrl> + <fileToDeploy> + ${basedir}/target/${project.artifactId}-${project.version}.jar + </fileToDeploy> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> + + Added: trunk/wp-maven-plugin/src/it/deploy-jar/file/verify.groovy =================================================================== --- trunk/wp-maven-plugin/src/it/deploy-jar/file/verify.groovy (rev 0) +++ trunk/wp-maven-plugin/src/it/deploy-jar/file/verify.groovy 2011-08-19 08:22:52 UTC (rev 1177) @@ -0,0 +1,6 @@ + + +file = new File(basedir, 'target/remote/deploy-jar-file-1.0.jar'); +assert file.exists(); + +return true; Added: trunk/wp-maven-plugin/src/it/settings.xml =================================================================== --- trunk/wp-maven-plugin/src/it/settings.xml (rev 0) +++ trunk/wp-maven-plugin/src/it/settings.xml 2011-08-19 08:22:52 UTC (rev 1177) @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> + + + +<settings> + + <servers> + <server> + <id>serverFile</id> + <username>tony</username> + </server> + </servers> + + <profiles> + <profile> + <id>it-repo</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <repositories> + <repository> + <id>local.central</id> + <url>file:///@localRepository@</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> + </repositories> + <pluginRepositories> + <pluginRepository> + <id>local.central</id> + <url>file:///@localRepository@</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </pluginRepository> + </pluginRepositories> + </profile> + </profiles> + + <pluginGroups> + <pluginGroup>org.codehaus.mojo</pluginGroup> + </pluginGroups> +</settings> Deleted: trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/DeployUtil.java =================================================================== --- trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/DeployUtil.java 2011-08-18 16:20:39 UTC (rev 1176) +++ trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/DeployUtil.java 2011-08-19 08:22:52 UTC (rev 1177) @@ -1,811 +0,0 @@ -package org.nuiton.wikitty.plugin; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.List; -import java.util.Locale; -import java.util.Set; - -import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.model.DistributionManagement; -import org.apache.maven.model.Site; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.logging.Log; - -import org.apache.maven.project.MavenProject; -import org.apache.maven.settings.Proxy; -import org.apache.maven.settings.Server; -import org.apache.maven.settings.Settings; -import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest; -import org.apache.maven.settings.crypto.SettingsDecrypter; -import org.apache.maven.settings.crypto.SettingsDecryptionResult; -import org.apache.maven.wagon.CommandExecutionException; -import org.apache.maven.wagon.CommandExecutor; -import org.apache.maven.wagon.ConnectionException; -import org.apache.maven.wagon.ResourceDoesNotExistException; -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.PlexusConstants; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.configurator.ComponentConfigurationException; -import org.codehaus.plexus.component.configurator.ComponentConfigurator; -import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.codehaus.plexus.configuration.PlexusConfiguration; -import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; -import org.codehaus.plexus.context.Context; -import org.codehaus.plexus.context.ContextException; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.xml.Xpp3Dom; - - - -public class DeployUtil { - /* *//** - * Directory containing the generated project sites and report distributions. - * - * @parameter alias="outputDirectory" expression="${project.reporting.outputDirectory}" - * @required - *//* - private File inputDirectory; - - *//** - * Whether to run the "chmod" command on the remote site after the deploy. - * Defaults to "true". - * - * @parameter expression="${maven.site.chmod}" default-value="true" - * @since 2.1 - *//* - private boolean chmod; - - *//** - * The mode used by the "chmod" command. Only used if chmod = true. - * Defaults to "g+w,a+rX". - * - * @parameter expression="${maven.site.chmod.mode}" default-value="g+w,a+rX" - * @since 2.1 - *//* - private String chmodMode; - - *//** - * The options used by the "chmod" command. Only used if chmod = true. - * Defaults to "-Rf". - * - * @parameter expression="${maven.site.chmod.options}" default-value="-Rf" - * @since 2.1 - *//* - private String chmodOptions; - - *//** - * Set this to 'true' to skip site deployment. - * - * @parameter expression="${maven.site.deploy.skip}" default-value="false" - * @since 3.0 - *//* - private boolean skipDeploy; - - *//** - * @component - *//* - private WagonManager wagonManager; - - *//** - * The current user system settings for use in Maven. - * - * @parameter expression="${settings}" - * @required - * @readonly - *//* - private Settings settings; - - *//** - * @parameter expression="${session}" - * @required - * @readonly - * @since 3.0-beta-2 - *//* - protected MavenSession mavenSession; - - private PlexusContainer container; - - private String deployRepositoryID; - - private String deployRepositoryUrl; - - private Log log; - - *//** - * The String "staging/". - *//* - protected static final String DEFAULT_STAGING_DIRECTORY = "staging/"; - - *//** {@inheritDoc} *//* - public void execute() - throws MojoExecutionException - { - if ( skipDeploy ) - { - getLog().info( "maven.site.deploy.skip = true: Skipping site deployment" ); - return; - } - - deployTo( new org.apache.maven.plugins.site.wagon.repository.Repository( - getDeployRepositoryID(), - appendSlash( getDeployRepositoryURL() ) ) ); - } - - public Log getLog() { - return log; - - } - - *//** - * Make sure the given url ends with a slash. - * - * @param url a String. - * - * @return if url already ends with '/' it is returned unchanged, - * otherwise a '/' character is appended. - *//* - protected static String appendSlash( final String url ) - { - if ( url.endsWith( "/" ) ) - { - return url; - } - else - { - return url + "/"; - } - } - - *//** - * Specifies the id to look up credential settings. - * - * @return the id to look up credentials for the deploy. Not null. - * - * @throws MojoExecutionException - * if the ID cannot be determined - *//* - protected String getDeployRepositoryID() - throws MojoExecutionException{ - return deployRepositoryID; - } - - *//** - * Specifies the target URL for the deploy. - * This should be the top-level URL, ie above modules and locale sub-directories. - * - * @return the url to deploy to. Not null. - * - * @throws MojoExecutionException - * if the URL cannot be constructed - *//* - protected String getDeployRepositoryURL() - throws MojoExecutionException{ - return deployRepositoryUrl; - } - - *//** - * Find the relative path between the distribution URLs of the top parent and the current project. - * - * @return the relative path or "./" if the two URLs are the same. - * - * @throws MojoExecutionException - *//* - private String getDeployModuleDirectory() - throws MojoExecutionException - { - String relative = siteTool.getRelativePath( getSite( project ).getUrl(), - getRootSite( project ).getUrl() ); - - // SiteTool.getRelativePath() uses File.separatorChar, - // so we need to convert '\' to '/' in order for the URL to be valid for Windows users - relative = relative.replace( '\\', '/' ); - - return ( "".equals( relative ) ) ? "./" : relative; - } - - *//** - * Use wagon to deploy the generated site to a given repository. - * - * @param repository the repository to deply to. - * This needs to contain a valid, non-null {@link Repository#getId() id} - * to look up credentials for the deploy, and a valid, non-null - * {@link Repository#getUrl() scm url} to deploy to. - * - * @throws MojoExecutionException if the deploy fails. - *//* - private void deployTo( final Repository repository ) - throws MojoExecutionException - { - if ( !inputDirectory.exists() ) - { - throw new MojoExecutionException( "The site does not exist, please run site:site first" ); - } - - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "Deploying to '" + repository.getUrl() - + "',\n Using credentials from server id '" + repository.getId() + "'" ); - } - - deploy( inputDirectory, repository ); - } - - private void deploy( final File directory, final Repository repository ) - throws MojoExecutionException - { - // TODO: work on moving this into the deployer like the other deploy methods - final Wagon wagon = getWagon( repository, wagonManager ); - - try - { - configureWagon( wagon, repository.getId(), settings, container, getLog() ); - } - catch ( TransferFailedException e ) - { - throw new MojoExecutionException( "Unable to configure Wagon: '" + repository.getProtocol() + "'", e ); - } - - try - { - final ProxyInfo proxyInfo; - if ( !isMaven3OrMore() ) - { - proxyInfo = getProxyInfo( repository, wagonManager ); - } - else - { - try - { - SettingsDecrypter settingsDecrypter = container.lookup( SettingsDecrypter.class ); - - proxyInfo = getProxy( repository, settingsDecrypter ); - } - catch ( ComponentLookupException cle ) - { - throw new MojoExecutionException( "Unable to lookup SettingsDecrypter: " + cle.getMessage(), cle ); - } - } - - push( directory, repository, wagon, proxyInfo, siteTool.getAvailableLocales( locales ), - getDeployModuleDirectory() ); - - if ( chmod ) - { - chmod( wagon, repository, chmodOptions, chmodMode ); - } - } - finally - { - try - { - wagon.disconnect(); - } - catch ( ConnectionException e ) - { - getLog().error( "Error disconnecting wagon - ignored", e ); - } - } - } - - *//** - * Find the build directory of the top level project in the reactor. - * If no top level project is found, the build directory of the current project is returned. - * - * @return the build directory of the top level project. - *//* - protected File getTopLevelBuildDirectory() - { - // Find the top level project in the reactor - final MavenProject topLevelProject = getTopLevelProject( reactorProjects ); - - // Use the top level project's build directory if there is one, otherwise use this project's build directory - final File buildDirectory; - - if ( topLevelProject == null ) - { - getLog().debug( "No top level project found in the reactor, using the current project." ); - - buildDirectory = new File( project.getBuild().getDirectory() ); - } - else - { - getLog().debug( "Using the top level project found in the reactor." ); - - buildDirectory = new File( topLevelProject.getBuild().getDirectory() ); - } - - return buildDirectory; - } - - private Wagon getWagon( final Repository repository, final WagonManager manager ) - throws MojoExecutionException - { - final Wagon wagon; - - try - { - wagon = manager.getWagon( repository ); - } - catch ( UnsupportedProtocolException e ) - { - String shortMessage = - "Unsupported protocol: '" + repository.getProtocol() + "' for site deployment to " - + "distributionManagement.site.url=" + repository.getUrl() + "."; - String longMessage = - "\n" + shortMessage + "\n" + - "Currently supported protocols are: " + getSupportedProtocols() + ".\n" - + " Protocols may be added through wagon providers.\n" - + " For more information, see " - + "http://maven.apache.org/plugins/maven-site-plugin/examples/adding-deploy-pro..."; - - getLog().error( longMessage ); - - throw new MojoExecutionException( shortMessage ); - } - catch ( TransferFailedException e ) - { - throw new MojoExecutionException( "Unable to configure Wagon: '" + repository.getProtocol() + "'", e ); - } - - if ( !wagon.supportsDirectoryCopy() ) - { - throw new MojoExecutionException( - "Wagon protocol '" + repository.getProtocol() + "' doesn't support directory copying" ); - } - - return wagon; - } - - private String getSupportedProtocols() - { - try - { - Set<String> protocols = container.lookupMap( Wagon.class ).keySet(); - - return StringUtils.join( protocols.iterator(), ", " ); - } - catch ( ComponentLookupException e ) - { - // in the unexpected case there is a problem when instantiating a wagon provider - getLog().error( e ); - } - return ""; - } - - private void push( final File inputDirectory, final Repository repository, final Wagon wagon, - final ProxyInfo proxyInfo, final List<Locale> localesList, final String relativeDir ) - throws MojoExecutionException - { - AuthenticationInfo authenticationInfo = wagonManager.getAuthenticationInfo( repository.getId() ); - getLog().debug( "authenticationInfo with id '" + repository.getId() + "': " - + ( ( authenticationInfo == null ) ? "-" : authenticationInfo.getUserName() ) ); - - try - { - Debug debug = new Debug(); - - wagon.addSessionListener( debug ); - - wagon.addTransferListener( debug ); - - if ( proxyInfo != null ) - { - getLog().debug( "connect with proxyInfo" ); - wagon.connect( repository, authenticationInfo, proxyInfo ); - } - else if ( proxyInfo == null && authenticationInfo != null ) - { - getLog().debug( "connect with authenticationInfo and without proxyInfo" ); - wagon.connect( repository, authenticationInfo ); - } - else - { - getLog().debug( "connect without authenticationInfo and without proxyInfo" ); - wagon.connect( repository ); - } - - getLog().info( "Pushing " + inputDirectory ); - - // Default is first in the list - final String defaultLocale = localesList.get( 0 ).getLanguage(); - - for ( Locale locale : localesList ) - { - if ( locale.getLanguage().equals( defaultLocale ) ) - { - // TODO: this also uploads the non-default locales, - // is there a way to exclude directories in wagon? - getLog().info( " >>> to " + repository.getUrl() + relativeDir ); - - wagon.putDirectory( inputDirectory, relativeDir ); - } - else - { - getLog().info( " >>> to " + repository.getUrl() + locale.getLanguage() + "/" + relativeDir ); - - wagon.putDirectory( new File( inputDirectory, locale.getLanguage() ), - locale.getLanguage() + "/" + relativeDir ); - } - } - } - catch ( ResourceDoesNotExistException e ) - { - throw new MojoExecutionException( "Error uploading site", e ); - } - catch ( TransferFailedException e ) - { - throw new MojoExecutionException( "Error uploading site", e ); - } - catch ( AuthorizationException e ) - { - throw new MojoExecutionException( "Error uploading site", e ); - } - catch ( ConnectionException e ) - { - throw new MojoExecutionException( "Error uploading site", e ); - } - catch ( AuthenticationException e ) - { - throw new MojoExecutionException( "Error uploading site", e ); - } - } - - private static void chmod( final Wagon wagon, final Repository repository, final String chmodOptions, - final String chmodMode ) - throws MojoExecutionException - { - try - { - if ( wagon instanceof CommandExecutor ) - { - CommandExecutor exec = (CommandExecutor) wagon; - exec.executeCommand( "chmod " + chmodOptions + " " + chmodMode + " " + repository.getBasedir() ); - } - // else ? silently ignore, FileWagon is not a CommandExecutor! - } - catch ( CommandExecutionException e ) - { - throw new MojoExecutionException( "Error uploading site", e ); - } - } - - *//** - * <p> - * Get the <code>ProxyInfo</code> of the proxy associated with the <code>host</code> - * and the <code>protocol</code> of the given <code>repository</code>. - * </p> - * <p> - * Extract from <a href="http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html"> - * J2SE Doc : Networking Properties - nonProxyHosts</a> : "The value can be a list of hosts, - * each separated by a |, and in addition a wildcard character (*) can be used for matching" - * </p> - * <p> - * Defensively support for comma (",") and semi colon (";") in addition to pipe ("|") as separator. - * </p> - * - * @param repository the Repository to extract the ProxyInfo from. - * @param wagonManager the WagonManager used to connect to the Repository. - * @return a ProxyInfo object instantiated or <code>null</code> if no matching proxy is found - *//* - public static ProxyInfo getProxyInfo( Repository repository, WagonManager wagonManager ) - { - ProxyInfo proxyInfo = wagonManager.getProxy( repository.getProtocol() ); - - if ( proxyInfo == null ) - { - return null; - } - - String host = repository.getHost(); - String nonProxyHostsAsString = proxyInfo.getNonProxyHosts(); - String[] nonProxyHosts = StringUtils.split( nonProxyHostsAsString, ",;|" ); - for ( int i = 0; i < nonProxyHosts.length; i++ ) - { - String nonProxyHost = nonProxyHosts[i]; - if ( StringUtils.contains( nonProxyHost, "*" ) ) - { - // Handle wildcard at the end, beginning or middle of the nonProxyHost - final int pos = nonProxyHost.indexOf( '*' ); - String nonProxyHostPrefix = nonProxyHost.substring( 0, pos ); - String nonProxyHostSuffix = nonProxyHost.substring( pos + 1 ); - // prefix* - if ( StringUtils.isNotEmpty( nonProxyHostPrefix ) && host.startsWith( nonProxyHostPrefix ) - && StringUtils.isEmpty( nonProxyHostSuffix ) ) - { - return null; - } - // *suffix - if ( StringUtils.isEmpty( nonProxyHostPrefix ) - && StringUtils.isNotEmpty( nonProxyHostSuffix ) && host.endsWith( nonProxyHostSuffix ) ) - { - return null; - } - // prefix*suffix - if ( StringUtils.isNotEmpty( nonProxyHostPrefix ) && host.startsWith( nonProxyHostPrefix ) - && StringUtils.isNotEmpty( nonProxyHostSuffix ) && host.endsWith( nonProxyHostSuffix ) ) - { - return null; - } - } - else if ( host.equals( nonProxyHost ) ) - { - return null; - } - } - return proxyInfo; - } - - *//** - * Get proxy information for Maven 3. - * - * @param repository - * @param log - * @param mavenSession - * @param settingsDecrypter - * @return - *//* - private ProxyInfo getProxy( Repository repository, SettingsDecrypter settingsDecrypter ) - { - String protocol = repository.getProtocol(); - String url = repository.getUrl(); - - getLog().debug( "repository protocol " + protocol ); - - String originalProtocol = protocol; - // olamy: hackish here protocol (wagon hint in fact !) is dav - // but the real protocol (transport layer) is http(s) - // and it's the one use in wagon to find the proxy arghhh - // so we will check both - if ( StringUtils.equalsIgnoreCase( "dav", protocol ) && url.startsWith( "dav:" ) ) - { - url = url.substring( 4 ); - if ( url.startsWith( "http" ) ) - { - try - { - URL urlSite = new URL( url ); - protocol = urlSite.getProtocol(); - getLog().debug( "found dav protocol so transform to real transport protocol " + protocol ); - } - catch ( MalformedURLException e ) - { - getLog().warn( "fail to build URL with " + url ); - } - - } - } - else - { - getLog().debug( "getProxy 'protocol': " + protocol ); - } - if ( mavenSession != null && protocol != null ) - { - MavenExecutionRequest request = mavenSession.getRequest(); - - if ( request != null ) - { - List<Proxy> proxies = request.getProxies(); - - if ( proxies != null ) - { - for ( Proxy proxy : proxies ) - { - if ( proxy.isActive() - && ( protocol.equalsIgnoreCase( proxy.getProtocol() ) || originalProtocol - .equalsIgnoreCase( proxy.getProtocol() ) ) ) - { - SettingsDecryptionResult result = settingsDecrypter - .decrypt( new DefaultSettingsDecryptionRequest( proxy ) ); - proxy = result.getProxy(); - - ProxyInfo proxyInfo = new ProxyInfo(); - proxyInfo.setHost( proxy.getHost() ); - // so hackish for wagon the protocol is https for site dav : dav:https://dav.codehaus.org/mojo/ - proxyInfo.setType( protocol );//proxy.getProtocol() ); - proxyInfo.setPort( proxy.getPort() ); - proxyInfo.setNonProxyHosts( proxy.getNonProxyHosts() ); - proxyInfo.setUserName( proxy.getUsername() ); - proxyInfo.setPassword( proxy.getPassword() ); - - getLog().debug( "found proxyInfo " - + ( proxyInfo == null ? "null" : "host:port " + proxyInfo.getHost() - + ":" + proxyInfo.getPort() + ", " + proxyInfo.getUserName() ) ); - - return proxyInfo; - } - } - } - } - } - getLog().debug( "getProxy 'protocol': " + protocol + " no ProxyInfo found"); - return null; - } - - *//** - * Configure the Wagon with the information from serverConfigurationMap ( which comes from settings.xml ) - * - * @todo Remove when {@link WagonManager#getWagon(Repository) is available}. It's available in Maven 2.0.5. - * @param wagon - * @param repositoryId - * @param settings - * @param container - * @param log - * @throws WagonConfigurationException - *//* - private static void configureWagon( Wagon wagon, String repositoryId, Settings settings, PlexusContainer container, - Log log ) - throws TransferFailedException - { - log.debug( " configureWagon " ); - - // MSITE-25: Make sure that the server settings are inserted - for ( int i = 0; i < settings.getServers().size(); i++ ) - { - Server server = settings.getServers().get( i ); - String id = server.getId(); - - log.debug( "configureWagon server " + id ); - - if ( id != null && id.equals( repositoryId ) ) - { - if ( server.getConfiguration() != null ) - { - final PlexusConfiguration plexusConf = - new XmlPlexusConfiguration( (Xpp3Dom) server.getConfiguration() ); - - ComponentConfigurator componentConfigurator = null; - try - { - componentConfigurator = (ComponentConfigurator) container.lookup( ComponentConfigurator.ROLE, "basic" ); - componentConfigurator.configureComponent( wagon, plexusConf, container.getContainerRealm() ); - } - catch ( final ComponentLookupException e ) - { - throw new TransferFailedException( "While configuring wagon for \'" + repositoryId - + "\': Unable to lookup wagon configurator." + " Wagon configuration cannot be applied.", e ); - } - catch ( ComponentConfigurationException e ) - { - throw new TransferFailedException( "While configuring wagon for \'" + repositoryId - + "\': Unable to apply wagon configuration.", e ); - } - finally - { - if ( componentConfigurator != null ) - { - try - { - container.release( componentConfigurator ); - } - catch ( ComponentLifecycleException e ) - { - log.error( "Problem releasing configurator - ignoring: " + e.getMessage() ); - } - } - } - } - } - } - } - - *//** {@inheritDoc} *//* - public void contextualize( Context context ) - throws ContextException - { - container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); - } - - *//** - * Find the top level parent in the reactor, i.e. the execution root. - * - * @param reactorProjects The projects in the reactor. May be null in which case null is returned. - * - * @return The top level project in the reactor, or <code>null</code> if none can be found - *//* - private static MavenProject getTopLevelProject( List<MavenProject> reactorProjects ) - { - if ( reactorProjects == null ) - { - return null; - } - - for ( MavenProject reactorProject : reactorProjects ) - { - if ( reactorProject.isExecutionRoot() ) - { - return reactorProject; - } - } - - return null; - } - - *//** - * Extract the distributionManagment site from the given MavenProject. - * - * @param project the MavenProject. Not null. - * - * @return the project site. Not null. - * Also site.getUrl() and site.getId() are guaranteed to be not null. - * - * @throws MojoExecutionException if any of the site info is missing. - *//* - protected static Site getSite( final MavenProject project ) - throws MojoExecutionException - { - final String name = project.getName() + " (" - + project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion() + ")"; - - final DistributionManagement distributionManagement = project.getDistributionManagement(); - - if ( distributionManagement == null ) - { - throw new MojoExecutionException( "Missing distribution management in project " + name ); - } - - final Site site = distributionManagement.getSite(); - - if ( site == null ) - { - throw new MojoExecutionException( - "Missing site information in the distribution management of the project " + name ); - } - - if ( site.getUrl() == null || site.getId() == null ) - { - throw new MojoExecutionException( "Missing site data: specify url and id for project " + name ); - } - - return site; - } - - *//** - * Extract the distributionManagment site of the top level parent of the given MavenProject. - * This climbs up the project hierarchy and returns the site of the last project - * for which {@link #getSite(org.apache.maven.project.MavenProject)} returns a site. - * - * @param project the MavenProject. Not null. - * - * @return the top level site. Not null. - * Also site.getUrl() and site.getId() are guaranteed to be not null. - * - * @throws MojoExecutionException if no site info is found in the tree. - *//* - protected Site getRootSite( MavenProject project ) - throws MojoExecutionException - { - Site site = getSite( project ); - - MavenProject parent = project; - - while ( parent.getParent() != null ) - { - // MSITE-585, MNG-1943 - parent = siteTool.getParentProject( parent, reactorProjects, localRepository ); - - try - { - site = getSite( parent ); - } - catch ( MojoExecutionException e ) - { - break; - } - } - - return site; - }*/ -} Modified: trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/WPDeployJarMojo.java =================================================================== --- trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/WPDeployJarMojo.java 2011-08-18 16:20:39 UTC (rev 1176) +++ trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/WPDeployJarMojo.java 2011-08-19 08:22:52 UTC (rev 1177) @@ -24,37 +24,59 @@ */ package org.nuiton.wikitty.plugin; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.List; - +import org.apache.maven.artifact.manager.WagonConfigurationException; import org.apache.maven.artifact.manager.WagonManager; +import org.apache.maven.artifact.versioning.ComparableVersion; import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.site.AbstractSiteMojo; -import org.apache.maven.plugins.site.SiteDeployMojo; -import org.apache.maven.plugins.site.SiteMojo; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugins.site.wagon.repository.Repository; +import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Proxy; +import org.apache.maven.settings.Server; import org.apache.maven.settings.Settings; import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest; import org.apache.maven.settings.crypto.SettingsDecrypter; import org.apache.maven.settings.crypto.SettingsDecryptionResult; +import org.apache.maven.wagon.CommandExecutionException; +import org.apache.maven.wagon.CommandExecutor; import org.apache.maven.wagon.ConnectionException; +import org.apache.maven.wagon.ResourceDoesNotExistException; 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.PlexusConstants; import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.component.configurator.ComponentConfigurationException; +import org.codehaus.plexus.component.configurator.ComponentConfigurator; +import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.configuration.PlexusConfiguration; +import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; +import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + /** * To deploy a wikitty publication jar. * @@ -66,14 +88,60 @@ * @requiresDependencyResolution runtime * @since 3.2 */ -public class WPDeployJarMojo extends AbstractWPMojo { - // implements Contextualizable - protected String uploadUrl; - protected String serveurID; - +public class WPDeployJarMojo extends AbstractWPMojo implements Contextualizable { + /** - * @component + * Id of server. + * + * @parameter expression="${serverId}" + * @required */ + protected String serverId; + + /** + * URL of server to use to log into server. + * + * @parameter expression="${serverUrl}" + * @required + */ + protected String serverUrl; + + /** + * File to deploy. + * + * @parameter expression="${fileToDeploy}" + * @required + */ + protected File fileToDeploy; + + /** + * Whether to run the "chmod" command on the remote site after the deploy. + * Defaults to "true". + * + * @parameter expression="${maven.site.chmod}" default-value="true" + * @since 2.1 + */ + private boolean chmod; + + /** + * The mode used by the "chmod" command. Only used if chmod = true. + * Defaults to "g+w,a+rX". + * + * @parameter expression="${maven.site.chmod.mode}" default-value="g+w,a+rX" + * @since 2.1 + */ + private String chmodMode; + + /** + * The options used by the "chmod" command. Only used if chmod = true. + * Defaults to "-Rf". + * + * @parameter expression="${maven.site.chmod.options}" default-value="-Rf" + * @since 2.1 + */ + private String chmodOptions; + + /** @component */ private WagonManager wagonManager; /** @@ -85,42 +153,376 @@ */ private Settings settings; + /** + * @parameter expression="${session}" + * @required + * @readonly + * @since 3.0-beta-2 + */ + protected MavenSession mavenSession; private PlexusContainer container; - - + + private Repository repository; + + /** + * All available wagons. + * + * @component role="org.apache.maven.wagon.Wagon" + * @since 1.0 + */ + protected Map<String, Wagon> wagons; + + /** @component */ + private SettingsDecrypter settingsDecrypter; + + private ProxyInfo proxyInfo; + + private Wagon wagon; + @Override protected void init() throws Exception { - //TODO + + repository = new Repository( + serverId, + serverUrl + ); + + if (!fileToDeploy.exists()) { + throw new MojoExecutionException("The file to deploy " + fileToDeploy + " does not exist"); + } + + + if (!isMaven3OrMore()) { + proxyInfo = getProxyInfo(); + } else { + + proxyInfo = getProxy(); + } + + wagon = getWagon(repository, wagonManager); + + try { + configureWagon(wagon, repository.getId(), settings, container, getLog()); + } catch (TransferFailedException e) { + throw new MojoExecutionException("Unable to configure Wagon: '" + repository.getProtocol() + "'", e); + } + } @Override protected void doAction() throws Exception { - - DeployUtil deploy = new DeployUtil(); - - String file = getProject().getBuild().getDirectory(); - file+=File.separator+WPJarMojo.EXTERNALIZE_PREFIX+applicationName+".jar"; - File jarFile= new File(file); - - // SiteDeployMojo - - - /* - - deploy.setFile(jarFile); - deploy.setUrl("localhost:7878"); - deploy.setRepositoryId("bob"); - - - - - - - deploy.execute();*/ + if (getLog().isDebugEnabled()) { + getLog().debug("Deploying to '" + repository.getUrl() + + "',\n Using credentials from server id '" + repository.getId() + "'"); + } + + try { + + AuthenticationInfo authenticationInfo = wagonManager.getAuthenticationInfo(repository.getId()); + getLog().debug("authenticationInfo with id '" + repository.getId() + "': " + + (authenticationInfo == null ? "-" : authenticationInfo.getUserName())); + + try { + Debug debug = new Debug(); + + wagon.addSessionListener(debug); + + wagon.addTransferListener(debug); + + if (proxyInfo != null) { + getLog().debug("connect with proxyInfo"); + wagon.connect(repository, authenticationInfo, proxyInfo); + } else if (authenticationInfo != null) { + getLog().debug("connect with authenticationInfo and without proxyInfo"); + wagon.connect(repository, authenticationInfo); + } else { + getLog().debug("connect without authenticationInfo and without proxyInfo"); + wagon.connect(repository); + } + + getLog().info("Pushing " + fileToDeploy); + + wagon.put(fileToDeploy, fileToDeploy.getName()); + + } catch (ResourceDoesNotExistException e) { + throw new MojoExecutionException("Error uploading site", e); + } catch (TransferFailedException e) { + throw new MojoExecutionException("Error uploading site", e); + } catch (AuthorizationException e) { + throw new MojoExecutionException("Error uploading site", e); + } catch (ConnectionException e) { + throw new MojoExecutionException("Error uploading site", e); + } catch (AuthenticationException e) { + throw new MojoExecutionException("Error uploading site", e); + } + + if (chmod) { + try { + if (wagon instanceof CommandExecutor) { + CommandExecutor exec = (CommandExecutor) wagon; + exec.executeCommand("chmod " + chmodOptions + " " + chmodMode + " " + repository.getBasedir()); + } + // else ? silently ignore, FileWagon is not a CommandExecutor! + } catch (CommandExecutionException e) { + throw new MojoExecutionException("Error uploading site", e); + } + } + } finally { + try { + wagon.disconnect(); + } catch (ConnectionException e) { + getLog().error("Error disconnecting wagon - ignored", e); + } + } + } + protected boolean isMaven3OrMore() { + return new ComparableVersion(getMavenVersion()).compareTo(new ComparableVersion("3.0")) >= 0; + } -} + protected String getMavenVersion() { + // This relies on the fact that MavenProject is the in core classloader + // and that the core classloader is for the maven-core artifact + // and that should have a pom.properties file + // if this ever changes, we will have to revisit this code. + Properties properties = new Properties(); + InputStream in = + MavenProject.class.getClassLoader().getResourceAsStream("META-INF/maven/org.apache.maven/maven-core/pom.properties"); + try { + properties.load(in); + } catch (IOException ioe) { + return ""; + } finally { + IOUtil.close(in); + } + + return properties.getProperty("version").trim(); + } + + private String getSupportedProtocols() { + Set<String> protocols = wagons.keySet(); + + return StringUtils.join(protocols.iterator(), ", "); + } + + /** + * <p> + * Get the <code>ProxyInfo</code> of the proxy associated with the <code>host</code> + * and the <code>protocol</code> of the given <code>repository</code>. + * </p> + * <p> + * Extract from <a href="http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html"> + * J2SE Doc : Networking Properties - nonProxyHosts</a> : "The value can be a list of hosts, + * each separated by a |, and in addition a wildcard character (*) can be used for matching" + * </p> + * <p> + * Defensively support for comma (",") and semi colon (";") in addition to pipe ("|") as separator. + * </p> + * + * @return a ProxyInfo object instantiated or <code>null</code> if no matching proxy is found + */ + public ProxyInfo getProxyInfo() { + + ProxyInfo proxyInfo = wagonManager.getProxy(repository.getProtocol()); + + if (proxyInfo == null) { + return null; + } + + String host = repository.getHost(); + String nonProxyHostsAsString = proxyInfo.getNonProxyHosts(); + String[] nonProxyHosts = StringUtils.split(nonProxyHostsAsString, ",;|"); + for (int i = 0; i < nonProxyHosts.length; i++) { + String nonProxyHost = nonProxyHosts[i]; + if (StringUtils.contains(nonProxyHost, "*")) { + // Handle wildcard at the end, beginning or middle of the nonProxyHost + int pos = nonProxyHost.indexOf('*'); + String nonProxyHostPrefix = nonProxyHost.substring(0, pos); + String nonProxyHostSuffix = nonProxyHost.substring(pos + 1); + // prefix* + if (StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix) + && StringUtils.isEmpty(nonProxyHostSuffix)) { + return null; + } + // *suffix + if (StringUtils.isEmpty(nonProxyHostPrefix) + && StringUtils.isNotEmpty(nonProxyHostSuffix) && host.endsWith(nonProxyHostSuffix)) { + return null; + } + // prefix*suffix + if (StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix) + && StringUtils.isNotEmpty(nonProxyHostSuffix) && host.endsWith(nonProxyHostSuffix)) { + return null; + } + } else if (host.equals(nonProxyHost)) { + return null; + } + } + return proxyInfo; + } + + /** + * Get proxy information for Maven 3. + * + * @return + */ + private ProxyInfo getProxy() { + String protocol = repository.getProtocol(); + String url = repository.getUrl(); + + getLog().debug("repository protocol " + protocol); + + String originalProtocol = protocol; + // olamy: hackish here protocol (wagon hint in fact !) is dav + // but the real protocol (transport layer) is http(s) + // and it's the one use in wagon to find the proxy arghhh + // so we will check both + if (StringUtils.equalsIgnoreCase("dav", protocol) && url.startsWith("dav:")) { + url = url.substring(4); + if (url.startsWith("http")) { + try { + URL urlSite = new URL(url); + protocol = urlSite.getProtocol(); + getLog().debug("found dav protocol so transform to real transport protocol " + protocol); + } catch (MalformedURLException e) { + getLog().warn("fail to build URL with " + url); + } + + } + } else { + getLog().debug("getProxy 'protocol': " + protocol); + } + if (mavenSession != null && protocol != null) { + MavenExecutionRequest request = mavenSession.getRequest(); + + if (request != null) { + List<Proxy> proxies = request.getProxies(); + + if (proxies != null) { + for (Proxy proxy : proxies) { + if (proxy.isActive() + && (protocol.equalsIgnoreCase(proxy.getProtocol()) || originalProtocol + .equalsIgnoreCase(proxy.getProtocol()))) { + SettingsDecryptionResult result = settingsDecrypter + .decrypt(new DefaultSettingsDecryptionRequest(proxy)); + proxy = result.getProxy(); + + ProxyInfo proxyInfo = new ProxyInfo(); + proxyInfo.setHost(proxy.getHost()); + // so hackish for wagon the protocol is https for site dav : dav:https://dav.codehaus.org/mojo/ + proxyInfo.setType(protocol);//proxy.getProtocol() ); + proxyInfo.setPort(proxy.getPort()); + proxyInfo.setNonProxyHosts(proxy.getNonProxyHosts()); + proxyInfo.setUserName(proxy.getUsername()); + proxyInfo.setPassword(proxy.getPassword()); + + getLog().debug("found proxyInfo " + + "host:port " + proxyInfo.getHost() + + ":" + proxyInfo.getPort() + ", " + proxyInfo.getUserName()); + + return proxyInfo; + } + } + } + } + } + getLog().debug("getProxy 'protocol': " + protocol + " no ProxyInfo found"); + return null; + } + + private Wagon getWagon(org.apache.maven.wagon.repository.Repository repository, WagonManager manager) + throws MojoExecutionException { + Wagon wagon; + + try { + wagon = manager.getWagon(repository); + } catch (UnsupportedProtocolException e) { + String shortMessage = + "Unsupported protocol: '" + repository.getProtocol() + "' for site deployment to " + + "distributionManagement.site.url=" + repository.getUrl() + "."; + String longMessage = + "\n" + shortMessage + "\n" + + "Currently supported protocols are: " + getSupportedProtocols() + ".\n" + + " Protocols may be added through wagon providers.\n" + + " For more information, see " + + "http://maven.apache.org/plugins/maven-site-plugin/examples/adding-deploy-pro..."; + + getLog().error(longMessage); + + throw new MojoExecutionException(shortMessage); + } catch (TransferFailedException e) { + throw new MojoExecutionException("Unable to configure Wagon: '" + repository.getProtocol() + "'", e); + } + + if (!wagon.supportsDirectoryCopy()) { + throw new MojoExecutionException( + "Wagon protocol '" + repository.getProtocol() + "' doesn't support directory copying"); + } + + return wagon; + } + + /** + * Configure the Wagon with the information from serverConfigurationMap ( which comes from settings.xml ) + * + * @param wagon + * @param repositoryId + * @param settings + * @param container + * @param log + * @throws WagonConfigurationException + * @todo Remove when {@link WagonManager#getWagon(org.apache.maven.wagon.repository.Repository) is available}. It's available in Maven 2.0.5. + */ + private static void configureWagon(Wagon wagon, String repositoryId, Settings settings, PlexusContainer container, + Log log) + throws TransferFailedException { + log.debug(" configureWagon "); + + // MSITE-25: Make sure that the server settings are inserted + for (int i = 0; i < settings.getServers().size(); i++) { + Server server = settings.getServers().get(i); + String id = server.getId(); + + log.debug("configureWagon server " + id); + + if (id != null && id.equals(repositoryId)) { + if (server.getConfiguration() != null) { + PlexusConfiguration plexusConf = + new XmlPlexusConfiguration((Xpp3Dom) server.getConfiguration()); + + ComponentConfigurator componentConfigurator = null; + try { + componentConfigurator = (ComponentConfigurator) container.lookup(ComponentConfigurator.ROLE, "basic"); + componentConfigurator.configureComponent(wagon, plexusConf, container.getContainerRealm()); + } catch (ComponentLookupException e) { + throw new TransferFailedException("While configuring wagon for \'" + repositoryId + + "\': Unable to lookup wagon configurator." + " Wagon configuration cannot be applied.", e); + } catch (ComponentConfigurationException e) { + throw new TransferFailedException("While configuring wagon for \'" + repositoryId + + "\': Unable to apply wagon configuration.", e); + } finally { + if (componentConfigurator != null) { + try { + container.release(componentConfigurator); + } catch (ComponentLifecycleException e) { + log.error("Problem releasing configurator - ignoring: " + e.getMessage()); + } + } + } + } + } + } + } + + /** {@inheritDoc} */ + public void contextualize(Context context) + throws ContextException { + container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY); + } + + +} \ No newline at end of file
participants (1)
-
mfortun@users.nuiton.org