visualweb.websvcmgr/test/unit/src/org/netbeans/modules/websvc/saas/util/InstalledFileLocatorImpl.java
author Jesse Glick <jglick@netbeans.org>
Wed, 23 Mar 2011 16:50:27 -0400
changeset 3213 c85dcf71e424
permissions -rw-r--r--
Tests at least should compile now.
     1 /*
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3  *
     4  * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
     5  *
     6  * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
     7  * Other names may be trademarks of their respective owners.
     8  *
     9  * The contents of this file are subject to the terms of either the GNU
    10  * General Public License Version 2 only ("GPL") or the Common
    11  * Development and Distribution License("CDDL") (collectively, the
    12  * "License"). You may not use this file except in compliance with the
    13  * License. You can obtain a copy of the License at
    14  * http://www.netbeans.org/cddl-gplv2.html
    15  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    16  * specific language governing permissions and limitations under the
    17  * License.  When distributing the software, include this License Header
    18  * Notice in each file and include the License file at
    19  * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    20  * particular file as subject to the "Classpath" exception as provided
    21  * by Oracle in the GPL Version 2 section of the License file that
    22  * accompanied this code. If applicable, add the following below the
    23  * License Header, with the fields enclosed by brackets [] replaced by
    24  * your own identifying information:
    25  * "Portions Copyrighted [year] [name of copyright owner]"
    26  *
    27  * Contributor(s):
    28  *
    29  * Portions Copyrighted 2007 Sun Microsystems, Inc.
    30  */
    31 
    32 package org.netbeans.modules.websvc.saas.util;
    33 
    34 import java.io.File;
    35 import java.util.ArrayList;
    36 import org.openide.modules.InstalledFileLocator;
    37 
    38 /**
    39  *  InstalledFileLocator implementation that searches the NB install directory
    40  * (uses java.endorsed.dirs value from nbproject/project.properties)
    41  * @author quynguyen
    42  */
    43 public class InstalledFileLocatorImpl extends InstalledFileLocator {
    44 
    45     private ArrayList<File> baseDirs;
    46     private File userDirConfigRoot;
    47     
    48     public InstalledFileLocatorImpl() {
    49         super();
    50         File endorsedDir = new File(System.getProperty("java.endorsed.dirs"));
    51         for (int i = 0; i < 5; i++) {
    52             endorsedDir = endorsedDir.getParentFile();
    53         }
    54 
    55         File installRoot = endorsedDir;
    56         File[] subdirs = installRoot.listFiles();
    57         baseDirs = new ArrayList<File>();
    58 
    59         for (int i = 0; subdirs != null && i < subdirs.length; i++) {
    60             if (subdirs[i].isDirectory()) {
    61                 baseDirs.add(subdirs[i]);
    62             }
    63         }
    64     }
    65 
    66     @Override
    67     public File locate(String relativePath, String codeNameBase, boolean localized) {
    68         for (File baseDir : baseDirs) {
    69             File f = new File(baseDir, relativePath);
    70             if (f.exists()) {
    71                 return f;
    72             }
    73         }
    74 
    75         return null;
    76     }
    77     
    78     public void setUserConfigRoot(File baseDir) {
    79         if (userDirConfigRoot != null) {
    80             baseDirs.remove(userDirConfigRoot);
    81             userDirConfigRoot = null;
    82         }
    83         
    84         if (baseDir != null) {
    85             baseDirs.add(baseDir);
    86             userDirConfigRoot = baseDir;
    87         }
    88     }
    89 }