List of usage examples for org.apache.maven.project MavenProject getDescription
public String getDescription()
From source file:de.saumya.mojo.gem.GemspecWriter.java
@SuppressWarnings("unchecked") GemspecWriter(final File gemspec, final MavenProject project, final GemArtifact artifact) throws IOException { this.latestModified = project.getFile() == null ? 0 : project.getFile().lastModified(); this.gemspec = gemspec; this.gemspec.getParentFile().mkdirs(); this.writer = new FileWriter(gemspec); this.project = project; append("Gem::Specification.new do |s|"); append("name", artifact.getGemName()); append("version", gemVersion(project.getVersion())); append();/*from w w w .j av a 2s.com*/ append("summary", project.getName()); append("description", project.getDescription()); append("homepage", project.getUrl()); append(); for (final Developer developer : (List<Developer>) project.getDevelopers()) { appendAuthor(developer.getName(), developer.getEmail()); } for (final Contributor contributor : (List<Contributor>) project.getContributors()) { appendAuthor(contributor.getName(), contributor.getEmail()); } append(); for (final License license : (List<License>) project.getLicenses()) { appendLicense(license.getUrl(), license.getName()); } }
From source file:fr.in2p3.maven.plugin.DependencyXmlMojo.java
private void dump(DependencyNode current, PrintStream out) throws MojoExecutionException, MojoFailureException { String artifactId = current.getArtifact().getArtifactId(); boolean hasClassifier = (current.getArtifact().getClassifier() != null); if ((artifactId.startsWith("jsaga-") || artifactId.startsWith("saga-")) && !hasClassifier) { MavenProject module = this.getMavenProject(current.getArtifact()); if (module != null) { // Filter does NOT work // AndArtifactFilter scopeFilter = new AndArtifactFilter(); // scopeFilter.add(new ScopeArtifactFilter(Artifact.SCOPE_COMPILE)); // scopeFilter.add(new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME)); try { current = dependencyTreeBuilder.buildDependencyTree(module, localRepository, factory, artifactMetadataSource, null, collector); } catch (DependencyTreeBuilderException e) { throw new MojoExecutionException("Unable to build dependency tree", e); }//from w w w .ja v a 2 s.c o m } } // dump (part 1) indent(current, out); out.print("<artifact"); Artifact artifact = current.getArtifact(); addAttribute(out, "id", artifact.getArtifactId()); addAttribute(out, "group", artifact.getGroupId()); // Get version from HashMap String v = includedArtifacts.get(artifact.getArtifactId()); if (v != null) { artifact.setVersion(v); } addAttribute(out, "version", artifact.getVersion()); addAttribute(out, "type", artifact.getType()); addAttribute(out, "scope", artifact.getScope()); addAttribute(out, "classifier", artifact.getClassifier()); try { addAttribute(out, "file", this.getJarFile(artifact).toString()); } catch (Exception e) { getLog().debug(artifact.getArtifactId() + "Could not find JAR"); } MavenProject proj = this.getMavenProject(artifact); if (proj != null) { if (!proj.getName().startsWith("Unnamed - ")) { addAttribute(out, "name", proj.getName()); } addAttribute(out, "description", proj.getDescription()); addAttribute(out, "url", proj.getUrl()); if (proj.getOrganization() != null) { addAttribute(out, "organization", proj.getOrganization().getName()); addAttribute(out, "organizationUrl", proj.getOrganization().getUrl()); } if (proj.getLicenses().size() > 0) { License license = (License) proj.getLicenses().get(0); addAttribute(out, "license", license.getName()); addAttribute(out, "licenseUrl", license.getUrl()); } } out.println(">"); // recurse for (Iterator it = current.getChildren().iterator(); it.hasNext();) { DependencyNode child = (DependencyNode) it.next(); // filter dependencies with scope "test", except those with classifier "tests" (i.e. adaptor integration tests) if ("test".equals(child.getArtifact().getScope()) && !"tests".equals(child.getArtifact().getClassifier())) { Artifact c = child.getArtifact(); getLog().debug(artifact.getArtifactId() + ": ignoring dependency " + c.getGroupId() + ":" + c.getArtifactId()); } else { this.dump(child, out); } } // dump (part 2) indent(current, out); out.println("</artifact>"); }
From source file:guru.nidi.maven.tools.dependency.ArtifactFormatter.java
License:Apache License
private String format(Artifact artifact, String format) { final String s = format.replace("%g", artifact.getGroupId()).replace("%a", artifact.getArtifactId()) .replace("%t", artifact.getType()).replace("%v", artifact.getVersion()).replace("%n", "<br/>"); final Matcher m = Pattern.compile("%(\\d*)d(s?)").matcher(s); StringBuffer sb = new StringBuffer(); while (m.find()) { try {//from w ww .j ava 2 s.c o m final MavenProject project = mavenContext.projectFromArtifact(artifact); String desc = project == null || project.getDescription() == null ? "" : project.getDescription(); if (m.group(1).length() > 0) { desc = linebreak(desc, Integer.parseInt(m.group(1))); } final int pos = find(desc, "\\.\\s"); final String shortDesc = pos < 0 ? desc : desc.substring(0, pos + 1); m.appendReplacement(sb, m.group(2).length() == 0 ? desc : shortDesc); } catch (ProjectBuildingException e) { //ignore } } m.appendTail(sb); return sb.toString(); }
From source file:io.fabric8.maven.AbstractFabric8Mojo.java
License:Apache License
protected void copySummaryText(File appBuildDir) throws IOException { MavenProject project = getProject(); String description = project.getDescription(); if (Strings.isNotBlank(description)) { File summaryMd = new File(appBuildDir, "Summary.md"); summaryMd.getParentFile().mkdirs(); if (!summaryMd.exists()) { byte[] bytes = description.getBytes(); Files.copy(new ByteArrayInputStream(bytes), new FileOutputStream(summaryMd)); }/* w w w.j a v a 2 s. c o m*/ } }
From source file:io.fabric8.maven.HelmMojo.java
License:Apache License
protected Chart createChart() { Chart answer = new Chart(); answer.setName(chartName);/*from w w w . j a v a 2 s. c o m*/ MavenProject project = getProject(); if (project != null) { answer.setVersion(project.getVersion()); answer.setDescription(project.getDescription()); answer.setHome(project.getUrl()); List<Developer> developers = project.getDevelopers(); if (developers != null) { List<String> maintainers = new ArrayList<>(); for (Developer developer : developers) { String email = developer.getEmail(); String name = developer.getName(); String text = Strings.defaultIfEmpty(name, ""); if (Strings.isNotBlank(email)) { if (Strings.isNotBlank(text)) { text = text + " <" + email + ">"; } else { text = email; } } if (Strings.isNotBlank(text)) { maintainers.add(text); } } answer.setMaintainers(maintainers); } } return answer; }
From source file:io.fabric8.maven.ZipMojo.java
License:Apache License
protected void generateZip() throws DependencyTreeBuilderException, MojoExecutionException, IOException, MojoFailureException { File appBuildDir = buildDir;//from w ww .jav a 2s . c o m if (Strings.isNotBlank(pathInZip)) { appBuildDir = new File(buildDir, pathInZip); } appBuildDir.mkdirs(); if (hasConfigDir()) { copyAppConfigFiles(appBuildDir, appConfigDir); } else { getLog().info("The app configuration files directory " + appConfigDir + " doesn't exist, so not copying any additional project documentation or configuration files"); } MavenProject project = getProject(); if (!ignoreProject) { File kubernetesJson = getKubernetesJson(); if (kubernetesJson != null && kubernetesJson.isFile() && kubernetesJson.exists()) { File jsonFile = new File(appBuildDir, "kubernetes.json"); jsonFile.getParentFile().mkdirs(); Files.copy(kubernetesJson, jsonFile); } // TODO if no iconRef is specified we could try guess based on the project? // lets check if we can use an icon reference copyIconToFolder(appBuildDir); } // lets only generate a app zip if we have a requirement (e.g. we're not a parent pom packaging project) and // we have defined some configuration files or dependencies // to avoid generating dummy apps for parent poms if (hasConfigDir() || !ignoreProject) { if (includeReadMe) { copyReadMe(appBuildDir); } if (generateSummaryFile) { copySummaryText(appBuildDir); } if (generateAppPropertiesFile) { String name = project.getName(); if (Strings.isNullOrBlank(name)) { name = project.getArtifactId(); } String description = project.getDescription(); Properties appProperties = new Properties(); appProperties.put("name", name); if (Strings.isNotBlank(description)) { appProperties.put("description", description); } appProperties.put("groupId", project.getGroupId()); appProperties.put("artifactId", project.getArtifactId()); appProperties.put("version", project.getVersion()); File appPropertiesFile = new File(appBuildDir, "fabric8.properties"); appPropertiesFile.getParentFile().mkdirs(); if (!appPropertiesFile.exists()) { appProperties.store(new FileWriter(appPropertiesFile), "Fabric8 Properties"); } } File outputZipFile = getZipFile(); File legalDir = null; if (includeLegal) { legalDir = new File(project.getBuild().getOutputDirectory(), "META-INF"); } Zips.createZipFile(getLog(), buildDir, outputZipFile, legalDir); projectHelper.attachArtifact(project, artifactType, artifactClassifier, outputZipFile); getLog().info("Created app zip file: " + outputZipFile); } }
From source file:io.sarl.maven.docs.AbstractDocumentationMojo.java
License:Apache License
private Properties createProjectProperties() { final Properties props = new Properties(); final MavenProject prj = this.session.getCurrentProject(); props.put("project.groupId", prj.getGroupId()); //$NON-NLS-1$ props.put("project.artifactId", prj.getArtifactId()); //$NON-NLS-1$ props.put("project.basedir", prj.getBasedir()); //$NON-NLS-1$ props.put("project.description", prj.getDescription()); //$NON-NLS-1$ props.put("project.id", prj.getId()); //$NON-NLS-1$ props.put("project.inceptionYear", prj.getInceptionYear()); //$NON-NLS-1$ props.put("project.name", prj.getName()); //$NON-NLS-1$ props.put("project.version", prj.getVersion()); //$NON-NLS-1$ props.put("project.url", prj.getUrl()); //$NON-NLS-1$ props.put("project.encoding", this.encoding); //$NON-NLS-1$ return props; }
From source file:net.ubos.tools.pacmanpkgmavenplugin.PacmanPkgMavenPlugin.java
License:Open Source License
/** * {@inheritDoc}/* w w w . ja v a 2 s . c om*/ * * @throws MojoExecutionException */ @Override public void execute() throws MojoExecutionException { MavenProject project = (MavenProject) getPluginContext().get("project"); String packaging = project.getPackaging(); if (!"jar".equals(packaging) && !"ear".equals(packaging) && !"war".equals(packaging)) { return; } getLog().info("Generating PKGBUILD @ " + project.getName()); // pull stuff out of MavenProject String artifactId = project.getArtifactId(); String version = project.getVersion(); String url = project.getUrl(); String description = project.getDescription(); Set<Artifact> dependencies = project.getDependencyArtifacts(); File artifactFile = project.getArtifact().getFile(); if (artifactFile == null || !artifactFile.exists()) { throw new MojoExecutionException("pacmanpkg must be executed as part of a build, not standalone," + " otherwise it can't find the main JAR file"); } // translate to PKGBUILD fields String pkgname = artifactId; String pkgver = version.replaceAll("-SNAPSHOT", "a"); // alpha String pkgdesc = "A Java package available on UBOS"; if (description != null) { if (description.length() > 64) { pkgdesc = description.substring(0, 64) + "..."; } else { pkgdesc = description; } } ArrayList<String> depends = new ArrayList<>(dependencies.size()); for (Artifact a : dependencies) { if (!"test".equals(a.getScope())) { depends.add(a.getArtifactId()); } } // write to PKGBUILD try { File baseDir = project.getBasedir(); File pkgBuild = new File(baseDir, "target/PKGBUILD"); PrintWriter out = new PrintWriter(pkgBuild); getLog().debug("Writing PKGBUILD to " + pkgBuild.getAbsolutePath()); out.println("#"); out.println(" * Automatically generated by pacman-pkg-maven-plugin; do not modify."); out.println("#"); out.println(); out.println("pkgname=" + pkgname); out.println("pkgver=" + pkgver); out.println("pkgrel=" + pkgrel); out.println("pkgdesc='" + pkgdesc + "'"); out.println("arch=('any')"); out.println("url='" + url + "'"); out.println("license=('" + license + "')"); out.print("depends=("); String sep = ""; for (String d : depends) { out.print(sep); sep = ","; out.print("'"); out.print(d); out.print("'"); } out.println(")"); out.println(); out.println("package() ("); out.println(" mkdir -p ${pkgdir}/usr/share/java"); out.println(" install -m644 ${startdir}/" + artifactFile.getName() + " ${pkgdir}/usr/share/java/"); out.println(")"); out.close(); } catch (IOException ex) { throw new MojoExecutionException("Failed to write target/PKGBUILD", ex); } }
From source file:npanday.assembler.impl.AssemblerContextImpl.java
License:Apache License
public AssemblyInfo getAssemblyInfo(MavenProject mavenProject) { String basedir = mavenProject.getBasedir().toString(); AssemblyInfo assemblyInfo = new AssemblyInfo(); String description = (mavenProject.getDescription() != null) ? mavenProject.getDescription() : ""; String version = (mavenProject.getVersion() != null) ? mavenProject.getVersion() : ""; String name = mavenProject.getName(); Organization org = mavenProject.getOrganization(); String company = (org != null) ? org.getName() : ""; String copyright = ""; String informationalVersion = ""; String configuration = ""; File file = new File(basedir + "/COPYRIGHT.txt"); if (file.exists()) { logger.debug("NPANDAY-020-000: Found Copyright: " + file.getAbsolutePath()); FileInputStream fis = null; try {// ww w. ja v a 2 s. c o m fis = new FileInputStream(file); copyright = IOUtil.toString(fis).replace("\r", " ").replace("\n", " ").replace("\"", "'"); } catch (IOException e) { logger.info("NPANDAY-020-001: Could not get copyright: File = " + file.getAbsolutePath(), e); } finally { if (fis != null) { IOUtil.close(fis); } } } informationalVersion = version; if (version.contains("-")) { version = version.split("-")[0]; } assemblyInfo.setCompany(company); assemblyInfo.setCopyright(copyright); assemblyInfo.setCulture(""); assemblyInfo.setDescription(description); assemblyInfo.setProduct(company + "-" + name); assemblyInfo.setTitle(name); assemblyInfo.setTrademark(""); assemblyInfo.setInformationalVersion(informationalVersion); assemblyInfo.setVersion(version); assemblyInfo.setConfiguration(configuration); return assemblyInfo; }
From source file:org.apache.camel.maven.packaging.PackageComponentMojo.java
License:Apache License
public static void prepareComponent(Log log, MavenProject project, MavenProjectHelper projectHelper, File componentOutDir) throws MojoExecutionException { File camelMetaDir = new File(componentOutDir, "META-INF/services/org/apache/camel/"); StringBuilder buffer = new StringBuilder(); int count = 0; for (Resource r : project.getBuild().getResources()) { File f = new File(r.getDirectory()); if (!f.exists()) { f = new File(project.getBasedir(), r.getDirectory()); }/*from w ww .jav a 2 s . com*/ f = new File(f, "META-INF/services/org/apache/camel/component"); if (f.exists() && f.isDirectory()) { File[] files = f.listFiles(); if (files != null) { for (File file : files) { // skip directories as there may be a sub .resolver directory if (file.isDirectory()) { continue; } String name = file.getName(); if (name.charAt(0) != '.') { count++; if (buffer.length() > 0) { buffer.append(" "); } buffer.append(name); } } } } } if (count > 0) { Properties properties = new Properties(); String names = buffer.toString(); properties.put("components", names); properties.put("groupId", project.getGroupId()); properties.put("artifactId", project.getArtifactId()); properties.put("version", project.getVersion()); properties.put("projectName", project.getName()); if (project.getDescription() != null) { properties.put("projectDescription", project.getDescription()); } camelMetaDir.mkdirs(); File outFile = new File(camelMetaDir, "component.properties"); try { properties.store(new FileWriter(outFile), "Generated by camel-package-maven-plugin"); log.info("Generated " + outFile + " containing " + count + " Camel " + (count > 1 ? "components: " : "component: ") + names); if (projectHelper != null) { List<String> includes = new ArrayList<String>(); includes.add("**/component.properties"); projectHelper.addResource(project, componentOutDir.getPath(), includes, new ArrayList<String>()); projectHelper.attachArtifact(project, "properties", "camelComponent", outFile); } } catch (IOException e) { throw new MojoExecutionException("Failed to write properties to " + outFile + ". Reason: " + e, e); } } else { log.debug( "No META-INF/services/org/apache/camel/component directory found. Are you sure you have created a Camel component?"); } }