List of usage examples for org.apache.maven.plugin MojoExecutionException MojoExecutionException
public MojoExecutionException(String message)
MojoExecutionException
exception providing a message
. From source file:com.adaptiweb.mojo.BuildNumberMojo.java
License:Apache License
/** * @see org.apache.maven.plugin.Mojo#execute() *//*w w w . jav a 2 s . c om*/ public void execute() throws MojoExecutionException { now = System.currentTimeMillis(); if (isPropertyWanted(buildNumberProperty)) doExportProperty(buildNumberProperty, getVersion()); if (isPropertyWanted(timestampProperty)) doExportProperty(timestampProperty, getTimeStamp(timestampFormat)); if (isWorkingCopy()) { if (doCheck && !doCheck() && !neverFail) throw new MojoExecutionException("Checking working copy fails!"); if (isPropertyWanted(revisionNumberProperty)) doExportProperty(revisionNumberProperty, String.valueOf(getSVNInfo().getRevision())); if (isPropertyWanted(lastCommittedRevisionProperty)) doExportProperty(lastCommittedRevisionProperty, String.valueOf(getSVNInfo().getCommittedRevision())); } getLog().info("Exported properties: " + exportedProperties); }
From source file:com.addicticks.maven.httpsupload.mojo.UploadAbstractMojo.java
License:Apache License
protected void setEndpointCredentials(HttpsFileUploaderConfig config, URL targetURL) throws MojoExecutionException { String targetHost = targetURL.getHost().toLowerCase(); Server serverSettings = settings.getServer(targetHost); if (serverSettings != null) { if (serverSettings.getUsername() != null && serverSettings.getPassword() != null) { getLog().debug("Found Server settings in settings.xml for " + targetHost + " : username : " + serverSettings.getUsername() + ", password : *********"); config.setEndpointUsername(serverSettings.getUsername()); config.setEndpointPassword(serverSettings.getPassword()); } else {//w ww .j a va 2 s .c o m throw new MojoExecutionException("Found Server settings in settings.xml for " + targetHost + " but no username and password information was found"); } } else { throw new MojoExecutionException("No Server settings found in settings.xml for " + targetHost); } }
From source file:com.addicticks.maven.httpsupload.mojo.UploadAbstractMojo.java
License:Apache License
protected void upload(HttpsFileUploaderConfig config, List<UploadItem> filesToUpload, Map<String, String> otherFields) throws MojoExecutionException { getLog().info("Uploading to " + targetURL); try {//from www .java 2 s . c o m HttpsFileUploaderResult result = HttpsFileUploader.upload(config, filesToUpload, extraFields, this); if (result.isError()) { getLog().error("Uploading was unsuccesful !"); String responseText = result.getResponseTextNoHtml(); throw new MojoExecutionException("Could not upload to " + targetURL + ". Error from server was : " + System.lineSeparator() + "Status code: " + Utils.getHttpStatusCodeText(result.getHttpStatusCode()) + System.lineSeparator() + ((responseText == null) ? "<server did not return a text response>" : responseText)); } } catch (IOException ex) { throw new MojoExecutionException("Error uploading file to " + targetURL.toString(), ex); } }
From source file:com.addicticks.maven.httpsupload.mojo.UploadMultipleMojo.java
License:Apache License
private void validateUploadFiles() throws MojoExecutionException { int fieldsWithNoName = 0; for (UploadFile e : uploadFiles) { if (e.getFormFieldName() == null || e.getFormFieldName().isEmpty()) { fieldsWithNoName++;// w w w . j a va 2 s . co m if (fieldsWithNoName == 1) { e.setFormFieldName("file"); } else { e.setFormFieldName("file" + fieldsWithNoName); } } if (e.getFile() == null) { throw new MojoExecutionException("'file' is required on 'uploadFile'"); } } }
From source file:com.adgear.data.plugin.IDLSchemaMojo.java
License:Apache License
/** * Recursive function which traverses the dependency graph adjacency matrix and computes the * length of the longest dependency chain. A exception is thrown when the graph is found to be * inconsistent, either through a circularity or an orphan. * * @param path Current dependency chain/*from www . j a v a 2 s.c o m*/ * @return Length of the longest subchain starting at the end of the current chain */ private Integer getDependencyRank(Map<String, IDLObject> map, List<String> path) throws MojoExecutionException { String name = path.get(path.size() - 1); int maxRank = 0; if (!map.containsKey(name)) { throw new MojoExecutionException( "Unresolved dependency: " + Arrays.toString(path.toArray(new String[path.size()]))); } Set<String> dependencies = map.get(name).getRequired(); if (dependencies == null) { return 0; } for (String required : dependencies) { ArrayList<String> requiredPath = new ArrayList<String>(path); requiredPath.add(required); if (path.contains(required)) { throw new MojoExecutionException( "Circular dependency: " + Arrays.toString(requiredPath.toArray(new String[path.size()]))); } int rank = 1 + getDependencyRank(map, requiredPath); maxRank = (rank > maxRank) ? rank : maxRank; } return maxRank; }
From source file:com.adgear.data.plugin.IDLSchemaMojo.java
License:Apache License
/** * @param map Dependency graph map * @param outputDir Directory in which to put the compiled files *///from www . ja v a 2 s .co m void compileAll(Map<String, IDLObject> map, File outputDir) throws MojoExecutionException { for (IDLObject o : map.values()) { if (o.getRequired() == null) { Schema s = new Schema.Parser().parse(o.getCode()); if (s == null) { throw new MojoExecutionException("Error parsing Avro schema " + o.getName()); } String ns = o.getName().replaceFirst("\\.[^\\.]+$", ""); String nsprop = s.getProp("namespace"); if (nsprop == null) { String code = s.toString().replaceFirst("\\{", "{\"namespace\" : \"" + ns + "\","); s = new Schema.Parser().parse(code); } else { if (!nsprop.equals(ns)) { throw new MojoExecutionException("Avro schema " + o.getName() + " declares as namespace " + nsprop + " which does not correspond to its location."); } } compileSchema(s, outputDir); } } Map<String, Integer> rankMap = new HashMap<String, Integer>(); for (Map.Entry<String, IDLObject> entry : map.entrySet()) { if (entry.getValue().getRequired() != null) { List<String> path = new ArrayList<String>(); path.add(entry.getKey()); rankMap.put(entry.getKey(), getDependencyRank(map, path)); } } ArrayList<IDLObject> list = new ArrayList<IDLObject>(); for (int oldSize = -1, rank = 0; list.size() > oldSize; ++rank) { oldSize = list.size(); for (Map.Entry<String, Integer> entry : rankMap.entrySet()) { if (entry.getValue() == rank) { list.add(map.get(entry.getKey())); } } } for (IDLObject o : list) { Set<IDLObject> set = collect(map, o); StringBuilder sb = new StringBuilder(); sb.append("protocol ").append(o.getName().replaceAll("\\.", "_")).append("__protocol {"); for (IDLObject obj : list) { if (set.contains(obj)) { sb.append('\n').append(obj.getCode()).append('\n'); } } sb.append("}\n"); Protocol p = parseProtocol(sb.toString()); for (Schema s : p.getTypes()) { compileSchema(s, outputDir); } } }
From source file:com.adviser.maven.MojoSupport.java
License:Apache License
protected Artifact resourceToArtifact(String resourceLocation, boolean skipNonMavenProtocols) throws MojoExecutionException { resourceLocation = resourceLocation.replace("\r\n", "").replace("\n", "").replace(" ", "").replace("\t", "");/*from w ww . ja v a 2 s . c o m*/ final int index = resourceLocation.indexOf("mvn:"); if (index < 0) { if (skipNonMavenProtocols) { return null; } throw new MojoExecutionException("Resource URL is not a maven URL: " + resourceLocation); } else { resourceLocation = resourceLocation.substring(index + "mvn:".length()); } // Truncate the URL when a '#', a '?' or a '$' is encountered final int index1 = resourceLocation.indexOf('?'); final int index2 = resourceLocation.indexOf('#'); int endIndex = -1; if (index1 > 0) { if (index2 > 0) { endIndex = Math.min(index1, index2); } else { endIndex = index1; } } else if (index2 > 0) { endIndex = index2; } if (endIndex >= 0) { resourceLocation = resourceLocation.substring(0, endIndex); } final int index3 = resourceLocation.indexOf('$'); if (index3 > 0) { resourceLocation = resourceLocation.substring(0, index3); } //check if the resourceLocation descriptor contains also remote repository information. ArtifactRepository repo = null; if (resourceLocation.startsWith("http://")) { final int repoDelimIntex = resourceLocation.indexOf('!'); String repoUrl = resourceLocation.substring(0, repoDelimIntex); repo = new DefaultArtifactRepository(repoUrl, repoUrl, new DefaultRepositoryLayout()); org.apache.maven.repository.Proxy mavenProxy = configureProxyToInlineRepo(); if (mavenProxy != null) { repo.setProxy(mavenProxy); } resourceLocation = resourceLocation.substring(repoDelimIntex + 1); } String[] parts = resourceLocation.split("/"); String groupId = parts[0]; String artifactId = parts[1]; String version = null; String classifier = null; String type = "jar"; if (parts.length > 2) { version = parts[2]; if (parts.length > 3) { type = parts[3]; if (parts.length > 4) { classifier = parts[4]; } } } else { Dependency dep = findDependency(project.getDependencies(), artifactId, groupId); if (dep == null && project.getDependencyManagement() != null) { dep = findDependency(project.getDependencyManagement().getDependencies(), artifactId, groupId); } if (dep != null) { version = dep.getVersion(); classifier = dep.getClassifier(); type = dep.getType(); } } if (version == null || version.length() == 0) { throw new MojoExecutionException("Cannot find version for: " + resourceLocation); } Artifact artifact = factory.createArtifactWithClassifier(groupId, artifactId, version, type, classifier); artifact.setRepository(repo); return artifact; }
From source file:com.agilejava.blammo.mojo.BlammoGeneratorMojo.java
License:Open Source License
public void execute() throws MojoExecutionException, MojoFailureException { List loggers = null;//from w ww . j av a 2s . c om try { loggers = new BlammoParser(messageIdPrefix, messageIdOffset).parse(javaSourcesDir); } catch (BlammoParserException bpe) { throw new MojoExecutionException( bpe.getMessage() + ": line " + bpe.getLineNumber() + " in " + bpe.getSourceFile().getFile()); } produceImplementations(loggers); produceResourceFiles(loggers); project.addCompileSourceRoot(targetDirectory.getAbsolutePath()); Resource resource = new Resource(); resource.setDirectory(targetDirectory.getAbsolutePath()); ArrayList patterns = new ArrayList(); patterns.add("**/*.properties"); resource.setIncludes(patterns); project.getBuild().addResource(resource); }
From source file:com.agilejava.docbkx.maven.AbstractCitrusPdfMojo.java
License:Open Source License
private void setField(Class<?> targetType, String fieldName, Object value) throws MojoExecutionException { try {/*from w w w . j av a2 s . c o m*/ Field field = targetType.getDeclaredField(fieldName); if (field != null) { field.setAccessible(true); field.set(this, value); } } catch (Exception e) { throw new MojoExecutionException(e.getMessage()); } }
From source file:com.agilejava.docbkx.maven.AbstractFoMojo.java
License:Apache License
private InputStream openFileForInput(File file) throws MojoExecutionException { try {/* w ww . j av a 2 s .co m*/ return new FileInputStream(file); } catch (FileNotFoundException fnfe) { throw new MojoExecutionException("Failed to open " + file + " for input."); } }