diff --git a/codegen/core/pom.xml b/codegen/core/pom.xml new file mode 100644 index 0000000000..8f7b6f0ade --- /dev/null +++ b/codegen/core/pom.xml @@ -0,0 +1,106 @@ + + + + + jclouds-codegen-project + org.jclouds + 1.0-SNAPSHOT + ../project/pom.xml + + 4.0.0 + jclouds-codegen-core + jclouds code generator + jar + jclouds code generator + + + scm:svn:http://jclouds.googlecode.com/svn/trunk/codegen/core + scm:svn:https://jclouds.googlecode.com/svn/trunk/codegen/core + http://jclouds.googlecode.com/svn/trunk/codegen/core + + + + + gson + http://google-gson.googlecode.com/svn/mavenrepo + + + + + + commons-io + commons-io + 1.4 + + + com.google.code.gson + gson + 1.3 + compile + + + org.freemarker + freemarker + 2.3.14 + + + com.google.collections + google-collections + 1.0-rc1 + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.jclouds.codegen.util.CodeGenerator + + + + + + maven-assembly-plugin + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + + diff --git a/codegen/core/src/main/java/org/jclouds/codegen/ec2/model/BaseBean.java b/codegen/core/src/main/java/org/jclouds/codegen/ec2/model/BaseBean.java new file mode 100644 index 0000000000..729a2b478d --- /dev/null +++ b/codegen/core/src/main/java/org/jclouds/codegen/ec2/model/BaseBean.java @@ -0,0 +1,79 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +package org.jclouds.codegen.ec2.model; + +import java.util.Set; + +/** + * + * @author Adrian Cole + */ +public class BaseBean { + + private String type; + private String ancestor; + private Set see; + private String exampleCode; + private Set fields; + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setAncestor(String ancestor) { + this.ancestor = ancestor; + } + + public String getAncestor() { + return ancestor; + } + + public void setSee(Set see) { + this.see = see; + } + + public Set getSee() { + return see; + } + + public void setExampleCode(String exampleCode) { + this.exampleCode = exampleCode; + } + + public String getExampleCode() { + return exampleCode; + } + + public void setFields(Set fields) { + this.fields = fields; + } + + public Set getFields() { + return fields; + } +} diff --git a/codegen/core/src/main/java/org/jclouds/codegen/ec2/model/BeanField.java b/codegen/core/src/main/java/org/jclouds/codegen/ec2/model/BeanField.java new file mode 100644 index 0000000000..1464bc3df7 --- /dev/null +++ b/codegen/core/src/main/java/org/jclouds/codegen/ec2/model/BeanField.java @@ -0,0 +1,116 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +package org.jclouds.codegen.ec2.model; + +import java.util.Map; + +/** + * + * @author Adrian Cole + */ +public class BeanField { + + private String ancestor; + private String children; + private String constraints; + private String defaultValue; + private String desc; + private Map valueMap; + private String name; + private String optional; + private String type; + + public void setAncestor(String ancestor) { + this.ancestor = ancestor; + } + + public String getAncestor() { + return ancestor; + } + + public void setChildren(String children) { + this.children = children; + } + + public String getChildren() { + return children; + } + + public void setConstraints(String constraints) { + this.constraints = constraints; + } + + public String getConstraints() { + return constraints; + } + + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } + + public String getDefaultValue() { + return defaultValue; + } + + public void setDesc(String desc) { + this.desc = desc; + } + + public String getDesc() { + return desc; + } + + public void setValueMap(Map valueMap) { + this.valueMap = valueMap; + } + + public Map getValueMap() { + return valueMap; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setOptional(String optional) { + this.optional = optional; + } + + public String getOptional() { + return optional; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + +} diff --git a/codegen/core/src/main/java/org/jclouds/codegen/model/API.java b/codegen/core/src/main/java/org/jclouds/codegen/model/API.java new file mode 100644 index 0000000000..c69f8a1e3e --- /dev/null +++ b/codegen/core/src/main/java/org/jclouds/codegen/model/API.java @@ -0,0 +1,57 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +package org.jclouds.codegen.model; + +import java.util.List; +import java.util.Map; + +/** + * @author Adrian Cole + * @author James Murty + */ +public class API { + private List packages; + private Map domain; + + @Override + public String toString() { + return getPackages().toString(); + } + + public void setPackages(List packages) { + this.packages = packages; + } + + public List getPackages() { + return packages; + } + + public void setDomain(Map domain) { + this.domain = domain; + } + + public Map getDomain() { + return domain; + } +} diff --git a/codegen/core/src/main/java/org/jclouds/codegen/model/Command.java b/codegen/core/src/main/java/org/jclouds/codegen/model/Command.java new file mode 100644 index 0000000000..fc1d43cc46 --- /dev/null +++ b/codegen/core/src/main/java/org/jclouds/codegen/model/Command.java @@ -0,0 +1,67 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +package org.jclouds.codegen.model; + +/** + * @author Adrian Cole + * @author James Murty + */ +public class Command extends TopLevelType { + private TopLevelType options; + private TopLevelType handler; + private DomainType response; + private String description; + + public void setDescription(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } + + public void setOptions(TopLevelType options) { + this.options = options; + } + + public TopLevelType getOptions() { + return options; + } + + public void setHandler(TopLevelType handler) { + this.handler = handler; + } + + public TopLevelType getHandler() { + return handler; + } + + public void setResponse(DomainType response) { + this.response = response; + } + + public DomainType getResponse() { + return response; + } +} diff --git a/codegen/core/src/main/java/org/jclouds/codegen/model/DomainType.java b/codegen/core/src/main/java/org/jclouds/codegen/model/DomainType.java new file mode 100644 index 0000000000..3186a8a4f4 --- /dev/null +++ b/codegen/core/src/main/java/org/jclouds/codegen/model/DomainType.java @@ -0,0 +1,39 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +package org.jclouds.codegen.model; + + +public class DomainType extends Type { + + private String ancestor; + + public void setAncestor(String ancestor) { + this.ancestor = ancestor; + } + + public String getAncestor() { + return ancestor; + } + +} \ No newline at end of file diff --git a/codegen/core/src/main/java/org/jclouds/codegen/model/Field.java b/codegen/core/src/main/java/org/jclouds/codegen/model/Field.java new file mode 100644 index 0000000000..6f27899aba --- /dev/null +++ b/codegen/core/src/main/java/org/jclouds/codegen/model/Field.java @@ -0,0 +1,116 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +package org.jclouds.codegen.model; + +import java.util.Map; + +/** + * + * @author Adrian Cole + */ +public class Field { + + private String constraints; + private String defaultValue; + private String desc; + private String name; + private String javaName; + private boolean optional = true; + private String type; + private String javaType; + private Map valueMap; + + public void setConstraints(String constraints) { + this.constraints = constraints; + } + + public String getConstraints() { + return constraints; + } + + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } + + public String getDefaultValue() { + return defaultValue; + } + + public void setDesc(String desc) { + this.desc = desc; + } + + public String getDesc() { + return desc; + } + + public void setValueMap(Map valueMap) { + this.valueMap = valueMap; + } + + public Map getValueMap() { + return valueMap; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setOptional(boolean optional) { + this.optional = optional; + } + + public boolean getOptional() { + return optional; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setJavaName(String javaName) { + this.javaName = javaName; + } + + public String getJavaName() { + return javaName; + } + + public void setJavaType(String javaType) { + this.javaType = javaType; + } + + public String getJavaType() { + return javaType; + } + +} diff --git a/codegen/core/src/main/java/org/jclouds/codegen/model/Package.java b/codegen/core/src/main/java/org/jclouds/codegen/model/Package.java new file mode 100644 index 0000000000..142f4b8f6b --- /dev/null +++ b/codegen/core/src/main/java/org/jclouds/codegen/model/Package.java @@ -0,0 +1,49 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +package org.jclouds.codegen.model; + +import java.util.List; + +/** + * + * @author James Murty + */ +public class Package { + private String name; + private List commands; + + @Override + public String toString() { + return String.format("{'name':'%1$s', 'commands':%2$s", name, commands); + } + + public String getName() { + return name; + } + + public List getCommands() { + return commands; + } + +} diff --git a/codegen/core/src/main/java/org/jclouds/codegen/model/TopLevelType.java b/codegen/core/src/main/java/org/jclouds/codegen/model/TopLevelType.java new file mode 100644 index 0000000000..c5f05cbe5c --- /dev/null +++ b/codegen/core/src/main/java/org/jclouds/codegen/model/TopLevelType.java @@ -0,0 +1,57 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +package org.jclouds.codegen.model; + + +public class TopLevelType extends Type { + + private String ancestor; + private String exampleCode; + private String exampleHTML; + + public void setAncestor(String ancestor) { + this.ancestor = ancestor; + } + + public String getAncestor() { + return ancestor; + } + + public void setExampleCode(String exampleCode) { + this.exampleCode = exampleCode; + } + + public String getExampleCode() { + return exampleCode; + } + + public void setExampleHTML(String exampleHTML) { + this.exampleHTML = exampleHTML; + } + + public String getExampleHTML() { + return exampleHTML; + } + +} \ No newline at end of file diff --git a/codegen/core/src/main/java/org/jclouds/codegen/model/Type.java b/codegen/core/src/main/java/org/jclouds/codegen/model/Type.java new file mode 100644 index 0000000000..babc3075cb --- /dev/null +++ b/codegen/core/src/main/java/org/jclouds/codegen/model/Type.java @@ -0,0 +1,74 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2009, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jclouds.codegen.model; + +import java.util.Set; + +public class Type { + + private String packageName; + private String name; + private String javaName; + private Set see; + private Set fields; + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setJavaName(String javaName) { + this.javaName = javaName; + } + + public String getJavaName() { + return javaName; + } + + public void setSee(Set see) { + this.see = see; + } + + public Set getSee() { + return see; + } + + public void setFields(Set fields) { + this.fields = fields; + } + + public Set getFields() { + return fields; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + public String getPackageName() { + return packageName; + } + +} \ No newline at end of file diff --git a/codegen/core/src/main/java/org/jclouds/codegen/util/CodeGenerator.java b/codegen/core/src/main/java/org/jclouds/codegen/util/CodeGenerator.java new file mode 100644 index 0000000000..0d3214d635 --- /dev/null +++ b/codegen/core/src/main/java/org/jclouds/codegen/util/CodeGenerator.java @@ -0,0 +1,196 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +package org.jclouds.codegen.util; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.HashMap; +import java.util.Map; + +import org.jclouds.codegen.model.API; +import org.jclouds.codegen.model.Command; +import org.jclouds.codegen.model.DomainType; +import org.jclouds.codegen.model.Package; +import org.jclouds.codegen.model.Type; + +import com.google.gson.Gson; +import com.google.gson.JsonParseException; + +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; + +/** + * Converts object models representing AWS API beans into Java classes. + *

+ * This implementation is designed to perform the following steps: + *