use of spoon.compiler.InvalidClassPathException in project spoon by INRIA.
the class StandardEnvironment method verifySourceClasspath.
private void verifySourceClasspath(String[] sourceClasspath) throws InvalidClassPathException {
for (String classPathElem : sourceClasspath) {
// preconditions
File classOrJarFolder = new File(classPathElem);
if (!classOrJarFolder.exists()) {
throw new InvalidClassPathException(classPathElem + " does not exist, it is not a valid folder");
}
if (classOrJarFolder.isDirectory()) {
// it should not contain a java file
SpoonFolder tmp = new FileSystemFolder(classOrJarFolder);
List<SpoonFile> javaFiles = tmp.getAllJavaFiles();
if (javaFiles.size() > 0) {
logger.warn("You're trying to give source code in the classpath, this should be given to " + "addInputSource " + javaFiles);
}
} else if (classOrJarFolder.getName().endsWith(".class")) {
throw new InvalidClassPathException(".class files are not accepted in source classpath.");
}
}
}
use of spoon.compiler.InvalidClassPathException in project spoon by INRIA.
the class ExceptionTest method testExceptionInvalidAPI.
@Test
public void testExceptionInvalidAPI() throws Exception {
try {
Launcher spoon = new Launcher();
spoon.getFactory().getEnvironment().setLevel("OFF");
SpoonModelBuilder comp = spoon.createCompiler();
comp.setSourceClasspath("does_not_exist.jar");
fail();
} catch (InvalidClassPathException e) {
}
try {
Launcher spoon = new Launcher();
spoon.getFactory().getEnvironment().setLevel("OFF");
SpoonModelBuilder comp = spoon.createCompiler();
comp.setSourceClasspath("src");
} catch (InvalidClassPathException e) {
fail();
// you're trying to give source code in the classpath, this should be accepted but causes a warn log entry
}
}
use of spoon.compiler.InvalidClassPathException in project spoon by INRIA.
the class APITest method testSourceClasspathDoesNotAcceptDotClass.
@Test
public void testSourceClasspathDoesNotAcceptDotClass() {
// contract: setSourceClassPath does not accept .class files
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/api/testclasses/Bar.java");
launcher.setBinaryOutputDirectory("./target/spoon-setscp");
launcher.getEnvironment().setShouldCompile(true);
launcher.run();
final Launcher launcher2 = new Launcher();
try {
launcher2.getEnvironment().setSourceClasspath(new String[] { "./target/spoon-setscp/spoon/test/api/testclasses/Bar.class" });
fail();
} catch (Exception e) {
assertTrue(e instanceof InvalidClassPathException);
assertTrue(e.getMessage().contains(".class files are not accepted in source classpath."));
}
}
Aggregations