mirror of https://github.com/apache/activemq.git
To get the openwire generation scripts to work under maven2, I first needed to create a gram plugin. This module should eventually move the the groovy project since
it would be better maintained there. git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@419352 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a49017fb10
commit
8b0f2930a3
|
@ -0,0 +1,103 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
Copyright 2005-2006 The Apache Software Foundation
|
||||
|
||||
Licensed 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.
|
||||
-->
|
||||
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>incubator-activemq</groupId>
|
||||
<artifactId>activemq-parent</artifactId>
|
||||
<version>4.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>maven-gram-plugin</artifactId>
|
||||
<packaging>maven-plugin</packaging>
|
||||
<name>Gram Plugin</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-project</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-archiver</artifactId>
|
||||
<version>1.0-alpha-5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-archiver</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-utils</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-artifact</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>groovy</groupId>
|
||||
<artifactId>groovy-all</artifactId>
|
||||
<version>1.0-jsr-03</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>annogen</groupId>
|
||||
<artifactId>annogen</artifactId>
|
||||
<version>0.1.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>default-tools.jar</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>java.vendor</name>
|
||||
<value>Sun Microsystems Inc.</value>
|
||||
</property>
|
||||
</activation>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.sun</groupId>
|
||||
<artifactId>tools</artifactId>
|
||||
<version>1.4.2</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${java.home}/../lib/tools.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,145 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2005-2006 The Apache Software Foundation
|
||||
*
|
||||
* Licensed 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.apache.activemq.maven;
|
||||
|
||||
import groovy.lang.GroovyShell;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.codehaus.groovy.control.CompilationFailedException;
|
||||
import org.codehaus.jam.JamService;
|
||||
import org.codehaus.jam.JamServiceFactory;
|
||||
import org.codehaus.jam.JamServiceParams;
|
||||
import org.codehaus.plexus.archiver.manager.ArchiverManager;
|
||||
|
||||
/**
|
||||
* Greates a Mojo for Gram.
|
||||
*
|
||||
* This module is largly based on the Gram class here:
|
||||
* http://cvs.groovy.codehaus.org/browse/groovy/groovy/modules/gram/src/main/org/codehaus/gram/Gram.java?r=1.4
|
||||
*
|
||||
* We need to get this moved over the groovy project eventually.. Putting in ActiveMQ for now so we can keep going.
|
||||
*
|
||||
* @goal gram
|
||||
* @description Runs the Gram code generator
|
||||
*/
|
||||
public class GramMojo extends AbstractMojo
|
||||
{
|
||||
/**
|
||||
* Source directories of the project.
|
||||
*
|
||||
* @parameter expression="${project.compileSourceRoots}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
private List sourceDirs;
|
||||
|
||||
|
||||
/**
|
||||
* @parameter
|
||||
* @required
|
||||
*/
|
||||
String scripts = "";
|
||||
|
||||
/**
|
||||
* @parameter
|
||||
*/
|
||||
Map groovyProperties = Collections.EMPTY_MAP;
|
||||
|
||||
/**
|
||||
* To look up Archiver/UnArchiver implementations
|
||||
*
|
||||
* @parameter expression="${component.org.codehaus.plexus.archiver.manager.ArchiverManager}"
|
||||
* @required
|
||||
*/
|
||||
protected ArchiverManager archiverManager;
|
||||
|
||||
public void execute() throws MojoExecutionException
|
||||
{
|
||||
|
||||
try {
|
||||
|
||||
System.out.println("Parsing source files in: " + sourceDirs);
|
||||
|
||||
JamServiceFactory jamServiceFactory = JamServiceFactory.getInstance();
|
||||
JamServiceParams params = jamServiceFactory.createServiceParams();
|
||||
|
||||
File[] dirs = new File[sourceDirs.size()];
|
||||
{
|
||||
int i=0;
|
||||
for (Iterator iter = sourceDirs.iterator(); iter.hasNext();) {
|
||||
dirs[i++] = new File((String) iter.next());
|
||||
}
|
||||
}
|
||||
|
||||
params.includeSourcePattern(dirs, "**/*.java");
|
||||
JamService jam = jamServiceFactory.createService(params);
|
||||
|
||||
String[] scriptsArray = scripts.split(":");
|
||||
for (int i = 1; i < scriptsArray.length; i++) {
|
||||
String script = scriptsArray[i].trim();
|
||||
if(script.length() > 0 ) {
|
||||
getLog().info("Evaluating Groovy script: " + script);
|
||||
execute(jam, script);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
getLog().error("Caught: " + e, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void execute(JamService jam, String script) throws CompilationFailedException, IOException {
|
||||
File file = new File(script);
|
||||
if (file.isFile()) {
|
||||
GroovyShell shell = createShell(jam);
|
||||
shell.evaluate(file);
|
||||
}
|
||||
else {
|
||||
// lets try load the script on the classpath
|
||||
InputStream in = getClass().getClassLoader().getResourceAsStream(script);
|
||||
if (in == null) {
|
||||
in = Thread.currentThread().getContextClassLoader().getResourceAsStream(script);
|
||||
if (in == null) {
|
||||
throw new IOException("No script called: " + script + " could be found on the classpath or the file system");
|
||||
}
|
||||
}
|
||||
GroovyShell shell = createShell(jam);
|
||||
shell.evaluate(in, script);
|
||||
}
|
||||
}
|
||||
|
||||
protected GroovyShell createShell(JamService jam) {
|
||||
GroovyShell answer = new GroovyShell();
|
||||
for (Iterator iter = groovyProperties.entrySet().iterator(); iter.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) iter.next();
|
||||
answer.setProperty((String) entry.getKey(), entry.getValue());
|
||||
}
|
||||
answer.setProperty("jam", jam);
|
||||
answer.setProperty("classes", jam.getAllClasses());
|
||||
return answer;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue