List of usage examples for org.apache.maven.plugin MojoExecutionException MojoExecutionException
public MojoExecutionException(String message)
MojoExecutionException
exception providing a message
. From source file:ch.sourcepond.maven.plugin.jenkins.CliMojo.java
License:Apache License
/** * @param pCustomXsltFieldName/*from w w w.j a va 2 s. c om*/ * @param pCustomXslt * @param pCoordFieldName * @param pCoords * @return * @throws MojoExecutionException * @throws MojoFailureException */ private File resolveXsltOrNull(final String pCustomXsltFieldName, final File pCustomXslt, final String pCoordFieldName, final String pCoords) throws MojoExecutionException, MojoFailureException { if (pCustomXslt != null && pCoords != null) { throw new MojoExecutionException(messages.getMessage(MOJO_ERROR_AMBIGUOUS_XSLT_CONFIGURATION, pCustomXsltFieldName, pCoordFieldName)); } File xslt = pCustomXslt; if (pCoords != null) { xslt = rsf.newResolver(getLog(), repoSystem, repoSession, remoteRepos).resolveXslt(pCoords); } return xslt; }
From source file:ch.sourcepond.maven.plugin.jenkins.config.ConfigImpl.java
License:Apache License
/** * @throws MojoExecutionException/*from w w w.j av a2 s . co m*/ */ void validate(final Log pLog) throws MojoExecutionException { // Do not allow noKeyAuth when private key is set if (isNoKeyAuth() && getPrivateKeyOrNull() != null) { throw new MojoExecutionException(messages .getMessage(CONFIG_VALIDATION_ERROR_NO_KEY_AUTH_AND_PRIVATE_KEY_SET, getPrivateKeyOrNull())); } // If a secure base-uri has been set, there must be a trust-store if // certificate check is not disabled. if (isSecure() && !isNoCertificateCheck() && getTrustStoreOrNull() == null) { throw new MojoExecutionException( messages.getMessage(CONFIG_VALIDATION_ERROR_SECURE_BUT_NO_TRUSTSTORE_SPECIFIED)); } // If a trust-store has been specified, insure that a password is set if (getTrustStoreOrNull() != null) { if (isBlank(getTrustStorePasswordOrNull())) { throw new MojoExecutionException(messages.getMessage( CONFIG_VALIDATION_ERROR_NO_TRUSTSTORE_PASSWORD_SPECIFIED, getTrustStoreOrNull())); } if (MIN_TRUSTSTORE_PWD_LENGTH > getTrustStorePasswordOrNull().length()) { throw new MojoExecutionException(messages.getMessage( CONFIG_VALIDATION_ERROR_TRUSTSTORE_PASSWORD_TOO_SHORT, MIN_TRUSTSTORE_PWD_LENGTH)); } } if (getTrustStoreOrNull() == null && !isBlank(getTrustStorePasswordOrNull())) { pLog.warn(messages.getMessage(CONFIG_VALIDATION_WARN_TRUSTSTORE_PASSWORD_NOT_NECESSARY)); } warnFieldCannotBeApplied(CONFIG_VALIDATION_WARN_XSLT_NOT_APPLIABLE, pLog, stdin, stdinXslt, STDIN_FIELD, STDIN_XSLT_FIELD); warnFieldCannotBeApplied(CONFIG_VALIDATION_WARN_XSLT_NOT_APPLIABLE, pLog, stdout, stdoutXslt, STDOUT_FIELD, STDOUT_XSLT_FIELD); warnFieldCannotBeApplied(CONFIG_VALIDATION_WARN_PARAMS_NOT_APPLIABLE, pLog, stdinXslt, stdinXsltParams, STDIN_XSLT_FIELD, STDIN_PARAMS_FIELD); warnFieldCannotBeApplied(CONFIG_VALIDATION_WARN_PARAMS_NOT_APPLIABLE, pLog, stdoutXslt, stdoutXsltParams, STDOUT_XSLT_FIELD, STDOUT_PARAMS_FIELD); }
From source file:ch.sourcepond.maven.plugin.jenkins.config.download.DownloaderImpl.java
License:Apache License
/** * @param pLog// www.ja v a 2 s .c o m * @param pConfig * @return * @throws IOException * @throws ClientProtocolException * @throws MojoExecutionException */ private String determineJenkinsVersion(final Log pLog, final CloseableHttpClient pClient, final Config pConfig) throws ClientProtocolException, IOException, MojoExecutionException { final HttpUriRequest versionRequest = clientFacade.newGet(pConfig.getBaseUri()); try (final CloseableHttpResponse response = pClient.execute(versionRequest)) { if (response.containsHeader(VERSION_HEADER_NAME)) { final Header[] header = response.getHeaders(VERSION_HEADER_NAME); isTrue(header.length == 1, "Jenkins API changed; received multiple version headers. Please report this as bug (https://github.com/SourcePond/jenkins-maven-plugin/issues)"); final String version = header[0].getValue(); if (pLog.isInfoEnabled()) { pLog.info(messages.getMessage(DOWNLOADER_INFO_VERSION_FOUND, version)); } return version; } else { throw new MojoExecutionException(messages.getMessage(DOWNLOADER_ERROR_NO_VERSION_HEADER, pConfig.getBaseUri(), VERSION_HEADER_NAME)); } } }
From source file:ch.sourcepond.maven.plugin.jenkins.config.download.DownloaderImpl.java
License:Apache License
@Override public String downloadCliJar(final Log pLog, final Config pValidatedConfig) throws MojoExecutionException { try (final CloseableHttpClient client = clientFacade.newClient(pValidatedConfig)) { final String jenkinsVersion = determineJenkinsVersion(pLog, client, pValidatedConfig); final Path downloadedCliJar = getDownloadedCliJar(pValidatedConfig.getJenkinscliDirectory(), jenkinsVersion);/*from w w w.j av a2 s.c o m*/ if (!isRegularFile(downloadedCliJar)) { final HttpUriRequest request = clientFacade.newGet(pValidatedConfig.getCliJarUri()); try { try (final CloseableHttpResponse response = client.execute(request)) { final StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() != SC_OK) { throw new MojoExecutionException(messages.getMessage(DOWNLOADER_ERROR_WRONG_STATUS_CODE, statusLine, pValidatedConfig.getCliJarUri())); } final HttpEntity entity = response.getEntity(); if (entity != null) { try (final InputStream in = entity.getContent()) { copy(in, downloadedCliJar); } } else { throw new MojoExecutionException(messages.getMessage(DOWNLOADER_ERROR_ENTITY_IS_NULL, pValidatedConfig.getCliJarUri())); } } } finally { request.abort(); } } final String absoluteDownloadedCliPath = downloadedCliJar.toAbsolutePath().toString(); if (pLog.isInfoEnabled()) { pLog.info(messages.getMessage(DOWNLOADER_INFO_USED_CLI_JAR, absoluteDownloadedCliPath)); } return absoluteDownloadedCliPath; } catch (final IOException | KeyManagementException | NoSuchAlgorithmException | KeyStoreException | CertificateException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:ch.sourcepond.maven.plugin.jenkins.process.ProcessFacadeImpl.java
License:Apache License
@Override public void execute(final Log pLog, final Config pConfig) throws MojoExecutionException { final List<String> command = cmdFactory.newCommand(pConfig); try {/* w ww . j av a 2 s .c o m*/ final ProcessExecutor executor = procExecFactory.newExecutor(pLog, pConfig, command); final int exitValue = executor.execute().getExitValue(); if (exitValue != 0) { final StringBuilder builder = new StringBuilder(); for (final String token : command) { builder.append(token).append(" "); } throw new MojoExecutionException( messages.getMessage(PROCESS_ERROR_EXITVALUE, exitValue, builder.toString())); } } catch (InvalidExitValueException | IOException | InterruptedException | TimeoutException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:ch.sourcepond.maven.plugin.jenkins.proxy.ProxyFinderImpl.java
License:Apache License
@Override public Proxy findProxy(final String pProxyIdOrNull, final Settings pSettings) throws MojoExecutionException { assert pSettings != null : "pSettings is null but should not be!"; Proxy proxy = null;/*from w w w . j a v a 2 s.co m*/ if (pProxyIdOrNull != null) { for (final Proxy p : pSettings.getProxies()) { if (p.getId() == null) { continue; } if (p.getId().equals(pProxyIdOrNull)) { proxy = p; break; } } if (proxy == null) { throw new MojoExecutionException( messages.getMessage(CONFIG_VALIDATION_ERROR_NO_PROXY_FOUND, pProxyIdOrNull)); } } return proxy; }
From source file:ch.sourcepond.maven.plugin.jenkins.resolver.ResolverImpl.java
License:Apache License
@Override public File resolveXslt(final String pXsltCoords) throws MojoExecutionException { final Artifact artifact = factory.newArtifact(pXsltCoords); final ArtifactRequest request = factory.newRequest(); request.setArtifact(artifact);// ww w.ja v a2 s . c o m request.setRepositories(remoteRepos); try { final ArtifactResult result = repoSystem.resolveArtifact(repoSession, request); final Artifact resolvedArtifact = result.getArtifact(); if (resolvedArtifact == null) { for (final Exception e : result.getExceptions()) { log.error(e); } throw new MojoExecutionException( messages.getMessage(RESOLVER_ERROR_RESOLUTION_FAILED, pXsltCoords)); } final File xsltFile = resolvedArtifact.getFile(); notNull(xsltFile, "Resolved artifact has no file associated; Please report this as bug (https://github.com/SourcePond/jenkins-maven-plugin/issues)"); return xsltFile; } catch (final ArtifactResolutionException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:ch.sourcepond.maven.plugin.repobuilder.AdditionalArtifact.java
License:Apache License
/** * @return/* ww w .ja v a 2 s .c o m*/ * @throws MojoExecutionException */ Artifact toArtifact() throws MojoExecutionException { final DefaultArtifactHandler handler = new DefaultArtifactHandler(); String extension = this.extension; if (isBlank(extension)) { extension = getFileExtension(file.getAbsolutePath()); } if (isBlank(extension)) { throw new MojoExecutionException( "No extension specified; either add an extension to the artifact-file, or, specify parameter 'extension'! Invalid config item: " + this); } handler.setExtension(extension); final Artifact artifact = new DefaultArtifact(groupId, artifactId, version, "", handler.getExtension(), classifier, handler); artifact.setFile(file); return artifact; }
From source file:ch.sourcepond.maven.release.commons.PluginException.java
License:Apache License
public void printBigErrorMessageAndThrow(final Log log) throws MojoExecutionException { log.error(""); log.error(""); log.error(""); log.error("************************************"); log.error("Could not execute the release plugin"); log.error("************************************"); log.error(""); log.error(""); log.error(getMessage());/* w w w . j a v a2 s .c om*/ for (final String line : messages) { log.error(line); } log.error(""); log.error(""); printCause(log); throw new MojoExecutionException(getMessage()); }
From source file:ch.sourcepond.maven.release.ReleaseInvoker.java
License:Apache License
public final void runMavenBuild(final Reactor reactor) throws MojoExecutionException { request.setInteractive(false);/*from ww w . j av a 2 s . c o m*/ request.setShowErrors(true); request.setDebug(debugEnabled || log.isDebugEnabled()); final Properties env = cloneSystemProperties(); if (skipTests) { env.put(SKIP_TESTS, String.valueOf(true)); } request.setProperties(env); request.setGoals(getGoals()); final List<String> profiles = profilesToActivate(); request.setProfiles(profiles); final List<String> changedModules = new ArrayList<String>(); final List<String> modulesToRelease = getModulesToRelease(); for (final ReleasableModule releasableModule : reactor) { final String modulePath = releasableModule.getRelativePathToModule(); final boolean userExplicitlyWantsThisToBeReleased = modulesToRelease.contains(modulePath); final boolean userImplicitlyWantsThisToBeReleased = modulesToRelease.isEmpty(); if (userExplicitlyWantsThisToBeReleased || (userImplicitlyWantsThisToBeReleased && releasableModule.getVersion().hasChanged())) { changedModules.add(modulePath); } } request.setProjects(changedModules); final String profilesInfo = profiles.isEmpty() ? "no profiles activated" : "profiles " + profiles; log.info(format("About to run mvn %s with %s and modules %s", goals, profilesInfo, changedModules)); try { final InvocationResult result = invoker.execute(request); if (result.getExitCode() != 0) { throw new MojoExecutionException("Maven execution returned code " + result.getExitCode()); } } catch (final MavenInvocationException e) { throw new MojoExecutionException("Failed to build artifact", e); } }