Search in sources :

Example 1 with SpoonFolder

use of spoon.compiler.SpoonFolder 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 SpoonFolder

use of spoon.compiler.SpoonFolder in project spoon by INRIA.

the class ResourceTest method testVirtualFolder.

@Test
public void testVirtualFolder() throws Exception {
    String dir = "src/test/resources/spoon/test/api/";
    FileSystemFolder fileSystemFolder = new FileSystemFolder(new File(dir));
    String dir2 = "src/test/resources/spoon/test/exceptions/";
    FileSystemFolder fileSystemFolder2 = new FileSystemFolder(new File(dir2));
    SpoonFolder folder = new VirtualFolder();
    folder.addFolder(fileSystemFolder);
    folder.addFolder(fileSystemFolder2);
    assertEquals(4, folder.getAllFiles().size());
    // the README is not a Java file
    assertEquals(3, folder.getAllJavaFiles().size());
}
Also used : VirtualFolder(spoon.support.compiler.VirtualFolder) SpoonFolder(spoon.compiler.SpoonFolder) FileSystemFolder(spoon.support.compiler.FileSystemFolder) File(java.io.File) FileSystemFile(spoon.support.compiler.FileSystemFile) Test(org.junit.Test)

Example 3 with SpoonFolder

use of spoon.compiler.SpoonFolder in project spoon by INRIA.

the class FileSystemFolder method getSubFolders.

public List<SpoonFolder> getSubFolders() {
    List<SpoonFolder> subFolders;
    subFolders = new ArrayList<>();
    for (File f : file.listFiles()) {
        if (!(SpoonResourceHelper.isArchive(f) || f.isFile())) {
            try {
                subFolders.add(SpoonResourceHelper.createFolder(f));
            } catch (FileNotFoundException e) {
                Launcher.LOGGER.error(e.getMessage(), e);
            }
        }
    }
    return subFolders;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) SpoonFolder(spoon.compiler.SpoonFolder) SpoonFile(spoon.compiler.SpoonFile) File(java.io.File)

Example 4 with SpoonFolder

use of spoon.compiler.SpoonFolder in project spoon by INRIA.

the class FileSystemFolderTest method jarFileIsNotSubfolder.

@Test
public void jarFileIsNotSubfolder() {
    String folderPath = "./src/test/resources/folderWithJar";
    FileSystemFolder folder = new FileSystemFolder(new File(folderPath));
    List<SpoonFolder> subFolders = folder.getSubFolders();
    assertTrue(subFolders.isEmpty());
}
Also used : SpoonFolder(spoon.compiler.SpoonFolder) FileSystemFolder(spoon.support.compiler.FileSystemFolder) File(java.io.File) Test(org.junit.Test) LauncherTest(spoon.LauncherTest)

Aggregations

File (java.io.File)4 SpoonFolder (spoon.compiler.SpoonFolder)4 FileSystemFolder (spoon.support.compiler.FileSystemFolder)3 Test (org.junit.Test)2 SpoonFile (spoon.compiler.SpoonFile)2 FileNotFoundException (java.io.FileNotFoundException)1 LauncherTest (spoon.LauncherTest)1 InvalidClassPathException (spoon.compiler.InvalidClassPathException)1 FileSystemFile (spoon.support.compiler.FileSystemFile)1 VirtualFolder (spoon.support.compiler.VirtualFolder)1