Search in sources :

Example 1 with ClassPathFilter

use of org.finos.legend.engine.shared.javaCompiler.ClassPathFilter in project legend-engine by finos.

the class JavaHelper method createNewJavaCompiler.

private static EngineJavaCompiler createNewJavaCompiler() {
    List<ClassPathFilter> filters = Lists.mutable.of(new ExecutionPlanDependenciesFilter());
    ExecutionPlanJavaCompilerExtensionLoader.extensions().forEach(ext -> filters.add(ext.getExtraClassPathFilter()));
    return new EngineJavaCompiler(JavaVersion.JAVA_8, new CompositeClassPathFilter(filters));
}
Also used : EngineJavaCompiler(org.finos.legend.engine.shared.javaCompiler.EngineJavaCompiler) ClassPathFilter(org.finos.legend.engine.shared.javaCompiler.ClassPathFilter) CompositeClassPathFilter(org.finos.legend.engine.shared.javaCompiler.CompositeClassPathFilter) CompositeClassPathFilter(org.finos.legend.engine.shared.javaCompiler.CompositeClassPathFilter) ExecutionPlanDependenciesFilter(org.finos.legend.engine.plan.compilation.ExecutionPlanDependenciesFilter)

Example 2 with ClassPathFilter

use of org.finos.legend.engine.shared.javaCompiler.ClassPathFilter in project legend-engine by finos.

the class TestJavaCompileClassPathFilter method compilesWhenPackageIsFilteredIn.

@Test
public void compilesWhenPackageIsFilteredIn() throws Exception {
    ClassPathFilter filter = new ClassPathFilter() {

        @Override
        public boolean isPermittedPackage(String packageName) {
            return packageName.equals(JavaVersion.class.getPackage().getName());
        }

        @Override
        public boolean isPermittedClass(String packageName, String className) {
            return isPermittedPackage(packageName);
        }
    };
    EngineJavaCompiler c = new EngineJavaCompiler(JavaVersion.JAVA_8, filter);
    c.compile(Lists.mutable.with(StringJavaSource.newStringJavaSource("engine.generated", "Example", code)));
    Assert.assertEquals("JAVA_8", execute(c));
}
Also used : EngineJavaCompiler(org.finos.legend.engine.shared.javaCompiler.EngineJavaCompiler) ClassPathFilter(org.finos.legend.engine.shared.javaCompiler.ClassPathFilter) Test(org.junit.Test)

Example 3 with ClassPathFilter

use of org.finos.legend.engine.shared.javaCompiler.ClassPathFilter in project legend-engine by finos.

the class TestJavaCompileClassPathFilter method failsWhenPackageIsFilteredOut.

@Test(expected = JavaCompileException.class)
public void failsWhenPackageIsFilteredOut() throws Exception {
    ClassPathFilter filter = new ClassPathFilter() {

        @Override
        public boolean isPermittedPackage(String packageName) {
            return !packageName.equals(JavaVersion.class.getPackage().getName());
        }

        @Override
        public boolean isPermittedClass(String packageName, String className) {
            return isPermittedPackage(packageName);
        }
    };
    EngineJavaCompiler c = new EngineJavaCompiler(JavaVersion.JAVA_8, filter);
    c.compile(Lists.mutable.with(StringJavaSource.newStringJavaSource("engine.generated", "Example", code)));
}
Also used : EngineJavaCompiler(org.finos.legend.engine.shared.javaCompiler.EngineJavaCompiler) ClassPathFilter(org.finos.legend.engine.shared.javaCompiler.ClassPathFilter) JavaVersion(org.finos.legend.engine.shared.javaCompiler.JavaVersion) Test(org.junit.Test)

Example 4 with ClassPathFilter

use of org.finos.legend.engine.shared.javaCompiler.ClassPathFilter in project legend-engine by finos.

the class TestJavaCompileClassPathFilter method succeedsWhenPackageIsFilteredOutButFilteringSwitchedOff.

@Test
public void succeedsWhenPackageIsFilteredOutButFilteringSwitchedOff() throws Exception {
    ClassPathFilter filter = new ClassPathFilter() {

        @Override
        public boolean isPermittedPackage(String packageName) {
            return !packageName.equals(JavaVersion.class.getPackage().getName());
        }

        @Override
        public boolean isPermittedClass(String packageName, String className) {
            return isPermittedPackage(packageName);
        }
    };
    EngineJavaCompiler c = new EngineJavaCompiler(JavaVersion.JAVA_8, filter);
    c.setFilteringEnabled(false);
    c.compile(Lists.mutable.with(StringJavaSource.newStringJavaSource("engine.generated", "Example", code)));
    Assert.assertEquals("JAVA_8", execute(c));
}
Also used : EngineJavaCompiler(org.finos.legend.engine.shared.javaCompiler.EngineJavaCompiler) ClassPathFilter(org.finos.legend.engine.shared.javaCompiler.ClassPathFilter) JavaVersion(org.finos.legend.engine.shared.javaCompiler.JavaVersion) Test(org.junit.Test)

Example 5 with ClassPathFilter

use of org.finos.legend.engine.shared.javaCompiler.ClassPathFilter in project legend-engine by finos.

the class TestJavaCompileClassPathFilter method compilesWhenClassIsFilteredIn.

@Test
public void compilesWhenClassIsFilteredIn() throws Exception {
    ClassPathFilter filter = new ClassPathFilter() {

        @Override
        public boolean isPermittedPackage(String packageName) {
            return packageName.equals(JavaVersion.class.getPackage().getName());
        }

        @Override
        public boolean isPermittedClass(String packageName, String className) {
            return isPermittedPackage(packageName) && className.equals(JavaVersion.class.getSimpleName());
        }
    };
    EngineJavaCompiler c = new EngineJavaCompiler(JavaVersion.JAVA_8, filter);
    c.compile(Lists.mutable.with(StringJavaSource.newStringJavaSource("engine.generated", "Example", code)));
    Assert.assertEquals("JAVA_8", execute(c));
}
Also used : EngineJavaCompiler(org.finos.legend.engine.shared.javaCompiler.EngineJavaCompiler) ClassPathFilter(org.finos.legend.engine.shared.javaCompiler.ClassPathFilter) Test(org.junit.Test)

Aggregations

ClassPathFilter (org.finos.legend.engine.shared.javaCompiler.ClassPathFilter)6 EngineJavaCompiler (org.finos.legend.engine.shared.javaCompiler.EngineJavaCompiler)6 Test (org.junit.Test)5 JavaVersion (org.finos.legend.engine.shared.javaCompiler.JavaVersion)3 ExecutionPlanDependenciesFilter (org.finos.legend.engine.plan.compilation.ExecutionPlanDependenciesFilter)1 CompositeClassPathFilter (org.finos.legend.engine.shared.javaCompiler.CompositeClassPathFilter)1