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

Change how the default class translation files path is constructed #106

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;

import javax.annotation.processing.ProcessingEnvironment;
Expand Down Expand Up @@ -146,10 +147,18 @@ private List<File> findTranslationFiles(final MessageInterface messageInterface)
if (translationFilesPath != null) {
classTranslationFilesPath = translationFilesPath + packageName.replace('.', File.separatorChar);

//By default use the class output folder
//By default, use the class output folder
} else {
FileObject fObj = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, packageName, interfaceName);
classTranslationFilesPath = fObj.toUri().getPath().replace(interfaceName, "");
// Create some random name:
String relativeName = interfaceName + UUID.randomUUID();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's weird to me is the exception is java.io.FileNotFoundException, yet using a random file name makes it work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, in the original approach, it was trying to get a resource (and eclipse compiler wants resources to actually exist) while this patch is just creating a new resource (so a potential problem could be that a file with that "random" name actually exists 🙈)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry getResource() vs createResource(). I should have noticed that.

// Eclipse compiler will throw an exception on processingEnv.getFiler().getResource(..)
// when the resource is missing, while the regular javac will just return a file object that points to
// a non-existent file.
// Since we only care about the path here ... we are going to create a dummy resource file
// that that will be cleaned up right after:
FileObject fObj = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, packageName, relativeName);
classTranslationFilesPath = fObj.toUri().getPath().replace(relativeName, "");
fObj.delete();
}
final List<File> result;
File[] files = new File(classTranslationFilesPath).listFiles(new TranslationFileFilter(interfaceName));
Expand Down