You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/04/25 07:07:36 UTC

[GitHub] JaroslavTulach closed pull request #6: Gradle plugin to process the @JavaScriptBody annotations

JaroslavTulach closed pull request #6: Gradle plugin to process the @JavaScriptBody annotations
URL: https://github.com/apache/incubator-netbeans-html4j/pull/6
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/.gitignore b/.gitignore
index 22ed2af..2987134 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,6 @@
 /target/
 *.orig
 */nb-configuration.xml
-
+/html4j-maven-plugin/src/test/resources/org/netbeans/html/mojo/gradle*/build/*
+/html4j-maven-plugin/src/test/resources/org/netbeans/html/mojo/gradle*/.gradle/*
+/html4j-maven-plugin/src/test/resources/org/netbeans/html/mojo/gradle*/.nb*gradle/*
\ No newline at end of file
diff --git a/html4j-maven-plugin/pom.xml b/html4j-maven-plugin/pom.xml
index f1ddbfe..182c492 100644
--- a/html4j-maven-plugin/pom.xml
+++ b/html4j-maven-plugin/pom.xml
@@ -36,6 +36,12 @@
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
+  <repositories>
+      <repository>
+          <id>gradle</id>
+          <url>https://repo.gradle.org/gradle/libs-releases-local/</url>
+      </repository>
+  </repositories>
   <build>
       <plugins>
           <plugin>
@@ -65,9 +71,37 @@
                   <skip>true</skip>
               </configuration>
           </plugin>
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-compiler-plugin</artifactId>
+            <version>2.3.2</version>
+            <configuration>
+               <source>1.7</source>
+               <target>1.7</target>
+            </configuration>
+         </plugin>
+         <plugin>
+             <groupId>org.fortasoft</groupId>
+             <artifactId>gradle-maven-plugin</artifactId>
+             <version>1.0.8</version>
+             <configuration>
+                 <tasks>
+                     <task>build</task>
+                 </tasks>
+                 <gradleProjectDirectory>src/test/resources/org/netbeans/html/mojo/gradle1</gradleProjectDirectory>
+             </configuration>
+             <executions>
+                 <execution>
+                     <phase>generate-test-resources</phase>
+                     <goals>
+                         <goal>invoke</goal>
+                     </goals>
+                 </execution>
+             </executions>
+         </plugin>
       </plugins>
   </build>
-      
+
   <dependencies>
       <dependency>
           <groupId>org.apache.maven</groupId>
@@ -88,7 +122,7 @@
           <type>jar</type>
       </dependency>
       <dependency>
-          <groupId>org.ow2.asm</groupId> 
+          <groupId>org.ow2.asm</groupId>
           <artifactId>asm</artifactId>
           <type>jar</type>
       </dependency>
@@ -98,5 +132,25 @@
           <scope>test</scope>
           <type>jar</type>
       </dependency>
+      <dependency>
+          <groupId>org.netbeans.html</groupId>
+          <artifactId>net.java.html.boot</artifactId>
+          <version>${project.version}</version>
+          <scope>test</scope>
+          <type>jar</type>
+      </dependency>
+      <!-- gradle plugin -->
+      <dependency>
+          <groupId>org.gradle</groupId>
+          <artifactId>gradle-core</artifactId>
+          <version>3.0</version>
+          <scope>provided</scope>
+      </dependency>
+      <dependency>
+          <groupId>org.codehaus.groovy</groupId>
+          <artifactId>groovy</artifactId>
+          <version>1.8.3</version>
+          <scope>provided</scope>
+      </dependency>
   </dependencies>
 </project>
diff --git a/html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotations.java b/html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotations.java
new file mode 100644
index 0000000..9457287
--- /dev/null
+++ b/html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotations.java
@@ -0,0 +1,309 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.html.mojo;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Reader;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.objectweb.asm.ClassReader;
+
+abstract class ProcessJsAnnotations {
+    private Boolean addAsm;
+    private final LinkedList<URL> cp = new LinkedList<>();
+    private final List<File> roots = new LinkedList<>();
+
+    protected abstract void log(String msg);
+
+    public void addClasspathEntry(File f) {
+        try {
+            cp.add(f.toURI().toURL());
+        } catch (MalformedURLException ex) {
+            throw new IllegalStateException(ex);
+        }
+    }
+
+    public void setAddAsm(boolean add) {
+        this.addAsm = add;
+    }
+
+    public void addRoot(File file) {
+        roots.add(file);
+    }
+
+    public void process() throws IOException {
+        MultiFile classes = new MultiFile(roots);
+        for (File r : roots) {
+            cp.add(r.toURI().toURL());
+        }
+        URLClassLoader l = new URLClassLoader(cp.toArray(new URL[cp.size()]));
+        Boolean asm = addAsm;
+        if (asm == null) {
+            try {
+                l.loadClass(ClassReader.class.getName());
+                // OK
+                asm = false;
+            } catch (ClassNotFoundException ex) {
+                asm = true;
+            }
+        }
+        if (asm) {
+            URL loc = ClassReader.class.getProtectionDomain().getCodeSource().getLocation();
+            cp.addFirst(loc);
+            l = new URLClassLoader(cp.toArray(new URL[cp.size()]));
+        }
+
+        MultiFile master = classes.child("META-INF", "net.java.html.js.classes");
+        processClasses(l, master, classes);
+    }
+
+    private void processClasses(ClassLoader l, MultiFile master, MultiFile f) throws IOException {
+        if (!f.exists()) {
+            return;
+        }
+        if (f.isDirectory()) {
+            boolean classes = f.child("net.java.html.js.classes").exists();
+            MultiFile[] arr = f.listFiles();
+            if (arr != null) {
+                for (MultiFile file : arr) {
+                    if (classes || file.isDirectory()) {
+                        processClasses(l, master, file);
+                    }
+                }
+            }
+        }
+
+        if (!f.isFile() || !f.getName().endsWith(".class")) {
+            return;
+        }
+
+        byte[] arr = f.readFully();
+        byte[] newArr = null;
+        try {
+            Class<?> fnUtils = l.loadClass("org.netbeans.html.boot.impl.FnUtils");
+            Method transform = fnUtils.getMethod("transform", byte[].class, ClassLoader.class);
+
+            newArr = (byte[]) transform.invoke(null, arr, l);
+            if (newArr == null || newArr == arr) {
+                return;
+            }
+            filterClass(f.getParentFile().child("net.java.html.js.classes"), f.getName());
+            filterClass(master, f.getName());
+        } catch (Exception ex) {
+            throw new IOException("Can't process " + f, ex);
+        }
+        log("Processing " + f);
+        f.writeArr(newArr);
+    }
+
+    private static void filterClass(MultiFile f, String className) throws IOException {
+        if (!f.exists()) {
+            return;
+        }
+        if (className.endsWith(".class")) {
+            className = className.substring(0, className.length() - 6);
+        }
+
+        List<String> arr;
+        boolean modified;
+        try (BufferedReader r = new BufferedReader(f.reader())) {
+            arr = new ArrayList<>();
+            modified = false;
+            for (;;) {
+                String line = r.readLine();
+                if (line == null) {
+                    break;
+                }
+                if (line.endsWith(className)) {
+                    modified = true;
+                    continue;
+                }
+                arr.add(line);
+            }
+        }
+
+        if (modified) {
+            if (arr.isEmpty()) {
+                f.delete();
+            } else {
+                try (FileWriter w = f.writer()) {
+                    for (String l : arr) {
+                        w.write(l);
+                        w.write("\n");
+                    }
+                }
+            }
+        }
+    }
+
+    private static final class MultiFile {
+
+        private final List<File> roots;
+
+        MultiFile(List<File> roots) {
+            this.roots = roots;
+        }
+
+        MultiFile child(String... names) {
+            List<File> arr = new ArrayList<>();
+            for (File r : roots) {
+                for (String n : names) {
+                    r = new File(r, n);
+                }
+                arr.add(r);
+            }
+            return new MultiFile(arr);
+        }
+
+        boolean exists() {
+            for (File r : roots) {
+                if (r.exists()) {
+                    return true;
+                }
+            }
+            return false;
+        }
+
+        boolean isDirectory() {
+            for (File r : roots) {
+                if (r.isDirectory()) {
+                    return true;
+                }
+            }
+            return false;
+        }
+
+        String getName() {
+            for (File r : roots) {
+                return r.getName();
+            }
+            return null;
+        }
+
+        MultiFile[] listFiles() {
+            Set<String> names = new TreeSet<>();
+            for (File r : roots) {
+                final String[] children = r.list();
+                if (children == null) {
+                    continue;
+                }
+                names.addAll(Arrays.asList(children));
+            }
+            MultiFile[] arr = new MultiFile[names.size()];
+            int at = 0;
+            for (String name : names) {
+                arr[at++] = child(name);
+            }
+            return arr;
+        }
+
+        boolean isFile() {
+            for (File r : roots) {
+                if (r.isFile()) {
+                    return true;
+                }
+            }
+            return false;
+        }
+
+        private MultiFile getParentFile() {
+            List<File> arr = new ArrayList<>();
+            for (File r : roots) {
+                arr.add(r.getParentFile());
+            }
+            return new MultiFile(arr);
+        }
+
+        byte[] readFully() throws IOException {
+            for (File f : roots) {
+                if (f.isFile()) {
+                    byte[] arr;
+                    try (FileInputStream is = new FileInputStream(f)) {
+                        arr = new byte[(int)f.length()];
+                        int off = 0;
+                        while (off < arr.length) {
+                            int read = is.read(arr, off, arr.length - off);
+                            if (read == -1) {
+                                break;
+                            }
+                            off += read;
+                        }
+                    }
+                    return arr;
+                }
+            }
+            throw new FileNotFoundException();
+        }
+
+        private void writeArr(byte[] newArr) throws IOException, FileNotFoundException {
+            for (File f : roots) {
+                if (f.isDirectory()) {
+                    continue;
+                }
+                f.getParentFile().mkdirs();
+                try (FileOutputStream os = new FileOutputStream(f)) {
+                    os.write(newArr);
+                }
+                return;
+            }
+            throw new FileNotFoundException();
+        }
+
+        private Reader reader() throws FileNotFoundException {
+            for (File r : roots) {
+                if (r.isFile()) {
+                    return new FileReader(r);
+                }
+            }
+            throw new FileNotFoundException();
+        }
+
+        private void delete() {
+            for (File r : roots) {
+                r.delete();
+            }
+        }
+
+        private FileWriter writer() throws IOException {
+            for (File r : roots) {
+                if (r.isFile()) {
+                    return new FileWriter(r);
+                }
+            }
+            throw new FileNotFoundException();
+        }
+    }
+}
diff --git a/html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotationsGradle.java b/html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotationsGradle.java
new file mode 100644
index 0000000..861a940
--- /dev/null
+++ b/html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotationsGradle.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.html.mojo;
+
+import java.util.Set;
+import org.gradle.api.Action;
+import org.gradle.api.DefaultTask;
+import org.gradle.api.Plugin;
+import org.gradle.api.Project;
+import org.gradle.api.Task;
+
+public final class ProcessJsAnnotationsGradle implements Plugin<Project> {
+
+    @Override
+    public void apply(final Project p) {
+        final ProcessJsAnnotationsTask process = p.getTasks().create("process-js-annotations", ProcessJsAnnotationsTask.class, new Action<ProcessJsAnnotationsTask>() {
+            @Override
+            public void execute(ProcessJsAnnotationsTask process) {
+            }
+        });
+        p.afterEvaluate(new Action<Project>() {
+            @Override
+            public void execute(final Project p) {
+                Set<? extends Task> tasks = (Set<? extends Task>) p.findProperty("tasks");
+                for (Task task : tasks) {
+                    if (task.getName().startsWith("compile")) {
+                        process.dependsOn(task);
+                    }
+                    if (
+                            task.getName().equals("test") ||
+                            task.getName().equals("run") ||
+                            task.getName().equals("jar")
+                    ) {
+                        if (task instanceof DefaultTask) {
+                            ((DefaultTask)task).dependsOn(process);
+                        }
+                    }
+                }
+                process.doLast(new Action<Task>() {
+                    @Override
+                    public void execute(Task t) {
+                        process.processJsAnnotations(p);
+                    }
+                });
+            }
+        });
+    }
+}
diff --git a/html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotationsMojo.java b/html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotationsMojo.java
index 8f16300..c4dd9f6 100644
--- a/html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotationsMojo.java
+++ b/html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotationsMojo.java
@@ -18,22 +18,8 @@
  */
 package org.netbeans.html.mojo;
 
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
 import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -44,7 +30,6 @@
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.annotations.ResolutionScope;
 import org.apache.maven.project.MavenProject;
-import org.objectweb.asm.ClassReader;
 
 @Mojo(
     name="process-js-annotations",
@@ -54,16 +39,21 @@
 public final class ProcessJsAnnotationsMojo extends AbstractMojo {
     @Component
     private MavenProject prj;
-    
+
     @Parameter(defaultValue = "${project.build.directory}/classes")
     private File classes;
-    
+
     public ProcessJsAnnotationsMojo() {
     }
 
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
-        LinkedList<URL> arr = new LinkedList<URL>();
+        ProcessJsAnnotations jsa = new ProcessJsAnnotations() {
+            @Override
+            protected void log(String msg) {
+                getLog().info(msg);
+            }
+        };
         boolean foundAsm = false;
         for (Artifact a : prj.getArtifacts()) {
             final File f = a.getFile();
@@ -71,129 +61,17 @@ public void execute() throws MojoExecutionException, MojoFailureException {
                 if (a.getArtifactId().equals("asm")) {
                     foundAsm = true;
                 }
-                try {
-                    arr.add(f.toURI().toURL());
-                } catch (MalformedURLException ex) {
-                    throw new IllegalStateException(ex);
-                }
+                jsa.addClasspathEntry(f);
             }
         }
         if (!foundAsm) {
-            URL loc = ClassReader.class.getProtectionDomain().getCodeSource().getLocation();
-            arr.addFirst(loc);
+            jsa.setAddAsm(true);
         }
+        jsa.addRoot(classes);
         try {
-            arr.add(classes.toURI().toURL());
-            URLClassLoader l = new URLClassLoader(arr.toArray(new URL[arr.size()]));
-            File master = new File(new File(classes, "META-INF"), "net.java.html.js.classes");
-            processClasses(l, master, classes);
+            jsa.process();
         } catch (IOException ex) {
             throw new MojoExecutionException("Problem converting JavaScriptXXX annotations", ex);
         }
     }
-    
-    private void processClasses(ClassLoader l, File master, File f) throws IOException, MojoExecutionException {
-        if (!f.exists()) {
-            return;
-        }
-        if (f.isDirectory()) {
-            boolean classes = new File(f, "net.java.html.js.classes").exists();
-            File[] arr = f.listFiles();
-            if (arr != null) {
-                for (File file : arr) {
-                    if (classes || file.isDirectory()) {
-                        processClasses(l, master, file);
-                    }
-                }
-            }
-            return;
-        }
-        
-        if (!f.getName().endsWith(".class")) {
-            return;
-        }
-        
-        byte[] arr = new byte[(int)f.length()];
-        FileInputStream is = new FileInputStream(f);
-        try {
-            readArr(arr, is);
-        } finally {
-            is.close();
-        }
-
-        byte[] newArr = null;
-        try {
-            Class<?> fnUtils = l.loadClass("org.netbeans.html.boot.impl.FnUtils");
-            Method transform = fnUtils.getMethod("transform", byte[].class, ClassLoader.class);
-            
-            newArr = (byte[]) transform.invoke(null, arr, l);
-            if (newArr == null || newArr == arr) {
-                return;
-            }
-            filterClass(new File(f.getParentFile(), "net.java.html.js.classes"), f.getName());
-            filterClass(master, f.getName());
-        } catch (Exception ex) {
-            throw new MojoExecutionException("Can't process " + f, ex);
-        }
-        getLog().info("Processing " + f);
-        writeArr(f, newArr);        
-    }
-
-    private void writeArr(File f, byte[] newArr) throws IOException, FileNotFoundException {
-        FileOutputStream os = new FileOutputStream(f);
-        try {
-            os.write(newArr);
-        } finally {
-            os.close();
-        }
-    }
-
-    private static void readArr(byte[] arr, InputStream is) throws IOException {
-        int off = 0;
-        while (off< arr.length) {
-            int read = is.read(arr, off, arr.length - off);
-            if (read == -1) {
-                break;
-            }
-            off += read;
-        }
-    }
-    
-    private static void filterClass(File f, String className) throws IOException {
-        if (!f.exists()) {
-            return;
-        }
-        if (className.endsWith(".class")) {
-            className = className.substring(0, className.length() - 6);
-        }
-        
-        BufferedReader r = new BufferedReader(new FileReader(f));
-        List<String> arr = new ArrayList<String>();
-        boolean modified = false;
-        for (;;) {
-            String line = r.readLine();
-            if (line == null) {
-                break;
-            }
-            if (line.endsWith(className)) {
-                modified = true;
-                continue;
-            }
-            arr.add(line);
-        }
-        r.close();
-        
-        if (modified) {
-            if (arr.isEmpty()) {
-                f.delete();
-            } else {
-                FileWriter w = new FileWriter(f);
-                for (String l : arr) {
-                    w.write(l);
-                    w.write("\n");
-                }
-                w.close();
-            }
-        }
-    }
 }
diff --git a/html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotationsTask.java b/html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotationsTask.java
new file mode 100644
index 0000000..8e26237
--- /dev/null
+++ b/html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotationsTask.java
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.html.mojo;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.Set;
+import org.gradle.api.DefaultTask;
+import org.gradle.api.GradleException;
+import org.gradle.api.Project;
+
+public class ProcessJsAnnotationsTask extends DefaultTask {
+    void processJsAnnotations(final Project p) {
+        final Set<?> allSourceSets = (Set<?>) p.findProperty("sourceSets");
+        if (allSourceSets == null) {
+            throw new GradleException("Cannot find sourceSets for project " + p);
+        }
+        for (Object sourceSet : allSourceSets) {
+            ProcessJsAnnotations process = new ProcessJsAnnotations() {
+                @Override
+                protected void log(String msg) {
+                    p.getLogger().info(msg);
+                }
+            };
+            Iterable cp = invoke(Iterable.class, sourceSet, "getRuntimeClasspath");
+            for (Object elem : cp) {
+                final File pathElement = (File) elem;
+                process.addClasspathEntry(pathElement);
+            }
+            Iterable<?> outs = invoke(Iterable.class, sourceSet, "getOutput");
+            for (Object classes : outs) {
+                process.addRoot((File) classes);
+            }
+            try {
+                process.process();
+            } catch (IOException ex) {
+                throw new GradleException(ex.getMessage(), ex);
+            }
+        }
+    }
+
+    private static <T> T invoke(Class<T> returnType, Object obj, String methodName) {
+        try {
+            Method methodOutput = obj.getClass().getMethod(methodName);
+            Object res = methodOutput.invoke(obj);
+            return returnType.cast(res);
+        } catch (Exception ex) {
+            throw new IllegalStateException(ex);
+        }
+    }
+
+}
diff --git a/html4j-maven-plugin/src/main/resources/META-INF/gradle-plugins/html4j.properties b/html4j-maven-plugin/src/main/resources/META-INF/gradle-plugins/html4j.properties
new file mode 100644
index 0000000..1e3c8ea
--- /dev/null
+++ b/html4j-maven-plugin/src/main/resources/META-INF/gradle-plugins/html4j.properties
@@ -0,0 +1,21 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+implementation-class=org.netbeans.html.mojo.ProcessJsAnnotationsGradle
+
diff --git a/html4j-maven-plugin/src/test/java/org/netbeans/html/mojo/Gradle1Test.java b/html4j-maven-plugin/src/test/java/org/netbeans/html/mojo/Gradle1Test.java
new file mode 100644
index 0000000..482e529
--- /dev/null
+++ b/html4j-maven-plugin/src/test/java/org/netbeans/html/mojo/Gradle1Test.java
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.html.mojo;
+
+import java.io.Closeable;
+import java.io.Reader;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.concurrent.Callable;
+import org.netbeans.html.boot.spi.Fn;
+import static org.testng.Assert.*;
+import org.testng.annotations.Test;
+
+public class Gradle1Test {
+    @Test
+    public void checkTheResultOfTheBuild() throws Exception {
+        URL b = Gradle1Test.class.getResource("gradle1/build.gradle");
+        assertNotNull(b, "gradle build script found");
+        URL u = Gradle1Test.class.getResource("gradle1/build/libs/gradle1-1.0-SNAPSHOT.jar");
+        assertNotNull(u, "Result of gradle1 build found");
+        URLClassLoader l = new URLClassLoader(new URL[] { u }, Gradle1Test.class.getClassLoader());
+        Class<?> clazz = l.loadClass("Gradle1Check");
+        Callable<?> r = (Callable<?>) clazz.newInstance();
+
+        try (Closeable c = Fn.activate(new NumberPresenter())) {
+            Object value = r.call();
+            assertTrue(value instanceof Number, "It is a number");
+            assertEquals(((Number)value).intValue(), 42, "The meaning is returned");
+        }
+    }
+
+    private static final class NumberPresenter implements Fn.Presenter {
+
+        @Override
+        public Fn defineFn(String code, String... ignore) {
+            if (code.startsWith("return")) {
+                code = code.substring(6);
+            }
+            code = code.replace(';', ' ').trim();
+            return new NumberFn(Integer.valueOf(code));
+        }
+
+        @Override
+        public void displayPage(URL url, Runnable r) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public void loadScript(Reader reader) throws Exception {
+            throw new UnsupportedOperationException();
+        }
+
+    }
+
+    private static class NumberFn extends Fn {
+
+        private final int value;
+
+        public NumberFn(int value) {
+            this.value = value;
+        }
+
+        @Override
+        public Object invoke(Object o, Object... os) throws Exception {
+            return value;
+        }
+    }
+}
diff --git a/html4j-maven-plugin/src/test/resources/org/netbeans/html/mojo/gradle1/build.gradle b/html4j-maven-plugin/src/test/resources/org/netbeans/html/mojo/gradle1/build.gradle
new file mode 100644
index 0000000..f162133
--- /dev/null
+++ b/html4j-maven-plugin/src/test/resources/org/netbeans/html/mojo/gradle1/build.gradle
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+defaultTasks 'clean', 'build'
+
+buildscript {
+    repositories {
+        mavenLocal()
+    }
+    dependencies {
+        classpath "org.ow2.asm:asm:5.0"
+        classpath files("../../../../../../../../target/classes/")
+    }
+}
+
+
+group 'org.netbeans.html.gradle1'
+version '1.0-SNAPSHOT'
+
+apply plugin: 'java'
+apply plugin: 'html4j'
+
+dependencies {
+    compile fileTree(dir: '../../../../../../../../../boot/target/', include: ['*.jar'])
+}
+
diff --git a/html4j-maven-plugin/src/test/resources/org/netbeans/html/mojo/gradle1/src/main/java/Gradle1Check.java b/html4j-maven-plugin/src/test/resources/org/netbeans/html/mojo/gradle1/src/main/java/Gradle1Check.java
new file mode 100644
index 0000000..88b97fc
--- /dev/null
+++ b/html4j-maven-plugin/src/test/resources/org/netbeans/html/mojo/gradle1/src/main/java/Gradle1Check.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import net.java.html.js.JavaScriptBody;
+import java.util.concurrent.Callable;
+
+public class Gradle1Check implements Callable<Integer> {
+
+    @Override
+    public Integer call() throws Exception {
+        return compute();
+    }
+
+    @JavaScriptBody(args = {}, body = "return 42;")
+    private static int compute() {
+        return -1;
+    }
+}
diff --git a/pom.xml b/pom.xml
index b0e8a9f..f55467b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -216,6 +216,8 @@ org.netbeans.html.boot.impl:org.netbeans.html.boot.fx:org.netbeans.html.context.
                         <exclude>**/target/**</exclude>
                         <exclude>.gitignore</exclude>
                         <exclude>**/.git/**</exclude>
+                        <exclude>**/.gradle/**</exclude>
+                        <exclude>**/.nb-gradle/**</exclude>
                         <exclude>**/.repository/**</exclude>
                         <exclude>**/.maven/**</exclude>
                         <exclude>**/*.sigtest</exclude>
@@ -223,6 +225,7 @@ org.netbeans.html.boot.impl:org.netbeans.html.boot.fx:org.netbeans.html.context.
                         <exclude>README.md</exclude>
                         <exclude>DEPENDENCIES</exclude>
                         <exclude>**/main/resources/org/netbeans/html/ko4j/knockout-3.4.0.js</exclude>
+                        <exclude>**/test/resources/org/netbeans/html/mojo/gradle*/build/**</exclude>
                     </excludes>
                     <excludeSubProjects>false</excludeSubProjects>
                     <useDefaultExcludes>false</useDefaultExcludes>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists