Revision: 19583
          http://sourceforge.net/p/gate/code/19583
Author:   markagreenwood
Date:     2016-09-20 05:55:30 +0000 (Tue, 20 Sep 2016)
Log Message:
-----------
the new GATE maven plugin to help with the build process

Added Paths:
-----------
    gate/branches/sawdust2/gate-maven-plugin/
    gate/branches/sawdust2/gate-maven-plugin/.classpath
    gate/branches/sawdust2/gate-maven-plugin/.project
    gate/branches/sawdust2/gate-maven-plugin/pom.xml
    gate/branches/sawdust2/gate-maven-plugin/src/
    gate/branches/sawdust2/gate-maven-plugin/src/it/
    gate/branches/sawdust2/gate-maven-plugin/src/it/settings.xml
    gate/branches/sawdust2/gate-maven-plugin/src/it/simple-it/
    gate/branches/sawdust2/gate-maven-plugin/src/it/simple-it/pom.xml
    gate/branches/sawdust2/gate-maven-plugin/src/it/simple-it/verify.groovy
    gate/branches/sawdust2/gate-maven-plugin/src/main/
    gate/branches/sawdust2/gate-maven-plugin/src/main/java/
    gate/branches/sawdust2/gate-maven-plugin/src/main/java/uk/
    gate/branches/sawdust2/gate-maven-plugin/src/main/java/uk/ac/
    gate/branches/sawdust2/gate-maven-plugin/src/main/java/uk/ac/gate/
    gate/branches/sawdust2/gate-maven-plugin/src/main/java/uk/ac/gate/maven/
    
gate/branches/sawdust2/gate-maven-plugin/src/main/java/uk/ac/gate/maven/DumpCreoleToXML.java

Added: gate/branches/sawdust2/gate-maven-plugin/.classpath
===================================================================
--- gate/branches/sawdust2/gate-maven-plugin/.classpath                         
(rev 0)
+++ gate/branches/sawdust2/gate-maven-plugin/.classpath 2016-09-20 05:55:30 UTC 
(rev 19583)
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="src" output="target/classes" path="src/main/java">
+               <attributes>
+                       <attribute name="optional" value="true"/>
+                       <attribute name="maven.pomderived" value="true"/>
+               </attributes>
+       </classpathentry>
+       <classpathentry kind="src" output="target/test-classes" 
path="src/test/java">
+               <attributes>
+                       <attribute name="optional" value="true"/>
+                       <attribute name="maven.pomderived" value="true"/>
+               </attributes>
+       </classpathentry>
+       <classpathentry kind="con" 
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
+               <attributes>
+                       <attribute name="maven.pomderived" value="true"/>
+               </attributes>
+       </classpathentry>
+       <classpathentry kind="con" 
path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+               <attributes>
+                       <attribute name="maven.pomderived" value="true"/>
+               </attributes>
+       </classpathentry>
+       <classpathentry kind="output" path="target/classes"/>
+</classpath>

Added: gate/branches/sawdust2/gate-maven-plugin/.project
===================================================================
--- gate/branches/sawdust2/gate-maven-plugin/.project                           
(rev 0)
+++ gate/branches/sawdust2/gate-maven-plugin/.project   2016-09-20 05:55:30 UTC 
(rev 19583)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>gate-maven-plugin</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.m2e.core.maven2Builder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+               <nature>org.eclipse.m2e.core.maven2Nature</nature>
+       </natures>
+</projectDescription>

Added: gate/branches/sawdust2/gate-maven-plugin/pom.xml
===================================================================
--- gate/branches/sawdust2/gate-maven-plugin/pom.xml                            
(rev 0)
+++ gate/branches/sawdust2/gate-maven-plugin/pom.xml    2016-09-20 05:55:30 UTC 
(rev 19583)
@@ -0,0 +1,56 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+       <modelVersion>4.0.0</modelVersion>
+
+       <groupId>uk.ac.gate</groupId>
+       <artifactId>gate-maven-plugin</artifactId>
+       <version>0.0.1-SNAPSHOT</version>
+       <packaging>maven-plugin</packaging>
+
+       <name>GATE Maven Plugin</name>
+
+       <organization>
+               <name>GATE</name>
+               <url>http://gate.ac.uk</url>
+       </organization>
+
+       <properties>
+               <maven.compiler.source>1.8</maven.compiler.source>
+               <maven.compiler.target>1.8</maven.compiler.target>
+               
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+       </properties>
+
+       <dependencies>
+               <dependency>
+                       <groupId>org.apache.maven</groupId>
+                       <artifactId>maven-plugin-api</artifactId>
+                       <version>2.0</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.maven.plugin-tools</groupId>
+                       <artifactId>maven-plugin-annotations</artifactId>
+                       <version>3.2</version>
+                       <scope>provided</scope>
+               </dependency>
+
+               <dependency>
+                       <groupId>org.apache.maven</groupId>
+                       <artifactId>maven-project</artifactId>
+                       <version>2.0.11</version>
+               </dependency>
+
+               <dependency>
+                       <groupId>org.apache.maven</groupId>
+                       <artifactId>maven-artifact</artifactId>
+                       <version>2.0.11</version>
+               </dependency>
+
+               <dependency>
+                       <groupId>uk.ac.gate</groupId>
+                       <artifactId>gate-core</artifactId>
+                       <version>9.0-SNAPSHOT</version>
+               </dependency>
+       </dependencies>
+
+
+</project>

Added: gate/branches/sawdust2/gate-maven-plugin/src/it/settings.xml
===================================================================
--- gate/branches/sawdust2/gate-maven-plugin/src/it/settings.xml                
                (rev 0)
+++ gate/branches/sawdust2/gate-maven-plugin/src/it/settings.xml        
2016-09-20 05:55:30 UTC (rev 19583)
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<settings>
+  <profiles>
+    <profile>
+      <id>it-repo</id>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
+      <repositories>
+        <repository>
+          <id>local.central</id>
+          <url>@localRepositoryUrl@</url>
+          <releases>
+            <enabled>true</enabled>
+          </releases>
+          <snapshots>
+            <enabled>true</enabled>
+          </snapshots>
+        </repository>
+      </repositories>
+      <pluginRepositories>
+        <pluginRepository>
+          <id>local.central</id>
+          <url>@localRepositoryUrl@</url>
+          <releases>
+            <enabled>true</enabled>
+          </releases>
+          <snapshots>
+            <enabled>true</enabled>
+          </snapshots>
+        </pluginRepository>
+      </pluginRepositories>
+    </profile>
+  </profiles>
+</settings>

Added: gate/branches/sawdust2/gate-maven-plugin/src/it/simple-it/pom.xml
===================================================================
--- gate/branches/sawdust2/gate-maven-plugin/src/it/simple-it/pom.xml           
                (rev 0)
+++ gate/branches/sawdust2/gate-maven-plugin/src/it/simple-it/pom.xml   
2016-09-20 05:55:30 UTC (rev 19583)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>uk.ac.gate.it</groupId>
+  <artifactId>simple-it</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <description>A simple IT verifying the basic use case.</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>@project.groupId@</groupId>
+        <artifactId>@project.artifactId@</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>touch</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>touch</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: gate/branches/sawdust2/gate-maven-plugin/src/it/simple-it/verify.groovy
===================================================================
--- gate/branches/sawdust2/gate-maven-plugin/src/it/simple-it/verify.groovy     
                        (rev 0)
+++ gate/branches/sawdust2/gate-maven-plugin/src/it/simple-it/verify.groovy     
2016-09-20 05:55:30 UTC (rev 19583)
@@ -0,0 +1,3 @@
+File touchFile = new File( basedir, "target/touch.txt" );
+
+assert touchFile.isFile()

Added: 
gate/branches/sawdust2/gate-maven-plugin/src/main/java/uk/ac/gate/maven/DumpCreoleToXML.java
===================================================================
--- 
gate/branches/sawdust2/gate-maven-plugin/src/main/java/uk/ac/gate/maven/DumpCreoleToXML.java
                                (rev 0)
+++ 
gate/branches/sawdust2/gate-maven-plugin/src/main/java/uk/ac/gate/maven/DumpCreoleToXML.java
        2016-09-20 05:55:30 UTC (rev 19583)
@@ -0,0 +1,138 @@
+package uk.ac.gate.maven;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+
+import gate.Gate;
+import gate.Gate.ResourceInfo;
+import gate.Plugin;
+import gate.creole.CreoleAnnotationHandler;
+import gate.util.GateClassLoader;
+import gate.util.asm.ClassReader;
+
+@Mojo(name = "DumpCreoleToXML", defaultPhase = LifecyclePhase.PROCESS_CLASSES)
+public class DumpCreoleToXML extends AbstractMojo {
+  private XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
+
+  @Parameter(defaultValue = "${project.build.outputDirectory}", property = 
"dir", required = true)
+  private File dir;
+
+  @Parameter(defaultValue = "${project.groupId}", property = "group", required 
= true)
+  private String group;
+
+  @Parameter(defaultValue = "${project.artifactId}", property = "artifact", 
required = true)
+  private String artifact;
+
+  @Parameter(defaultValue = "${project.version}", property = "version", 
required = true)
+  private String version;
+
+  @Parameter(defaultValue="${project}", readonly=true, required=true)
+  private MavenProject project;
+  
+  public void execute() throws MojoExecutionException {
+        
+    File creoleXML = new File(dir, "creole.xml");
+    
+    if (!creoleXML.exists()) return;
+    
+    File expandedXML = new File(dir, "META-INF/gate/creole.xml");
+    expandedXML.getParentFile().mkdirs();
+    
+    GateClassLoader cl = null;
+    
+    try (FileOutputStream fos = new FileOutputStream(expandedXML);) {
+      Gate.init();
+      cl = Gate.getClassLoader().getDisposableClassLoader(dir.toString());
+      cl.addURL(dir.toURI().toURL());
+      
+      for (Artifact artifact : 
(Set<Artifact>)project.getDependencyArtifacts()) {
+        //This seems wrong as it's also adding GATE itself which we should 
probably try and avoid
+        cl.addURL(artifact.getFile().toURI().toURL());
+      }
+     
+      Plugin plugin = new TargetPlugin(creoleXML,cl);
+      CreoleAnnotationHandler annotationHandler = new 
CreoleAnnotationHandler(plugin);
+      Document creoleDoc = plugin.getCreoleXML();
+      annotationHandler.processAnnotations(creoleDoc);    
+      outputter.output(creoleDoc, fos);
+    } catch(Exception e) {
+      throw new MojoExecutionException("error expanding creole", e);
+    }
+    finally {
+      Gate.getClassLoader().forgetClassLoader(cl);
+    }
+  }
+
+  @SuppressWarnings("serial")
+  class TargetPlugin extends Plugin.Maven {
+    private File creoleFile;
+    private GateClassLoader cl;
+
+    public TargetPlugin(File creoleFile, GateClassLoader cl) throws 
MalformedURLException {
+      super(group, artifact, version);
+      this.cl = cl;
+      this.creoleFile = creoleFile;
+      this.baseURL = new URL(creoleFile.toURI().toURL(), ".");
+    }
+
+    @Override
+    public Document getCreoleXML() throws Exception {
+      SAXBuilder builder = new SAXBuilder(false);
+      Document jdomDoc = builder.build(new FileInputStream(creoleFile),
+          baseURL.toExternalForm());
+      Element creoleRoot = jdomDoc.getRootElement();
+      Set<String> resources = new HashSet<String>();
+      String dir = creoleFile.getParent();
+      if(!dir.endsWith(File.separator)) dir = dir + File.separator;
+      scanDir(dir.length(), creoleFile.getParentFile(), resources);
+      for(String resource : resources) {
+        Element resourceElement = new Element("RESOURCE");
+        Element classElement = new Element("CLASS");
+        classElement.setText(resource);
+        resourceElement.addContent(classElement);
+        creoleRoot.addContent(resourceElement);
+      }
+      return jdomDoc;
+    }
+
+    private void scanDir(int prefix, File dir, Set<String> resources)
+        throws IOException {
+      for(File file : dir.listFiles()) {
+        if(file.isDirectory()) {
+          scanDir(prefix, file, resources);
+        } else if(file.getName().endsWith((".class"))) {
+          String className = file.getAbsolutePath().substring(prefix);
+          className =
+              className.substring(0, className.length() - 6).replace('/', '.');
+          ClassReader classReader = new ClassReader(new FileInputStream(file));
+          ResourceInfo resInfo = new ResourceInfo(null, className, null);
+          ResourceInfoVisitor visitor = new ResourceInfoVisitor(resInfo);
+          classReader.accept(visitor, ClassReader.SKIP_CODE
+              | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
+          if(visitor.isCreoleResource()) {
+            resources.add(className);
+          }
+        }
+      }
+    }
+  }
+}

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
_______________________________________________
GATE-cvs mailing list
GATE-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to