Adding display name to the index, deleting the CategoryStorage from indexer
authorJan Lahoda <jlahoda@netbeans.org>
Fri, 24 Jun 2011 12:52:51 +0200
changeset 602267ce38bf4e1
parent 601 31c553c68621
child 603 344c8da2fe02
Adding display name to the index, deleting the CategoryStorage from indexer
remoting/ide/api/nbproject/genfiles.properties
remoting/server/indexer/impl/src/org/netbeans/modules/jackpot30/backend/impl/CategoryStorage.java
remoting/server/indexer/impl/src/org/netbeans/modules/jackpot30/backend/impl/OptionProcessorImpl.java
remoting/server/web/base.web.api/nbproject/project.properties
remoting/server/web/base.web.api/src/org/netbeans/modules/jackpot30/backend/base/CategoryStorage.java
     1.1 --- a/remoting/ide/api/nbproject/genfiles.properties	Fri Jun 24 12:50:36 2011 +0200
     1.2 +++ b/remoting/ide/api/nbproject/genfiles.properties	Fri Jun 24 12:52:51 2011 +0200
     1.3 @@ -3,6 +3,6 @@
     1.4  build.xml.stylesheet.CRC32=a56c6a5b@1.47
     1.5  # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
     1.6  # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
     1.7 -nbproject/build-impl.xml.data.CRC32=83c779aa
     1.8 +nbproject/build-impl.xml.data.CRC32=520e4629
     1.9  nbproject/build-impl.xml.script.CRC32=33cac223
    1.10  nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.47
     2.1 --- a/remoting/server/indexer/impl/src/org/netbeans/modules/jackpot30/backend/impl/CategoryStorage.java	Fri Jun 24 12:50:36 2011 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,126 +0,0 @@
     2.4 -/*
     2.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     2.6 - *
     2.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
     2.8 - *
     2.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    2.10 - * Other names may be trademarks of their respective owners.
    2.11 - *
    2.12 - * The contents of this file are subject to the terms of either the GNU
    2.13 - * General Public License Version 2 only ("GPL") or the Common
    2.14 - * Development and Distribution License("CDDL") (collectively, the
    2.15 - * "License"). You may not use this file except in compliance with the
    2.16 - * License. You can obtain a copy of the License at
    2.17 - * http://www.netbeans.org/cddl-gplv2.html
    2.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    2.19 - * specific language governing permissions and limitations under the
    2.20 - * License.  When distributing the software, include this License Header
    2.21 - * Notice in each file and include the License file at
    2.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    2.23 - * particular file as subject to the "Classpath" exception as provided
    2.24 - * by Oracle in the GPL Version 2 section of the License file that
    2.25 - * accompanied this code. If applicable, add the following below the
    2.26 - * License Header, with the fields enclosed by brackets [] replaced by
    2.27 - * your own identifying information:
    2.28 - * "Portions Copyrighted [year] [name of copyright owner]"
    2.29 - *
    2.30 - * If you wish your version of this file to be governed by only the CDDL
    2.31 - * or only the GPL Version 2, indicate your decision by adding
    2.32 - * "[Contributor] elects to include this software in this distribution
    2.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    2.34 - * single choice of license, a recipient has the option to distribute
    2.35 - * your version of this file under either the CDDL, the GPL Version 2 or
    2.36 - * to extend the choice of license to its licensees as provided above.
    2.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    2.38 - * Version 2 license, then the option applies only if the new code is
    2.39 - * made subject to such option by the copyright holder.
    2.40 - *
    2.41 - * Contributor(s):
    2.42 - *
    2.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
    2.44 - */
    2.45 -package org.netbeans.modules.jackpot30.backend.impl;
    2.46 -
    2.47 -import java.net.MalformedURLException;
    2.48 -import java.net.URL;
    2.49 -import java.util.HashMap;
    2.50 -import java.util.HashSet;
    2.51 -import java.util.Map;
    2.52 -import java.util.Set;
    2.53 -import java.util.prefs.BackingStoreException;
    2.54 -import java.util.prefs.Preferences;
    2.55 -import org.openide.filesystems.FileObject;
    2.56 -import org.openide.filesystems.FileStateInvalidException;
    2.57 -import org.openide.filesystems.URLMapper;
    2.58 -import org.openide.util.Exceptions;
    2.59 -import org.openide.util.NbPreferences;
    2.60 -
    2.61 -/**
    2.62 - *
    2.63 - * @author lahvac
    2.64 - */
    2.65 -public class CategoryStorage {
    2.66 -
    2.67 -    public static void setCategoryContent(String categoryId, String categoryName, Set<FileObject> content) {
    2.68 -        Preferences categoriesNode = NbPreferences.forModule(CategoryStorage.class).node("categories");
    2.69 -
    2.70 -        categoriesNode.put(categoryId + "_displayName", categoryName);
    2.71 -
    2.72 -        StringBuilder roots = new StringBuilder();
    2.73 -
    2.74 -        for (FileObject f : content) {
    2.75 -            if (roots.length() > 0) {
    2.76 -                roots.append(';');
    2.77 -            }
    2.78 -
    2.79 -            try {
    2.80 -                roots.append(f.getURL().toExternalForm());
    2.81 -            } catch (FileStateInvalidException ex) {
    2.82 -                Exceptions.printStackTrace(ex);
    2.83 -            }
    2.84 -        }
    2.85 -
    2.86 -        categoriesNode.put(categoryId + "_roots", roots.toString());
    2.87 -    }
    2.88 -
    2.89 -    public static Set<FileObject> getCategoryContent(String categoryId) {
    2.90 -        Preferences categoriesNode = NbPreferences.forModule(CategoryStorage.class).node("categories");
    2.91 -        String roots = categoriesNode.get(categoryId + "_roots", "");
    2.92 -        Set<FileObject> result = new HashSet<FileObject>();
    2.93 -
    2.94 -        for (String urlString : roots.split(";")) {
    2.95 -            if (urlString.isEmpty()) continue;
    2.96 -
    2.97 -            try {
    2.98 -                URL url = new URL(urlString);
    2.99 -                FileObject root = URLMapper.findFileObject(url);
   2.100 -
   2.101 -                if (root != null) {
   2.102 -                    result.add(root);
   2.103 -                }
   2.104 -            } catch (MalformedURLException ex) {
   2.105 -                Exceptions.printStackTrace(ex);
   2.106 -            }
   2.107 -        }
   2.108 -
   2.109 -        return result;
   2.110 -    }
   2.111 -
   2.112 -    public static Map<String, String> listCategoriesWithNames() {
   2.113 -        Map<String, String> result = new HashMap<String, String>();
   2.114 -        Preferences categoriesNode = NbPreferences.forModule(CategoryStorage.class).node("categories");
   2.115 -
   2.116 -        try {
   2.117 -            for (String key : categoriesNode.keys()) {
   2.118 -                if (key.endsWith("_displayName")) {
   2.119 -                    String id = key.substring(0, key.length() - "_displayName".length());
   2.120 -                    result.put(id, categoriesNode.get(key, id));
   2.121 -                }
   2.122 -            }
   2.123 -        } catch (BackingStoreException ex) {
   2.124 -            Exceptions.printStackTrace(ex);
   2.125 -        }
   2.126 -
   2.127 -        return result;
   2.128 -    }
   2.129 -}
     3.1 --- a/remoting/server/indexer/impl/src/org/netbeans/modules/jackpot30/backend/impl/OptionProcessorImpl.java	Fri Jun 24 12:50:36 2011 +0200
     3.2 +++ b/remoting/server/indexer/impl/src/org/netbeans/modules/jackpot30/backend/impl/OptionProcessorImpl.java	Fri Jun 24 12:52:51 2011 +0200
     3.3 @@ -47,6 +47,7 @@
     3.4  import java.io.IOException;
     3.5  import java.io.InputStream;
     3.6  import java.util.Arrays;
     3.7 +import java.util.HashMap;
     3.8  import java.util.HashSet;
     3.9  import java.util.Map;
    3.10  import java.util.Properties;
    3.11 @@ -116,12 +117,6 @@
    3.12                  env.getErrorStream().println("Warning: no category-name specified.");
    3.13                  return;
    3.14              }
    3.15 -
    3.16 -            try {
    3.17 -                CategoryStorage.setCategoryContent(categoryId, categoryName, getRoots(optionValues.get(CATEGORY_PROJECTS), env));
    3.18 -            } catch (InterruptedException ex) {
    3.19 -                throw (CommandException) new CommandException(0).initCause(ex);
    3.20 -            }
    3.21          }
    3.22  
    3.23          String cacheTarget = optionValues.get(CACHE_TARGET)[0];
    3.24 @@ -135,7 +130,9 @@
    3.25          }
    3.26  
    3.27          try {
    3.28 -            indexProjects(CategoryStorage.getCategoryContent(categoryId), env);
    3.29 +            Set<FileObject> roots = getRoots(optionValues.get(CATEGORY_PROJECTS), env);
    3.30 +
    3.31 +            indexProjects(roots, env);
    3.32          } catch (InterruptedException ex) {
    3.33              throw (CommandException) new CommandException(0).initCause(ex);
    3.34          } catch (IOException ex) {
    3.35 @@ -173,6 +170,10 @@
    3.36              out.putNextEntry(new ZipEntry(categoryId + "/segments"));
    3.37  
    3.38              outSegments.store(out, "");
    3.39 +
    3.40 +            out.putNextEntry(new ZipEntry(categoryId + "/info"));
    3.41 +
    3.42 +            out.write(("{ \"displayName\": \"" + categoryName + "\" }").getBytes("UTF-8"));
    3.43          } catch (IOException ex) {
    3.44              throw (CommandException) new CommandException(0).initCause(ex);
    3.45          } finally {
     4.1 --- a/remoting/server/web/base.web.api/nbproject/project.properties	Fri Jun 24 12:50:36 2011 +0200
     4.2 +++ b/remoting/server/web/base.web.api/nbproject/project.properties	Fri Jun 24 12:52:51 2011 +0200
     4.3 @@ -30,6 +30,8 @@
     4.4  file.reference.org-netbeans-modules-parsing-api.jar=../../../../server/lib/org-netbeans-modules-parsing-api.jar
     4.5  file.reference.org-openide-filesystems.jar=../../../../server/lib/org-openide-filesystems.jar
     4.6  file.reference.org-openide-util-lookup.jar=../../../../server/lib/org-openide-util-lookup.jar
     4.7 +file.reference.util-commons.jar=../../../ide/api/external/util-commons.jar
     4.8 +file.reference.util-pojson.jar=../../../ide/api/external/util-pojson.jar
     4.9  includes=**
    4.10  jar.compress=false
    4.11  javac.classpath=\
    4.12 @@ -38,7 +40,9 @@
    4.13      ${file.reference.org-netbeans-modules-java-source.jar}:\
    4.14      ${file.reference.org-netbeans-modules-parsing-api.jar}:\
    4.15      ${file.reference.org-openide-filesystems.jar}:\
    4.16 -    ${file.reference.org-openide-util-lookup.jar}
    4.17 +    ${file.reference.org-openide-util-lookup.jar}:\
    4.18 +    ${file.reference.util-commons.jar}:\
    4.19 +    ${file.reference.util-pojson.jar}
    4.20  # Space-separated list of extra javac options
    4.21  javac.compilerargs=
    4.22  javac.deprecation=false
     5.1 --- a/remoting/server/web/base.web.api/src/org/netbeans/modules/jackpot30/backend/base/CategoryStorage.java	Fri Jun 24 12:50:36 2011 +0200
     5.2 +++ b/remoting/server/web/base.web.api/src/org/netbeans/modules/jackpot30/backend/base/CategoryStorage.java	Fri Jun 24 12:52:51 2011 +0200
     5.3 @@ -42,17 +42,20 @@
     5.4  package org.netbeans.modules.jackpot30.backend.base;
     5.5  
     5.6  import java.io.File;
     5.7 +import java.io.FileNotFoundException;
     5.8  import java.io.IOException;
     5.9  import java.lang.reflect.Field;
    5.10  import java.net.URL;
    5.11  import java.util.ArrayList;
    5.12  import java.util.Collections;
    5.13 +import java.util.HashMap;
    5.14  import java.util.HashSet;
    5.15  import java.util.List;
    5.16  import java.util.Map;
    5.17  import java.util.Set;
    5.18  import java.util.logging.Level;
    5.19  import java.util.logging.Logger;
    5.20 +import org.codeviation.pojson.Pojson;
    5.21  import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
    5.22  import org.openide.filesystems.FileObject;
    5.23  import org.openide.filesystems.FileUtil;
    5.24 @@ -73,7 +76,22 @@
    5.25          List<CategoryStorage> result = new ArrayList<CategoryStorage>();
    5.26  
    5.27          for (File cat : cacheRoot.listFiles()) {
    5.28 -            result.add(new CategoryStorage(cat.getName()));
    5.29 +            File info = new File(cat, "info");
    5.30 +            String displayName = cat.getName();
    5.31 +            if (info.canRead()) {
    5.32 +                try {
    5.33 +                    @SuppressWarnings("unchecked")
    5.34 +                    Map<String, Object> data = Pojson.load(HashMap.class, info);
    5.35 +                    if (data.containsKey("displayName")) {
    5.36 +                        displayName = (String) data.get("displayName"); //XXX: should check type!
    5.37 +                    }
    5.38 +                } catch (FileNotFoundException ex) {
    5.39 +                    Logger.getLogger(CategoryStorage.class.getName()).log(Level.SEVERE, null, ex);
    5.40 +                } catch (IOException ex) {
    5.41 +                    Logger.getLogger(CategoryStorage.class.getName()).log(Level.SEVERE, null, ex);
    5.42 +                }
    5.43 +            }
    5.44 +            result.add(new CategoryStorage(cat.getName(), displayName));
    5.45          }
    5.46  
    5.47          return result;
    5.48 @@ -88,9 +106,11 @@
    5.49      }
    5.50      
    5.51      private final String id;
    5.52 +    private final String displayName;
    5.53  
    5.54 -    private CategoryStorage(String id) {
    5.55 +    private CategoryStorage(String id, String displayName) {
    5.56          this.id = id;
    5.57 +        this.displayName = displayName;
    5.58      }
    5.59  
    5.60      public Iterable<? extends URL> getCategoryIndexFolders() {
    5.61 @@ -106,6 +126,7 @@
    5.62  
    5.63              invertedSegmentsField.setAccessible(true);
    5.64              
    5.65 +            @SuppressWarnings("unchecked")
    5.66              Map<String, String> invertedSegments = (Map<String, String>) invertedSegmentsField.get(null);
    5.67  
    5.68              for (String c : invertedSegments.keySet()) {
    5.69 @@ -132,7 +153,7 @@
    5.70      }
    5.71  
    5.72      public String getDisplayName() {
    5.73 -        return id;//XXX
    5.74 +        return displayName;
    5.75      }
    5.76  
    5.77      public FileObject getCacheRoot() {