Skip to content

Commit

Permalink
DRILL-4203: Fix DrillVersionInfo to make it provide a valid version n…
Browse files Browse the repository at this point in the history
…umber even during the unit tests.

This is now a build-time generated class, rather than one that looks on the
classpath for META-INF files.

This pattern for file generation with parameters passed from the POM files
was borrowed from parquet-mr.
  • Loading branch information
jaltekruse authored and parthchandra committed Oct 14, 2016
1 parent 17b9648 commit 2f4b5ef
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 58 deletions.

This file was deleted.

90 changes: 90 additions & 0 deletions common/src/main/java/org/apache/drill/version/Generator.java
@@ -0,0 +1,90 @@
/**
* 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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.drill.version;

import com.google.common.base.Preconditions;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
* This class is called from the exec->vector module using Maven-exec.
* To make use of the class, it needs to be compiled in an earlier module.
* For the configuration see the pom.xml file in that module.
*/
public class Generator {

public static void main(String[] args) {
String toReplace = "REPLACE_WITH_DRILL_VERSION";
String template =
"/**\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" +
"package org.apache.drill.common.util;\n" +
"\n" +
"/**\n" +
" * Get access to the Drill Version\n" +
" */\n" +
"// File generated during build, DO NOT EDIT!!\n" +
"public class DrillVersionInfo {\n" +
"\n" +
" /**\n" +
" * Get the Drill version from the Manifest file\n" +
" * @return the version number as x.y.z\n" +
" */\n" +
" public static String getVersion() {\n" +
" return \"" + toReplace + "\";\n" +
" }\n" +
"}\n";
Preconditions.checkArgument(args.length == 2,
"Two arguments expected, the first is the target java source directory for the generated file" +
" and the second is the Drill version.");
File srcFile = new File(args[0] + "/org/apache/drill/common/util/DrillVersionInfo.java");
srcFile = srcFile.getAbsoluteFile();
File parent = srcFile.getParentFile();
if (!parent.exists()) {
if (!parent.mkdirs()) {
throw new RuntimeException("Error generating Drill version info class. Couldn't mkdirs for " + parent);
}
}
final FileWriter writer;
try {
writer = new FileWriter(srcFile);
writer.write(template.replace(toReplace, args[1]));
writer.close();
} catch (IOException e) {
throw new RuntimeException("Error generating Drill version info class. " +
"Couldn't open source file for writing: " + srcFile);
}
}
}
22 changes: 22 additions & 0 deletions exec/vector/pom.xml
Expand Up @@ -120,6 +120,28 @@
</execution>
</executions>
</plugin>
<plugin> <!-- generate class to provide current version number -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.apache.drill.version.Generator</mainClass>
<includePluginDependencies>true</includePluginDependencies>
<arguments>
<argument>${basedir}/target/generated-sources</argument>
<argument>${project.version}</argument>
</arguments>
<sourceRoot>${basedir}/target/generated-sources</sourceRoot>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
Expand Down

0 comments on commit 2f4b5ef

Please sign in to comment.