【笔记】NC正式环境部署后的modules转换成适用于开发环境的modules文件格式

2023-05-16

package cn.transfor;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * <p>正式环境的modules与我们开发项目的项目结构有一定的差别,如果我们要在新的git分布式管理工具上上传正式环境的modules,
 * 那么这个modules无法直接检出做为我们的项目,因此需要把modules转换为项目结构</p>
 * <p><b>说明:</b>最好是保存一份现有的项目,在把正式modules转换称对应的项目结后,用转换后的项目覆盖原来的项目,这样就能把正式环境的代码同步到我们的项目中</p>
 * <p>创建时间:2019年5月9日 14点10分</p>
 * @author zihui
 */
public class Transfor {

    private InputStream input;
    private OutputStream output;
    private static int length;
    
    /**
     * 例如需要转换称项目格式的文件夹结构如下所示:
     * modules_47_190417/
     *   |--| aim/
     *   |--|--lib/
     *   |--|--|--| pubaim_aimreport.jar
     *   |--|--|--| pubaim_embase.jar
     *   |--|--|--| ...
     *   |--| fdcpm/
     *   |--|--| class/
     *   |--|--|--| com/
     *   |--|--|--|--| ufida/
     *   |--|--|--|--|--| report/
     *   |--|--|--| nc/
     *   |--|--|--| test/
     *   |--|--|--| docconfig.properties
     *   |--|--| client/
     *   |--|--| config/
     *   |--|--| lib/
     *   |--|--| METADATA/
     *   |--|--| META-INF/
     *   |--|--|--| class/
     *   |--|--|--| lin/
     *   |--|--|--| bm.upm
     *   |--|--|--| ChangeControl.upm
     *   |--|--|--| ...
     */
    private String sourceFolder = "C:\\Users\\zihui\\Desktop\\TransTest\\modules_47_190417"; //需要转换项目格式的文件夹路径
    private String destinationFolder = "C:\\Users\\zihui\\Desktop\\TransTest\\modules_new"; //转换的目标路径
    
    public void getFileList() throws IOException {
        
        File createDestinationFolder = new File(destinationFolder);
        if(!createDestinationFolder.exists()) {
            createDestinationFolder.mkdirs();
        }
        
        
        File s_dir = new File(sourceFolder);
        File[] files = s_dir.listFiles(); //正式modules下的所有文件
        if(files != null) {
            for(int i = 0 ; i < files.length ; i++) {
                String fileName = files[i].getName(); //正式modules下所有文件的名称
                if(files[i].isDirectory()) {
                    String d_folder_second = destinationFolder+"\\"+fileName; //C:\\Users\\zihui\\Desktop\\TransTest\\modules_new\\fdcpm
                    File d_dir_second = new File(d_folder_second); 
                    if(!d_dir_second.exists()) {
                        d_dir_second.mkdir();
                    }
                    String s_folder_second = sourceFolder+"\\"+fileName;//C:\\Users\\zihui\\Desktop\\TransTest\\modules_47_190417\\fdcpm
                    File s_dir_second = new File(s_folder_second);
                    File[] second_files = s_dir_second.listFiles(); //正式modules/fdcpm下所有文件
                    if(second_files != null) {
                        for(int j = 0 ; j < second_files.length ; j++) {
                            String fileName_second = second_files[j].getName(); //正式modules/fdcpm下所有文件的名称
                            boolean isDirectory = second_files[j].isDirectory();
                            if(isDirectory && "classes".equals(fileName_second)) {
                                String d_folder_three = d_folder_second+"\\src\\public"; //C:\\Users\\zihui\\Desktop\\TransTest\\modules_new\\fdcpm\\src\\public
                                File d_dir_three = new File(d_folder_three);
                                if(!d_dir_three.exists()) {
                                    d_dir_three.mkdirs(); 
                                }
                                String beginFilename = s_folder_second+"\\"+fileName_second;//C:\\Users\\zihui\\Desktop\\TransTest\\modules_47_190417\\fdcpm\\class
                                String endFilename = d_folder_three;//C:\\Users\\zihui\\Desktop\\TransTest\\modules_new\\fdcpm\\src\\public
                                cycleCopyFiles(beginFilename, endFilename);
                                
                            } else if(isDirectory && "client".equals(fileName_second)) {
                                String d_folder_three = d_folder_second+"\\src\\client"; //C:\\Users\\zihui\\Desktop\\TransTest\\modules_new\\fdcpm\\src\\client
                                File d_dir_three = new File(d_folder_three);
                                if(!d_dir_three.exists()) {
                                    d_dir_three.mkdirs();
                                }
                                //C:\\Users\\zihui\\Desktop\\TransTest\\modules_47_190417\\fdcpm\\client\\classes
                                String beginFilename = s_folder_second+"\\"+fileName_second+"\\classes";
                                String endFilename = d_folder_three;//C:\\Users\\zihui\\Desktop\\TransTest\\modules_new\\fdcpm\\src\\client
                                cycleCopyFiles(beginFilename, endFilename);
                                
                            } else if(isDirectory && "META-INF".equals(fileName_second)) {
                                String s_folder_three = s_folder_second+"\\"+fileName_second;//C:\\Users\\zihui\\Desktop\\TransTest\\modules_47_190417\\fdcpm\\META_INF
                                File s_dir_three = new File(s_folder_three);
                                File[] metainf_files = s_dir_three.listFiles();
                                if(metainf_files != null) {
                                    for(int k = 0 ; k < metainf_files.length ; k++) {
                                        String metainf_fileName = metainf_files[k].getName();
                                        if(metainf_files[k].isDirectory() && "classes".equals(metainf_fileName)) {
                                            String d_folder_three = d_folder_second+"\\src\\private"; //C:\\Users\\zihui\\Desktop\\TransTest\\modules_new\\fdcpm\\src\\private
                                            File d_dir_three = new File(d_folder_three);
                                            if(!d_dir_three.exists()) {
                                                d_dir_three.mkdirs();
                                            }
                                            String beginFilename = s_folder_three+"\\classes";//C:\\Users\\zihui\\Desktop\\TransTest\\modules_47_190417\\fdcpm\\META_INF\\classes
                                            String endFilename = d_folder_three;//C:\\Users\\zihui\\Desktop\\TransTest\\modules_new\\fdcpm\\src\\private
                                            cycleCopyFiles(beginFilename, endFilename);
                                            
                                        } else if(!metainf_files[k].isDirectory() && (metainf_fileName.endsWith(".upm") || metainf_fileName.endsWith(".aop"))) {
                                            String metainfoPath = d_folder_second+"\\META-INF";//C:\\Users\\zihui\\Desktop\\TransTest\\modules_new\\fdcpm\\META-INF
                                            File mkMETAINF = new File(metainfoPath);
                                            if(!mkMETAINF.exists()) {
                                                mkMETAINF.mkdir();
                                            }
                                            String beginFilename = s_folder_three+"\\"+metainf_fileName;
                                            String endFilename = metainfoPath+"\\"+metainf_fileName;
                                            fileCopy(beginFilename, endFilename);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    
                }
            }
            System.out.println("项目结构转换完成");
        } else {
            System.out.println("路径:" + s_dir + "下没有任何文件!");
        }
    }
    
    /**
     * 文件的复制
     * @param beginFilename 原始文件
     * @param endFilename 目标文件
     */
    public void fileCopy(String beginFilename, String endFilename) {
        // 创建输入输出流对象
        try {
            input = new FileInputStream(beginFilename);
            output = new FileOutputStream(endFilename);
            try {
                length = input.available(); // 获取文件长度
                byte[] buffer = new byte[length]; // 创建缓存区域
                input.read(buffer); // 将文件中的数据写入缓存数组
                output.write(buffer); // 将缓存数组中的数据输出到文件
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            if (input != null && output != null) {
                try {
                    input.close(); // 关闭流
                    output.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    
    /**
     * <p>循环查询beginPath文件夹中的内容,如果是文件夹就在endPath路径下创建相同的文件夹,如果是文件就在endPath路径下复制相同的文件</p>
     * <p>创建时间:2019年5月9日 12点04分</p>
     * @author zihui
     * @param beginPath 需循环查询的源路径
     * @param endPath 目标路径
     * @throws IOException
     */
    public void cycleCopyFiles(String beginPath, String endPath) throws IOException {
        File beginDir = new File(beginPath);
        File[] beginDirFiles = beginDir.listFiles();
        if(beginDirFiles != null) {
            for(int i = 0 ; i < beginDirFiles.length ; i++) {
                String nextName = beginDirFiles[i].getName();
                if(beginDirFiles[i].isDirectory()) {
                    String newbeginPath = beginPath+"\\"+nextName;
                    String newendPath = endPath+"\\"+nextName;
                    File create = new File(newendPath);
                    create.mkdir();
                    cycleCopyFiles(newbeginPath, newendPath);
                } else {
                    String newCopyFile1 = beginPath+"\\"+nextName;
                    String newCopyFile2 = endPath+"\\"+nextName;
                    fileCopy(newCopyFile1, newCopyFile2);
                }
            }
        }
    }
    
    public static void main(String[] args) {
        Transfor tf = new Transfor();
        try {
            tf.getFileList();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

【笔记】NC正式环境部署后的modules转换成适用于开发环境的modules文件格式 的相关文章

随机推荐

  • k8s部署redis集群(方案1)

    目录 一 创建configmap 二 创建redis集群 三 集群初始化 四 验证集群省略 补充 1 如果整个 redis 集群的 pod 全部都挂掉了 xff0c pod自动拉起后 xff0c 集群不可用 xff0c 需要重建集群 2 重
  • QT5 实现UDP和串口通信

    QT5实现UDP和串口通信 前言 硬件平台 xff1a X86工控机 温湿度模块 xff1b 使用QT5编程实现X86工控机 xff08 客户端 xff09 与网络调试助手UDP通信 xff0c 同时X86工控机与温湿度模块实现串口通信 通
  • STM32单片机DMA串口数据收发

    前言 本实验是在原子哥的DMA实验的基础上进行修改 xff0c 添加了DMA串口数据接收功能 接收到指定数据时LED1的状态翻转 内附源码下载链接 xff1a 添加链接描述 注意 xff1a 在编写DMA串口数据收发时 xff0c DMA发
  • RT-Thread studio 添加CAN通信功能

    前言 最近在学习rt thread xff0c 在学习到CAN通信时遇到了一些问题 xff0c 首先就是如何注册CAN设备 发现在rt thread中 xff0c CAN 与其他的设备注册不一样 xff0c rt thread不会把CAN驱
  • 教你如何一步一步制作自己的PCB个人LOGO

    做了这么多年的硬件了 xff0c 也画了好多电路板 xff0c 昨天心血来潮决定以后在绘制电路板上添加上自己的LOGO 目录 一 LOGO 设计 二 LOGO修改 三 导入AD 一 LOGO 设计 于是开始制作LOGO图案 xff0c 由于
  • Visual Studio v141 生成工具 报错

    使用Visual Studio 2019的时候 xff0c 兼容旧有版本的VS出现如下报错 xff1a 错误 MSB8020 无法找到 Visual Studio 2017 的生成工具 平台工具集 61 v141 若要使用 v141 生成工
  • 一次多线程优化读取文件的实战

    需求描述 xff1a 商户每天会定时将文件传到我们的sftp服务器 xff0c 我们需要对文件解析落库等操作 方案A xff1a 起初的设计是将文件下载到本地 xff0c 读取整个文件 xff0c 落库等一系列处理 方案A的设计本来是没问题
  • VisualStudio突然无法启动显示log文件Error解决方法

    visual studio 启动报 activityLog xml文件 错误 1 在安装目录里面找到 devenv exe 这个文件的所在位置C Program FilesMicrosoft Visual Studio 10 0Common
  • 【笔记】Java实现通过本地浏览器打开UClient访问NC服务,如果失败,则打开IE浏览器访问NC Web服务

    span class token keyword package span span class token namespace nc span class token punctuation span baseapp span class
  • 将VMware虚拟机移到其它磁盘(C盘->D盘)

    1 打开我们的VMware xff0c 然后鼠标放在你的虚拟机上 xff0c 可以看到你的虚拟机所在的路径 xff0c 图中在C盘 xff1a 2 将虚拟机移除 xff0c 鼠标放在虚拟机上 xff0c 右键选择移除 弹出确认框 xff0c
  • linux之shell的正则表达式

    一 grep 文本过滤命令 span class hljs keyword grep span 命令是一种强大的文本搜索工具 xff0c 可以根据用户指定的 模式 对目标文本进行匹配检查 xff0c 打印匹配到的行 xff1b 由正则表达式
  • DDNS 服务搭建

    一 简介 DDNS xff08 动态域名服务 xff09 是将用户的动态公网ip地址映射到一个固定的域名解析服务上 xff0c 用户每次连接网络的时候客户端程序就会通过信息传递把该主机的动态公网ip地址推送到服务商的域名解析上 xff0c
  • 数据库关系代数--小练习

    Department dNo dName officeRoom homePage Student sNo sName sex age dNo Course cNo cName cPNo credit dNo SC sNo cNo score
  • 计算机基础-移位运算

    在代码中经常使用进行高低位的截取 哈希计算 xff0c 甚至运用在乘除法运算中 向右移动1位近似表示除以2 xff08 如下表所示 xff09 xff0c 十进制的奇数转化为二进制数后 xff0c 在向右移时 xff0c 最右边的1将被直接
  • Python for-in循环前面有一个变量

    展开全部 1 ls2 61 str i for i in ls1 等价于 1 2 3
  • 04-vscode搭建cmake的编译环境

    vscode 43 mingw搭建C C 43 43 环境系列 01 vscode 43 mingw搭建编译调试环境 02 vscode编译调试单个源文件程序 03 vscode编译调试多个源文件程序 04 vscode搭建cmake的编译
  • C++的string与char* char[]相互转换

    这俩天忙着调试一块AD芯片 xff0c 突然想起今天是程序员日 xff0c 嗯 xff0c 也不知道写点什么 xff0c 那就随笔写点这段时间看的C 43 43 吧 C 43 43 与C语言中最常见的就是字符串了 xff0c 因此 xff0
  • PGSQL主键自增的情况下添加数据可能出现错误的解决方法

    PGSQL主键自增的情况下添加数据可能出现错误的解决方法 平时我们在使用数据库的时候 xff0c 能够体会到逐渐自增所带来的好处 xff0c 首先因为增量增长按序存放的特性 xff0c 使得数据检索的效率得到了一定的提升 其次主键自增能够保
  • 纯Git实现前端项目打包部署

    本篇文章主要是记录实现过程中遇到的问题 xff0c 以及如何解决出现的问题 xff0c 原始教程参考杨成功所写的这篇文章 纯 Git 实现前端 CI CD 纯Git实现前端项目打包部署 实现原理实现步骤1 在服务器中安装相应的软件程序2 服
  • 【笔记】NC正式环境部署后的modules转换成适用于开发环境的modules文件格式

    span class token keyword package span span class token namespace cn span class token punctuation span transfor span span