]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/SelectModuleBelong.java
1. Fix EDKT463: When wizard new or clone a msa/spd/fpd, should follow these rules
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / SelectModuleBelong.java
index da971b9fa67a95a263eb7c418b03a468ca95887b..a052b74d3e70d002d45cbe2fbd2c956a7be30fe4 100644 (file)
@@ -37,6 +37,7 @@ import org.tianocore.PlatformHeaderDocument.PlatformHeader;
 import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;\r
 import org.tianocore.frameworkwizard.common.DataType;\r
 import org.tianocore.frameworkwizard.common.DataValidation;\r
+import org.tianocore.frameworkwizard.common.GlobalData;\r
 import org.tianocore.frameworkwizard.common.IFileFilter;\r
 import org.tianocore.frameworkwizard.common.Log;\r
 import org.tianocore.frameworkwizard.common.SaveFile;\r
@@ -475,10 +476,14 @@ public class SelectModuleBelong extends IDialog {
      \r
      **/\r
     public boolean check() {\r
+        String path = this.jTextFieldFilePath.getText();\r
+        String guid = this.jTextFieldGuid.getText();\r
+        String version = this.jTextFieldVersion.getText();\r
+        \r
         //\r
         // Check if all required fields are not empty\r
         //\r
-        if (isEmpty(this.jTextFieldFilePath.getText())) {\r
+        if (isEmpty(path)) {\r
             Log.wrn("New File", "A File Path must be entered!");\r
             return false;\r
         }\r
@@ -486,11 +491,11 @@ public class SelectModuleBelong extends IDialog {
             Log.wrn("New File", "A Name must be entered");\r
             return false;\r
         }\r
-        if (isEmpty(this.jTextFieldGuid.getText())) {\r
+        if (isEmpty(guid)) {\r
             Log.wrn("New File", "The Guid must be entered!");\r
             return false;\r
         }\r
-        if (isEmpty(this.jTextFieldVersion.getText())) {\r
+        if (isEmpty(version)) {\r
             Log.wrn("New File", "A Version number must be entered!");\r
             return false;\r
         }\r
@@ -502,17 +507,19 @@ public class SelectModuleBelong extends IDialog {
             Log.wrn("New File", "Incorrect data type for the Name!");\r
             return false;\r
         }\r
-        if (!DataValidation.isGuid((this.jTextFieldGuid).getText())) {\r
+        if (!DataValidation.isGuid((guid))) {\r
             Log.wrn("New File", "Incorrect data type for Guid, which must be in registry format! (8-4-4-4-12)");\r
             return false;\r
         }\r
+        \r
+\r
 \r
         if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r
             //\r
             // Check if the module is already existed in current package\r
             //\r
             String packagePath = packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()).getPath();\r
-            String modulePath = Tools.convertPathToCurrentOsType(this.jTextFieldFilePath.getText());\r
+            String modulePath = Tools.convertPathToCurrentOsType(path);\r
             Vector<String> msaFile = wt.getAllModulesOfPackage(packagePath);\r
 \r
             for (int index = 0; index < msaFile.size(); index++) {\r
@@ -521,13 +528,31 @@ public class SelectModuleBelong extends IDialog {
                     return false;\r
                 }\r
             }\r
+            \r
+            //\r
+            // Check if path already exists\r
+            //\r
+            if (GlobalData.isDuplicateRelativePath(Tools.getFilePathOnly(modulePath), mode)) {\r
+                Log.wrn("New File", "There already exists a same directory with a module");\r
+                return false;\r
+            }\r
+            \r
+            //\r
+            // Check if Guid+Version is unique\r
+            //\r
+            String packageGuid = packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()).getGuid();\r
+            String packageVersion = packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()).getVersion();\r
+            if (GlobalData.findModuleId(guid, version, packageGuid, packageVersion) != null) {\r
+                Log.wrn("New File", "A module with same Guid and same Version already exists, please selece a new Guid or Version!");\r
+                return false;\r
+            }\r
         }\r
 \r
         if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {\r
             //\r
             // Check if the package is already existed in database\r
             //\r
-            String path = Tools.convertPathToCurrentOsType(this.jTextFieldFilePath.getText());\r
+            path = Tools.convertPathToCurrentOsType(path);\r
             Vector<PackageIdentification> vPackageList = wt.getAllPackages();\r
             if (vPackageList != null && vPackageList.size() > 0) {\r
                 for (int index = 0; index < vPackageList.size(); index++) {\r
@@ -537,13 +562,29 @@ public class SelectModuleBelong extends IDialog {
                     }\r
                 }\r
             }\r
+            \r
+            //\r
+            // Check if path already exists\r
+            //\r
+            if (GlobalData.isDuplicateRelativePath(Tools.getFilePathOnly(path), mode)) {\r
+                Log.wrn("New File", "There already exists a same directory with a package");\r
+                return false;\r
+            }\r
+            \r
+            //\r
+            // Check if Guid+Version is unique\r
+            //\r
+            if (GlobalData.findPackageId(guid, version) != null) {\r
+                Log.wrn("New File", "A package with same Guid and same Version already exists, please selece a new Guid or Version!");\r
+                return false;\r
+            }\r
         }\r
 \r
         if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {\r
             //\r
             // Check if the platform is already existed in database\r
             //\r
-            String path = Tools.convertPathToCurrentOsType(this.jTextFieldFilePath.getText());\r
+            path = Tools.convertPathToCurrentOsType(path);\r
             Vector<PlatformIdentification> vPlatfromList = wt.getAllPlatforms();\r
             if (vPlatfromList != null && vPlatfromList.size() > 0) {\r
                 for (int index = 0; index < vPlatfromList.size(); index++) {\r
@@ -553,6 +594,22 @@ public class SelectModuleBelong extends IDialog {
                     }\r
                 }\r
             }\r
+            \r
+            //\r
+            // Check if path already exists\r
+            //\r
+            if (GlobalData.isDuplicateRelativePath(Tools.getFilePathOnly(path), mode)) {\r
+                Log.wrn("New File", "There already exists a same directory with a platform");\r
+                return false;\r
+            }\r
+            \r
+            //\r
+            // Check if Guid+Version is unique\r
+            //\r
+            if (GlobalData.findPlatformId(guid, version) != null) {\r
+                Log.wrn("New File", "A platform with same Guid and same Version already exists, please selece a new Guid or Version!");\r
+                return false;\r
+            }\r
         }\r
 \r
         return true;\r