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