use of org.apache.tools.ant.BuildException in project hibernate-orm by hibernate.
the class SchemaUpdateTask method execute.
/**
* Execute the task
*/
@Override
public void execute() throws BuildException {
log("Running Hibernate Core SchemaUpdate.");
log("This is an Ant task supporting only mapping files, if you want to use annotations see http://tools.hibernate.org.");
try {
final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder();
configure(ssrBuilder);
final StandardServiceRegistry ssr = ssrBuilder.build();
final MetadataSources metadataSources = new MetadataSources(ssr);
configure(metadataSources);
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
configure(metadataBuilder, ssr);
final MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();
new SchemaUpdate().setOutputFile(outputFile.getPath()).setDelimiter(delimiter).setHaltOnError(haltOnError).execute(TargetTypeHelper.parseLegacyCommandLineOptions(!quiet, !text, outputFile.getPath()), metadata);
} catch (HibernateException e) {
throw new BuildException("Schema text failed: " + e.getMessage(), e);
} catch (FileNotFoundException e) {
throw new BuildException("File not found: " + e.getMessage(), e);
} catch (IOException e) {
throw new BuildException("IOException : " + e.getMessage(), e);
} catch (BuildException e) {
throw e;
} catch (Exception e) {
throw new BuildException(e);
}
}
use of org.apache.tools.ant.BuildException in project hibernate-orm by hibernate.
the class SchemaValidatorTask method execute.
/**
* Execute the task
*/
@Override
public void execute() throws BuildException {
try {
final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder();
configure(ssrBuilder);
final StandardServiceRegistry ssr = ssrBuilder.build();
try {
final MetadataSources metadataSources = new MetadataSources(ssrBuilder.build());
configure(metadataSources);
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
configure(metadataBuilder, ssr);
final MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();
new SchemaValidator().validate(metadata, ssr);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
} catch (HibernateException e) {
throw new BuildException("Schema text failed: " + e.getMessage(), e);
} catch (FileNotFoundException e) {
throw new BuildException("File not found: " + e.getMessage(), e);
} catch (IOException e) {
throw new BuildException("IOException : " + e.getMessage(), e);
} catch (BuildException e) {
throw e;
} catch (Exception e) {
throw new BuildException(e);
}
}
use of org.apache.tools.ant.BuildException in project hibernate-orm by hibernate.
the class EnhancementTask method toClassLoader.
private ClassLoader toClassLoader(List<File> runtimeClasspath) throws BuildException {
List<URL> urls = new ArrayList<>();
for (File file : runtimeClasspath) {
try {
urls.add(file.toURI().toURL());
log("Adding classpath entry for classes root " + file.getAbsolutePath(), Project.MSG_DEBUG);
} catch (MalformedURLException e) {
String msg = "Unable to resolve classpath entry to URL: " + file.getAbsolutePath();
if (failOnError) {
throw new BuildException(msg, e);
}
log(msg, Project.MSG_WARN);
}
}
return new URLClassLoader(urls.toArray(new URL[urls.size()]), Enhancer.class.getClassLoader());
}
use of org.apache.tools.ant.BuildException in project hibernate-orm by hibernate.
the class EnhancementTask method execute.
@Override
public void execute() throws BuildException {
if (!shouldApply()) {
log("Skipping Hibernate bytecode enhancement task execution since no feature is enabled", Project.MSG_WARN);
return;
}
if (!dir.startsWith(base)) {
throw new BuildException("The enhancement directory 'dir' (" + dir + ") is no subdirectory of 'base' (" + base + ")");
}
// Perform a depth first search for sourceSet
File root = new File(dir);
if (!root.exists()) {
log("Skipping Hibernate enhancement task execution since there is no classes dir " + dir, Project.MSG_INFO);
return;
}
walkDir(root);
if (sourceSet.isEmpty()) {
log("Skipping Hibernate enhancement task execution since there are no classes to enhance on " + dir, Project.MSG_INFO);
return;
}
log("Starting Hibernate enhancement task for classes on " + dir, Project.MSG_INFO);
ClassLoader classLoader = toClassLoader(Collections.singletonList(new File(base)));
EnhancementContext enhancementContext = new DefaultEnhancementContext() {
@Override
public ClassLoader getLoadingClassLoader() {
return classLoader;
}
@Override
public boolean doBiDirectionalAssociationManagement(UnloadedField field) {
return enableAssociationManagement;
}
@Override
public boolean doDirtyCheckingInline(UnloadedClass classDescriptor) {
return enableDirtyTracking;
}
@Override
public boolean hasLazyLoadableAttributes(UnloadedClass classDescriptor) {
return enableLazyInitialization;
}
@Override
public boolean isLazyLoadable(UnloadedField field) {
return enableLazyInitialization;
}
@Override
public boolean doExtendedEnhancement(UnloadedClass classDescriptor) {
return enableExtendedEnhancement;
}
};
if (enableExtendedEnhancement) {
log("Extended enhancement is enabled. Classes other than entities may be modified. You should consider access the entities using getter/setter methods and disable this property. Use at your own risk.", Project.MSG_WARN);
}
Enhancer enhancer = Environment.getBytecodeProvider().getEnhancer(enhancementContext);
for (File file : sourceSet) {
byte[] enhancedBytecode = doEnhancement(file, enhancer);
if (enhancedBytecode == null) {
continue;
}
writeOutEnhancedClass(enhancedBytecode, file);
log("Successfully enhanced class [" + file + "]", Project.MSG_INFO);
}
}
use of org.apache.tools.ant.BuildException in project mylyn.docs by eclipse.
the class EpubTask method execute.
@Override
public void execute() throws BuildException {
// When running from within Eclipse, the project may not have been set
if (getProject() == null) {
Project project = new Project();
setProject(project);
}
addFilesets();
if (toc != null) {
if (toc.generate) {
oebps.setGenerateToc(true);
} else if (toc.file != null) {
oebps.setTableOfContents(toc.file);
}
}
try {
EPUB epub = new EPUB(logger);
epub.add(oebps);
if (workingFolder == null) {
epub.pack(epubFile);
} else {
epub.pack(epubFile, workingFolder);
}
} catch (Exception e) {
throw new BuildException(e);
}
}
Aggregations