use of com.android.dx.cf.direct.ClassPathOpener.FileNameFilter in project J2ME-Loader by nikita36078.
the class Main method processAllFiles.
/**
* Constructs the output {@link DexFile}, fill it in with all the
* specified classes, and populate the resources map if required.
*
* @return whether processing was successful
*/
private boolean processAllFiles() {
createDexFile();
if (args.jarOutput) {
outputResources = new TreeMap<String, byte[]>();
}
anyFilesProcessed = false;
String[] fileNames = args.fileNames;
Arrays.sort(fileNames);
// translate classes in parallel
classTranslatorPool = new ThreadPoolExecutor(args.numThreads, args.numThreads, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(2 * args.numThreads, true), new ThreadPoolExecutor.CallerRunsPolicy());
// collect translated and write to dex in order
classDefItemConsumer = Executors.newSingleThreadExecutor();
try {
if (args.mainDexListFile != null) {
// with --main-dex-list
FileNameFilter mainPassFilter = args.strictNameCheck ? new MainDexListFilter() : new BestEffortMainDexListFilter();
// forced in main dex
for (int i = 0; i < fileNames.length; i++) {
processOne(fileNames[i], mainPassFilter);
}
if (dexOutputFutures.size() > 0) {
throw new DexException("Too many classes in " + Arguments.MAIN_DEX_LIST_OPTION + ", main dex capacity exceeded");
}
if (args.minimalMainDex) {
// Wait for classes in progress to complete
synchronized (dexRotationLock) {
while (maxMethodIdsInProcess > 0 || maxFieldIdsInProcess > 0) {
try {
dexRotationLock.wait();
} catch (InterruptedException ex) {
/* ignore */
}
}
}
rotateDexFile();
}
// remaining files
for (int i = 0; i < fileNames.length; i++) {
processOne(fileNames[i], new NotFilter(mainPassFilter));
}
} else {
// without --main-dex-list
for (int i = 0; i < fileNames.length; i++) {
processOne(fileNames[i], ClassPathOpener.acceptAll);
}
}
} catch (StopProcessing ex) {
/*
* Ignore it and just let the error reporting do
* their things.
*/
}
try {
classTranslatorPool.shutdown();
classTranslatorPool.awaitTermination(600L, TimeUnit.SECONDS);
classDefItemConsumer.shutdown();
classDefItemConsumer.awaitTermination(600L, TimeUnit.SECONDS);
for (Future<Boolean> f : addToDexFutures) {
try {
f.get();
} catch (ExecutionException ex) {
// Catch any previously uncaught exceptions from
// class translation and adding to dex.
int count = errors.incrementAndGet();
if (count < 10) {
if (args.debug) {
context.err.println("Uncaught translation error:");
ex.getCause().printStackTrace(context.err);
} else {
context.err.println("Uncaught translation error: " + ex.getCause());
}
} else {
throw new InterruptedException("Too many errors");
}
}
}
} catch (InterruptedException ie) {
classTranslatorPool.shutdownNow();
classDefItemConsumer.shutdownNow();
throw new RuntimeException("Translation has been interrupted", ie);
} catch (Exception e) {
classTranslatorPool.shutdownNow();
classDefItemConsumer.shutdownNow();
e.printStackTrace(context.out);
throw new RuntimeException("Unexpected exception in translator thread.", e);
}
int errorNum = errors.get();
if (errorNum != 0) {
context.err.println(errorNum + " error" + ((errorNum == 1) ? "" : "s") + "; aborting");
return false;
}
if (args.incremental && !anyFilesProcessed) {
return true;
}
if (!(anyFilesProcessed || args.emptyOk)) {
context.err.println("no classfiles specified");
return false;
}
if (args.optimize && args.statistics) {
context.codeStatistics.dumpStatistics(context.out);
}
return true;
}
use of com.android.dx.cf.direct.ClassPathOpener.FileNameFilter in project buck by facebook.
the class Main method processAllFiles.
/**
* Constructs the output {@link DexFile}, fill it in with all the
* specified classes, and populate the resources map if required.
*
* @return whether processing was successful
*/
private boolean processAllFiles() {
createDexFile();
if (args.jarOutput) {
outputResources = new TreeMap<String, byte[]>();
}
anyFilesProcessed = false;
String[] fileNames = args.fileNames;
Arrays.sort(fileNames);
// translate classes in parallel
classTranslatorPool = new ThreadPoolExecutor(args.numThreads, args.numThreads, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(2 * args.numThreads, true), new ThreadPoolExecutor.CallerRunsPolicy());
// collect translated and write to dex in order
classDefItemConsumer = Executors.newSingleThreadExecutor();
try {
if (args.mainDexListFile != null) {
// with --main-dex-list
FileNameFilter mainPassFilter = args.strictNameCheck ? new MainDexListFilter() : new BestEffortMainDexListFilter();
// forced in main dex
for (int i = 0; i < fileNames.length; i++) {
processOne(fileNames[i], mainPassFilter);
}
if (dexOutputFutures.size() > 0) {
throw new DexException("Too many classes in " + Arguments.MAIN_DEX_LIST_OPTION + ", main dex capacity exceeded");
}
if (args.minimalMainDex) {
// Wait for classes in progress to complete
synchronized (dexRotationLock) {
while (maxMethodIdsInProcess > 0 || maxFieldIdsInProcess > 0) {
try {
dexRotationLock.wait();
} catch (InterruptedException ex) {
/* ignore */
}
}
}
rotateDexFile();
}
// remaining files
for (int i = 0; i < fileNames.length; i++) {
processOne(fileNames[i], new NotFilter(mainPassFilter));
}
} else {
// without --main-dex-list
for (int i = 0; i < fileNames.length; i++) {
processOne(fileNames[i], ClassPathOpener.acceptAll);
}
}
} catch (StopProcessing ex) {
/*
* Ignore it and just let the error reporting do
* their things.
*/
}
try {
classTranslatorPool.shutdown();
classTranslatorPool.awaitTermination(600L, TimeUnit.SECONDS);
classDefItemConsumer.shutdown();
classDefItemConsumer.awaitTermination(600L, TimeUnit.SECONDS);
for (Future<Boolean> f : addToDexFutures) {
try {
f.get();
} catch (ExecutionException ex) {
// Catch any previously uncaught exceptions from
// class translation and adding to dex.
int count = errors.incrementAndGet();
if (count < 10) {
if (args.debug) {
context.err.println("Uncaught translation error:");
ex.getCause().printStackTrace(context.err);
} else {
context.err.println("Uncaught translation error: " + ex.getCause());
}
} else {
throw new InterruptedException("Too many errors");
}
}
}
} catch (InterruptedException ie) {
classTranslatorPool.shutdownNow();
classDefItemConsumer.shutdownNow();
throw new RuntimeException("Translation has been interrupted", ie);
} catch (Exception e) {
classTranslatorPool.shutdownNow();
classDefItemConsumer.shutdownNow();
e.printStackTrace(out);
throw new RuntimeException("Unexpected exception in translator thread.", e);
}
int errorNum = errors.get();
if (errorNum != 0) {
context.err.println(errorNum + " error" + ((errorNum == 1) ? "" : "s") + "; aborting");
return false;
}
if (args.incremental && !anyFilesProcessed) {
return true;
}
if (!(anyFilesProcessed || args.emptyOk)) {
context.err.println("no classfiles specified");
return false;
}
if (args.optimize && args.statistics) {
context.codeStatistics.dumpStatistics(context.out);
}
return true;
}
Aggregations