예제 #1
0
        public JavaClass convert(Type abstractMojoType, string groupId)
        {
            JavaClass javaClass = new JavaClass();
             	javaClass.PackageName = abstractMojoType.Namespace;
             	javaClass.ClassName = abstractMojoType.Name;
             	javaClass.ExtendsClassName = "org.apache.npanday.plugins.AbstractMojo";

             	ImportPackage importPackage = new ImportPackage();
             	javaClass.ImportPackage = importPackage.AddPackage("org.apache.npanday.plugins.FieldAnnotation");

             	List<String> classComments = new List<String>();
            System.Attribute[] attributes =
                System.Attribute.GetCustomAttributes(abstractMojoType);

            foreach(Attribute attribute in attributes)
            {
                if(attribute is ClassAttribute)
                {
                    ClassAttribute mojo = (ClassAttribute) attribute;
                    classComments.Add(@"@phase " + mojo.Phase);
                    classComments.Add(@"@goal " + mojo.Goal);
                    break;
                }
            }

            javaClass.Comments = classComments;

             	List<JavaField> javaFields = new List<JavaField>();
            foreach(FieldInfo field in abstractMojoType.GetFields())
            {
                foreach (Attribute attribute in field.GetCustomAttributes(true))
                {
                    FieldAttribute mojo = (FieldAttribute) attribute;
                    javaFields.Add(CreateJavaField("public", mojo.Type, mojo.Name,
                                                   CreateMojoComment(mojo.Expression),
                                                   "FieldAnnotation()"));
                }
            }

            //mojo parameters
            javaFields.Add(CreateJavaField("private", "org.apache.maven.project.MavenProject", "project",
                                           CreateMojoComment("${project}"), null));
            javaFields.Add(CreateJavaField("private", "String", "localRepository",
                                           CreateMojoComment("${settings.localRepository}"), null));
            javaFields.Add(CreateJavaField("private", "String", "vendor",
                                           CreateMojoComment("${vendor}"), null));
            javaFields.Add(CreateJavaField("private", "String", "vendorVersion",
                                           CreateMojoComment("${vendorVersion}"), null));
            javaFields.Add(CreateJavaField("private", "String", "frameworkVersion",
                                           CreateMojoComment("${frameworkVersion}"), null));

            //components
            List<String> comments = new List<String>();
            comments.Add("@component");
            javaFields.Add(CreateJavaField("private", "npanday.executable.NetExecutableFactory",
                                           "netExecutableFactory", comments, null));
            javaFields.Add(CreateJavaField("private", "org.apache.npanday.plugins.PluginContext",
                                           "pluginContext", comments, null));

            //methods
            List<JavaMethod> javaMethods = new List<JavaMethod>();

            javaMethods.Add(CreateJavaMethod("public", "String", "getMojoArtifactId",
                                             new Code().AddLine(@"return """
                                                                + abstractMojoType.Namespace + @""";")));

            javaMethods.Add(CreateJavaMethod("public", "String", "getMojoGroupId",
                                             new Code().AddLine(@"return """
                                                                + groupId + @""";")));

            javaMethods.Add(CreateJavaMethod("public", "String", "getClassName",
                                             new Code().AddLine(@"return """ + abstractMojoType.Namespace
                                                                + "." + abstractMojoType.Name + @""";")));

            javaMethods.Add(CreateJavaMethod("public", "org.apache.npanday.plugins.PluginContext",
                                             "getNetPluginContext",
                                             CreateCodeWithSimpleReturnType("pluginContext")));

            javaMethods.Add(CreateJavaMethod("public", "npanday.executable.NetExecutableFactory",
                                             "getNetExecutableFactory",
                                             CreateCodeWithSimpleReturnType("netExecutableFactory")));

            javaMethods.Add(CreateJavaMethod("public", "org.apache.maven.project.MavenProject", "getMavenProject",
                                             CreateCodeWithSimpleReturnType("project")));

            javaMethods.Add(CreateJavaMethod("public", "String", "getLocalRepository",
                                             CreateCodeWithSimpleReturnType("localRepository")));

            javaMethods.Add(CreateJavaMethod("public", "String", "getVendorVersion",
                                             CreateCodeWithSimpleReturnType("vendorVersion")));

            javaMethods.Add(CreateJavaMethod("public", "String", "getVendor",
                                             CreateCodeWithSimpleReturnType("vendor")));

            javaMethods.Add(CreateJavaMethod("public", "String", "getFrameworkVersion",
                                             CreateCodeWithSimpleReturnType("frameworkVersion")));
            javaClass.JavaMethods = javaMethods;
             	javaClass.JavaFields = javaFields;
             	return javaClass;
        }
예제 #2
0
        public void unmarshall(JavaClass javaClass, FileInfo fileInfo)
        {
            StreamWriter streamWriter = fileInfo.CreateText();
            streamWriter.WriteLine("package " + javaClass.PackageName + ";");
            streamWriter.WriteLine("");

            foreach(String importPackageName in javaClass.ImportPackage.Packages)
            {
                streamWriter.WriteLine("import " + importPackageName + ";");
                streamWriter.WriteLine("");
            }

            if(javaClass.Comments != null)
            {
                streamWriter.WriteLine("/**");
                foreach(String comment in javaClass.Comments)
                {
                    streamWriter.WriteLine(" * " + comment);
                }
                streamWriter.WriteLine(" */");
            }

            streamWriter.WriteLine("public class " + javaClass.ClassName);
            if(javaClass.ExtendsClassName != null)
            {
                streamWriter.WriteLine("    extends " + javaClass.ExtendsClassName);
            }
            streamWriter.WriteLine("{");

            if(javaClass.JavaFields != null)
            {
                foreach(JavaField javaField in javaClass.JavaFields)
                {
                    List<String> comments = javaField.Comments;
                    if(comments != null && comments.Count > 0)
                    {
                        streamWriter.WriteLine("       /**");
                        foreach(String comment in comments)
                        {
                            streamWriter.WriteLine("        * " + comment);
                        }
                        streamWriter.WriteLine("        */");
                    }
                    if(javaField.Annotation != null)
                    {
                        streamWriter.WriteLine("        @" + javaField.Annotation);
                    }

                    streamWriter.WriteLine("        " + javaField.Access + " " +
                                          javaField.ReturnType + " " + javaField.FieldName + ";");
                    streamWriter.WriteLine("");
                }
            }

            if(javaClass.JavaMethods != null)
            {
                foreach(JavaMethod javaMethod in javaClass.JavaMethods)
                {
                    List<String> comments = javaMethod.Comments;
                    if(comments != null && comments.Count > 0)
                    {
                        streamWriter.WriteLine("       /**");
                        foreach(String comment in comments)
                        {
                            streamWriter.WriteLine("      * " + comment);
                        }
                        streamWriter.WriteLine("        */");
                    }
                    streamWriter.WriteLine("        " + javaMethod.Access + " " + javaMethod.ReturnType
                                           + " " + javaMethod.MethodName + "()");
                    streamWriter.WriteLine("        {");
                    foreach(String codeLine in javaMethod.Code.CodeLines)
                    {
                        streamWriter.WriteLine("            " + codeLine);
                    }
                    streamWriter.WriteLine("        }");
                    streamWriter.WriteLine("");

                }
            }

            streamWriter.WriteLine("}");
            streamWriter.AutoFlush = true;
            streamWriter.Close();
            Console.WriteLine("File Exists = " + fileInfo.Exists);
        }