List of usage examples for org.apache.maven.plugin MojoExecutionException MojoExecutionException
public MojoExecutionException(String message)
MojoExecutionException
exception providing a message
. From source file:com.basistech.autogen.AutogenMojo.java
License:Open Source License
/** {@inheritDoc} */ public void execute() throws MojoExecutionException, MojoFailureException { File f = outputDirectory;/*from w w w . j a v a2 s . co m*/ if (!f.exists()) { f.mkdirs(); } if (project != null && outputDirectory != null && outputDirectory.exists()) { project.addCompileSourceRoot(outputDirectory.getAbsolutePath()); } for (Template template : templates) { List<String> args = new ArrayList<String>(); args.add("autogen.py"); args.add("-t"); if (!template.getCode().exists()) { throw new MojoExecutionException( String.format("Template %s does not exist.", template.getCode().getAbsolutePath())); } args.add(template.getCode().getAbsolutePath()); args.add("-o"); File outputDir = outputDirectory; if (template.getPackageName() != null) { String dirTail = template.getPackageName().replaceAll("\\.", "/"); outputDir = new File(outputDir, dirTail); } if (!outputDir.exists()) { outputDir.mkdirs(); } String outName = template.getCode().getName().replace(String.format(".%1s.tpl", language), String.format(".%1$s", language)); File of = new File(outputDir, outName); args.add(of.getAbsolutePath()); args.add(template.getData().getAbsolutePath()); getLog().info("Running: " + args); runAutogen(pySystemState, args.toArray(new String[args.size()])); } }
From source file:com.basistech.bbhmp.OsgiVersionMojo.java
License:Open Source License
public void execute() throws MojoExecutionException { boolean snapshot = project.getVersion().endsWith("-SNAPSHOT"); boolean hasQualifier = false; String result;// w w w .j a va 2 s. c o m Matcher matcher = CXX_PATTERN.matcher(project.getVersion()); if (matcher.matches()) { result = String.format("%s_%s", matcher.group(1), matcher.group(2)); hasQualifier = true; // c-number is always a qualifier } else { matcher = PLAIN_PATTERN.matcher(project.getVersion()); if (matcher.matches()) { String major = matcher.group("major"); String minor = matcher.group("minor"); String patch = matcher.group("patch"); String qualifier = matcher.group("qualifier"); hasQualifier = qualifier != null; result = String.format("%s.%s.%s%s", major, minor == null ? "0" : minor, patch == null ? "0" : patch, qualifier == null ? "" : qualifier); } else { throw new MojoExecutionException(String.format( "Version %s does not match either x.y.z, x.y.z.cXX.Y(<qualifier>), or x.y.z.<qualifier>", project.getVersion())); } } if (snapshot || timestampQualifier) { SimpleDateFormat format = new SimpleDateFormat(TIMESTAMP_PATTERN); TimeZone timeZone = TimeZone.getTimeZone("GMT"); format.setTimeZone(timeZone); Date now = new Date(); Calendar calendar = new GregorianCalendar(); calendar.setTime(now); calendar.setTimeZone(timeZone); calendar.add(Calendar.SECOND, 0); /* add or update the qualifier */ result = result + (hasQualifier ? "-" : ".") + format.format(calendar.getTime()); } defineProperty(propertyName, result); }
From source file:com.basistech.bbhmp.RosapiBundleCollectorMojo.java
License:Open Source License
private void copyFile(File artifact, File destFile) throws MojoExecutionException { try {//from ww w.j a v a 2 s .co m getLog().info("Copying " + artifact.getAbsolutePath() + destFile); if (artifact.isDirectory()) { throw new MojoExecutionException("Artifact has not been packaged yet."); } FileUtils.copyFile(artifact, destFile); } catch (IOException e) { throw new MojoExecutionException("Error copying artifact from " + artifact + " to " + destFile, e); } }
From source file:com.basistech.oss.pump.PumpFindParentBasedirMojo.java
License:Apache License
/** {@inheritDoc}*/ public void execute() throws MojoExecutionException, MojoFailureException { for (MavenProject proj = project; proj != null; proj = proj.getParent()) { if (groupId.equals(proj.getGroupId()) && artifactId.equals(proj.getArtifactId())) { String absBase = proj.getBasedir().getAbsolutePath(); project.getProperties().put(propertyName, absBase); getLog().info("Setting " + propertyName + " to " + absBase); return; }/*from www . ja v a 2 s . c o m*/ } throw new MojoExecutionException("No parent had specified group:artifact"); }
From source file:com.basistech.ReleaseNoteMojo.java
License:Open Source License
private boolean getAuthFromSettings(Client client) throws MojoExecutionException { if (serverId == null) { return false; }//from w w w . j a va 2 s .c o m Server server = getServer(settings, serverId); if (server == null) { throw new MojoExecutionException( MessageFormat.format("Server ''{0}'' not found in settings", serverId)); } getLog().debug(MessageFormat.format("Using ''{0}'' server credentials", serverId)); try { SettingsDecrypter settingsDecrypter = container.lookup(SettingsDecrypter.class); SettingsDecryptionResult result = settingsDecrypter .decrypt(new DefaultSettingsDecryptionRequest(server)); server = result.getServer(); } catch (ComponentLookupException cle) { throw new MojoExecutionException("Unable to lookup SettingsDecrypter: " + cle.getMessage(), cle); } String serverUsername = server.getUsername(); String serverPassword = server.getPassword(); if (serverUsername != null && serverUsername.length() > 0 && serverPassword != null && serverPassword.length() > 0) { getLog().debug("Using basic authentication with username: " + serverUsername); setupBasicAuthentication(client, serverUsername, serverPassword); return true; } // A server password without a username is assumed to be an OAuth2 token if (serverPassword != null && serverPassword.length() > 0) { getLog().debug("Using OAuth2 access token authentication"); setupOauth2(client, serverPassword); return true; } getLog().debug(MessageFormat.format("Server ''{0}'' is missing username/password credentials", serverId)); return false; }
From source file:com.bealearts.livecycle.AppInfoMojo.java
License:Apache License
/** * Execute the Mojo//from w ww.j ava 2s. com */ public void execute() throws MojoExecutionException { if (!this.buildDirectory.exists()) { if (!this.buildDirectory.mkdirs()) throw new MojoExecutionException( "Error creating output directory: " + this.buildDirectory.getAbsolutePath()); } File classesFolder = new File(this.buildDirectory, "classes"); try { FileUtils.copyDirectory(this.sourceDirectory, classesFolder); } catch (IOException e) { throw new MojoExecutionException("Error copying source files", e); } LCAUtils lcaUtils = new LCAUtils(this.getLog()); LCADefinition lcaDef; try { lcaDef = lcaUtils.parseSourceFiles(classesFolder); } catch (Exception e) { throw new MojoExecutionException("Error parsing source files", e); } lcaDef.setCreatedBy(this.createdBy); lcaDef.setDescription(this.description); InputStream lcaTemplate = this.getClass().getClassLoader().getResourceAsStream("app.info.template"); String content; try { content = lcaUtils.renderAppInfo(lcaTemplate, lcaDef); } catch (IOException e) { throw new MojoExecutionException("Error loading template", e); } try { lcaUtils.writeAppInfo(classesFolder, content); } catch (IOException e) { throw new MojoExecutionException("Error writing app.info file to: " + classesFolder.getAbsolutePath(), e); } }
From source file:com.bekioui.maven.plugin.client.ClientMojo.java
License:Apache License
@SuppressWarnings("unchecked") @Override// w w w .ja v a2 s . c om public void execute() throws MojoExecutionException { if (!mavenProject.getArtifactId().equals(apiArtifactId)) { return; } if (mavenProject.getParent() == null) { throw new MojoExecutionException("API has to be a maven module with parent pom."); } List<Plugin> plugins = mavenProject.getParent().getBuildPlugins(); for (Plugin plugin : plugins) { if (!plugin.getGroupId().equals("com.bekioui.plugin") || !plugin.getArtifactId().equals("client-maven-plugin")) { continue; } if (!plugin.getExecutions().isEmpty()) { throw new MojoExecutionException("client-maven-plugin has to not contain execution configuration."); } break; } Properties properties = Properties.builder() // .apiUrl(apiUrl) // .apiArtifactId(apiArtifactId) // .clientArtifactId(clientArtifactId) // .clientPrefix(clientPrefix) // .resourcePackageName(resourcePackageName) // .build(); Project project = ProjectInitializer.initialize(mavenProject, properties); PomGenerator.generate(project); ClientConfigGenerator.generate(project); List<JavaSourceFile> javaSourceFiles = JavaFileInspector.inspect(project, resourcePackageName); List<Resource> resources = ResourceInspector.inspect(project, javaSourceFiles); TypeName clientFactoryType = ClientFactoryGenerator.generate(project, resources); List<ContextResource> contextResources = ContextGenerator.generate(project, resources, clientFactoryType); ClientGenerator.generate(project, contextResources, clientFactoryType); }
From source file:com.betfair.cougar.codegen.IdlToDSMojo.java
License:Apache License
private void writeWsdlStylesheet(File xslFile) throws Exception { if (wsdlXslResource == null) { throw new MojoExecutionException("wsdl resource not specified"); }//from w w w . ja v a 2 s . c o m FileUtil.resourceToFile(wsdlXslResource, xslFile, getClass()); getLog().debug("Wrote wsdl stylesheet from resource " + wsdlXslResource + " to " + xslFile); }
From source file:com.betfair.cougar.codegen.IdlToDSMojo.java
License:Apache License
private void writeXsdStylesheet(File xslFile) throws Exception { if (xsdXslResource == null) { throw new MojoExecutionException("xsd resource not specified"); }// w ww. ja va2 s .c o m FileUtil.resourceToFile(xsdXslResource, xslFile, getClass()); getLog().debug("Wrote xsd stylesheet from resource " + xsdXslResource + " to " + xslFile); }
From source file:com.betfair.cougar.codegen.IdlToDSMojo.java
License:Apache License
private void writeIDDStylesheet(File xslFile) throws Exception { if (iddStripperXslResource == null) { throw new MojoExecutionException("wsdl resource not specified"); }//from w w w . java2 s.c om FileUtil.resourceToFile(iddStripperXslResource, xslFile, getClass()); getLog().debug("Wrote IDD stylesheet from resource " + iddStripperXslResource + " to " + xslFile); }