List of usage examples for org.apache.maven.plugin MojoExecutionException MojoExecutionException
public MojoExecutionException(String message)
MojoExecutionException
exception providing a message
. From source file:com.all4tec.sa.maven.proguard.ProGuardMojo.java
License:Apache License
private static File getProguardJar(ProGuardMojo mojo) throws MojoExecutionException { Artifact proguardArtifact = null;/*from w w w . j a v a 2 s.c o m*/ int proguardArtifactDistance = -1; // This should be solved in Maven 2.1 for (Iterator i = mojo.pluginArtifacts.iterator(); i.hasNext();) { Artifact artifact = (Artifact) i.next(); mojo.getLog().debug("pluginArtifact: " + artifact.getFile()); if (artifact.getArtifactId().startsWith("proguard") && !artifact.getArtifactId().startsWith("proguard-maven-plugin")) { int distance = artifact.getDependencyTrail().size(); mojo.getLog().debug("proguard DependencyTrail: " + distance); if ((mojo.proguardVersion != null) && (mojo.proguardVersion.equals(artifact.getVersion()))) { proguardArtifact = artifact; break; } else if (proguardArtifactDistance == -1) { proguardArtifact = artifact; proguardArtifactDistance = distance; } else if (distance < proguardArtifactDistance) { proguardArtifact = artifact; proguardArtifactDistance = distance; } } } if (proguardArtifact != null) { mojo.getLog().debug("proguardArtifact: " + proguardArtifact.getFile()); return proguardArtifact.getFile().getAbsoluteFile(); } mojo.getLog().info("proguard jar not found in pluginArtifacts"); ClassLoader cl; cl = mojo.getClass().getClassLoader(); // cl = Thread.currentThread().getContextClassLoader(); String classResource = "/" + mojo.proguardMainClass.replace('.', '/') + ".class"; URL url = cl.getResource(classResource); if (url == null) { throw new MojoExecutionException( "Obfuscation failed ProGuard (" + mojo.proguardMainClass + ") not found in classpath"); } String proguardJar = url.toExternalForm(); if (proguardJar.startsWith("jar:file:")) { proguardJar = proguardJar.substring("jar:file:".length()); proguardJar = proguardJar.substring(0, proguardJar.indexOf('!')); } else { throw new MojoExecutionException("Unrecognized location (" + proguardJar + ") in classpath"); } return new File(proguardJar); }
From source file:com.all4tec.sa.maven.proguard.ProGuardMojo.java
License:Apache License
private static void proguardMain(File proguardJar, ArrayList<String> argsList, ProGuardMojo mojo) throws MojoExecutionException { Java java = new Java(); Project antProject = new Project(); antProject.setName(mojo.mavenProject.getName()); antProject.init();// w ww.j av a2s. com DefaultLogger antLogger = new DefaultLogger(); antLogger.setOutputPrintStream(System.out); antLogger.setErrorPrintStream(System.err); antLogger.setMessageOutputLevel(mojo.log.isDebugEnabled() ? Project.MSG_DEBUG : Project.MSG_INFO); antProject.addBuildListener(antLogger); antProject.setBaseDir(mojo.mavenProject.getBasedir()); java.setProject(antProject); java.setTaskName("proguard"); mojo.getLog().info("proguard jar: " + proguardJar); java.createClasspath().setLocation(proguardJar); // java.createClasspath().setPath(System.getProperty("java.class.path")); java.setClassname(mojo.proguardMainClass); java.setFailonerror(true); java.setFork(true); // get the maxMemory setting if (mojo.maxMemory != null) { java.setMaxmemory(mojo.maxMemory); } for (Iterator<String> i = argsList.iterator(); i.hasNext();) { java.createArg().setValue(i.next()); } int result = java.executeJava(); if (result != 0) { throw new MojoExecutionException("Obfuscation failed (result=" + result + ")"); } }
From source file:com.all4tec.sa.maven.proguard.ProGuardMojo.java
License:Apache License
private static Artifact getDependancy(Inclusion inc, MavenProject mavenProject) throws MojoExecutionException { Set dependancy = mavenProject.getArtifacts(); for (Iterator i = dependancy.iterator(); i.hasNext();) { Artifact artifact = (Artifact) i.next(); if (inc.match(artifact)) { return artifact; }// w w w.j a v a2 s .c o m } throw new MojoExecutionException("artifactId Not found " + inc.artifactId); }
From source file:com.all4tec.sa.maven.proguard.ProGuardMojo.java
License:Apache License
private static File getClasspathElement(Artifact artifact, MavenProject mavenProject) throws MojoExecutionException { if (artifact.getClassifier() != null) { return artifact.getFile(); }// w ww . ja v a 2s . c o m String refId = artifact.getGroupId() + ":" + artifact.getArtifactId(); MavenProject project = (MavenProject) mavenProject.getProjectReferences().get(refId); if (project != null) { return new File(project.getBuild().getOutputDirectory()); } else { File file = artifact.getFile(); if ((file == null) || (!file.exists())) { throw new MojoExecutionException("Dependency Resolution Required " + artifact); } return file; } }
From source file:com.alphacsp.maven.plugins.sonarj.SonarReportMojo.java
public void execute() throws MojoExecutionException, MojoFailureException { if (report == null) report = new File(getProject().getReporting().getOutputDirectory(), SONARJ); if (!report.exists()) { report.mkdirs();// w w w . ja va2 s .c om } if (sonarHome == null) { throw new MojoExecutionException("Sonar Home is mandatory"); } String sonarHomePath = sonarHome.getAbsolutePath(); if (!sonarHome.exists() || !sonarHome.isDirectory()) { throw new MojoExecutionException( "Sonar Home " + sonarHomePath + " does not exists or is not a directory"); } if (license == null) { throw new MojoExecutionException("Providing a license file is mandatory"); } String licensePath = license.getAbsolutePath(); if (!license.exists() || !license.isFile()) { throw new MojoExecutionException("License file " + licensePath + " does not exists or is not a file"); } if (architectureDescription == null) { throw new MojoExecutionException("Providing an architecture description file is mandatory"); } String architectureDescriptionPath = architectureDescription.getAbsolutePath(); if (!architectureDescription.exists() || !architectureDescription.isFile()) { throw new MojoExecutionException("Architecture description file " + architectureDescriptionPath + " does not exists or is not a file"); } if (workspaceDescription == null) { // TODO: generate it File sonarOutDir = new File(getProject().getBuild().getDirectory(), SONARJ); if (!sonarOutDir.exists()) { sonarOutDir.mkdirs(); } workspaceDescription = new File(sonarOutDir.getAbsolutePath(), getProject().getArtifactId() + "-workspace.xml"); } Project antProject = getAntProject(); SonarJAntTask sonarJTask = new SonarJAntTask(); sonarJTask.setProject(antProject); sonarJTask.setLicense(new Path(antProject, licensePath)); sonarJTask.setWorkspaceDescription(new Path(antProject, workspaceDescription.getAbsolutePath())); sonarJTask.setReport(new Path(antProject, report.getAbsolutePath())); sonarJTask.setArchitectureDescription(new Path(antProject, architectureDescriptionPath)); sonarJTask.execute(); }
From source file:com.ankhcraft.maven.plugin.gem.GenerateGemspecMojo.java
License:Open Source License
/** Generates the gemspec. */ public void execute() throws MojoExecutionException { StringBuilder sb = new StringBuilder("--- !ruby/object:Gem::Specification\n"); sb.append("name: ").append(baseName).append("\n"); sb.append("version: !ruby/object:Gem::Version\n version: ").append(version).append("\n"); sb.append("platform: ").append(platform).append("\n"); String authors[] = getAuthors(); writeStringArray(sb, null, "authors", authors); String binDir = getBinDir();/*from w w w .j a va2 s . co m*/ if (binDir != null) sb.append("bindir: ").append(binDir).append("\n"); sb.append("cert_chain: []\n\n"); String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").format(new Date()); int n = date.length() - 2; sb.append("date: ").append(date.substring(0, n)).append(":").append(date.substring(n)).append("\n"); sb.append("default_executable: ").append(defaultExecutable == null ? "" : defaultExecutable).append("\n"); sb.append("dependencies: "); List<Artifact> deps = getGemDependencies(); if (deps != null && deps.size() > 0) { sb.append("\n"); for (Artifact dep : deps) { sb.append("- !ruby/object:Gem::Dependency\n"); sb.append(" name:").append(dep.getArtifactId()).append("\n"); sb.append(" type: :runtime\n"); sb.append(" version_requirement:\n"); sb.append(" version_requirements: !ruby/object:Gem::Requirement\n"); sb.append(" requirements:\n"); sb.append(" - - \">=\"\n"); sb.append(" - - !ruby/object:Gem::Version\n"); sb.append(" - - version: \"").append(dep.getVersion()).append("\n"); sb.append(" version:\n"); dep.getVersion(); } } else sb.append("[]\n\n"); String desc = getProject().getDescription(); if (desc != null && (desc = desc.trim()).length() > 0) sb.append("description: |\n ").append(desc).append("\n\n"); sb.append("email: ").append(getEmail()).append("\n"); writeStringArray(sb, null, "executables", getExecutables()); writeStringArray(sb, null, "extensions", getExtensions()); writeStringArray(sb, null, "extra_rdoc_files", extraRdocFiles); writeStringList(sb, null, "files", getGemFiles()); sb.append("has_rdoc: true\n"); sb.append("licenses: []\n"); sb.append("rdoc_options:\n- --charset=UTF-8\nrequire_paths:\n- lib\n"); if (rubyforgeProject != null) sb.append("rubyforge_project: ").append(rubyforgeProject).append("\n"); sb.append("required_rubygems_version: "); sb.append(requiredRubygemsVersion == null ? "" : requiredRubygemsVersion).append("\n"); sb.append("required_ruby_version: "); sb.append(requiredRubyVersion == null ? "" : requiredRubyVersion).append("\n"); sb.append("rubygems_version: ").append(rubygemsVersion).append("\n"); sb.append("signing_key:\n"); sb.append("specification_version: 3\n"); sb.append("summary: ").append(getProject().getName()).append("\n"); writeStringList(sb, null, "test_files", getGemTestFiles()); File gemspec = getGemFile(outputDirectory, finalName, null, "gemspec"); if (gemspec.exists() && !gemspec.delete()) throw new MojoExecutionException("Failed to delete previous gemspec: " + gemspec); BufferedWriter wr = null; try { gemspec.getParentFile().mkdir(); gemspec.createNewFile(); wr = new BufferedWriter(new FileWriter(gemspec), 4096); wr.write(sb.toString()); wr.flush(); } catch (IOException e) { throw new MojoExecutionException("IO error while writing gemspec (" + gemspec.getAbsolutePath() + ")", e); } finally { try { if (wr != null) wr.close(); } catch (IOException ignore) { } } }
From source file:com.anthemengineering.mojo.infer.InferMojo.java
License:Apache License
/** * Downloads a distribution of Infer appropriate for the current operating system or fails if the current * operating system is not supported./*from w ww. j a v a2 s. co m*/ * @param inferDownloadDir directory to which to download Infer * @return the path to the executable Infer script * @throws MojoExecutionException if an Exception occurs that should fail execution */ private String downloadInfer(File inferDownloadDir) throws MojoExecutionException { getLog().info("Maven-infer-plugin is configured to download Infer. Downloading now."); URL url = null; try { final OperatingSystem system = currentOs(); if (downloadUrl != null) { url = new URL(downloadUrl); } else if (system == OperatingSystem.OSX) { url = new URL(OSX_INFER_DOWNLOAD_URL); } else if (system == OperatingSystem.LINUX) { url = new URL(LINUX_INFER_DOWNLOAD_URL); } else { final String errMsg = String.format( "Unsupported operating system: %s. Cannot continue Infer analysis.", System.getProperty(OS_NAME)); getLog().error(errMsg); throw new MojoExecutionException(errMsg); } getLog().info(String.format("Downloading: %s", downloadUrl.toString())); final File downloadedFile = new File(inferDownloadDir, url.getFile()); // TODO: could make these configurable FileUtils.copyURLToFile(url, downloadedFile, CONNECTION_TIMEOUT, READ_TIMEOUT); getLog().info( String.format("Infer downloaded to %s; now extracting.", inferDownloadDir.getAbsolutePath())); extract(downloadedFile, inferDownloadDir); getLog().info("Infer has been extracted, continuing with Infer check."); final Collection<File> files = FileUtils.listFiles(inferDownloadDir, null, true); for (final File file : files) { if (INFER_CMD_NAME.equals(file.getName()) && "bin".equals(file.getParentFile().getName())) { return file.getAbsolutePath(); } } } catch (MalformedURLException e) { final String errMsg = String.format("URL was malformed: " + url); getLog().error(errMsg, e); throw new MojoExecutionException(errMsg, e); } catch (final IOException e) { final String errMsg = String.format("Unable to get Infer from URL: %s! Cannot continue Infer check.", url); getLog().error(errMsg, e); throw new MojoExecutionException(errMsg, e); } throw new MojoExecutionException("Unable to download infer! Aborting execution..."); }
From source file:com.anthemengineering.mojo.rpmbuild.RpmbuildMojo.java
License:Apache License
private void executeRpmbuild() throws MojoExecutionException { Commandline cl = new Commandline(); cl.setExecutable("rpmbuild"); cl.createArg().setValue("-ba"); cl.createArg().setValue("--define"); cl.createArg().setValue("_topdir " + topdir.getAbsolutePath()); for (Map.Entry<String, String> e : defines.entrySet()) { cl.createArg().setValue("--define"); cl.createArg().setValue(String.format("%s %s", e.getKey(), e.getValue())); }//w ww .ja v a2 s . c om cl.createArg().setValue(new File(new File(topdir, "SPECS"), spec.getName()).getAbsolutePath()); try { getLog().info("Executing " + cl.toString()); Process process = cl.execute(); int rval = process.waitFor(); if (rval != 0) { throw new MojoExecutionException("Failed to execute: " + cl.getLiteralExecutable()); } } catch (CommandLineException e) { throw new MojoExecutionException("Failed to execute: " + cl.getLiteralExecutable(), e); } catch (InterruptedException e) { throw new MojoExecutionException("Failed to execute: " + cl.getLiteralExecutable(), e); } }
From source file:com.antwerkz.sofia.SofiaMojo.java
License:Apache License
public void generate() throws IOException, MojoExecutionException { if (!inputFile.exists()) { throw new MojoExecutionException("Missing inputFile file: " + inputFile); }/*from w ww . j a va 2 s .c o m*/ new LocalizerGenerator(new SofiaConfig().setBundleName(inputFile.getName()).setPackageName(packageName) .setProperties(inputFile).setType(loadLoggingType()).setUseControl(playController) .setOutputDirectory(outputDirectory).setGenerateJavascript(javascript) .setJavascriptOutputFile(jsOutputFile).setCharset(Charset.forName(charset))).write(); }
From source file:com.antwerkz.sofia.SofiaMojo.java
License:Apache License
private LoggingType loadLoggingType() throws MojoExecutionException { try {/*from w w w. j a v a 2 s.c o m*/ return loggingType == null ? null : LoggingType.valueOf(loggingType.toUpperCase()); } catch (IllegalArgumentException e) { throw new MojoExecutionException("Unknown logging type: " + loggingType); } }