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:biz.paluch.maven.configurator.ConfigureArtifactMojo.java
License:Open Source License
/** * Perform configuration for an external artifact. * * @throws MojoExecutionException// w w w . j a v a 2 s . c om * @throws MojoFailureException */ @Override public void execute() throws MojoExecutionException, MojoFailureException { Artifact artifact = factory.createArtifactWithClassifier(groupId, artifactId, version, type, classifier); try { artifactResolver.resolve(artifact, pomRemoteRepositories, localRepository); } catch (AbstractArtifactResolutionException e) { throw new MojoExecutionException(e.getMessage(), e); } configure(artifact.getFile()); }
From source file:biz.vidal.maven.plugins.uberjar.UberjarMojo.java
License:Apache License
/** * @throws MojoExecutionException//from w w w .j a va2s. c om */ public void execute() throws MojoExecutionException { if (classworldsBootArtifact == null) { classworldsBootArtifact = new ArtifactModel(); classworldsBootArtifact.setGroupId("classworlds"); classworldsBootArtifact.setArtifactId("classworlds-boot"); classworldsBootArtifact.setVersion("1.0"); } else { checkArtifact(classworldsBootArtifact, "classworldsBootArtifact"); } if (classworldsArtifact == null) { classworldsArtifact = new ArtifactModel(); classworldsArtifact.setGroupId("classworlds"); classworldsArtifact.setArtifactId("classworlds"); classworldsArtifact.setVersion("1.1"); } else { checkArtifact(classworldsArtifact, "classworldsArtifact"); } final Set<Artifact> artifacts = project.getArtifacts(); Set<File> artifactFiles = new LinkedHashSet<File>(); for (Artifact artifact : artifacts) { artifactFiles.add(artifact.getFile()); } Artifact classworldsArt = createArtifact(classworldsArtifact); Artifact bootArt = createArtifact(classworldsBootArtifact); resolve(classworldsArt); resolve(bootArt); JavaArchive classworldsJar = createFromZipFile(JavaArchive.class, classworldsArt.getFile()); JavaArchive bootJar = createFromZipFile(JavaArchive.class, bootArt.getFile()); String appJarName = project.getArtifactId() + "." + project.getArtifact().getArtifactHandler().getExtension(); JavaArchive appJar = create(JavaArchive.class, appJarName).addAsResource(classesDirectory, "/"); UberjarArchive uberJar = create(UberjarArchive.class).merge(bootJar).addAsLibrary(appJar) .addAsLibraries(artifactFiles.toArray(new File[] {})).setMainClass(mainClass) .setClassworlds(classworldsJar).createConfiguration(); File outputJar = (outputFile != null) ? outputFile : uberjarArtifactFileWithClassifier(); uberJar.as(ZipExporter.class).exportTo(outputJar, true); // Now add our extra resources try { if (outputFile == null) { boolean renamed = false; if (classifier != null) { getLog().info("Attaching uberjar artifact."); projectHelper.attachArtifact(project, project.getArtifact().getType(), classifier, outputJar); } else if (!renamed) { getLog().info("Replacing original artifact with uberjar artifact."); File originalArtifact = project.getArtifact().getFile(); replaceFile(originalArtifact, outputJar); } } } catch (Exception e) { throw new MojoExecutionException("Error creating uberjar jar: " + e.getMessage(), e); } }
From source file:biz.vidal.maven.plugins.uberjar.UberjarMojo.java
License:Apache License
private void resolve(Artifact artifact) throws MojoExecutionException { try {/* www.ja v a2s . com*/ artifactResolver.resolve(artifact, remoteArtifactRepositories, localRepository); } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Could not resolve " + artifact, e); } catch (ArtifactNotFoundException e) { throw new MojoExecutionException("Could not find " + artifact, e); } }
From source file:biz.vidal.maven.plugins.uberjar.UberjarMojo.java
License:Apache License
private void replaceFile(File oldFile, File newFile) throws MojoExecutionException { getLog().info("Replacing " + oldFile + " with " + newFile); if (!newFile.renameTo(oldFile)) { // try a gc to see if an unclosed stream needs garbage collecting System.gc();//from w w w . j a v a 2s.c o m System.gc(); if (!newFile.renameTo(oldFile)) { // Still didn't work. We'll do a copy try { FileOutputStream fout = new FileOutputStream(oldFile); FileInputStream fin = new FileInputStream(newFile); try { IOUtil.copy(fin, fout); } finally { IOUtil.close(fin); IOUtil.close(fout); } try { newFile.delete(); } catch (Exception e) { newFile.deleteOnExit(); } } catch (IOException ex) { throw new MojoExecutionException("Could not replace original artifact with uberjar artifact!", ex); } } } }
From source file:br.com.anteros.restdoc.maven.plugin.AnterosRestDocMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { /**// w ww . j a v a 2 s .co m * Se no informar o nome do documento .adoc principal copiamos o padro * para a pasta sourceDirectory. */ if (sourceDocumentName == null) { sourceDocumentName = "index.adoc"; try { InputStream openStream = ResourceUtils.getResourceAsStream("template_index.adoc"); if (!sourceDirectory.exists()) sourceDirectory.mkdirs(); FileOutputStream fos = new FileOutputStream( new File(sourceDirectory + File.separator + sourceDocumentName)); br.com.anteros.core.utils.IOUtils.copy(openStream, fos); fos.flush(); fos.close(); openStream.close(); } catch (IOException e) { throw new MojoExecutionException( "No foi informado o nome do documento principal para gerar a documentao e no foi encontrado o padro.", e); } } List<String> dependencySourcePaths = null; if (includeDependencySources) { try { dependencySourcePaths = getDependencySourcePaths(); } catch (MavenReportException e1) { throw new MojoExecutionException("Ocorreu um erro obtendo source code das dependncias.", e1); } } String temporaryDirectoryJson = rootDir + File.separator + TARGET + File.separator + ANTEROS_JSONC_JAVADOC; /** * Monta a lista de parmetros que sero usados para ler a * documentao(javadoc). */ List<String> parameters = new ArrayList<String>(); parameters.add(PROTECTED_OPTION); parameters.add(SOURCEPATH_OPTION); StringBuilder sbSourcesPath = new StringBuilder(); sbSourcesPath.append(getSourcesPath()); if (dependencySourcePaths != null) { for (String ds : dependencySourcePaths) { sbSourcesPath.append(File.pathSeparator); sbSourcesPath.append(ds); } } sbSourcesPath.append(File.pathSeparator).append(temporaryDirectoryJson); parameters.add(sbSourcesPath.toString()); if (packageScanEndpoints != null) { for (String p : packageScanEndpoints) { if (p.contains("*")) throw new MojoExecutionException("Pacotes no podem conter asteriscos(*) no nome " + p); parameters.add(p); } } parameters.add(SPRING_WEB_CONTROLLER); parameters.add(DOCLET_OPTION); parameters.add(AnterosRestDoclet.class.getName()); parameters.add(CLASSPATH_OPTION); parameters.add(getClassPath()); /** * Executa o javadoc para obter os comentrios referente as classes que * sero geradas na documentao da API REST usando um Doclet * customizado (AnterosRestDoclet) */ com.sun.tools.javadoc.Main.execute(parameters.toArray(new String[] {})); /** * L o arquivo JSON contendo informaes sobre os endpoints lidos com o * javadoc via AnterosRestDoclet(Doclet customizado). */ File temporaryJsonPath = new File(temporaryDirectoryJson); if (!temporaryJsonPath.exists()) temporaryJsonPath.mkdirs(); File file = new File(temporaryJsonPath + File.separator + ANTEROS_JSON); FileInputStream fis; try { fis = new FileInputStream(file); /** * Le os dados do JSON gerado a partir do javadoc. */ ObjectMapper mapper = new ObjectMapper(); ClassDescriptor[] classDescriptors = mapper.readValue(fis, ClassDescriptor[].class); /** * Gera o arquivo de items da documentao. */ String filePath = ""; if (sourceDirectory != null) { filePath = sourceDirectory.getAbsolutePath(); } else if (sourceDocumentName != null) { filePath = sourceDocumentName.substring(0, sourceDocumentName.lastIndexOf(File.separator)); } File itemsFile = new File(filePath, ITEMS_ADOC); Writer writer = new FileWriter(itemsFile); SnippetGenerator.generate(urlBase, writer, classDescriptors); writer.flush(); writer.close(); fis.close(); /** * Altera o CSS default do plugin para o tema azul */ if (!attributes.containsKey("stylesheet")) { File stylesheetFile = new File(filePath, "asciidoc_stylesheet.css"); try { InputStream openStream = ResourceUtils.getResourceAsStream("asciidoc_stylesheet.css"); FileOutputStream fos = new FileOutputStream(stylesheetFile); br.com.anteros.core.utils.IOUtils.copy(openStream, fos); fos.flush(); fos.close(); openStream.close(); } catch (IOException e) { throw new MojoExecutionException("No foi possvel copiar o template padro de CSS.", e); } this.attributes.put("stylesheet", stylesheetFile.getAbsolutePath()); } /** * Executa gerao dos arquivos da documentao a partir dos * arquivos .adoc (asciidoc) */ super.execute(); } catch (Exception e) { e.printStackTrace(); throw new MojoExecutionException("No foi possvel gerar a documentao da API Rest.", e); } }
From source file:br.com.ingenieux.mojo.aws.AbstractAWSMojo.java
License:Apache License
protected <T> T createServiceFor(Class<T> serviceClass) throws MojoExecutionException { try {/*w w w . j av a 2 s . c om*/ clientFactory = new AWSClientFactory(getAWSCredentials(), getClientConfiguration(), regionName); return clientFactory.getService(serviceClass); } catch (Exception exc) { throw new MojoExecutionException("Unable to create service", exc); } }
From source file:br.com.ingenieux.mojo.beanstalk.cmd.dns.BindDomainsCommand.java
License:Apache License
/** * Constructor/*from w w w. j a v a 2 s. com*/ * * @param parentMojo parent mojo */ public BindDomainsCommand(AbstractNeedsEnvironmentMojo parentMojo) throws AbstractMojoExecutionException { super(parentMojo); try { this.r53 = parentMojo.getClientFactory().getService(AmazonRoute53Client.class); this.ec2 = parentMojo.getClientFactory().getService(AmazonEC2Client.class); this.elb = parentMojo.getClientFactory().getService(AmazonElasticLoadBalancingClient.class); } catch (Exception exc) { throw new MojoExecutionException("Failure", exc); } }
From source file:br.com.ingenieux.mojo.jbake.GenerateMojo.java
License:Apache License
public void execute() throws MojoExecutionException { try {// ww w . j av a2 s . co m Oven oven = new Oven(inputDirectory, outputDirectory, isClearCache); oven.setupPaths(); oven.bake(); shutdownDatabase(); } catch (Exception e) { getLog().info("Oops", e); throw new MojoExecutionException("Failure when running: ", e); } }
From source file:br.com.ingenieux.mojo.jbake.WatchMojo.java
License:Apache License
public void execute() throws MojoExecutionException { super.execute(); getLog().info("Now listening for changes on path " + inputDirectory.getPath()); initServer();//from w w w . j a v a 2 s . co m try { final AtomicBoolean done = new AtomicBoolean(false); final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); (new Thread() { @Override public void run() { try { getLog().info("Running. Hit <ENTER> to finish"); reader.readLine(); } catch (Exception exc) { } finally { done.set(true); } } }).start(); DirWatcher dirWatcher = new DirWatcher(Paths.get(inputDirectory.getPath())); do { Boolean result = dirWatcher.processEvents(); if (Boolean.FALSE.equals(result)) { Thread.sleep(1000); } else if (Boolean.TRUE.equals(result)) { refreshLock.writeLock().lock(); getLog().info("Refreshing"); super.execute(); refreshLock.writeLock().unlock(); } else if (null == result) { break; } } while (!done.get()); } catch (Exception exc) { getLog().info("Oops", exc); throw new MojoExecutionException("Oops", exc); } finally { getLog().info("Finishing"); stopServer(); Orient.instance().shutdown(); } }
From source file:br.com.objectos.aws.rds.maven.plugin.CreateSnapshotMojo.java
License:Apache License
private void execute0() throws MojoExecutionException { AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AmazonRDSClient client = new AmazonRDSClient(credentials); CreateDBSnapshotRequest createDBSnapshotRequest = new CreateDBSnapshotRequest() .withDBInstanceIdentifier(dBInstanceIdentifier).withDBSnapshotIdentifier(dBSnapshotIdentifier); info("Starting RDS Snapshot '%s' at '%s'", dBSnapshotIdentifier, dBInstanceIdentifier); long startTime = System.currentTimeMillis(); DBSnapshot snapshot = client.createDBSnapshot(createDBSnapshotRequest); info("Backing up... please wait."); while (!isDone(snapshot)) { try {/*from www . java2 s . c o m*/ Thread.sleep(5000); snapshot = describeSnapshot(client); if (snapshot == null) { break; } } catch (InterruptedException e) { throw new MojoExecutionException("Interrupted while waiting", e); } } long endTime = System.currentTimeMillis(); info("Snapshot took %d ms", endTime - startTime); }