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 -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final intprivate static final Objectprivate static final Integerprivate IntegerSpecify this if you want the port be chosen with a number lower than that one.private IntegerSpecify this if you want the port be chosen with a number higher than that one.private FileOutput file to write the generated properties to.private String[]A List to property names to be placed in Maven project.private org.apache.maven.project.MavenProjectprivate booleanSpecify true or false if you want the port selection randomized.private String[]A List of urls to resource where list of name could be found.Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcreateOutputDirectoryIfNotExist(File outputFile) voidexecute()private intfindAvailablePortNumber(Integer portNumberStartingPoint, List<Integer> reservedPorts) Returns the first number available, starting at portNumberStartingPoint that's not already in the reservedPorts list.private intprivate ServerSocketprivate voidload(ReserveListenerPortMojo.UrlResource resource) private voidprivate voidloadUrls()reservePort(int port) Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
BUILD_HELPER_RESERVED_PORTS
- See Also:
-
FIRST_NON_ROOT_PORT_NUMBER
private static final int FIRST_NON_ROOT_PORT_NUMBER- See Also:
-
MAX_PORT_NUMBER
-
LOCK
-
portNames
A List to property names to be placed in Maven project. At least one of#urlsor#portNameshas to be specified.- Since:
- 1.2
-
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#urlsor#portNameshas to be specified.- Since:
- 1.11
-
outputFile
Output file to write the generated properties to. if not given, they are written to Maven project- Since:
- 1.2
-
minPortNumber
Specify this if you want the port be chosen with a number higher than that one.If
maxPortNumberis specified, defaults to 1024.- Since:
- 1.8
-
maxPortNumber
Specify this if you want the port be chosen with a number lower than that one.- Since:
- 1.8
-
randomPort
@Parameter private boolean randomPortSpecify 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
-
-
Constructor Details
-
ReserveListenerPortMojo
public ReserveListenerPortMojo()
-
-
Method Details
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
createOutputDirectoryIfNotExist
- Throws:
IOException
-
getServerSocket
private ServerSocket getServerSocket() throws IOException, org.apache.maven.plugin.MojoExecutionException- Throws:
IOExceptionorg.apache.maven.plugin.MojoExecutionException
-
randomPortList
-
reservePort
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
getNextPortNumber
private int getNextPortNumber() -
getReservedPorts
-
findAvailablePortNumber
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
-