List of usage examples for org.apache.maven.plugin MojoExecutionException MojoExecutionException
public MojoExecutionException(String message, Throwable cause)
MojoExecutionException
exception wrapping an underlying Throwable
and providing a message
. From source file:com.bekioui.maven.plugin.client.generator.FileGenerator.java
License:Apache License
public static void generate(Project project, String packageName, TypeSpec typeSpec) throws MojoExecutionException { try {/*from w w w . ja v a 2 s .c om*/ JavaFile javaFile = JavaFile.builder(packageName, typeSpec).build(); javaFile.writeTo(new File(project.clientDirectory(), SRC_FOLDER)); } catch (IOException e) { throw new MojoExecutionException("Failed to generate file.", e); } }
From source file:com.bekioui.maven.plugin.client.generator.PomGenerator.java
License:Apache License
public static void generate(Project project) throws MojoExecutionException { boolean overrideParent = false; Model parentModel = project.mavenProject().getParent().getOriginalModel(); if (!parentModel.getModules().contains(project.properties().clientArtifactId())) { overrideParent = true;/*from w w w . j a v a2 s . c o m*/ parentModel.getModules().add(project.properties().clientArtifactId()); } Model model = new Model(); model.setModelVersion("4.0.0"); Parent parent = new Parent(); parent.setGroupId(project.mavenProject().getParent().getGroupId()); parent.setArtifactId(project.mavenProject().getParent().getArtifactId()); parent.setVersion(project.mavenProject().getParent().getVersion()); model.setParent(parent); model.setArtifactId(project.properties().clientArtifactId()); List<Dependency> dependencies = new ArrayList<>(); Dependency apiDependency = new Dependency(); apiDependency.setGroupId(project.mavenProject().getGroupId()); apiDependency.setArtifactId(project.mavenProject().getArtifactId()); apiDependency.setVersion(project.mavenProject().getVersion()); dependencies.add(apiDependency); Dependency springContextDependency = new Dependency(); springContextDependency.setGroupId("org.springframework"); springContextDependency.setArtifactId("spring-context"); springContextDependency.setVersion("4.2.5.RELEASE"); dependencies.add(springContextDependency); Dependency jaxrsClientDependency = new Dependency(); jaxrsClientDependency.setGroupId("com.bekioui.jaxrs"); jaxrsClientDependency.setArtifactId("jaxrs-client"); jaxrsClientDependency.setVersion("1.1.1"); dependencies.add(jaxrsClientDependency); model.setDependencies(dependencies); try { MavenXpp3Writer writer = new MavenXpp3Writer(); if (overrideParent) { writer.write(new FileWriter(new File(parentModel.getProjectDirectory(), POM_FILE_NAME)), parentModel); } writer.write(new FileWriter(new File(project.clientDirectory(), POM_FILE_NAME)), model); } catch (IOException e) { throw new MojoExecutionException("Failed to create client pom.xml file.", e); } }
From source file:com.bekioui.maven.plugin.client.initializer.ProjectInitializer.java
License:Apache License
@SuppressWarnings("unchecked") public static Project initialize(MavenProject mavenProject, Properties properties) throws MojoExecutionException { String clientPackagename = mavenProject.getParent().getGroupId() + ".client"; String contextPackageName = clientPackagename + ".context"; String apiPackageName = clientPackagename + ".api"; String implPackageName = clientPackagename + ".impl"; String resourceBasedirPath = mavenProject.getBasedir().getAbsolutePath(); String projectBasedirPath = resourceBasedirPath.substring(0, resourceBasedirPath.lastIndexOf(File.separator)); File clientDirectory = new File(projectBasedirPath + File.separator + properties.clientArtifactId()); if (clientDirectory.exists()) { try {/*from w w w .jav a 2s. c om*/ FileUtils.deleteDirectory(clientDirectory); } catch (IOException e) { throw new MojoExecutionException("Failed to delete existing client directory.", e); } } clientDirectory.mkdir(); File javaSourceDirectory = new File(resourceBasedirPath + FULL_SRC_FOLDER + properties.resourcePackageName().replaceAll("\\.", File.separator)); if (!javaSourceDirectory.isDirectory()) { throw new MojoExecutionException( "Java sources directory not found: " + javaSourceDirectory.getAbsolutePath()); } List<String> classpathElements; try { classpathElements = mavenProject.getCompileClasspathElements(); } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException("Failed to get compile classpath elements.", e); } List<URL> classpaths = new ArrayList<>(); for (String element : classpathElements) { try { classpaths.add(new File(element).toURI().toURL()); } catch (MalformedURLException e) { throw new MojoExecutionException(element + " is an invalid classpath element.", e); } } return Project.builder() // .mavenProject(mavenProject) // .properties(properties) // .clientPackageName(clientPackagename) // .contextPackageName(contextPackageName) // .apiPackageName(apiPackageName) // .implPackageName(implPackageName) // .clientDirectory(clientDirectory) // .javaSourceDirectory(javaSourceDirectory) // .classpaths(classpaths) // .build(); }
From source file:com.bekioui.maven.plugin.client.inspector.ResourceInspector.java
License:Apache License
public static List<Resource> inspect(Project project, List<JavaSourceFile> javaSourceFiles) throws MojoExecutionException { try (URLClassLoader classLoader = new URLClassLoader(project.classPathsArray())) { List<Resource> resources = new ArrayList<>(); for (JavaSourceFile javaSourceFile : javaSourceFiles) { Class<?> resourceClass = classLoader.loadClass(javaSourceFile.path()); if (!resourceClass.isInterface()) { continue; }//from www. java2s. c o m String resourceFieldName = resourceClass.getSimpleName().substring(0, 1).toLowerCase() .concat(resourceClass.getSimpleName().substring(1)); List<MethodSpec> methods = new ArrayList<>(); for (Method method : resourceClass.getMethods()) { StringJoiner arguments = new StringJoiner(", ", "(", ")"); List<ParameterSpec> parameters = new ArrayList<>(); int count = 0; for (Type type : method.getGenericParameterTypes()) { String argument = ARGUMENT_NAME + count++; arguments.add(argument); parameters.add(ParameterSpec.builder(type, argument).build()); } String statement = (method.getReturnType().equals(void.class) ? "" : "return ") + resourceFieldName + "." + method.getName() + arguments.toString(); methods.add(MethodSpec.methodBuilder(method.getName()) // .addModifiers(Modifier.PUBLIC) // .returns(method.getGenericReturnType()) // .addParameters(parameters) // .addStatement(statement) // .build()); } resources.add(Resource.builder() // .className(resourceClass.getSimpleName())// .fieldName(resourceFieldName) // .typeName(ClassName.get(resourceClass).box()) // .methods(methods) // .build()); } return resources; } catch (IOException e) { throw new MojoExecutionException("Failed to initialize class loader.", e); } catch (ClassNotFoundException e) { throw new MojoExecutionException("Failed to load class.", e); } }
From source file:com.benasmussen.maven.plugin.i18n.InternationalizationMojo.java
License:Apache License
public void execute() throws MojoExecutionException { String currentFile = null;/* w ww . jav a2s . c o m*/ InputStream is = null; try { if (!outputDirectory.exists()) { getLog().info("Create output directory: " + outputDirectory); outputDirectory.mkdirs(); } // use default file if empty if (files == null || files.isEmpty()) { files = new ArrayList<String>(); files.add(DEFAULT_FILE); } // loop files for (String file : files) { currentFile = file; getLog().info("Process file " + file); is = new FileInputStream(file); // xls resource reader ResourceReader resourceReader = new ResourceReader(is); resourceReader.setKeyCell(keyCell); resourceReader.setLocaleCell(localeCell); resourceReader.process(); List<ResourceEntry> resultEntries = resourceReader.getEntries(); List<ResourceWriter> resourceWriter = new ArrayList<ResourceWriter>(); // properties if (outputFormat.contains(FORMAT_PROPERTIES)) { resourceWriter.add(new PropertiesResourceWriter()); } // json if (outputFormat.contains(FORMAT_JSON)) { resourceWriter.add(new JsonResourceWriter()); } // xml if (outputFormat.contains(FORMAT_XML)) { resourceWriter.add(new XmlResourceWriter()); } // process output writer for (ResourceWriter writer : resourceWriter) { writer.setOutputEnconding(outputEncoding); writer.setOutputFolder(outputDirectory); writer.setResourceEntries(resultEntries); writer.write(); } IOUtils.closeQuietly(is); } } catch (Exception e) { throw new MojoExecutionException("Error processing file " + currentFile, e); } finally { IOUtils.closeQuietly(is); } }
From source file:com.betfair.cougar.codegen.IdlToDSMojo.java
License:Apache License
public void execute() throws MojoExecutionException { getLog().info("Starting Cougar code generation"); if (isOffline()) { getLog().warn("Maven in offline mode, plugin is NOT validating IDDs against schemas"); } else {//w w w .ja va 2 s . c o m getLog().debug("Unbundling schemas for validation"); catalogFile = unwrapSchemas(); } initResourceLoader(); initResolver(); // needs the resource loader // load wsdl.xsl (as resource) and write (as file) to a working directory prepWsdlXsl(); // load xsd.xsl (as resource) and write (as file) to a working directory prepXsdXsl(); // load iddstripper.xsl (as resource) and write (as file) to a working directory prepIddStripperXsl(); try { getLog().debug("Starting IDL to Java"); for (Service service : getServices()) { processService(service); } // this replaces the functionality of build-helper-maven-plugin addSource(); } catch (Exception e) { getLog().error(e); throw new MojoExecutionException("Failed processing IDL: " + e, e); } getLog().info("Completed Cougar code generation"); }
From source file:com.betfair.cougar.codegen.IdlToDSMojo.java
License:Apache License
private void prepIddStripperXsl() throws MojoExecutionException { try {/*w w w . j a v a 2 s . c o m*/ iddStripperXsl = new File(getBaseDir(), iddStripperXslFile); initOutputDir(iddStripperXsl.getParentFile()); writeIDDStylesheet(iddStripperXsl); } catch (Exception e) { throw new MojoExecutionException("Failed to write local copy of IDD stripper stylesheet: " + e, e); } }
From source file:com.betfair.cougar.codegen.IdlToDSMojo.java
License:Apache License
/** * Read a wsdl.xsl (stylesheet) from a resource, and write it to a working directory. * * @return the on-disk wsdl.xsl file/*from w w w. ja v a2s . c om*/ */ private void prepWsdlXsl() throws MojoExecutionException { try { wsdlXsl = new File(getBaseDir(), wsdlXslFile); initOutputDir(wsdlXsl.getParentFile()); writeWsdlStylesheet(wsdlXsl); } catch (Exception e) { throw new MojoExecutionException("Failed to write local copy of WSDL stylesheet: " + e, e); } }
From source file:com.betfair.cougar.codegen.IdlToDSMojo.java
License:Apache License
/** * Read a wsdl.xsl (stylesheet) from a resource, and write it to a working directory. * * @return the on-disk wsdl.xsl file/*from w w w . j ava2 s . c o m*/ */ private void prepXsdXsl() throws MojoExecutionException { try { xsdXsl = new File(getBaseDir(), xsdXslFile); initOutputDir(xsdXsl.getParentFile()); writeXsdStylesheet(xsdXsl); } catch (Exception e) { throw new MojoExecutionException("Failed to write local copy of XSD stylesheet: " + e, e); } }
From source file:com.betfair.cougar.codegen.IdlToDSMojo.java
License:Apache License
private void initResourceLoader() throws MojoExecutionException { try {//from w w w . jav a 2 s. co m if (isIddAsResource()) { // we need this classLoader because it's the only way to get to the project dependencies resourceLoader = new ResourceLoader(getRuntimeClassPath()); } else { resourceLoader = new ResourceLoader(); } } catch (Exception e) { throw new MojoExecutionException("Error initialising classloader: " + e, e); } }