-
Notifications
You must be signed in to change notification settings - Fork 10
[MASSEMBLY-617] : Add new FileMapper for giving a suffix to filename … #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
9370b32
94833d1
b29e094
9ffe46a
8954c8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package org.codehaus.plexus.components.io.filemappers; | ||
|
|
||
| /* | ||
| * Copyright 2007 The Codehaus Foundation. | ||
| * | ||
| * Licensed 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. | ||
| */ | ||
|
|
||
| import javax.annotation.Nonnull; | ||
|
|
||
| import org.codehaus.plexus.util.StringUtils; | ||
|
|
||
| /** | ||
| * A file mapper, which maps by adding a suffix. | ||
|
||
| */ | ||
| public class SuffixFileMapper extends AbstractFileMapper | ||
| { | ||
| /** | ||
| * The suffix mappers role-hint: "suffix". | ||
| */ | ||
| public static final String ROLE_HINT = "suffix"; | ||
|
|
||
| private String suffix; | ||
|
|
||
| @Nonnull public String getMappedFileName( @Nonnull String name ) | ||
| { | ||
| final String s = super.getMappedFileName( name ); // Check for null, etc. | ||
| return getMappedFileName( suffix, s ); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the suffix to add. | ||
| */ | ||
| public String getSuffix() | ||
| { | ||
| return suffix; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the suffix to add. | ||
| */ | ||
| public void setSuffix( String suffix ) | ||
| { | ||
| this.suffix = suffix; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As Not all marchers all have that (the regex one does not have) but I think as most have it is better this way. |
||
| } | ||
|
|
||
| /** | ||
| * Performs the mapping of a file name by adding a suffix. | ||
| */ | ||
| public static String getMappedFileName( String suffix, String name ) | ||
|
||
| { | ||
| String nameWithSuffix = name; | ||
| if ( StringUtils.isNotBlank( suffix ) ) | ||
|
||
| { | ||
| if ( name.contains( "." ) ) | ||
| { | ||
| String beforeExtension = name.substring( 0, name.indexOf('.') ); | ||
|
||
| String afterExtension = name.substring( name.indexOf('.') + 1 ) ; | ||
| nameWithSuffix = beforeExtension + suffix + "." + afterExtension; | ||
| } | ||
| else | ||
| { | ||
| nameWithSuffix += suffix; | ||
| } | ||
| } | ||
| return nameWithSuffix; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,6 +164,22 @@ public void testPrefixMapper() throws Exception | |
| mapper.setPrefix( prefix ); | ||
| testFileMapper( mapper, SAMPLES, results ); | ||
| } | ||
|
|
||
| public void testSuffixMapper() throws Exception | ||
| { | ||
| final String suffix = "suffix"; | ||
| String[] results = getIdentityResults(); | ||
| testFileMapper( new SuffixFileMapper(), SAMPLES, results ); | ||
| testFileMapper( (SuffixFileMapper) lookup( FileMapper.ROLE, SuffixFileMapper.ROLE_HINT ), SAMPLES, results ); | ||
|
|
||
| results = new String[] {null, null, "asuffix", "xyzsuffix.gif", "b/asuffix", "b/xyzsuffix.gif", "b\\asuffix", "b\\xyzsuffix.gif", "csuffix.c/a", "csuffix.c/xyz.gif", "csuffix.c\\a", "csuffix.c\\xyz.gif"}; | ||
|
||
| SuffixFileMapper mapper = new SuffixFileMapper(); | ||
| mapper.setSuffix( suffix ); | ||
| testFileMapper( mapper, SAMPLES, results ); | ||
| mapper = (SuffixFileMapper) lookup( FileMapper.ROLE, SuffixFileMapper.ROLE_HINT ); | ||
| mapper.setSuffix( suffix ); | ||
| testFileMapper( mapper, SAMPLES, results ); | ||
| } | ||
|
|
||
| private RegExpFileMapper configure( RegExpFileMapper pMapper, String pPattern, String pReplacement ) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just noticed that this is the old license header. Judging by the other new files in the codehaus-plexus project you can just delete this line and keep the rest (the Apache license).