]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/Clone.java
1. Fix EDKT457 Multiple FPD, MSA or SPD files in a directory is prohibited
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / Clone.java
index 3395434efda5ceef6da95a1f79772f14b5633990..d8030f775ac5cbe6803718133d4aae2564595271 100644 (file)
@@ -376,9 +376,31 @@ public class Clone extends IDialog {
             this.jLabelBelong.setEnabled(false);\r
             this.jComboBoxExistingPackage.setEnabled(false);\r
             this.jButtonBrowse.setVisible(false);\r
-            this.jTextFieldFilePath.setToolTipText("<html>Input the package's relative path and file name, for example:<br>MdePkg\\MdePkg.spd</html>");\r
+            this.jTextFieldFilePath\r
+                                   .setToolTipText("<html>Input the package's relative path and file name, for example:<br>MdePkg\\MdePkg.spd</html>");\r
             this.jTextFieldFilePath.setSize(320, this.jTextFieldFilePath.getSize().height);\r
             this.jLabelDestinationFile.setText("New Package Path and Filename");\r
+\r
+            //\r
+            // Check if the package can be cloned\r
+            //\r
+            PackageSurfaceArea spd = GlobalData.openingPackageList\r
+                                                                  .getPackageSurfaceAreaFromId(GlobalData.openingPackageList\r
+                                                                                                                            .getIdByPath(this.oldId\r
+                                                                                                                                                   .getPath()));\r
+            if (spd != null) {\r
+                if (spd.getPackageDefinitions() != null) {\r
+                    if (!spd.getPackageDefinitions().getRePackage()) {\r
+                        Log.wrn("Clone Package", "This package can't repackaged and cloned");\r
+                        this.jTextFieldBaseName.setEnabled(false);\r
+                        this.jTextFieldFilePath.setEnabled(false);\r
+                        this.jTextFieldGuid.setEnabled(false);\r
+                        this.jTextFieldVersion.setEnabled(false);\r
+                        this.jButtonGenerateGuid.setEnabled(false);\r
+                        this.jButtonOk.setEnabled(false);\r
+                    }\r
+                }\r
+            }\r
         }\r
         //\r
         // For PLATFORM_SURFACE_AREA\r
@@ -407,7 +429,8 @@ public class Clone extends IDialog {
             this.jButtonGenerateGuid.setEnabled(false);\r
             this.jLabelVersion.setEnabled(false);\r
             this.jTextFieldVersion.setEnabled(false);\r
-            this.jTextFieldFilePath.setToolTipText("<html>Input the workspace path, for example:<br>C:\\MyWorkspace</html>");\r
+            this.jTextFieldFilePath\r
+                                   .setToolTipText("<html>Input the workspace path, for example:<br>C:\\MyWorkspace</html>");\r
             this.jLabelDestinationFile.setText("New Workspace Path");\r
         }\r
     }\r
@@ -546,42 +569,77 @@ public class Clone extends IDialog {
      @retval false  Any one of name, guid and version is invalid\r
      \r
      **/\r
-    private boolean checkId() {\r
+    private boolean checkId(int mode) {\r
+        String name = this.jTextFieldBaseName.getText();\r
+        String guid = this.jTextFieldGuid.getText();\r
+        String version = this.jTextFieldVersion.getText();\r
+        \r
         //\r
         // Check Basename\r
         //\r
-        if (isEmpty(this.jTextFieldBaseName.getText())) {\r
+        if (isEmpty(name)) {\r
             Log.wrn("Clone", "The Name is required!");\r
             return false;\r
         }\r
-        if (!DataValidation.isBaseName(this.jTextFieldBaseName.getText())) {\r
-            Log.wrn("Clone", "<html>Incorrect data type for the Name, it must<br>be a single word, starting with an alpha character.</html>");\r
+        if (!DataValidation.isBaseName(name)) {\r
+            Log\r
+               .wrn("Clone",\r
+                    "<html>Incorrect data type for the Name, it must<br>be a single word, starting with an alpha character.</html>");\r
             return false;\r
         }\r
 \r
         //\r
         // Check Guid\r
         //\r
-        if (isEmpty(this.jTextFieldGuid.getText())) {\r
+        if (isEmpty(guid)) {\r
             Log.wrn("Clone", "A Guid is required!!");\r
             return false;\r
         }\r
-        if (!DataValidation.isGuid(this.jTextFieldGuid.getText())) {\r
-            Log.wrn("Clone", "<html>Incorrect data type for Guid, which must<br>be in registry format (8-4-4-4-12) for example:<br>d3adb123-eef1-466d-39ac-02febcaf5997</html>");\r
+        if (!DataValidation.isGuid(guid)) {\r
+            Log\r
+               .wrn(\r
+                    "Clone",\r
+                    "<html>Incorrect data type for Guid, which must<br>be in registry format (8-4-4-4-12) for example:<br>d3adb123-eef1-466d-39ac-02febcaf5997</html>");\r
             return false;\r
         }\r
 \r
         //\r
         // Check Version\r
         //\r
-        if (isEmpty(this.jTextFieldVersion.getText())) {\r
+        if (isEmpty(version)) {\r
             Log.wrn("Clone", "A Version must be entered!");\r
             return false;\r
         }\r
-        if (!DataValidation.isVersion(this.jTextFieldVersion.getText())) {\r
-            Log.wrn("Clone", "<html>Incorrect data type for Version, which must<br>be one or more digits, optionally followed by sequence<br>of one or more dot,  one or more digits; examples:<br>1.0 1.0.1 12.25.256</html>");\r
+        if (!DataValidation.isVersion(version)) {\r
+            Log\r
+               .wrn(\r
+                    "Clone",\r
+                    "<html>Incorrect data type for Version, which must<br>be one or more digits, optionally followed by sequence<br>of one or more dot,  one or more digits; examples:<br>1.0 1.0.1 12.25.256</html>");\r
             return false;\r
         }\r
+        \r
+        if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r
+            String packageGuid = packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()).getGuid();\r
+            String packageVersion = packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()).getVersion();\r
+            if (GlobalData.findModuleIdByGuidVersion(guid, version, packageGuid, packageVersion) != null) {\r
+                Log.wrn("Clone", "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
+            if (GlobalData.findPackageIdByGuidVersion(guid, version) != null) {\r
+                Log.wrn("Clone", "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
+            if (GlobalData.findPlatformIdByGuidVersion(guid, version) != null) {\r
+                Log.wrn("Clone", "A platform with same Guid and same Version already exists, please selece a new Guid or Version!");\r
+                return false;\r
+            }\r
+        }\r
 \r
         //\r
         // Save information to id\r
@@ -642,7 +700,7 @@ public class Clone extends IDialog {
         //\r
         if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r
             trg = this.getModulePath();\r
-            if (src.equals(trg)) {\r
+            if (Tools.getFilePathOnly(src).equals(Tools.getFilePathOnly(trg))) {\r
                 Log.wrn("Clone", "The source and destination paths for cloning a module must be different!");\r
                 return false;\r
             }\r
@@ -651,7 +709,7 @@ public class Clone extends IDialog {
                 Log.wrn("Clone", "The target module already exists!");\r
                 return false;\r
             }\r
-            return checkId();\r
+            return checkId(mode);\r
         }\r
 \r
         //\r
@@ -672,7 +730,7 @@ public class Clone extends IDialog {
                 Log.wrn("Clone", "The target package already exists!");\r
                 return false;\r
             }\r
-            return checkId();\r
+            return checkId(mode);\r
         }\r
 \r
         //\r
@@ -683,12 +741,16 @@ public class Clone extends IDialog {
                 Log.wrn("Clone", "The platform clone must be located in the current workspace!");\r
                 return false;\r
             }\r
+            if (Tools.getFilePathOnly(src).equals(Tools.getFilePathOnly(trg))) {\r
+                Log.wrn("Clone", "The source and destination paths for cloning a platform must be different!");\r
+                return false;\r
+            }\r
             trgFile = new File(trg);\r
             if (trgFile.exists()) {\r
                 Log.wrn("Clone", "The target platform already exists.");\r
                 return false;\r
             }\r
-            return checkId();\r
+            return checkId(mode);\r
         }\r
 \r
         return true;\r
@@ -726,13 +788,29 @@ public class Clone extends IDialog {
             newId.setPath(trg);\r
             vFiles = wt.getAllFilesPathOfModule(src);\r
 \r
+            String oldPackagePath = GlobalData.openingModuleList.getIdByPath(src).getPackageId().getPath();\r
+            String newPackagePath = packages.elementAt(this.jComboBoxExistingPackage.getSelectedIndex()).getPath();\r
+\r
             //\r
             // First copy all files to new directory\r
             //\r
             FileOperation.copyFile(src, trg);\r
             for (int index = 1; index < vFiles.size(); index++) {\r
                 String oldFile = vFiles.get(index);\r
-                String newFile = vFiles.get(index).replace(Tools.getFilePathOnly(src), Tools.getFilePathOnly(trg));\r
+                String newFile = "";\r
+                if (oldFile.indexOf(Tools.getFilePathOnly(src)) > -1) {\r
+                    //\r
+                    // The file is not include header\r
+                    //\r
+                    newFile = oldFile.replace(Tools.getFilePathOnly(src), Tools.getFilePathOnly(trg));\r
+                } else if (oldFile.indexOf(Tools.getFilePathOnly(oldPackagePath)) > -1) {\r
+                    //\r
+                    // The file is include header\r
+                    //\r
+                    newFile = oldFile.replace(Tools.getFilePathOnly(oldPackagePath),\r
+                                              Tools.getFilePathOnly(newPackagePath));\r
+                }\r
+\r
                 FileOperation.copyFile(oldFile, newFile);\r
             }\r
 \r
@@ -753,7 +831,7 @@ public class Clone extends IDialog {
             // Update <Cloned> Section\r
             //\r
             updateModuleClonedId(msa, oldId);\r
-            \r
+\r
             //\r
             // Save to file\r
             //\r
@@ -775,7 +853,7 @@ public class Clone extends IDialog {
             // Update the db file\r
             //\r
             wt.addModuleToPackage(mid, psa);\r
-            \r
+\r
             //\r
             // Update GlobalData\r
             //\r
@@ -838,20 +916,20 @@ public class Clone extends IDialog {
             // Update the db file\r
             //\r
             wt.addPackageToDatabase(pid);\r
-            \r
+\r
             //\r
             // Update GlobalData\r
             //\r
             GlobalData.vPackageList.addElement(pid);\r
             GlobalData.openingPackageList.insertToOpeningPackageList(pid, spd);\r
-            \r
+\r
             //\r
             // Add all cloned modules\r
             //\r
             Vector<String> modulePaths = GlobalData.getAllModulesOfPackage(pid.getPath());\r
             String modulePath = null;\r
             ModuleSurfaceArea msa = null;\r
-            \r
+\r
             for (int indexJ = 0; indexJ < modulePaths.size(); indexJ++) {\r
                 try {\r
                     modulePath = modulePaths.get(indexJ);\r
@@ -871,7 +949,7 @@ public class Clone extends IDialog {
                 GlobalData.vModuleList.addElement(mid);\r
                 GlobalData.openingModuleList.insertToOpeningModuleList(mid, msa);\r
             }\r
-            \r
+\r
             this.returnType = DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA;\r
         }\r
 \r
@@ -908,7 +986,7 @@ public class Clone extends IDialog {
             // Update the db file\r
             //\r
             wt.addPlatformToDatabase(fid);\r
-            \r
+\r
             //\r
             // Update GlobalData\r
             //\r