// create final PEAR file object
File finalPearFileName = new File(this.targetDir, this.componentId
+ ".pear");
// log PEAR packaging details
Log log = getLog();
log.info("Start building PEAR package for component " + this.componentId);
log.debug("UIMA PEAR INFORMATION ");
log.debug("======================");
log.debug("main component dir: " + this.mainComponentDir);
log.debug("main component desc: " + this.mainComponentDesc);
log.debug("component id: " + this.componentId);
log.debug("classpath: " + this.classpath);
log.debug("datapath: " + this.datapath);
log.debug("target dir: " + this.targetDir);
log.debug("pear packaging dir: "
+ this.pearPackagingDir.getAbsolutePath());
log.debug("final PEAR file: " + finalPearFileName.getAbsolutePath());
// check Maven project packaging type - only jar packaging is supported
if (!this.project.getPackaging().equals("jar")) {
throw new MojoExecutionException(
"Wrong packaging type, only 'jar' packaging is supported");
}
try {
// copies all PEAR data to the PEAR packaging directory
copyPearData();
// copy created jar package to the PEAR packaging lib directory
// get jar file name
String jarFileName = this.project.getBuild().getFinalName() + ".jar";
// get jar file location
File finalJarFile = new File(this.project.getBuild().getDirectory(),
jarFileName);
// check if the jar file exist
if (finalJarFile.exists()) {
// specify the target directory for the jar file
File target = new File(this.pearPackagingDir,
InstallationController.PACKAGE_LIB_DIR);
File targetFile = new File(target, jarFileName);
// copy the jar file to the target directory
FileUtils.copyFile(finalJarFile, targetFile);
} else {
// jar file does not exist - build was not successful
String errorMessage = "Jar package "
+ finalJarFile.getAbsolutePath() + " not found";
log.debug(errorMessage);
throw new IOException(errorMessage);
}
// add compiled jar to the PEAR classpath
StringBuffer buffer = new StringBuffer();
buffer.append(";$main_root/");
buffer.append(InstallationController.PACKAGE_LIB_DIR);
buffer.append("/");
buffer.append(this.project.getBuild().getFinalName());
buffer.append(".jar");
String classpathExtension = buffer.toString();
if(this.classpath != null) {
this.classpath = this.classpath + classpathExtension;
} else {
this.classpath = classpathExtension.substring(1,classpathExtension.length());
}
// create the PEAR package
createPear();
// log success message
log.info("PEAR package for component " + this.componentId
+ " successfully created at: "
+ finalPearFileName.getAbsolutePath());
// set UIMA logger back to the original log level
UIMAFramework.getLogger().setLevel(level);
} catch (PackageCreatorException e) {
log.debug(e.getMessage());
throw new MojoExecutionException(e.getMessage());
} catch (IOException e) {
log.debug(e.getMessage());
throw new MojoExecutionException(e.getMessage());
}
}