// skip file if Java version is not supported by the tool (@SetteSnippetContainer)
// NOTE it can be also done with snippet containers... (and also done in CATG
// generator!)
private void writeRunnerProject() throws IOException, XmlException, ParseException {
        // TODO revise whole method
        // TODO now using a newer JAPA (suuports java 8), -> maybe ANTLR supports better
        PathUtils.createDir(getRunnerProjectSettings().getBaseDir().toPath());
        // copy snippets
        PathUtils.copy(getSnippetProject().getSourceDir(),
                getRunnerProjectSettings().getSnippetSourceDirectory().toPath());
        // create INFO file
        writeInfoFile();
        // remove SETTE annotations and imports from file
        Collection<File> filesWritten = Files
                .walk(getRunnerProjectSettings().getSnippetSourceDirectory().toPath())
                .filter(Files::isRegularFile).map(Path::toFile).sorted()
                .collect(Collectors.toList());
        for (File file : filesWritten) {
            // parse source with JavaParser
            log.debug("Parsing with JavaParser: {}", file);
            CompilationUnit compilationUnit = JavaParser.parse(file);
            log.debug("Parsed with JavaParser: {}", file);
            // extract type
            List<TypeDeclaration> types = compilationUnit.getTypes();
            if (types.size() != 1) {
                // NOTE better exception type
                throw new RuntimeException(
                        "Java source files containing more that one types are not supported");
            }
            TypeDeclaration type = types.get(0);
            // skip file if Java version is not supported by the tool (@SetteSnippetContainer)
            // NOTE it can be also done with snippet containers... (and also done in CATG
            // generator!)
            List<AnnotationExpr> classAnnotations = type.getAnnotations();
            JavaVersion reqJavaVer = getRequiredJavaVersion(classAnnotations);
            if (reqJavaVer != null && !getTool().supportsJavaVersion(reqJavaVer)) {
                System.err.println(
                        "Skipping file: " + file + " (required Java version: " + reqJavaVer + ")");
                PathUtils.delete(file.toPath());
            } else {
                // remove SETTE annotations from the class
                Predicate<AnnotationExpr> isSetteAnnotation = (a -> a.getName().getName()
                        .startsWith("Sette"));
                classAnnotations.removeIf(isSetteAnnotation);
                // remove SETTE annotations from the members
                for (BodyDeclaration member : type.getMembers()) {
                    member.getAnnotations().removeIf(isSetteAnnotation);
                }
                // TODO enhance
                List<String> toRemovePrefixes = new ArrayList<>();
                toRemovePrefixes.add("hu.bme.mit.sette.snippets.inputs");
                toRemovePrefixes.add("hu.bme.mit.sette.common");
                // remove SETTE imports
                compilationUnit.getImports().removeIf(importDeclaration -> {
                    String impDecl = importDeclaration.getName().toString();
                    for (String prefix : toRemovePrefixes) {
                        if (impDecl.startsWith(prefix)) {
                            return true;
                        }
                    }
                    return false;
                });
                // save edited source code
                String source = compilationUnit.toString();
                if (type instanceof EnumDeclaration) {
                    // FIXME remove after javaparser bug is fixed
                    source = source.replaceFirst(type.getName() + "\\s+implements\\s*\\{",
                            type.getName() + " {");
                }
                PathUtils.write(file.toPath(), source.getBytes());
            }
        }
        // copy libraries
        if (getSnippetProject().getLibDir().toFile().exists()) {
            PathUtils.copy(getSnippetProject().getLibDir(),
                    getRunnerProjectSettings().getSnippetLibraryDirectory().toPath());
        }
        // create project
        this.eclipseProject.save(getRunnerProjectSettings().getBaseDir().toPath());
    }
}
TypeDeclaration type = types.get(0);
// skip file if Java version is not supported by the tool (@SetteSnippetContainer)
// NOTE it can be also done with snippet containers... (and also done in CATG
// generator!)
List<AnnotationExpr> classAnnotations = type.getAnnotations();
JavaVersion reqJavaVer = getRequiredJavaVersion(classAnnotations);
CompilationUnit compilationUnit = JavaParser.parse(file);
log.debug("Parsed with JavaParser: {}", file);
// extract type
List<TypeDeclaration> types = compilationUnit.getTypes();
if (types.size() != 1) {
// NOTE better exception type
throw new RuntimeException(
"Java source files containing more that one types are not supported");
}
TypeDeclaration type = types.get(0);
// skip file if Java version is not supported by the tool (@SetteSnippetContainer)
// NOTE it can be also done with snippet containers... (and also done in CATG
// generator!)
List<AnnotationExpr> classAnnotations = type.getAnnotations();
JavaVersion reqJavaVer = getRequiredJavaVersion(classAnnotations);
if (reqJavaVer != null && !getTool().supportsJavaVersion(reqJavaVer)) {
System.err.println(
"Skipping file: " + file + " (required Java version: " + reqJavaVer + ")");
PathUtils.delete(file.toPath());
} else {
// remove SETTE annotations from the class
Predicate<AnnotationExpr> isSetteAnnotation = (a -> a.getName().getName()
.startsWith("Sette"));
// create INFO file
writeInfoFile();
// remove SETTE annotations and imports from file
Collection<File> filesWritten = Files
.walk(getRunnerProjectSettings().getSnippetSourceDirectory().toPath())
.filter(Files::isRegularFile).map(Path::toFile).sorted()
.collect(Collectors.toList());
for (File file : filesWritten) {
// parse source with JavaParser
log.debug("Parsing with JavaParser: {}", file);
CompilationUnit compilationUnit = JavaParser.parse(file);
log.debug("Parsed with JavaParser: {}", file);
// extract type
List<TypeDeclaration> types = compilationUnit.getTypes();
if (types.size() != 1) {
// NOTE better exception type
throw new RuntimeException(
"Java source files containing more that one types are not supported");
}
TypeDeclaration type = types.get(0);
// skip file if Java version is not supported by the tool (@SetteSnippetContainer)
// NOTE it can be also done with snippet containers... (and also done in CATG
// generator!)
List<AnnotationExpr> classAnnotations = type.getAnnotations();
JavaVersion reqJavaVer = getRequiredJavaVersion(classAnnotations);
if (reqJavaVer != null && !getTool().supportsJavaVersion(reqJavaVer)) {
System.err.println(
"Skipping file: " + file + " (required Java version: " + reqJavaVer + ")");
PathUtils.delete(file.toPath());
} else {
// remove SETTE annotations from the class
Predicate<AnnotationExpr> isSetteAnnotation = (a -> a.getName().getName()
.startsWith("Sette"));
classAnnotations.removeIf(isSetteAnnotation);
// remove SETTE annotations from the members
for (BodyDeclaration member : type.getMembers()) {
member.getAnnotations().removeIf(isSetteAnnotation);
}
// TODO enhance
List<String> toRemovePrefixes = new ArrayList<>();
toRemovePrefixes.add("hu.bme.mit.sette.snippets.inputs");
toRemovePrefixes.add("hu.bme.mit.sette.common");
// remove SETTE imports