Repository: zookeeper
Updated Branches:
refs/heads/branch-3.4 fa718b93f -> 13ca3f3b8
ZOOKEEPER-2749: Cleanup findbug warnings in branch-3.4: Experimental Warnings
There were a bunch of findbugs warnings related to not closing FileWriters in findbugs. We should conform to best practices and close them.
We should also cherrypick this to 3.5
Author: Abraham Fine <afine@apache.org>
Reviewers: Michael Han <hanm@apache.org>
Closes #221 from afine/ZOOKEEPER-2749
Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/13ca3f3b
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/13ca3f3b
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/13ca3f3b
Branch: refs/heads/branch-3.4
Commit: 13ca3f3b80e3db3f4a614eed37bfe9ed0453e306
Parents: fa718b9
Author: Abraham Fine <afine@apache.org>
Authored: Sat Apr 8 15:57:00 2017 -0700
Committer: Michael Han <hanm@apache.org>
Committed: Sat Apr 8 15:57:00 2017 -0700
----------------------------------------------------------------------
.../org/apache/jute/compiler/CGenerator.java | 126 ++--
.../org/apache/jute/compiler/CppGenerator.java | 119 ++--
.../main/org/apache/jute/compiler/JRecord.java | 621 ++++++++++---------
.../apache/zookeeper/version/util/VerGen.java | 10 +-
4 files changed, 456 insertions(+), 420 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/13ca3f3b/src/java/main/org/apache/jute/compiler/CGenerator.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/jute/compiler/CGenerator.java b/src/java/main/org/apache/jute/compiler/CGenerator.java
index 4bfdcad..689ee21 100644
--- a/src/java/main/org/apache/jute/compiler/CGenerator.java
+++ b/src/java/main/org/apache/jute/compiler/CGenerator.java
@@ -61,70 +61,82 @@ class CGenerator {
+ outputDirectory);
}
}
- FileWriter c = new FileWriter(new File(outputDirectory, mName+".c"));
- FileWriter h = new FileWriter(new File(outputDirectory, mName+".h"));
- h.write("/**\n");
- h.write("* Licensed to the Apache Software Foundation (ASF) under one\n");
- h.write("* or more contributor license agreements. See the NOTICE file\n");
- h.write("* distributed with this work for additional information\n");
- h.write("* regarding copyright ownership. The ASF licenses this file\n");
- h.write("* to you under the Apache License, Version 2.0 (the\n");
- h.write("* \"License\"); you may not use this file except in compliance\n");
- h.write("* with the License. You may obtain a copy of the License at\n");
- h.write("*\n");
- h.write("* http://www.apache.org/licenses/LICENSE-2.0\n");
- h.write("*\n");
- h.write("* Unless required by applicable law or agreed to in writing, software\n");
- h.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n");
- h.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n");
- h.write("* See the License for the specific language governing permissions and\n");
- h.write("* limitations under the License.\n");
- h.write("*/\n");
- h.write("\n");
+ FileWriter c = null;
+ FileWriter h = null;
+ try {
+ c = new FileWriter(new File(outputDirectory, mName+".c"));
+ h = new FileWriter(new File(outputDirectory, mName+".h"));
- c.write("/**\n");
- c.write("* Licensed to the Apache Software Foundation (ASF) under one\n");
- c.write("* or more contributor license agreements. See the NOTICE file\n");
- c.write("* distributed with this work for additional information\n");
- c.write("* regarding copyright ownership. The ASF licenses this file\n");
- c.write("* to you under the Apache License, Version 2.0 (the\n");
- c.write("* \"License\"); you may not use this file except in compliance\n");
- c.write("* with the License. You may obtain a copy of the License at\n");
- c.write("*\n");
- c.write("* http://www.apache.org/licenses/LICENSE-2.0\n");
- c.write("*\n");
- c.write("* Unless required by applicable law or agreed to in writing, software\n");
- c.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n");
- c.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n");
- c.write("* See the License for the specific language governing permissions and\n");
- c.write("* limitations under the License.\n");
- c.write("*/\n");
- c.write("\n");
+ h.write("/**\n");
+ h.write("* Licensed to the Apache Software Foundation (ASF) under one\n");
+ h.write("* or more contributor license agreements. See the NOTICE file\n");
+ h.write("* distributed with this work for additional information\n");
+ h.write("* regarding copyright ownership. The ASF licenses this file\n");
+ h.write("* to you under the Apache License, Version 2.0 (the\n");
+ h.write("* \"License\"); you may not use this file except in compliance\n");
+ h.write("* with the License. You may obtain a copy of the License at\n");
+ h.write("*\n");
+ h.write("* http://www.apache.org/licenses/LICENSE-2.0\n");
+ h.write("*\n");
+ h.write("* Unless required by applicable law or agreed to in writing, software\n");
+ h.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n");
+ h.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n");
+ h.write("* See the License for the specific language governing permissions and\n");
+ h.write("* limitations under the License.\n");
+ h.write("*/\n");
+ h.write("\n");
- h.write("#ifndef __"+mName.toUpperCase().replace('.','_')+"__\n");
- h.write("#define __"+mName.toUpperCase().replace('.','_')+"__\n");
+ c.write("/**\n");
+ c.write("* Licensed to the Apache Software Foundation (ASF) under one\n");
+ c.write("* or more contributor license agreements. See the NOTICE file\n");
+ c.write("* distributed with this work for additional information\n");
+ c.write("* regarding copyright ownership. The ASF licenses this file\n");
+ c.write("* to you under the Apache License, Version 2.0 (the\n");
+ c.write("* \"License\"); you may not use this file except in compliance\n");
+ c.write("* with the License. You may obtain a copy of the License at\n");
+ c.write("*\n");
+ c.write("* http://www.apache.org/licenses/LICENSE-2.0\n");
+ c.write("*\n");
+ c.write("* Unless required by applicable law or agreed to in writing, software\n");
+ c.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n");
+ c.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n");
+ c.write("* See the License for the specific language governing permissions and\n");
+ c.write("* limitations under the License.\n");
+ c.write("*/\n");
+ c.write("\n");
- h.write("#include \"recordio.h\"\n");
- for (Iterator<JFile> i = mInclFiles.iterator(); i.hasNext();) {
- JFile f = i.next();
- h.write("#include \""+f.getName()+".h\"\n");
- }
- // required for compilation from C++
- h.write("\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n");
+ h.write("#ifndef __"+mName.toUpperCase().replace('.','_')+"__\n");
+ h.write("#define __"+mName.toUpperCase().replace('.','_')+"__\n");
- c.write("#include <stdlib.h>\n"); // need it for calloc() & free()
- c.write("#include \""+mName+".h\"\n\n");
+ h.write("#include \"recordio.h\"\n");
+ for (Iterator<JFile> i = mInclFiles.iterator(); i.hasNext();) {
+ JFile f = i.next();
+ h.write("#include \""+f.getName()+".h\"\n");
+ }
+ // required for compilation from C++
+ h.write("\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n");
- for (Iterator<JRecord> i = mRecList.iterator(); i.hasNext();) {
- JRecord jr = i.next();
- jr.genCCode(h, c);
- }
+ c.write("#include <stdlib.h>\n"); // need it for calloc() & free()
+ c.write("#include \""+mName+".h\"\n\n");
- h.write("\n#ifdef __cplusplus\n}\n#endif\n\n");
- h.write("#endif //"+mName.toUpperCase().replace('.','_')+"__\n");
+ for (Iterator<JRecord> i = mRecList.iterator(); i.hasNext();) {
+ JRecord jr = i.next();
+ jr.genCCode(h, c);
+ }
- h.close();
- c.close();
+ h.write("\n#ifdef __cplusplus\n}\n#endif\n\n");
+ h.write("#endif //"+mName.toUpperCase().replace('.','_')+"__\n");
+ } finally {
+ try {
+ if (h != null) {
+ h.close();
+ }
+ } finally {
+ if (c != null) {
+ c.close();
+ }
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/13ca3f3b/src/java/main/org/apache/jute/compiler/CppGenerator.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/jute/compiler/CppGenerator.java b/src/java/main/org/apache/jute/compiler/CppGenerator.java
index 16d44ce..98892a3 100644
--- a/src/java/main/org/apache/jute/compiler/CppGenerator.java
+++ b/src/java/main/org/apache/jute/compiler/CppGenerator.java
@@ -61,65 +61,76 @@ class CppGenerator {
+ outputDirectory);
}
}
- FileWriter cc = new FileWriter(new File(outputDirectory, mName+".cc"));
- FileWriter hh = new FileWriter(new File(outputDirectory, mName+".hh"));
+ FileWriter cc = null;
+ FileWriter hh = null;
- hh.write("/**\n");
- hh.write("* Licensed to the Apache Software Foundation (ASF) under one\n");
- hh.write("* or more contributor license agreements. See the NOTICE file\n");
- hh.write("* distributed with this work for additional information\n");
- hh.write("* regarding copyright ownership. The ASF licenses this file\n");
- hh.write("* to you under the Apache License, Version 2.0 (the\n");
- hh.write("* \"License\"); you may not use this file except in compliance\n");
- hh.write("* with the License. You may obtain a copy of the License at\n");
- hh.write("*\n");
- hh.write("* http://www.apache.org/licenses/LICENSE-2.0\n");
- hh.write("*\n");
- hh.write("* Unless required by applicable law or agreed to in writing, software\n");
- hh.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n");
- hh.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n");
- hh.write("* See the License for the specific language governing permissions and\n");
- hh.write("* limitations under the License.\n");
- hh.write("*/\n");
- hh.write("\n");
+ try {
+ cc = new FileWriter(new File(outputDirectory, mName+".cc"));
+ hh = new FileWriter(new File(outputDirectory, mName+".hh"));
+ hh.write("/**\n");
+ hh.write("* Licensed to the Apache Software Foundation (ASF) under one\n");
+ hh.write("* or more contributor license agreements. See the NOTICE file\n");
+ hh.write("* distributed with this work for additional information\n");
+ hh.write("* regarding copyright ownership. The ASF licenses this file\n");
+ hh.write("* to you under the Apache License, Version 2.0 (the\n");
+ hh.write("* \"License\"); you may not use this file except in compliance\n");
+ hh.write("* with the License. You may obtain a copy of the License at\n");
+ hh.write("*\n");
+ hh.write("* http://www.apache.org/licenses/LICENSE-2.0\n");
+ hh.write("*\n");
+ hh.write("* Unless required by applicable law or agreed to in writing, software\n");
+ hh.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n");
+ hh.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n");
+ hh.write("* See the License for the specific language governing permissions and\n");
+ hh.write("* limitations under the License.\n");
+ hh.write("*/\n");
+ hh.write("\n");
- cc.write("/**\n");
- cc.write("* Licensed to the Apache Software Foundation (ASF) under one\n");
- cc.write("* or more contributor license agreements. See the NOTICE file\n");
- cc.write("* distributed with this work for additional information\n");
- cc.write("* regarding copyright ownership. The ASF licenses this file\n");
- cc.write("* to you under the Apache License, Version 2.0 (the\n");
- cc.write("* \"License\"); you may not use this file except in compliance\n");
- cc.write("* with the License. You may obtain a copy of the License at\n");
- cc.write("*\n");
- cc.write("* http://www.apache.org/licenses/LICENSE-2.0\n");
- cc.write("*\n");
- cc.write("* Unless required by applicable law or agreed to in writing, software\n");
- cc.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n");
- cc.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n");
- cc.write("* See the License for the specific language governing permissions and\n");
- cc.write("* limitations under the License.\n");
- cc.write("*/\n");
- cc.write("\n");
+ cc.write("/**\n");
+ cc.write("* Licensed to the Apache Software Foundation (ASF) under one\n");
+ cc.write("* or more contributor license agreements. See the NOTICE file\n");
+ cc.write("* distributed with this work for additional information\n");
+ cc.write("* regarding copyright ownership. The ASF licenses this file\n");
+ cc.write("* to you under the Apache License, Version 2.0 (the\n");
+ cc.write("* \"License\"); you may not use this file except in compliance\n");
+ cc.write("* with the License. You may obtain a copy of the License at\n");
+ cc.write("*\n");
+ cc.write("* http://www.apache.org/licenses/LICENSE-2.0\n");
+ cc.write("*\n");
+ cc.write("* Unless required by applicable law or agreed to in writing, software\n");
+ cc.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n");
+ cc.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n");
+ cc.write("* See the License for the specific language governing permissions and\n");
+ cc.write("* limitations under the License.\n");
+ cc.write("*/\n");
+ cc.write("\n");
- hh.write("#ifndef __"+mName.toUpperCase().replace('.','_')+"__\n");
- hh.write("#define __"+mName.toUpperCase().replace('.','_')+"__\n");
+ hh.write("#ifndef __"+mName.toUpperCase().replace('.','_')+"__\n");
+ hh.write("#define __"+mName.toUpperCase().replace('.','_')+"__\n");
- hh.write("#include \"recordio.hh\"\n");
- for (Iterator<JFile> i = mInclFiles.iterator(); i.hasNext();) {
- JFile f = i.next();
- hh.write("#include \""+f.getName()+".hh\"\n");
- }
- cc.write("#include \""+mName+".hh\"\n");
-
- for (Iterator<JRecord> i = mRecList.iterator(); i.hasNext();) {
- JRecord jr = i.next();
- jr.genCppCode(hh, cc);
- }
+ hh.write("#include \"recordio.hh\"\n");
+ for (Iterator<JFile> i = mInclFiles.iterator(); i.hasNext();) {
+ JFile f = i.next();
+ hh.write("#include \""+f.getName()+".hh\"\n");
+ }
+ cc.write("#include \""+mName+".hh\"\n");
- hh.write("#endif //"+mName.toUpperCase().replace('.','_')+"__\n");
+ for (Iterator<JRecord> i = mRecList.iterator(); i.hasNext();) {
+ JRecord jr = i.next();
+ jr.genCppCode(hh, cc);
+ }
- hh.close();
- cc.close();
+ hh.write("#endif //"+mName.toUpperCase().replace('.','_')+"__\n");
+ } finally {
+ try {
+ if (hh != null) {
+ hh.close();
+ }
+ } finally {
+ if (cc != null) {
+ cc.close();
+ }
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/13ca3f3b/src/java/main/org/apache/jute/compiler/JRecord.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/jute/compiler/JRecord.java b/src/java/main/org/apache/jute/compiler/JRecord.java
index 01ba298..13965f7 100644
--- a/src/java/main/org/apache/jute/compiler/JRecord.java
+++ b/src/java/main/org/apache/jute/compiler/JRecord.java
@@ -404,167 +404,173 @@ public class JRecord extends JCompType {
throw new IOException(pkgpath + " is not a directory.");
}
File jfile = new File(pkgdir, getName()+".java");
- FileWriter jj = new FileWriter(jfile);
- jj.write("// File generated by hadoop record compiler. Do not edit.\n");
- jj.write("/**\n");
- jj.write("* Licensed to the Apache Software Foundation (ASF) under one\n");
- jj.write("* or more contributor license agreements. See the NOTICE file\n");
- jj.write("* distributed with this work for additional information\n");
- jj.write("* regarding copyright ownership. The ASF licenses this file\n");
- jj.write("* to you under the Apache License, Version 2.0 (the\n");
- jj.write("* \"License\"); you may not use this file except in compliance\n");
- jj.write("* with the License. You may obtain a copy of the License at\n");
- jj.write("*\n");
- jj.write("* http://www.apache.org/licenses/LICENSE-2.0\n");
- jj.write("*\n");
- jj.write("* Unless required by applicable law or agreed to in writing, software\n");
- jj.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n");
- jj.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n");
- jj.write("* See the License for the specific language governing permissions and\n");
- jj.write("* limitations under the License.\n");
- jj.write("*/\n");
- jj.write("\n");
- jj.write("package "+getJavaPackage()+";\n\n");
- jj.write("import org.apache.jute.*;\n");
- jj.write("public class "+getName()+" implements Record {\n");
- for (Iterator<JField> i = mFields.iterator(); i.hasNext();) {
- JField jf = i.next();
- jj.write(jf.genJavaDecl());
- }
- jj.write(" public "+getName()+"() {\n");
- jj.write(" }\n");
+ FileWriter jj = null;
+ try{
+ jj = new FileWriter(jfile);
+ jj.write("// File generated by hadoop record compiler. Do not edit.\n");
+ jj.write("/**\n");
+ jj.write("* Licensed to the Apache Software Foundation (ASF) under one\n");
+ jj.write("* or more contributor license agreements. See the NOTICE file\n");
+ jj.write("* distributed with this work for additional information\n");
+ jj.write("* regarding copyright ownership. The ASF licenses this file\n");
+ jj.write("* to you under the Apache License, Version 2.0 (the\n");
+ jj.write("* \"License\"); you may not use this file except in compliance\n");
+ jj.write("* with the License. You may obtain a copy of the License at\n");
+ jj.write("*\n");
+ jj.write("* http://www.apache.org/licenses/LICENSE-2.0\n");
+ jj.write("*\n");
+ jj.write("* Unless required by applicable law or agreed to in writing, software\n");
+ jj.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n");
+ jj.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n");
+ jj.write("* See the License for the specific language governing permissions and\n");
+ jj.write("* limitations under the License.\n");
+ jj.write("*/\n");
+ jj.write("\n");
+ jj.write("package "+getJavaPackage()+";\n\n");
+ jj.write("import org.apache.jute.*;\n");
+ jj.write("public class "+getName()+" implements Record {\n");
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext();) {
+ JField jf = i.next();
+ jj.write(jf.genJavaDecl());
+ }
+ jj.write(" public "+getName()+"() {\n");
+ jj.write(" }\n");
- jj.write(" public "+getName()+"(\n");
- int fIdx = 0;
- int fLen = mFields.size();
- for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
- JField jf = i.next();
- jj.write(jf.genJavaConstructorParam(jf.getName()));
- jj.write((fLen-1 == fIdx)?"":",\n");
- }
- jj.write(") {\n");
- fIdx = 0;
- for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
- JField jf = i.next();
- jj.write(jf.genJavaConstructorSet(jf.getName()));
- }
- jj.write(" }\n");
- fIdx = 0;
- for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
- JField jf = i.next();
- jj.write(jf.genJavaGetSet(fIdx));
- }
- jj.write(" public void serialize(OutputArchive a_, String tag) throws java.io.IOException {\n");
- jj.write(" a_.startRecord(this,tag);\n");
- fIdx = 0;
- for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
- JField jf = i.next();
- jj.write(jf.genJavaWriteMethodName());
- }
- jj.write(" a_.endRecord(this,tag);\n");
- jj.write(" }\n");
+ jj.write(" public "+getName()+"(\n");
+ int fIdx = 0;
+ int fLen = mFields.size();
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
+ JField jf = i.next();
+ jj.write(jf.genJavaConstructorParam(jf.getName()));
+ jj.write((fLen-1 == fIdx)?"":",\n");
+ }
+ jj.write(") {\n");
+ fIdx = 0;
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
+ JField jf = i.next();
+ jj.write(jf.genJavaConstructorSet(jf.getName()));
+ }
+ jj.write(" }\n");
+ fIdx = 0;
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
+ JField jf = i.next();
+ jj.write(jf.genJavaGetSet(fIdx));
+ }
+ jj.write(" public void serialize(OutputArchive a_, String tag) throws java.io.IOException {\n");
+ jj.write(" a_.startRecord(this,tag);\n");
+ fIdx = 0;
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
+ JField jf = i.next();
+ jj.write(jf.genJavaWriteMethodName());
+ }
+ jj.write(" a_.endRecord(this,tag);\n");
+ jj.write(" }\n");
- jj.write(" public void deserialize(InputArchive a_, String tag) throws java.io.IOException {\n");
- jj.write(" a_.startRecord(tag);\n");
- fIdx = 0;
- for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
- JField jf = i.next();
- jj.write(jf.genJavaReadMethodName());
- }
- jj.write(" a_.endRecord(tag);\n");
- jj.write("}\n");
-
- jj.write(" public String toString() {\n");
- jj.write(" try {\n");
- jj.write(" java.io.ByteArrayOutputStream s =\n");
- jj.write(" new java.io.ByteArrayOutputStream();\n");
- jj.write(" CsvOutputArchive a_ = \n");
- jj.write(" new CsvOutputArchive(s);\n");
- jj.write(" a_.startRecord(this,\"\");\n");
- fIdx = 0;
- for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
- JField jf = i.next();
- jj.write(jf.genJavaWriteMethodName());
- }
- jj.write(" a_.endRecord(this,\"\");\n");
- jj.write(" return new String(s.toByteArray(), \"UTF-8\");\n");
- jj.write(" } catch (Throwable ex) {\n");
- jj.write(" ex.printStackTrace();\n");
- jj.write(" }\n");
- jj.write(" return \"ERROR\";\n");
- jj.write(" }\n");
-
- jj.write(" public void write(java.io.DataOutput out) throws java.io.IOException {\n");
- jj.write(" BinaryOutputArchive archive = new BinaryOutputArchive(out);\n");
- jj.write(" serialize(archive, \"\");\n");
- jj.write(" }\n");
-
- jj.write(" public void readFields(java.io.DataInput in) throws java.io.IOException {\n");
- jj.write(" BinaryInputArchive archive = new BinaryInputArchive(in);\n");
- jj.write(" deserialize(archive, \"\");\n");
- jj.write(" }\n");
-
- jj.write(" public int compareTo (Object peer_) throws ClassCastException {\n");
- boolean unimplemented = false;
- for (JField f : mFields) {
- if ((f.getType() instanceof JMap)
- || (f.getType() instanceof JVector))
- {
- unimplemented = true;
+ jj.write(" public void deserialize(InputArchive a_, String tag) throws java.io.IOException {\n");
+ jj.write(" a_.startRecord(tag);\n");
+ fIdx = 0;
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
+ JField jf = i.next();
+ jj.write(jf.genJavaReadMethodName());
}
- }
- if (unimplemented) {
- jj.write(" throw new UnsupportedOperationException(\"comparing "
- + getName() + " is unimplemented\");\n");
- } else {
+ jj.write(" a_.endRecord(tag);\n");
+ jj.write("}\n");
+
+ jj.write(" public String toString() {\n");
+ jj.write(" try {\n");
+ jj.write(" java.io.ByteArrayOutputStream s =\n");
+ jj.write(" new java.io.ByteArrayOutputStream();\n");
+ jj.write(" CsvOutputArchive a_ = \n");
+ jj.write(" new CsvOutputArchive(s);\n");
+ jj.write(" a_.startRecord(this,\"\");\n");
+ fIdx = 0;
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
+ JField jf = i.next();
+ jj.write(jf.genJavaWriteMethodName());
+ }
+ jj.write(" a_.endRecord(this,\"\");\n");
+ jj.write(" return new String(s.toByteArray(), \"UTF-8\");\n");
+ jj.write(" } catch (Throwable ex) {\n");
+ jj.write(" ex.printStackTrace();\n");
+ jj.write(" }\n");
+ jj.write(" return \"ERROR\";\n");
+ jj.write(" }\n");
+
+ jj.write(" public void write(java.io.DataOutput out) throws java.io.IOException {\n");
+ jj.write(" BinaryOutputArchive archive = new BinaryOutputArchive(out);\n");
+ jj.write(" serialize(archive, \"\");\n");
+ jj.write(" }\n");
+
+ jj.write(" public void readFields(java.io.DataInput in) throws java.io.IOException {\n");
+ jj.write(" BinaryInputArchive archive = new BinaryInputArchive(in);\n");
+ jj.write(" deserialize(archive, \"\");\n");
+ jj.write(" }\n");
+
+ jj.write(" public int compareTo (Object peer_) throws ClassCastException {\n");
+ boolean unimplemented = false;
+ for (JField f : mFields) {
+ if ((f.getType() instanceof JMap)
+ || (f.getType() instanceof JVector))
+ {
+ unimplemented = true;
+ }
+ }
+ if (unimplemented) {
+ jj.write(" throw new UnsupportedOperationException(\"comparing "
+ + getName() + " is unimplemented\");\n");
+ } else {
+ jj.write(" if (!(peer_ instanceof "+getName()+")) {\n");
+ jj.write(" throw new ClassCastException(\"Comparing different types of records.\");\n");
+ jj.write(" }\n");
+ jj.write(" "+getName()+" peer = ("+getName()+") peer_;\n");
+ jj.write(" int ret = 0;\n");
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
+ JField jf = i.next();
+ jj.write(jf.genJavaCompareTo());
+ jj.write(" if (ret != 0) return ret;\n");
+ }
+ jj.write(" return ret;\n");
+ }
+ jj.write(" }\n");
+
+ jj.write(" public boolean equals(Object peer_) {\n");
jj.write(" if (!(peer_ instanceof "+getName()+")) {\n");
- jj.write(" throw new ClassCastException(\"Comparing different types of records.\");\n");
+ jj.write(" return false;\n");
+ jj.write(" }\n");
+ jj.write(" if (peer_ == this) {\n");
+ jj.write(" return true;\n");
jj.write(" }\n");
jj.write(" "+getName()+" peer = ("+getName()+") peer_;\n");
- jj.write(" int ret = 0;\n");
+ jj.write(" boolean ret = false;\n");
for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
JField jf = i.next();
- jj.write(jf.genJavaCompareTo());
- jj.write(" if (ret != 0) return ret;\n");
+ jj.write(jf.genJavaEquals());
+ jj.write(" if (!ret) return ret;\n");
}
jj.write(" return ret;\n");
- }
- jj.write(" }\n");
-
- jj.write(" public boolean equals(Object peer_) {\n");
- jj.write(" if (!(peer_ instanceof "+getName()+")) {\n");
- jj.write(" return false;\n");
- jj.write(" }\n");
- jj.write(" if (peer_ == this) {\n");
- jj.write(" return true;\n");
- jj.write(" }\n");
- jj.write(" "+getName()+" peer = ("+getName()+") peer_;\n");
- jj.write(" boolean ret = false;\n");
- for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
- JField jf = i.next();
- jj.write(jf.genJavaEquals());
- jj.write(" if (!ret) return ret;\n");
- }
- jj.write(" return ret;\n");
- jj.write(" }\n");
+ jj.write(" }\n");
- jj.write(" public int hashCode() {\n");
- jj.write(" int result = 17;\n");
- jj.write(" int ret;\n");
- for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
- JField jf = i.next();
- jj.write(jf.genJavaHashCode());
- jj.write(" result = 37*result + ret;\n");
+ jj.write(" public int hashCode() {\n");
+ jj.write(" int result = 17;\n");
+ jj.write(" int ret;\n");
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
+ JField jf = i.next();
+ jj.write(jf.genJavaHashCode());
+ jj.write(" result = 37*result + ret;\n");
+ }
+ jj.write(" return result;\n");
+ jj.write(" }\n");
+ jj.write(" public static String signature() {\n");
+ jj.write(" return \""+getSignature()+"\";\n");
+ jj.write(" }\n");
+
+ jj.write("}\n");
+ } finally {
+ if (jj != null) {
+ jj.close();
+ }
}
- jj.write(" return result;\n");
- jj.write(" }\n");
- jj.write(" public static String signature() {\n");
- jj.write(" return \""+getSignature()+"\";\n");
- jj.write(" }\n");
- jj.write("}\n");
-
- jj.close();
}
public void genCsharpCode(File outputDirectory) throws IOException {
@@ -577,173 +583,180 @@ public class JRecord extends JCompType {
throw new IOException(outputDirectory + " is not a directory.");
}
File csharpFile = new File(outputDirectory, getName()+".cs");
- FileWriter cs = new FileWriter(csharpFile);
- cs.write("// File generated by hadoop record compiler. Do not edit.\n");
- cs.write("/**\n");
- cs.write("* Licensed to the Apache Software Foundation (ASF) under one\n");
- cs.write("* or more contributor license agreements. See the NOTICE file\n");
- cs.write("* distributed with this work for additional information\n");
- cs.write("* regarding copyright ownership. The ASF licenses this file\n");
- cs.write("* to you under the Apache License, Version 2.0 (the\n");
- cs.write("* \"License\"); you may not use this file except in compliance\n");
- cs.write("* with the License. You may obtain a copy of the License at\n");
- cs.write("*\n");
- cs.write("* http://www.apache.org/licenses/LICENSE-2.0\n");
- cs.write("*\n");
- cs.write("* Unless required by applicable law or agreed to in writing, software\n");
- cs.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n");
- cs.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n");
- cs.write("* See the License for the specific language governing permissions and\n");
- cs.write("* limitations under the License.\n");
- cs.write("*/\n");
- cs.write("\n");
- cs.write("using System;\n");
- cs.write("using Org.Apache.Jute;\n");
- cs.write("\n");
- cs.write("namespace "+getCsharpNameSpace()+"\n");
- cs.write("{\n");
-
- String className = getCsharpName();
- cs.write("public class "+className+" : IRecord, IComparable \n");
- cs.write("{\n");
- cs.write(" public "+ className +"() {\n");
- cs.write(" }\n");
-
- cs.write(" public "+className+"(\n");
- int fIdx = 0;
- int fLen = mFields.size();
- for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
- JField jf = i.next();
- cs.write(jf.genCsharpConstructorParam(jf.getCsharpName()));
- cs.write((fLen-1 == fIdx)?"":",\n");
- }
- cs.write(") {\n");
- fIdx = 0;
- for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
- JField jf = i.next();
- cs.write(jf.genCsharpConstructorSet(jf.getCsharpName()));
- }
- cs.write(" }\n");
- fIdx = 0;
- for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
- JField jf = i.next();
- cs.write(jf.genCsharpGetSet(fIdx));
+ FileWriter cs = null;
+
+ try {
+ cs = new FileWriter(csharpFile);
+
+ cs.write("// File generated by hadoop record compiler. Do not edit.\n");
+ cs.write("/**\n");
+ cs.write("* Licensed to the Apache Software Foundation (ASF) under one\n");
+ cs.write("* or more contributor license agreements. See the NOTICE file\n");
+ cs.write("* distributed with this work for additional information\n");
+ cs.write("* regarding copyright ownership. The ASF licenses this file\n");
+ cs.write("* to you under the Apache License, Version 2.0 (the\n");
+ cs.write("* \"License\"); you may not use this file except in compliance\n");
+ cs.write("* with the License. You may obtain a copy of the License at\n");
+ cs.write("*\n");
+ cs.write("* http://www.apache.org/licenses/LICENSE-2.0\n");
+ cs.write("*\n");
+ cs.write("* Unless required by applicable law or agreed to in writing, software\n");
+ cs.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n");
+ cs.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n");
+ cs.write("* See the License for the specific language governing permissions and\n");
+ cs.write("* limitations under the License.\n");
+ cs.write("*/\n");
cs.write("\n");
- }
- cs.write(" public void Serialize(IOutputArchive a_, String tag) {\n");
- cs.write(" a_.StartRecord(this,tag);\n");
- fIdx = 0;
- for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
- JField jf = i.next();
- cs.write(jf.genCsharpWriteMethodName());
- }
- cs.write(" a_.EndRecord(this,tag);\n");
- cs.write(" }\n");
+ cs.write("using System;\n");
+ cs.write("using Org.Apache.Jute;\n");
+ cs.write("\n");
+ cs.write("namespace "+getCsharpNameSpace()+"\n");
+ cs.write("{\n");
+
+ String className = getCsharpName();
+ cs.write("public class "+className+" : IRecord, IComparable \n");
+ cs.write("{\n");
+ cs.write(" public "+ className +"() {\n");
+ cs.write(" }\n");
+
+ cs.write(" public "+className+"(\n");
+ int fIdx = 0;
+ int fLen = mFields.size();
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
+ JField jf = i.next();
+ cs.write(jf.genCsharpConstructorParam(jf.getCsharpName()));
+ cs.write((fLen-1 == fIdx)?"":",\n");
+ }
+ cs.write(") {\n");
+ fIdx = 0;
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
+ JField jf = i.next();
+ cs.write(jf.genCsharpConstructorSet(jf.getCsharpName()));
+ }
+ cs.write(" }\n");
+ fIdx = 0;
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
+ JField jf = i.next();
+ cs.write(jf.genCsharpGetSet(fIdx));
+ cs.write("\n");
+ }
+ cs.write(" public void Serialize(IOutputArchive a_, String tag) {\n");
+ cs.write(" a_.StartRecord(this,tag);\n");
+ fIdx = 0;
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
+ JField jf = i.next();
+ cs.write(jf.genCsharpWriteMethodName());
+ }
+ cs.write(" a_.EndRecord(this,tag);\n");
+ cs.write(" }\n");
- cs.write(" public void Deserialize(IInputArchive a_, String tag) {\n");
- cs.write(" a_.StartRecord(tag);\n");
- fIdx = 0;
- for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
- JField jf = i.next();
- cs.write(jf.genCsharpReadMethodName());
- }
- cs.write(" a_.EndRecord(tag);\n");
- cs.write("}\n");
-
- cs.write(" public override String ToString() {\n");
- cs.write(" try {\n");
- cs.write(" System.IO.MemoryStream ms = new System.IO.MemoryStream();\n");
- cs.write(" MiscUtil.IO.EndianBinaryWriter writer =\n");
- cs.write(" new MiscUtil.IO.EndianBinaryWriter(MiscUtil.Conversion.EndianBitConverter.Big, ms, System.Text.Encoding.UTF8);\n");
- cs.write(" BinaryOutputArchive a_ = \n");
- cs.write(" new BinaryOutputArchive(writer);\n");
- cs.write(" a_.StartRecord(this,\"\");\n");
- fIdx = 0;
- for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
- JField jf = i.next();
- cs.write(jf.genCsharpWriteMethodName());
- }
- cs.write(" a_.EndRecord(this,\"\");\n");
- cs.write(" ms.Position = 0;\n");
- cs.write(" return System.Text.Encoding.UTF8.GetString(ms.ToArray());\n");
- cs.write(" } catch (Exception ex) {\n");
- cs.write(" Console.WriteLine(ex.StackTrace);\n");
- cs.write(" }\n");
- cs.write(" return \"ERROR\";\n");
- cs.write(" }\n");
-
- cs.write(" public void Write(MiscUtil.IO.EndianBinaryWriter writer) {\n");
- cs.write(" BinaryOutputArchive archive = new BinaryOutputArchive(writer);\n");
- cs.write(" Serialize(archive, \"\");\n");
- cs.write(" }\n");
-
- cs.write(" public void ReadFields(MiscUtil.IO.EndianBinaryReader reader) {\n");
- cs.write(" BinaryInputArchive archive = new BinaryInputArchive(reader);\n");
- cs.write(" Deserialize(archive, \"\");\n");
- cs.write(" }\n");
-
- cs.write(" public int CompareTo (object peer_) {\n");
- boolean unimplemented = false;
- for (JField f : mFields) {
- if ((f.getType() instanceof JMap)
- || (f.getType() instanceof JVector))
- {
- unimplemented = true;
+ cs.write(" public void Deserialize(IInputArchive a_, String tag) {\n");
+ cs.write(" a_.StartRecord(tag);\n");
+ fIdx = 0;
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
+ JField jf = i.next();
+ cs.write(jf.genCsharpReadMethodName());
}
- }
- if (unimplemented) {
- cs.write(" throw new InvalidOperationException(\"comparing "
- + getCsharpName() + " is unimplemented\");\n");
- } else {
+ cs.write(" a_.EndRecord(tag);\n");
+ cs.write("}\n");
+
+ cs.write(" public override String ToString() {\n");
+ cs.write(" try {\n");
+ cs.write(" System.IO.MemoryStream ms = new System.IO.MemoryStream();\n");
+ cs.write(" MiscUtil.IO.EndianBinaryWriter writer =\n");
+ cs.write(" new MiscUtil.IO.EndianBinaryWriter(MiscUtil.Conversion.EndianBitConverter.Big, ms, System.Text.Encoding.UTF8);\n");
+ cs.write(" BinaryOutputArchive a_ = \n");
+ cs.write(" new BinaryOutputArchive(writer);\n");
+ cs.write(" a_.StartRecord(this,\"\");\n");
+ fIdx = 0;
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
+ JField jf = i.next();
+ cs.write(jf.genCsharpWriteMethodName());
+ }
+ cs.write(" a_.EndRecord(this,\"\");\n");
+ cs.write(" ms.Position = 0;\n");
+ cs.write(" return System.Text.Encoding.UTF8.GetString(ms.ToArray());\n");
+ cs.write(" } catch (Exception ex) {\n");
+ cs.write(" Console.WriteLine(ex.StackTrace);\n");
+ cs.write(" }\n");
+ cs.write(" return \"ERROR\";\n");
+ cs.write(" }\n");
+
+ cs.write(" public void Write(MiscUtil.IO.EndianBinaryWriter writer) {\n");
+ cs.write(" BinaryOutputArchive archive = new BinaryOutputArchive(writer);\n");
+ cs.write(" Serialize(archive, \"\");\n");
+ cs.write(" }\n");
+
+ cs.write(" public void ReadFields(MiscUtil.IO.EndianBinaryReader reader) {\n");
+ cs.write(" BinaryInputArchive archive = new BinaryInputArchive(reader);\n");
+ cs.write(" Deserialize(archive, \"\");\n");
+ cs.write(" }\n");
+
+ cs.write(" public int CompareTo (object peer_) {\n");
+ boolean unimplemented = false;
+ for (JField f : mFields) {
+ if ((f.getType() instanceof JMap)
+ || (f.getType() instanceof JVector))
+ {
+ unimplemented = true;
+ }
+ }
+ if (unimplemented) {
+ cs.write(" throw new InvalidOperationException(\"comparing "
+ + getCsharpName() + " is unimplemented\");\n");
+ } else {
+ cs.write(" if (!(peer_ is "+getCsharpName()+")) {\n");
+ cs.write(" throw new InvalidOperationException(\"Comparing different types of records.\");\n");
+ cs.write(" }\n");
+ cs.write(" "+getCsharpName()+" peer = ("+getCsharpName()+") peer_;\n");
+ cs.write(" int ret = 0;\n");
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
+ JField jf = i.next();
+ cs.write(jf.genCsharpCompareTo());
+ cs.write(" if (ret != 0) return ret;\n");
+ }
+ cs.write(" return ret;\n");
+ }
+ cs.write(" }\n");
+
+ cs.write(" public override bool Equals(object peer_) {\n");
cs.write(" if (!(peer_ is "+getCsharpName()+")) {\n");
- cs.write(" throw new InvalidOperationException(\"Comparing different types of records.\");\n");
+ cs.write(" return false;\n");
+ cs.write(" }\n");
+ cs.write(" if (peer_ == this) {\n");
+ cs.write(" return true;\n");
cs.write(" }\n");
- cs.write(" "+getCsharpName()+" peer = ("+getCsharpName()+") peer_;\n");
- cs.write(" int ret = 0;\n");
+ cs.write(" bool ret = false;\n");
+ cs.write(" " + getCsharpName() + " peer = (" + getCsharpName() + ")peer_;\n");
for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
JField jf = i.next();
- cs.write(jf.genCsharpCompareTo());
- cs.write(" if (ret != 0) return ret;\n");
+ cs.write(jf.genCsharpEquals());
+ cs.write(" if (!ret) return ret;\n");
}
cs.write(" return ret;\n");
- }
- cs.write(" }\n");
-
- cs.write(" public override bool Equals(object peer_) {\n");
- cs.write(" if (!(peer_ is "+getCsharpName()+")) {\n");
- cs.write(" return false;\n");
- cs.write(" }\n");
- cs.write(" if (peer_ == this) {\n");
- cs.write(" return true;\n");
- cs.write(" }\n");
- cs.write(" bool ret = false;\n");
- cs.write(" " + getCsharpName() + " peer = (" + getCsharpName() + ")peer_;\n");
- for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
- JField jf = i.next();
- cs.write(jf.genCsharpEquals());
- cs.write(" if (!ret) return ret;\n");
- }
- cs.write(" return ret;\n");
- cs.write(" }\n");
+ cs.write(" }\n");
- cs.write(" public override int GetHashCode() {\n");
- cs.write(" int result = 17;\n");
- cs.write(" int ret;\n");
- for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
- JField jf = i.next();
- cs.write(jf.genCsharpHashCode());
- cs.write(" result = 37*result + ret;\n");
+ cs.write(" public override int GetHashCode() {\n");
+ cs.write(" int result = 17;\n");
+ cs.write(" int ret;\n");
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
+ JField jf = i.next();
+ cs.write(jf.genCsharpHashCode());
+ cs.write(" result = 37*result + ret;\n");
+ }
+ cs.write(" return result;\n");
+ cs.write(" }\n");
+ cs.write(" public static string Signature() {\n");
+ cs.write(" return \""+getSignature()+"\";\n");
+ cs.write(" }\n");
+
+ cs.write("}\n");
+ cs.write("}\n");
+ } finally {
+ if (cs != null) {
+ cs.close();
+ }
}
- cs.write(" return result;\n");
- cs.write(" }\n");
- cs.write(" public static string Signature() {\n");
- cs.write(" return \""+getSignature()+"\";\n");
- cs.write(" }\n");
-
- cs.write("}\n");
- cs.write("}\n");
-
- cs.close();
}
public static String getCsharpFQName(String name) {
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/13ca3f3b/src/java/main/org/apache/zookeeper/version/util/VerGen.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/version/util/VerGen.java b/src/java/main/org/apache/zookeeper/version/util/VerGen.java
index 93a0710..7285a2b 100644
--- a/src/java/main/org/apache/zookeeper/version/util/VerGen.java
+++ b/src/java/main/org/apache/zookeeper/version/util/VerGen.java
@@ -34,7 +34,7 @@ public class VerGen {
System.exit(1);
}
- public static void generateFile(File outputDir, Version version, String rev, String buildDate)
+ public static void generateFile(File outputDir, Version version, String rev, String buildDate) throws IOException
{
String path = PACKAGE_NAME.replaceAll("\\.", "/");
File pkgdir = new File(outputDir, path);
@@ -91,10 +91,6 @@ public class VerGen {
w.write(" String BUILD_DATE=\"" + buildDate
+ "\";\n");
w.write("}\n");
- } catch (IOException e) {
- System.out.println("Unable to generate version.Info file: "
- + e.getMessage());
- System.exit(1);
} finally {
if (w != null) {
try {
@@ -172,6 +168,10 @@ public class VerGen {
System.err.println(
"All version-related parameters must be valid integers!");
throw e;
+ } catch (IOException e) {
+ System.out.println("Unable to generate version.Info file: "
+ + e.getMessage());
+ System.exit(1);
}
}
|