You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Benjamin Marwell (Jira)" <ji...@apache.org> on 2020/12/23 19:36:00 UTC
[jira] [Updated] (ARCHETYPE-400) method
DefaultFilesetArchetypeGenerator.replaceFilenameTokens(final String
filePath, final Context context) doesn't work when two tokens are close to
each other
[ https://issues.apache.org/jira/browse/ARCHETYPE-400?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Benjamin Marwell updated ARCHETYPE-400:
---------------------------------------
Description:
Hello,
In a maven archetype we can use properties in filepaths which are replaced when the archetype is generated.
e.g.:
Properties :
* int1FirstMaj = Inscription
* nameMaj = TEST
{code:java}
filepath = __int1FirstMaj____nameMaj__RemoteService.java
{code}
The method {{DefaultFilesetArchetypeGenerator.replaceFilenameTokens(final String filePath, final Context context)}} use the delimiter '{{\_\_}}' to replace the properties.
So, after the build, my filepath should be : {{InscriptionTESTRemoteService.java}}
The problem is the following:
- The method looks for the start delimiter index which is 0 in my exemple and the end delimiter index which is 14.
- It replaces {{\_\_int1FirstMaj\_\_}} with 'Inscription'. My filepath is now 'Inscription__nameMaj__RemoteService.java'.
- The method changes the start index value to : start = end + DELIMITER.length() + 1; So the start index is now : 14+2+1=17
- For the second property {{\_\_nameMaj\_\_}} the method looks for the start delimiter index from the new start index (17). But the delimiter for the property {{\_\_nameMaj\_\_}} is at the index 11 so the property {{\_\_nameMaj\_\_}} is never found nor replaced.
To fix this issue, we have to replace the line 403 in the file org.apache.maven.archetype.generator.DefaultFilesetArchetypeGenerator from :
{code:java}
start = end + DELIMITER.length() + 1;
{code}
to :
{code:java}
start = start +contextPropertyValue.length();
{code}
contextPropertyValue being the value of the propety 'int1FirstMaj' which is 'Inscription'. The new start index becomes 0+11=11 and the next property {{\_\_nameMaj\_\_}} will be found and replaced.
was:
Hello,
In a maven archetype we can use properties in filepaths which are replaced when the archetype is generated.
e.g.:
Properties :
- int1FirstMaj = Inscription
- nameMaj = TEST
filepath = __int1FirstMaj____nameMaj__RemoteService.java
The method DefaultFilesetArchetypeGenerator.replaceFilenameTokens(final String filePath, final Context context) use the delimiter '__' to replace the properties.
So, after the build, my filepath should be : InscriptionTESTRemoteService.java
The problem is the following:
- The method looks for the start delimiter index which is 0 in my exemple and the end delimiter index which is 14.
- It replaces '__int1FirstMaj__' with 'Inscription'. My filepath is now 'Inscription__nameMaj__RemoteService.java'.
- The method changes the start index value to : start = end + DELIMITER.length() + 1; So the start index is now : 14+2+1=17
- For the second property '__nameMaj__' the method looks for the start delimiter index from the new start index (17). But the delimiter for the property '__nameMaj__' is at the index 11 so the property '__nameMaj__' is never found nor replaced.
To fix this issue, we have to replace the line 403 in the file org.apache.maven.archetype.generator.DefaultFilesetArchetypeGenerator from :
start = end + DELIMITER.length() + 1;
to :
start = start +contextPropertyValue.length();
contextPropertyValue being the value of the propety 'int1FirstMaj' which is 'Inscription'. The new start index becomes 0+11=11 and the next property '__nameMaj__' will be found and replaced.
> method DefaultFilesetArchetypeGenerator.replaceFilenameTokens(final String filePath, final Context context) doesn't work when two tokens are close to each other
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: ARCHETYPE-400
> URL: https://issues.apache.org/jira/browse/ARCHETYPE-400
> Project: Maven Archetype
> Issue Type: Bug
> Components: Generator
> Affects Versions: 2.1, 2.2, 2.3
> Reporter: Romain Douet
> Priority: Minor
> Labels: GoodForNewContributors
>
> Hello,
> In a maven archetype we can use properties in filepaths which are replaced when the archetype is generated.
> e.g.:
> Properties :
> * int1FirstMaj = Inscription
> * nameMaj = TEST
> {code:java}
> filepath = __int1FirstMaj____nameMaj__RemoteService.java
> {code}
> The method {{DefaultFilesetArchetypeGenerator.replaceFilenameTokens(final String filePath, final Context context)}} use the delimiter '{{\_\_}}' to replace the properties.
> So, after the build, my filepath should be : {{InscriptionTESTRemoteService.java}}
> The problem is the following:
> - The method looks for the start delimiter index which is 0 in my exemple and the end delimiter index which is 14.
> - It replaces {{\_\_int1FirstMaj\_\_}} with 'Inscription'. My filepath is now 'Inscription__nameMaj__RemoteService.java'.
> - The method changes the start index value to : start = end + DELIMITER.length() + 1; So the start index is now : 14+2+1=17
> - For the second property {{\_\_nameMaj\_\_}} the method looks for the start delimiter index from the new start index (17). But the delimiter for the property {{\_\_nameMaj\_\_}} is at the index 11 so the property {{\_\_nameMaj\_\_}} is never found nor replaced.
>
> To fix this issue, we have to replace the line 403 in the file org.apache.maven.archetype.generator.DefaultFilesetArchetypeGenerator from :
> {code:java}
> start = end + DELIMITER.length() + 1;
> {code}
> to :
> {code:java}
> start = start +contextPropertyValue.length();
> {code}
>
> contextPropertyValue being the value of the propety 'int1FirstMaj' which is 'Inscription'. The new start index becomes 0+11=11 and the next property {{\_\_nameMaj\_\_}} will be found and replaced.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)