Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Fix #1312 : Container name should not be generated from maven group Id #1321

Merged
merged 1 commit into from
Jul 30, 2018

Conversation

rohanKanojia
Copy link
Member

@rohanKanojia
Copy link
Member Author

@nicolaferraro @hrishin : Could you please review whenever you get time?

Copy link
Member

@hrishin hrishin left a comment

Choose a reason for hiding this comment

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

thanks, @rohanKanojia.

return projectGroupId;
}
else {
return projectGroupId.replaceAll("[^a-zA-Z0-9]", "");
Copy link
Member

Choose a reason for hiding this comment

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

the regex [^a-zA-Z0-9] would also replace - which is desired?

return projectGroupId;
}
else {
return projectGroupId.replaceAll("[^a-zA-Z0-9-]", "");
Copy link
Contributor

Choose a reason for hiding this comment

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

This replacement still does not ensure that a name does not start or end with a -. Ok, a groupId propably never starts with a minus, but maybe it could end with one ?

I would add something like .replace("^-*(.*)-*$","\\1") ...

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, please correct me if I'm wrong. I tested my regex with groupId ending with a -, I think it handles. Plus how does your regex trims . from groupId? Does replace work with regex? I tried your regex with replaceAll but it seems to be replacing everything with 1

Copy link
Contributor

Choose a reason for hiding this comment

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

@rohanKanojia I mean to add the regexp I suggest in addition to yours of course (and it was not tested, therefore that something like ...)

projectGroupId.replaceAll("[^a-zA-Z0-9-]", "").replaceFirst("^-*(.*)-*$","\\1")

The idea is to remove leading and trailing - from the name as these are not allowed.

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

A minor comment but otherwise looks good to me.

@rhuss
Copy link
Contributor

rhuss commented Jul 19, 2018

@hrishin if the fix is good enough for you, could you please approve the PR ? thx!

@rohanKanojia rohanKanojia added the pr/change-requested Reviewer requested a change label Jul 24, 2018
}
else {
return projectGroupId.replaceAll("[^a-zA-Z0-9-]", "")
.replaceFirst("^-", "\\1")
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure that this works ? You have no capturing group, so what should \1 refer to ? Actually you could use .replaceAll("^-*","") if you want to do it two steps.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tested it on groupIds like io.fabric8-test-, io.fabric8-test- and -io.fabric8-test-, Sorry I'm not an expert of regexes so might be doing some mistake. We can replace - with any character in the desired container characters range, I just thought replacing it with 1. Since you also suggested this in previous comment.

I tried your regex also i.e projectGroupId.replaceAll("[^a-zA-Z0-9-]", "").replaceFirst("^-*(.*)-*$","\\1") but it seems to be replacing everything with 1

Copy link
Contributor

@rhuss rhuss Jul 24, 2018

Choose a reason for hiding this comment

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

No, that \1 references the content of the capturing group in the previous expression (...). Its not "1" literally ;). Let me suggest a working solution and push it to your branch ...

Copy link
Contributor

Choose a reason for hiding this comment

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

If you are interested how this works, look for "regular expression capturing group"

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

Please fix the regexp (happy to help if its too complicated).

@rhuss rhuss self-assigned this Jul 24, 2018
@rohanKanojia rohanKanojia added the target/3.5 PR targeted to 3.5 label Jul 24, 2018
.name("test")
.build();
String containerName = KubernetesResourceUtil.extractContainerName(project, imageConfiguration);
assertTrue(containerName.matches(KubernetesResourceUtil.CONTAINER_NAME_REGEX));
Copy link
Contributor

Choose a reason for hiding this comment

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

assertj is already in classpath why not starting writing assertions using it?

@rhuss rhuss removed the pr/change-requested Reviewer requested a change label Jul 30, 2018
@rhuss
Copy link
Contributor

rhuss commented Jul 30, 2018

Looks good, thanks a lot ! And sorry for the confusion ...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
target/3.5 PR targeted to 3.5
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants