KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > platform > HarnessUpgrader


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project.ui.platform;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Set JavaDoc;
27 import org.netbeans.modules.apisupport.project.Util;
28 import org.netbeans.modules.apisupport.project.ui.ModuleUISettings;
29 import org.netbeans.modules.apisupport.project.ui.UIUtil;
30 import org.netbeans.modules.apisupport.project.universe.NbPlatform;
31 import org.openide.NotifyDescriptor;
32 import org.openide.util.Mutex;
33 import org.openide.util.NbBundle;
34
35 /**
36  * Offers to upgrade old harnesses to the new version.
37  * @author Jesse Glick
38  * @see "issue #71630"
39  */

40 class HarnessUpgrader {
41     
42     private HarnessUpgrader() {}
43     
44     public static void checkForUpgrade() {
45         if (ModuleUISettings.getDefault().getHarnessesUpgraded()) {
46             return;
47         }
48         ModuleUISettings.getDefault().setHarnessesUpgraded(true);
49         final Set JavaDoc<NbPlatform> toUpgrade = new HashSet JavaDoc();
50         Iterator JavaDoc it = NbPlatform.getPlatforms().iterator();
51         while (it.hasNext()) {
52             NbPlatform p = (NbPlatform) it.next();
53             if (p.isDefault() && !p.isValid()) {
54                 continue;
55             }
56             if (p.getHarnessVersion() >= NbPlatform.HARNESS_VERSION_50u1) {
57                 continue;
58             }
59             if (!p.getHarnessLocation().equals(p.getBundledHarnessLocation())) {
60                 // Somehow custom, forget it.
61
continue;
62             }
63             toUpgrade.add(p);
64         }
65         if (!toUpgrade.isEmpty()) {
66             Mutex.EVENT.readAccess(new Runnable JavaDoc() {
67                 public void run() {
68                     promptForUpgrade(toUpgrade);
69                 }
70             });
71         }
72     }
73     
74     private static void promptForUpgrade(Set JavaDoc<NbPlatform> platforms) {
75         if (UIUtil.showAcceptCancelDialog(
76                 NbBundle.getMessage(HarnessUpgrader.class, "HarnessUpgrader.title"),
77                 NbBundle.getMessage(HarnessUpgrader.class, "HarnessUpgrader.text"),
78                 NbBundle.getMessage(HarnessUpgrader.class, "HarnessUpgrader.upgrade"),
79                 NbBundle.getMessage(HarnessUpgrader.class, "HarnessUpgrader.skip"),
80                 NotifyDescriptor.QUESTION_MESSAGE)) {
81             try {
82                 doUpgrade(platforms);
83             } catch (IOException JavaDoc e) {
84                 Util.err.notify(e);
85             }
86         }
87     }
88     
89     private static void doUpgrade(Set JavaDoc<NbPlatform> platforms) throws IOException JavaDoc {
90         File JavaDoc defaultHarness = NbPlatform.getDefaultPlatform().getHarnessLocation();
91         Iterator JavaDoc it = platforms.iterator();
92         while (it.hasNext()) {
93             NbPlatform p = (NbPlatform) it.next();
94             p.setHarnessLocation(defaultHarness);
95         }
96     }
97     
98 }
99
Popular Tags