Last active
August 29, 2015 14:10
-
-
Save prietopa/688698382a958c83eb20 to your computer and use it in GitHub Desktop.
crea una lista de "schemasList" y de "classesToBeBoundList" para la configuracion de Spring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.pp.jm.spring.oxm.config.test; | |
import java.io.File; | |
import java.io.IOException; | |
import java.util.Collection; | |
import org.apache.commons.io.FileUtils; | |
import org.junit.Test; | |
public class ListDirectoryTest { | |
@Test | |
public void test_schemasList() throws IOException { | |
StringBuffer buf = new StringBuffer(); | |
buf.append("\t<util:list id=\"schemasList\">\n"); | |
File directory = new File("src/main/resources"); | |
String[] extensions = new String[] {"xsd"}; | |
Collection<File> files = FileUtils.listFiles(directory, extensions, true); | |
for (File file: files) { | |
buf.append("\t\t<value>classpath:"); | |
String path = file.getPath(); | |
path = path.substring("src/main/resources".length() + 1, path.length()); | |
path = path.replace("\\", "/"); | |
buf.append(path); | |
buf.append("</value>\n"); | |
} | |
buf.append("\t</util:list>\n"); | |
System.out.println(buf.toString()); | |
} | |
@Test | |
public void test_classesToBeBoundList() throws IOException { | |
String[] extensions = new String[] {"java"}; | |
String[] exclude = new String[] {"es"}; | |
StringBuffer buf = new StringBuffer(); | |
buf.append("\t<util:list id=\"classesToBeBoundList\">\n"); | |
fillValuesFrom(buf, "src/main/java", extensions, exclude, true); | |
buf.append("\t</util:list>\n"); | |
System.out.println(buf.toString()); | |
} | |
private void fillValuesFrom(StringBuffer buf, String directoryPath, String[] extensions, String[] exclude, boolean recursive) { | |
File directory = new File(directoryPath); | |
Collection<File> files = FileUtils.listFiles(directory, extensions, recursive); | |
for (File file: files) { | |
String path = file.getPath(); | |
if(StringUtils.contains(file.getName(), "package-info")) { | |
continue; | |
} | |
if(StringUtils.contains(file.getName(), "ObjectFactory")) { | |
continue; | |
} | |
path = path.substring(directoryPath.length() + 1, path.length()); | |
path = path.replace("\\", "."); | |
if(isPacakageExclude(path, exclude)) { | |
continue; | |
} | |
buf.append("\t\t<value>"); | |
buf.append(StringUtils.substringBefore(path, ".java")); | |
buf.append("</value>\n"); | |
} | |
} | |
private boolean isPacakageExclude(String path, String[] excludes) { | |
boolean encontrado = false; | |
for(String str: excludes) { | |
if(StringUtils.startsWithIgnoreCase(path, str)) { | |
encontrado = true; | |
} | |
} | |
return encontrado; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mejora: