From 42ff19796085d688540fbbfb5b8005aa77d60d83 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Fri, 9 Sep 2005 20:57:44 +0000 Subject: [PATCH] o getting rid of old cruft that has long since been useful git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@279875 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/plugin/generator/BeanGenerator.java | 199 ------------- .../jelly/JellyHarnessGenerator.java | 273 ------------------ 2 files changed, 472 deletions(-) delete mode 100644 maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/BeanGenerator.java delete mode 100644 maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/jelly/JellyHarnessGenerator.java diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/BeanGenerator.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/BeanGenerator.java deleted file mode 100644 index d310bdc67a..0000000000 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/BeanGenerator.java +++ /dev/null @@ -1,199 +0,0 @@ -package org.apache.maven.tools.plugin.generator; - -/* - * Copyright 2001-2004 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. - */ - -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.plugin.descriptor.Parameter; -import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.codehaus.modello.generator.java.javasource.JClass; -import org.codehaus.modello.generator.java.javasource.JConstructor; -import org.codehaus.modello.generator.java.javasource.JMethod; -import org.codehaus.modello.generator.java.javasource.JParameter; -import org.codehaus.modello.generator.java.javasource.JSourceWriter; -import org.codehaus.modello.generator.java.javasource.JType; -import org.codehaus.plexus.util.IOUtil; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Iterator; -import java.util.List; - -/** - * [JC] Is this class defunct now? I can't find o.a.m.plugin.BeanPluginAdapter in the codebase... - * I'm not going to edit this class to account for aliases, deprecation, etc. until I know. - * - * @todo use the descriptions in the descriptor for the javadoc pushed into the - * source code. - */ -public class BeanGenerator - implements Generator -{ - public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor ) - throws IOException - { - for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); ) - { - MojoDescriptor descriptor = (MojoDescriptor) it.next(); - processPluginDescriptor( descriptor, destinationDirectory ); - } - } - - protected void processPluginDescriptor( MojoDescriptor descriptor, File destinationDirectory ) - throws IOException - { - String implementation = descriptor.getImplementation(); - - String className = implementation.substring( implementation.lastIndexOf( "." ) + 1 ) + "Bean"; - - JClass jClass = new JClass( className ); - - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - - jClass.setSuperClass( "org.apache.maven.plugin.BeanPluginAdapter" ); - - jClass.addImport( "java.util.*" ); - - // ---------------------------------------------------------------------- - // Use the same package as the plugin we are wrapping. - // ---------------------------------------------------------------------- - - String packageName = implementation.substring( 0, implementation.lastIndexOf( "." ) ); - - jClass.setPackageName( packageName ); - - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - - JConstructor constructor = new JConstructor( jClass ); - - constructor.getSourceCode().add( "super( new " + implementation + "() );" ); - - jClass.addConstructor( constructor ); - - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - - List parameters = descriptor.getParameters(); - - for ( int i = 0; i < parameters.size(); i++ ) - { - Parameter parameter = (Parameter) parameters.get( i ); - - jClass.addMethod( createSetter( parameter ) ); - } - - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - - String packageDirectory = replace( packageName, ".", "/", -1 ); - - File destination = new File( destinationDirectory, packageDirectory + "/" + className + ".java" ); - - if ( !destination.getParentFile().exists() ) - { - destination.getParentFile().mkdirs(); - } - - FileWriter writer = null; - try - { - writer = new FileWriter( destination ); - - JSourceWriter sourceWriter = new JSourceWriter( writer ); - - jClass.print( sourceWriter ); - - writer.flush(); - } - finally - { - IOUtil.close( writer ); - } - } - - private JMethod createSetter( Parameter parameter ) - { - String propertyName = capitalise( parameter.getName() ); - - JMethod setter = new JMethod( null, "set" + propertyName ); - - String type = parameter.getType(); - - JType parameterType; - - int arrayLocation = type.indexOf( "[]" ); - - if ( arrayLocation > 0 ) - { - type = type.substring( 0, arrayLocation ); - - parameterType = new JClass( type ).createArray(); - } - else - { - parameterType = new JClass( type ); - } - - setter.addParameter( new JParameter( parameterType, parameter.getName() ) ); - - setter.getSourceCode().add( "addParameter( " + "\"" + parameter.getName() + "\", " + parameter.getName() - + " );" ); - - return setter; - } - - protected String capitalise( String str ) - { - if ( str == null || str.length() == 0 ) - { - return str; - } - - return new StringBuffer( str.length() ).append( Character.toTitleCase( str.charAt( 0 ) ) ) - .append( str.substring( 1 ) ) - .toString(); - } - - protected String replace( String text, String repl, String with, int max ) - { - if ( text == null || repl == null || with == null || repl.length() == 0 ) - { - return text; - } - - StringBuffer buf = new StringBuffer( text.length() ); - int start = 0, end = 0; - while ( (end = text.indexOf( repl, start )) != -1 ) - { - buf.append( text.substring( start, end ) ).append( with ); - start = end + repl.length(); - - if ( --max == 0 ) - { - break; - } - } - buf.append( text.substring( start ) ); - return buf.toString(); - } -} \ No newline at end of file diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/jelly/JellyHarnessGenerator.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/jelly/JellyHarnessGenerator.java deleted file mode 100644 index 38b3a7d9f4..0000000000 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/jelly/JellyHarnessGenerator.java +++ /dev/null @@ -1,273 +0,0 @@ -package org.apache.maven.tools.plugin.generator.jelly; - -/* - * Copyright 2001-2005 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. - */ - -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.plugin.descriptor.Parameter; -import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.tools.plugin.generator.Generator; -import org.apache.maven.tools.plugin.util.PluginUtils; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; -import org.codehaus.plexus.util.xml.XMLWriter; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Iterator; -import java.util.List; - -/** - * @todo use the descriptions in the descriptor for the javadoc pushed into the - * source code. - * @todo write plugin.properties (as a place holder, we don't technially need - * it) - * @todo convert POM or just strip out the dependencies to create a project.xml - * that will serve as the trigger to download dependencies. - */ -public class JellyHarnessGenerator - implements Generator -{ - protected String getClassName( MojoDescriptor pluginDescriptor ) - { - return pluginDescriptor.getImplementation() + "Bean"; - } - - public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor ) - throws IOException - { - FileWriter writer = null; - PrettyPrintXMLWriter w; - try - { - writer = new FileWriter( new File( destinationDirectory, "plugin.jelly" ) ); - - w = new PrettyPrintXMLWriter( writer ); - - writePluginFile( w, pluginDescriptor ); - - writer.flush(); - } - finally - { - IOUtil.close( writer ); - } - - // ---------------------------------------------------------------------- - // project.xml - // ---------------------------------------------------------------------- - - writer = null; - try - { - writer = new FileWriter( new File( destinationDirectory, "project.xml" ) ); - - w = new PrettyPrintXMLWriter( writer ); - - writeProjectFile( w, pluginDescriptor ); - - writer.flush(); - } - finally - { - IOUtil.close( writer ); - } - } - - private void writePluginFile( PrettyPrintXMLWriter w, PluginDescriptor pluginDescriptor ) - { - w.startElement( "project" ); - - w.addAttribute( "xmlns:j", "jelly:core" ); - - w.addAttribute( "xmlns:d", "jelly:define" ); - - w.addAttribute( "xmlns:" + pluginDescriptor.getGoalPrefix(), pluginDescriptor.getGoalPrefix() ); - - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - - w.startElement( "d:taglib" ); - - w.addAttribute( "uri", pluginDescriptor.getGoalPrefix() ); - - for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); ) - { - MojoDescriptor descriptor = (MojoDescriptor) it.next(); - processMojoDescriptor( descriptor, w ); - } - - w.endElement(); - - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - - for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); ) - { - MojoDescriptor descriptor = (MojoDescriptor) it.next(); - writeGoals( descriptor, w ); - } - - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - - w.endElement(); - } - - private void writeProjectFile( PrettyPrintXMLWriter w, PluginDescriptor pluginDescriptor ) - { - w.startElement( "project" ); - - w.startElement( "dependencies" ); - - PluginUtils.writeDependencies( w, pluginDescriptor ); - - w.endElement(); - - w.endElement(); - } - - protected void processMojoDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w ) - { - String goalName = mojoDescriptor.getGoal(); - - // ---------------------------------------------------------------------- - // jellybean - // ---------------------------------------------------------------------- - // - // - // - // - // ---------------------------------------------------------------------- - - w.startElement( "d:jellybean" ); - - w.addAttribute( "name", goalName + "Bean" ); - - w.addAttribute( "className", getClassName( mojoDescriptor ) ); - - w.addAttribute( "method", "execute" ); - - w.endElement(); - - // ---------------------------------------------------------------------- - // tag - // ---------------------------------------------------------------------- - // - // - // - // - // - // ---------------------------------------------------------------------- - - w.startElement( "d:tag" ); - - w.addAttribute( "name", goalName ); - - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - - w.startElement( mojoDescriptor.getFullGoalName() + "Bean" ); - - List parameters = mojoDescriptor.getParameters(); - - for ( int i = 0; i < parameters.size(); i++ ) - { - Parameter parameter = (Parameter) parameters.get( i ); - - String paramName = parameter.getAlias(); - - if ( StringUtils.isEmpty( paramName ) ) - { - paramName = parameter.getName(); - } - - w.addAttribute( paramName, "${" + paramName + "}" ); - } - - w.endElement(); - - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - - w.endElement(); - } - - private void writeGoals( MojoDescriptor mojoDescriptor, XMLWriter w ) - { - w.startElement( "goal" ); - - w.addAttribute( "name", mojoDescriptor.getFullGoalName() ); - - if ( mojoDescriptor.getDescription() != null ) - { - w.addAttribute( "description", mojoDescriptor.getDescription() ); - } - - w.startElement( mojoDescriptor.getFullGoalName() + "Bean" ); - - List goalParameters = mojoDescriptor.getParameters(); - - for ( int j = 0; j < goalParameters.size(); j++ ) - { - Parameter p = (Parameter) goalParameters.get( j ); - - String expression = p.getExpression(); - - int projectIndex = expression.indexOf( "project" ); - - if ( projectIndex > 0 ) - { - expression = expression.substring( 0, projectIndex ) + "pom" + - expression.substring( projectIndex + 7 ); - } - - w.addAttribute( p.getName(), expression ); - } - - w.endElement(); - - w.endElement(); - } - - protected String capitalise( String str ) - { - if ( str == null || str.length() == 0 ) - { - return str; - } - - return new StringBuffer( str.length() ).append( Character.toTitleCase( str.charAt( 0 ) ) ).append( - str.substring( 1 ) ).toString(); - } -} \ No newline at end of file