You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JavaSources.java 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (C) 2012-present the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.pf4j.test;
  17. import com.google.testing.compile.JavaFileObjects;
  18. import javax.tools.JavaFileObject;
  19. import java.util.List;
  20. import static com.google.testing.compile.Compiler.javac;
  21. /**
  22. * Keep common Java sources (useful in many tests).
  23. * For Java 13+ is recommended to use Text Block feature (it's more clear).
  24. *
  25. * @author Decebal Suiu
  26. */
  27. public class JavaSources {
  28. public static final JavaFileObject Greeting = JavaFileObjects.forSourceLines("Greeting",
  29. "package test;",
  30. "import org.pf4j.ExtensionPoint;",
  31. "",
  32. "public interface Greeting extends ExtensionPoint {",
  33. " String getGreeting();",
  34. "}");
  35. public static final JavaFileObject WhazzupGreeting = JavaFileObjects.forSourceLines("WhazzupGreeting",
  36. "package test;",
  37. "import org.pf4j.Extension;",
  38. "",
  39. "@Extension",
  40. "public class WhazzupGreeting implements Greeting {",
  41. " @Override",
  42. " public String getGreeting() {",
  43. " return \"Whazzup\";",
  44. " }",
  45. "}");
  46. /**
  47. * Compile a list of sources using javac compiler.
  48. */
  49. public static List<JavaFileObject> compileAll(JavaFileObject... sources) {
  50. return javac().compile(sources).generatedFiles();
  51. }
  52. public static JavaFileObject compile(JavaFileObject source) {
  53. return compileAll(source).get(0);
  54. }
  55. }