Pessoal estou desenvolvendo um plugin que tem o intuito de contar
linhas em um pacote, no qual consta arquivos de mais de uma extensão.
O que acontece é o seguinte, ele so acessa os arquivos do diretorio principal,
os sub-diretorios não estão sendo acessados. Alguem poderia me dá uma ajuda nisso.
abaixo vai o codigo:
public class Main {
/**
-
@param pArgs
*/
public static void main(String[] pArgs) {
String lDiretorioArquivos = “C:\Projeto”;
File lDiretorio = new File(lDiretorioArquivos);
if (lDiretorio.exists() && lDiretorio.canRead()) {
String[] lArquivosDiretorio = lDiretorio.list(new FilenameFilter() {
public boolean accept(File dir, String pNname) {
if (pNname.endsWith(".jsp") || pNname.endsWith(".js") || pNname.endsWith(".xml") || pNname.endsWith(".java")){
return true;
} else {
return false;
}
}
});
if (lArquivosDiretorio != null) {
int lTotalLinhas = 0;
for (String lArquivo : lArquivosDiretorio) {
int lLinhasArquivo = 0;
try {
lLinhasArquivo = contarLinhasValidas(lDiretorioArquivos + “\” + lArquivo);
} catch (Exception e) {
System.out.println(“Arquivo " + lArquivo + " não pôde ser lido.”);
}
System.out.println("Arquivo " + lArquivo + “: " + lLinhasArquivo + " linha(s).”);
lTotalLinhas += lLinhasArquivo;
}
System.out.println("total de arquivos: " + lArquivosDiretorio.length);
System.out.println("total de linhas (linhas em branco ou com comentário foram ignoradas): " + lTotalLinhas);
System.out.println(“Média de " + ((float)lTotalLinhas / (float)lArquivosDiretorio.length) + " linhas não-comentadas e não-nulas por Arquivo.”);
}
} else {
System.out.println(“Diretório Inválido.”);
}
}
/**
- Conta o total de linhas válidas (não-comentadas e não-brancas) no arquivo especificado.
- @param pPathArquivo o Path para o Arquivo
- @return
-
@throws IOException
/
public static int contarLinhasValidas(String pPathArquivo) throws IOException {
int lTotalLinhas = 0;
BufferedReader lReader = new BufferedReader(new FileReader(pPathArquivo));
String lLinha = null;
while ((lLinha = lReader.readLine()) != null) {
if (lLinha != null) {
if (!lLinha.trim().equals("") //elimina linha vazia
&& !lLinha.contains("//") //elimina comentário
&& !lLinha.contains("/")
&& !lLinha.contains("<%")
&& !lLinha.contains("<!–")
) {
lTotalLinhas++;
}
}
}
return lTotalLinhas;
}
}