X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=sidebyside;f=Tools%2FSource%2FFrameworkWizard%2Fsrc%2Forg%2Ftianocore%2Fframeworkwizard%2Fworkspace%2FWorkspaceTools.java;h=dda8844495e07b054947554a0aac52a34e713343;hb=5a24e806b0d343b2a847996f4758ed2a06a363fb;hp=c6432ac284ab4902f34b38ce3033fb71e5f4ea1b;hpb=a13899c5acad2f5e125abdae972b4c3d1e522f69;p=mirror_edk2.git diff --git a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/workspace/WorkspaceTools.java b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/workspace/WorkspaceTools.java index c6432ac284..dda8844495 100644 --- a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/workspace/WorkspaceTools.java +++ b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/workspace/WorkspaceTools.java @@ -14,26 +14,33 @@ **/ package org.tianocore.frameworkwizard.workspace; +import java.io.File; import java.io.IOException; +import java.util.List; import java.util.Vector; +import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlException; import org.tianocore.DbPathAndFilename; -import org.tianocore.FrameworkDatabaseDocument; +import org.tianocore.FrameworkDatabaseDocument.FrameworkDatabase; +import org.tianocore.IndustryStdIncludesDocument.IndustryStdIncludes; import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea; import org.tianocore.MsaFilesDocument.MsaFiles; import org.tianocore.MsaHeaderDocument.MsaHeader; import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea; import org.tianocore.PlatformHeaderDocument.PlatformHeader; import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea; +import org.tianocore.SourceFilesDocument.SourceFiles; import org.tianocore.SpdHeaderDocument.SpdHeader; import org.tianocore.frameworkwizard.common.DataType; -import org.tianocore.frameworkwizard.common.Identification; import org.tianocore.frameworkwizard.common.Log; -import org.tianocore.frameworkwizard.common.OpenFile; import org.tianocore.frameworkwizard.common.SaveFile; import org.tianocore.frameworkwizard.common.Tools; -import org.tianocore.frameworkwizard.module.Identification.ModuleIdentification; +import org.tianocore.frameworkwizard.common.Identifications.Identification; +import org.tianocore.frameworkwizard.common.Identifications.OpenFile; +import org.tianocore.frameworkwizard.far.FarHeader; +import org.tianocore.frameworkwizard.far.FarIdentification; +import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification; import org.tianocore.frameworkwizard.packaging.PackageIdentification; import org.tianocore.frameworkwizard.platform.PlatformIdentification; @@ -41,7 +48,7 @@ public class WorkspaceTools { // // Define class members // - private FrameworkDatabaseDocument.FrameworkDatabase fdb = null; + private FrameworkDatabase fdb = null; private Vector vModuleList = new Vector(); @@ -54,20 +61,147 @@ public class WorkspaceTools { Open Framework Database file */ - private void openFrameworkDb() { + private FrameworkDatabase openFrameworkDb() { String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile(); strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath); try { fdb = OpenFile.openFrameworkDb(strFrameworkDbFilePath); } catch (XmlException e) { Log.err("Open Framework Database " + strFrameworkDbFilePath, e.getMessage()); - return; + return null; } catch (Exception e) { Log.err("Open Framework Database " + strFrameworkDbFilePath, "Invalid file type"); - return; + return null; } + return fdb; } + public void addFarToDb(List packageList, List platformList, FarHeader far) { + FrameworkDatabase fdb = openFrameworkDb(); + + for (int i = 0; i < packageList.size(); i++) { + DbPathAndFilename item = DbPathAndFilename.Factory.newInstance(); + item.setFarGuid(far.getGuidValue()); + item.setStringValue(packageList.get(i)); + fdb.getPackageList().getFilenameList().add(item); + } + + for (int i = 0; i < platformList.size(); i++) { + DbPathAndFilename item = DbPathAndFilename.Factory.newInstance(); + item.setFarGuid(far.getGuidValue()); + item.setStringValue(platformList.get(i)); + fdb.getPlatformList().getFilenameList().add(item); + } + + DbPathAndFilename farItem = DbPathAndFilename.Factory.newInstance(); + farItem.setFarGuid(far.getGuidValue()); + farItem.setStringValue(far.getFarName()); + fdb.getFarList().getFilenameList().add(farItem); + + String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile(); + strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath); + + try { + SaveFile.saveDbFile(strFrameworkDbFilePath, fdb); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + + public void removeFarFromDb(FarIdentification far) { + FrameworkDatabase fdb = openFrameworkDb(); + // + // Remove Packages + // + XmlCursor cursor = fdb.getPackageList().newCursor(); + cursor.toFirstChild(); + do { + DbPathAndFilename item = (DbPathAndFilename)cursor.getObject(); + + if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) { + cursor.removeXml(); + } + } while (cursor.toNextSibling()); + cursor.dispose(); + + // + // Remove Platforms + // + cursor = fdb.getPlatformList().newCursor(); + cursor.toFirstChild(); + do { + DbPathAndFilename item = (DbPathAndFilename)cursor.getObject(); + if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) { + cursor.removeXml(); + } + } while (cursor.toNextSibling()); + + // + // Remove Far + // + cursor = fdb.getFarList().newCursor(); + cursor.toFirstChild(); + do { + DbPathAndFilename item = (DbPathAndFilename)cursor.getObject(); + if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) { + cursor.removeXml(); + } + } while (cursor.toNextSibling()); + cursor.dispose(); + + String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile(); + strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath); + try { + SaveFile.saveDbFile(strFrameworkDbFilePath, fdb); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + public String getPackageFarGuid(PackageIdentification packageId) { + openFrameworkDb(); + + for (int index = 0; index < fdb.getPackageList().getFilenameList().size(); index++) { + DbPathAndFilename item = fdb.getPackageList().getFilenameArray(index); + String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + + item.getStringValue(); + File tempFile = new File(path); + if (tempFile.getPath().equalsIgnoreCase(packageId.getSpdFile().getPath())) { + return fdb.getPackageList().getFilenameArray(index).getFarGuid(); + } + } + + return null; + } + + public String getPlatformFarGuid(PlatformIdentification platformId) { + openFrameworkDb(); + + for (int index = 0; index < fdb.getPlatformList().getFilenameList().size(); index++) { + DbPathAndFilename item = fdb.getPlatformList().getFilenameArray(index); + String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + + item.getStringValue(); + File tempFile = new File(path); + if (tempFile.getPath().equalsIgnoreCase(platformId.getFpdFile().getPath())) { + return fdb.getPlatformList().getFilenameArray(index).getFarGuid(); + } + } + + return null; + } + + public String getModuleFarGuid(ModuleIdentification moduleId) { + PackageIdentification packageId = getPackageIdByModuleId(moduleId); + if (packageId != null) { + return getPackageFarGuid(packageId); + } + else { + return null; + } + } /** Get all modules' paths from one package @@ -80,18 +214,49 @@ public class WorkspaceTools { MsaFiles files = OpenFile.openSpdFile(path).getMsaFiles(); if (files != null) { for (int index = 0; index < files.getFilenameList().size(); index++) { - modulePath.addElement(files.getFilenameList().get(index)); + String msaPath = files.getFilenameList().get(index); + msaPath = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + msaPath; + msaPath = Tools.convertPathToCurrentOsType(msaPath); + modulePath.addElement(msaPath); } } } catch (IOException e) { - e.printStackTrace(); + } catch (XmlException e) { - e.printStackTrace(); + } catch (Exception e) { - e.printStackTrace(); + } return modulePath; } + + /** + Get all Industry Std Includes' paths from one package + + @return a Vector with all paths + + **/ + public Vector getAllIndustryStdIncludesOfPackage(String path) { + Vector includePath = new Vector(); + try { + IndustryStdIncludes files = OpenFile.openSpdFile(path).getIndustryStdIncludes(); + if (files != null) { + for (int index = 0; index < files.getIndustryStdHeaderList().size(); index++) { + String temp = files.getIndustryStdHeaderList().get(index).getName(); + temp = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + temp; + temp = Tools.convertPathToCurrentOsType(temp); + includePath.addElement(temp); + } + } + } catch (IOException e) { + + } catch (XmlException e) { + + } catch (Exception e) { + + } + return includePath; + } /** Get all package basic information form the FrameworkDatabase.db file @@ -114,22 +279,126 @@ public class WorkspaceTools { vPackageList.addElement(new PackageIdentification(id)); } catch (IOException e) { Log.err("Open Package Surface Area " + path, e.getMessage()); - e.printStackTrace(); + } catch (XmlException e) { Log.err("Open Package Surface Area " + path, e.getMessage()); - e.printStackTrace(); + } catch (Exception e) { Log.err("Open Package Surface Area " + path, "Invalid file type"); - e.printStackTrace(); + } } + Tools.sortPackages(vPackageList, DataType.SORT_TYPE_ASCENDING); return vPackageList; } + public Vector getAllFars() { + openFrameworkDb(); + Vector v = new Vector(); + for (int index = 0; index < fdb.getFarList().getFilenameList().size(); index++) { + DbPathAndFilename item = fdb.getFarList().getFilenameList().get(index); + FarIdentification far = new FarIdentification(item.getFarGuid(), item.getMd5Sum(), item.getStringValue()); + v.addElement(far); + } + return v; + } + + public Vector getPackagesByFar(FarIdentification far) { + Identification id = null; + openFrameworkDb(); + Vector v = new Vector(); + + for (int index = 0; index < fdb.getPackageList().getFilenameList().size(); index++) { + DbPathAndFilename item = fdb.getPackageList().getFilenameArray(index); + String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + + item.getStringValue(); + path = Tools.convertPathToCurrentOsType(path); + + if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) { + + try { + id = getId(path, OpenFile.openSpdFile(path)); + v.addElement(new PackageIdentification(id)); + } catch (IOException e) { + Log.err("Open Package Surface Area " + path, e.getMessage()); + e.printStackTrace(); + } catch (XmlException e) { + Log.err("Open Package Surface Area " + path, e.getMessage()); + e.printStackTrace(); + } catch (Exception e) { + Log.err("Open Package Surface Area " + path, "Invalid file type"); + e.printStackTrace(); + } + } + } + return v; + } + + public Vector getPlatformsByFar(FarIdentification far) { + Identification id = null; + openFrameworkDb(); + Vector v = new Vector(); + + for (int index = 0; index < fdb.getPlatformList().getFilenameList().size(); index++) { + DbPathAndFilename item = fdb.getPlatformList().getFilenameArray(index); + String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + + item.getStringValue(); + path = Tools.convertPathToCurrentOsType(path); + + if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) { + try { + id = getId(path, OpenFile.openFpdFile(path)); + v.addElement(new PlatformIdentification(id)); + } catch (IOException e) { + Log.err("Open Platform Surface Area " + path, e.getMessage()); + e.printStackTrace(); + } catch (XmlException e) { + Log.err("Open Platform Surface Area " + path, e.getMessage()); + e.printStackTrace(); + } catch (Exception e) { + Log.err("Open Platform Surface Area " + path, "Invalid file type"); + e.printStackTrace(); + } + } + } + return v; + } + /** - Get all package basic information form the FrameworkDatabase.db file + Get all module basic information from a package + + @param id Package id + @return A vector includes all modules' basic information + + **/ + public Vector getAllModules(PackageIdentification pid) { + Vector v = new Vector(); + Vector modulePaths = this.getAllModulesOfPackage(pid.getPath()); + Identification id = null; + String modulePath = null; + + for (int index = 0; index < modulePaths.size(); index++) { + try { + modulePath = modulePaths.get(index); + id = getId(modulePath, OpenFile.openMsaFile(modulePath)); + } catch (IOException e) { + Log.log("Error when Open Module Surface Area " + modulePath, e.getMessage()); + } catch (XmlException e) { + Log.log("Error when Open Module Surface Area " + modulePath, e.getMessage()); + } catch (Exception e) { + Log.log("Error when Open Module Surface Area " + modulePath, "Invalid file type " + e.getMessage()); + } + v.addElement(new ModuleIdentification(id, pid)); + } + Tools.sortModules(v, DataType.SORT_TYPE_ASCENDING); + return v; + + } + + /** + Get all module basic information form the FrameworkDatabase.db file - @return vPackageList A vector includes all packages' basic information + @return vModuleList A vector includes all modules' basic information */ public Vector getAllModules() { @@ -149,26 +418,22 @@ public class WorkspaceTools { for (int indexI = 0; indexI < vPackageList.size(); indexI++) { packagePath = vPackageList.elementAt(indexI).getPath(); modulePaths = this.getAllModulesOfPackage(packagePath); - packagePath = packagePath.substring(0, packagePath.lastIndexOf(DataType.FILE_SEPARATOR) - + DataType.FILE_SEPARATOR.length()); + for (int indexJ = 0; indexJ < modulePaths.size(); indexJ++) { - modulePath = Tools.convertPathToCurrentOsType(packagePath + modulePaths.elementAt(indexJ)); try { + modulePath = modulePaths.get(indexJ); id = getId(modulePath, OpenFile.openMsaFile(modulePath)); vModuleList.addElement(new ModuleIdentification(id, vPackageList.elementAt(indexI))); } catch (IOException e) { Log.err("Open Module Surface Area " + modulePath, e.getMessage()); - e.printStackTrace(); } catch (XmlException e) { Log.err("Open Module Surface Area " + modulePath, e.getMessage()); - e.printStackTrace(); } catch (Exception e) { Log.err("Open Module Surface Area " + modulePath, "Invalid file type"); - e.printStackTrace(); } } } - + Tools.sortModules(vModuleList, DataType.SORT_TYPE_ASCENDING); return vModuleList; } @@ -193,15 +458,13 @@ public class WorkspaceTools { vPlatformList.addElement(new PlatformIdentification(id)); } catch (IOException e) { Log.err("Open Platform Surface Area " + path, e.getMessage()); - e.printStackTrace(); } catch (XmlException e) { Log.err("Open Platform Surface Area " + path, e.getMessage()); - e.printStackTrace(); } catch (Exception e) { Log.err("Open Platform Surface Area " + path, "Invalid file type"); - e.printStackTrace(); } } + Tools.sortPlatforms(vPlatformList, DataType.SORT_TYPE_ASCENDING); return vPlatformList; } @@ -219,6 +482,7 @@ public class WorkspaceTools { } } } + Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING); return vector; } @@ -236,6 +500,7 @@ public class WorkspaceTools { } } } + Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING); return vector; } @@ -251,8 +516,9 @@ public class WorkspaceTools { for (int index = 0; index < spd.getPpiDeclarations().getEntryList().size(); index++) { vector.addElement(spd.getPpiDeclarations().getEntryList().get(index).getCName()); } - } + } } + Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING); return vector; } @@ -268,8 +534,9 @@ public class WorkspaceTools { for (int index = 0; index < spd.getGuidDeclarations().getEntryList().size(); index++) { vector.addElement(spd.getGuidDeclarations().getEntryList().get(index).getCName()); } - } + } } + Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING); return vector; } @@ -285,8 +552,9 @@ public class WorkspaceTools { for (int index = 0; index < spd.getPcdDeclarations().getPcdEntryList().size(); index++) { vector.addElement(spd.getPcdDeclarations().getPcdEntryList().get(index).getCName()); } - } + } } + Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING); return vector; } @@ -308,15 +576,13 @@ public class WorkspaceTools { } } catch (IOException e) { // TODO Auto-generated catch block - e.printStackTrace(); } catch (XmlException e) { // TODO Auto-generated catch block - e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block - e.printStackTrace(); } } + Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING); return vector; } @@ -336,15 +602,13 @@ public class WorkspaceTools { } } catch (IOException e) { // TODO Auto-generated catch block - e.printStackTrace(); } catch (XmlException e) { // TODO Auto-generated catch block - e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block - e.printStackTrace(); } } + Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING); return vector; } @@ -364,15 +628,13 @@ public class WorkspaceTools { } } catch (IOException e) { // TODO Auto-generated catch block - e.printStackTrace(); } catch (XmlException e) { // TODO Auto-generated catch block - e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block - e.printStackTrace(); } } + Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING); return vector; } @@ -392,15 +654,13 @@ public class WorkspaceTools { } } catch (IOException e) { // TODO Auto-generated catch block - e.printStackTrace(); } catch (XmlException e) { // TODO Auto-generated catch block - e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block - e.printStackTrace(); } } + Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING); return vector; } @@ -420,15 +680,13 @@ public class WorkspaceTools { } } catch (IOException e) { // TODO Auto-generated catch block - e.printStackTrace(); } catch (XmlException e) { // TODO Auto-generated catch block - e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block - e.printStackTrace(); } } + Tools.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING); return vector; } @@ -452,10 +710,8 @@ public class WorkspaceTools { for (int indexI = 0; indexI < vPackageList.size(); indexI++) { packagePath = vPackageList.elementAt(indexI).getPath(); modulePaths = this.getAllModulesOfPackage(packagePath); - packagePath = packagePath.substring(0, packagePath.lastIndexOf(DataType.FILE_SEPARATOR) - + DataType.FILE_SEPARATOR.length()); for (int indexJ = 0; indexJ < modulePaths.size(); indexJ++) { - modulePath = Tools.convertPathToCurrentOsType(packagePath + modulePaths.elementAt(indexJ)); + modulePath = modulePaths.get(indexJ); try { mid = getId(modulePath, OpenFile.openMsaFile(modulePath)); // @@ -465,11 +721,11 @@ public class WorkspaceTools { return vPackageList.elementAt(indexI); } } catch (IOException e) { - e.printStackTrace(); + } catch (XmlException e) { - e.printStackTrace(); + } catch (Exception e) { - e.printStackTrace(); + } } } @@ -571,4 +827,78 @@ public class WorkspaceTools { strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath); SaveFile.saveDbFile(strFrameworkDbFilePath, fdb); } + + /** + Get all file's path from one module + + @param path + @return + @throws IOException + @throws XmlException + @throws Exception + + **/ + public Vector getAllModuleFilesPath(String path) throws IOException, XmlException, Exception { + Vector v = new Vector(); + path = Tools.convertPathToCurrentOsType(path); + v.addElement(path); + ModuleSurfaceArea msa = OpenFile.openMsaFile(path); + if (msa != null) { + // + // Get all files' path of a module + // + SourceFiles sf = msa.getSourceFiles(); + if (sf != null) { + for (int index = 0; index < sf.getFilenameList().size(); index++) { + String temp = sf.getFilenameList().get(index).getStringValue(); + temp = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + temp; + v.addElement(Tools.convertPathToCurrentOsType(temp)); + } + } + } + + return v; + } + + /** + Get all file's path from one package + + @param path + @return + @throws IOException + @throws XmlException + @throws Exception + + **/ + public Vector getAllPakcageFilesPath(String path) throws IOException, XmlException, Exception { + Vector v = new Vector(); + path = Tools.convertPathToCurrentOsType(path); + // + // First add package + // + v.addElement(path); + + // + // Add the package's industry std includes one by one + // + Vector f1 = new Vector(); + f1 = getAllIndustryStdIncludesOfPackage(path); + for (int index = 0; index < f1.size(); index++) { + v.addElement(f1.get(index)); + } + + // + // Add module's files one by one + // + f1 = new Vector(); + f1 = getAllModulesOfPackage(path); + for (int indexI = 0; indexI < f1.size(); indexI++) { + Vector f2 = getAllModuleFilesPath(f1.get(indexI)); + for (int indexJ = 0; indexJ < f2.size(); indexJ++) { + v.addElement(f2.get(indexJ)); + } + } + + return v; + } }