Commit ff27a62d authored by David Trott's avatar David Trott

Merge commit 'sergey/master'

parents 05a64e31 3e6cea0a
...@@ -53,8 +53,7 @@ abstract class AbstractThriftMojo extends AbstractMojo { ...@@ -53,8 +53,7 @@ abstract class AbstractThriftMojo extends AbstractMojo {
protected MavenProjectHelper projectHelper; protected MavenProjectHelper projectHelper;
/** /**
* This is the path to the {@code thrift} executable. By default it will * This is the path to the {@code thrift} executable. By default it will search the {@code $PATH}.
* search the {@code $PATH}.
* *
* @parameter default-value="thrift" * @parameter default-value="thrift"
* @required * @required
...@@ -67,9 +66,8 @@ abstract class AbstractThriftMojo extends AbstractMojo { ...@@ -67,9 +66,8 @@ abstract class AbstractThriftMojo extends AbstractMojo {
private File[] additionalThriftPathElements = new File[]{}; private File[] additionalThriftPathElements = new File[]{};
/** /**
* Since {@code thrift} cannot access jars, thrift files in dependenceies are * Since {@code thrift} cannot access jars, thrift files in dependenceies are extracted to this location and deleted
* extracted to this location and deleted on exit. This directory is always * on exit. This directory is always cleaned during execution.
* cleaned during execution.
* *
* @parameter expression="${java.io.tmpdir}/maven-thrift" * @parameter expression="${java.io.tmpdir}/maven-thrift"
* @required * @required
...@@ -77,7 +75,6 @@ abstract class AbstractThriftMojo extends AbstractMojo { ...@@ -77,7 +75,6 @@ abstract class AbstractThriftMojo extends AbstractMojo {
private File temporaryThriftFileDirectory; private File temporaryThriftFileDirectory;
/** /**
*
* @parameter * @parameter
*/ */
private Set<String> includes = ImmutableSet.of(DEFAULT_INCLUDES); private Set<String> includes = ImmutableSet.of(DEFAULT_INCLUDES);
...@@ -93,11 +90,11 @@ abstract class AbstractThriftMojo extends AbstractMojo { ...@@ -93,11 +90,11 @@ abstract class AbstractThriftMojo extends AbstractMojo {
public void execute() throws MojoExecutionException, MojoFailureException { public void execute() throws MojoExecutionException, MojoFailureException {
checkParameters(); checkParameters();
final File thriftSourceRoot = getThriftSourceRoot(); final File thriftSourceRoot = getThriftSourceRoot();
if (thriftSourceRoot.exists()) { if(thriftSourceRoot.exists()) {
try { try {
ImmutableSet<File> thriftFiles = ImmutableSet<File> thriftFiles =
findThriftFilesInDirectory(thriftSourceRoot); findThriftFilesInDirectory(thriftSourceRoot);
if (thriftFiles.isEmpty()) { if(thriftFiles.isEmpty()) {
getLog().info("No thrift files to compile."); getLog().info("No thrift files to compile.");
} else { } else {
ImmutableSet<File> derivedThriftPathElements = ImmutableSet<File> derivedThriftPathElements =
...@@ -117,19 +114,19 @@ abstract class AbstractThriftMojo extends AbstractMojo { ...@@ -117,19 +114,19 @@ abstract class AbstractThriftMojo extends AbstractMojo {
.addThriftFiles(thriftFiles) .addThriftFiles(thriftFiles)
.build(); .build();
final int exitStatus = thrift.compile(); final int exitStatus = thrift.compile();
if (exitStatus != 0) { if(exitStatus != 0) {
throw new MojoFailureException( throw new MojoFailureException(
"Thrift did not exit cleanly. Review output for more information."); "Thrift did not exit cleanly. Review output for more information.");
} }
attachFiles(); attachFiles();
} }
} catch (IOException e) { } catch(IOException e) {
throw new MojoExecutionException("An IO error occured", e); throw new MojoExecutionException("An IO error occured", e);
} catch (IllegalArgumentException e) { } catch(IllegalArgumentException e) {
throw new MojoFailureException("Thrift failed to execute because: " throw new MojoFailureException("Thrift failed to execute because: "
+ e.getMessage(), e); + e.getMessage(), e);
} catch (CommandLineException e) { } catch(CommandLineException e) {
throw new MojoExecutionException( throw new MojoExecutionException(
"An error occured while invoking thrift.", e); "An error occured while invoking thrift.", e);
} }
...@@ -174,14 +171,13 @@ abstract class AbstractThriftMojo extends AbstractMojo { ...@@ -174,14 +171,13 @@ abstract class AbstractThriftMojo extends AbstractMojo {
*/ */
private ImmutableSet<File> getDependencyArtifactFiles() { private ImmutableSet<File> getDependencyArtifactFiles() {
Set<File> dependencyArtifactFiles = newHashSet(); Set<File> dependencyArtifactFiles = newHashSet();
for (Artifact artifact : getDependencyArtifacts()) { for(Artifact artifact : getDependencyArtifacts()) {
dependencyArtifactFiles.add(artifact.getFile()); dependencyArtifactFiles.add(artifact.getFile());
} }
return ImmutableSet.copyOf(dependencyArtifactFiles); return ImmutableSet.copyOf(dependencyArtifactFiles);
} }
/** /**
*
* @throws IOException * @throws IOException
*/ */
ImmutableSet<File> makeThriftPathFromJars( ImmutableSet<File> makeThriftPathFromJars(
...@@ -189,27 +185,29 @@ abstract class AbstractThriftMojo extends AbstractMojo { ...@@ -189,27 +185,29 @@ abstract class AbstractThriftMojo extends AbstractMojo {
throws IOException { throws IOException {
checkNotNull(classpathElementFiles, "classpathElementFiles"); checkNotNull(classpathElementFiles, "classpathElementFiles");
// clean the temporary directory to ensure that stale files aren't used // clean the temporary directory to ensure that stale files aren't used
if (temporaryThriftFileDirectory.exists()) { if(temporaryThriftFileDirectory.exists()) {
cleanDirectory(temporaryThriftFileDirectory); cleanDirectory(temporaryThriftFileDirectory);
} }
Set<File> thriftDirectories = newHashSet(); Set<File> thriftDirectories = newHashSet();
for (File classpathElementFile : classpathElementFiles) { for(File classpathElementFile : classpathElementFiles) {
checkArgument(classpathElementFile.isFile(), "%s is not a file", checkArgument(classpathElementFile.isFile(), "%s is not a file",
classpathElementFile); classpathElementFile);
// create the jar file. the constructor validates. // create the jar file. the constructor validates.
JarFile classpathJar = null; JarFile classpathJar = null;
try { try {
classpathJar = new JarFile(classpathElementFile); classpathJar = new JarFile(classpathElementFile);
} catch (IOException e) { } catch(IOException e) {
throw new IllegalArgumentException(format( throw new IllegalArgumentException(format(
"%s was not a readable artifact", classpathElementFile)); "%s was not a readable artifact", classpathElementFile));
} }
for (JarEntry jarEntry : list(classpathJar.entries())) { for(JarEntry jarEntry : list(classpathJar.entries())) {
final String jarEntryName = jarEntry.getName(); final String jarEntryName = jarEntry.getName();
if (jarEntry.getName().endsWith(THRIFT_FILE_SUFFIX)) { if(jarEntry.getName().endsWith(THRIFT_FILE_SUFFIX)) {
//replace logic is used in order to fix issue of an invalid windows classpath to the thrift file
// inside a jar.
final File uncompressedCopy = final File uncompressedCopy =
new File(new File(temporaryThriftFileDirectory, classpathJar new File(new File(temporaryThriftFileDirectory, classpathJar
.getName()), jarEntryName); .getName().replace(":", "_")), jarEntryName);
uncompressedCopy.getParentFile().mkdirs(); uncompressedCopy.getParentFile().mkdirs();
copyStreamToFile(new RawInputStreamFacade(classpathJar copyStreamToFile(new RawInputStreamFacade(classpathJar
.getInputStream(jarEntry)), uncompressedCopy); .getInputStream(jarEntry)), uncompressedCopy);
...@@ -237,7 +235,7 @@ abstract class AbstractThriftMojo extends AbstractMojo { ...@@ -237,7 +235,7 @@ abstract class AbstractThriftMojo extends AbstractMojo {
Iterable<File> directories) throws IOException { Iterable<File> directories) throws IOException {
checkNotNull(directories); checkNotNull(directories);
Set<File> thriftFiles = newHashSet(); Set<File> thriftFiles = newHashSet();
for (File directory : directories) { for(File directory : directories) {
thriftFiles.addAll(findThriftFilesInDirectory(directory)); thriftFiles.addAll(findThriftFilesInDirectory(directory));
} }
return ImmutableSet.copyOf(thriftFiles); return ImmutableSet.copyOf(thriftFiles);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment