use of org.codehaus.groovy.grails.plugins.AstPluginDescriptorReader in project grails-maven by grails.
the class DefaultGrailsServices method readGrailsPluginProject.
public GrailsPluginProject readGrailsPluginProject() throws MojoExecutionException {
final GrailsPluginProject pluginProject = new GrailsPluginProject();
final File[] files = getBasedir().listFiles(new FilenameFilter() {
public boolean accept(final File file, final String s) {
return s.endsWith(FILE_SUFFIX) && s.length() > FILE_SUFFIX.length();
}
});
if (files == null || files.length != 1) {
throw new MojoExecutionException("Could not find a plugin descriptor. Expected to find exactly one file " + "called FooGrailsPlugin.groovy in '" + getBasedir().getAbsolutePath() + "'.");
}
final File descriptor = files[0];
pluginProject.setFileName(descriptor);
final String className = descriptor.getName().substring(0, descriptor.getName().length() - ".groovy".length());
final String pluginName = getLowerCaseHyphenSeparatedName(getLogicalName(className, "GrailsPlugin"));
pluginProject.setPluginName(pluginName);
final GroovyClassLoader classLoader = new GroovyClassLoader();
final AstPluginDescriptorReader reader = new AstPluginDescriptorReader(classLoader);
final GrailsPluginInfo info = reader.readPluginInfo(new org.codehaus.groovy.grails.io.support.FileSystemResource(descriptor));
final String version = info.getVersion();
if (version == null || version.trim().length() == 0) {
throw new MojoExecutionException("Plugin does not have a version!");
}
pluginProject.setVersion(version);
return pluginProject;
}
Aggregations