Search in sources :

Example 1 with InvalidClassPathException

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.");
        }
    }
}
Also used : InvalidClassPathException(spoon.compiler.InvalidClassPathException) SpoonFolder(spoon.compiler.SpoonFolder) FileSystemFolder(spoon.support.compiler.FileSystemFolder) File(java.io.File) SpoonFile(spoon.compiler.SpoonFile) SpoonFile(spoon.compiler.SpoonFile)

Example 2 with InvalidClassPathException

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
    }
}
Also used : SpoonModelBuilder(spoon.SpoonModelBuilder) InvalidClassPathException(spoon.compiler.InvalidClassPathException) Launcher(spoon.Launcher) Test(org.junit.Test)

Example 3 with InvalidClassPathException

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."));
    }
}
Also used : InvalidClassPathException(spoon.compiler.InvalidClassPathException) Launcher(spoon.Launcher) InvalidClassPathException(spoon.compiler.InvalidClassPathException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

InvalidClassPathException (spoon.compiler.InvalidClassPathException)3 Test (org.junit.Test)2 Launcher (spoon.Launcher)2 File (java.io.File)1 IOException (java.io.IOException)1 SpoonModelBuilder (spoon.SpoonModelBuilder)1 SpoonFile (spoon.compiler.SpoonFile)1 SpoonFolder (spoon.compiler.SpoonFolder)1 FileSystemFolder (spoon.support.compiler.FileSystemFolder)1