Automated merge with http://hg.netbeans.org/netigso
authorffjre@netbeans.org
Sat, 20 Jun 2009 03:43:21 +0400
changeset 92232eafc9ea617
parent 921 9b35ddc3fdb0
parent 795 f15e0f9ef6a0
child 923 15ebda6eb52b
Automated merge with http://hg.netbeans.org/netigso
     1.1 --- a/openide.util/apichanges.xml	Fri Jun 19 03:44:33 2009 +0400
     1.2 +++ b/openide.util/apichanges.xml	Sat Jun 20 03:43:21 2009 +0400
     1.3 @@ -49,6 +49,23 @@
     1.4      <apidef name="actions">Actions API</apidef>
     1.5  </apidefs>
     1.6  <changes>
     1.7 +    <change id="org.openide.util.Lookup.paths">
     1.8 +        <api name="lookup"/>
     1.9 +        <summary>Added
    1.10 +            <code>org.openide.util.Lookup.paths</code> property
    1.11 +        </summary>
    1.12 +        <version major="7" minor="24"/>
    1.13 +        <date day="19" month="6" year="2009"/>
    1.14 +        <author login="jtulach"/>
    1.15 +        <compatibility addition="yes"/>
    1.16 +        <description>
    1.17 +            <p>
    1.18 +                 Better way to integrate Lookup.getDefault() and system filesystem.
    1.19 +            </p>
    1.20 +        </description>
    1.21 +        <class package="org.openide.util" name="Lookup"/>
    1.22 +        <issue number="166782"/>
    1.23 +    </change>
    1.24      <change id="enableStackTraces">
    1.25          <api name="util"/>
    1.26          <summary>Added constructor <code>RequestProcessor(String name, int throughput, boolean interruptThread, boolean enableStackTraces)</code></summary>
     2.1 --- a/openide.util/arch.xml	Fri Jun 19 03:44:33 2009 +0400
     2.2 +++ b/openide.util/arch.xml	Sat Jun 20 03:43:21 2009 +0400
     2.3 @@ -514,6 +514,21 @@
     2.4          is the result of <a href="@TOP@/org/openide/util/Lookup.html#getDefault()">Lookup.getDefault()</a>.
     2.5      </api>
     2.6      </li>
     2.7 +
     2.8 +    <li>
     2.9 +    <api type="export" group="property" name="org.openide.util.Lookup.paths" category="devel">
    2.10 +        Sometimes it may be useful for the Lookup to contains objects from
    2.11 +        some system file system folder. This can be done with
    2.12 +        <code>org.openide.util.Lookup.paths=Folder1:Folder2:Folder3</code>.
    2.13 +        If this property is set prior to first call to
    2.14 +        <a href="@TOP@/org/openide/util/Lookup.html#getDefault()">Lookup.getDefault()</a>,
    2.15 +        it is split into pieces (separator is <code>':'</code>) and individual
    2.16 +        parts are then used to construct <code>Lookups.forPath("Folder1")</code>,
    2.17 +        etc. All these lookups then become part of the
    2.18 +        <a href="@TOP@/org/openide/util/Lookup.html#getDefault()">Lookup.getDefault()</a>
    2.19 +        one. This property works since version 7.24
    2.20 +    </api>
    2.21 +    </li>
    2.22      
    2.23    </ul>
    2.24   </answer>
     3.1 --- a/openide.util/src/org/openide/util/Lookup.java	Fri Jun 19 03:44:33 2009 +0400
     3.2 +++ b/openide.util/src/org/openide/util/Lookup.java	Sat Jun 20 03:43:21 2009 +0400
     3.3 @@ -41,9 +41,11 @@
     3.4  
     3.5  package org.openide.util;
     3.6  
     3.7 +import java.util.ArrayList;
     3.8  import java.util.Collection;
     3.9  import java.util.Collections;
    3.10  import java.util.Iterator;
    3.11 +import java.util.List;
    3.12  import java.util.Set;
    3.13  import org.openide.util.lookup.Lookups;
    3.14  import org.openide.util.lookup.ProxyLookup;
    3.15 @@ -149,8 +151,10 @@
    3.16          }
    3.17  
    3.18          DefLookup def = new DefLookup();
    3.19 -        def.init(l, misl);
    3.20 -        return defaultLookup = def;
    3.21 +        def.init(l, misl, false);
    3.22 +        defaultLookup = def;
    3.23 +        def.init(l, misl, true);
    3.24 +        return defaultLookup;
    3.25      }
    3.26      
    3.27      private static final class DefLookup extends ProxyLookup {
    3.28 @@ -158,12 +162,21 @@
    3.29              super(new Lookup[0]);
    3.30          }
    3.31          
    3.32 -        public void init(ClassLoader loader, Lookup metaInfLookup) {
    3.33 +        public void init(ClassLoader loader, Lookup metaInfLookup, boolean addPath) {
    3.34              // Had no such line, use simple impl.
    3.35              // It does however need to have ClassLoader available or many things will break.
    3.36              // Use the thread context classloader in effect now.
    3.37              Lookup clLookup = Lookups.singleton(loader);
    3.38 -            setLookups(new Lookup[] { metaInfLookup, clLookup });
    3.39 +            List<Lookup> arr = new ArrayList<Lookup>();
    3.40 +            arr.add(metaInfLookup);
    3.41 +            arr.add(clLookup);
    3.42 +            String paths = System.getProperty("org.openide.util.Lookup.paths"); // NOI18N
    3.43 +            if (addPath && paths != null) {
    3.44 +                for (String p : paths.split(":")) { // NOI18N
    3.45 +                    arr.add(Lookups.forPath(p));
    3.46 +                }
    3.47 +            }
    3.48 +            setLookups(arr.toArray(new Lookup[0]));
    3.49          }
    3.50      }
    3.51      
    3.52 @@ -173,7 +186,7 @@
    3.53          if (defaultLookup instanceof DefLookup) {
    3.54              DefLookup def = (DefLookup)defaultLookup;
    3.55              ClassLoader l = Thread.currentThread().getContextClassLoader();
    3.56 -            def.init(l, Lookups.metaInfServices(l));
    3.57 +            def.init(l, Lookups.metaInfServices(l), true);
    3.58          }
    3.59      }
    3.60  
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/openide.util/test/unit/src/org/openide/util/lookup/PathInLookupTest.java	Sat Jun 20 03:43:21 2009 +0400
     4.3 @@ -0,0 +1,112 @@
     4.4 +/*
     4.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     4.6 + *
     4.7 + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
     4.8 + *
     4.9 + * The contents of this file are subject to the terms of either the GNU
    4.10 + * General Public License Version 2 only ("GPL") or the Common
    4.11 + * Development and Distribution License("CDDL") (collectively, the
    4.12 + * "License"). You may not use this file except in compliance with the
    4.13 + * License. You can obtain a copy of the License at
    4.14 + * http://www.netbeans.org/cddl-gplv2.html
    4.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    4.16 + * specific language governing permissions and limitations under the
    4.17 + * License.  When distributing the software, include this License Header
    4.18 + * Notice in each file and include the License file at
    4.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    4.20 + * particular file as subject to the "Classpath" exception as provided
    4.21 + * by Sun in the GPL Version 2 section of the License file that
    4.22 + * accompanied this code. If applicable, add the following below the
    4.23 + * License Header, with the fields enclosed by brackets [] replaced by
    4.24 + * your own identifying information:
    4.25 + * "Portions Copyrighted [year] [name of copyright owner]"
    4.26 + *
    4.27 + * Contributor(s):
    4.28 + *
    4.29 + * The Original Software is NetBeans. The Initial Developer of the Original
    4.30 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
    4.31 + * Microsystems, Inc. All Rights Reserved.
    4.32 + *
    4.33 + * If you wish your version of this file to be governed by only the CDDL
    4.34 + * or only the GPL Version 2, indicate your decision by adding
    4.35 + * "[Contributor] elects to include this software in this distribution
    4.36 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    4.37 + * single choice of license, a recipient has the option to distribute
    4.38 + * your version of this file under either the CDDL, the GPL Version 2 or
    4.39 + * to extend the choice of license to its licensees as provided above.
    4.40 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    4.41 + * Version 2 license, then the option applies only if the new code is
    4.42 + * made subject to such option by the copyright holder.
    4.43 + */
    4.44 +
    4.45 +package org.openide.util.lookup;
    4.46 +
    4.47 +import java.util.logging.Level;
    4.48 +import org.netbeans.junit.MockServices;
    4.49 +import org.netbeans.junit.NbTestCase;
    4.50 +import org.netbeans.modules.openide.util.NamedServicesProvider;
    4.51 +import org.openide.util.Lookup;
    4.52 +
    4.53 +/** 
    4.54 + * @author Jaroslav Tulach
    4.55 + */
    4.56 +public class PathInLookupTest extends NbTestCase {
    4.57 +    static {
    4.58 +        System.setProperty("org.openide.util.Lookup.paths", "MyServices:YourServices");
    4.59 +        MockServices.setServices(P.class);
    4.60 +        Lookup.getDefault();
    4.61 +    }
    4.62 +
    4.63 +    public PathInLookupTest(String name) {
    4.64 +        super(name);
    4.65 +    }
    4.66 +
    4.67 +    @Override
    4.68 +    protected Level logLevel() {
    4.69 +        return Level.FINE;
    4.70 +    }
    4.71 +    
    4.72 +    public void testInterfaceFoundInMyServices() throws Exception {
    4.73 +        assertNull("not found", Lookup.getDefault().lookup(Shared.class));
    4.74 +        Shared v = new Shared();
    4.75 +        P.ic1.add(v);
    4.76 +        assertNotNull("found", Lookup.getDefault().lookup(Shared.class));
    4.77 +        P.ic1.remove(v);
    4.78 +        assertNull("not found again", Lookup.getDefault().lookup(Shared.class));
    4.79 +    }
    4.80 +    public void testInterfaceFoundInMyServices2() throws Exception {
    4.81 +        assertNull("not found", Lookup.getDefault().lookup(Shared.class));
    4.82 +        Shared v = new Shared();
    4.83 +        P.ic2.add(v);
    4.84 +        assertNotNull("found", Lookup.getDefault().lookup(Shared.class));
    4.85 +        P.ic2.remove(v);
    4.86 +        assertNull("not found again", Lookup.getDefault().lookup(Shared.class));
    4.87 +    }
    4.88 +
    4.89 +    static final class Shared extends Object {}
    4.90 +
    4.91 +    public static final class P extends NamedServicesProvider {
    4.92 +        static InstanceContent ic1 = new InstanceContent();
    4.93 +        static InstanceContent ic2 = new InstanceContent();
    4.94 +        static AbstractLookup[] arr = {
    4.95 +            new AbstractLookup(ic1), new AbstractLookup(ic2)
    4.96 +        };
    4.97 +
    4.98 +
    4.99 +        @Override
   4.100 +        public Lookup create(String path) {
   4.101 +            int indx = -1;
   4.102 +            if (path.equals("MyServices/")) {
   4.103 +                indx = 0;
   4.104 +            }
   4.105 +            if (path.equals("YourServices/")) {
   4.106 +                indx = 1;
   4.107 +            }
   4.108 +            if (indx == -1) {
   4.109 +                fail("Unexpected lookup query: " + path);
   4.110 +            }
   4.111 +            return arr[indx];
   4.112 +        }
   4.113 +    }
   4.114 +
   4.115 +}