This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-mapping.git
commit 97b599d81de7270624b9ff64a1840f0c82a56aba Author: Gerd Aschemann <g...@aschemann.net> AuthorDate: Sun Jan 12 14:57:46 2025 +0100 [MSHARED-1462] Clean up code with `spotless:apply` which leads to many changes ( Cf. support-and-care/maven-support-and-care#77) --- pom.xml | 7 +- .../shared/mapping/DashClassifierValueSource.java | 47 +++--- .../apache/maven/shared/mapping/MappingUtils.java | 40 +++-- .../maven/shared/mapping/MappingUtilsTest.java | 165 ++++++++++----------- 4 files changed, 142 insertions(+), 117 deletions(-) diff --git a/pom.xml b/pom.xml index b73cab7..1f24e62 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,4 @@ -<?xml version='1.0' encoding='UTF-8'?> +<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -35,12 +35,13 @@ <scm> <connection>scm:git:https://gitbox.apache.org/repos/asf/maven-mapping.git</connection> <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-mapping.git</developerConnection> - <url>https://github.com/apache/maven-mapping/tree/${project.scm.tag}</url> <tag>HEAD</tag> + <url>https://github.com/apache/maven-mapping/tree/${project.scm.tag}</url> </scm> <issueManagement> <system>jira</system> - <url>https://issues.apache.org/jira/issues/?jql=project%20%3D%20MSHARED%20AND%20component%20%3D%20maven-mapping</url> </issueManagement> + <url>https://issues.apache.org/jira/issues/?jql=project%20%3D%20MSHARED%20AND%20component%20%3D%20maven-mapping</url> + </issueManagement> <ciManagement> <system>Jenkins</system> <url>https://ci-builds.apache.org/job/Maven/job/maven-box/job/maven-mapping/</url> diff --git a/src/main/java/org/apache/maven/shared/mapping/DashClassifierValueSource.java b/src/main/java/org/apache/maven/shared/mapping/DashClassifierValueSource.java index ce42ce7..c71c573 100644 --- a/src/main/java/org/apache/maven/shared/mapping/DashClassifierValueSource.java +++ b/src/main/java/org/apache/maven/shared/mapping/DashClassifierValueSource.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.maven.shared.mapping; /* @@ -28,34 +46,27 @@ import org.codehaus.plexus.interpolation.PropertiesBasedValueSource; * <code>dashClassifier</code> and <code>dashClassifier?</code>. * */ -public class DashClassifierValueSource - extends PropertiesBasedValueSource -{ +public class DashClassifierValueSource extends PropertiesBasedValueSource { /** * Create the ValueSource. * * @param classifier The classifier that should be used during interpolation */ - public DashClassifierValueSource( String classifier ) - { - super( createDashClassifierProperties( classifier ) ); + public DashClassifierValueSource(String classifier) { + super(createDashClassifierProperties(classifier)); } - private static Properties createDashClassifierProperties( String classifier ) - { + private static Properties createDashClassifierProperties(String classifier) { Properties classifierMask = new Properties(); - if ( classifier != null ) - { - classifierMask.setProperty( "dashClassifier?", "-" + classifier ); - classifierMask.setProperty( "dashClassifier", "-" + classifier ); - } - else - { - classifierMask.setProperty( "dashClassifier?", "" ); - classifierMask.setProperty( "dashClassifier", "" ); + if (classifier != null) { + classifierMask.setProperty("dashClassifier?", "-" + classifier); + classifierMask.setProperty("dashClassifier", "-" + classifier); + } else { + classifierMask.setProperty("dashClassifier?", ""); + classifierMask.setProperty("dashClassifier", ""); // Make sure that the classifier property is usable, if it is null - classifierMask.setProperty( "classifier", "" ); + classifierMask.setProperty("classifier", ""); } return classifierMask; } diff --git a/src/main/java/org/apache/maven/shared/mapping/MappingUtils.java b/src/main/java/org/apache/maven/shared/mapping/MappingUtils.java index 05cbcc4..dcec783 100644 --- a/src/main/java/org/apache/maven/shared/mapping/MappingUtils.java +++ b/src/main/java/org/apache/maven/shared/mapping/MappingUtils.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.maven.shared.mapping; /* @@ -44,10 +62,8 @@ import org.codehaus.plexus.interpolation.RegexBasedInterpolator; * @author Stephane Nicoll * @author Dennis Lundberg */ -public final class MappingUtils -{ - private MappingUtils() - { +public final class MappingUtils { + private MappingUtils() { // prevent instantiation. } @@ -60,7 +76,7 @@ public final class MappingUtils * Default file name mapping incl. classifier. */ public static final String DEFAULT_FILE_NAME_MAPPING_CLASSIFIER = - "@{artifactId}@-@{baseVersion}@-@{classifier}@.@{extension}@"; + "@{artifactId}@-@{baseVersion}@-@{classifier}@.@{extension}@"; /** * Evaluates the specified expression for the given artifact. @@ -70,18 +86,16 @@ public final class MappingUtils * @throws InterpolationException in case of an error * @return expression the expression to be evaluated */ - public static String evaluateFileNameMapping( String expression, Artifact artifact ) - throws InterpolationException - { + public static String evaluateFileNameMapping(String expression, Artifact artifact) throws InterpolationException { - RegexBasedInterpolator interpolator = new RegexBasedInterpolator( "\\@\\{(", ")?([^}]+)\\}@" ); - interpolator.addValueSource( new ObjectBasedValueSource( artifact ) ); - interpolator.addValueSource( new ObjectBasedValueSource( artifact.getArtifactHandler() ) ); + RegexBasedInterpolator interpolator = new RegexBasedInterpolator("\\@\\{(", ")?([^}]+)\\}@"); + interpolator.addValueSource(new ObjectBasedValueSource(artifact)); + interpolator.addValueSource(new ObjectBasedValueSource(artifact.getArtifactHandler())); // Support for special expressions, like @{dashClassifier?}@, see MWAR-212 - interpolator.addValueSource( new DashClassifierValueSource( artifact.getClassifier() ) ); + interpolator.addValueSource(new DashClassifierValueSource(artifact.getClassifier())); - String value = interpolator.interpolate( expression, "__artifact" ); + String value = interpolator.interpolate(expression, "__artifact"); return value; } diff --git a/src/test/java/org/apache/maven/shared/mapping/MappingUtilsTest.java b/src/test/java/org/apache/maven/shared/mapping/MappingUtilsTest.java index b96ec54..a127222 100644 --- a/src/test/java/org/apache/maven/shared/mapping/MappingUtilsTest.java +++ b/src/test/java/org/apache/maven/shared/mapping/MappingUtilsTest.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.maven.shared.mapping; /* @@ -20,7 +38,6 @@ package org.apache.maven.shared.mapping; */ import junit.framework.TestCase; - import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.plugin.testing.stubs.ArtifactStub; @@ -31,138 +48,120 @@ import org.codehaus.plexus.interpolation.InterpolationException; * * @author Stephane Nicoll */ -public class MappingUtilsTest - extends TestCase -{ +public class MappingUtilsTest extends TestCase { - public void testCompleteMapping() - throws InterpolationException - { + public void testCompleteMapping() throws InterpolationException { TestArtifactStub jar = new TestArtifactStub(); - jar.setGroupId( "org.apache.sample" ); - jar.setArtifactId( "maven-test-lib" ); - jar.setVersion( "1.0" ); - assertEquals( "maven-test-lib-1.0.jar", - MappingUtils.evaluateFileNameMapping( "@{artifactId}@-@{version}@.@{extension}@", jar ) ); - + jar.setGroupId("org.apache.sample"); + jar.setArtifactId("maven-test-lib"); + jar.setVersion("1.0"); + assertEquals( + "maven-test-lib-1.0.jar", + MappingUtils.evaluateFileNameMapping("@{artifactId}@-@{version}@.@{extension}@", jar)); } - public void testNoVersionMapping() - throws InterpolationException - { + public void testNoVersionMapping() throws InterpolationException { TestArtifactStub jar = new TestArtifactStub(); - jar.setGroupId( "org.apache.sample" ); - jar.setArtifactId( "maven-test-lib" ); - jar.setVersion( "1.0" ); - assertEquals( "maven-test-lib.jar", - MappingUtils.evaluateFileNameMapping( "@{artifactId}@.@{extension}@", jar ) ); - + jar.setGroupId("org.apache.sample"); + jar.setArtifactId("maven-test-lib"); + jar.setVersion("1.0"); + assertEquals("maven-test-lib.jar", MappingUtils.evaluateFileNameMapping("@{artifactId}@.@{extension}@", jar)); } - public void testMappingWithGroupId() - throws InterpolationException - { + public void testMappingWithGroupId() throws InterpolationException { TestArtifactStub jar = new TestArtifactStub(); - jar.setGroupId( "org.apache.sample" ); - jar.setArtifactId( "maven-test-lib" ); - jar.setVersion( "1.0" ); - assertEquals( "org.apache.sample-maven-test-lib-1.0.jar", - MappingUtils.evaluateFileNameMapping( "@{groupId}@-@{artifactId}@-@{version}@.@{extension}@", - jar ) ); - + jar.setGroupId("org.apache.sample"); + jar.setArtifactId("maven-test-lib"); + jar.setVersion("1.0"); + assertEquals( + "org.apache.sample-maven-test-lib-1.0.jar", + MappingUtils.evaluateFileNameMapping("@{groupId}@-@{artifactId}@-@{version}@.@{extension}@", jar)); } - public void testMappingWithClassifier() - throws InterpolationException - { + public void testMappingWithClassifier() throws InterpolationException { TestArtifactStub jar = new TestArtifactStub(); - jar.setGroupId( "org.apache.sample" ); - jar.setArtifactId( "maven-test-lib" ); - jar.setVersion( "1.0" ); - jar.setClassifier( "classifier" ); - assertEquals( "maven-test-lib-1.0-classifier.jar", - MappingUtils.evaluateFileNameMapping( MappingUtils.DEFAULT_FILE_NAME_MAPPING_CLASSIFIER, jar ) ); + jar.setGroupId("org.apache.sample"); + jar.setArtifactId("maven-test-lib"); + jar.setVersion("1.0"); + jar.setClassifier("classifier"); + assertEquals( + "maven-test-lib-1.0-classifier.jar", + MappingUtils.evaluateFileNameMapping(MappingUtils.DEFAULT_FILE_NAME_MAPPING_CLASSIFIER, jar)); } - public void testMappingWithNullClassifier() - throws InterpolationException - { + public void testMappingWithNullClassifier() throws InterpolationException { TestArtifactStub jar = new TestArtifactStub(); - jar.setGroupId( "org.apache.sample" ); - jar.setArtifactId( "maven-test-lib" ); - jar.setVersion( "1.0" ); - jar.setClassifier( null ); - assertEquals( "maven-test-lib-1.0-.jar", - MappingUtils.evaluateFileNameMapping( MappingUtils.DEFAULT_FILE_NAME_MAPPING_CLASSIFIER, jar ) ); + jar.setGroupId("org.apache.sample"); + jar.setArtifactId("maven-test-lib"); + jar.setVersion("1.0"); + jar.setClassifier(null); + assertEquals( + "maven-test-lib-1.0-.jar", + MappingUtils.evaluateFileNameMapping(MappingUtils.DEFAULT_FILE_NAME_MAPPING_CLASSIFIER, jar)); } /** * Test for MWAR-212. */ - public void testMappingWithOptionalClassifier() - throws InterpolationException - { + public void testMappingWithOptionalClassifier() throws InterpolationException { final String MAPPING_WITH_OPTIONAL_CLASSIFIER_1 = "@{artifactId}@-@{version}@@{dashClassifier}@.@{extension}@"; final String MAPPING_WITH_OPTIONAL_CLASSIFIER_2 = "@{artifactId}@-@{version}@@{dashClassifier?}@.@{extension}@"; TestArtifactStub jar = new TestArtifactStub(); - jar.setGroupId( "org.apache.sample" ); - jar.setArtifactId( "maven-test-lib" ); - jar.setVersion( "1.0" ); - assertEquals( "maven-test-lib-1.0.jar", - MappingUtils.evaluateFileNameMapping( MAPPING_WITH_OPTIONAL_CLASSIFIER_1, jar ) ); - assertEquals( "maven-test-lib-1.0.jar", - MappingUtils.evaluateFileNameMapping( MAPPING_WITH_OPTIONAL_CLASSIFIER_2, jar ) ); + jar.setGroupId("org.apache.sample"); + jar.setArtifactId("maven-test-lib"); + jar.setVersion("1.0"); + assertEquals( + "maven-test-lib-1.0.jar", + MappingUtils.evaluateFileNameMapping(MAPPING_WITH_OPTIONAL_CLASSIFIER_1, jar)); + assertEquals( + "maven-test-lib-1.0.jar", + MappingUtils.evaluateFileNameMapping(MAPPING_WITH_OPTIONAL_CLASSIFIER_2, jar)); jar = new TestArtifactStub(); - jar.setGroupId( "org.apache.sample" ); - jar.setArtifactId( "maven-test-lib" ); - jar.setVersion( "1.0" ); - jar.setClassifier( "classifier" ); - assertEquals( "maven-test-lib-1.0-classifier.jar", - MappingUtils.evaluateFileNameMapping( MAPPING_WITH_OPTIONAL_CLASSIFIER_1, jar ) ); - assertEquals( "maven-test-lib-1.0-classifier.jar", - MappingUtils.evaluateFileNameMapping( MAPPING_WITH_OPTIONAL_CLASSIFIER_2, jar ) ); + jar.setGroupId("org.apache.sample"); + jar.setArtifactId("maven-test-lib"); + jar.setVersion("1.0"); + jar.setClassifier("classifier"); + assertEquals( + "maven-test-lib-1.0-classifier.jar", + MappingUtils.evaluateFileNameMapping(MAPPING_WITH_OPTIONAL_CLASSIFIER_1, jar)); + assertEquals( + "maven-test-lib-1.0-classifier.jar", + MappingUtils.evaluateFileNameMapping(MAPPING_WITH_OPTIONAL_CLASSIFIER_2, jar)); } // A very dumb stub used to test the mappings - class TestArtifactStub - extends ArtifactStub - { + class TestArtifactStub extends ArtifactStub { /** * Override in this class because there is no setter in ArtifactStub. */ protected String classifier; - public TestArtifactStub() - { + public TestArtifactStub() { super(); - setType( "jar" ); + setType("jar"); } /** * Override in this class because ArtifactStub always returns null. */ @Override - public ArtifactHandler getArtifactHandler() - { - return new DefaultArtifactHandler( getType() ); + public ArtifactHandler getArtifactHandler() { + return new DefaultArtifactHandler(getType()); } @Override - public String getBaseVersion() - { + public String getBaseVersion() { return getVersion(); } @Override - public String getClassifier() - { + public String getClassifier() { return classifier; } - public void setClassifier( String classifier ) - { + public void setClassifier(String classifier) { this.classifier = classifier; } }