Package org.codehaus.mojo.buildhelper
Class ReserveListenerPortMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.codehaus.mojo.buildhelper.ReserveListenerPortMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
@Mojo(name="reserve-network-port", defaultPhase=PROCESS_TEST_CLASSES, threadSafe=true) public class ReserveListenerPortMojo extends org.apache.maven.plugin.AbstractMojo
Reserve a list of random and not in use network ports and place them in a configurable project properties.- Since:
- 1.2
- Version:
- $Id: ReserveListnerPortMojo.java 6754 2008-04-13 15:14:04Z dantran $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
ReserveListenerPortMojo.UrlResource
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
BUILD_HELPER_RESERVED_PORTS
private static java.lang.Integer
FIRST_NON_ROOT_PORT_NUMBER
private static java.lang.Object
lock
private static java.lang.Integer
MAX_PORT_NUMBER
private java.lang.Integer
maxPortNumber
Specify this if you want the port be chosen with a number lower than that one.private java.lang.Integer
minPortNumber
Specify this if you want the port be chosen with a number higher than that one.private java.io.File
outputFile
Output file to write the generated properties to.private java.lang.String[]
portNames
A List to property names to be placed in Maven project.private org.apache.maven.project.MavenProject
project
private boolean
randomPort
Specify true or false if you want the port selection randomized.private java.lang.String[]
urls
A List of urls to resource where list of name could be found.
-
Constructor Summary
Constructors Constructor Description ReserveListenerPortMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
createOutputDirectoryIfNotExist(java.io.File outputFile)
void
execute()
private int
findAvailablePortNumber(java.lang.Integer portNumberStartingPoint, java.util.List<java.lang.Integer> reservedPorts)
Returns the first number available, starting at portNumberStartingPoint that's not already in the reservedPorts list.private int
getNextPortNumber()
private java.util.List<java.lang.Integer>
getReservedPorts()
private java.net.ServerSocket
getServerSocket()
private void
load(ReserveListenerPortMojo.UrlResource resource)
private void
loadPortNamesFromResource(ReserveListenerPortMojo.UrlResource resource)
private void
loadUrls()
private java.util.List<java.lang.Integer>
randomPortList()
java.net.ServerSocket
reservePort(int port)
-
-
-
Field Detail
-
BUILD_HELPER_RESERVED_PORTS
private static final java.lang.String BUILD_HELPER_RESERVED_PORTS
- See Also:
- Constant Field Values
-
FIRST_NON_ROOT_PORT_NUMBER
private static final java.lang.Integer FIRST_NON_ROOT_PORT_NUMBER
-
MAX_PORT_NUMBER
private static final java.lang.Integer MAX_PORT_NUMBER
-
lock
private static final java.lang.Object lock
-
portNames
@Parameter private java.lang.String[] portNames
A List to property names to be placed in Maven project. At least one of#urls
or#portNames
has to be specified.- Since:
- 1.2
-
urls
@Parameter private java.lang.String[] urls
A List of urls to resource where list of name could be found. Can be in form of classpath:com/myproject/names.txt . At least one of#urls
or#portNames
has to be specified.- Since:
- 1.11
-
outputFile
@Parameter private java.io.File outputFile
Output file to write the generated properties to. if not given, they are written to Maven project- Since:
- 1.2
-
minPortNumber
@Parameter private java.lang.Integer minPortNumber
Specify this if you want the port be chosen with a number higher than that one.If
maxPortNumber
is specified, defaults to .- Since:
- 1.8
-
maxPortNumber
@Parameter private java.lang.Integer maxPortNumber
Specify this if you want the port be chosen with a number lower than that one.- Since:
- 1.8
-
randomPort
@Parameter private boolean randomPort
Specify true or false if you want the port selection randomized.- Since:
- 1.10
-
project
@Parameter(readonly=true, defaultValue="${project}") private org.apache.maven.project.MavenProject project
- Since:
- 1.2
-
-
Method Detail
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
createOutputDirectoryIfNotExist
private void createOutputDirectoryIfNotExist(java.io.File outputFile) throws java.io.IOException
- Throws:
java.io.IOException
-
getServerSocket
private java.net.ServerSocket getServerSocket() throws java.io.IOException, org.apache.maven.plugin.MojoExecutionException
- Throws:
java.io.IOException
org.apache.maven.plugin.MojoExecutionException
-
randomPortList
private java.util.List<java.lang.Integer> randomPortList()
-
reservePort
public java.net.ServerSocket reservePort(int port) throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
getNextPortNumber
private int getNextPortNumber()
-
getReservedPorts
private java.util.List<java.lang.Integer> getReservedPorts()
-
findAvailablePortNumber
private int findAvailablePortNumber(java.lang.Integer portNumberStartingPoint, java.util.List<java.lang.Integer> reservedPorts)
Returns the first number available, starting at portNumberStartingPoint that's not already in the reservedPorts list.- Parameters:
portNumberStartingPoint
- first port number to start from.reservedPorts
- the ports already reserved.- Returns:
- first number available not in the given list, starting at the given parameter.
-
loadUrls
private void loadUrls() throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
load
private void load(ReserveListenerPortMojo.UrlResource resource) throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
loadPortNamesFromResource
private void loadPortNamesFromResource(ReserveListenerPortMojo.UrlResource resource) throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
-