Skip to content

Commit 642d884

Browse files
committed
Resolve dependencies
OpenCode almost did the Option translation. Remove TODOs that point to a Maven feature marked as won't fix.
1 parent 7c14d19 commit 642d884

4 files changed

Lines changed: 97 additions & 93 deletions

File tree

src/main/java/org/apache/tomcat/maven/plugin/tomcat/deploy/AbstractDeployMojo.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ protected void deployWar()
172172

173173
getLog().info( messagesProvider.getMessage( "AbstractDeployMojo.deployingWar", getDeployedURL() ) );
174174

175-
URL warURL = getWarFile().toURL();
175+
URL warURL = getWarFile().toURI().toURL();
176176
TomcatManagerResponse tomcatResponse = getManager().deploy(getPath(), warURL, isUpdate(), getTag());
177177
checkTomcatResponse(tomcatResponse);
178178
log(tomcatResponse.getHttpResponseBody());
@@ -194,7 +194,7 @@ protected void deployContext()
194194

195195
getLog().info( messagesProvider.getMessage( "AbstractDeployMojo.deployingContext", getDeployedURL() ) );
196196

197-
URL contextURL = getContextFile().toURL();
197+
URL contextURL = getContextFile().toURI().toURL();
198198
TomcatManagerResponse tomcatResponse = getManager().deploy(getPath(), contextURL, isUpdate(), getTag());
199199
checkTomcatResponse(tomcatResponse);
200200
log(tomcatResponse.getHttpResponseBody());
@@ -217,8 +217,8 @@ protected void deployWarAndContext()
217217

218218
getLog().info( messagesProvider.getMessage( "AbstractDeployMojo.deployingWarContext", getDeployedURL() ) );
219219

220-
URL warURL = getWarFile().toURL();
221-
URL contextURL = getContextFile().toURL();
220+
URL warURL = getWarFile().toURI().toURL();
221+
URL contextURL = getContextFile().toURI().toURL();
222222

223223
TomcatManagerResponse tomcatResponse = getManager().deployContext( getPath(), contextURL, warURL, isUpdate(), getTag() );
224224

src/main/java/org/apache/tomcat/maven/plugin/tomcat/run/AbstractRunWarMojo.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
* Runs the current project as a packaged web application using an embedded Tomcat server.
2727
*
2828
* @author Mark Hobson (markhobson@gmail.com)
29-
* TODO depend on war:exploded when MNG-1649 resolved
3029
*/
3130
public abstract class AbstractRunWarMojo
3231
extends AbstractRunMojo

src/main/java/org/apache/tomcat/maven/plugin/tomcat/run/RunWarMojo.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
* Runs the current project as a packaged web application using an embedded Tomcat server.
2828
*
2929
* @author Mark Hobson (markhobson@gmail.com)
30-
* TODO depend on war:exploded when MNG-1649 resolved
3130
*/
3231
@Mojo( name = "run-war", requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true )
3332
@Execute( phase = LifecyclePhase.PACKAGE )

src/main/java/org/apache/tomcat/maven/runner/TomcatRunnerCli.java

Lines changed: 93 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020

2121
import org.apache.commons.cli.CommandLine;
2222
import org.apache.commons.cli.CommandLineParser;
23-
import org.apache.commons.cli.GnuParser;
24-
import org.apache.commons.cli.HelpFormatter;
23+
import org.apache.commons.cli.DefaultParser;
2524
import org.apache.commons.cli.Option;
26-
import org.apache.commons.cli.OptionBuilder;
2725
import org.apache.commons.cli.Options;
2826
import org.apache.commons.cli.ParseException;
27+
import org.apache.commons.cli.help.HelpFormatter;
2928

3029
import java.io.IOException;
3130
import java.io.InputStream;
@@ -36,119 +35,126 @@
3635
* @author Olivier Lamy
3736
* @since 2.0
3837
*/
39-
@SuppressWarnings( "static-access" )
4038
public class TomcatRunnerCli
4139
{
4240

4341
public static final String STAND_ALONE_PROPERTIES_FILENAME = "tomcat.standalone.properties";
4442

45-
static Option httpPort =
46-
OptionBuilder.withArgName( "httpPort" ).hasArg().withDescription( "http port to use" ).create( "httpPort" );
43+
static final Option HTTP_PORT =
44+
Option.builder().longOpt( "httpPort" ).hasArg().argName( "httpPort" )
45+
.desc( "http port to use" ).get();
4746

48-
static Option httpsPort =
49-
OptionBuilder.withArgName( "httpsPort" ).hasArg().withDescription( "https port to use" ).create( "httpsPort" );
47+
static final Option HTTPS_PORT =
48+
Option.builder().longOpt( "httpsPort" ).hasArg().argName( "httpsPort" )
49+
.desc( "https port to use" ).get();
5050

51-
static Option maxPostSize =
52-
OptionBuilder.withArgName( "maxPostSize" ).hasArg().withDescription( "max post size to use" ).create(
53-
"maxPostSize" );
51+
static final Option MAX_POST_SIZE =
52+
Option.builder().longOpt( "maxPostSize" ).hasArg().argName( "maxPostSize" )
53+
.desc( "max post size to use" ).get();
5454

55-
static Option ajpPort =
56-
OptionBuilder.withArgName( "ajpPort" ).hasArg().withDescription( "ajp port to use" ).create( "ajpPort" );
55+
static final Option AJP_PORT =
56+
Option.builder().longOpt( "ajpPort" ).hasArg().argName( "ajpPort" )
57+
.desc( "ajp port to use" ).get();
5758

58-
static Option serverXmlPath =
59-
OptionBuilder.withArgName( "serverXmlPath" ).hasArg().withDescription( "server.xml to use, optional" ).create(
60-
"serverXmlPath" );
59+
static final Option SERVER_XML_PATH =
60+
Option.builder().longOpt( "serverXmlPath" ).hasArg().argName( "serverXmlPath" )
61+
.desc( "server.xml to use, optional" ).get();
6162

62-
static Option resetExtract =
63-
OptionBuilder.withArgName( "resetExtract" ).withDescription( "clean previous extract directory" ).create(
64-
"resetExtract" );
63+
static final Option RESET_EXTRACT =
64+
Option.builder().longOpt( "resetExtract" ).desc( "clean previous extract directory" ).get();
6565

66-
static Option help = OptionBuilder.withLongOpt( "help" ).withDescription( "help" ).create( 'h' );
66+
static final Option HELP =
67+
Option.builder().longOpt( "help" ).desc( "help" ).get();
6768

68-
static Option debug = OptionBuilder.withLongOpt( "debug" ).withDescription( "debug" ).create( 'X' );
69+
static final Option DEBUG =
70+
Option.builder().option( "X" ).longOpt( "debug" ).desc( "debug" ).get();
6971

70-
static Option sysProps = OptionBuilder.withDescription( "use value for given property" ).hasArgs().withDescription(
71-
"key=value" ).withValueSeparator().create( 'D' );
72+
static final Option SYS_PROPS =
73+
Option.builder().option( "D" ).hasArgs().valueSeparator().argName( "key=value" )
74+
.desc( "use value for given property" ).get();
7275

73-
static Option clientAuth =
74-
OptionBuilder.withArgName( "clientAuth" ).withDescription( "enable client authentication for https" ).create(
75-
"clientAuth" );
76+
static final Option CLIENT_AUTH =
77+
Option.builder().longOpt( "clientAuth" ).desc( "enable client authentication for https" ).get();
7678

77-
static Option keyAlias =
78-
OptionBuilder.withArgName( "keyAlias" ).hasArgs().withDescription( "alias from keystore for ssl" ).create(
79-
"keyAlias" );
79+
static final Option KEY_ALIAS =
80+
Option.builder().longOpt( "keyAlias" ).hasArgs().argName( "alias from keystore for ssl" ).get();
8081

81-
static Option obfuscate =
82-
OptionBuilder.withArgName( "password" ).hasArgs().withDescription( "obfuscate the password and exit" ).create(
83-
"obfuscate" );
82+
static final Option OBFUSCATE =
83+
Option.builder().longOpt( "obfuscate" ).hasArgs().argName( "password" )
84+
.desc( "obfuscate the password and exit" ).get();
8485

85-
static Option httpProtocol = OptionBuilder.withArgName( "httpProtocol" ).hasArg().withDescription(
86-
"http protocol to use: HTTP/1.1 or org.apache.coyote.http11.Http11NioProtocol" ).create( "httpProtocol" );
86+
static final Option HTTP_PROTOCOL =
87+
Option.builder().longOpt( "httpProtocol" ).hasArg().argName( "httpProtocol" )
88+
.desc( "http protocol to use: HTTP/1.1 or org.apache.coyote.http11.Http11NioProtocol" ).get();
8789

88-
static Option extractDirectory = OptionBuilder.withArgName( "extractDirectory" ).hasArg().withDescription(
89-
"path to extract war content, default value: .extract" ).create( "extractDirectory" );
90+
static final Option EXTRACT_DIRECTORY =
91+
Option.builder().longOpt( "extractDirectory" ).hasArg().argName( "extractDirectory" )
92+
.desc( "path to extract war content, default value: .extract" ).get();
9093

91-
static Option uriEncoding = OptionBuilder.withArgName( "uriEncoding" ).hasArg().withDescription(
92-
"connector uriEncoding default ISO-8859-1" ).create( "uriEncoding" );
94+
static final Option URI_ENCODING =
95+
Option.builder().longOpt( "uriEncoding" ).hasArg().argName( "uriEncoding" )
96+
.desc( "connector uriEncoding default ISO-8859-1" ).get();
9397

94-
static Options options = new Options();
98+
static final Options OPTIONS = new Options();
9599

96100
static
97101
{
98-
options.addOption( httpPort ) //
99-
.addOption( httpsPort ) //
100-
.addOption( ajpPort ) //
101-
.addOption( serverXmlPath ) //
102-
.addOption( resetExtract ) //
103-
.addOption( help ) //
104-
.addOption( debug ) //
105-
.addOption( sysProps ) //
106-
.addOption( httpProtocol ) //
107-
.addOption( clientAuth ) //
108-
.addOption( keyAlias ) //
109-
.addOption( obfuscate ) //
110-
.addOption( extractDirectory ) //
111-
.addOption( uriEncoding ) //
112-
.addOption( maxPostSize );
102+
OPTIONS.addOption( HTTP_PORT )
103+
.addOption( HTTPS_PORT )
104+
.addOption( AJP_PORT )
105+
.addOption( MAX_POST_SIZE )
106+
.addOption( SERVER_XML_PATH )
107+
.addOption( RESET_EXTRACT )
108+
.addOption( HELP )
109+
.addOption( DEBUG )
110+
.addOption( SYS_PROPS )
111+
.addOption( HTTP_PROTOCOL )
112+
.addOption( CLIENT_AUTH )
113+
.addOption( KEY_ALIAS )
114+
.addOption( OBFUSCATE )
115+
.addOption( EXTRACT_DIRECTORY )
116+
.addOption( URI_ENCODING );
113117
}
114118

115119

116120
public static void main( String[] args )
117121
throws Exception
118122
{
119-
CommandLineParser parser = new GnuParser();
123+
CommandLineParser parser = new DefaultParser();
120124
CommandLine line = null;
121125
try
122126
{
123-
line = parser.parse( TomcatRunnerCli.options, args );
127+
line = parser.parse( TomcatRunnerCli.OPTIONS, args );
124128
}
125129
catch ( ParseException e )
126130
{
127131
System.err.println( "Parsing failed. Reason: " + e.getMessage() );
128-
HelpFormatter formatter = new HelpFormatter();
129-
formatter.printHelp( getCmdLineSyntax(), TomcatRunnerCli.options );
132+
HelpFormatter formatter = HelpFormatter.builder().get();
133+
formatter.printHelp(getCmdLineSyntax(), "Apache Tomcat Maven plugin executable WAR", TomcatRunnerCli.OPTIONS,
134+
"NOTE: The command line options are disabled if using Tomcat server.xml configuration", true);
130135
System.exit( 1 );
131136
}
132137

133-
if ( line.hasOption( help.getOpt() ) )
138+
if ( line.hasOption( HELP ) )
134139
{
135-
HelpFormatter formatter = new HelpFormatter();
136-
formatter.printHelp( getCmdLineSyntax(), TomcatRunnerCli.options );
140+
HelpFormatter formatter = HelpFormatter.builder().get();
141+
formatter.printHelp(getCmdLineSyntax(), "Apache Tomcat Maven plugin executable WAR", TomcatRunnerCli.OPTIONS,
142+
"NOTE: The command line options are disabled if using Tomcat server.xml configuration", true);
137143
System.exit( 0 );
138144
}
139145

140-
if ( line.hasOption( obfuscate.getOpt() ) )
146+
if ( line.hasOption( OBFUSCATE ) )
141147
{
142-
System.out.println( PasswordUtil.obfuscate( line.getOptionValue( obfuscate.getOpt() ) ) );
148+
System.out.println( PasswordUtil.obfuscate( line.getOptionValue( OBFUSCATE ) ) );
143149
System.exit( 0 );
144150
}
145151
TomcatRunner tomcatRunner = new TomcatRunner();
146152

147153
tomcatRunner.runtimeProperties = buildStandaloneProperties();
148154

149-
if ( line.hasOption( serverXmlPath.getOpt() ) )
155+
if ( line.hasOption( SERVER_XML_PATH ) )
150156
{
151-
tomcatRunner.serverXmlPath = line.getOptionValue( serverXmlPath.getOpt() );
157+
tomcatRunner.serverXmlPath = line.getOptionValue( SERVER_XML_PATH );
152158
}
153159

154160
String port = tomcatRunner.runtimeProperties.getProperty( TomcatRunner.HTTP_PORT_KEY );
@@ -158,41 +164,41 @@ public static void main( String[] args )
158164
}
159165

160166
// cli win for the port
161-
if ( line.hasOption( httpPort.getOpt() ) )
167+
if ( line.hasOption( HTTP_PORT ) )
162168
{
163-
tomcatRunner.httpPort = Integer.parseInt( line.getOptionValue( httpPort.getOpt() ) );
169+
tomcatRunner.httpPort = Integer.parseInt( line.getOptionValue( HTTP_PORT ) );
164170
}
165171

166-
if ( line.hasOption( maxPostSize.getOpt() ) )
172+
if ( line.hasOption( MAX_POST_SIZE ) )
167173
{
168-
tomcatRunner.maxPostSize = Integer.parseInt( line.getOptionValue( maxPostSize.getOpt() ) );
174+
tomcatRunner.maxPostSize = Integer.parseInt( line.getOptionValue( MAX_POST_SIZE ) );
169175
}
170176

171-
if ( line.hasOption( httpsPort.getOpt() ) )
177+
if ( line.hasOption( HTTPS_PORT ) )
172178
{
173-
tomcatRunner.httpsPort = Integer.parseInt( line.getOptionValue( httpsPort.getOpt() ) );
179+
tomcatRunner.httpsPort = Integer.parseInt( line.getOptionValue( HTTPS_PORT ) );
174180
}
175-
if ( line.hasOption( ajpPort.getOpt() ) )
181+
if ( line.hasOption( AJP_PORT ) )
176182
{
177-
tomcatRunner.ajpPort = Integer.parseInt( line.getOptionValue( ajpPort.getOpt() ) );
183+
tomcatRunner.ajpPort = Integer.parseInt( line.getOptionValue( AJP_PORT ) );
178184
}
179-
if ( line.hasOption( resetExtract.getOpt() ) )
185+
if ( line.hasOption( RESET_EXTRACT ) )
180186
{
181187
tomcatRunner.resetExtract = true;
182188
}
183-
if ( line.hasOption( debug.getOpt() ) )
189+
if ( line.hasOption( DEBUG ) )
184190
{
185191
tomcatRunner.debug = true;
186192
}
187193

188-
if ( line.hasOption( httpProtocol.getOpt() ) )
194+
if ( line.hasOption( HTTP_PROTOCOL ) )
189195
{
190-
tomcatRunner.httpProtocol = line.getOptionValue( httpProtocol.getOpt() );
196+
tomcatRunner.httpProtocol = line.getOptionValue( HTTP_PROTOCOL );
191197
}
192198

193-
if ( line.hasOption( sysProps.getOpt() ) )
199+
if ( line.hasOption( SYS_PROPS ) )
194200
{
195-
Properties systemProperties = line.getOptionProperties( sysProps.getOpt() );
201+
Properties systemProperties = line.getOptionProperties( SYS_PROPS );
196202
if ( systemProperties != null && !systemProperties.isEmpty() )
197203
{
198204
for ( Map.Entry<Object, Object> sysProp : systemProperties.entrySet() )
@@ -201,23 +207,23 @@ public static void main( String[] args )
201207
}
202208
}
203209
}
204-
if ( line.hasOption( clientAuth.getOpt() ) )
210+
if ( line.hasOption( CLIENT_AUTH ) )
205211
{
206212
tomcatRunner.clientAuth = "true";
207213
}
208-
if ( line.hasOption( keyAlias.getOpt() ) )
214+
if ( line.hasOption( KEY_ALIAS ) )
209215
{
210-
tomcatRunner.keyAlias = line.getOptionValue( keyAlias.getOpt() );
216+
tomcatRunner.keyAlias = line.getOptionValue( KEY_ALIAS );
211217
}
212218

213-
if ( line.hasOption( extractDirectory.getOpt() ) )
219+
if ( line.hasOption( EXTRACT_DIRECTORY ) )
214220
{
215-
tomcatRunner.extractDirectory = line.getOptionValue( extractDirectory.getOpt() );
221+
tomcatRunner.extractDirectory = line.getOptionValue( EXTRACT_DIRECTORY );
216222
}
217223

218-
if ( line.hasOption( uriEncoding.getOpt() ) )
224+
if ( line.hasOption( URI_ENCODING ) )
219225
{
220-
tomcatRunner.uriEncoding = line.getOptionValue( uriEncoding.getOpt() );
226+
tomcatRunner.uriEncoding = line.getOptionValue( URI_ENCODING );
221227
}
222228

223229
// here we go
@@ -238,4 +244,4 @@ public static String getCmdLineSyntax()
238244
{
239245
return "java -jar [path to your exec war jar]";
240246
}
241-
}
247+
}

0 commit comments

Comments
 (0)