用於cocos2d-x引擎(ndk)中為android項目產生編譯檔案清單_Android

來源:互聯網
上載者:User

 

複製代碼 代碼如下:

package com.leeass.generate;

import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;

/**
 * 用於cocos2d-x引擎中android項目編譯檔案清單產生
 * @author leeassamite
 *
 */
public class GenerateAndroidMakefile {
 /** 分隔字元 */
 private static final String LINE_BREAK = System.getProperty("line.separator", "/n");
 /** classes檔案夾 */
 private File classesDir = null;
 /** classes檔案夾路徑 */
 private String classesPath = "";
 /** classes檔案夾相對路徑 */
 private String classesRelativePath = "";
 /** 編譯檔案過濾器 */
 private BuildFileFilter buildFileFilter = null;

 /**
  * 建立GenerateAndroidMakefile
  * @param classesAbsolutePath classes檔案夾絕對路徑
  * @param classesRelativePath classes檔案夾在編譯檔案中的相對路徑
  * @throws Exception
  */
 public GenerateAndroidMakefile(String classesAbsolutePath,String classesRelativePath) throws Exception{
  if(classesRelativePath == null){
   throw new Exception("classes檔案夾相對路徑錯誤,不能為NULL!");
  }
  if(classesAbsolutePath == null || "".equals(classesAbsolutePath)){
   throw new Exception("classes檔案夾路徑輸入錯誤,不可為空!");
  }
  classesDir = new File(classesAbsolutePath);
  if((!classesDir.exists()) || (!classesDir.canRead()) || (!classesDir.isDirectory())){
   throw new FileNotFoundException("classes檔案夾不可讀:"+classesDir.getAbsolutePath());
  }
  this.classesPath = classesAbsolutePath;
  this.classesPath = classesAbsolutePath.replaceAll("\\\\", "/");
  this.classesRelativePath = classesRelativePath;
  buildFileFilter = new BuildFileFilter();
 }

 /**
  * 輸出編譯檔案清單
  */
 public void outputBuildFilesList(){
  StringBuilder buildFilesSb = new StringBuilder();
  outputBuildFileList(classesDir,buildFilesSb);
  System.out.println(buildFilesSb.toString());
 }
 private void outputBuildFileList(File buildfile,StringBuilder buildFilesSb){
  if(buildfile.isDirectory()){
   File[] files =buildfile.listFiles(buildFileFilter);
   for (File file : files) {
    outputBuildFileList(file,buildFilesSb);
   }
  }else{
   String buildfileStr = translateBuildFilePath(buildfile.getAbsolutePath()) + " \\";
   buildFilesSb.append(buildfileStr).append(LINE_BREAK);
  }
 }
 /**
  * 轉換編譯檔案路徑
  * @param filepath
  * @return
  */
 private String translateBuildFilePath(String filepath){
  return filepath.replaceAll("\\\\", "/").replace(classesPath, classesRelativePath);
 }

 /**
  * @param args
  * @throws FileNotFoundException
  */
 public static void main(String[] args) throws Exception {
  String classesPath = "D:\\developer\\cocos2d-x-2.1.4\\projects\\hszg_ol\\Classes";
  String relativePath = "                   ../../Classes";
  GenerateAndroidMakefile gam = new GenerateAndroidMakefile(classesPath,relativePath);
  gam.outputBuildFilesList();
 }

 
 /**
  * 編譯檔案過濾器
  * @author leeass
  *
  */
 class BuildFileFilter implements FileFilter{
  @Override
  public boolean accept(File pathname) {
   String name = pathname.getName().toLowerCase();
   return (!pathname.isHidden()) && (pathname.isDirectory() || name.endsWith(".c") || name.endsWith(".cpp"));
  }
 }

}



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.