You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gora.apache.org by le...@apache.org on 2014/06/04 18:36:33 UTC
[16/50] [abbrv] git commit: remove unused classes and old
GoraCompiler, move LicenseHeaders utils class to new GoraCompiler module
remove unused classes and old GoraCompiler, move LicenseHeaders utils class to new GoraCompiler module
git-svn-id: https://svn.apache.org/repos/asf/gora/trunk@1587288 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/1b5b36d3
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/1b5b36d3
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/1b5b36d3
Branch: refs/heads/master
Commit: 1b5b36d3fee0ba23c0ead04e65f34de09295b907
Parents: 136fc59
Author: Lewis John McGibbney <lewismc@apache.org = lewismc = Lewis John McGibbney lewismc@apache.org@apache.org>
Authored: Mon Apr 14 19:17:57 2014 +0000
Committer: Damien Raude-Morvan <da...@dictanova.com>
Committed: Wed Apr 16 00:18:55 2014 +0200
----------------------------------------------------------------------
.../org/apache/gora/compiler/GoraCompiler.java | 3 -
.../gora/compiler/utils/LicenseHeaders.java | 266 +++++++
.../org/apache/gora/compiler/GoraCompiler.java | 701 -------------------
.../gora/persistency/ListGenericArray.java | 0
.../java/org/apache/gora/persistency/State.java | 0
.../apache/gora/persistency/StateManager.java | 0
.../gora/persistency/StatefulHashMap.java | 0
.../apache/gora/persistency/StatefulMap.java | 0
.../gora/persistency/impl/StateManagerImpl.java | 0
.../persistency/ws/impl/StateManagerWSImpl.java | 0
.../org/apache/gora/util/LicenseHeaders.java | 257 -------
.../gora/mock/persistency/MockPersistent.java | 3 +-
.../persistency/impl/TestPersistentBase.java | 2 -
13 files changed, 268 insertions(+), 964 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/1b5b36d3/gora-compiler/src/main/java/org/apache/gora/compiler/GoraCompiler.java
----------------------------------------------------------------------
diff --git a/gora-compiler/src/main/java/org/apache/gora/compiler/GoraCompiler.java b/gora-compiler/src/main/java/org/apache/gora/compiler/GoraCompiler.java
index b4d77c5..84090e4 100644
--- a/gora-compiler/src/main/java/org/apache/gora/compiler/GoraCompiler.java
+++ b/gora-compiler/src/main/java/org/apache/gora/compiler/GoraCompiler.java
@@ -17,14 +17,12 @@
*/
package org.apache.gora.compiler;
-import java.beans.PersistenceDelegate;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -33,7 +31,6 @@ import org.apache.avro.Schema;
import org.apache.avro.Schema.Field;
import org.apache.avro.Schema.Type;
import org.apache.avro.compiler.specific.SpecificCompiler;
-import org.apache.avro.generic.GenericData.StringType;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.node.JsonNodeFactory;
http://git-wip-us.apache.org/repos/asf/gora/blob/1b5b36d3/gora-compiler/src/main/java/org/apache/gora/compiler/utils/LicenseHeaders.java
----------------------------------------------------------------------
diff --git a/gora-compiler/src/main/java/org/apache/gora/compiler/utils/LicenseHeaders.java b/gora-compiler/src/main/java/org/apache/gora/compiler/utils/LicenseHeaders.java
new file mode 100644
index 0000000..ff94220
--- /dev/null
+++ b/gora-compiler/src/main/java/org/apache/gora/compiler/utils/LicenseHeaders.java
@@ -0,0 +1,266 @@
+/**
+ * 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.apache.gora.compiler.utils;
+
+import java.util.HashMap;
+
+/**
+ * Utility class which specifies a collection of license headers which can be
+ * used within the GoraCompiler for generating alternative license headers for
+ * Java interfaces and classes generated from protocols and schemas.
+ */
+public class LicenseHeaders {
+
+ /**
+ * Chosen license to be included within the generated classes
+ */
+ private String licenseName;
+
+ /**
+ * Licenses supported by Gora Compilers
+ */
+ private static final String supportedLicenses[] = {"ASLv2", "AGPLv3", "CDDLv1", "FDLv13", "GPLv1", "GPLv2", "GPLv3", "LGPLv21", "LGPLv3"};
+
+ /**
+ * HashMap containing supported licenses' names and their corresponding text.
+ */
+ private HashMap<String, String> relatedLicenses;
+
+ // ASLv2 license header
+ @SuppressWarnings("unused")
+ private static final String ASLv2 =
+ "/**\n" +
+ " *Licensed to the Apache Software Foundation (ASF) under one\n" +
+ " *or more contributor license agreements. See the NOTICE file\n" +
+ " *distributed with this work for additional information\n" +
+ " *regarding copyright ownership. The ASF licenses this file\n" +
+ " *to you under the Apache License, Version 2.0 (the\"\n" +
+ " *License\"); you may not use this file except in compliance\n" +
+ " *with the License. You may obtain a copy of the License at\n" +
+ " *\n " +
+ " * http://www.apache.org/licenses/LICENSE-2.0\n" +
+ " * \n" +
+ " *Unless required by applicable law or agreed to in writing, software\n" +
+ " *distributed under the License is distributed on an \"AS IS\" BASIS,\n" +
+ " *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
+ " *See the License for the specific language governing permissions and\n" +
+ " *limitations under the License.\n" +
+ " */\n";
+
+ // AGPLv3 license header
+ @SuppressWarnings("unused")
+ private static final String AGPLv3 =
+ "/**\n" +
+ " * This program is free software: you can redistribute it and/or modify\n" +
+ " * it under the terms of the GNU Affero General Public License as published by\n" +
+ " * the Free Software Foundation, either version 3 of the License, or\n" +
+ " * (at your option) any later version.\n" +
+ " *\n " +
+ " * This program is distributed in the hope that it will be useful,\n" +
+ " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
+ " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
+ " * GNU General Public License for more details.\n" +
+ " */\n";
+
+ // CDDLv1 license header
+ @SuppressWarnings("unused")
+ private static final String CDDLv1 =
+ "/**\n" +
+ " * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0\n" +
+ " *\n " +
+ " * This program is free software: you can redistribute it and/or modify\n" +
+ " * it under the terms of the Common Development and Distrubtion License as\n" +
+ " * published by the Sun Microsystems, either version 1.0 of the\n" +
+ " * License, or (at your option) any later version.\n" +
+ " *\n " +
+ " * This program is distributed in the hope that it will be useful,\n" +
+ " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
+ " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
+ " * GNU General Lesser Public License for more details.\n" +
+ " *\n " +
+ " * You should have received a copy of the Common Development and Distrubtion\n" +
+ " * License along with this program. If not, see\n" +
+ " * <http://www.gnu.org/licenses/gpl-1.0.html>.\n" +
+ " */\n";
+
+ // FDLv1.3 license header
+ @SuppressWarnings("unused")
+ private static final String FDLv13 =
+ "/**\n" +
+ " * This program is free software: you can redistribute it and/or modify\n" +
+ " * it under the terms of the GNU Free Documentation License as published by\n" +
+ " * the Free Software Foundation, either version 1.3 of the License, or\n" +
+ " * (at your option) any later version.\n" +
+ " *\n " +
+ " * This program is distributed in the hope that it will be useful,\n" +
+ " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
+ " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
+ " * GNU General Public License for more details.\n" +
+ " *\n " +
+ " * You should have received a copy of the GNU Free Documentation License\n" +
+ " * along with this program. If not, see <http://www.gnu.org/licenses/>.\n" +
+ " */\n";
+
+ // GPLv1 license header
+ @SuppressWarnings("unused")
+ private static final String GPLv1 =
+ "/**\n" +
+ " * This program is free software: you can redistribute it and/or modify\n" +
+ " * it under the terms of the GNU General Public License as\n" +
+ " * published by the Free Software Foundation, either version 1 of the\n" +
+ " * License, or (at your option) any later version.\n" +
+ " *\n " +
+ " * This program is distributed in the hope that it will be useful,\n" +
+ " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
+ " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
+ " * GNU General Public License for more details.\n" +
+ " *\n " +
+ " * You should have received a copy of the GNU General Public\n" +
+ " * License along with this program. If not, see\n" +
+ " * <http://www.gnu.org/licenses/gpl-1.0.html>.\n" +
+ " */\n";
+
+ // GPLv2 license header
+ @SuppressWarnings("unused")
+ private static final String GPLv2 =
+ "/**\n" +
+ " * This program is free software: you can redistribute it and/or modify\n" +
+ " * it under the terms of the GNU General Public License as\n" +
+ " * published by the Free Software Foundation, either version 2 of the\n" +
+ " * License, or (at your option) any later version.\n" +
+ " *\n " +
+ " * This program is distributed in the hope that it will be useful,\n" +
+ " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
+ " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
+ " * GNU General Public License for more details.\n" +
+ " *\n " +
+ " * You should have received a copy of the GNU General Public\n" +
+ " * License along with this program. If not, see\n" +
+ " * <http://www.gnu.org/licenses/gpl-2.0.html>.\n" +
+ " */\n";
+
+ // GPLv3 license header
+ @SuppressWarnings("unused")
+ private static final String GPLv3 =
+ "/**\n" +
+ " * This program is free software: you can redistribute it and/or modify\n" +
+ " * it under the terms of the GNU General Public License as\n" +
+ " * published by the Free Software Foundation, either version 3 of the\n" +
+ " * License, or (at your option) any later version.\n" +
+ " *\n " +
+ " * This program is distributed in the hope that it will be useful,\n" +
+ " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
+ " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
+ " * GNU General Public License for more details.\n" +
+ " *\n " +
+ " * You should have received a copy of the GNU General Public\n" +
+ " * License along with this program. If not, see\n" +
+ " * <http://www.gnu.org/licenses/gpl-3.0.html>.\n" +
+ " */\n";
+
+ // LGPLv21 license header
+ @SuppressWarnings("unused")
+ private static final String LGPLv21 =
+ "/**\n" +
+ " * This program is free software: you can redistribute it and/or modify\n" +
+ " * it under the terms of the GNU Lesser General Public License as\n" +
+ " * published by the Free Software Foundation, either version 2.1 of the\n" +
+ " * License, or (at your option) any later version.\n" +
+ " *\n " +
+ " * This program is distributed in the hope that it will be useful,\n" +
+ " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
+ " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
+ " * GNU General Public License for more details.\n" +
+ " *\n " +
+ " * You should have received a copy of the GNU Lesser General Public\n" +
+ " * License along with this program. If not, see\n" +
+ " * <http://www.gnu.org/licenses/lgpl-2.1.html>.\n" +
+ " */\n";
+
+ // LGPLv3 license header
+ @SuppressWarnings("unused")
+ private static final String LGPLv3 =
+ "/**\n" +
+ " * This program is free software: you can redistribute it and/or modify\n" +
+ " * it under the terms of the GNU Lesser General Public License as\n" +
+ " * published by the Free Software Foundation, either version 3 of the\n" +
+ " * License, or (at your option) any later version.\n" +
+ " *\n " +
+ " * This program is distributed in the hope that it will be useful,\n" +
+ " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
+ " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
+ " * GNU General Public License for more details.\n" +
+ " *\n " +
+ " * You should have received a copy of the GNU Lesser General Public\n" +
+ " * License along with this program. If not, see\n" +
+ " * <http://www.gnu.org/licenses/lgpl-3.0.html>.\n" +
+ " */\n";
+
+ /**
+ * @param license
+ */
+ public LicenseHeaders(String pLicenseName) {
+ this.initializeRelations();
+ this.setLicenseName(pLicenseName);
+ }
+
+ /**
+ * Initializes relations between supported licenses and license text
+ */
+ public void initializeRelations(){
+ relatedLicenses = new HashMap<String, String>();
+ try {
+ for (String licenseValue : supportedLicenses) {
+ String var = (String) this.getClass().getDeclaredField(licenseValue).get(licenseValue);
+ relatedLicenses.put(licenseValue,var);
+ }
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (NoSuchFieldException e) {
+ e.printStackTrace();
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ *Set the license header for the LicenseHeader object.
+ *
+ */
+ public void setLicenseName(String pLicenseName) {
+ this.licenseName = pLicenseName;
+ }
+
+ /**
+ * Get the license header for the LicenseHeader object.
+ * @return
+ */
+ public String getLicense() {
+ return relatedLicenses.get(licenseName)!=null?relatedLicenses.get(licenseName):"";
+ }
+
+ /**
+ * Get the license name for the LicenseHeader object.
+ * @return
+ */
+ public String getLicenseName(){
+ return licenseName;
+ }
+}
http://git-wip-us.apache.org/repos/asf/gora/blob/1b5b36d3/gora-core/src/main/java/org/apache/gora/compiler/GoraCompiler.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/compiler/GoraCompiler.java b/gora-core/src/main/java/org/apache/gora/compiler/GoraCompiler.java
deleted file mode 100644
index e832e1d..0000000
--- a/gora-core/src/main/java/org/apache/gora/compiler/GoraCompiler.java
+++ /dev/null
@@ -1,701 +0,0 @@
-/**
- * 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.apache.gora.compiler;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Arrays;
-
-import org.apache.avro.Protocol;
-import org.apache.avro.Schema;
-import org.apache.avro.Protocol.Message;
-import org.apache.avro.Schema.Field;
-import org.apache.avro.specific.SpecificData;
-import org.apache.gora.util.LicenseHeaders;
-import org.apache.gora.util.TimingUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/** Generate specific Java interfaces and classes for protocols and schemas.
- * GoraCompiler takes its inspiration from, and is largely based on Avro's {@link SpecificCompiler}.
- */
-public class GoraCompiler {
- private File dest;
- private Writer out;
- private Set<Schema> queue = new HashSet<Schema>();
- private static final Logger log = LoggerFactory.getLogger(GoraCompiler.class);
- private static LicenseHeaders licenseHeader = new LicenseHeaders(null);
- private final static String DEFAULT_SCHEMA_EXTENTION = ".avsc";
-
- private GoraCompiler(File dest) {
- this.dest = dest; // root directory for output
- }
-
- /** Generates Java interface and classes for a protocol.
- * @param src the source Avro protocol file
- * @param dest the directory to place generated files in
- */
- public static void compileProtocol(File src, File dest) throws IOException {
- log.info("Compiling Protocol: " + src + " to: " + dest);
- if(licenseHeader != null) {
- log.info("The generated file will be " + licenseHeader.getLicenseName() + " licensed.");
- }
- GoraCompiler compiler = new GoraCompiler(dest);
- Protocol protocol = Protocol.parse(src);
- for (Schema s : protocol.getTypes()) // enqueue types
- compiler.enqueue(s);
- compiler.compileInterface(protocol); // generate interface
- compiler.compile(); // generate classes for types
- }
-
- /** Generates Java classes for a schema. */
- public static void compileSchema(File src, File dest) throws IOException {
- log.info("Compiling Schema: " + src + " to: " + dest);
- if(licenseHeader != null) {
- log.info("The generated artifact will be " + licenseHeader.getLicenseName() + " licensed.");
- }
- GoraCompiler compiler = new GoraCompiler(dest);
- compiler.enqueue(Schema.parse(src)); // enqueue types
- compiler.compile(); // generate classes for types
- }
-
- /** Generates Java classes for a number of schema files. */
- public static void compileSchema(File[] srcFiles, File dest) throws IOException {
- if(licenseHeader != null) {
- log.info("The generated artifact will be " + licenseHeader.getLicenseName() + " licensed.");
- }
- for (File src : srcFiles) {
- log.info("Compiling Schema: " + src + " to: " + dest);
- GoraCompiler compiler = new GoraCompiler(dest);
- compiler.enqueue(Schema.parse(src)); // enqueue types
- compiler.compile(); // generate classes for types
- }
- }
-
- private static String camelCasify(String s) {
- return s.substring(0, 1).toUpperCase() + s.substring(1);
- }
-
- /** Recognizes camel case */
- private static String toUpperCase(String s) {
- StringBuilder builder = new StringBuilder();
-
- for(int i=0; i<s.length(); i++) {
- if(i > 0) {
- if(Character.isUpperCase(s.charAt(i))
- && Character.isLowerCase(s.charAt(i-1))
- && Character.isLetter(s.charAt(i))) {
- builder.append("_");
- }
- }
- builder.append(Character.toUpperCase(s.charAt(i)));
- }
-
- return builder.toString();
- }
-
- /** Recursively enqueue schemas that need a class generated. */
- private void enqueue(Schema schema) throws IOException {
- if (queue.contains(schema)) return;
- switch (schema.getType()) {
- case RECORD:
- queue.add(schema);
- for (Field field : schema.getFields())
- enqueue(field.schema());
- break;
- case MAP:
- enqueue(schema.getValueType());
- break;
- case ARRAY:
- enqueue(schema.getElementType());
- break;
- case UNION:
- for (Schema s : schema.getTypes())
- enqueue(s);
- break;
- case ENUM:
- case FIXED:
- queue.add(schema);
- break;
- case STRING: case BYTES:
- case INT: case LONG:
- case FLOAT: case DOUBLE:
- case BOOLEAN: case NULL:
- break;
- default: throw new RuntimeException("Unknown type: "+schema);
- }
- }
-
- /** Generate java classes for enqueued schemas. */
- private void compile() throws IOException {
- for (Schema schema : queue)
- compile(schema);
- }
-
- private void compileInterface(Protocol protocol) throws IOException {
- startFile(protocol.getName(), protocol.getNamespace());
- try {
- line(0, "public interface "+protocol.getName()+" {");
-
- out.append("\n");
- for (Map.Entry<String,Message> e : protocol.getMessages().entrySet()) {
- String name = e.getKey();
- Message message = e.getValue();
- Schema request = message.getRequest();
- Schema response = message.getResponse();
- line(1, unbox(response)+" "+name+"("+params(request)+")");
- line(2,"throws AvroRemoteException"+errors(message.getErrors())+";");
- }
- line(0, "}");
- } finally {
- out.close();
- }
- }
-
- private void startFile(String name, String space) throws IOException {
- File dir = new File(dest, space.replace('.', File.separatorChar));
- if (!dir.exists())
- if (!dir.mkdirs())
- throw new IOException("Unable to create " + dir);
- name = cap(name) + ".java";
- out = new OutputStreamWriter(new FileOutputStream(new File(dir, name)));
- header(space);
- }
-
- private void header(String namespace) throws IOException {
- if (licenseHeader != null) {
- line(0, licenseHeader.getLicense());
- }
- if(namespace != null) {
- line(0, "package "+namespace+";\n");
- }
- line(0, "import java.nio.ByteBuffer;");
- line(0, "import java.util.Map;");
- line(0, "import java.util.HashMap;");
- line(0, "import org.apache.avro.Protocol;");
- line(0, "import org.apache.avro.Schema;");
- line(0, "import org.apache.avro.AvroRuntimeException;");
- line(0, "import org.apache.avro.Protocol;");
- line(0, "import org.apache.avro.util.Utf8;");
- line(0, "import org.apache.avro.ipc.AvroRemoteException;");
- line(0, "import org.apache.avro.generic.GenericArray;");
- line(0, "import org.apache.avro.specific.FixedSize;");
- line(0, "import org.apache.avro.specific.SpecificExceptionBase;");
- line(0, "import org.apache.avro.specific.SpecificRecordBase;");
- line(0, "import org.apache.avro.specific.SpecificRecord;");
- line(0, "import org.apache.avro.specific.SpecificFixed;");
- line(0, "import org.apache.gora.persistency.StateManager;");
- line(0, "import org.apache.gora.persistency.impl.PersistentBase;");
- line(0, "import org.apache.gora.persistency.impl.StateManagerImpl;");
- line(0, "import org.apache.gora.persistency.StatefulHashMap;");
- line(0, "import org.apache.gora.persistency.ListGenericArray;");
- for (Schema s : queue)
- if (namespace == null
- ? (s.getNamespace() != null)
- : !namespace.equals(s.getNamespace()))
- line(0, "import "+SpecificData.get().getClassName(s)+";");
- }
-
- private String params(Schema request) throws IOException {
- StringBuilder b = new StringBuilder();
- int count = 0;
- for (Field field : request.getFields()) {
- b.append(unbox(field.schema()));
- b.append(" ");
- b.append(field.name());
- if (++count < request.getFields().size())
- b.append(", ");
- }
- return b.toString();
- }
-
- /**
- * Method that adds javadoc to the generated data beans.
- * @param indent Specifies the indentation for the javadoc
- * @param javadoc The javadoc to be added. Use \n to span the javadoc
- * to multiple lines.
- * @throws IOException
- */
- private void addJavaDoc(int indent, String javadoc) throws IOException {
-
- if (javadoc==null)
- return;
-
- if (indent<0)
- return;
-
- line(indent, "");
- line(indent, "/**");
-
- if (javadoc.contains("\n")){
- String javadocLines[] = javadoc.split("\n");
-
- for(String line : javadocLines)
- line(indent, " * "+line);
- }
- else
- line(indent," * "+javadoc);
-
- line(indent, " */");
- }
-
- private String errors(Schema errs) throws IOException {
- StringBuilder b = new StringBuilder();
- for (Schema error : errs.getTypes().subList(1, errs.getTypes().size())) {
- b.append(", ");
- b.append(error.getName());
- }
- return b.toString();
- }
-
- private void compile(Schema schema) throws IOException {
- startFile(schema.getName(), schema.getNamespace());
- try {
- switch (schema.getType()) {
- case RECORD:
- addJavaDoc(0,schema.getDoc());
- line(0, "@SuppressWarnings(\"all\")");
- String type = type(schema);
- line(0, "public class "+ type
- +" extends PersistentBase {");
-
- // schema definition
- addJavaDoc(1,"Variable holding the data bean schema.");
- line(1, "public static final Schema _SCHEMA = Schema.parse(\""
- +esc(schema)+"\");");
-
- //field information
- addJavaDoc(1,"Enum containing all data bean's fields.");
- line(1, "public static enum Field {");
- int i=0;
- for (Field field : schema.getFields()) {
- line(2,toUpperCase(field.name())+"("+(i++)+ ",\"" + field.name() + "\"),");
- }
- line(2, ";");
-
- addJavaDoc(2,"Field's index.");
- line(2, "private int index;");
-
- addJavaDoc(2,"Field's name.");
- line(2, "private String name;");
-
- addJavaDoc(2,"Field's constructor\n"+
- "@param index field's index.\n"+
- "@param name field's name.");
- line(2, "Field(int index, String name) {this.index=index;this.name=name;}");
-
- addJavaDoc(2,"Gets field's index.\n"+
- "@return int field's index.");
- line(2, "public int getIndex() {return index;}");
-
- addJavaDoc(2,"Gets field's name.\n"+
- "@return String field's name.");
- line(2, "public String getName() {return name;}");
-
- addJavaDoc(2,"Gets field's attributes to string.\n"+
- "@return String field's attributes to string.");
- line(2, "public String toString() {return name;}");
- line(1, "};");
-
- addJavaDoc(2,"Contains all field's names.");
- StringBuilder builder = new StringBuilder(
- "public static final String[] _ALL_FIELDS = {");
- for (Field field : schema.getFields()) {
- builder.append("\"").append(field.name()).append("\",");
- }
- builder.append("};");
- line(1, builder.toString());
-
- line(1, "static {");
- line(2, "PersistentBase.registerFields("+type+".class, _ALL_FIELDS);");
- line(1, "}");
-
- // field declations
- for (Field field : schema.getFields()) {
- addJavaDoc(1,field.doc());
- line(1,"private "+unbox(field.schema())+" "+field.name()+";");
- }
-
- //constructors
- addJavaDoc(1,"Default Constructor");
- line(1, "public " + type + "() {");
- line(2, "this(new StateManagerImpl());");
- line(1, "}");
-
- addJavaDoc(1,"Constructor\n@param stateManager for the data bean.");
- line(1, "public " + type + "(StateManager stateManager) {");
- line(2, "super(stateManager);");
- for (Field field : schema.getFields()) {
- Schema fieldSchema = field.schema();
- switch (fieldSchema.getType()) {
- case ARRAY:
- String valueType = type(fieldSchema.getElementType());
- line(2, field.name()+" = new ListGenericArray<"+valueType+">(getSchema()" +
- ".getField(\""+field.name()+"\").schema());");
- break;
- case MAP:
- valueType = type(fieldSchema.getValueType());
- line(2, field.name()+" = new StatefulHashMap<Utf8,"+valueType+">();");
- }
- }
- line(1, "}");
-
- //newInstance(StateManager)
- addJavaDoc(1,"Returns a new instance by using a state manager.\n"+
- "@param stateManager for the data bean.\n"+
- "@return "+schema.getName()+" created.");
- line(1, "public " + type + " newInstance(StateManager stateManager) {");
- line(2, "return new " + type + "(stateManager);" );
- line(1, "}");
-
- // schema method
- addJavaDoc(1,"Returns the schema of the data bean.\n"+
- "@return Schema for the data bean.");
- line(1, "public Schema getSchema() { return _SCHEMA; }");
-
- // get method
- addJavaDoc(1,"Gets a specific field.\n"+
- "@param field index of a field for the data bean.\n"+
- "@return Object representing a data bean's field.");
- line(1, "public Object get(int _field) {");
- line(2, "switch (_field) {");
- i = 0;
- for (Field field : schema.getFields()) {
- line(2, "case "+(i++)+": return "+field.name()+";");
- }
- line(2, "default: throw new AvroRuntimeException(\"Bad index\");");
- line(2, "}");
- line(1, "}");
-
- // put method
- addJavaDoc(1,"Puts a value for a specific field.\n"+
- "@param field index of a field for the data bean.\n"+
- "@param value value of a field for the data bean.");
- line(1, "@SuppressWarnings(value=\"unchecked\")");
- line(1, "public void put(int _field, Object _value) {");
- line(2, "if(isFieldEqual(_field, _value)) return;");
- line(2, "getStateManager().setDirty(this, _field);");
- line(2, "switch (_field) {");
- i = 0;
- for (Field field : schema.getFields()) {
- line(2, "case "+i+":"+field.name()+" = ("+
- type(field.schema())+")_value; break;");
- i++;
- }
- line(2, "default: throw new AvroRuntimeException(\"Bad index\");");
- line(2, "}");
- line(1, "}");
-
- // java bean style getters and setters
- i = 0;
- for (Field field : schema.getFields()) {
- String camelKey = camelCasify(field.name());
- Schema fieldSchema = field.schema();
- switch (fieldSchema.getType()) {
- case INT:case LONG:case FLOAT:case DOUBLE:
- case BOOLEAN:case BYTES:case STRING: case ENUM: case RECORD:
- case FIXED:
- String unboxed = unbox(fieldSchema);
- String fieldType = type(fieldSchema);
- addJavaDoc(1,"Gets the "+camelKey+".\n"+
- "@return "+unboxed+" representing "+schema.getName()+" "+camelKey+".");
- line(1, "public "+unboxed+" get" +camelKey+"() {");
- line(2, "return ("+fieldType+") get("+i+");");
- line(1, "}");
-
- addJavaDoc(1,"Sets the "+camelKey+".\n"+
- "@param value containing "+schema.getName()+" "+camelKey+".");
- line(1, "public void set"+camelKey+"("+unboxed+" value) {");
- line(2, "put("+i+", value);");
- line(1, "}");
- break;
- case ARRAY:
- unboxed = unbox(fieldSchema.getElementType());
- fieldType = type(fieldSchema.getElementType());
-
- addJavaDoc(1,"Gets the "+camelKey+" array.\n"+
- "@return GenericArray<"+fieldType+"> containing "+fieldType+" elements.");
- line(1, "public GenericArray<"+fieldType+"> get"+camelKey+"() {");
- line(2, "return (GenericArray<"+fieldType+">) get("+i+");");
- line(1, "}");
-
- addJavaDoc(1,"Adds a "+unboxed+" element into the array.\n"+
- "@param the "+unboxed+" element to be added.");
- line(1, "public void addTo"+camelKey+"("+unboxed+" element) {");
- line(2, "getStateManager().setDirty(this, "+i+");");
- line(2, field.name()+".add(element);");
- line(1, "}");
- break;
- case MAP:
- unboxed = unbox(fieldSchema.getValueType());
- fieldType = type(fieldSchema.getValueType());
-
- addJavaDoc(1,"Gets "+camelKey+".\n"+
- "@return Map containing "+camelKey+" value.");
- line(1, "public Map<Utf8, "+fieldType+"> get"+camelKey+"() {");
- line(2, "return (Map<Utf8, "+fieldType+">) get("+i+");");
- line(1, "}");
-
- addJavaDoc(1,"Gets the "+camelKey+"'s value using a key.\n"+
- "@param key gets a specific "+camelKey+" using a "+schema.getName()+"ID.\n"+
- "@return "+fieldType+" containing "+camelKey+" value.");
- line(1, "public "+fieldType+" getFrom"+camelKey+"(Utf8 key) {");
- line(2, "if ("+field.name()+" == null) { return null; }");
- line(2, "return "+field.name()+".get(key);");
- line(1, "}");
-
- addJavaDoc(1,"Adds a "+camelKey+" into a "+schema.getName()+".\n"+
- "@param Map containing "+camelKey+" value.");
- line(1, "public void putTo"+camelKey+"(Utf8 key, "+unboxed+" value) {");
- line(2, "getStateManager().setDirty(this, "+i+");");
- line(2, field.name()+".put(key, value);");
- line(1, "}");
-
- addJavaDoc(1,"Removes "+camelKey+" from a "+schema.getName()+".\n"+
- "@return key "+schema.getName()+" ID to be removed.");
- line(1, "public "+fieldType+" removeFrom"+camelKey+"(Utf8 key) {");
- line(2, "if ("+field.name()+" == null) { return null; }");
- line(2, "getStateManager().setDirty(this, "+i+");");
- line(2, "return "+field.name()+".remove(key);");
- line(1, "}");
- break;
- case UNION:
- fieldType = type(fieldSchema);
-
- //Create get method: public <unbox(field.schema())> get<camelKey>()
- addJavaDoc(1,"Gets "+camelKey+".\n"+
- "@return the "+unbox(field.schema())+" value.");
- line(1, "public "+unbox(field.schema())+" get" +camelKey+"() {");
- line(2, "return ("+unbox(field.schema())+") get("+i+");");
- line(1, "}");
-
- //Create set methods: public void set<camelKey>(<subschema.fieldType> value)
- for (Schema s : fieldSchema.getTypes()) {
- if (s.getType().equals(Schema.Type.NULL)) continue ;
- String unionFieldType = type(s);
-
- addJavaDoc(1,"Sets the "+camelKey+".\n"+
- "@param the "+camelKey+" value to be set.");
- line(1, "public void set"+camelKey+"("+unionFieldType+" value) {");
- line(2, "put("+i+", value);");
- line(1, "}");
- }
- break;
- case NULL:
- throw new RuntimeException("Unexpected NULL field: "+field);
- default:
- throw new RuntimeException("Unknown field: "+field);
- }
- i++;
- }
- line(0, "}");
-
- break;
- case ENUM:
- line(0, "public enum "+type(schema)+" { ");
- StringBuilder b = new StringBuilder();
- int count = 0;
- for (String symbol : schema.getEnumSymbols()) {
- b.append(symbol);
- if (++count < schema.getEnumSymbols().size())
- b.append(", ");
- }
- line(1, b.toString());
- line(0, "}");
- break;
- case FIXED:
- line(0, "@FixedSize("+schema.getFixedSize()+")");
- line(0, "public class "+type(schema)+" extends SpecificFixed {}");
- break;
- case MAP: case ARRAY: case UNION: case STRING: case BYTES:
- case INT: case LONG: case FLOAT: case DOUBLE: case BOOLEAN: case NULL:
- break;
- default: throw new RuntimeException("Unknown type: "+schema);
- }
- } finally {
- out.close();
- }
- }
-
- private static final Schema NULL_SCHEMA = Schema.create(Schema.Type.NULL);
-
- public static String type(Schema schema) {
- switch (schema.getType()) {
- case RECORD:
- case ENUM:
- case FIXED:
- return schema.getName();
- case ARRAY:
- return "GenericArray<"+type(schema.getElementType())+">";
- case MAP:
- return "Map<Utf8,"+type(schema.getValueType())+">";
- case UNION:
- List<Schema> types = schema.getTypes(); // elide unions with null
- if ((types.size() == 2) && types.contains(NULL_SCHEMA))
- return type(types.get(types.get(0).equals(NULL_SCHEMA) ? 1 : 0));
- return "Object";
- case STRING: return "Utf8";
- case BYTES: return "ByteBuffer";
- case INT: return "Integer";
- case LONG: return "Long";
- case FLOAT: return "Float";
- case DOUBLE: return "Double";
- case BOOLEAN: return "Boolean";
- case NULL: return "Void";
- default: throw new RuntimeException("Unknown type: "+schema);
- }
- }
-
- public static String unbox(Schema schema) {
- switch (schema.getType()) {
- case INT: return "int";
- case LONG: return "long";
- case FLOAT: return "float";
- case DOUBLE: return "double";
- case BOOLEAN: return "boolean";
- default: return type(schema);
- }
- }
-
- private void line(int indent, String text) throws IOException {
- for (int i = 0; i < indent; i ++) {
- out.append(" ");
- }
- out.append(text);
- out.append("\n");
- }
-
- static String cap(String name) {
- return name.substring(0,1).toUpperCase()+name.substring(1,name.length());
- }
-
- private static String esc(Object o) {
- return o.toString().replace("\"", "\\\"");
- }
-
- /**
- * The main method used to invoke the GoraCompiler. It accepts an input (JSON) avsc
- * schema file, the target output directory and an optional parameter defining the
- * license header to be used when compiling the avsc into the generated class.
- * If no license is explicitely defined, an ASFv2.0 license header is attributed
- * to all generated files by default.
- */
- public static void main(String[] args) throws Exception {
- if (args.length < 2) {
- System.err.println("Usage: GoraCompiler <schema file> <output dir> [-license <id>]");
- System.err.println(" <schema file> - individual avsc file to be compiled or a directory path containing avsc files");
- System.err.println(" <output dir> - output directory for generated Java files");
- System.err.println(" [-license <id>] - the preferred license header to add to the\n" +
- "\t\t generated Java file. Current options include; \n" +
- "\t\t ASLv2 (Apache Software License v2.0) \n" +
- "\t\t AGPLv3 (GNU Affero General Public License)\n" +
- "\t\t CDDLv1 (Common Development and Distribution License v1.0)\n" +
- "\t\t FDLv13 (GNU Free Documentation License v1.3)\n" +
- "\t\t GPLv1 (GNU General Public License v1.0)\n" +
- "\t\t GPLv2 (GNU General Public License v2.0)\n" +
- "\t\t GPLv3 (GNU General Public License v3.0)\n " +
- "\t\t LGPLv21 (GNU Lesser General Public License v2.1)\n" +
- "\t\t LGPLv3 (GNU Lesser General Public License v3)\n") ;
- System.exit(1);
- }
-
- SimpleDateFormat sdf;
- File inputFile;
- File output;
- long start;
-
- for (int i = 1; i < args.length; i++) {
- licenseHeader.setLicenseName("ASLv2");
- if ("-license".equals(args[i])) {
- licenseHeader.setLicenseName(args[++i]);
- }
- }
-
- if (args.length==2){ //case of single file or single directory
- inputFile = new File(args[0]);
- output = new File(args[1]);
-
- if(!inputFile.exists() || !output.exists()){
- log.error("input file path or output file path doesn't exist.");
- System.exit(1);
- }
-
- sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- start = System.currentTimeMillis();
- log.info("GoraCompiler: starting at " + sdf.format(start));
- if(inputFile.isDirectory()) {
- ArrayList<File> inputSchemas = new ArrayList<File>();
- File[] listOfFiles= inputFile.listFiles();
-
- if ( (listOfFiles!=null) && (listOfFiles.length>0)){
- for (File file : listOfFiles) {
- if (file.isFile() && file.exists() && file.getName().endsWith(DEFAULT_SCHEMA_EXTENTION)) {
- inputSchemas.add(file);
- }
- }
-
- compileSchema(inputSchemas.toArray(new File[inputSchemas.size()]), output);
- }
- else{
- log.info("Path contains no files. Nothing to compile.");
- }
- }
- else if (inputFile.isFile()) {
- compileSchema(inputFile, output);
- }
- }
- else{ //case of dynamic filename extension (such as *.* or *.json)
- List<String> files = new ArrayList<String>(Arrays.asList(args));
- output = new File(files.get(files.size()-1));
- files.remove(files.size()-1); //remove the last one, as this is the output directory
-
- if(!output.exists()){
- log.error("output path doesn't exist");
- System.exit(1);
- }
-
- sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- start = System.currentTimeMillis();
- log.info("GoraCompiler: starting at " + sdf.format(start));
-
- for(String filename : files){ //loop for all the retrieved files
- inputFile = new File(filename);
- if(!inputFile.exists()){
- log.error("input file: "+filename+" doesn't exist.");
- continue; //in case the file does not exist, continue to the next file
- }
-
- compileSchema(inputFile, output);
- }
- }
-
- long end = System.currentTimeMillis();
- log.info("GoraCompiler: finished at " + sdf.format(end) + ", elapsed: " + TimingUtil.elapsedTime(start, end));
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/gora/blob/1b5b36d3/gora-core/src/main/java/org/apache/gora/persistency/ListGenericArray.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/persistency/ListGenericArray.java b/gora-core/src/main/java/org/apache/gora/persistency/ListGenericArray.java
deleted file mode 100644
index e69de29..0000000
http://git-wip-us.apache.org/repos/asf/gora/blob/1b5b36d3/gora-core/src/main/java/org/apache/gora/persistency/State.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/persistency/State.java b/gora-core/src/main/java/org/apache/gora/persistency/State.java
deleted file mode 100644
index e69de29..0000000
http://git-wip-us.apache.org/repos/asf/gora/blob/1b5b36d3/gora-core/src/main/java/org/apache/gora/persistency/StateManager.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/persistency/StateManager.java b/gora-core/src/main/java/org/apache/gora/persistency/StateManager.java
deleted file mode 100644
index e69de29..0000000
http://git-wip-us.apache.org/repos/asf/gora/blob/1b5b36d3/gora-core/src/main/java/org/apache/gora/persistency/StatefulHashMap.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/persistency/StatefulHashMap.java b/gora-core/src/main/java/org/apache/gora/persistency/StatefulHashMap.java
deleted file mode 100644
index e69de29..0000000
http://git-wip-us.apache.org/repos/asf/gora/blob/1b5b36d3/gora-core/src/main/java/org/apache/gora/persistency/StatefulMap.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/persistency/StatefulMap.java b/gora-core/src/main/java/org/apache/gora/persistency/StatefulMap.java
deleted file mode 100644
index e69de29..0000000
http://git-wip-us.apache.org/repos/asf/gora/blob/1b5b36d3/gora-core/src/main/java/org/apache/gora/persistency/impl/StateManagerImpl.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/persistency/impl/StateManagerImpl.java b/gora-core/src/main/java/org/apache/gora/persistency/impl/StateManagerImpl.java
deleted file mode 100644
index e69de29..0000000
http://git-wip-us.apache.org/repos/asf/gora/blob/1b5b36d3/gora-core/src/main/java/org/apache/gora/persistency/ws/impl/StateManagerWSImpl.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/persistency/ws/impl/StateManagerWSImpl.java b/gora-core/src/main/java/org/apache/gora/persistency/ws/impl/StateManagerWSImpl.java
deleted file mode 100644
index e69de29..0000000
http://git-wip-us.apache.org/repos/asf/gora/blob/1b5b36d3/gora-core/src/main/java/org/apache/gora/util/LicenseHeaders.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/util/LicenseHeaders.java b/gora-core/src/main/java/org/apache/gora/util/LicenseHeaders.java
deleted file mode 100644
index 800691d..0000000
--- a/gora-core/src/main/java/org/apache/gora/util/LicenseHeaders.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/**
- * 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.apache.gora.util;
-
-import java.util.HashMap;
-
-/**
- * Utility class which specifies a collection of license headers which can be
- * used within the GoraCompiler for generating alternative license headers for
- * Java interfaces and classes generated from protocols and schemas.
- */
-public class LicenseHeaders {
-
- /**
- * Chosen license to be included within the generated classes
- */
- private String licenseName;
-
- /**
- * Licenses supported by Gora Compilers
- */
- private static final String supportedLicenses[] = {"ASLv2", "AGPLv3", "CDDLv1", "FDLv13", "GPLv1", "GPLv2", "GPLv3", "LGPLv21", "LGPLv3"};
-
- /**
- * HashMap containing supported licenses' names and their corresponding text.
- */
- private HashMap<String, String> relatedLicenses;
-
- // ASLv2 license header
- private static final String ASLv2 =
- "/**\n" +
- " *Licensed to the Apache Software Foundation (ASF) under one\n" +
- " *or more contributor license agreements. See the NOTICE file\n" +
- " *distributed with this work for additional information\n" +
- " *regarding copyright ownership. The ASF licenses this file\n" +
- " *to you under the Apache License, Version 2.0 (the\"\n" +
- " *License\"); you may not use this file except in compliance\n" +
- " *with the License. You may obtain a copy of the License at\n" +
- " *\n " +
- " * http://www.apache.org/licenses/LICENSE-2.0\n" +
- " * \n" +
- " *Unless required by applicable law or agreed to in writing, software\n" +
- " *distributed under the License is distributed on an \"AS IS\" BASIS,\n" +
- " *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
- " *See the License for the specific language governing permissions and\n" +
- " *limitations under the License.\n" +
- " */\n";
-
- // AGPLv3 license header
- private static final String AGPLv3 =
- "/**\n" +
- " * This program is free software: you can redistribute it and/or modify\n" +
- " * it under the terms of the GNU Affero General Public License as published by\n" +
- " * the Free Software Foundation, either version 3 of the License, or\n" +
- " * (at your option) any later version.\n" +
- " *\n " +
- " * This program is distributed in the hope that it will be useful,\n" +
- " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
- " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
- " * GNU General Public License for more details.\n" +
- " */\n";
-
- // CDDLv1 license header
- private static final String CDDLv1 =
- "/**\n" +
- " * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0\n" +
- " *\n " +
- " * This program is free software: you can redistribute it and/or modify\n" +
- " * it under the terms of the Common Development and Distrubtion License as\n" +
- " * published by the Sun Microsystems, either version 1.0 of the\n" +
- " * License, or (at your option) any later version.\n" +
- " *\n " +
- " * This program is distributed in the hope that it will be useful,\n" +
- " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
- " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
- " * GNU General Lesser Public License for more details.\n" +
- " *\n " +
- " * You should have received a copy of the Common Development and Distrubtion\n" +
- " * License along with this program. If not, see\n" +
- " * <http://www.gnu.org/licenses/gpl-1.0.html>.\n" +
- " */\n";
-
- // FDLv1.3 license header
- private static final String FDLv13 =
- "/**\n" +
- " * This program is free software: you can redistribute it and/or modify\n" +
- " * it under the terms of the GNU Free Documentation License as published by\n" +
- " * the Free Software Foundation, either version 1.3 of the License, or\n" +
- " * (at your option) any later version.\n" +
- " *\n " +
- " * This program is distributed in the hope that it will be useful,\n" +
- " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
- " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
- " * GNU General Public License for more details.\n" +
- " *\n " +
- " * You should have received a copy of the GNU Free Documentation License\n" +
- " * along with this program. If not, see <http://www.gnu.org/licenses/>.\n" +
- " */\n";
-
- // GPLv1 license header
- private static final String GPLv1 =
- "/**\n" +
- " * This program is free software: you can redistribute it and/or modify\n" +
- " * it under the terms of the GNU General Public License as\n" +
- " * published by the Free Software Foundation, either version 1 of the\n" +
- " * License, or (at your option) any later version.\n" +
- " *\n " +
- " * This program is distributed in the hope that it will be useful,\n" +
- " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
- " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
- " * GNU General Public License for more details.\n" +
- " *\n " +
- " * You should have received a copy of the GNU General Public\n" +
- " * License along with this program. If not, see\n" +
- " * <http://www.gnu.org/licenses/gpl-1.0.html>.\n" +
- " */\n";
-
- // GPLv2 license header
- private static final String GPLv2 =
- "/**\n" +
- " * This program is free software: you can redistribute it and/or modify\n" +
- " * it under the terms of the GNU General Public License as\n" +
- " * published by the Free Software Foundation, either version 2 of the\n" +
- " * License, or (at your option) any later version.\n" +
- " *\n " +
- " * This program is distributed in the hope that it will be useful,\n" +
- " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
- " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
- " * GNU General Public License for more details.\n" +
- " *\n " +
- " * You should have received a copy of the GNU General Public\n" +
- " * License along with this program. If not, see\n" +
- " * <http://www.gnu.org/licenses/gpl-2.0.html>.\n" +
- " */\n";
-
- // GPLv3 license header
- private static final String GPLv3 =
- "/**\n" +
- " * This program is free software: you can redistribute it and/or modify\n" +
- " * it under the terms of the GNU General Public License as\n" +
- " * published by the Free Software Foundation, either version 3 of the\n" +
- " * License, or (at your option) any later version.\n" +
- " *\n " +
- " * This program is distributed in the hope that it will be useful,\n" +
- " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
- " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
- " * GNU General Public License for more details.\n" +
- " *\n " +
- " * You should have received a copy of the GNU General Public\n" +
- " * License along with this program. If not, see\n" +
- " * <http://www.gnu.org/licenses/gpl-3.0.html>.\n" +
- " */\n";
-
- // LGPLv21 license header
- private static final String LGPLv21 =
- "/**\n" +
- " * This program is free software: you can redistribute it and/or modify\n" +
- " * it under the terms of the GNU Lesser General Public License as\n" +
- " * published by the Free Software Foundation, either version 2.1 of the\n" +
- " * License, or (at your option) any later version.\n" +
- " *\n " +
- " * This program is distributed in the hope that it will be useful,\n" +
- " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
- " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
- " * GNU General Public License for more details.\n" +
- " *\n " +
- " * You should have received a copy of the GNU Lesser General Public\n" +
- " * License along with this program. If not, see\n" +
- " * <http://www.gnu.org/licenses/lgpl-2.1.html>.\n" +
- " */\n";
-
- // LGPLv3 license header
- private static final String LGPLv3 =
- "/**\n" +
- " * This program is free software: you can redistribute it and/or modify\n" +
- " * it under the terms of the GNU Lesser General Public License as\n" +
- " * published by the Free Software Foundation, either version 3 of the\n" +
- " * License, or (at your option) any later version.\n" +
- " *\n " +
- " * This program is distributed in the hope that it will be useful,\n" +
- " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
- " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
- " * GNU General Public License for more details.\n" +
- " *\n " +
- " * You should have received a copy of the GNU Lesser General Public\n" +
- " * License along with this program. If not, see\n" +
- " * <http://www.gnu.org/licenses/lgpl-3.0.html>.\n" +
- " */\n";
-
- /**
- * @param license
- */
- public LicenseHeaders(String pLicenseName) {
- this.initializeRelations();
- this.setLicenseName(pLicenseName);
- }
-
- /**
- * Initializes relations between supported licenses and license text
- */
- public void initializeRelations(){
- relatedLicenses = new HashMap<String, String>();
- try {
- for (String licenseValue : supportedLicenses) {
- String var = (String) this.getClass().getDeclaredField(licenseValue).get(licenseValue);
- relatedLicenses.put(licenseValue,var);
- }
- } catch (SecurityException e) {
- e.printStackTrace();
- } catch (NoSuchFieldException e) {
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
-
- /**
- *Set the license header for the LicenseHeader object.
- *
- */
- public void setLicenseName(String pLicenseName) {
- this.licenseName = pLicenseName;
- }
-
- /**
- * Get the license header for the LicenseHeader object.
- * @return
- */
- public String getLicense() {
- return relatedLicenses.get(licenseName)!=null?relatedLicenses.get(licenseName):"";
- }
-
- /**
- * Get the license name for the LicenseHeader object.
- * @return
- */
- public String getLicenseName(){
- return licenseName;
- }
-}
http://git-wip-us.apache.org/repos/asf/gora/blob/1b5b36d3/gora-core/src/test/java/org/apache/gora/mock/persistency/MockPersistent.java
----------------------------------------------------------------------
diff --git a/gora-core/src/test/java/org/apache/gora/mock/persistency/MockPersistent.java b/gora-core/src/test/java/org/apache/gora/mock/persistency/MockPersistent.java
index b33629b..93c5c11 100644
--- a/gora-core/src/test/java/org/apache/gora/mock/persistency/MockPersistent.java
+++ b/gora-core/src/test/java/org/apache/gora/mock/persistency/MockPersistent.java
@@ -56,7 +56,8 @@ public class MockPersistent extends PersistentBase {
@Override
public Schema getSchema() {
- return Schema.parse("{\"type\":\"record\",\"name\":\"MockPersistent\",\"namespace\":\"org.apache.gora.mock.persistency\",\"fields\":[{\"name\":\"foo\",\"type\":\"int\"},{\"name\":\"baz\",\"type\":\"int\"}]}");
+ Schema.Parser parser = new Schema.Parser();
+ return parser.parse("{\"type\":\"record\",\"name\":\"MockPersistent\",\"namespace\":\"org.apache.gora.mock.persistency\",\"fields\":[{\"name\":\"foo\",\"type\":\"int\"},{\"name\":\"baz\",\"type\":\"int\"}]}");
}
public void setFoo(int foo) {
http://git-wip-us.apache.org/repos/asf/gora/blob/1b5b36d3/gora-core/src/test/java/org/apache/gora/persistency/impl/TestPersistentBase.java
----------------------------------------------------------------------
diff --git a/gora-core/src/test/java/org/apache/gora/persistency/impl/TestPersistentBase.java b/gora-core/src/test/java/org/apache/gora/persistency/impl/TestPersistentBase.java
index ab730be..74337e4 100644
--- a/gora-core/src/test/java/org/apache/gora/persistency/impl/TestPersistentBase.java
+++ b/gora-core/src/test/java/org/apache/gora/persistency/impl/TestPersistentBase.java
@@ -20,8 +20,6 @@ package org.apache.gora.persistency.impl;
import java.io.IOException;
import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import org.apache.avro.Schema.Field;
import org.apache.avro.util.Utf8;