From 07948ea5303d94486906dfe810a6e1e404407c6c Mon Sep 17 00:00:00 2001 From: Huang Xiao Date: Thu, 15 Aug 2024 20:17:05 +0800 Subject: [PATCH] [MDEPLOY-320] Simplify and unify message (#64) 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 --- .../maven/plugins/deploy/DeployMojo.java | 14 +++---- .../maven/plugins/deploy/DeployMojoTest.java | 37 +++++++++---------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java index 2c586615..7cf7a7ef 100644 --- a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java +++ b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java @@ -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(); diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java index 52964cc5..ce128e4f 100644 --- a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java @@ -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."); } } @@ -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."); } } @@ -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."); } }