List of usage examples for org.apache.maven.plugin MojoExecutionException MojoExecutionException
public MojoExecutionException(String message)
MojoExecutionException
exception providing a message
. From source file:com.atolcd.alfresco.AmpMojo.java
public void execute() throws MojoExecutionException { // Module properties getLog().info("Processing module.properties file"); moduleProperties.put("module.id", project.getGroupId() + "." + project.getArtifactId()); String projectVersion = project.getVersion(); String finalVersion = VersionUtil.getFinalVersion(projectVersion); if (finalVersion == null) { // No valid version found in finalVersion throw new MojoExecutionException( "Invalid version \"" + projectVersion + "\", not matching \"[0..9]+(\\.[0..9]+)*\""); }// w w w . j av a 2 s. co m if (!projectVersion.equals(finalVersion)) { getLog().info("Filtering version to have a valid alfresco version"); } getLog().info("Using final version " + finalVersion); moduleProperties.put("module.version", finalVersion); File modulePropertiesFile = new File(targetDirectory, "module.properties"); FileOutputStream fos = null; try { fos = new FileOutputStream(modulePropertiesFile); moduleProperties.store(fos, null); } catch (IOException e) { throw new MojoExecutionException("Could not process module.properties", e); } finally { IOUtil.close(fos); } zipArchiver.addFile(modulePropertiesFile, "module.properties"); // File-mapping properties file (automatically created for Share projects) if (shareModule) { if (filemappingProperties == null) { filemappingProperties = new Properties(); } filemappingProperties.put("/web", "/"); } if (filemappingProperties != null && !filemappingProperties.isEmpty()) { if (!filemappingProperties.containsKey("include.default")) { filemappingProperties.put("include.default", "true"); } File filemappingPropertiesFile = new File(targetDirectory, "file-mapping.properties"); try { fos = new FileOutputStream(filemappingPropertiesFile); filemappingProperties.store(fos, null); } catch (IOException e) { throw new MojoExecutionException("Could not process file-mapping.properties", e); } finally { IOUtil.close(fos); } zipArchiver.addFile(filemappingPropertiesFile, "file-mapping.properties"); } // Alfresco configuration files // Mapped from configured resources to their respective target paths getLog().info("Adding configuration files"); MavenResourcesExecution resourcesExecution; File targetConfigDirectory = new File(targetDirectory, "config"); targetConfigDirectory.mkdir(); try { if (StringUtils.isEmpty(encoding)) { getLog().warn("File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING + ", i.e. build is platform dependent!"); } resourcesExecution = new MavenResourcesExecution(project.getResources(), targetConfigDirectory, project, encoding, null, Collections.<String>emptyList(), session); resourcesFiltering.filterResources(resourcesExecution); } catch (MavenFilteringException e) { throw new MojoExecutionException("Could not filter resources", e); } zipArchiver.addDirectory(targetConfigDirectory, "config/"); // Web sources directory if (webDirectory.exists()) { getLog().info("Adding web sources"); zipArchiver.addDirectory(webDirectory, "web/"); } // Web build directory (minified sources) if (webBuildDirectory.exists()) { getLog().info("Adding minified web sources"); zipArchiver.addDirectory(webBuildDirectory, "web/"); } // Webscripts if (webscriptsDirectory.exists()) { getLog().info("Adding webscripts"); zipArchiver.addDirectory(webscriptsDirectory, "config/alfresco/extension/templates/webscripts/"); } // Alfresco webscripts overrides if (alfrescoWebscriptsDirectory.exists()) { getLog().info("Adding webscripts overrides"); zipArchiver.addDirectory(alfrescoWebscriptsDirectory, "config/alfresco/templates/webscripts/org/alfresco/"); } // Licenses if (licensesDirectory.exists()) { getLog().info("Adding licenses"); zipArchiver.addDirectory(licensesDirectory, "licenses/"); } // Root if (rootDirectory != null && rootDirectory.exists()) { getLog().info("Adding root directory files"); zipArchiver.addDirectory(rootDirectory, ""); } // JAR file MavenArchiver archiver = new MavenArchiver(); archiver.setArchiver(jarArchiver); archiver.setOutputFile(jarFile); jarArchiver.addDirectory(outputDirectory, new String[] { "**/*.class" }, null); MavenArchiveConfiguration archive = new MavenArchiveConfiguration(); try { archiver.createArchive(session, project, archive); } catch (Exception e) { throw new MojoExecutionException("Could not build the jar file", e); } mavenProjectHelper.attachArtifact(project, "jar", "classes", jarFile); if (jarFile.exists()) { getLog().info("Adding JAR file"); zipArchiver.addFile(jarFile, "lib/" + jarFile.getName()); } // Dependencies (mapped to the AMP file "lib" directory) getLog().info("Adding JAR dependencies"); Set<Artifact> artifacts = project.getArtifacts(); for (Iterator<Artifact> iter = artifacts.iterator(); iter.hasNext();) { Artifact artifact = (Artifact) iter.next(); ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME); if (!artifact.isOptional() && filter.include(artifact) && "jar".equals(artifact.getType())) { zipArchiver.addFile(artifact.getFile(), "lib/" + artifact.getFile().getName()); } } File ampFile = new File(targetDirectory, project.getBuild().getFinalName() + ".amp"); zipArchiver.setDestFile(ampFile); try { zipArchiver.createArchive(); } catch (IOException e) { throw new MojoExecutionException("Could not build the amp file", e); } project.getArtifact().setFile(ampFile); }
From source file:com.autentia.mvn.plugin.changes.BugzillaChangesMojo.java
License:Open Source License
public void execute() throws MojoExecutionException, MojoFailureException { this.getLog().debug("Entering."); this.getLog().info("Component:" + this.componentName); // si el informe el solo para el padre y es un hijo salimos // si es un hijo y no est definido el component salimos if (isParentProject() || (parentOnly && isEmpty(componentName))) { return;/*from www . ja va 2s . c om*/ } versionName = getVersionNameFromProject(); // inicializamos el gestor de peticiones this.httpRequest = new HttpRequest(this.getLog()); // inicializamos la url del Bugzilla this.bugzillaUrl = this.project.getIssueManagement().getUrl(); // preparamos el cliente HTTP para las peticiones final HttpClient client = new HttpClient(); final HttpClientParams clientParams = client.getParams(); clientParams.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true); final HttpState state = new HttpState(); final HostConfiguration hc = new HostConfiguration(); client.setHostConfiguration(hc); client.setState(state); this.determineProxy(client); if (!performLogin(client)) { throw new MojoExecutionException( "The username or password you entered is not valid. Cannot login in Bugzilla: " + bugzillaUrl); } final String bugsIds = this.getBugList(client); final Document bugsDocument = this.getBugsDocument(client, bugsIds); builChangesXML(bugsDocument); this.getLog().debug("Exiting."); }
From source file:com.autentia.mvn.plugin.release.bugzilla.BugzillaReleaseMojo.java
License:Open Source License
public void execute() throws MojoExecutionException { getLog().debug("Entering."); if (productName == null) { // use project name if is null productName = project.getName(); }/*from w w w. j av a 2s. c o m*/ if (isParentProject()) { return; } versionName = getVersionNameFromProject(); newMilestone = getNextMilestone(); promptVersionAndMilestone(); // Bugzilla url from issueManagement bugzillaUrl = project.getIssueManagement().getUrl(); final WebConversation wc = new WebConversation(); if (!performLogin(wc)) { throw new MojoExecutionException( "The username or password you entered is not valid. Cannot login in Bugzilla: " + bugzillaUrl); } createNewVersion(wc); closeResolvedBugs(wc); createNewMilestone(wc); changeMilestoneForUnresolvedBugs(wc); getLog().debug("Exiting."); }
From source file:com.autentia.mvn.plugin.release.bugzilla.BugzillaReleaseMojo.java
License:Open Source License
/** * Create the new milestone in bugzilla/*from w ww . j av a 2 s. c o m*/ * * @param wc * @throws MojoExecutionException */ private void createNewMilestone(final WebConversation wc) throws MojoExecutionException { try { getLog().info("Creating new milestone ..."); final WebRequest req = new GetMethodWebRequest(bugzillaUrl + EDITMILESTONES_URL); req.setParameter(PRODUCT_PARAMETER, productName); req.setParameter(ACTION_PARAMETER, ADD_PARAMETER_VALUE); final WebResponse resp = wc.getResponse(req); final WebForm[] webForms = resp.getForms(); WebForm theForm = null; for (final WebForm webForm : webForms) { if (webForm.getAction().equals(EDITMILESTONES_URL)) { theForm = webForm; break; } } if (theForm == null) { throw new MojoExecutionException("Can't create new milestone"); } theForm.setParameter("milestone", newMilestone); theForm.submit(); getLog().info("New milestone created ..."); } catch (final MalformedURLException e) { throw new MojoExecutionException("Can't create new milestone", e); } catch (final IOException e) { throw new MojoExecutionException("Can't create new milestone", e); } catch (final SAXException e) { throw new MojoExecutionException("Can't create new milestone", e); } }
From source file:com.autentia.mvn.plugin.release.bugzilla.BugzillaReleaseMojo.java
License:Open Source License
/** * Create the new version in bugzilla/*w ww . j av a 2 s. c o m*/ * * @param wc * @throws MojoExecutionException */ private void createNewVersion(final WebConversation wc) throws MojoExecutionException { try { getLog().info("Creating new version ..."); final WebRequest req = new GetMethodWebRequest(bugzillaUrl + EDITVERSIONS_URL); req.setParameter(PRODUCT_PARAMETER, productName); req.setParameter(ACTION_PARAMETER, ADD_PARAMETER_VALUE); final WebResponse resp = wc.getResponse(req); final WebForm[] webForms = resp.getForms(); WebForm theForm = null; for (final WebForm webForm : webForms) { if (webForm.getAction().equals(EDITVERSIONS_URL)) { theForm = webForm; break; } } if (theForm == null) { throw new MojoExecutionException("Can't create new version"); } theForm.setParameter(VERSION_PARAMETER, versionName); theForm.submit(); getLog().info("New version created ..."); } catch (final MalformedURLException e) { throw new MojoExecutionException("Can't create new version", e); } catch (final IOException e) { throw new MojoExecutionException("Can't create new version", e); } catch (final SAXException e) { throw new MojoExecutionException("Can't create new version", e); } }
From source file:com.azurenight.maven.TroposphereMojo.java
License:Apache License
private void setupVariables() throws MojoExecutionException { jythonArtifact = findJythonArtifact(); if (temporaryBuildDirectory == null) { temporaryBuildDirectory = new File("target/jython-plugins-tmp"); }//from ww w .j a va 2 s . co m temporaryBuildDirectory.mkdirs(); packageDownloadCacheDir = new File(temporaryBuildDirectory, "build"); packageDownloadCacheDir.mkdir(); libdir = new File(temporaryBuildDirectory, "Lib"); if (!jythonArtifact.getFile().getName().endsWith(".jar")) { throw new MojoExecutionException( "I expected " + jythonArtifact + " to provide a jar, but got " + jythonArtifact.getFile()); } setuptoolsResource = getClass().getResource(SETUPTOOLS_EGG); if (setuptoolsResource == null) throw new MojoExecutionException("resource setuptools egg not found"); setuptoolsJar = new File(packageDownloadCacheDir, SETUPTOOLS_EGG); sitepackagesdir = new File(libdir, "site-packages"); botoURL = getClass().getResource(BOTO_EGG); botoFile = new File(packageDownloadCacheDir, BOTO_EGG); tropoURL = getClass().getResource(TROPO_EGG); tropoFile = new File(packageDownloadCacheDir, TROPO_EGG); if (libs == null) { getLog().info("libraries list empty"); libs = new ArrayList<String>(); } if (!libs.contains("boto")) { getLog().debug("missing boto library, adding automatically"); libs.add(botoFile.getAbsolutePath()); } if (!libs.contains("troposphere")) { getLog().debug("missing troposphere library, adding automatically"); libs.add(tropoFile.getAbsolutePath()); } }
From source file:com.azurenight.maven.TroposphereMojo.java
License:Apache License
/** * @return// w w w . j a va2s.c o m * @throws MojoExecutionException */ private Artifact findJythonArtifact() throws MojoExecutionException { for (Artifact i : project.getArtifacts()) { if (i.getArtifactId().equals("jython-standalone") && i.getGroupId().equals("org.python")) { return i; } } throw new MojoExecutionException("org.python.jython-standalone dependency not found. \n" + "Add a dependency to jython-standalone 2.7-b1 or newer to your project: \n" + " <dependency>\n" + " <groupId>org.python</groupId>\n" + " <artifactId>jython-standalone</artifactId>\n" + " <version>2.7-b1</version>\n" + " </dependency>" + "\n"); }
From source file:com.baidu.jprotobuf.mojo.AbstractExecMojo.java
License:Apache License
/** * Parses the argument string given by the user. Strings are recognized as everything between STRING_WRAPPER. * PARAMETER_DELIMITER is ignored inside a string. STRING_WRAPPER and PARAMETER_DELIMITER can be escaped using * ESCAPE_CHAR.//w w w . ja va 2 s . c om * * @return Array of String representing the arguments * @throws MojoExecutionException for wrong formatted arguments */ protected String[] parseCommandlineArgs() throws MojoExecutionException { if (commandlineArgs == null) { return null; } else { try { return CommandLineUtils.translateCommandline(commandlineArgs); } catch (Exception e) { throw new MojoExecutionException(e.getMessage()); } } }
From source file:com.baidu.jprotobuf.mojo.PreCompileMojo.java
License:Apache License
/** * Execute goal./*from w w w. j av a 2 s . c om*/ * * @throws MojoExecutionException execution of the main class or one of the threads it generated failed. * @throws MojoFailureException something bad happened... */ public void execute() throws MojoExecutionException, MojoFailureException { if (isSkip()) { getLog().info("skipping execute as per configuraion"); return; } if (killAfter != -1) { getLog().warn("Warning: killAfter is now deprecated. Do you need it ? Please comment on MEXEC-6."); } arguments = new String[] { outputParentDirectory.getAbsolutePath(), outputDirectory.getAbsolutePath(), filterClassPackage }; if (getLog().isDebugEnabled()) { StringBuffer msg = new StringBuffer("Invoking : "); msg.append(mainClass); msg.append(".main("); for (int i = 0; i < arguments.length; i++) { if (i > 0) { msg.append(", "); } msg.append(arguments[i]); } msg.append(")"); getLog().debug(msg); } final Log log = getLog(); IsolatedThreadGroup threadGroup = new IsolatedThreadGroup(mainClass /* name */); Thread bootstrapThread = new Thread(threadGroup, new Runnable() { public void run() { long current = System.currentTimeMillis(); try { Method main = Thread.currentThread().getContextClassLoader().loadClass(mainClass) .getMethod("main", new Class[] { String[].class }); if (!main.isAccessible()) { getLog().debug("Setting accessibility to true in order to invoke main()."); main.setAccessible(true); } if (!Modifier.isStatic(main.getModifiers())) { throw new MojoExecutionException( "Can't call main(String[])-method because it is not static."); } main.invoke(null, new Object[] { arguments }); } catch (NoSuchMethodException e) { // just pass it on Thread.currentThread().getThreadGroup().uncaughtException(Thread.currentThread(), new Exception( "The specified mainClass doesn't contain a main method with appropriate signature.", e)); } catch (Exception e) { // just pass it on Thread.currentThread().getThreadGroup().uncaughtException(Thread.currentThread(), e); } finally { log.info("JProtobuf pre compile done time took: " + (System.currentTimeMillis() - current) + "ms"); } } }, mainClass + ".main()"); bootstrapThread.setContextClassLoader(getClassLoader()); setSystemProperties(); bootstrapThread.start(); joinNonDaemonThreads(threadGroup); // It's plausible that spontaneously a non-daemon thread might be created as we try and shut down, // but it's too late since the termination condition (only daemon threads) has been triggered. if (keepAlive) { getLog().warn( "Warning: keepAlive is now deprecated and obsolete. Do you need it? Please comment on MEXEC-6."); waitFor(0); } if (cleanupDaemonThreads) { terminateThreads(threadGroup); try { threadGroup.destroy(); } catch (IllegalThreadStateException e) { getLog().warn("Couldn't destroy threadgroup " + threadGroup, e); } } if (originalSystemProperties != null) { System.setProperties(originalSystemProperties); } synchronized (threadGroup) { if (threadGroup.uncaughtException != null) { throw new MojoExecutionException("An exception occured while executing the Java class. " + threadGroup.uncaughtException.getMessage(), threadGroup.uncaughtException); } } registerSourceRoots(); }
From source file:com.baidu.jprotobuf.mojo.PreCompileMojo.java
License:Apache License
/** * Examine the plugin dependencies to find the executable artifact. * /* www .ja va 2 s. c o m*/ * @return an artifact which refers to the actual executable tool (not a POM) * @throws MojoExecutionException if no executable artifact was found */ private Artifact findExecutableArtifact() throws MojoExecutionException { // ILimitedArtifactIdentifier execToolAssembly = this.getExecutableToolAssembly(); Artifact executableTool = null; for (Artifact pluginDep : this.pluginDependencies) { if (this.executableDependency.matches(pluginDep)) { executableTool = pluginDep; break; } } if (executableTool == null) { throw new MojoExecutionException( "No dependency of the plugin matches the specified executableDependency." + " Specified executableToolAssembly is: " + executableDependency.toString()); } return executableTool; }