mirror of https://github.com/acidanthera/audk.git
Enhance Installation, removing and creating FAR functionality.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@964 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
3cc092acf2
commit
1898a0c348
|
@ -59,15 +59,6 @@ public class DistributeRule {
|
|||
AggregationOperation.union(farPkgList,
|
||||
dbPkgList));
|
||||
|
||||
//
|
||||
// If dependencies don't meet, print the error message and return.
|
||||
//
|
||||
// if (resultList != null || resultList.size()> 0){
|
||||
// Iterator resItem = resultList.iterator();
|
||||
// while (resItem.hasNext()){
|
||||
// System.out.println("Missing package:" + resItem.next().toString() + " !");
|
||||
// }
|
||||
// }
|
||||
return resultList;
|
||||
|
||||
}
|
||||
|
|
|
@ -63,8 +63,9 @@ public class Far {
|
|||
this.mainfest = new Mainfest(getMainfestFile());
|
||||
}
|
||||
|
||||
public void creatFar(List<PackageIdentification> pkgList, List<PlatformIdentification> plfList,
|
||||
Set<String> fileFilter, FarHeader fHeader) throws Exception {
|
||||
public void creatFar (List<PackageIdentification> pkgList,
|
||||
List<PlatformIdentification> plfList, Set<String> fileFilter,
|
||||
FarHeader fHeader) throws Exception{
|
||||
jos = new JarOutputStream(new FileOutputStream(jarFile));
|
||||
|
||||
//
|
||||
|
@ -97,11 +98,7 @@ public class Far {
|
|||
private void writeToJar(File file, JarOutputStream jos) throws Exception{
|
||||
byte[] buffer = new byte[(int)file.length()];
|
||||
FileInputStream fInput = new FileInputStream(file);
|
||||
JarEntry entry = new JarEntry(
|
||||
Tools
|
||||
.convertPathToUnixType(Tools
|
||||
.getRelativePath(file.getPath(),
|
||||
Workspace.getCurrentWorkspace())));
|
||||
JarEntry entry = new JarEntry(Tools.convertPathToUnixType(Tools.getRelativePath(file.getPath(),Workspace.getCurrentWorkspace())));
|
||||
jos.putNextEntry(entry);
|
||||
fInput.read(buffer);
|
||||
jos.write(buffer);
|
||||
|
@ -113,8 +110,7 @@ public class Far {
|
|||
extract(allFile, dir);
|
||||
}
|
||||
|
||||
public void InstallFar(Map<PlatformIdentification, File> plfMap, Map<PackageIdentification, File> pkgMap)
|
||||
throws Exception {
|
||||
public void InstallFar (Map<PlatformIdentification, File> plfMap, Map<PackageIdentification, File> pkgMap) throws Exception{
|
||||
Set<PlatformIdentification> plfKeys = plfMap.keySet();
|
||||
Iterator<PlatformIdentification> plfIter = plfKeys.iterator();
|
||||
while (plfIter.hasNext()) {
|
||||
|
@ -153,6 +149,38 @@ public class Far {
|
|||
public boolean hibernateToFile() {
|
||||
return true;
|
||||
}
|
||||
// public static void main(String[] args){
|
||||
// try {
|
||||
// JarFile jarFile = new JarFile(new File("C:\\cvswork\\newEdk\\jar.jar.far"));
|
||||
// JarEntry je= jarFile.getJarEntry("MdePkg/MdePkg.spd");
|
||||
// InputStream is = jarFile.getInputStream(je);
|
||||
// byte[] buffer = new byte[1];
|
||||
// File tempFile = new File("C:\\cvswork\\newEdk\\tempFile");
|
||||
// File tfile2 = new File("C:\\cvswork\\newEdk\\tempFile1");
|
||||
// FileOutputStream fos1 = new FileOutputStream(tfile2);
|
||||
// FileOutputStream fos = new FileOutputStream(tempFile);
|
||||
// int size = is.read(buffer);
|
||||
// int totoalSize = size;
|
||||
// while ( size >= 0) {
|
||||
// fos.write(buffer);
|
||||
// size = is.read(buffer);
|
||||
// totoalSize = totoalSize + size;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//// is = jarFile.getInputStream(je);
|
||||
//// is.read(totalbuffer);
|
||||
//// fos.write(totalbuffer);
|
||||
// fos.close();
|
||||
// byte[] totalbuffer = new byte[(int)tempFile.length()];
|
||||
// FileInputStream fis = new FileInputStream(tempFile);
|
||||
// fis.read(totalbuffer);
|
||||
// fos1.write(totalbuffer);
|
||||
// fos1.close();
|
||||
// }catch(Exception e){
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
public void extract(List<FarFileItem> allFile, String dir) throws Exception {
|
||||
|
||||
|
@ -164,10 +192,6 @@ public class Far {
|
|||
while (filesItem.hasNext()) {
|
||||
try {
|
||||
ffItem = (FarFileItem)filesItem.next();
|
||||
// Enumeration<JarEntry> a = jf.entries();
|
||||
// while (a.hasMoreElements()) {
|
||||
// System.out.println("##" + a.nextElement().getName());
|
||||
// }
|
||||
je = jf.getJarEntry(Tools.convertPathToUnixType(ffItem.getDefaultPath()));
|
||||
InputStream entryStream = jf.getInputStream(je);
|
||||
File file = new File(dir + ffItem.getRelativeFilename());
|
||||
|
@ -179,19 +203,28 @@ public class Far {
|
|||
//
|
||||
FileOutputStream outputStream = new FileOutputStream(file);
|
||||
|
||||
|
||||
try {
|
||||
//
|
||||
// Read the entry data and write it to the output
|
||||
// file.
|
||||
//
|
||||
int size = entryStream.available();
|
||||
byte[] buffer = new byte[size];
|
||||
outputStream.write(buffer);
|
||||
// if (!(FarMd5.md5(buffer)).equalsIgnoreCase(ffItem.getMd5Value())){
|
||||
// throw new Exception (je.getName() + " Md5 is invalided!");
|
||||
// }
|
||||
byte[] buffer = new byte[1];
|
||||
File tempFile = new File("tempFile");
|
||||
FileOutputStream fos = new FileOutputStream(tempFile);
|
||||
int size = entryStream.read(buffer);
|
||||
while ( size >= 0) {
|
||||
fos.write(buffer);
|
||||
size = entryStream.read(buffer);
|
||||
}
|
||||
|
||||
// System.out.println(je.getName() + " extracted.");
|
||||
fos.close();
|
||||
byte[] totalBuffer = new byte[(int)tempFile.length()];
|
||||
FileInputStream fis = new FileInputStream(tempFile);
|
||||
fis.read(totalBuffer);
|
||||
outputStream.write(totalBuffer);
|
||||
fis.close();
|
||||
tempFile.delete();
|
||||
} finally {
|
||||
outputStream.close();
|
||||
}
|
||||
|
@ -200,23 +233,11 @@ public class Far {
|
|||
}
|
||||
|
||||
} finally {
|
||||
//jf.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// public void installFarPackage (PackageIdentification pkgId, String dir) throws Exception{
|
||||
// String pkgDir = null;
|
||||
// List<FarFileItem> farFileList = new ArrayList<FarFileItem>();
|
||||
// farFileList = this.mainfest.getPackageContents(pkgId);
|
||||
// if (dir == null){
|
||||
// pkgDir = this.mainfest.getPackageDefaultPath(pkgId);
|
||||
// }else {
|
||||
// pkgDir = dir;
|
||||
// }
|
||||
// extract(farFileList,pkgDir);
|
||||
// }
|
||||
|
||||
public void addFileToFar (File file, JarOutputStream farOuputStream, String workDir){
|
||||
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
/** @file
|
||||
|
||||
The file is used to save information of Far item.
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
package org.tianocore.frameworkwizard.far;
|
||||
|
||||
public class FarIdentification {
|
||||
|
|
|
@ -57,7 +57,6 @@ public class Mainfest implements ManifestInterface {
|
|||
// / Mainfest file element name
|
||||
// /
|
||||
final static String mfFileName = "FarMainfest.MF";
|
||||
|
||||
//
|
||||
// Header
|
||||
//
|
||||
|
@ -164,8 +163,8 @@ public class Mainfest implements ManifestInterface {
|
|||
this.fhInfo = fHeader;
|
||||
}
|
||||
|
||||
public void createManifest(List<PackageIdentification> pkgList, List<PlatformIdentification> plfList,
|
||||
Set<String> fileFilter) throws Exception {
|
||||
public void createManifest(List<PackageIdentification> pkgList,
|
||||
List<PlatformIdentification> plfList, Set<String> fileFilter) throws Exception {
|
||||
|
||||
//
|
||||
// Add Package and it's contents to FarPackageList.
|
||||
|
@ -275,7 +274,8 @@ public class Mainfest implements ManifestInterface {
|
|||
fPkgList.add(farPackage);
|
||||
}
|
||||
|
||||
private void recursiveDirectory(Set<File> files, Set<File> fpds, File dir, Set<String> fileFilter) {
|
||||
private void recursiveDirectory(Set<File> files, Set<File> fpds, File dir,
|
||||
Set<String> fileFilter) {
|
||||
if (isFilter(dir, fileFilter)) {
|
||||
return;
|
||||
}
|
||||
|
@ -306,8 +306,7 @@ public class Mainfest implements ManifestInterface {
|
|||
//
|
||||
// Add farFileName
|
||||
//
|
||||
ffItem = new FarFileItem(Tools.getRelativePath(fpfFile.getPath(), Workspace.getCurrentWorkspace()),
|
||||
FarMd5.md5(fpfFile));
|
||||
ffItem = new FarFileItem(Tools.getRelativePath(fpfFile.getPath(),Workspace.getCurrentWorkspace()), FarMd5.md5(fpfFile));
|
||||
fpfItem.setFarFile(ffItem);
|
||||
|
||||
//
|
||||
|
@ -344,10 +343,8 @@ public class Mainfest implements ManifestInterface {
|
|||
// identification.
|
||||
//
|
||||
|
||||
PackageIdentification pkgId = new PackageIdentification(fPkg.getFarFile().getRelativeFilename(),
|
||||
fPkg.getGuidValue(), fPkg.getVersion());
|
||||
pkgId.setPath(Workspace.getCurrentWorkspace() + File.separatorChar + fPkg.getDefaultPath()
|
||||
+ File.separatorChar + fPkg.getFarFile().getRelativeFilename());
|
||||
PackageIdentification pkgId = new PackageIdentification(fPkg.getFarFile().getRelativeFilename(), fPkg.getGuidValue(), fPkg.getVersion());
|
||||
pkgId.setPath(Workspace.getCurrentWorkspace() + File.separatorChar + fPkg.getDefaultPath() + File.separatorChar + fPkg.getFarFile().getRelativeFilename());
|
||||
// wsTool.getId(
|
||||
// Workspace.getCurrentWorkspace() + File.separatorChar
|
||||
// + fPkg.getDefaultPath(), OpenFile
|
||||
|
@ -364,7 +361,8 @@ public class Mainfest implements ManifestInterface {
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public List<PlatformIdentification> getPlatformList() throws Exception, IOException, XmlException {
|
||||
public List<PlatformIdentification> getPlatformList() throws Exception,
|
||||
IOException, XmlException {
|
||||
//
|
||||
// PlatformIdentification set.
|
||||
//
|
||||
|
@ -372,14 +370,14 @@ public class Mainfest implements ManifestInterface {
|
|||
Iterator plfItem = this.fPlfList.iterator();
|
||||
while (plfItem.hasNext()) {
|
||||
FarPlatformItem fpfItem = (FarPlatformItem) plfItem.next();
|
||||
File file = new File(Workspace.getCurrentWorkspace() + File.separatorChar
|
||||
File file = new File(Workspace.getCurrentWorkspace()
|
||||
+ File.separatorChar
|
||||
+ fpfItem.getFarFile().getRelativeFilename());
|
||||
//
|
||||
// Set platformIdentificaiton's path as absolutly path (include
|
||||
// workspace and FPD relatively path)
|
||||
//
|
||||
PlatformIdentification plfId = new PlatformIdentification(fpfItem.getFarFile().getRelativeFilename(),
|
||||
fpfItem.getGuidValue(), fpfItem.getVersion(),
|
||||
PlatformIdentification plfId = new PlatformIdentification (fpfItem.getFarFile().getRelativeFilename(), fpfItem.getGuidValue(),fpfItem.getVersion(),
|
||||
file.getPath());
|
||||
|
||||
// (PlatformIdentification) wsTool
|
||||
|
@ -401,6 +399,7 @@ public class Mainfest implements ManifestInterface {
|
|||
if (item.isIdentityPlf(platformId)) {
|
||||
FarFileItem farFileItem = item.getFarFile();
|
||||
farFileItem.setDefaultPath(farFileItem.getRelativeFilename());
|
||||
farFileItem.setRelativeFilename(Tools.getFileNameOnly(farFileItem.getRelativeFilename()));
|
||||
result.add(farFileItem);
|
||||
break ;
|
||||
}
|
||||
|
@ -441,6 +440,7 @@ public class Mainfest implements ManifestInterface {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
return farFileList;
|
||||
}
|
||||
|
||||
|
@ -482,16 +482,18 @@ public class Mainfest implements ManifestInterface {
|
|||
//
|
||||
// Set farFileItem relativeFileName = absolutePath + file Name.
|
||||
//
|
||||
farFileList.add(new FarFileItem(pkg.getDefaultPath() + File.separatorChar + ffItem.getRelativeFilename(),
|
||||
ffItem.getMd5Value()));
|
||||
farFileList.add(new FarFileItem(pkg.getDefaultPath()
|
||||
+ File.separatorChar + ffItem.getRelativeFilename(), ffItem
|
||||
.getMd5Value()));
|
||||
//
|
||||
// Add all files in contents to list.
|
||||
//
|
||||
Iterator contentsItem = pkg.getContentList().iterator();
|
||||
while (contentsItem.hasNext()) {
|
||||
ffItem = (FarFileItem) contentsItem.next();
|
||||
farFileList.add(new FarFileItem(pkg.getDefaultPath() + File.separator + ffItem.getRelativeFilename(),
|
||||
ffItem.getMd5Value()));
|
||||
farFileList.add(new FarFileItem(pkg.getDefaultPath()
|
||||
+ File.separator + ffItem.getRelativeFilename(), ffItem
|
||||
.getMd5Value()));
|
||||
}
|
||||
//
|
||||
// Add all farfiles in <FarPlatformList> to list.
|
||||
|
@ -500,8 +502,9 @@ public class Mainfest implements ManifestInterface {
|
|||
Iterator plfItem = plfList.iterator();
|
||||
while (plfItem.hasNext()) {
|
||||
ffItem = ((FarPlatformItem) plfItem.next()).getFarFile();
|
||||
farFileList.add(new FarFileItem(pkg.getDefaultPath() + File.separator + ffItem.getRelativeFilename(),
|
||||
ffItem.getMd5Value()));
|
||||
farFileList.add(new FarFileItem(pkg.getDefaultPath()
|
||||
+ File.separator + ffItem.getRelativeFilename(), ffItem
|
||||
.getMd5Value()));
|
||||
}
|
||||
}
|
||||
return farFileList;
|
||||
|
@ -553,7 +556,8 @@ public class Mainfest implements ManifestInterface {
|
|||
//
|
||||
// Add far files in <FarPlatformList> to list
|
||||
//
|
||||
NodeList elementList = this.mainfestDoc.getElementsByTagName(farPlatformList);
|
||||
NodeList elementList = this.mainfestDoc
|
||||
.getElementsByTagName(farPlatformList);
|
||||
for (int i = 0; i < elementList.getLength(); i++) {
|
||||
//
|
||||
// Get <farPlatform> node list.
|
||||
|
@ -571,13 +575,15 @@ public class Mainfest implements ManifestInterface {
|
|||
//
|
||||
// Get child node value and set to platformIdentification.
|
||||
//
|
||||
if (tempNode.getNodeName().equalsIgnoreCase(farPackage_FarfileName)) {
|
||||
if (tempNode.getNodeName().equalsIgnoreCase(
|
||||
farPackage_FarfileName)) {
|
||||
NamedNodeMap farAttr = tempNode.getAttributes();
|
||||
//
|
||||
// Change relative path to absolute one
|
||||
//
|
||||
FarFileItem farFile = new FarFileItem(tempNode.getTextContent(),
|
||||
farAttr.getNamedItem(farFileName_Md5sum).getTextContent());
|
||||
FarFileItem farFile = new FarFileItem(tempNode
|
||||
.getTextContent(), farAttr.getNamedItem(
|
||||
farFileName_Md5sum).getTextContent());
|
||||
ffiList.add(farFile);
|
||||
}
|
||||
}
|
||||
|
@ -590,7 +596,8 @@ public class Mainfest implements ManifestInterface {
|
|||
//
|
||||
// create mainfest root node
|
||||
//
|
||||
Element rootNode = this.mainfestDoc.createElement("FrameworkArchiveManifest");
|
||||
Element rootNode = this.mainfestDoc
|
||||
.createElement("FrameworkArchiveManifest");
|
||||
this.mainfestDoc.appendChild(rootNode);
|
||||
|
||||
//
|
||||
|
@ -668,7 +675,8 @@ public class Mainfest implements ManifestInterface {
|
|||
// Write the DOM document to the file
|
||||
//
|
||||
Transformer xformer = TransformerFactory.newInstance().newTransformer();
|
||||
xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
|
||||
xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",
|
||||
"2");
|
||||
xformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
|
||||
//
|
||||
|
@ -679,7 +687,8 @@ public class Mainfest implements ManifestInterface {
|
|||
// Prepare the output file, get the Mainifest file name from <FarHeader>
|
||||
// /<FarName>.
|
||||
//
|
||||
this.mfFile = new File(Workspace.getCurrentWorkspace() + File.separatorChar + mfFileName);
|
||||
this.mfFile = new File(Workspace.getCurrentWorkspace()
|
||||
+ File.separatorChar + mfFileName);
|
||||
//
|
||||
// generate all directory path
|
||||
//
|
||||
|
@ -688,7 +697,8 @@ public class Mainfest implements ManifestInterface {
|
|||
}
|
||||
|
||||
public void pkgToFarPkgNode(Element parentNode, FarPackage pkgItem) {
|
||||
Element pkgNode = this.mainfestDoc.createElement(farPackageList_FarPackage);
|
||||
Element pkgNode = this.mainfestDoc
|
||||
.createElement(farPackageList_FarPackage);
|
||||
//
|
||||
// Add <FarFileName>
|
||||
//
|
||||
|
@ -704,7 +714,8 @@ public class Mainfest implements ManifestInterface {
|
|||
//
|
||||
// Add <DefaultPath>
|
||||
//
|
||||
setStrItemToNode(pkgNode, pkgItem.getDefaultPath(), farPackage_DefaultPath);
|
||||
setStrItemToNode(pkgNode, pkgItem.getDefaultPath(),
|
||||
farPackage_DefaultPath);
|
||||
|
||||
//
|
||||
// Add <Contents>
|
||||
|
@ -719,7 +730,8 @@ public class Mainfest implements ManifestInterface {
|
|||
}
|
||||
|
||||
public void PlfToPlatformNode(Element parentNode, FarPlatformItem fplItem) {
|
||||
Element fplNode = this.mainfestDoc.createElement(farPlatformList_FarPlatform);
|
||||
Element fplNode = this.mainfestDoc
|
||||
.createElement(farPlatformList_FarPlatform);
|
||||
//
|
||||
// Add <FarFileName>
|
||||
//
|
||||
|
@ -740,7 +752,8 @@ public class Mainfest implements ManifestInterface {
|
|||
}
|
||||
|
||||
public void ffiToFfNode(Element parentNode, FarFileItem ffi) {
|
||||
Element farFileName = this.mainfestDoc.createElement(farPackage_FarfileName);
|
||||
Element farFileName = this.mainfestDoc
|
||||
.createElement(farPackage_FarfileName);
|
||||
farFileName.setTextContent(ffi.getRelativeFilename());
|
||||
System.out.println(farFileName.getTextContent());
|
||||
System.out.println(ffi.getRelativeFilename());
|
||||
|
@ -748,7 +761,8 @@ public class Mainfest implements ManifestInterface {
|
|||
parentNode.appendChild(farFileName);
|
||||
}
|
||||
|
||||
public void setStrItemToNode(Element parentNode, String strValue, String strName) {
|
||||
public void setStrItemToNode(Element parentNode, String strValue,
|
||||
String strName) {
|
||||
Element node = this.mainfestDoc.createElement(strName);
|
||||
node.setTextContent(strValue);
|
||||
parentNode.appendChild(node);
|
||||
|
@ -871,7 +885,8 @@ public class Mainfest implements ManifestInterface {
|
|||
* @param fpfListNode
|
||||
* @param plfList
|
||||
*/
|
||||
public void parseFarPlatformList(Node fpfListNode, List<FarPlatformItem> plfList) {
|
||||
public void parseFarPlatformList(Node fpfListNode,
|
||||
List<FarPlatformItem> plfList) {
|
||||
//
|
||||
// Get <FarPlatform> list.
|
||||
//
|
||||
|
@ -935,7 +950,8 @@ public class Mainfest implements ManifestInterface {
|
|||
public FarFileItem parseFarFile(Node farFileNode) {
|
||||
String ffName = farFileNode.getTextContent();
|
||||
NamedNodeMap attr = farFileNode.getAttributes();
|
||||
FarFileItem ffItem = new FarFileItem(ffName, attr.getNamedItem(farFileName_Md5sum).getTextContent());
|
||||
FarFileItem ffItem = new FarFileItem(ffName, attr.getNamedItem(
|
||||
farFileName_Md5sum).getTextContent());
|
||||
return ffItem;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.awt.event.MouseEvent;
|
|||
import java.awt.event.MouseListener;
|
||||
import java.io.File;
|
||||
import java.util.Vector;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JPanel;
|
||||
|
@ -233,7 +234,8 @@ public class UpdateStepOne extends IDialog implements MouseListener {
|
|||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getSource() == jButtonCancel) {
|
||||
this.setVisible(false);
|
||||
} else if (e.getSource() == jButtonNext) {
|
||||
}
|
||||
else if (e.getSource() == jButtonNext) {
|
||||
//
|
||||
// Judge if FAR file is existed
|
||||
//
|
||||
|
@ -246,6 +248,13 @@ public class UpdateStepOne extends IDialog implements MouseListener {
|
|||
//
|
||||
// Judge FAR is valid
|
||||
//
|
||||
try{
|
||||
JarFile file = new JarFile(farFile);
|
||||
this.far = new Far(file);
|
||||
} catch (Exception ex){
|
||||
Log.err(ex.getMessage());
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Add more logic process here
|
||||
|
@ -261,7 +270,8 @@ public class UpdateStepOne extends IDialog implements MouseListener {
|
|||
this.setVisible(false);
|
||||
stepTwo.prepareTable();
|
||||
stepTwo.setVisible(true);
|
||||
} else if (e.getSource() == jButtonBrowser) {
|
||||
}
|
||||
else if (e.getSource() == jButtonBrowser) {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
fc.setAcceptAllFileFilterUsed(false);
|
||||
fc.addChoosableFileFilter(new IFileFilter(DataType.FAR_SURFACE_AREA_EXT));
|
||||
|
|
|
@ -17,8 +17,13 @@ import java.awt.Dimension;
|
|||
import java.awt.Toolkit;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextArea;
|
||||
|
@ -29,11 +34,14 @@ import javax.swing.JTable;
|
|||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import org.tianocore.frameworkwizard.common.Log;
|
||||
import org.tianocore.frameworkwizard.common.Tools;
|
||||
import org.tianocore.frameworkwizard.common.ui.IDialog;
|
||||
import org.tianocore.frameworkwizard.far.AggregationOperation;
|
||||
import org.tianocore.frameworkwizard.far.DistributeRule;
|
||||
import org.tianocore.frameworkwizard.far.Far;
|
||||
import org.tianocore.frameworkwizard.packaging.PackageIdentification;
|
||||
import org.tianocore.frameworkwizard.platform.PlatformIdentification;
|
||||
import org.tianocore.frameworkwizard.workspace.Workspace;
|
||||
import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
|
||||
|
||||
|
@ -63,6 +71,7 @@ public class UpdateStepTwo extends IDialog implements MouseListener {
|
|||
private JTable jTablePackage = null;
|
||||
|
||||
private PartialTableModel model = null;
|
||||
List<PackageIdentification> updatPkgList = new ArrayList<PackageIdentification>();
|
||||
|
||||
public UpdateStepTwo(IDialog iDialog, boolean modal, UpdateStepOne stepOne) {
|
||||
this(iDialog, modal);
|
||||
|
@ -174,11 +183,11 @@ public class UpdateStepTwo extends IDialog implements MouseListener {
|
|||
WorkspaceTools wt = new WorkspaceTools();
|
||||
List<PackageIdentification> packagesInDb = wt.getAllPackages();
|
||||
|
||||
List<PackageIdentification> result = AggregationOperation.intersection(packagesInDb, packagesInFar);
|
||||
updatPkgList = AggregationOperation.intersection(packagesInDb, packagesInFar);
|
||||
//
|
||||
// Change here to get packages and platforms from FAR
|
||||
//
|
||||
Iterator<PackageIdentification> iter = result.iterator();//packageList.iterator();
|
||||
Iterator<PackageIdentification> iter = updatPkgList.iterator() ;//packageList.iterator();
|
||||
while (iter.hasNext()) {
|
||||
String[] str = new String[4];
|
||||
PackageIdentification item = iter.next();
|
||||
|
@ -188,7 +197,8 @@ public class UpdateStepTwo extends IDialog implements MouseListener {
|
|||
str[3] = Tools.getFilePathOnly(Tools.getRelativePath(item.getPath(), Workspace.getCurrentWorkspace()));
|
||||
model.addRow(str);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -235,51 +245,150 @@ public class UpdateStepTwo extends IDialog implements MouseListener {
|
|||
}
|
||||
return jContentPane;
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getSource() == jButtonCancel) {
|
||||
this.setVisible(false);
|
||||
} else if (e.getSource() == jButtonFinish) {
|
||||
}
|
||||
else if (e.getSource() == jButtonFinish) {
|
||||
//
|
||||
// Check depedency ?
|
||||
//
|
||||
WorkspaceTools wsTools = new WorkspaceTools();
|
||||
|
||||
Iterator<PackageIdentification> iter = updatPkgList.iterator();
|
||||
List<PackageIdentification> depResultList = new ArrayList<PackageIdentification>();
|
||||
while (iter.hasNext()){
|
||||
List<PackageIdentification> depPkgList = stepOne.getFar().getPackageDependencies(iter.next());
|
||||
depResultList = AggregationOperation.union(depResultList, depPkgList);
|
||||
}
|
||||
|
||||
List<PackageIdentification> dbPkgList = DistributeRule.vectorToList(wsTools.getAllPackages());
|
||||
List<PackageIdentification> resultList = AggregationOperation.minus(depResultList, AggregationOperation.union(
|
||||
this.updatPkgList, dbPkgList));
|
||||
Iterator resultIter = resultList.iterator();
|
||||
while (resultIter.hasNext()){
|
||||
Log.err("Missing dependency package " + ((PackageIdentification)resultIter.next()).toString() + "in workspace!");
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Remove all update packages
|
||||
//
|
||||
//
|
||||
// For all packages, remove all files.
|
||||
// Exception FPD file still in DB
|
||||
//
|
||||
Vector<PlatformIdentification> allPlatforms = wsTools.getAllPlatforms();
|
||||
Set<File> allPlatformFiles = new LinkedHashSet<File>();
|
||||
|
||||
Iterator<PlatformIdentification> allPlfIter = allPlatforms.iterator();
|
||||
while (iter.hasNext()) {
|
||||
allPlatformFiles.add(allPlfIter.next().getFpdFile());
|
||||
}
|
||||
|
||||
Iterator<PackageIdentification> packageIter = this.updatPkgList.iterator();
|
||||
while (packageIter.hasNext()) {
|
||||
PackageIdentification item = packageIter.next();
|
||||
Set<File> deleteFiles = new LinkedHashSet<File>();
|
||||
recursiveDir(deleteFiles, item.getSpdFile().getParentFile(), allPlatformFiles);
|
||||
Iterator<File> iterDeleteFile = deleteFiles.iterator();
|
||||
while (iterDeleteFile.hasNext()){
|
||||
deleteFiles(iterDeleteFile.next());
|
||||
}
|
||||
//
|
||||
// Remove all empty parent dir
|
||||
//
|
||||
File parentDir = item.getSpdFile().getParentFile();
|
||||
while (parentDir.listFiles().length == 0) {
|
||||
File tempFile = parentDir;
|
||||
parentDir = parentDir.getParentFile();
|
||||
tempFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Install all update packages
|
||||
//
|
||||
Iterator<PackageIdentification> updataIter = this.updatPkgList.iterator();
|
||||
while (updataIter.hasNext()){
|
||||
PackageIdentification pkgId = updataIter.next();
|
||||
try{
|
||||
stepOne.getFar().installPackage(pkgId, pkgId.getSpdFile());
|
||||
}catch (Exception ex){
|
||||
Log.err("Can install " + pkgId.toString() + " pakcage, please check it!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
this.setVisible(false);
|
||||
} else if (e.getSource() == jButtonPrevious) {
|
||||
}
|
||||
else if (e.getSource() == jButtonPrevious) {
|
||||
this.setVisible(false);
|
||||
stepOne.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
private void recursiveDir(Set<File> files, File dir, Set<File> platformFiles) {
|
||||
File[] fileList = dir.listFiles();
|
||||
for (int i = 0; i < fileList.length; i ++) {
|
||||
if (fileList[i].isFile()) {
|
||||
if( ! platformFiles.contains(fileList[i])) {
|
||||
files.add(fileList[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (isContain(fileList[i], platformFiles)) {
|
||||
recursiveDir(files, fileList[i], platformFiles);
|
||||
}
|
||||
else {
|
||||
files.add(fileList[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteFiles(File file) {
|
||||
if (file.isDirectory()) {
|
||||
File[] files = file.listFiles();
|
||||
for (int i = 0; i < files.length; i ++) {
|
||||
deleteFiles(files[i]);
|
||||
}
|
||||
}
|
||||
file.delete();
|
||||
}
|
||||
|
||||
private boolean isContain(File dir, Set<File> platformFiles) {
|
||||
Iterator<File> iter = platformFiles.iterator();
|
||||
while (iter.hasNext()) {
|
||||
File file = iter.next();
|
||||
if (file.getPath().startsWith(dir.getPath())) {
|
||||
//
|
||||
// continue this FPD file
|
||||
//
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class PartialTableModel extends DefaultTableModel {
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue