alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.core;

import java.beans.PropertyVetoException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import org.openide.filesystems.*;

import org.netbeans.core.projects.SessionManager;

/** Default repository.
 */
public final class NbRepository extends Repository {
    /** name of system folder to be located in the USER_DIR and HOME_DIR */
    static final String SYSTEM_FOLDER = "config"; // NOI18N

    /**
     * Create a repository based on the normal system file system.
     */
    public NbRepository () {
        super (createDefaultFileSystem());
    }

    /** Creates defalt file system.
    */
    private static FileSystem createDefaultFileSystem () {
        String systemDir = System.getProperty("system.dir"); // NOI18N
        
        if (systemDir != null) {
            // initiliaze the filesystem for this property 

            try {
                return SessionManager.getDefault().create(new File (systemDir), null, new File[0]);
            } catch (IOException ex) {
                ex.printStackTrace();
                throw new InternalError ();
            } catch (PropertyVetoException ex) {
                ex.printStackTrace();
                throw new InternalError ();
            }
        }
        
        String homeDir = NonGui.getHomeDir ();
        if (homeDir != null) {
            // -----------------------------------------------------------------------------------------------------
            // 1. Initialization and checking of netbeans.home and netbeans.user directories

            File homeDirFile = new File (NonGui.getHomeDir ());
            File userDirFile = new File (NonGui.getUserDir ());
            if (!homeDirFile.exists ()) {
                System.err.println (NonGui.getString("CTL_Netbeanshome_notexists"));
                doExit (2);
            }
            if (!homeDirFile.isDirectory ()) {
                System.err.println (NonGui.getString("CTL_Netbeanshome1"));
                doExit (3);
            }
            if (!userDirFile.exists ()) {
                System.err.println (NonGui.getString("CTL_Netbeanshome2"));
                doExit (4);
            }
            if (!userDirFile.isDirectory ()) {
                System.err.println (NonGui.getString("CTL_Netbeanshome3"));
                doExit (5);
            }
            
            // #27151: may also be additional install dirs
            List extradirs = new ArrayList(); // List
            String nbdirs = System.getProperty("netbeans.dirs");
            if (nbdirs != null) {
                StringTokenizer tok = new StringTokenizer(nbdirs, File.pathSeparator);
                while (tok.hasMoreTokens()) {
                    File f = new File(tok.nextToken(), SYSTEM_FOLDER);
                    if (f.isDirectory()) {
                        extradirs.add(f);
                    }
                }
            }

            // -----------------------------------------------------------------------------------------------------
            // 7. Initialize FileSystems

            
            // system FS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            {
                Exception exc;
                try {
                    File u = new File (userDirFile, SYSTEM_FOLDER);
                    File h = new File (homeDirFile, SYSTEM_FOLDER);
                    return SessionManager.getDefault().create(u, h, (File[])extradirs.toArray(new File[extradirs.size()]));
                } catch (IOException ex) {
                    exc = ex;
                } catch (PropertyVetoException ex) {
                    exc = ex;
                }

                exc.printStackTrace ();
                Object[] arg = new Object[] {systemDir};
                System.err.println (new java.text.MessageFormat(
                    NonGui.getString("CTL_Cannot_mount_systemfs")
                ).format(arg));
                doExit (3);
            }
        }

        try {
            return SessionManager.getDefault().create(null, null, new File[0]);
        } catch (IOException ex) {
            ex.printStackTrace();
            throw new InternalError ();
        } catch (PropertyVetoException ex) {
            ex.printStackTrace();
            throw new InternalError ();
        }
    }

    
    //
    // methods that delegate to TM
    //
    
    private static void doExit (int value) {
        org.netbeans.TopSecurityManager.exit(value);
    }
    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.