// Calculate the usenames based on the relativized filenames on the filesystem
if (baseDir == null)
baseDir = new File(SystemProperties.getProperty("user.dir"));
ResourceLoader cpResourceLoader = null;
Map sourcesToCopyMap = new HashMap();
if (classpath != null)
cpResourceLoader = new PathResourceLoader(classpath);
boolean result = true;
File schemasDir = IOUtil.createDir(classesDir, "schema" + SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/src");
// build the in-memory type system
XmlErrorWatcher errorListener = new XmlErrorWatcher(outerErrorListener);
SchemaTypeSystem system = loadTypeSystem(name, xsdFiles, wsdlFiles, urlFiles, configFiles,
javaFiles, cpResourceLoader, download, noUpa, noPvr, noAnn, noVDoc, noExt, mdefNamespaces,
baseDir, sourcesToCopyMap, errorListener, schemasDir, cmdLineEntRes, classpath, javasource);
if (errorListener.hasError())
result = false;
long finish = System.currentTimeMillis();
if (!quiet)
System.out.println("Time to build schema type system: " + ((double)(finish - start) / 1000.0) + " seconds" );
// now code generate and compile the JAR
if (result && system != null) // todo: don't check "result" here if we want to compile anyway, ignoring invalid schemas
{
start = System.currentTimeMillis();
// filer implementation writes binary .xsd and generated source to disk
Repackager repackager = (repackage == null ? null : new Repackager(repackage));
FilerImpl filer = new FilerImpl(classesDir, srcDir, repackager, verbose, incrSrcGen);
// currently just for schemaCodePrinter
XmlOptions options = new XmlOptions();
if (codePrinter != null)
options.setSchemaCodePrinter(codePrinter);
if (javasource != null)
options.setGenerateJavaVersion(javasource);
// save .xsb files
system.save(filer);
// gen source files
result &= SchemaTypeSystemCompiler.generateTypes(system, filer, options);
if (incrSrcGen)
{
// We have to delete extra source files that may be out of date
SchemaCodeGenerator.deleteObsoleteFiles(srcDir, srcDir,
new HashSet(filer.getSourceFiles()));
}
if (result)
{
finish = System.currentTimeMillis();
if (!quiet)
System.out.println("Time to generate code: " + ((double)(finish - start) / 1000.0) + " seconds" );
}
// compile source
if (result && !nojavac)
{
start = System.currentTimeMillis();
List sourcefiles = filer.getSourceFiles();
if (javaFiles != null)
sourcefiles.addAll(java.util.Arrays.asList(javaFiles));
if (!CodeGenUtil.externalCompile(sourcefiles, classesDir, classpath, debug, compiler, javasource, memoryInitialSize, memoryMaximumSize, quiet, verbose))
result = false;
finish = System.currentTimeMillis();
if (result && !params.isQuiet())
System.out.println("Time to compile code: " + ((double)(finish - start) / 1000.0) + " seconds" );
// jar classes and .xsb
if (result && outputJar != null)
{
try
{
new JarHelper().jarDir(classesDir, outputJar);
}
catch (IOException e)
{
System.err.println("IO Error " + e);
result = false;
}
if (result && !params.isQuiet())
System.out.println("Compiled types to: " + outputJar);
}
}
}
if (!result && !quiet)
{
System.out.println("BUILD FAILED");
}
else {
// call schema compiler extension if registered
runExtensions(extensions, system, classesDir);
}
if (cpResourceLoader != null)
cpResourceLoader.close();
return result;
}