Repository navigation
PARQUET-297: generate Version class using parquet-generator #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
11d29bc
10d0b38
6b47b04
ddb469a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * 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.parquet.version; | ||
|
|
||
| /** | ||
| * main class for code generation hook in build for version generation | ||
| */ | ||
| public class Generator { | ||
| public static void main(String[] args) throws Exception { | ||
| VersionGenerator.main(args); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * 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.parquet.version; | ||
|
|
||
| import java.io.File; | ||
| import java.io.FileWriter; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.util.Properties; | ||
|
|
||
| public class VersionGenerator { | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| File srcFile = new File(args[0] + "/org/apache/parquet/Version.java"); | ||
| srcFile = srcFile.getAbsoluteFile(); | ||
| File parent = srcFile.getParentFile(); | ||
| if (!parent.exists()) { | ||
| if (!parent.mkdirs()) { | ||
| throw new IOException("Couldn't mkdirs for " + parent); | ||
| } | ||
| } | ||
| new VersionGenerator(srcFile).run(); | ||
| } | ||
|
|
||
| private final FileWriter writer; | ||
|
|
||
| public VersionGenerator(File file) throws IOException { | ||
| this.writer = new FileWriter(file); | ||
| } | ||
|
|
||
| public void run() throws IOException { | ||
| InputStream in = VersionGenerator.class.getResourceAsStream("/parquet-version.properties"); | ||
| if (in == null) { | ||
| throw new IOException("/parquet-version.properties not found"); | ||
| } | ||
| Properties props = new Properties(); | ||
| props.load(in); | ||
|
|
||
| add("package org.apache.parquet;\n" + | ||
| "\n" + | ||
| "/**\n" + | ||
| " * This class is auto-generated by {@link org.apache.parquet.version.VersionGenerator}\n" + | ||
| " * Do not manually edit!\n" + | ||
| " */\n"); | ||
|
|
||
| add("public class Version {\n"); | ||
|
|
||
| add(" public static final String VERSION_NUMBER = \""); | ||
| add(props.getProperty("versionNumber")); | ||
| add("\";\n"); | ||
|
|
||
| add(" public static final String FULL_VERSION = \""); | ||
| add(props.getProperty("fullVersion")); | ||
| add("\";\n\n"); | ||
|
|
||
| add(" public static void main(String[] args) {\n"); | ||
| add(" System.out.println(FULL_VERSION);\n"); | ||
| add(" }\n"); | ||
|
|
||
| add("}\n"); | ||
| writer.close(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other than the main method, this looks compatible with the old Version class to me. While it's nit-picking and probably over-cautious, I think we should probably include main.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| } | ||
|
|
||
| private void add(String s) throws IOException { | ||
| writer.write(s); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # | ||
| # 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. | ||
|
|
||
| versionNumber = ${project.version} | ||
| fullVersion = parquet-mr version ${project.version} (build ${buildNumber}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why these changes should be included in the version pull request. Maybe this was an accident?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to break circular dependency between parquet-generator and parquet-common.
This was the only method from parquet-common that was used by parquet-generator, so I've just copied it here and removed dependency on parquet-common (have a look at parquet-generator/pom.xml change).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, that makes sense to me. Sounds good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah sort of a bummer but not too bad. Can you add a comment to this method:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add a comment about ByteUtils. Not sure it is worth fixing though as the method is one-liner, is not parquet specific and easy to understand.