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:br.com.objectos.masche.maven.plugin.CreateSchemaMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (!skip) {//w w w . ja va2s.c o m try { execute0(); } catch (ClassNotFoundException e) { throw new MojoExecutionException( "Could not load JDBC driver. " + "Are you sure you defined the correct plugin dependency?", e); } catch (IOException e) { throw new MojoExecutionException("Could not create database", e); } catch (SqlException e) { throw new MojoExecutionException("Could not create database", e); } } }
From source file:br.com.uggeri.maven.builder.mojo.DependencyResolver.java
public List<Artifact> resolveDependencies(MavenProject project, Artifact artifact) throws MojoExecutionException { final List<Artifact> artifactDependencies = new ArrayList<Artifact>(); Artifact pomArtifact = createArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "pom"); resolveArtifact(project, pomArtifact); if (pomArtifact.isResolved()) { DefaultModelReader dmr = new DefaultModelReader(); try {//from ww w . ja v a2 s . com Model pomModel = dmr.read(pomArtifact.getFile(), null); for (Dependency dep : pomModel.getDependencies()) { final Artifact depArtifact = createArtifact(dep); if (log != null && log.isDebugEnabled()) { log.debug("Dependencia encontrada para " + artifact.getId() + "."); } resolveArtifact(project, depArtifact); if (depArtifact.isResolved()) { artifactDependencies.add(depArtifact); } } } catch (IOException ex) { throw new MojoExecutionException("Erro ao ler o arquivo POM do artefato " + artifact.getId(), ex); } } return artifactDependencies; }
From source file:br.eti.jadler.nsis.maven.plugin.GenerateMojo.java
License:Apache License
private void genInstallOption() throws MojoExecutionException { final InstallOptions options = new InstallOptions(); final String label = "By default " + installDirectory + " add its directory to the system PATH for all users."; final String doNotAddInPath = "Do not add " + displayName + " to the system PATH"; final String addForAllUsers = "Add " + displayName + " to the system PATH for all users"; final String addForCurrentUser = "Add " + displayName + " to the system PATH for current user"; final String checkbox = "Create " + displayName + " Desktop Icon"; options.add(new Field(1, "label", label, 0, -1, 0, 20, null)); options.add(new Field(2, "radiobutton", doNotAddInPath, 0, -1, 30, 40, 0)); options.add(new Field(3, "radiobutton", addForAllUsers, 0, -1, 40, 50, 1)); options.add(new Field(4, "radiobutton", addForCurrentUser, 0, -1, 50, 60, 0)); options.add(new Field(5, "CheckBox", checkbox, 0, -1, 80, 90, 0)); try {/*w ww . j a v a2 s . c o m*/ options.writeToFile(installOptions); } catch (IOException ex) { throw new MojoExecutionException( "Unable to generate project script " + installOptions.getAbsolutePath(), ex); } }
From source file:br.eti.jadler.nsis.maven.plugin.GenerateMojo.java
License:Apache License
private void genProjectScript() throws MojoExecutionException { final URL template = this.getClass().getClassLoader().getResource("template.nsh"); final String buildDirectory = project.getBuild().getDirectory(); final File file = new File(buildDirectory + "/project.nsi"); getLog().info("Generating " + file.getAbsolutePath() + " from " + template.getPath()); try {//from w ww . j ava 2s . co m FileUtils.copyURLToFile(template, file); final Charset charset = StandardCharsets.UTF_8; String templateContent = new String(Files.readAllBytes(file.toPath()), charset); final String licenseMacro; if (new File(licenseFile).exists()) { licenseMacro = "!insertmacro MUI_PAGE_LICENSE " + licenseFile; } else { licenseMacro = ""; } String includeHeaders = ""; if (headers != null) { for (String header : headers) { includeHeaders += "\n!include \"" + header + "\""; } } if (includes != null) { getLog().debug("Files to be included: " + Arrays.toString(includes)); DirectoryScanner scanner = new DirectoryScanner(); scanner.setIncludes(includes); scanner.setBasedir(buildDirectory); scanner.setCaseSensitive(false); scanner.scan(); String[] includedFiles = scanner.getIncludedFiles(); getLog().debug("IncludedFiles: " + Arrays.toString(includedFiles)); for (String includedFile : includedFiles) { if (!fullInstall.contains(includedFile)) { int lastIndexOf = includedFile.lastIndexOf("/"); if (lastIndexOf > 0) { fullInstall.add("\tSetOutPath \"\\$INSTDIR\\\\" + includedFile.replaceAll("/", "\\\\\\\\").substring(0, lastIndexOf + 1) + "\"\n"); } else { fullInstall.add("\tSetOutPath \"\\$INSTDIR\"\n"); } String str = includedFile.replace("/", "\\\\"); fullInstall.add("\tFile /r \"" + str + "\"\n"); deleteFiles.add("\tDelete \"\\$INSTDIR\\\\" + str + "\"\n"); } File f = new File(buildDirectory + "/" + includedFile); while (!f.getAbsolutePath().equals(buildDirectory)) { if (f.isDirectory()) { String replace = f.getAbsolutePath().replace(buildDirectory + "/", "").replace("/", "\\\\"); replace = "\tRMDir \"\\$INSTDIR\\\\" + replace + "\"\n"; if (!removeDirs.contains(replace)) { removeDirs.add(replace); } } f = f.getParentFile(); } } } String preInstallCommands = ""; if (extraPreInstallCommands != null) { for (String command : extraPreInstallCommands) { preInstallCommands += command + "\n"; } } String postInstallCommands = ""; if (extraPostInstallCommands != null) { for (String command : extraPostInstallCommands) { postInstallCommands += command + "\n"; } } String preUninstallCommands = ""; if (extraPreUninstallCommands != null) { for (String command : extraPreUninstallCommands) { preUninstallCommands += command + "\n"; } } String postUninstallCommands = ""; // if (extraPostUninstallCommands != null) { // for (String command : extraPostUninstallCommands) { // postUninstallCommands += command + "\n"; // } // } // String embed = ""; // if (embededInstallers != null) { // for (EmbededInstaller embededInstaller : embededInstallers) { // embed += embededInstaller.toString() + "\n"; // } // } String userDefines = ""; if (defines != null) { for (Map.Entry<Object, Object> entry : defines.entrySet()) { final Object key = entry.getKey(); final Object value = entry.getValue(); userDefines += "\n!define " + key + " \"" + value + "\""; } } templateContent = replace(templateContent, "@NSIS_COMPRESSOR@", compressor.toString()); templateContent = replace(templateContent, "@NSIS_COMPRESSOR_DIC_SIZE@", "" + compressor.getDictionarySize()); templateContent = replace(templateContent, "@NSIS_CONTACT@", contact); templateContent = replace(templateContent, "@NSIS_DEFINES@", userDefines); templateContent = replace(templateContent, "@NSIS_DELETE_FILES@", deleteFiles.toString()); templateContent = replace(templateContent, "@NSIS_DELETE_DIRECTORIES@", removeDirs.toString()); templateContent = replace(templateContent, "@NSIS_DISPLAY_NAME@", displayName); templateContent = replace(templateContent, "@NSIS_DOWNLOAD_SITE@", ""); // templateContent = replace(templateContent, "@NSIS_EMBEDED_INSTALLER@", embed); templateContent = replace(templateContent, "@NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL@", enableUninstallBeforeInstall ? "ON" : "OFF"); templateContent = replace(templateContent, "@NSIS_EXTRA_PRE_INSTALL_COMMANDS@", preInstallCommands); templateContent = replace(templateContent, "@NSIS_EXTRA_POST_INSTALL_COMMANDS@", postInstallCommands); templateContent = replace(templateContent, "@NSIS_EXTRA_PRE_UNINSTALL_COMMANDS@", preUninstallCommands); templateContent = replace(templateContent, "@NSIS_EXTRA_POST_UNINSTALL_COMMANDS@", postUninstallCommands); templateContent = replace(templateContent, "@NSIS_FULL_INSTALL@", fullInstall.toString()); templateContent = replace(templateContent, "@NSIS_HELP_LINK@", helpLink); templateContent = replace(templateContent, "@NSIS_INCLUDES@", includeHeaders); templateContent = replace(templateContent, "@NSIS_INSTALL_DIRECTORY@", installDirectory.replace("/", "\\\\")); templateContent = replace(templateContent, "@NSIS_INSTALL_OPTIONS@", installOptions.getName()); templateContent = replace(templateContent, "@NSIS_INSTALL_ROOT@", installRoot); // templateContent = replace(templateContent, "@NSIS_INSTALLED_ICON_NAME@", muiIcon); templateContent = replace(templateContent, "@NSIS_INSTALLER_MUI_COMPONENTS_DESC@", "!define MUI_COMPONENTSPAGE_NODESC"); templateContent = replace(templateContent, "@NSIS_MODIFY_PATH@", modifyPath ? "ON" : "OFF"); templateContent = replace(templateContent, "@NSIS_MUI_HEADERIMAGE_BITMAP@", "!define MUI_HEADERIMAGE_BITMAP \"" + muiHeader + "\""); templateContent = replace(templateContent, "@NSIS_MUI_ICON@", "!define MUI_ICON \"" + muiIcon + "\""); templateContent = replace(templateContent, "@NSIS_MUI_UNICON@", "!define MUI_UNICON \"" + muiUnIcon + "\""); templateContent = replace(templateContent, "@NSIS_MUI_WELCOMEFINISHPAGE_BITMAP@", "!define MUI_WELCOMEFINISHPAGE_BITMAP \"" + muiPanel + "\""); templateContent = replace(templateContent, "@NSIS_OUTPUT_FILE_NAME@", outputFileName); templateContent = replace(templateContent, "@NSIS_PACKAGE_INSTALL_REGISTRY_KEY@", displayName); templateContent = replace(templateContent, "@NSIS_PACKAGE_NAME@", packageName); templateContent = replace(templateContent, "@NSIS_PACKAGE_VENDOR@", packageVendor); templateContent = replace(templateContent, "@NSIS_PACKAGE_VERSION@", packageVersion); templateContent = replace(templateContent, "@NSIS_RESOURCE_FILE_LICENSE@", licenseMacro); templateContent = replace(templateContent, "@NSIS_SPLASH_IMAGE@", splash); templateContent = replace(templateContent, "@NSIS_UNINSTALLER_NAME@", uninstallerName); templateContent = replace(templateContent, "@NSIS_URL_INFO_ABOUT@", urlInfoAbout); Files.write(file.toPath(), templateContent.getBytes(charset)); } catch (IOException ex) { throw new MojoExecutionException("Unable to generate project script " + template.getPath(), ex); } }
From source file:br.msf.maven.compressor.CompressorMojo.java
License:Open Source License
public void execute() throws MojoExecutionException { try {// ww w. ja v a 2s. c om if (IOUtils.isDirectory(sourceDirectory)) { IOUtils.makeDirs(outputDirectory); (new CompressorService(packSettings())).doTheTrick(); } } catch (Exception ex) { throw new MojoExecutionException("Error while attempting to minify scripts...", ex); } }
From source file:ca.trentonadams.maven.plugins.RunRMI.java
License:Apache License
/** * Starts the rmi registry by either forking the rmiregistry command, or * using the java internal LocateRegistry.createRegistry(port) API, * depending on if someone set the "fork" plugin configuration to true or * not./*from w w w.ja v a2 s . c o m*/ * * @throws MojoExecutionException if an unrecoverable error occurs. */ private void startRegistry() throws MojoExecutionException { // BEGIN startRegistry() try { registry = LocateRegistry.getRegistry(registryPort); registry.list(); mojoLog.info("found registry"); } catch (RemoteException e) { mojoLog.warn("rmiregistry does not exist, attempting " + "to create it..."); mojoLog.debug("exception", e); registry = null; } if (registry == null) { if (fork) { // BEGIN fork rmiregistry command mojoLog.info("forking registry command"); // commands.add("/usr/bin/rmiregistry"); // TODO location of rmiregistry command needs to be // configurable or detectable runCommand(rmiRegistryCommand + " " + registryPort); mojoLog.info("waiting for registry startup, " + "press Ctrl-C if this takes too long..."); boolean registryStarted = false; do { try { Thread.sleep(100); registry = LocateRegistry.getRegistry(registryPort); registry.list(); registryStarted = true; } catch (RemoteException e) { mojoLog.debug("still waiting for registry " + "startup, no need to be alarmed: ", e); } catch (InterruptedException e) { throw new MojoExecutionException( "Interrupted " + "while waiting for registry startup, " + "exiting...", e); } } while (!registryStarted); } // END fork rmiregistry command else { // BEGIN internal rmi registry mojoLog.info("starting internal registry..."); try { registry = LocateRegistry.createRegistry(registryPort); } catch (RemoteException e) { mojoLog.debug("error creating non-forking internal " + "registry", e); } } // END internal rmi registry } else { mojoLog.info("registry: " + registry); mojoLog.info("using existing rmiregistry instance"); } }
From source file:ca.trentonadams.maven.plugins.RunRMI.java
License:Apache License
/** * Verify that the RMI server started up successfully. This will only work * if the verify option has been configured in the POM. * * @throws MojoExecutionException if an unrecoverable error occurs. *///from w ww. j a va2 s .c o m private void verifyRMIServer() throws MojoExecutionException { // BEGIN verifyRMIServer() /* mojoLog.warn("Work around issue with objects not being bound " + "(sleep 2000ms)..."); Thread.sleep(2000);*/ try { if (verifyMethod != null) { long beginMs = System.currentTimeMillis(); mojoLog.info("calling rmiServer." + verifyMethod + " and waiting up to " + waitTimeMs + "ms "); do { try { final Remote rmiServer = registry.lookup(verifyBindName); final Method method = rmiServer.getClass().getMethod(verifyMethod); final String returnValue = (String) method.invoke(rmiServer); if (returnValue.equals(verifyReturnValue)) { mojoLog.info("rmi startup verification successful"); } return; } catch (NotBoundException e) { Thread.sleep(1000); } } while (System.currentTimeMillis() - beginMs <= waitTimeMs); mojoLog.error("rmi startup failed. waitTimeMs not set " + "high enough?"); } else { mojoLog.warn("\"verify\" configuration not setup, unable to " + "verify successful rmi startup, but it may be working"); } } catch (NoSuchMethodException e) { throw new MojoExecutionException( "method does not exist, your " + "\"verify\" plugin configuration parameters are incorrect", e); } catch (AccessException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (InterruptedException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (InvocationTargetException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (IllegalAccessException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (RemoteException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:ca.uhn.hl7v2.mvnplugin.ClassicConfGenMojo.java
License:Mozilla Public License
/** * {@inheritDoc}/*from ww w. ja v a 2 s. c o m*/ */ public void execute() throws MojoExecutionException, MojoFailureException { try { String profileString; FileReader reader = new FileReader(profile); profileString = IOUtil.toString(reader); DeploymentManager dm = new DeploymentManager(targetDirectory, packageName); dm.generate(profileString); } catch (FileNotFoundException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (ConformanceException e) { throw new MojoExecutionException(e.getMessage(), e); } project.addCompileSourceRoot(targetDirectory); }
From source file:ca.uhn.hl7v2.mvnplugin.SourceGenMojo.java
License:Mozilla Public License
/** * {@inheritDoc}// w ww .ja v a 2s.c om */ public void execute() throws MojoExecutionException, MojoFailureException { if (skip) { getLog().warn("Configured to skip"); } if (forceGroupNames) { System.setProperty("force.group", "true"); } else { System.setProperty("force.group", "false"); } if (new File(targetDirectory).exists()) { getLog().warn("Already exists version " + version + ", skipping!"); } else if (!alreadyMade.contains(version)) { // I haven't entirely figured out why, but Maven runs this plugin // several times for each version, which takes forever, so we assume // that if the directory exists, we don't need to generate again alreadyMade.add(version); if (jdbcUser == null) { jdbcUser = ""; } if (jdbcPassword == null) { jdbcPassword = ""; } System.setProperty(NormativeDatabase.PROP_DATABASE_USER, jdbcUser); System.setProperty(NormativeDatabase.PROP_DATABASE_PASSWORD, jdbcPassword); System.setProperty(NormativeDatabase.PROP_DATABASE_URL, jdbcUrl); try { EventMapGenerator.generateEventMap(targetResourceDirectory, version); String targetDir = structuresAsResources ? targetResourceDirectory : targetDirectory; SourceGenerator.makeAll(targetDir, version, false, templatePackage, "java"); } catch (HL7Exception e) { throw new MojoExecutionException("Failed to build source ", e); } catch (SQLException e) { throw new MojoExecutionException("Failed to build source ", e); } catch (IOException e) { throw new MojoExecutionException("Failed to build source ", e); } } else { getLog().warn("Already made version " + version + ", skipping!"); } if (!structuresAsResources) { getLog().info("Adding " + targetDirectory + " to compile source root"); project.addCompileSourceRoot(targetDirectory); } }
From source file:ca.uhn.hl7v2.mvnplugin.XrefGenMojo.java
License:Mozilla Public License
/** * {@inheritDoc}/*from w ww. j a v a 2s .c o m*/ */ public void execute() throws MojoExecutionException, MojoFailureException { if (skip) { getLog().warn("Configured to skip"); } if (!alreadyMade.contains(version)) { // I haven't entirely figured out why, but Maven runs this plugin // several times for each version, which takes forever, so we assume // that if the directory exists, we don't need to generate again alreadyMade.add(version); if (jdbcUser == null) { jdbcUser = ""; } if (jdbcPassword == null) { jdbcPassword = ""; } System.setProperty(NormativeDatabase.PROP_DATABASE_USER, jdbcUser); System.setProperty(NormativeDatabase.PROP_DATABASE_PASSWORD, jdbcPassword); System.setProperty(NormativeDatabase.PROP_DATABASE_URL, jdbcUrl); DataTypeGenerator.setMakeAll(true); try { SourceGenerator.makeAll(targetDirectory, version, false, templatePackage, "json"); EventMapGenerator.generateEventDesc(targetDirectory, version, templatePackage); } catch (HL7Exception e) { e.printStackTrace(); throw new MojoExecutionException("Failed to build source ", e); } catch (Exception e) { e.printStackTrace(); throw new MojoExecutionException("Failed to build source ", e); } } else { getLog().warn("Already made version " + version + ", skipping!"); } }