View Javadoc
1   /*
2    * (c) Copyright 2006-2020 by rapiddweller GmbH & Volker Bergmann. All rights reserved.
3    *
4    * Redistribution and use in source and binary forms, with or without
5    * modification, is permitted under the terms of the
6    * GNU General Public License.
7    *
8    * For redistributing this software or a derivative work under a license other
9    * than the GPL-compatible Free Software License as defined by the Free
10   * Software Foundation or approved by OSI, you must first obtain a commercial
11   * license to this software product from rapiddweller GmbH & Volker Bergmann.
12   *
13   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14   * WITHOUT A WARRANTY OF ANY KIND. ALL EXPRESS OR IMPLIED CONDITIONS,
15   * REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
16   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
17   * HEREBY EXCLUDED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24   * POSSIBILITY OF SUCH DAMAGE.
25   */
26  
27  package com.rapiddweller.benerator;
28  
29  import com.rapiddweller.common.LogCategoriesConstants;
30  import com.rapiddweller.common.StringUtil;
31  import com.rapiddweller.common.SystemInfo;
32  import com.rapiddweller.common.VMInfo;
33  import com.rapiddweller.common.ui.InfoPrinter;
34  import com.rapiddweller.common.version.VersionInfo;
35  import com.rapiddweller.common.version.VersionNumber;
36  import com.rapiddweller.profile.Profiling;
37  import org.apache.logging.log4j.LogManager;
38  import org.apache.logging.log4j.Logger;
39  
40  import java.io.File;
41  
42  /**
43   * Provides general utility methods for Benerator.<br/><br/>
44   * Created: 01.02.2013 16:20:10
45   *
46   * @author Volker Bergmann
47   * @since 0.8.0
48   */
49  public class BeneratorUtil {
50  
51    private static final Logger CONFIG_LOGGER = LogManager.getLogger(LogCategoriesConstants.CONFIG);
52  
53    /**
54     * Is descriptor file path boolean.
55     *
56     * @param filePath the file path
57     * @return the boolean
58     */
59    public static boolean isDescriptorFilePath(String filePath) {
60      if (StringUtil.isEmpty(filePath)) {
61        return false;
62      }
63      String lcName = filePath.toLowerCase();
64      return ("benerator.xml".equals(filePath) || lcName.replace(File.separatorChar, '/').endsWith("/benerator.xml") || lcName.endsWith(".ben.xml"));
65    }
66  
67    /**
68     * Check system.
69     *
70     * @param printer the printer
71     */
72    public static void checkSystem(InfoPrinter printer) {
73      printVersionInfo(printer);
74      printer.printLines("Configured heap size limit: " + Runtime.getRuntime().maxMemory() / 1024 / 1024 + " MB");
75      try {
76        Class.forName("javax.script.ScriptEngine");
77      } catch (ClassNotFoundException e) {
78        CONFIG_LOGGER.error("You need to run benerator with Java 6 or greater!");
79        if (SystemInfo.isMacOsx()) {
80          CONFIG_LOGGER.error("Please check the manual for Java setup on Mac OS X.");
81        }
82        System.exit(BeneratorConstants.EXIT_CODE_ERROR);
83      }
84      VersionNumber javaVersion = VersionNumber.valueOf(VMInfo.getJavaVersion());
85      if (javaVersion.compareTo(VersionNumber.valueOf("1.6")) < 0) {
86        CONFIG_LOGGER.warn("benerator is written for and tested under Java 6 - " +
87            "you managed to set up JSR 223, but may face other problems.");
88      }
89      if (Profiling.isEnabled()) {
90        CONFIG_LOGGER.warn("Profiling is active. This may lead to memory issues");
91      }
92    }
93  
94    /**
95     * Print version info.
96     *
97     * @param printer the printer
98     */
99    public static void printVersionInfo(InfoPrinter printer) {
100     VersionInfo version = VersionInfo.getInfo("benerator");
101     printer.printLines(
102         "Benerator " + version.getVersion() + " build " + version.getBuildNumber(),
103         "Java version " + VMInfo.getJavaVersion(),
104         "JVM " + VMInfo.getJavaVmName() + " " + VMInfo.getJavaVmVersion() + " (" + VMInfo.getJavaVmVendor() + ")",
105         "OS " + SystemInfo.getOsName() + " " + SystemInfo.getOsVersion() + " (" + SystemInfo.getOsArchitecture() + ")"
106     );
107   }
108 
109   /**
110    * Log config.
111    *
112    * @param config the config
113    */
114   public static void logConfig(String config) {
115     CONFIG_LOGGER.info(config);
116   }
117 
118 }