Skip to content

Commit

Permalink
[MDEPLOY-320] Simplify and unify message (#64)
Browse files Browse the repository at this point in the history
This plugin used old ctor for MojoExecutionException that uses "message", "long message" and "source". The source is fully unused in Maven Core, while long message just complicates things.

Just unify message, use one "standard" exception message.

---

https://issues.apache.org/jira/browse/MDEPLOY-320
  • Loading branch information
youngledo authored Aug 15, 2024
1 parent 14cc4c3 commit 07948ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
14 changes: 5 additions & 9 deletions src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,16 @@ RemoteRepository getDeploymentRepository(
+ "\" instead.");
repo = getRemoteRepository(id, url);
} else {
throw new MojoExecutionException(
altDeploymentRepo,
"Invalid legacy syntax and layout for repository.",
"Invalid legacy syntax and layout for alternative repository. Use \"" + id + "::" + url
+ "\" instead, and only default layout is supported.");
throw new MojoExecutionException("Invalid legacy syntax and layout for alternative repository: \""
+ altDeploymentRepo + "\". Use \"" + id + "::" + url
+ "\" instead, and only default layout is supported.");
}
} else {
matcher = ALT_REPO_SYNTAX_PATTERN.matcher(altDeploymentRepo);

if (!matcher.matches()) {
throw new MojoExecutionException(
altDeploymentRepo,
"Invalid syntax for repository.",
"Invalid syntax for alternative repository. Use \"id::url\".");
throw new MojoExecutionException("Invalid syntax for alternative repository: \"" + altDeploymentRepo
+ "\". Use \"id::url\".");
} else {
String id = matcher.group(1).trim();
String url = matcher.group(2).trim();
Expand Down
37 changes: 18 additions & 19 deletions src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -711,17 +711,18 @@ public void testLegacyAltDeploymentRepositoryWithLegacyLayout() throws Exception

setVariableValueToObject(mojo, "project", project);
setVariableValueToObject(mojo, "session", session);
setVariableValueToObject(mojo, "altDeploymentRepository", "altDeploymentRepository::legacy::http://localhost");
String altDeploymentRepository = "altDeploymentRepository::legacy::http://localhost";
setVariableValueToObject(mojo, "altDeploymentRepository", altDeploymentRepository);

project.setVersion("1.0-SNAPSHOT");
try {
mojo.getDeploymentRepository(project, null, null, "altDeploymentRepository::legacy::http://localhost");
mojo.getDeploymentRepository(project, null, null, altDeploymentRepository);
fail("Should throw: Invalid legacy syntax and layout for repository.");
} catch (MojoExecutionException e) {
assertEquals(e.getMessage(), "Invalid legacy syntax and layout for repository.");
assertEquals(
e.getLongMessage(),
"Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::http://localhost\" instead, and only default layout is supported.");
e.getMessage(),
"Invalid legacy syntax and layout for alternative repository: \"" + altDeploymentRepository
+ "\". Use \"altDeploymentRepository::http://localhost\" instead, and only default layout is supported.");
}
}

Expand All @@ -730,19 +731,18 @@ public void testInsaneAltDeploymentRepository() throws Exception {

setVariableValueToObject(mojo, "project", project);
setVariableValueToObject(mojo, "session", session);
setVariableValueToObject(
mojo, "altDeploymentRepository", "altDeploymentRepository::hey::wow::foo::http://localhost");
String altDeploymentRepository = "altDeploymentRepository::hey::wow::foo::http://localhost";
setVariableValueToObject(mojo, "altDeploymentRepository", altDeploymentRepository);

project.setVersion("1.0-SNAPSHOT");
try {
mojo.getDeploymentRepository(
project, null, null, "altDeploymentRepository::hey::wow::foo::http://localhost");
mojo.getDeploymentRepository(project, null, null, altDeploymentRepository);
fail("Should throw: Invalid legacy syntax and layout for repository.");
} catch (MojoExecutionException e) {
assertEquals(e.getMessage(), "Invalid legacy syntax and layout for repository.");
assertEquals(
e.getLongMessage(),
"Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::wow::foo::http://localhost\" instead, and only default layout is supported.");
e.getMessage(),
"Invalid legacy syntax and layout for alternative repository: \"" + altDeploymentRepository
+ "\". Use \"altDeploymentRepository::wow::foo::http://localhost\" instead, and only default layout is supported.");
}
}

Expand All @@ -766,19 +766,18 @@ public void testLegacyScmSvnAltDeploymentRepository() throws Exception {
mojo = new DeployMojo();

setVariableValueToObject(mojo, "project", project);
setVariableValueToObject(
mojo, "altDeploymentRepository", "altDeploymentRepository::legacy::scm:svn:http://localhost");
String altDeploymentRepository = "altDeploymentRepository::legacy::scm:svn:http://localhost";
setVariableValueToObject(mojo, "altDeploymentRepository", altDeploymentRepository);

project.setVersion("1.0-SNAPSHOT");
try {
mojo.getDeploymentRepository(
project, null, null, "altDeploymentRepository::legacy::scm:svn:http://localhost");
mojo.getDeploymentRepository(project, null, null, altDeploymentRepository);
fail("Should throw: Invalid legacy syntax and layout for repository.");
} catch (MojoExecutionException e) {
assertEquals(e.getMessage(), "Invalid legacy syntax and layout for repository.");
assertEquals(
e.getLongMessage(),
"Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::scm:svn:http://localhost\" instead, and only default layout is supported.");
e.getMessage(),
"Invalid legacy syntax and layout for alternative repository: \"" + altDeploymentRepository
+ "\". Use \"altDeploymentRepository::scm:svn:http://localhost\" instead, and only default layout is supported.");
}
}

Expand Down

0 comments on commit 07948ea

Please sign in to comment.