Search in sources :

Example 1 with PathTraverser

use of org.eclipse.xtext.mwe.PathTraverser in project xtext-xtend by eclipse.

the class JavaFileConverterTest method runConverter.

public void runConverter() {
    try {
        File _parentFile = new File("").getAbsoluteFile().getParentFile();
        final File srcProjectRoot = new File(_parentFile, this.sourceProject);
        File _parentFile_1 = srcProjectRoot.getParentFile();
        final File testProject = new File(_parentFile_1, this.targetProject);
        String _path = srcProjectRoot.getPath();
        String _plus = ("Working in " + _path);
        InputOutput.<String>println(_plus);
        final PathTraverser pathTraverser = new PathTraverser();
        String _absolutePath = srcProjectRoot.getAbsolutePath();
        final Set<URI> allResourceUris = pathTraverser.findAllResourceUris(_absolutePath, new Predicate<URI>() {

            @Override
            public boolean apply(final URI input) {
                final String fileName = input.toFileString();
                return (("java".equals(input.fileExtension()) && (!fileName.contains("xtend-gen"))) && (!fileName.contains("batch-compiler-data")));
            }
        });
        int errors = 0;
        int problems = 0;
        int files = 0;
        int filesWithErrorsOrProblems = 0;
        for (final URI uri : allResourceUris) {
            {
                String _fileString = uri.toFileString();
                final File file = new File(_fileString);
                final String javaFileProjRelPath = uri.toFileString().replace(srcProjectRoot.getAbsolutePath(), "");
                InputOutput.<String>println(("Converting: " + javaFileProjRelPath));
                boolean compileError = false;
                final String javaCode = Files.toString(file, Charset.defaultCharset());
                final JavaConverter.ConversionResult xtendResult = this.converToXtend(file.getName(), javaCode);
                final int knownProblemsFound = IterableExtensions.size(xtendResult.getProblems());
                String xtendCode = xtendResult.getXtendCode();
                String fileName = (javaFileProjRelPath + ".xtend");
                try {
                    this.file(xtendCode, true);
                } catch (final Throwable _t) {
                    if (_t instanceof AssertionError) {
                        final AssertionError error = (AssertionError) _t;
                        compileError = true;
                        StringConcatenation _builder = new StringConcatenation();
                        _builder.append(javaFileProjRelPath);
                        _builder.append(" - ");
                        String _message = error.getMessage();
                        _builder.append(_message);
                        System.err.println(_builder);
                    } else {
                        throw Exceptions.sneakyThrow(_t);
                    }
                }
                if (((knownProblemsFound != 0) || compileError)) {
                    filesWithErrorsOrProblems++;
                    if ((knownProblemsFound != 0)) {
                        this.writeToFile(testProject, javaFileProjRelPath, javaCode);
                        String _fileName = fileName;
                        fileName = (_fileName + ".error");
                    } else {
                        errors++;
                    }
                }
                int _problems = problems;
                problems = (_problems + knownProblemsFound);
                files++;
                this.writeToFile(testProject, fileName, xtendCode);
            }
        }
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("Not covered Errors (");
        _builder.append(errors);
        _builder.append(")");
        InputOutput.<String>println(_builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("Known Problems (");
        _builder_1.append(problems);
        _builder_1.append(")");
        InputOutput.<String>println(_builder_1.toString());
        StringConcatenation _builder_2 = new StringConcatenation();
        _builder_2.append("Files read (");
        _builder_2.append(files);
        _builder_2.append(")");
        InputOutput.<String>println(_builder_2.toString());
        StringConcatenation _builder_3 = new StringConcatenation();
        _builder_3.append("Files with errors/problems (");
        _builder_3.append(filesWithErrorsOrProblems);
        _builder_3.append(")");
        InputOutput.<String>println(_builder_3.toString());
        InputOutput.<String>println("Done...");
        Assert.assertEquals(this.problemsExpected, problems);
        Assert.assertEquals(this.errorsExpected, errors);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) PathTraverser(org.eclipse.xtext.mwe.PathTraverser) File(java.io.File) URI(org.eclipse.emf.common.util.URI)

Example 2 with PathTraverser

use of org.eclipse.xtext.mwe.PathTraverser in project xtext-xtend by eclipse.

the class XtendBatchCompiler method loadXtendFiles.

protected ResourceSet loadXtendFiles(final ResourceSet resourceSet) {
    encodingProvider.setDefaultEncoding(getFileEncoding());
    final NameBasedFilter nameBasedFilter = new NameBasedFilter();
    nameBasedFilter.setExtension(fileExtensionProvider.getPrimaryFileExtension());
    PathTraverser pathTraverser = new PathTraverser();
    List<String> sourcePathDirectories = getSourcePathDirectories();
    Multimap<String, URI> pathes = pathTraverser.resolvePathes(sourcePathDirectories, new Predicate<URI>() {

        @Override
        public boolean apply(URI input) {
            boolean matches = nameBasedFilter.matches(input);
            return matches;
        }
    });
    for (String src : pathes.keySet()) {
        for (URI uri : pathes.get(src)) {
            if (log.isDebugEnabled()) {
                log.debug("load xtend file '" + uri + "'");
            }
            resourceSet.getResource(uri, true);
        }
    }
    return resourceSet;
}
Also used : PathTraverser(org.eclipse.xtext.mwe.PathTraverser) URI(org.eclipse.emf.common.util.URI) NameBasedFilter(org.eclipse.xtext.mwe.NameBasedFilter)

Aggregations

URI (org.eclipse.emf.common.util.URI)2 PathTraverser (org.eclipse.xtext.mwe.PathTraverser)2 File (java.io.File)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 NameBasedFilter (org.eclipse.xtext.mwe.NameBasedFilter)1