KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seplatform > J2SEInstallImpl


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.java.j2seplatform;
21
22 import org.openide.filesystems.*;
23 import org.openide.util.Utilities;
24 import org.openide.util.NbBundle;
25 import org.openide.ErrorManager;
26 import org.netbeans.modules.java.j2seplatform.wizard.J2SEWizardIterator;
27 import org.netbeans.modules.java.j2seplatform.platformdefinition.Util;
28
29 import java.io.IOException JavaDoc;
30 import java.io.File JavaDoc;
31 import java.util.Collections JavaDoc;
32
33 import org.openide.WizardDescriptor;
34
35 /**
36  * Installer factory for standard J2SE Platforms
37  *
38  * @author Svatopluk Dedic
39  */

40 class J2SEInstallImpl extends org.netbeans.spi.java.platform.PlatformInstall {
41
42     private static final String JavaDoc APPLE_JAVAVM_FRAMEWORK_PATH = "/System/Library/Frameworks/JavaVM.framework/Versions/";//NOI18N
43

44     private boolean winOS;
45
46
47     J2SEInstallImpl(boolean winOS) {
48         this.winOS = winOS;
49     }
50     
51     static J2SEInstallImpl create() {
52         boolean windows = Utilities.isWindows();
53         
54         return new J2SEInstallImpl(windows);
55     }
56     
57     /**
58      * Performs a quick & dirty check whether there's a JRE installed.
59      * The method looks into the folder for something, which - depending on
60      * the platform's conventions - has name "java.exe" or "java"
61      */

62     public boolean accept(FileObject dir) {
63         if (!dir.isFolder()) {
64             return false;
65         }
66         if (Utilities.isMac()) {
67             //For MacOS X only the version folder is interesting
68
// all other places are links to it
69
File JavaDoc f = FileUtil.toFile(dir);
70             if (f == null || !f.getAbsolutePath().startsWith(APPLE_JAVAVM_FRAMEWORK_PATH))
71                 return false;
72         }
73         FileObject tool = Util.findTool("java", Collections.singleton(dir)); //NOI18N
74
if (tool == null) {
75             return false;
76         }
77         tool = Util.findTool("javac", Collections.singleton(dir)); //NOI18N
78
return tool != null;
79     }
80     
81     public WizardDescriptor.InstantiatingIterator createIterator(FileObject baseFolder) {
82         try {
83             return new J2SEWizardIterator(baseFolder);
84         } catch (IOException JavaDoc ioe) {
85             ErrorManager.getDefault().notify (ioe);
86             return null;
87         }
88     }
89
90     public String JavaDoc getDisplayName() {
91         return NbBundle.getMessage(J2SEInstallImpl.class,"TXT_J2SEPlatform");
92     }
93 }
94
Popular Tags