summaryrefslogtreecommitdiff
path: root/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/far/DistributeRule.java
blob: 730e385c743865a2f8bfab18faa278f64e91375c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/** @file
 
 The file is used to distribute Far
 
 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;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import org.tianocore.frameworkwizard.packaging.PackageIdentification;
import org.tianocore.frameworkwizard.workspace.WorkspaceTools;

public class DistributeRule {
    static PackageQuery pkgQ = new PackageQuery();

    static WorkspaceTools wsTools = new WorkspaceTools();

    static List<PackageIdentification> farPkgList = new ArrayList<PackageIdentification>();

    public static List<PackageIdentification> installFarCheck(Far far) {

        Far myFar = far;
        List<PackageIdentification> pkgDepList = new ArrayList<PackageIdentification>();
        List<PackageIdentification> dbPkgList = new ArrayList<PackageIdentification>();
        List<PackageIdentification> depResultList = new ArrayList<PackageIdentification>();
        //
        // Get Far packages list;
        // 
        try {
            farPkgList = myFar.manifest.getPackageList();
            Iterator pkgItems = farPkgList.iterator();
            while (pkgItems.hasNext()) {
                PackageIdentification id = (PackageIdentification) pkgItems.next();
                pkgDepList = myFar.getPackageDependencies(id);
                depResultList = AggregationOperation.union(depResultList, pkgDepList);
            }
            dbPkgList = vectorToList(wsTools.getAllPackages());

        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

        //
        // Check does the dependence meet the requirement.
        //
        List<PackageIdentification> resultList = AggregationOperation.minus(depResultList,
                                                                            AggregationOperation.union(farPkgList,
                                                                                                       dbPkgList));

        return resultList;

    }

    //    public void installPackgCheck (PackageIdentification pkgId, String pkgPath){
    //        List<PackageIdentification> dbPkgList = new ArrayList<PackageIdentification>();
    //        dbPkgList = vectorToList(wsTools.getAllPackages());
    //        //
    //        // Install far's package one by one.
    //        //
    //        if ((AggregationOperation.getExistItems(pkgId, dbPkgList))){
    //            
    //        }
    //    }

    public void UpdatCheck(String orgFar, String destFar) {

    }

    public static List<PackageIdentification> vectorToList(Vector vec) {
        List<PackageIdentification> set = new ArrayList<PackageIdentification>();
        Iterator vecItem = vec.iterator();
        while (vecItem.hasNext()) {
            set.add((PackageIdentification) vecItem.next());
        }
        return set;
    }
}