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.asual.summer.onejar.OneJarMojo.java
License:Apache License
public void execute() throws MojoExecutionException { JarOutputStream out = null;/* w ww . j a v a2 s . c om*/ JarInputStream in = null; try { File jarFile = new File(buildDirectory, jarName); File warFile = new File(buildDirectory, warName); Manifest manifest = new Manifest(new ByteArrayInputStream("Manifest-Version: 1.0\n".getBytes("UTF-8"))); manifest.getMainAttributes().putValue("Main-Class", JAR_MAIN_CLASS); manifest.getMainAttributes().putValue("One-Jar-Main-Class", ONE_JAR_MAIN_CLASS); out = new JarOutputStream(new FileOutputStream(jarFile, false), manifest); in = new JarInputStream(getClass().getClassLoader().getResourceAsStream(ONE_JAR_DIST)); putEntry(out, new FileInputStream(warFile), new ZipEntry(JAR_CLASSPATH + warFile.getName())); for (Artifact artifact : pluginArtifacts) { if (artifact.getArtifactId().equalsIgnoreCase("summer-onejar")) { artifact.updateVersion(artifact.getVersion(), localRepository); putEntry(out, new FileInputStream(artifact.getFile()), new ZipEntry(JAR_CLASSPATH + artifact.getFile().getName())); MavenProject project = mavenProjectBuilder.buildFromRepository(artifact, remoteArtifactRepositories, localRepository); List<Dependency> dependencies = project.getDependencies(); for (Dependency dependency : dependencies) { if (!"provided".equals(dependency.getScope())) { Artifact dependencyArtifact = artifactFactory.createArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getScope(), dependency.getType()); dependencyArtifact.updateVersion(dependencyArtifact.getVersion(), localRepository); putEntry(out, new FileInputStream(dependencyArtifact.getFile()), new ZipEntry(JAR_CLASSPATH + dependencyArtifact.getFile().getName())); } } } } while (true) { ZipEntry entry = in.getNextEntry(); if (entry != null) { putEntry(out, in, entry); } else { break; } } projectHelper.attachArtifact(project, "jar", jarFile); } catch (Exception e) { getLog().error(e.getMessage(), e); throw new MojoExecutionException(e.getMessage(), e); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(in); } }
From source file:com.atlassian.maven.plugin.clover.CloverCheckMojo.java
License:Apache License
/** * Check a Clover database and fail the build if the TPC is below the threshold. * * @param database the Clover database to verify * @throws MojoExecutionException when the TPC is below the threshold *///from w ww.j a v a 2 s.co m private void checkDatabase(final String database) throws MojoExecutionException { final Project antProject = new Project(); antProject.init(); AbstractCloverMojo.registerCloverAntTasks(antProject, getLog()); CloverPassTask cloverPassTask = createCloverPassTask(database, antProject); cloverPassTask.init(); cloverPassTask.setInitString(database); cloverPassTask.setHaltOnFailure(true); cloverPassTask.setFailureProperty("clovercheckproperty"); if (this.codeType != null) { cloverPassTask.setCodeType(codeType); } if (this.targetPercentage != null) { cloverPassTask.setTarget(new Percentage(this.targetPercentage)); getLog().info("Checking for coverage of [" + targetPercentage + "] for database [" + database + "]"); if (this.methodPercentage != null) { cloverPassTask.setMethodTarget(new Percentage(this.methodPercentage)); getLog().info("Checking for method coverage of [" + methodPercentage + "] for database [" + database + "]"); } if (this.conditionalPercentage != null) { cloverPassTask.setConditionalTarget(new Percentage(this.conditionalPercentage)); getLog().info("Checking for conditional coverage of [" + conditionalPercentage + "] for database [" + database + "]"); } if (this.statementPercentage != null) { cloverPassTask.setStatementTarget(new Percentage(this.statementPercentage)); getLog().info("Checking for statement coverage of [" + statementPercentage + "] for database [" + database + "]"); } } else if (this.historyDir.exists() && this.historyDir.isDirectory()) { cloverPassTask.setHistorydir(this.historyDir); cloverPassTask.setThreshold(new Percentage(this.historyThreshold)); getLog().info("Checking coverage against historical data [" + this.historyDir + " +/-" + this.historyThreshold + " ] for database [" + database + "]"); } else { getLog().warn("Skipping clover:check as 'maven.clover.targetPercentage' is not defined " + "and 'maven.clover.historyDir' (" + this.historyDir.getPath() + ") does not exist or is not a directory."); return; } if (this.contextFilters != null) { cloverPassTask.setFilter(this.contextFilters); } setTestSourceRoots(cloverPassTask); try { cloverPassTask.execute(); } catch (BuildException e) { getLog().error(antProject.getProperty("clovercheckproperty")); if (this.failOnViolation) { throw new MojoExecutionException(e.getMessage(), e); } else { getLog().warn("Clover test percentage coverage is below threshold but failOnViolation is set to " + " false, preventing the build from failing."); } } }
From source file:com.atlassian.maven.plugin.clover.CloverMergeMojo.java
License:Apache License
private void mergeCloverDatabases() throws MojoExecutionException { AbstractCloverMojo.registerLicenseFile(getProject(), getResourceManager(), this.licenseLocation, getLog(), this.getClass().getClassLoader(), this.license); try {// ww w .j a v a2 s .c om final Project antProject = new Project(); antProject.init(); CloverMergeTask merge = new CloverMergeTask(); merge.setProject(antProject); merge.init(); merge.setInitString(getCloverMergeDatabase()); CloverMergeTask.CloverDbSet dbSet = new CloverMergeTask.CloverDbSet(); dbSet.setProject(antProject); dbSet.setIncludes(includes); dbSet.setDir(baseDir); if (span != null) { dbSet.setSpan(new Interval(span)); } merge.addCloverDbSet(dbSet); merge.execute(); } catch (BuildException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:com.atlassian.maven.plugin.clover.internal.AbstractCloverMojo.java
License:Apache License
public static File getResourceAsFile(final MavenProject project, final ResourceManager resourceManager, final String resourceLocation, final Log logger, final ClassLoader classloader) throws MojoExecutionException { logger.debug("Getting resource: '" + resourceLocation + "'"); resourceManager.addSearchPath("url", ""); resourceManager.addSearchPath(FileResourceLoader.ID, project.getFile().getParentFile().getAbsolutePath()); final ClassLoader origLoader = Thread.currentThread().getContextClassLoader(); try {// w ww. j a va2 s. com Thread.currentThread().setContextClassLoader(classloader); try { logger.debug("Attempting to load resource from [" + resourceLocation + "] ..."); final File outputFile = File.createTempFile("mvn", "resource"); outputFile.deleteOnExit(); return resourceManager.getResourceAsFile(resourceLocation, outputFile.getPath()); } catch (Exception e) { throw new MojoExecutionException("Failed to load resource as file [" + resourceLocation + "]", e); } } finally { Thread.currentThread().setContextClassLoader(origLoader); } }
From source file:com.atlassian.maven.plugin.clover.internal.instrumentation.AbstractInstrumenter.java
License:Apache License
/** * Copy all files that have been excluded by the user (using the excludes configuration property). This is required * as otherwise the excluded files won't be in the new Clover source directory and thus won't be compiled by the * compile plugin. This will lead to compilation errors if any other Java file depends on any of them. * * @throws MojoExecutionException if a failure happens during the copy *///from w w w . j a va2 s . c om private void copyExcludedFiles(final Map<String, String[]> excludedFiles, final String targetDirectory) throws MojoExecutionException { for (String sourceRoot : excludedFiles.keySet()) { final String[] filesInSourceRoot = excludedFiles.get(sourceRoot); for (String fileName : filesInSourceRoot) { final File srcFile = new File(sourceRoot, fileName); try { configuration.getLog().debug( "Copying excluded file: " + srcFile.getAbsolutePath() + " to " + targetDirectory); FileUtils.copyFile(srcFile, new File(targetDirectory, srcFile.getPath().substring(sourceRoot.length()))); } catch (IOException e) { throw new MojoExecutionException( "Failed to copy excluded file [" + srcFile + "] to [" + targetDirectory + "]", e); } } } }
From source file:com.atsid.mojo.testservers.ZookeeperTestServerRunMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { Thread thread = new Thread(new Runnable() { public void run() { getLog().info("Starting zookeeper server"); try { ZookeeperTestRunner zookeeperTestRunner = new ZookeeperTestRunner(); zookeeperTestRunner.registerAsMBean(); zookeeperTestRunner.setClasspathEntries(resolveClasspath()); zookeeperTestRunner.setQuiet(zookeeperQuiet); zookeeperTestRunner.startupServer(); } catch (Exception e) { getLog().error(e);// w w w . j a va 2 s . co m } } }); thread.setName("Zookeeper test server-" + System.currentTimeMillis()); thread.start(); getLog().info("Server started"); if (daemon) { try { thread.join(); } catch (InterruptedException e) { throw new MojoExecutionException("Error joining thread", e); } } }
From source file:com.autentia.mvn.plugin.changes.BugzillaChangesMojo.java
License:Open Source License
/** * Builds changes XML document from Bugzilla XML Document * //from w w w . jav a 2 s . co m * @param bugsDocument * @throws MojoExecutionException */ private void builChangesXML(final Document bugsDocument) throws MojoExecutionException { FileOutputStream fos = null; Transform t; try { t = new Transform(this.getClass().getClassLoader().getResourceAsStream("bugzilla.xsl")); } catch (final TransformerConfigurationException e) { this.getLog().error("Internal XSL error.", e); throw new MojoExecutionException("Error with internal XSL transformation file.", e); } ByteArrayOutputStream baos = null; try { // creamos los directorios this.createFilePath(); // formamos el documento de cambios final byte[] changesXml = t.transformar(bugsDocument); // comprobamos si ya existe el fichero y estamos con currentVersionOnly=true. // por lo que hay que mantener los cambios de versiones anteriores if (this.currentVersionOnly && this.xmlPath.exists()) { final Document changesDocument = this.getChangesDocument(); // buscamos la release que se corresponde con la versin actual final NodeList nodelist = changesDocument.getElementsByTagName(ELEMENT_RELEASE); boolean replaced = false; for (int i = 0; i < nodelist.getLength(); i++) { final Element elementRelease = (Element) nodelist.item(i); if (this.versionName.equals(elementRelease.getAttribute(ATTRIBUTE_VERSION))) { // sustituimos el nodo de la release por el que hemos obtenido ahora this.replaceReleaseNode(elementRelease, changesXml); replaced = true; break; } } if (!replaced) { this.addNewRelease(changesDocument, changesXml); } this.saveChangesDocument(changesDocument); } else { // escribimos el documento XML de cambios fos = new FileOutputStream(this.xmlPath); baos = new ByteArrayOutputStream(); baos.write(changesXml); baos.writeTo(fos); baos.flush(); fos.flush(); } } catch (final IOException e) { this.getLog().error("Error creating file " + this.xmlPath, e); throw new MojoExecutionException("Error creating file " + this.xmlPath, e); } catch (final TransformerException e) { this.getLog().error("Error creating file " + this.xmlPath, e); throw new MojoExecutionException("Error creating file " + this.xmlPath, e); } finally { if (baos != null) { try { baos.close(); } catch (final IOException e) { // ignore } } if (fos != null) { try { fos.close(); } catch (final IOException e) { // ignore } } } }
From source file:com.autentia.mvn.plugin.changes.BugzillaChangesMojo.java
License:Open Source License
/** * Adds the new release element to changes.xml document * //w ww. j a va 2s . c o m * @param changesDocument * @param changesXml * @throws MojoExecutionException */ private void addNewRelease(final Document changesDocument, final byte[] changesXml) throws MojoExecutionException { try { // formamos el documento obtenido final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); final DocumentBuilder db = dbf.newDocumentBuilder(); final ByteArrayInputStream bais = new ByteArrayInputStream(changesXml); final Document docChanges = db.parse(bais); // recuperamos el nodo de la release // slo debe haber un elemento final Node releaseNode = docChanges.getElementsByTagName(ELEMENT_RELEASE).item(0); // lo aadimos al elemento body del que ya tenemos // solo hay un body final Element bodyElement = (Element) changesDocument.getElementsByTagName(ELEMENT_BODY).item(0); final Node importNode = changesDocument.importNode(releaseNode, true); bodyElement.appendChild(importNode); } catch (final ParserConfigurationException e) { this.getLog().error("Error reading file " + this.xmlPath, e); throw new MojoExecutionException("Error reading file " + this.xmlPath, e); } catch (final SAXException e) { this.getLog().error("Error reading file " + this.xmlPath, e); throw new MojoExecutionException("Error reading file " + this.xmlPath, e); } catch (final IOException e) { this.getLog().error("Error reading file " + this.xmlPath, e); throw new MojoExecutionException("Error reading file " + this.xmlPath, e); } }
From source file:com.autentia.mvn.plugin.changes.BugzillaChangesMojo.java
License:Open Source License
/** * Replaces the current release node in the changes.xml document * //w w w.ja va 2 s .com * @param elementRelease * @param changesXml * @throws MojoExecutionException */ private void replaceReleaseNode(final Element elementRelease, final byte[] changesXml) throws MojoExecutionException { try { // formamos el documento obtenido final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); final DocumentBuilder db = dbf.newDocumentBuilder(); final ByteArrayInputStream bais = new ByteArrayInputStream(changesXml); final Document docChanges = db.parse(bais); // recuperamos el nodo de la release // slo debe haber un elemento final Node releaseNode = docChanges.getElementsByTagName(ELEMENT_RELEASE).item(0); final Node importNode = elementRelease.getOwnerDocument().importNode(releaseNode, true); elementRelease.getParentNode().replaceChild(importNode, elementRelease); } catch (final ParserConfigurationException e) { this.getLog().error("Error reading file " + this.xmlPath, e); throw new MojoExecutionException("Error reading file " + this.xmlPath, e); } catch (final SAXException e) { this.getLog().error("Error reading file " + this.xmlPath, e); throw new MojoExecutionException("Error reading file " + this.xmlPath, e); } catch (final IOException e) { this.getLog().error("Error reading file " + this.xmlPath, e); throw new MojoExecutionException("Error reading file " + this.xmlPath, e); } }
From source file:com.autentia.mvn.plugin.changes.BugzillaChangesMojo.java
License:Open Source License
/** * Gets XML document from changes.xml/*w w w .j a va 2s . c o m*/ * * @return * @throws MojoExecutionException */ private Document getChangesDocument() throws MojoExecutionException { try { final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); final DocumentBuilder db = dbf.newDocumentBuilder(); final Document docChanges = db.parse(this.xmlPath); return docChanges; } catch (final ParserConfigurationException e) { this.getLog().error("Error reading file " + this.xmlPath, e); throw new MojoExecutionException("Error reading file " + this.xmlPath, e); } catch (final SAXException e) { this.getLog().error("Error reading file " + this.xmlPath, e); throw new MojoExecutionException("Error reading file " + this.xmlPath, e); } catch (final IOException e) { this.getLog().error("Error reading file " + this.xmlPath, e); throw new MojoExecutionException("Error reading file " + this.xmlPath, e); } }