Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there anyway to set JOOR to create a test directory under \target ? #87

Closed
cvgaviao opened this issue Sep 23, 2019 · 7 comments
Closed

Comments

@cvgaviao
Copy link

I'm trying to create an annotation processor class and started to use JOOR to test it.

    @Test
    public void ensureAnnotationProcessorCreatesResourceBundleClassAndPropertiesWithMultipleLocales() throws Exception {
        MessageBundleGeneratorAnnotationProcessor processor = new MessageBundleGeneratorAnnotationProcessor();
        Reflect.compile(
                "br.com.c8tech.javalib.apt.i18n.SourceResourceBundleWithTwoMethods",
                "package br.com.c8tech.javalib.apt.i18n; "
                        + "@MessageBundle "
                        + "public interface SourceResourceBundleWithTwoMethods {"
                        + "@Message(value=\" worked {0} ! \", locale=\"pt-BR\" )"
                        + " public String m1(String pZero);" 
                        + "@Message(\" worked {0} {1}! \")"
                        + " public String m2(String pZero, String pOne);" 
                        + "}",
                        new CompileOptions().options("-source", "8")
                        .processors(processor))
        .type();
        assertTrue(processor.isProcessed());
    }

In the class under test I'm creating a resource file:

FileObject f = processingEnv.getFiler().createResource(
                    StandardLocation.SOURCE_OUTPUT, "", resourceName);
            

I'm running the test inside Eclipse IDE and I was expecting that the resulting files was being created inside a specific test directory under project's \target directory, but it is being created inside my annotation processor project's directory instead.

Am I missing something ?

@lukaseder
Copy link
Member

Not sure what could be missing here. Would you mind creating a complete test case so we can reproduce it?

@cvgaviao
Copy link
Author

Not sure what could be missing here. Would you mind creating a complete test case so we can reproduce it?

Hi @lukaseder, thanks for your time.

I've pushed an initial code of my annotation processor project to github: https://github.com/cvgaviao/c8tech-jlib-i18n/blob/master/c8tech-jlib-i18n-apt/src/test/java/br/com/c8tech/jlib/i18n/apt/MessageBundleAnnotationProcessorTest.java

Note that when running this test the resulting artifacts are being created inside the c8tech-jlib-i18n-apt/ directory.

@lukaseder
Copy link
Member

@cvgaviao
Copy link
Author

cvgaviao commented Oct 2, 2019

Have you tried specifying the -s option in your CompileOptions?

Wow, this is it !!!
I've passed too many years running tests with maven/eclipse and I never noted that they provide that -s to the compiler :( .

As I'm using Junit5, I've created a simple extension that creates and injects the method test's directory into a Path method parameter. So the developer just need to use it to set the -soption.

I'll will commit and post the link here soon. Perhaps others need it too.

thanks !

@cvgaviao
Copy link
Author

cvgaviao commented Oct 2, 2019

@lukaseder, one more question:

Do I need to set any parameter in order to see the messages provided to processingEnv.getMessager().printMessage() method?

@cvgaviao
Copy link
Author

cvgaviao commented Oct 2, 2019

Have you tried specifying the -s option in your CompileOptions?

Well, actually the use of -s do not resolved my problem. It was partially resolved by using -d.

When generating resource files using processingEnv.getFiler().createResource. The resource are correctly created in the directory passed to -doption.

But unfortunately, neither -s or -d is working when generating source files using processingEnv.getFiler().createSourceFile.

Somehow the calculated directory being used is something like this: org.joor.Compile$JavaFileObject[string:///br/com/c8tech/jlib/i18n/apt/SourceResourceBundleWithTwoMethodsAndMultipleLocalesImpl.java]

@lukaseder
Copy link
Member

Do I need to set any parameter in order to see the messages provided to processingEnv.getMessager().printMessage() method?

I guess that's currently not possible yet. The output appears in the exception in case of a compilation error, but not in case of the happy path. I've created a feature request for this: #88

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants