import com.pyx4j.log4j.MavenLogAppender;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
-import java.security.NoSuchAlgorithmException;
-import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
* @required
* @readonly
*/
- private String buildDirectory;
+ String buildDirectory;
/** Parameters to configure the genaration of the SQL *********************/
- public final void execute(String filename)
+ public final void execute(ModificationTracker tracker)
throws
MojoFailureException,
MojoExecutionException
return;
}
- ModificationTracker tracker;
- try
- {
- tracker = new ModificationTracker(buildDirectory, filename, getLog());
- }
- catch (NoSuchAlgorithmException e)
- {
- throw new MojoFailureException("Digest-Algorithm MD5 is missing!", e);
- }
-
final SimpleConnectionProvider connectionProvider =
new SimpleConnectionProvider(getLog());
else
getLog().debug("Configuration unchanged.");
- /** Check, that the outputfile is writable */
- final File output = getOutputFile(filename);
/** Check, if the outputfile is missing or was changed */
- checkOutputFile(output, tracker);
+ try
+ {
+ tracker.track();
+ }
+ catch (IOException e)
+ {
+ String error =
+ "Error while checking the generated script: " + e.getMessage();
+ getLog().error(error);
+ throw new MojoExecutionException(error);
+ }
/** Configure Hibernate */
final StandardServiceRegistry serviceRegistry =
/** Truncate output file */
try
{
- new FileOutputStream(output).getChannel().truncate(0).close();
+ tracker.turncat();
}
catch (IOException e)
{
String error =
- "Error while truncating " + output.getAbsolutePath() + ": "
+ "Error while truncating output file: " // TODO: Filename unknown here!
+ e.getMessage();
getLog().warn(error);
throw new MojoExecutionException(error);
{
thread.setContextClassLoader(classLoader);
ExceptionHandlerCollectingImpl handler =
- build((MetadataImplementor)metadataBuilder.build(), output);
+ build((MetadataImplementor)metadataBuilder.build());
if (handler.getExceptions().size() > 0)
{
StringBuilder builder = new StringBuilder();
{
thread.setContextClassLoader(contextClassLoader);
/** Track, the content of the generated script */
- checkOutputFile(output, tracker);
+ try
+ {
+ tracker.track();
+ }
+ catch (IOException e)
+ {
+ String error =
+ "Error while checking the generated script: " + e.getMessage();
+ getLog().error(error);
+ throw new MojoExecutionException(error);
+ }
}
}
catch (MojoExecutionException e)
}
- abstract ExceptionHandlerCollectingImpl build(
- MetadataImplementor metadata,
- File file
- )
+ abstract ExceptionHandlerCollectingImpl build(MetadataImplementor metadata)
throws
MojoFailureException,
MojoExecutionException;
return output;
}
- private void checkOutputFile(File output, ModificationTracker tracker)
- throws
- MojoExecutionException
- {
- try
- {
- if (output.exists())
- tracker.track(SCRIPT, new FileInputStream(output));
- else
- tracker.track(SCRIPT, ZonedDateTime.now().toString());
- }
- catch (IOException e)
- {
- String error =
- "Error while checking the generated script: " + e.getMessage();
- getLog().error(error);
- throw new MojoExecutionException(error);
- }
- }
-
private void addMappings(MetadataSources sources, ModificationTracker tracker)
throws MojoFailureException
{