Ability to generate the wiki from the command line.
authorJan Lahoda <jlahoda@netbeans.org>
Thu, 12 Jul 2012 15:44:44 +0200
changeset 1785123dc2edfe953
parent 17850 89899efa914c
child 17852 187963701a8c
Ability to generate the wiki from the command line.
javahints.generate/nbproject/project.xml
javahints.generate/src/org/netbeans/modules/javahints/generate/GenerateHintWiki.java
javahints.generate/src/org/netbeans/modules/javahints/generate/OptionProcessorImpl.java
     1.1 --- a/javahints.generate/nbproject/project.xml	Thu Jul 12 13:51:10 2012 +0200
     1.2 +++ b/javahints.generate/nbproject/project.xml	Thu Jul 12 15:44:44 2012 +0200
     1.3 @@ -14,6 +14,15 @@
     1.4                      </run-dependency>
     1.5                  </dependency>
     1.6                  <dependency>
     1.7 +                    <code-name-base>org.netbeans.modules.sendopts</code-name-base>
     1.8 +                    <build-prerequisite/>
     1.9 +                    <compile-dependency/>
    1.10 +                    <run-dependency>
    1.11 +                        <release-version>2</release-version>
    1.12 +                        <specification-version>2.23</specification-version>
    1.13 +                    </run-dependency>
    1.14 +                </dependency>
    1.15 +                <dependency>
    1.16                      <code-name-base>org.netbeans.spi.java.hints</code-name-base>
    1.17                      <build-prerequisite/>
    1.18                      <compile-dependency/>
    1.19 @@ -45,6 +54,14 @@
    1.20                          <specification-version>8.22</specification-version>
    1.21                      </run-dependency>
    1.22                  </dependency>
    1.23 +                <dependency>
    1.24 +                    <code-name-base>org.openide.util.lookup</code-name-base>
    1.25 +                    <build-prerequisite/>
    1.26 +                    <compile-dependency/>
    1.27 +                    <run-dependency>
    1.28 +                        <specification-version>8.16</specification-version>
    1.29 +                    </run-dependency>
    1.30 +                </dependency>
    1.31              </module-dependencies>
    1.32              <public-packages/>
    1.33          </data>
     2.1 --- a/javahints.generate/src/org/netbeans/modules/javahints/generate/GenerateHintWiki.java	Thu Jul 12 13:51:10 2012 +0200
     2.2 +++ b/javahints.generate/src/org/netbeans/modules/javahints/generate/GenerateHintWiki.java	Thu Jul 12 15:44:44 2012 +0200
     2.3 @@ -50,10 +50,11 @@
     2.4  import java.util.Map.Entry;
     2.5  import org.netbeans.modules.java.hints.providers.spi.HintMetadata;
     2.6  import org.netbeans.modules.java.hints.spiimpl.RulesManager;
     2.7 -import org.openide.awt.ActionRegistration;
     2.8 +import org.netbeans.spi.java.hints.Hint.Kind;
     2.9 +import org.openide.awt.ActionID;
    2.10  import org.openide.awt.ActionReference;
    2.11  import org.openide.awt.ActionReferences;
    2.12 -import org.openide.awt.ActionID;
    2.13 +import org.openide.awt.ActionRegistration;
    2.14  import org.openide.filesystems.FileObject;
    2.15  import org.openide.filesystems.FileUtil;
    2.16  import org.openide.util.Exceptions;
    2.17 @@ -71,6 +72,10 @@
    2.18      private  static final String HINTS_FOLDER = "org-netbeans-modules-java-hints/rules/hints/";  // NOI18N
    2.19  
    2.20      public void actionPerformed(ActionEvent e) {
    2.21 +        System.out.println(generateWiki());
    2.22 +    }
    2.23 +    
    2.24 +    public static String generateWiki() {
    2.25          Map<String, String> since = readSinceData();
    2.26          Map<String, List<HintMetadata>> category2Hint = new TreeMap<String, List<HintMetadata>>();
    2.27  
    2.28 @@ -88,6 +93,10 @@
    2.29  
    2.30          StringWriter baseOut = new StringWriter();
    2.31          PrintWriter out = new PrintWriter(baseOut);
    2.32 +        int totalHints = 0;
    2.33 +        int devHints = 0;
    2.34 +        int totalSuggestions = 0;
    2.35 +        int devSuggestions = 0;
    2.36  
    2.37          for (Entry<String, List<HintMetadata>> categoryEntry : category2Hint.entrySet()) {
    2.38              out.println("===" + categoryEntry.getKey() + "===");
    2.39 @@ -106,17 +115,32 @@
    2.40  
    2.41                      if (sinceVersion != null) {
    2.42                          out.print(" '''Since " + sinceVersion + "'''");
    2.43 +                    } else {
    2.44 +                        out.print(" '''In NetBeans 6.8 or earlier'''");
    2.45                      }
    2.46                  } else {
    2.47                      out.print(" '''In current development version'''");
    2.48 +                    if (hm.kind == Kind.INSPECTION) {
    2.49 +                        devHints++;
    2.50 +                    } else {
    2.51 +                        devSuggestions++;
    2.52 +                    }
    2.53                  }
    2.54                  out.println();
    2.55                  out.println();
    2.56 +                if (hm.kind == Kind.INSPECTION) {
    2.57 +                    totalHints++;
    2.58 +                } else {
    2.59 +                    totalSuggestions++;
    2.60 +                }
    2.61              }
    2.62          }
    2.63  
    2.64          out.close();
    2.65 -        System.err.println(baseOut.toString());
    2.66 +        
    2.67 +        return "There are " + totalHints + " total hints/inspections, " + devHints + " of them in current development version only.\n\n" +
    2.68 +               "There are " + totalSuggestions + " total suggestions/actions, " + devSuggestions + " of them in current development version only.\n\n" +
    2.69 +               baseOut.toString();
    2.70      }
    2.71  
    2.72      static String getFileObjectLocalizedName( FileObject fo ) {
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/javahints.generate/src/org/netbeans/modules/javahints/generate/OptionProcessorImpl.java	Thu Jul 12 15:44:44 2012 +0200
     3.3 @@ -0,0 +1,98 @@
     3.4 +/*
     3.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3.6 + *
     3.7 + * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
     3.8 + *
     3.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    3.10 + * Other names may be trademarks of their respective owners.
    3.11 + *
    3.12 + * The contents of this file are subject to the terms of either the GNU
    3.13 + * General Public License Version 2 only ("GPL") or the Common
    3.14 + * Development and Distribution License("CDDL") (collectively, the
    3.15 + * "License"). You may not use this file except in compliance with the
    3.16 + * License. You can obtain a copy of the License at
    3.17 + * http://www.netbeans.org/cddl-gplv2.html
    3.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    3.19 + * specific language governing permissions and limitations under the
    3.20 + * License.  When distributing the software, include this License Header
    3.21 + * Notice in each file and include the License file at
    3.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    3.23 + * particular file as subject to the "Classpath" exception as provided
    3.24 + * by Oracle in the GPL Version 2 section of the License file that
    3.25 + * accompanied this code. If applicable, add the following below the
    3.26 + * License Header, with the fields enclosed by brackets [] replaced by
    3.27 + * your own identifying information:
    3.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    3.29 + *
    3.30 + * If you wish your version of this file to be governed by only the CDDL
    3.31 + * or only the GPL Version 2, indicate your decision by adding
    3.32 + * "[Contributor] elects to include this software in this distribution
    3.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    3.34 + * single choice of license, a recipient has the option to distribute
    3.35 + * your version of this file under either the CDDL, the GPL Version 2 or
    3.36 + * to extend the choice of license to its licensees as provided above.
    3.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    3.38 + * Version 2 license, then the option applies only if the new code is
    3.39 + * made subject to such option by the copyright holder.
    3.40 + *
    3.41 + * Contributor(s):
    3.42 + *
    3.43 + * Portions Copyrighted 2012 Sun Microsystems, Inc.
    3.44 + */
    3.45 +package org.netbeans.modules.javahints.generate;
    3.46 +
    3.47 +import java.io.BufferedOutputStream;
    3.48 +import java.io.File;
    3.49 +import java.io.FileOutputStream;
    3.50 +import java.io.IOException;
    3.51 +import java.io.OutputStream;
    3.52 +import java.util.Arrays;
    3.53 +import java.util.HashSet;
    3.54 +import java.util.Map;
    3.55 +import java.util.Set;
    3.56 +import org.netbeans.api.sendopts.CommandException;
    3.57 +import org.netbeans.spi.sendopts.Env;
    3.58 +import org.netbeans.spi.sendopts.Option;
    3.59 +import org.netbeans.spi.sendopts.OptionProcessor;
    3.60 +import org.openide.LifecycleManager;
    3.61 +import org.openide.util.Exceptions;
    3.62 +import org.openide.util.lookup.ServiceProvider;
    3.63 +
    3.64 +/**
    3.65 + *
    3.66 + * @author lahvac
    3.67 + */
    3.68 +@ServiceProvider(service=OptionProcessor.class)
    3.69 +public class OptionProcessorImpl extends OptionProcessor {
    3.70 +
    3.71 +    private static final Option GENERATE_WIKI = Option.requiredArgument('g', "generate-wiki-text-and-exit");
    3.72 +    private static final Set<Option> OPTIONS = new HashSet<Option>(Arrays.asList(GENERATE_WIKI));
    3.73 +    
    3.74 +    @Override
    3.75 +    protected Set<Option> getOptions() {
    3.76 +        return OPTIONS;
    3.77 +    }
    3.78 +
    3.79 +    @Override
    3.80 +    protected void process(Env env, Map<Option, String[]> optionValues) throws CommandException {
    3.81 +        if (optionValues.containsKey(GENERATE_WIKI)) {
    3.82 +            OutputStream out = null;
    3.83 +            try {
    3.84 +                String targetFilePath = optionValues.get(GENERATE_WIKI)[0];
    3.85 +                File target = new File(env.getCurrentDirectory(), targetFilePath);
    3.86 +                out = new BufferedOutputStream(new FileOutputStream(target));
    3.87 +                out.write(GenerateHintWiki.generateWiki().getBytes("UTF-8"));
    3.88 +                LifecycleManager.getDefault().exit();
    3.89 +            } catch (IOException ex) {
    3.90 +                Exceptions.printStackTrace(ex);
    3.91 +            } finally {
    3.92 +                try {
    3.93 +                    out.close();
    3.94 +                } catch (IOException ex) {
    3.95 +                    Exceptions.printStackTrace(ex);
    3.96 +                }
    3.97 +            }
    3.98 +        }
    3.99 +    }
   3.100 +    
   3.101 +}