use of org.apache.maven.plugin.MojoExecutionException in project querydsl by querydsl.
the class AbstractMetaDataExportMojo method execute.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (isForTest()) {
project.addTestCompileSourceRoot(targetFolder);
} else {
project.addCompileSourceRoot(targetFolder);
}
if (skip) {
return;
}
try {
Configuration configuration = new Configuration(SQLTemplates.DEFAULT);
NamingStrategy namingStrategy;
if (namingStrategyClass != null) {
namingStrategy = (NamingStrategy) Class.forName(namingStrategyClass).newInstance();
} else {
namingStrategy = new DefaultNamingStrategy();
}
// defaults for Scala
if (createScalaSources) {
if (serializerClass == null) {
serializerClass = "com.querydsl.scala.sql.ScalaMetaDataSerializer";
}
if (exportBeans && beanSerializerClass == null) {
beanSerializerClass = "com.querydsl.scala.ScalaBeanSerializer";
}
}
MetaDataExporter exporter = new MetaDataExporter();
exporter.setNamePrefix(emptyIfSetToBlank(namePrefix));
exporter.setNameSuffix(Strings.nullToEmpty(nameSuffix));
exporter.setBeanPrefix(Strings.nullToEmpty(beanPrefix));
exporter.setBeanSuffix(Strings.nullToEmpty(beanSuffix));
if (beansTargetFolder != null) {
exporter.setBeansTargetFolder(new File(beansTargetFolder));
}
exporter.setCreateScalaSources(createScalaSources);
exporter.setPackageName(packageName);
exporter.setBeanPackageName(beanPackageName);
exporter.setInnerClassesForKeys(innerClassesForKeys);
exporter.setTargetFolder(new File(targetFolder));
exporter.setNamingStrategy(namingStrategy);
exporter.setSchemaPattern(schemaPattern);
exporter.setTableNamePattern(tableNamePattern);
exporter.setColumnAnnotations(columnAnnotations);
exporter.setValidationAnnotations(validationAnnotations);
exporter.setSchemaToPackage(schemaToPackage);
exporter.setLowerCase(lowerCase);
exporter.setExportTables(exportTables);
exporter.setExportViews(exportViews);
exporter.setExportAll(exportAll);
exporter.setTableTypesToExport(tableTypesToExport);
exporter.setExportPrimaryKeys(exportPrimaryKeys);
exporter.setExportForeignKeys(exportForeignKeys);
exporter.setExportDirectForeignKeys(exportDirectForeignKeys);
exporter.setExportInverseForeignKeys(exportInverseForeignKeys);
exporter.setSpatial(spatial);
if (imports != null && imports.length > 0) {
exporter.setImports(imports);
}
if (serializerClass != null) {
try {
exporter.setSerializerClass((Class) Class.forName(serializerClass));
} catch (ClassNotFoundException e) {
getLog().error(e);
throw new MojoExecutionException(e.getMessage(), e);
}
}
if (exportBeans) {
if (beanSerializerClass != null) {
exporter.setBeanSerializerClass((Class) Class.forName(beanSerializerClass));
} else {
BeanSerializer serializer = new BeanSerializer();
if (beanInterfaces != null) {
for (String iface : beanInterfaces) {
int sepIndex = iface.lastIndexOf('.');
if (sepIndex < 0) {
serializer.addInterface(new SimpleType(iface));
} else {
String packageName = iface.substring(0, sepIndex);
String simpleName = iface.substring(sepIndex + 1);
serializer.addInterface(new SimpleType(iface, packageName, simpleName));
}
}
}
serializer.setAddFullConstructor(beanAddFullConstructor);
serializer.setAddToString(beanAddToString);
serializer.setPrintSupertype(beanPrintSupertype);
exporter.setBeanSerializer(serializer);
}
}
String sourceEncoding = (String) project.getProperties().get("project.build.sourceEncoding");
if (sourceEncoding != null) {
exporter.setSourceEncoding(sourceEncoding);
}
if (customTypes != null) {
for (String cl : customTypes) {
configuration.register((Type<?>) Class.forName(cl).newInstance());
}
}
if (typeMappings != null) {
for (TypeMapping mapping : typeMappings) {
mapping.apply(configuration);
}
}
if (numericMappings != null) {
for (NumericMapping mapping : numericMappings) {
mapping.apply(configuration);
}
}
if (renameMappings != null) {
for (RenameMapping mapping : renameMappings) {
mapping.apply(configuration);
}
}
if (columnComparatorClass != null) {
try {
exporter.setColumnComparatorClass((Class) Class.forName(this.columnComparatorClass).asSubclass(Comparator.class));
} catch (ClassNotFoundException e) {
getLog().error(e);
throw new MojoExecutionException(e.getMessage(), e);
}
}
exporter.setConfiguration(configuration);
Class.forName(jdbcDriver);
String user;
String password;
if (server == null) {
user = jdbcUser;
password = jdbcPassword;
} else {
AuthenticationInfo info = wagonManager.getAuthenticationInfo(server);
if (info == null) {
throw new MojoExecutionException("No authentication info for server " + server);
}
user = info.getUserName();
if (user == null) {
throw new MojoExecutionException("Missing username from server " + server);
}
password = info.getPassword();
if (password == null) {
throw new MojoExecutionException("Missing password from server " + server);
}
}
Connection conn = DriverManager.getConnection(jdbcUrl, user, password);
try {
exporter.export(conn.getMetaData());
} finally {
if (conn != null) {
conn.close();
}
}
} catch (ClassNotFoundException e) {
throw new MojoExecutionException(e.getMessage(), e);
} catch (SQLException e) {
throw new MojoExecutionException(e.getMessage(), e);
} catch (InstantiationException e) {
throw new MojoExecutionException(e.getMessage(), e);
} catch (IllegalAccessException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project randomizedtesting by randomizedtesting.
the class JUnit4Mojo method validateParameters.
/**
* Initial validation of input parameters and configuration.
*/
private void validateParameters() throws MojoExecutionException {
// Check for junit dependency on project level.
Artifact junitArtifact = projectArtifactMap.get(junitArtifactName);
if (junitArtifact == null) {
throw new MojoExecutionException("Missing JUnit artifact in project dependencies: " + junitArtifactName);
}
checkVersion("JUnit", "[4.10,)", junitArtifact);
// Fill in complex defaults if not given.
if (includes == null || includes.isEmpty()) {
includes = Arrays.asList("**/Test*.class", "**/*Test.class");
}
if (excludes == null || excludes.isEmpty()) {
excludes = Arrays.asList("**/*$*.class");
}
}
use of org.apache.maven.plugin.MojoExecutionException in project randomizedtesting by randomizedtesting.
the class JUnit4Mojo method execute.
/**
* Run the mojo.
*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if ("pom".equals(packaging)) {
getLog().debug("Skipping execution for packaging \"" + packaging + "\"");
return;
}
// Check directory existence first.
if (!dir.isDirectory() || !tempDir.isDirectory()) {
getLog().warn("Location does not exist or is not a directory: " + dir.getAbsolutePath());
skipTests = true;
}
if (skipTests) {
return;
}
validateParameters();
// Ant project setup.
final Project antProject = new Project();
antProject.init();
antProject.setBaseDir(dir);
antProject.addBuildListener(new MavenListenerAdapter(getLog()));
// Generate JUnit4 ANT task model and generate a synthetic ANT file.
Document doc = DocumentFactory.getInstance().createDocument();
try {
populateJUnitElement(createDocumentSkeleton(doc));
File tempAntFile = createTemporaryAntFile(doc);
ProjectHelper.configureProject(antProject, tempAntFile);
try {
antProject.executeTarget(DEFAULT_TARGET);
} finally {
if (!leaveTemporary) {
tempAntFile.delete();
}
}
} catch (IOException e) {
throw new MojoExecutionException("An I/O error occurred: " + e.getMessage(), e);
} catch (BuildException e) {
throw new MojoExecutionException(e.getMessage(), e.getCause());
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project byte-buddy by raphw.
the class ByteBuddyMojo method processOutputDirectory.
/**
* Processes all class files within the given directory.
*
* @param root The root directory to process.
* @param classPath A list of class path elements expected by the processed classes.
* @throws MojoExecutionException If the user configuration results in an error.
* @throws MojoFailureException If the plugin application raises an error.
* @throws IOException If an I/O exception occurs.
*/
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Applies Maven exception wrapper")
private void processOutputDirectory(File root, List<? extends String> classPath) throws MojoExecutionException, MojoFailureException, IOException {
if (!root.isDirectory()) {
throw new MojoExecutionException("Target location does not exist or is no directory: " + root);
}
ClassLoaderResolver classLoaderResolver = new ClassLoaderResolver(getLog(), repositorySystem, repositorySystemSession, remoteRepositories);
try {
List<Plugin> plugins = new ArrayList<Plugin>(transformations.size());
for (Transformation transformation : transformations) {
String plugin = transformation.getPlugin();
try {
plugins.add((Plugin) Class.forName(plugin, false, classLoaderResolver.resolve(transformation.asCoordinate(groupId, artifactId, version))).getDeclaredConstructor().newInstance());
getLog().info("Created plugin: " + plugin);
} catch (Exception exception) {
throw new MojoExecutionException("Cannot create plugin: " + transformation.getRawPlugin(), exception);
}
}
EntryPoint entryPoint = (initialization == null ? Initialization.makeDefault() : initialization).getEntryPoint(classLoaderResolver, groupId, artifactId, version);
getLog().info("Resolved entry point: " + entryPoint);
transform(root, entryPoint, classPath, plugins);
} finally {
classLoaderResolver.close();
}
}
use of org.apache.maven.plugin.MojoExecutionException in project byte-buddy by raphw.
the class ByteBuddyMojo method transform.
/**
* Applies all registered transformations.
*
* @param root The root directory to process.
* @param entryPoint The transformation's entry point.
* @param classPath A list of class path elements expected by the processed classes.
* @param plugins The plugins to apply.
* @throws MojoExecutionException If the user configuration results in an error.
* @throws MojoFailureException If the plugin application raises an error.
* @throws IOException If an I/O exception occurs.
*/
private void transform(File root, EntryPoint entryPoint, List<? extends String> classPath, List<Plugin> plugins) throws MojoExecutionException, MojoFailureException, IOException {
List<ClassFileLocator> classFileLocators = new ArrayList<ClassFileLocator>(classPath.size() + 1);
classFileLocators.add(new ClassFileLocator.ForFolder(root));
for (String target : classPath) {
File artifact = new File(target);
classFileLocators.add(artifact.isFile() ? ClassFileLocator.ForJarFile.of(artifact) : new ClassFileLocator.ForFolder(artifact));
}
ClassFileLocator classFileLocator = new ClassFileLocator.Compound(classFileLocators);
try {
TypePool typePool = new TypePool.Default.WithLazyResolution(new TypePool.CacheProvider.Simple(), classFileLocator, TypePool.Default.ReaderMode.FAST, TypePool.ClassLoading.ofBootPath());
getLog().info("Processing class files located in in: " + root);
ByteBuddy byteBuddy;
try {
byteBuddy = entryPoint.getByteBuddy();
} catch (Throwable throwable) {
throw new MojoExecutionException("Cannot create Byte Buddy instance", throwable);
}
processDirectory(root, root, byteBuddy, entryPoint, suffix == null || suffix.isEmpty() ? MethodNameTransformer.Suffixing.withRandomSuffix() : new MethodNameTransformer.Suffixing(suffix), classFileLocator, typePool, plugins);
} finally {
classFileLocator.close();
}
}
Aggregations