Fail the build when the reference resource is not found
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 12 Dec 2013 18:33:11 +0100
changeset 348b18accb1660f
parent 340 eda32ccb6882
child 349 53634fd10e30
Fail the build when the reference resource is not found
boot/src/main/java/org/apidesign/html/boot/impl/JavaScriptProcesor.java
     1.1 --- a/boot/src/main/java/org/apidesign/html/boot/impl/JavaScriptProcesor.java	Thu Nov 28 14:44:08 2013 +0100
     1.2 +++ b/boot/src/main/java/org/apidesign/html/boot/impl/JavaScriptProcesor.java	Thu Dec 12 18:33:11 2013 +0100
     1.3 @@ -49,6 +49,8 @@
     1.4  import javax.lang.model.type.TypeKind;
     1.5  import javax.lang.model.type.TypeMirror;
     1.6  import javax.tools.Diagnostic;
     1.7 +import javax.tools.FileObject;
     1.8 +import javax.tools.StandardLocation;
     1.9  import net.java.html.js.JavaScriptBody;
    1.10  import net.java.html.js.JavaScriptResource;
    1.11  import org.openide.util.lookup.ServiceProvider;
    1.12 @@ -100,6 +102,31 @@
    1.13                  }
    1.14              }
    1.15          }
    1.16 +        for (Element e : roundEnv.getElementsAnnotatedWith(JavaScriptResource.class)) {
    1.17 +            JavaScriptResource r = e.getAnnotation(JavaScriptResource.class);
    1.18 +            if (r == null) {
    1.19 +                continue;
    1.20 +            }
    1.21 +            final String res;
    1.22 +            if (r.value().startsWith("/")) {
    1.23 +                res = r.value();
    1.24 +            } else {
    1.25 +                res = findPkg(e).replace('.', '/') + "/" + r.value();
    1.26 +            }
    1.27 +            
    1.28 +            try {
    1.29 +                FileObject os = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "", res);
    1.30 +                os.openInputStream().close();
    1.31 +            } catch (IOException ex1) {
    1.32 +                try {
    1.33 +                    FileObject os2 = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", res);
    1.34 +                    os2.openInputStream().close();
    1.35 +                } catch (IOException ex2) {
    1.36 +                    msg.printMessage(Diagnostic.Kind.ERROR, "Cannot find " + res + " in " + res + " package", e);
    1.37 +                }
    1.38 +            }
    1.39 +        }
    1.40 +
    1.41          if (roundEnv.processingOver()) {
    1.42              generateCallbackClass(javacalls);
    1.43              javacalls.clear();