+ Set<URL> urls = new HashSet<URL>();
+ if (scanClasses)
+ {
+ getLog().debug("Only dependencies relative to persistent-unit " + unit.getName() + " are scanned!");
+ /**
+ * Scan the root of the persiten unit and configured jars for
+ * annotated classes
+ */
+ getLog().debug(" - adding " + unit.getPersistenceUnitRootUrl());
+ urls.add(unit.getPersistenceUnitRootUrl());
+ for (URL url : unit.getJarFileUrls())
+ {
+ getLog().debug(" - adding " + url);
+ urls.add(url);
+ }
+ if (scanTestClasses)
+ addRoot(urls, testOutputDirectory);
+ }
+ else
+ getLog().debug("Scanning of unlisted classes is prohibited in persistent-unit " + unit.getName());
+ 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
+ */
+ getLog().info("Adding mappings from persistence-unit " + unit.getName());
+ for (String mapping : unit.getMappingFileNames())
+ {
+ getLog().info(" - adding " + 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 */