+ /** Add the remaining class-path-elements */
+ completeClassPath(classLoader);
+
+ /** Apply mappings from hibernate-configuration, if present */
+ if (config != null)
+ {
+ for (MappingReference mapping : config.getMappingReferences())
+ mapping.apply(sources);
+ }
+
+ Set<String> classes;
+ if (unit == null)
+ {
+ /** No persistent unit: default behaviour */
+ if (scanClasses == null)
+ scanClasses = true;
+ Set<URL> urls = new HashSet<URL>();
+ if (scanClasses)
+ addRoot(urls, outputDirectory);
+ if (scanTestClasses)
+ addRoot(urls, testOutputDirectory);
+ addDependencies(urls);
+ classes = scanUrls(urls);
+ }
+ else
+ {
+ /** Follow configuration in persisten unit */
+ if (scanClasses == null)
+ scanClasses = !unit.isExcludeUnlistedClasses();
+ Set<URL> urls = new HashSet<URL>();
+ if (scanClasses)
+ {
+ /**
+ * Scan the root of the persiten unit and configured jars for
+ * annotated classes
+ */
+ urls.add(unit.getPersistenceUnitRootUrl());
+ for (URL url : unit.getJarFileUrls())
+ urls.add(url);
+ }
+ if (scanTestClasses)
+ addRoot(urls, testOutputDirectory);
+ classes = scanUrls(urls);
+ for (String className : unit.getManagedClassNames())
+ classes.add(className);
+ /**
+ * Add mappings from the default mapping-file
+ * <code>META-INF/orm.xml</code>, if present
+ */
+ boolean error = false;
+ InputStream is;
+ is = classLoader.getResourceAsStream("META-INF/orm.xml");
+ if (is != null)
+ {
+ getLog().info("Adding default JPA-XML-mapping from META-INF/orm.xml");
+ try
+ {
+ tracker.track("META-INF/orm.xml", is);
+ sources.addResource("META-INF/orm.xml");
+ }
+ catch (IOException e)
+ {
+ getLog().error("cannot read META-INF/orm.xml: " + e);
+ error = true;
+ }
+ }
+ else
+ {
+ getLog().debug("no META-INF/orm.xml found");
+ }
+ /**
+ * Add mappings from files, that are explicitly configured in the
+ * persistence unit
+ */
+ for (String mapping : unit.getMappingFileNames())
+ {
+ getLog().info("Adding explicitly configured mapping from " + mapping);
+ is = classLoader.getResourceAsStream(mapping);
+ if (is != null)
+ {
+ try
+ {
+ tracker.track(mapping, is);
+ sources.addResource(mapping);
+ }
+ catch (IOException e)
+ {
+ getLog().info("cannot read mapping-file " + mapping + ": " + e);
+ error = true;
+ }
+ }
+ else
+ {
+ getLog().error("cannot find mapping-file " + mapping);
+ error = true;
+ }
+ }
+ if (error)
+ throw new MojoFailureException(
+ "error, while reading mappings configured in persistence-unit \"" +
+ unit.getName() +
+ "\""
+ );
+ }
+
+ /** Add the configured/collected annotated classes */
+ for (String className : classes)
+ addAnnotated(className, sources, classLoaderService, tracker);
+
+ /** Add explicitly configured classes */