1 /*
   2  * Copyright (c) 2008, 2014, Oracle and/or its affiliates.
   3  * All rights reserved. Use is subject to license terms.
   4  *
   5  * This file is available and licensed under the following license:
   6  *
   7  * Redistribution and use in source and binary forms, with or without
   8  * modification, are permitted provided that the following conditions
   9  * are met:
  10  *
  11  *  - Redistributions of source code must retain the above copyright
  12  *    notice, this list of conditions and the following disclaimer.
  13  *  - Redistributions in binary form must reproduce the above copyright
  14  *    notice, this list of conditions and the following disclaimer in
  15  *    the documentation and/or other materials provided with the distribution.
  16  *  - Neither the name of Oracle Corporation nor the names of its
  17  *    contributors may be used to endorse or promote products derived
  18  *    from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31  */
  32 
  33 package ensemble.compiletime;
  34 
  35 import ensemble.compiletime.search.BuildEnsembleSearchIndex;
  36 import java.io.File;
  37 import java.util.Arrays;
  38 import java.util.List;
  39 
  40 /**
  41  * This is run during the build by ant to build sample files and search indexes
  42  */
  43 public class EnsembleCompiletimeMain {
  44     
  45     static {
  46         System.setProperty("java.net.useSystemProxies", "true");
  47     }
  48     
  49     public static void main(String[] args) {
  50         System.out.println("==================================================================");
  51         System.out.println("                 Ensemble Compile Time Build");
  52         System.out.println("args = "+Arrays.toString(args));
  53         System.out.println("==================================================================");
  54         File ensembleDir = new File(System.getProperty("user.dir"));
  55         System.out.println("ensembleDir = " + ensembleDir+" - "+ensembleDir.exists());
  56         File generatedSrcDir = new File(ensembleDir,"src/generated/java/ensemble/generated");
  57         System.out.println("generatedSrcDir = " + generatedSrcDir+" - "+generatedSrcDir.exists());
  58         generatedSrcDir.mkdirs();
  59         System.out.println("generatedSrcDir = " + generatedSrcDir.getAbsolutePath());
  60         File samplesDir = new File(ensembleDir,"src/samples/java");
  61         System.out.println("samplesDir = " + samplesDir.getAbsolutePath());
  62         File resourcesDir = new File(ensembleDir,"src/samples/resources");
  63         System.out.println("resourcesDir = " + resourcesDir.getAbsolutePath());
  64         // process args
  65         boolean buildSearchIndex = false, buildSampleClass = false;
  66         for (int a=0; a< args.length; a++) {
  67             if (args[a].equalsIgnoreCase("index")) buildSearchIndex = true;
  68             if (args[a].equalsIgnoreCase("samples")) buildSampleClass = true;
  69         }
  70         System.out.println("buildSearchIndex = " + buildSearchIndex);
  71         System.out.println("buildSampleClass = " + buildSampleClass);
  72         // build samples list
  73         List<Sample> allSamples = BuildSamplesList.build(samplesDir, resourcesDir, buildSampleClass ? new File(generatedSrcDir,"Samples.java") : null);
  74         System.out.println("TOTAL SAMPLES = " + allSamples.size());
  75         if (buildSampleClass) {
  76             System.out.println("==================================================================");
  77             System.out.println("                 Written Samples.java class file");
  78             System.out.println("==================================================================");
  79         }
  80         
  81         System.out.println("buildSearchIndex = " + buildSearchIndex);
  82         if(buildSearchIndex) {
  83             System.out.println("==================================================================");
  84             System.out.println("                     Building Search Index");
  85             System.out.println("==================================================================");
  86             File indexDir = new File(ensembleDir,"src/generated/resources/ensemble/search/index");
  87             indexDir.mkdirs();
  88             BuildEnsembleSearchIndex.buildSearchIndex(
  89                 allSamples, 
  90                 "https://docs.oracle.com/javase/8/javafx/api/",
  91                 "https://docs.oracle.com/javafx/index.html",
  92                 indexDir);
  93         }
  94     }
  95 }