Commit e9d4a01b authored by David Trott's avatar David Trott

Grabbed staleness check from maven-protoc-plugin.

parent fe80dbd6
...@@ -128,6 +128,16 @@ abstract class AbstractThriftMojo extends AbstractMojo { ...@@ -128,6 +128,16 @@ abstract class AbstractThriftMojo extends AbstractMojo {
*/ */
private Set<String> excludes = ImmutableSet.of(); private Set<String> excludes = ImmutableSet.of();
/**
* @parameter
*/
private long staleMillis = 0;
/**
* @parameter
*/
private boolean checkStaleness = false;
/** /**
* Executes the mojo. * Executes the mojo.
*/ */
...@@ -137,12 +147,16 @@ abstract class AbstractThriftMojo extends AbstractMojo { ...@@ -137,12 +147,16 @@ abstract class AbstractThriftMojo extends AbstractMojo {
if (thriftSourceRoot.exists()) { if (thriftSourceRoot.exists()) {
try { try {
ImmutableSet<File> thriftFiles = findThriftFilesInDirectory(thriftSourceRoot); ImmutableSet<File> thriftFiles = findThriftFilesInDirectory(thriftSourceRoot);
final File outputDirectory = getOutputDirectory();
ImmutableSet<File> outputFiles = findGeneratedFilesInDirectory(getOutputDirectory());
if (thriftFiles.isEmpty()) { if (thriftFiles.isEmpty()) {
getLog().info("No thrift files to compile."); getLog().info("No thrift files to compile.");
} else if (checkStaleness && ((lastModified(thriftFiles) + staleMillis) < lastModified(outputFiles))) {
getLog().info("Skipping compilation because target directory newer than sources.");
} else { } else {
ImmutableSet<File> derivedThriftPathElements = ImmutableSet<File> derivedThriftPathElements =
makeThriftPathFromJars(temporaryThriftFileDirectory, getDependencyArtifactFiles()); makeThriftPathFromJars(temporaryThriftFileDirectory, getDependencyArtifactFiles());
final File outputDirectory = getOutputDirectory();
outputDirectory.mkdirs(); outputDirectory.mkdirs();
// Quick fix to fix issues with two mvn installs in a row (ie no clean) // Quick fix to fix issues with two mvn installs in a row (ie no clean)
...@@ -177,6 +191,25 @@ abstract class AbstractThriftMojo extends AbstractMojo { ...@@ -177,6 +191,25 @@ abstract class AbstractThriftMojo extends AbstractMojo {
} }
} }
ImmutableSet<File> findGeneratedFilesInDirectory(File directory) throws IOException {
if (directory == null || !directory.isDirectory())
return ImmutableSet.of();
// TODO(gak): plexus-utils needs generics
@SuppressWarnings("unchecked")
List<File> javaFilesInDirectory = getFiles(directory, "**/*.java", null);
return ImmutableSet.copyOf(javaFilesInDirectory);
}
private long lastModified(ImmutableSet<File> files) {
long result = 0;
for (File file : files) {
if (file.lastModified() > result)
result = file.lastModified();
}
return result;
}
private void checkParameters() { private void checkParameters() {
checkNotNull(project, "project"); checkNotNull(project, "project");
checkNotNull(projectHelper, "projectHelper"); checkNotNull(projectHelper, "projectHelper");
......
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