@@ -0,0 +1,3019 @@
+package org.codehaus.mojo.buildhelper;%0D%0A%0D%0A/*%0D%0A * The MIT License%0D%0A * %0D%0A * Copyright (c) 2004, The Codehaus%0D%0A * %0D%0A * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and%0D%0A * associated documentation files (the %22Software%22), to deal in the Software without restriction,%0D%0A * including without limitation the rights to use, copy, modify, merge, publish, distribute,%0D%0A * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is%0D%0A * furnished to do so, subject to the following conditions:%0D%0A * %0D%0A * The above copyright notice and this permission notice shall be included in all copies or%0D%0A * substantial portions of the Software.%0D%0A * %0D%0A * THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT%0D%0A * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND%0D%0A * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,%0D%0A * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,%0D%0A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.%0D%0A */%0D%0A%0D%0Aimport java.io.IOException;%0D%0Aimport java.net.ServerSocket;%0D%0A%0D%0Aimport org.apache.maven.plugin.AbstractMojo;%0D%0Aimport org.apache.maven.plugin.MojoExecutionException;%0D%0Aimport org.apache.maven.plugin.MojoFailureException;%0D%0Aimport org.apache.maven.project.MavenProject;%0D%0A%0D%0A/**%0D%0A * Reserve a list of random and not in used network ports and place them %0D%0A * in a configurable project properties. %0D%0A * %0D%0A * @goal reserve-network-ports%0D%0A * @phase process-test-classes%0D%0A * @author %3Ca href=%22dantran@gmail.com%22%3EDan T. Tran%3C/a%3E%0D%0A * @version $Id: ReserveListnerPortMojo.java 6754 2008-04-13 15:14:04Z dantran $%0D%0A * @since 1.1%0D%0A */%0D%0Apublic class ReserveListenerPortMojo%0D%0A    extends AbstractMojo%0D%0A%7B%0D%0A%0D%0A    /**%0D%0A     * A List to property names to be placed in maven project%0D%0A     * @parameter %0D%0A     * @required%0D%0A     * %0D%0A     */%0D%0A    private String %5B%5D names = new String%5B0%5D;%0D%0A    %0D%0A    /**%0D%0A     * @parameter expression=%22$%7Bproject%7D%22%0D%0A     * @required%0D%0A     * @readonly%0D%0A     */%0D%0A    private MavenProject project;%0D%0A%0D%0A%0D%0A    public void execute()%0D%0A        throws MojoExecutionException, MojoFailureException%0D%0A    %7B%0D%0A        for ( int i = 0 ; i %3C names.length; ++i )%0D%0A        %7B%0D%0A            String unusedPort = Integer.toString( getNextAvailablePort()  );%0D%0A            project.getProperties().setProperty( names%5Bi%5D, unusedPort );%0D%0A        %7D%0D%0A    %7D%0D%0A    %0D%0A    private int getNextAvailablePort()%0D%0A        throws MojoExecutionException%0D%0A    %7B%0D%0A        int unusedPort = 0;%0D%0A        try%0D%0A        %7B%0D%0A            ServerSocket socket = new ServerSocket( 0 );%0D%0A            unusedPort = socket.getLocalPort();%0D%0A            socket.close();%0D%0A        %7D%0D%0A        catch ( IOException e )%0D%0A        %7B%0D%0A            throw new MojoExecutionException( %22Error getting an avaiable port from system%22, e );%0D%0A        %7D%0D%0A%0D%0A        return unusedPort;%0D%0A    %7D%0D%0A    %0D%0A%7D%0D%0A

Add a mojo to reserve a list of random and unused network ports and place in a configurable maven project properties