Search in sources :

Example 51 with BuildException

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);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataBuilder(org.hibernate.boot.MetadataBuilder) HibernateException(org.hibernate.HibernateException) MetadataSources(org.hibernate.boot.MetadataSources) FileNotFoundException(java.io.FileNotFoundException) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) FileNotFoundException(java.io.FileNotFoundException) HibernateException(org.hibernate.HibernateException) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 52 with BuildException

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);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataBuilder(org.hibernate.boot.MetadataBuilder) HibernateException(org.hibernate.HibernateException) MetadataSources(org.hibernate.boot.MetadataSources) FileNotFoundException(java.io.FileNotFoundException) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) FileNotFoundException(java.io.FileNotFoundException) HibernateException(org.hibernate.HibernateException) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 53 with BuildException

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());
}
Also used : MalformedURLException(java.net.MalformedURLException) Enhancer(org.hibernate.bytecode.enhance.spi.Enhancer) URLClassLoader(java.net.URLClassLoader) ArrayList(java.util.ArrayList) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) URL(java.net.URL)

Example 54 with BuildException

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);
    }
}
Also used : UnloadedClass(org.hibernate.bytecode.enhance.spi.UnloadedClass) DefaultEnhancementContext(org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext) Enhancer(org.hibernate.bytecode.enhance.spi.Enhancer) URLClassLoader(java.net.URLClassLoader) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) UnloadedField(org.hibernate.bytecode.enhance.spi.UnloadedField) EnhancementContext(org.hibernate.bytecode.enhance.spi.EnhancementContext) DefaultEnhancementContext(org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext)

Example 55 with BuildException

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);
    }
}
Also used : Project(org.apache.tools.ant.Project) EPUB(org.eclipse.mylyn.docs.epub.core.EPUB) BuildException(org.apache.tools.ant.BuildException) BuildException(org.apache.tools.ant.BuildException)

Aggregations

BuildException (org.apache.tools.ant.BuildException)930 IOException (java.io.IOException)390 File (java.io.File)365 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)75 ArrayList (java.util.ArrayList)65 InputStream (java.io.InputStream)62 Project (org.apache.tools.ant.Project)61 Resource (org.apache.tools.ant.types.Resource)58 FileSet (org.apache.tools.ant.types.FileSet)52 Path (org.apache.tools.ant.types.Path)52 Commandline (org.apache.tools.ant.types.Commandline)51 Properties (java.util.Properties)50 OutputStream (java.io.OutputStream)44 FileOutputStream (java.io.FileOutputStream)42 FileResource (org.apache.tools.ant.types.resources.FileResource)42 FileInputStream (java.io.FileInputStream)41 URL (java.net.URL)40 BufferedReader (java.io.BufferedReader)37 Writer (java.io.Writer)37 MalformedURLException (java.net.MalformedURLException)37