Skip to content
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

[MASSEMBLY-617] : Add new FileMapper for giving a suffix to filename … #14

Closed
wants to merge 5 commits into from

Conversation

tcollignon
Copy link
Contributor

…-> SuffixFileMapper

HI, refer to #13 , @plamentotev tell me to use FileMapper instead of adding just a fileNameSuffix. So this PR intend to add a new FileMapper, who can add a suffix to filename.

Copy link
Member

@plamentotev plamentotev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

Thank you. I have a couple of comments:

  • I'm not sure what is the use case when you'll want the suffix to be added on the directory name. For example why I'll want csuffix.c\\xyz.gif instead of c.c\\xyzsuffix.gif
  • Please update the documentation as well - plexus-io/src/site/apt/filemappers.apt

{
if ( name.contains( "." ) )
{
String beforeExtension = name.substring( 0, name.indexOf('.') );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing white space around '.'.

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"};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splinting on two lines would make it more readable and there is missing space after the curly brace.

@tcollignon
Copy link
Contributor Author

I @plamentotev,

You're right, I have not managing directory in my Mapper, I have do it in this new commit. I have add documentation like you said, and add all of example in it to describe each case.
I hope it's good, if not tell me.

Copy link
Member

@plamentotev plamentotev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general looks good. Just few more comments. I've missed some of the things the last time - sorry about that.

public static String getMappedFileName( String suffix, String name )
{
String nameWithSuffix = name;
if ( StringUtils.isNotBlank( suffix ) )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of the mappers throw IllegalStateException if any of the params is not initialized. Would be nice if this mapper is consistent with the others (PrefixFileMapper is exception but I think it would be better if it stays the only exception).

/**
* Performs the mapping of a file name by adding a suffix.
*/
public static String getMappedFileName( String suffix, String name )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you followed the PrefixFileMapper code, but the rest does not have public static String getMappedFileName and I think it would be best to be consistent with them as PrefixFileMapper is a kind of exception. If you don't have other concerns I think it's best to move it to public String getMappedFileName( @Nonnull String name ).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I have no problem with that
Indeed like you said I'm basically inspired of PrefixFileMapper because I didn't know plexus-io :(

{
final int dirSep = Math.max( name.lastIndexOf( '/' ), name.lastIndexOf( '\\' ) );
String filename = dirSep > 0 ? name.substring( dirSep +1 ) : name;
String dirname = dirSep > 0 ? name.substring( 0, dirSep +1 ) : "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope I don't get annoying with that but I think there is missing white space after the plus sign.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem code style must be respected

String nameWithSuffix = name;
if ( StringUtils.isNotBlank( suffix ) )
{
final int dirSep = Math.max( name.lastIndexOf( '/' ), name.lastIndexOf( '\\' ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to split the file name into file name and directory name. See FileExtensionMapper for example. But feel free to leave it like that if you think it is more readable this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes actually I try to do the same thing as FileExtensionMapper but I want to handle the case of multiple "." in extension (like tar.gz). So I have added a new test case to check that is correctly handle by the SuffixMapper. So I it ok for you I give my code who works with this case (FileExtensionMapper does not handle that case)

* {Suffix File Mapper}

The {{{./apidocs/org/codehaus/plexus/components/io/filemappers/SuffixFileMapper.html}suffix
file mapper}} add the given suffix to the filename. The suffix will be added before the file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the correct is adds the given

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops you see my bad English :(

The {{{./apidocs/org/codehaus/plexus/components/io/filemappers/SuffixFileMapper.html}suffix
file mapper}} add the given suffix to the filename. The suffix will be added before the file
extension. Examples :
theFile.txt => theFileNiceSuffix.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The examples will be displayed on one line as the new lines will be stripped. If you wrap them as code that would solve the problem and they would stand out as well. And would be great if you add example with dot in the file name as it would make clear how the mapper behaves in such cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have still the following example : dir/archive.tar.gz => dir/archiveNiceSuffix.tar.gz
this is not enough ? If not please tell me an example

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is ok. My bad, didn't read the docs carefully enough. Sorry about that.

import org.codehaus.plexus.util.StringUtils;

/**
* A file mapper, which maps by adding a suffix.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if make it clear that the suffix is added before the dot. It is mentioned in the site docs but it would be nice if you state it here as well (so it is visible in the IDEs).

@@ -0,0 +1,74 @@
package org.codehaus.plexus.components.io.filemappers;

import java.util.regex.Matcher;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is unused import.

import java.util.regex.Matcher;

/*
* Copyright 2007 The Codehaus Foundation.
Copy link
Member

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).

*/
public void setSuffix( String suffix )
{
this.suffix = suffix;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As null is not valid value you can add check if suffix is null:

if ( suffix == null )
{
    throw new IllegalArgumentException( "The suffix is null." );
}

Not all marchers all have that (the regex one does not have) but I think as most have it is better this way.

@tcollignon
Copy link
Contributor Author

Ok I have fix all of this @plamentotev

@plamentotev plamentotev added this to the 3.1.0 milestone Jul 31, 2018
@plamentotev
Copy link
Member

Thank you for your contribution. I know there were a lot of comments but as you can see the different mappers have slightly different behavior and that can be confusing. thank you for having the patience to make your mapper consistent with the majority of the other mappers :)

I've bumped the Plexus IO version, made some small formatting changes, squashed the commits and merged them in master. Also I've striped some extra white spaces at the end of empty lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants