Hi Jessica,

What is the issue that Time found you are referring to ?

Regarding the way you found to allow creating projects with invalid names, this 
comes from the org.eclipse.cdt.core.templates, and in my opinion is a bug. 
What happens is that the template arguments, in our case the project name, is 
resolved the first time we press finish, with the invalid name we have set. 
When we receive an error and choose to go back, and change the project name to 
yet a new invalid project name, the argument of the template(project name), is 
not updated(for some sort of cache reasons) and thus by using the old project 
name, it surpasses the exception received in the first case.
I will open a bug for this on the cdt bugzilla.

Thanks,
Ioana

________________________________________
From: Zhang, Jessica
Sent: Friday, March 15, 2013 2:06 AM
To: Grigoropol, IoanaX; yocto@yoctoproject.org
Subject: RE: [yocto] [PATCH v2] [eclipse-poky][master]Add more comprehensive    
error message for invalid project name

Hi Ioana,

This patch still can't address the situation that found by Timo as following....

Thanks,
Jessica

I forgot to mention. I found a way to create projects with invalid names.

# Create a new Yocto C Project
# Enter a wrong name eg. Test"
# Press next
# Press finish
# --> Error Message is shown, press ok
# Press back
# Change the name to an also invalid name eg. Test$ # Click finish

-----Original Message-----
From: yocto-boun...@yoctoproject.org [mailto:yocto-boun...@yoctoproject.org] On 
Behalf Of Ioana Grigoropol
Sent: Thursday, March 14, 2013 4:50 AM
To: yocto@yoctoproject.org
Subject: [yocto] [PATCH v2] [eclipse-poky][master]Add more comprehensive error 
message for invalid project name

[Yocto #4008]

Signed-off-by: Ioana Grigoropol <ioanax.grigoro...@intel.com>
---
 .../org/yocto/sdk/ide/YoctoSDKMessages.properties  |    1 +
 .../sdk/ide/wizard/NewYoctoCProjectTemplate.java   |   27 ++++++++++++++++----
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git 
a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.properties 
b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.properties
index 8596123..fc9813f 100644
--- 
a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.properties
+++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.p
+++ roperties
@@ -10,6 +10,7 @@
  * BMW Car IT - added keys for target profiles
  
*******************************************************************************/
 Wizard.SDK.Warning.Title = Invalid Yocto Project ADT Location
+Wizard.SDK.Error.ProjecName = Project name "{0}" is invalid! \nNone of
+these characters are accepted inside project names: whitespaces, {1}

 Poky.SDK.Location.Empty = Specified Toolchain Root Location is empty.
 Poky.SDK.Location.Empty.Advice = You need specify Toolchain Root Location 
before building any project.
diff --git 
a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoCProjectTemplate.java
 
b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoCProjectTemplate.java
index 5ffd6b7..4d1684a 100644
--- 
a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoCProjectTemplate.java
+++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoCPr
+++ ojectTemplate.java
@@ -10,8 +10,11 @@
  
*******************************************************************************/
 package org.yocto.sdk.ide.wizard;

+import java.util.Arrays;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;

 import org.eclipse.cdt.autotools.core.AutotoolsNewProjectNature;
 import org.eclipse.cdt.core.CCorePlugin; @@ -46,11 +49,12 @@ import 
org.yocto.sdk.ide.YoctoProfileElement;
 import org.yocto.sdk.ide.YoctoSDKChecker;
 import org.yocto.sdk.ide.YoctoSDKChecker.SDKCheckRequestFrom;
 import org.yocto.sdk.ide.YoctoSDKChecker.SDKCheckResults;
+import org.yocto.sdk.ide.YoctoSDKMessages;
+import org.yocto.sdk.ide.YoctoSDKPlugin; import
+org.yocto.sdk.ide.YoctoUIElement;
 import org.yocto.sdk.ide.natures.YoctoSDKEmptyProjectNature;
 import org.yocto.sdk.ide.natures.YoctoSDKProjectNature;
 import org.yocto.sdk.ide.utils.YoctoSDKUtils;
-import org.yocto.sdk.ide.YoctoSDKPlugin; -import 
org.yocto.sdk.ide.YoctoUIElement;


 @SuppressWarnings("restriction")
@@ -58,11 +62,19 @@ public class NewYoctoCProjectTemplate extends ProcessRunner 
{
        protected boolean savedAutoBuildingValue;
        protected ProjectCreatedActions pca;
        protected IManagedBuildInfo info;
+       protected List<Character> illegalChars = Arrays.asList('$', 
'"','#','%','&','\'','(',')','*', '+', 
',','.','/',':',';','<','=','>','?','@','[','\\',']','^','`','{','|','}','~');
+       private static final String PROJECT_NAME_ERROR =
+"Wizard.SDK.Error.ProjecName";

        public NewYoctoCProjectTemplate() {
                pca = new ProjectCreatedActions();
        }
-
+       private String printIllegalChars(){
+               String print = "";
+               for (Character ch : illegalChars)
+                       print += ch + ", ";
+               print = print.substring(0, print.length() - 2);
+               return print;
+       }
        public void process(TemplateCore template, ProcessArgument[] args, 
String processId, IProgressMonitor monitor) throws ProcessFailureException {

                String projectName = args[0].getSimpleValue(); @@ -74,9 +86,9 
@@ public class NewYoctoCProjectTemplate extends ProcessRunner {
                boolean isEmptryProject = 
Boolean.valueOf(isEmptyProjetValue).booleanValue();
                IProject project = 
ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
                try {
-                       if (projectName.contains(" ")) {
+                       if (!isValidProjectName(projectName)) {
                                project.delete(true, null);
-                               throw new ProcessFailureException(projectName + 
" contains space(s).  Project name can't contain space(s)");
+                               throw new
+ProcessFailureException(YoctoSDKMessages.getFormattedString(PROJECT_NAM
+E_ERROR, new Object[]{projectName, printIllegalChars()}));
                        }
                        if (!project.exists()) {
                                IWorkspace workspace = 
ResourcesPlugin.getWorkspace(); @@ -166,6 +178,11 @@ public class 
NewYoctoCProjectTemplate extends ProcessRunner {
                        throw new 
OperationCanceledException(Messages.getString("NewManagedProject.3") + 
e.getMessage());
                }
        }
+       private boolean isValidProjectName(String projectName) {
+               Pattern pattern = Pattern.compile("^[a-zA-Z][a-zA-Z0-9_\\-]*$");
+               Matcher matcher = pattern.matcher(projectName);
+               return matcher.find();
+}

        protected final void turnOffAutoBuild(IWorkspace workspace) throws 
CoreException {
                IWorkspaceDescription workspaceDesc = 
workspace.getDescription();
--
1.7.9.5

_______________________________________________
yocto mailing list
yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/yocto
_______________________________________________
yocto mailing list
yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/yocto

Reply via email to