Example usage for java.io File getPath

List of usage examples for java.io File getPath

Introduction

In this page you can find the example usage for java.io File getPath.

Prototype

public String getPath() 

Source Link

Document

Converts this abstract pathname into a pathname string.

Usage

From source file:KillFilesByName.java

public static void main(String[] argv) {
    if (argv.length != 2) {
        System.err.println("usage: KillFilesByName dirname pattern");
        System.exit(1);/*from  www  .j  a v  a 2s . c  o m*/
    }

    File dir = new File(argv[0]);
    if (!dir.exists()) {
        System.out.println(argv[0] + " does not exist");
        return;
    }
    String patt = argv[1];

    String[] info = dir.list();
    for (int i = 0; i < info.length; i++) {
        File n = new File(argv[0] + dir.separator + info[i]);
        if (!n.isFile()) { // skip ., .., other directories, etc.
            continue;
        }
        if (info[i].indexOf(patt) == -1) { // name doesn't match
            continue;
        }
        System.out.println("removing " + n.getPath());
        if (!n.delete())
            System.err.println("Couldn't remove " + n.getPath());
    }
}

From source file:LauncherBootstrap.java

/**
 * The main method.//from  w w w . j  a  va  2 s .c  o m
 *
 * @param args command line arguments
 */
public static void main(String[] args) {

    try {

        // Try to find the LAUNCHER_JAR_FILE_NAME file in the class
        // loader's and JVM's classpath.
        URL coreURL = LauncherBootstrap.class.getResource("/" + LauncherBootstrap.LAUNCHER_JAR_FILE_NAME);
        if (coreURL == null)
            throw new FileNotFoundException(LauncherBootstrap.LAUNCHER_JAR_FILE_NAME);

        // Coerce the coreURL's directory into a file
        File coreDir = new File(URLDecoder.decode(coreURL.getFile())).getCanonicalFile().getParentFile();

        // Try to find the LAUNCHER_PROPS_FILE_NAME file in the same
        // directory as this class
        File propsFile = new File(coreDir, LauncherBootstrap.LAUNCHER_PROPS_FILE_NAME);
        if (!propsFile.canRead())
            throw new FileNotFoundException(propsFile.getPath());

        // Load the properties in the LAUNCHER_PROPS_FILE_NAME 
        Properties props = new Properties();
        FileInputStream fis = new FileInputStream(propsFile);
        props.load(fis);
        fis.close();

        // Create a class loader that contains the Launcher, Ant, and
        // JAXP classes.
        URL[] antURLs = LauncherBootstrap
                .fileListToURLs((String) props.get(LauncherBootstrap.ANT_CLASSPATH_PROP_NAME));
        URL[] urls = new URL[1 + antURLs.length];
        urls[0] = coreURL;
        for (int i = 0; i < antURLs.length; i++)
            urls[i + 1] = antURLs[i];
        ClassLoader parentLoader = Thread.currentThread().getContextClassLoader();
        URLClassLoader loader = null;
        if (parentLoader != null)
            loader = new URLClassLoader(urls, parentLoader);
        else
            loader = new URLClassLoader(urls);

        // Load the LAUNCHER_MAIN_CLASS_NAME class
        launcherClass = loader.loadClass(LAUNCHER_MAIN_CLASS_NAME);

        // Get the LAUNCHER_MAIN_CLASS_NAME class' getLocalizedString()
        // method as we need it for printing the usage statement
        Method getLocalizedStringMethod = launcherClass.getDeclaredMethod("getLocalizedString",
                new Class[] { String.class });

        // Invoke the LAUNCHER_MAIN_CLASS_NAME class' start() method.
        // If the ant.class.path property is not set correctly in the 
        // LAUNCHER_PROPS_FILE_NAME, this will throw an exception.
        Method startMethod = launcherClass.getDeclaredMethod("start", new Class[] { String[].class });
        int returnValue = ((Integer) startMethod.invoke(null, new Object[] { args })).intValue();
        // Always exit cleanly after invoking the start() method
        System.exit(returnValue);

    } catch (Throwable t) {

        t.printStackTrace();
        System.exit(1);

    }

}

From source file:at.tuwien.ifs.somtoolbox.apps.VisualisationImageSaver.java

public static void main(String[] args) {
    JSAPResult res = OptionFactory.parseResults(args, OPTIONS);

    String uFile = res.getString("unitDescriptionFile");
    String wFile = res.getString("weightVectorFile");
    String dwmFile = res.getString("dataWinnerMappingFile");
    String cFile = res.getString("classInformationFile");
    String vFile = res.getString("inputVectorFile");
    String tFile = res.getString("templateVectorFile");
    String ftype = res.getString("filetype");
    boolean unitGrid = res.getBoolean("unitGrid");

    String basename = res.getString("basename");
    if (basename == null) {
        basename = FileUtils.extractSOMLibInputPrefix(uFile);
    }/*from w w w  .  j av a  2 s.  c  om*/
    basename = new File(basename).getAbsolutePath();
    int unitW = res.getInt("width");
    int unitH = res.getInt("height", unitW);

    String[] vizs = res.getStringArray("vis");

    GrowingSOM gsom = null;
    CommonSOMViewerStateData state = CommonSOMViewerStateData.getInstance();
    try {
        SOMLibFormatInputReader inputReader = new SOMLibFormatInputReader(wFile, uFile, null);
        gsom = new GrowingSOM(inputReader);

        SharedSOMVisualisationData d = new SharedSOMVisualisationData(cFile, null, null, dwmFile, vFile, tFile,
                null);
        d.readAvailableData();
        state.inputDataObjects = d;
        gsom.setSharedInputObjects(d);

        Visualizations.initVisualizations(d, inputReader, 0, Palettes.getDefaultPalette(),
                Palettes.getAvailablePalettes());

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.exit(1);
    } catch (SOMLibFileFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.exit(1);
    }

    if (ArrayUtils.isEmpty(vizs)) {
        System.out.println("No specific visualisation specified - saving all available visualisations.");
        vizs = Visualizations.getReadyVisualizationNames();
        System.out.println("Found " + vizs.length + ": " + Arrays.toString(vizs));
    }

    for (String viz : vizs) {
        BackgroundImageVisualizerInstance v = Visualizations.getVisualizationByName(viz);
        if (v == null) {
            System.out.println("Visualization '" + viz + "' not found!");
            continue;
        }
        BackgroundImageVisualizer i = v.getVis();

        GrowingLayer layer = gsom.getLayer();
        try {
            int height = unitH * layer.getYSize();
            int width = unitW * layer.getXSize();
            HashMap<String, BufferedImage> visualizationFlavours = i.getVisualizationFlavours(v.getVariant(),
                    gsom, width, height);
            ArrayList<String> keys = new ArrayList<String>(visualizationFlavours.keySet());
            Collections.sort(keys);

            // if the visualisation has more than 5 flavours, we create a sub-dir for it
            String subDirName = "";
            String oldBasename = basename; // save original base name for later
            if (keys.size() > 5) {
                String parentDir = new File(basename).getParentFile().getPath(); // get the parent path
                String filePrefix = basename.substring(parentDir.length()); // end the file name prefix
                subDirName = parentDir + File.separator + filePrefix + "_" + viz + File.separator; // compose a new
                // subdir name
                new File(subDirName).mkdir(); // create the dir
                basename = subDirName + filePrefix; // and extend the base name by the subdir
            }
            for (String key : keys) {
                File out = new File(basename + "_" + viz + key + "." + ftype);
                System.out.println("Generating visualisation '" + viz + "' as '" + out.getPath() + "'.");
                BufferedImage image = visualizationFlavours.get(key);
                if (unitGrid) {
                    VisualisationUtils.drawUnitGrid(image, gsom, width, height);
                }
                ImageIO.write(image, ftype, out);
            }
            basename = oldBasename; // reset base name
        } catch (SOMToolboxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    System.exit(0);
}

From source file:com.doculibre.constellio.utils.resources.WriteResourceBundleUtils.java

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    File binDir = ClasspathUtils.getClassesDir();
    File projectDir = binDir.getParentFile();
    File sourceDir = new File(projectDir, "source");

    String defaultLanguage;/*from ww w  .  ja  v a2  s .com*/
    String otherLanguage;
    if (args.length > 0) {
        defaultLanguage = args[0];
        otherLanguage = args[1];
    } else {
        defaultLanguage = Locale.ENGLISH.getLanguage();
        otherLanguage = Locale.FRENCH.getLanguage();
    }

    List<File> propertiesFiles = (List<File>) FileUtils.listFiles(sourceDir, new String[] { "properties" },
            true);
    for (File propertiesFile : propertiesFiles) {
        File propertiesDir = propertiesFile.getParentFile();

        String propertiesNameWoutSuffix = StringUtils.substringBefore(propertiesFile.getName(), "_");
        propertiesNameWoutSuffix = StringUtils.substringBefore(propertiesNameWoutSuffix, ".properties");

        String noLanguageFileName = propertiesNameWoutSuffix + ".properties";
        String defaultLanguageFileName = propertiesNameWoutSuffix + "_" + defaultLanguage + ".properties";
        String otherLanguageFileName = propertiesNameWoutSuffix + "_" + otherLanguage + ".properties";

        File noLanguageFile = new File(propertiesDir, noLanguageFileName);
        File defaultLanguageFile = new File(propertiesDir, defaultLanguageFileName);
        File otherLanguageFile = new File(propertiesDir, otherLanguageFileName);

        if (defaultLanguageFile.exists() && otherLanguageFile.exists() && !noLanguageFile.exists()) {
            System.out.println(defaultLanguageFile.getPath() + " > " + noLanguageFileName);
            System.out.println(defaultLanguageFile.getPath() + " > empty file");

            defaultLanguageFile.renameTo(noLanguageFile);
            FileWriter defaultLanguageEmptyFileWriter = new FileWriter(defaultLanguageFile);
            defaultLanguageEmptyFileWriter.write("");
            IOUtils.closeQuietly(defaultLanguageEmptyFileWriter);
        }
    }
}

From source file:com.green.generate.Generate.java

public static void main(String[] args) throws Exception {

    // ==========  ?? ====================

    // ??????//  w  w w  .  ja va2 s  . c o  m
    // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className}

    // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4?
    String packageName = "com.thinkgem.jeesite.modules";

    String moduleName = "factory"; // ???sys
    String subModuleName = ""; // ????? 
    String className = "product"; // ??user
    String classAuthor = "ThinkGem"; // ThinkGem
    String functionName = "?"; // ??

    // ???
    Boolean isEnable = false;

    // ==========  ?? ====================

    if (!isEnable) {
        logger.error("????isEnable = true");
        return;
    }

    if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className)
            || StringUtils.isBlank(functionName)) {
        logger.error("??????????????");
        return;
    }

    // ?
    String separator = File.separator;

    // ?
    File projectPath = new DefaultResourceLoader().getResource("").getFile();
    while (!new File(projectPath.getPath() + separator + "src" + separator + "main").exists()) {
        projectPath = projectPath.getParentFile();
    }
    logger.info("Project Path: {}", projectPath);

    // ?
    String tplPath = StringUtils.replace(projectPath + "/src/main/java/com/thinkgem/jeesite/generate/template",
            "/", separator);
    logger.info("Template Path: {}", tplPath);

    // Java
    String javaPath = StringUtils.replaceEach(
            projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    logger.info("Java Path: {}", javaPath);

    // 
    String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/views", "/", separator);
    logger.info("View Path: {}", viewPath);

    // ???
    Configuration cfg = new Configuration();
    cfg.setDirectoryForTemplateLoading(new File(tplPath));

    // ???
    Map<String, String> model = Maps.newHashMap();
    model.put("packageName", StringUtils.lowerCase(packageName));
    model.put("moduleName", StringUtils.lowerCase(moduleName));
    model.put("subModuleName",
            StringUtils.isNotBlank(subModuleName) ? "." + StringUtils.lowerCase(subModuleName) : "");
    model.put("className", StringUtils.uncapitalize(className));
    model.put("ClassName", StringUtils.capitalize(className));
    model.put("classAuthor", StringUtils.isNotBlank(classAuthor) ? classAuthor : "Generate Tools");
    model.put("classVersion", DateUtils.getDate());
    model.put("functionName", functionName);
    model.put("tableName",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "_" + StringUtils.lowerCase(subModuleName) : "")
                    + "_" + model.get("className"));
    model.put("urlPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "/" + StringUtils.lowerCase(subModuleName) : "")
                    + "/" + model.get("className"));
    model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("urlPrefix"));
    model.put("permissionPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? ":" + StringUtils.lowerCase(subModuleName) : "")
                    + ":" + model.get("className"));

    // ? Entity
    Template template = cfg.getTemplate("entity.ftl");
    String content = FreeMarkers.renderTemplate(template, model);
    String filePath = javaPath + separator + model.get("moduleName") + separator + "entity" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + ".java";
    writeFile(content, filePath);
    logger.info("Entity: {}", filePath);

    // ? Dao
    template = cfg.getTemplate("dao.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("moduleName") + separator + "dao" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Dao.java";
    writeFile(content, filePath);
    logger.info("Dao: {}", filePath);

    // ? Service
    template = cfg.getTemplate("service.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("moduleName") + separator + "service" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Service.java";
    writeFile(content, filePath);
    logger.info("Service: {}", filePath);

    // ? Controller
    template = cfg.getTemplate("controller.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("moduleName") + separator + "web" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Controller.java";
    writeFile(content, filePath);
    logger.info("Controller: {}", filePath);

    // ? ViewForm
    template = cfg.getTemplate("viewForm.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".") + separator
            + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator
            + model.get("className") + "Form.jsp";
    writeFile(content, filePath);
    logger.info("ViewForm: {}", filePath);

    // ? ViewList
    template = cfg.getTemplate("viewList.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".") + separator
            + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator
            + model.get("className") + "List.jsp";
    writeFile(content, filePath);
    logger.info("ViewList: {}", filePath);

    logger.info("Generate Success.");
}

From source file:com.ourlife.dev.generate.Generate.java

public static void main(String[] args) throws Exception {

    // ==========  ?? ====================

    // ??????// w ww  .j a v a2s. c o  m
    // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className}

    // packageName
    // ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4?
    String packageName = "com.ourlife.dev.modules";

    String moduleName = "biz"; // ???sys
    String subModuleName = ""; // ?????
    String className = "orderLog"; // ??user
    String classAuthor = "ourlife"; // ourlife
    String functionName = "?"; // ??

    // ???
    Boolean isEnable = true;

    // ==========  ?? ====================

    if (!isEnable) {
        logger.error("????isEnable = true");
        return;
    }

    if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className)
            || StringUtils.isBlank(functionName)) {
        logger.error("??????????????");
        return;
    }

    // ?
    String separator = File.separator;

    // ?
    File projectPath = new DefaultResourceLoader().getResource("").getFile();
    while (!new File(projectPath.getPath() + separator + "src" + separator + "main").exists()) {
        projectPath = projectPath.getParentFile();
    }
    logger.info("Project Path: {}", projectPath);

    // ?
    String tplPath = StringUtils.replace(projectPath + "/src/main/java/com/ourlife/dev/generate/template", "/",
            separator);
    logger.info("Template Path: {}", tplPath);

    // Java
    String javaPath = StringUtils.replaceEach(
            projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    logger.info("Java Path: {}", javaPath);

    // 
    String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/views", "/", separator);
    logger.info("View Path: {}", viewPath);

    // ???
    Configuration cfg = new Configuration();
    cfg.setDirectoryForTemplateLoading(new File(tplPath));

    // ???
    Map<String, String> model = Maps.newHashMap();
    model.put("packageName", StringUtils.lowerCase(packageName));
    model.put("moduleName", StringUtils.lowerCase(moduleName));
    model.put("subModuleName",
            StringUtils.isNotBlank(subModuleName) ? "." + StringUtils.lowerCase(subModuleName) : "");
    model.put("className", StringUtils.uncapitalize(className));
    model.put("ClassName", StringUtils.capitalize(className));
    model.put("classAuthor", StringUtils.isNotBlank(classAuthor) ? classAuthor : "Generate Tools");
    model.put("classVersion", DateUtils.getDate());
    model.put("functionName", functionName);
    model.put("tableName",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "_" + StringUtils.lowerCase(subModuleName) : "")
                    + "_" + model.get("className"));
    model.put("urlPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "/" + StringUtils.lowerCase(subModuleName) : "")
                    + "/" + model.get("className"));
    model.put("viewPrefix", // StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("urlPrefix"));
    model.put("permissionPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? ":" + StringUtils.lowerCase(subModuleName) : "")
                    + ":" + model.get("className"));

    // ? Entity
    Template template = cfg.getTemplate("entity.ftl");
    String content = FreeMarkers.renderTemplate(template, model);
    String filePath = javaPath + separator + model.get("moduleName") + separator + "entity" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + ".java";
    writeFile(content, filePath);
    logger.info("Entity: {}", filePath);

    // ? Dao
    template = cfg.getTemplate("dao.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("moduleName") + separator + "dao" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Dao.java";
    writeFile(content, filePath);
    logger.info("Dao: {}", filePath);

    // ? Service
    template = cfg.getTemplate("service.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("moduleName") + separator + "service" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Service.java";
    writeFile(content, filePath);
    logger.info("Service: {}", filePath);

    // ? Controller
    template = cfg.getTemplate("controller.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("moduleName") + separator + "web" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Controller.java";
    writeFile(content, filePath);
    logger.info("Controller: {}", filePath);

    // ? ViewForm
    template = cfg.getTemplate("viewForm.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".") + separator
            + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator
            + model.get("className") + "Form.jsp";
    writeFile(content, filePath);
    logger.info("ViewForm: {}", filePath);

    // ? ViewList
    template = cfg.getTemplate("viewList.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".") + separator
            + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator
            + model.get("className") + "List.jsp";
    writeFile(content, filePath);
    logger.info("ViewList: {}", filePath);

    logger.info("Generate Success.");
}

From source file:com.joey.Fujikom.generate.Generate.java

public static void main(String[] args) throws Exception {

    // ==========  ?? ====================

    // ??????//from   w  w  w.  j a va 2  s.  c  om
    // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className}

    // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4?
    String packageName = "com.joey.Fujikom.modules";

    String moduleName = "factory"; // ???sys
    String subModuleName = ""; // ????? 
    String className = "product"; // ??user
    String classAuthor = "ThinkGem"; // ThinkGem
    String functionName = "?"; // ??

    // ???
    //Boolean isEnable = false;
    Boolean isEnable = true;

    // ==========  ?? ====================

    if (!isEnable) {
        logger.error("????isEnable = true");
        return;
    }

    if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className)
            || StringUtils.isBlank(functionName)) {
        logger.error("??????????????");
        return;
    }

    // ?
    String separator = File.separator;

    // ?
    File projectPath = new DefaultResourceLoader().getResource("").getFile();
    while (!new File(projectPath.getPath() + separator + "src" + separator + "main").exists()) {
        projectPath = projectPath.getParentFile();
    }
    logger.info("Project Path: {}", projectPath);

    // ?
    String tplPath = StringUtils.replace(projectPath + "/src/main/java/com/thinkgem/Fujikom/generate/template",
            "/", separator);
    logger.info("Template Path: {}", tplPath);

    // Java
    String javaPath = StringUtils.replaceEach(
            projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    logger.info("Java Path: {}", javaPath);

    // 
    String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/views", "/", separator);
    logger.info("View Path: {}", viewPath);

    // ???
    Configuration cfg = new Configuration();
    cfg.setDefaultEncoding("UTF-8");
    cfg.setDirectoryForTemplateLoading(new File(tplPath));

    // ???
    Map<String, String> model = Maps.newHashMap();
    model.put("packageName", StringUtils.lowerCase(packageName));
    model.put("moduleName", StringUtils.lowerCase(moduleName));
    model.put("subModuleName",
            StringUtils.isNotBlank(subModuleName) ? "." + StringUtils.lowerCase(subModuleName) : "");
    model.put("className", StringUtils.uncapitalize(className));
    model.put("ClassName", StringUtils.capitalize(className));
    model.put("classAuthor", StringUtils.isNotBlank(classAuthor) ? classAuthor : "Generate Tools");
    model.put("classVersion", DateUtils.getDate());
    model.put("functionName", functionName);
    model.put("tableName",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "_" + StringUtils.lowerCase(subModuleName) : "")
                    + "_" + model.get("className"));
    model.put("urlPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "/" + StringUtils.lowerCase(subModuleName) : "")
                    + "/" + model.get("className"));
    model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("urlPrefix"));
    model.put("permissionPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? ":" + StringUtils.lowerCase(subModuleName) : "")
                    + ":" + model.get("className"));

    // ? Entity
    Template template = cfg.getTemplate("entity.ftl");
    String content = FreeMarkers.renderTemplate(template, model);
    String filePath = javaPath + separator + model.get("moduleName") + separator + "entity" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + ".java";
    writeFile(content, filePath);
    logger.info("Entity: {}", filePath);

    // ? Dao
    template = cfg.getTemplate("dao.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("moduleName") + separator + "dao" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Dao.java";
    writeFile(content, filePath);
    logger.info("Dao: {}", filePath);

    // ? Service
    template = cfg.getTemplate("service.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("moduleName") + separator + "service" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Service.java";
    writeFile(content, filePath);
    logger.info("Service: {}", filePath);

    // ? Controller
    template = cfg.getTemplate("controller.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("moduleName") + separator + "web" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Controller.java";
    writeFile(content, filePath);
    logger.info("Controller: {}", filePath);

    // ? ViewForm
    template = cfg.getTemplate("viewForm.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".") + separator
            + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator
            + model.get("className") + "Form.jsp";
    writeFile(content, filePath);
    logger.info("ViewForm: {}", filePath);

    // ? ViewList
    template = cfg.getTemplate("viewList.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".") + separator
            + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator
            + model.get("className") + "List.jsp";
    writeFile(content, filePath);
    logger.info("ViewList: {}", filePath);

    logger.info("Generate Success.");
}

From source file:com.pansky.integration.generate.Generate.java

public static void main(String[] args) throws Exception {

    // ==========  ?? ====================

    // ??????/*www  .j  a  v  a 2s  . c o  m*/
    // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className}

    // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4?
    String packageName = "com.pansky.integration.modules";

    String moduleName = "test"; // ???sys
    String subModuleName = "test1"; // ????? 
    String className = "test1"; // ??user
    String classAuthor = "renmh"; // ThinkGem
    String functionName = ""; // ??

    // ???
    //      Boolean isEnable = false;
    Boolean isEnable = true;

    // ==========  ?? ====================

    if (!isEnable) {
        logger.error("????isEnable = true");
        return;
    }

    if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className)
            || StringUtils.isBlank(functionName)) {
        logger.error("??????????????");
        return;
    }

    // ?
    String separator = File.separator;

    // ?
    File projectPath = new DefaultResourceLoader().getResource("").getFile();
    while (!new File(projectPath.getPath() + separator + "src" + separator + "main").exists()) {
        projectPath = projectPath.getParentFile();
    }
    logger.info("Project Path: {}", projectPath);

    // ?
    String tplPath = StringUtils
            .replace(projectPath + "/src/main/java/com/pansky/integration/generate/template", "/", separator);
    logger.info("Template Path: {}", tplPath);

    // Java
    String javaPath = StringUtils.replaceEach(
            projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    String javaTestPath = StringUtils.replaceEach(
            projectPath + "/src/test/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    logger.info("Java Path: {}", javaPath);

    // 
    String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/views", "/", separator);
    logger.info("View Path: {}", viewPath);

    // ???
    Configuration cfg = new Configuration();
    cfg.setDefaultEncoding("UTF-8");
    cfg.setDirectoryForTemplateLoading(new File(tplPath));

    // ???
    Map<String, String> model = Maps.newHashMap();
    model.put("packageName", StringUtils.lowerCase(packageName));
    model.put("moduleName", StringUtils.lowerCase(moduleName));
    model.put("subModuleName",
            StringUtils.isNotBlank(subModuleName) ? "." + StringUtils.lowerCase(subModuleName) : "");
    model.put("className", StringUtils.uncapitalize(className));
    model.put("ClassName", StringUtils.capitalize(className));
    model.put("classAuthor", StringUtils.isNotBlank(classAuthor) ? classAuthor : "Generate Tools");
    model.put("classVersion", DateUtils.getDate());
    model.put("functionName", functionName);
    model.put("tableName",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "_" + StringUtils.lowerCase(subModuleName) : "")
                    + "_" + model.get("className"));
    model.put("urlPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "/" + StringUtils.lowerCase(subModuleName) : "")
                    + "/" + model.get("className"));
    model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("urlPrefix"));
    model.put("permissionPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? ":" + StringUtils.lowerCase(subModuleName) : "")
                    + ":" + model.get("className"));

    // ? Entity
    Template template = cfg.getTemplate("entity.ftl");
    String content = FreeMarkers.renderTemplate(template, model);
    String filePath = javaPath + separator + model.get("moduleName") + separator + "entity" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + ".java";
    writeFile(content, filePath);
    logger.info("Entity: {}", filePath);

    // ? Dao
    template = cfg.getTemplate("dao.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("moduleName") + separator + "dao" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Dao.java";
    writeFile(content, filePath);
    logger.info("Dao: {}", filePath);

    // ? Service
    template = cfg.getTemplate("service.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("moduleName") + separator + "service" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Service.java";
    writeFile(content, filePath);
    logger.info("Service: {}", filePath);

    // ? Controller
    template = cfg.getTemplate("controller.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("moduleName") + separator + "web" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Controller.java";
    writeFile(content, filePath);
    logger.info("Controller: {}", filePath);

    // ? ViewForm
    template = cfg.getTemplate("viewForm.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".") + separator
            + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator
            + model.get("className") + "Form.jsp";
    writeFile(content, filePath);
    logger.info("ViewForm: {}", filePath);

    // ? ViewList
    template = cfg.getTemplate("viewList.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".") + separator
            + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator
            + model.get("className") + "List.jsp";
    writeFile(content, filePath);
    logger.info("ViewList: {}", filePath);
    //?TestCase
    template = cfg.getTemplate("serviceTest.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaTestPath + separator + model.get("moduleName") + separator + "service" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "ServiceTest.java";
    writeFile(content, filePath);
    logger.info("Service: {}", filePath);
    logger.info("Generate Success.");
}

From source file:licenseUtil.LicenseUtil.java

public static void main(String[] args) throws IOException, IncompleteLicenseObjectException {
    if (args.length == 0) {
        logger.error("Missing parameters. Use --help to get a list of the possible options.");
    } else if (args[0].equals("--addPomToTsv")) {
        if (args.length < 4)
            logger.error(//from w ww  .  ja  v a2  s . c  o m
                    "Missing arguments for option --addPomToTsv. Please specify <pomFileName> <licenses.stub.tsv> <currentVersion> or use the option --help for further information.");
        String pomFN = args[1];
        String spreadSheetFN = args[2];
        String currentVersion = args[3];

        MavenProject project = null;
        try {
            project = Utils.readPom(new File(pomFN));
        } catch (XmlPullParserException e) {
            logger.error("Could not parse pom file: \"" + pomFN + "\"");
        }
        LicensingList licensingList = new LicensingList();
        File f = new File(spreadSheetFN);
        if (f.exists() && !f.isDirectory()) {
            licensingList.readFromSpreadsheet(spreadSheetFN);
        }

        licensingList.addMavenProject(project, currentVersion);
        licensingList.writeToSpreadsheet(spreadSheetFN);
    } else if (args[0].equals("--writeLicense3rdParty")) {
        if (args.length < 4)
            logger.error(
                    "Missing arguments for option --writeLicense3rdParty. Please provide <licenses.enhanced.tsv> <processModule> <currentVersion> [and <targetDir>] or use the option --help for further information.");
        String spreadSheetFN = args[1];
        String processModule = args[2];
        String currentVersion = args[3];

        HashMap<String, String> targetDirs = new HashMap<>();
        if (args.length > 4) {
            File targetDir = new File(args[4]);
            logger.info("scan pom files in direct subdirectories of \"" + targetDir.getPath()
                    + "\" to obtain target locations for 3rd party license files...");
            File[] subdirs = targetDir.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
            for (File subdir : subdirs) {
                File pomFile = new File(subdir.getPath() + File.separator + POM_FN);
                if (!pomFile.exists())
                    continue;
                MavenProject mavenProject;
                try {
                    mavenProject = Utils.readPom(pomFile);
                } catch (Exception e) {
                    logger.warn("Could not read from pom file: \"" + pomFile.getPath() + "\" because of "
                            + e.getMessage());
                    continue;
                }
                targetDirs.put(mavenProject.getModel().getArtifactId(), subdir.getAbsolutePath());
            }
        }

        LicensingList licensingList = new LicensingList();
        licensingList.readFromSpreadsheet(spreadSheetFN);
        if (processModule.toUpperCase().equals("ALL")) {
            for (String module : licensingList.getNonFixedHeaders()) {
                try {
                    writeLicense3rdPartyFile(module, licensingList, currentVersion, targetDirs.get(module));
                } catch (NoLicenseTemplateSetException e) {
                    logger.error("Could not write file for module \"" + module
                            + "\". There is no template specified for \"" + e.getLicensingObject()
                            + "\". Please add an existing template filename to the column \""
                            + LicensingObject.ColumnHeader.LICENSE_TEMPLATE.value() + "\" of \"" + spreadSheetFN
                            + "\".");
                }
            }
        } else {
            try {
                writeLicense3rdPartyFile(processModule, licensingList, currentVersion,
                        targetDirs.get(processModule));
            } catch (NoLicenseTemplateSetException e) {
                logger.error("Could not write file for module \"" + processModule
                        + "\". There is no template specified for \"" + e.getLicensingObject()
                        + "\". Please add an existing template filename to the column \""
                        + LicensingObject.ColumnHeader.LICENSE_TEMPLATE.value() + "\" of \"" + spreadSheetFN
                        + "\".");
            }
        }
    } else if (args[0].equals("--buildEffectivePom")) {
        Utils.writeEffectivePom(new File(args[1]), (new File(EFFECTIVE_POM_FN)).getAbsolutePath());
    } else if (args[0].equals("--updateTsvWithProjectsInFolder")) {
        if (args.length < 4)
            logger.error(
                    "Missing arguments for option --processProjectsInFolder. Please provide <superDirectory> <licenses.stub.tsv> and <currentVersion> or use the option --help for further information.");
        File directory = new File(args[1]);
        String spreadSheetFN = args[2];
        String currentVersion = args[3];
        LicensingList licensingList = new LicensingList();
        File f = new File(spreadSheetFN);
        if (f.exists() && !f.isDirectory()) {
            licensingList.readFromSpreadsheet(spreadSheetFN);
        }
        licensingList.addAll(processProjectsInFolder(directory, currentVersion, false));
        licensingList.writeToSpreadsheet(spreadSheetFN);

    } else if (args[0].equals("--purgeTsv")) {
        if (args.length < 3)
            logger.error(
                    "Missing arguments for option --purgeTsv. Please provide <spreadSheetIN.tsv>, <spreadSheetOUT.tsv> and <currentVersion> or use the option --help for further information.");
        String spreadSheetIN = args[1];
        String spreadSheetOUT = args[2];
        String currentVersion = args[3];

        LicensingList licensingList = new LicensingList();
        licensingList.readFromSpreadsheet(spreadSheetIN);
        licensingList.purge(currentVersion);
        licensingList.writeToSpreadsheet(spreadSheetOUT);

    } else if (args[0].equals("--help")) {
        InputStream in = LicenseUtil.class.getClassLoader().getResourceAsStream(README_PATH);
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
    } else {
        logger.error("Unknown parameter: " + args[0] + ". Use --help to get a list of the possible options.");
    }
}

From source file:com.sishuok.es.generate.Generate.java

public static void main(String[] args) throws Exception {

    // ==========  ?? ====================

    // ??????//from  w  ww.ja v  a2  s .  c  om
    // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className}

    // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4?
    String packageName = "com.sishuok.es";

    String sysName = "sys"; // ??sys?showcase?maintain?personal?shop
    String moduleName = "xxs"; // ???? 
    String tableName = "sys_xxs_attribute"; // user
    String className = "XxsAttribute"; // ??User
    String permissionName = "sys:xxsAttribute";//??????????
    String folderName = "xxs";//??
    String classAuthor = "xxs"; // ThinkGem
    String functionName = "??????"; // ??

    // ???
    //Boolean isEnable = false;
    Boolean isEnable = true;

    // ==========  ?? ====================

    if (!isEnable) {
        logger.error("????isEnable = true");
        return;
    }

    if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className)
            || StringUtils.isBlank(functionName)) {
        logger.error("??????????????");
        return;
    }

    // ?
    String separator = File.separator;

    // ?
    File projectPath = new DefaultResourceLoader().getResource("").getFile();
    while (!new File(projectPath.getPath() + separator + "src" + separator + "main").exists()) {
        projectPath = projectPath.getParentFile();
    }
    logger.info("Project Path: {}", projectPath);

    // ?
    String tplPath = StringUtils.replace(projectPath + "/src/main/java/com/sishuok/es/generate/template", "/",
            separator);
    logger.info("Template Path: {}", tplPath);

    // Java
    String javaPath = StringUtils.replaceEach(
            projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    logger.info("Java Path: {}", javaPath);

    // 
    String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/jsp/admin", "/", separator);
    logger.info("View Path: {}", viewPath);

    // ???
    Configuration cfg = new Configuration();
    cfg.setDefaultEncoding("UTF-8");
    cfg.setDirectoryForTemplateLoading(new File(tplPath));

    // ???
    Map<String, String> model = Maps.newHashMap();
    model.put("packageName", StringUtils.lowerCase(packageName)); //
    model.put("sysName", StringUtils.lowerCase(sysName)); //???
    model.put("moduleName", StringUtils.lowerCase(moduleName)); //???
    model.put("tableName", StringUtils.lowerCase(tableName)); //
    model.put("className", StringUtils.uncapitalize(className)); //???
    model.put("permissionName", permissionName); //????
    model.put("ClassName", StringUtils.capitalize(className)); //??
    model.put("classAuthor", StringUtils.isNotBlank(classAuthor) ? classAuthor : "Generate Tools"); //
    model.put("classVersion", DateUtils.getDate()); //
    model.put("functionName", functionName); //???
    model.put("folderName", folderName); //??
    model.put("urlPrefix", model.get("moduleName") + "_" + model.get("className")); //jsp??
    model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("urlPrefix"));
    model.put("permissionPrefix", model.get("sysName") + ":" + model.get("moduleName")); //??

    // ? Entity
    Template template = cfg.getTemplate("entity.ftl");
    String content = FreeMarkers.renderTemplate(template, model);
    String filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName")
            + separator + "entity" + separator + model.get("ClassName") + ".java";
    System.out.println("Entity   filePath" + filePath);
    writeFile(content, filePath);
    logger.info("Entity: {}", filePath);

    // ? Repository
    template = cfg.getTemplate("repository.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName") + separator
            + "repository" + separator + separator + model.get("ClassName") + "Repository.java";
    System.out.println("repository   filePath" + filePath);
    writeFile(content, filePath);
    logger.info("Dao: {}", filePath);

    // ? Service
    template = cfg.getTemplate("service.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName") + separator
            + "service" + separator + separator + model.get("ClassName") + "Service.java";
    System.out.println("Service   filePath" + filePath);
    writeFile(content, filePath);
    logger.info("Service: {}", filePath);

    // ? ??Controller
    template = cfg.getTemplate("frontController.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName") + separator
            + "web" + separator + "controller" + separator + "front" + separator + model.get("ClassName")
            + "Controller.java";
    System.out.println("Controller   filePath" + filePath);
    writeFile(content, filePath);
    logger.info("Controller: {}", filePath);

    // ? ??Controller
    template = cfg.getTemplate("adminController.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName") + separator
            + "web" + separator + "controller" + separator + "admin" + separator + model.get("ClassName")
            + "Controller.java";
    System.out.println("Controller   filePath" + filePath);
    writeFile(content, filePath);
    logger.info("Controller: {}", filePath);

    // ? editForm
    template = cfg.getTemplate("editForm.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = viewPath + separator + model.get("sysName") + separator + model.get("folderName") + separator
            + "editForm.jsp";
    System.out.println("---------------------------------------------------");
    System.out.println("ViewForm   filePath" + filePath);
    writeFile(content, filePath);
    logger.info("ViewForm: {}", filePath);

    // ? list
    template = cfg.getTemplate("list.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = viewPath + separator + model.get("sysName") + separator + model.get("folderName") + separator
            + "list.jsp";
    writeFile(content, filePath);
    System.out.println("ViewListfilePath" + filePath);
    logger.info("ViewList: {}", filePath);

    // ? searcheForm
    template = cfg.getTemplate("searchForm.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = viewPath + separator + model.get("sysName") + separator + model.get("folderName") + separator
            + "searchForm.jsp";
    writeFile(content, filePath);
    System.out.println("searcheForm filePath" + filePath);
    logger.info("ViewList: {}", filePath);

    // ? listTable
    template = cfg.getTemplate("listTable.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = viewPath + separator + model.get("sysName") + separator + model.get("folderName") + separator
            + "listTable.jsp";
    writeFile(content, filePath);
    System.out.println("listTable filePath" + filePath);
    logger.info("ViewList: {}", filePath);

    logger.info("Generate Success.");
}