List of usage examples for org.apache.maven.project MavenProject getInceptionYear
public String getInceptionYear()
From source file:com.rodiontsev.maven.plugins.buildinfo.providers.ProjectInfoProvider.java
License:Apache License
public Map<String, String> getInfo(MavenProject project, BuildInfoMojo mojo) { // finite set of project properties we expose final Map<String, String> props = new LinkedHashMap<String, String>(65); props.put("project.id", project.getId()); props.put("project.groupId", project.getGroupId()); props.put("project.artifactId", project.getArtifactId()); props.put("project.version", project.getVersion()); props.put("project.name", project.getName()); props.put("project.description", project.getDescription()); props.put("project.modelVersion", project.getModelVersion()); props.put("project.inceptionYear", project.getInceptionYear()); props.put("project.packaging", project.getPackaging()); props.put("project.url", project.getUrl()); final MavenProject parent = project.getParent(); if (parent != null) { props.put("project.parent.id", parent.getId()); props.put("project.parent.groupId", parent.getGroupId()); props.put("project.parent.artifactId", parent.getArtifactId()); props.put("project.parent.version", parent.getVersion()); props.put("project.parent.name", parent.getName()); props.put("project.parent.description", parent.getDescription()); props.put("project.parent.modelVersion", parent.getModelVersion()); props.put("project.parent.inceptionYear", parent.getInceptionYear()); props.put("project.parent.packaging", parent.getPackaging()); props.put("project.parent.url", parent.getUrl()); }//from w ww . j a v a 2 s . c o m // properties the user wants Map<String, String> info = new LinkedHashMap<String, String>(); for (String propertyName : mojo.getProjectProperties()) { String prop = props.get(propertyName); if (prop != null) { info.put(propertyName, prop); } } info.put("build.time", DateFormatUtils.format(new Date(), "d MMMM yyyy, HH:mm:ss ZZ", Locale.ENGLISH)); return info; }
From source file:com.rodiontsev.maven.plugins.buildinfo.providers.ProjectPropertiesProvider.java
License:Apache License
public Map<String, String> getInfo(MavenProject project, BuildInfoMojo mojo) { // finite set of project properties we expose final Map<String, String> projectProperties = new LinkedHashMap<String, String>(65); projectProperties.put("project.id", project.getId()); projectProperties.put("project.groupId", project.getGroupId()); projectProperties.put("project.artifactId", project.getArtifactId()); projectProperties.put("project.version", project.getVersion()); projectProperties.put("project.name", project.getName()); projectProperties.put("project.description", project.getDescription()); projectProperties.put("project.modelVersion", project.getModelVersion()); projectProperties.put("project.inceptionYear", project.getInceptionYear()); projectProperties.put("project.packaging", project.getPackaging()); projectProperties.put("project.url", project.getUrl()); MavenProject parent = project.getParent(); if (parent != null) { projectProperties.put("project.parent.id", parent.getId()); projectProperties.put("project.parent.groupId", parent.getGroupId()); projectProperties.put("project.parent.artifactId", parent.getArtifactId()); projectProperties.put("project.parent.version", parent.getVersion()); projectProperties.put("project.parent.name", parent.getName()); projectProperties.put("project.parent.description", parent.getDescription()); projectProperties.put("project.parent.modelVersion", parent.getModelVersion()); projectProperties.put("project.parent.inceptionYear", parent.getInceptionYear()); projectProperties.put("project.parent.packaging", parent.getPackaging()); projectProperties.put("project.parent.url", parent.getUrl()); }//from www . j a va 2s . co m Map<String, String> info = new LinkedHashMap<String, String>(); new InfoWriter().write(info, mojo.getProjectProperties(), new PropertyMapper() { @Override public String mapProperty(String propertyName) { return projectProperties.get(propertyName); } }); return info; }
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:org.arakhne.maven.plugins.tagreplacer.AbstractReplaceMojo.java
License:Open Source License
/** * Replace Javadoc tags in a string./*from www.java 2 s .c o m*/ * * @param sourceFile * is the filename in which the replacement is done. * @param sourceLine * is the line at which the replacement is done. * @param file * is the name of the file in the hierarchy from which the string was extracted. * @param artifact * is the artifact in which the file is located. If <code>null</code> the tags dedicated to the artifact will be replaced by the empty string. * @param line * is the line in which the tags should be replaced. * @param replacementType * is the type of replacement to be done. * @return the result of the replacement. * @throws MojoExecutionException */ protected synchronized String replaceInString(File sourceFile, int sourceLine, String file, ExtendedArtifact artifact, String line, ReplacementType replacementType) throws MojoExecutionException { // No possibility of replacement if (!line.contains("$")) //$NON-NLS-1$ return line; String nline = line; String replacementName = (artifact == null) ? null : artifact.getName(); String replacementVersion = (artifact == null) ? null : artifact.getVersion(); String replacementRevision = (artifact == null) ? null : artifact.getScmRevision(); String replacementArtifactId = ensureArtifactId(artifact); String replacementGroupId = ensureGroupId(artifact); String replacementWebsite = (artifact == null) ? null : artifact.getWebsite(); String replacementFilename = (artifact == null) ? null : file; String replacementOrganization = null; if (artifact != null) { Organization orga = artifact.getOrganization(); if (orga != null) { replacementOrganization = orga.getName(); } } SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //$NON-NLS-1$ String currentDate = fmt.format(this.invocationDate); fmt = new SimpleDateFormat("yyyy"); //$NON-NLS-1$ String year = fmt.format(this.invocationDate); String inceptionYear = null; MavenProject project = getMavenProject(artifact); if (project != null) { inceptionYear = project.getInceptionYear(); } if (inceptionYear == null || inceptionYear.isEmpty()) { inceptionYear = year; } String replacementFullVersion; if (artifact == null) { replacementFullVersion = null; } else { String rev = null; if (replacementRevision != null) { rev = "(rev:" + //$NON-NLS-1$ replacementRevision + ")"; //$NON-NLS-1$ } replacementFullVersion = join(" ", //$NON-NLS-1$ replacementVersion, rev, currentDate); } nline = replaceMacro(MACRO_NAME, nline, replacementName, replacementType, sourceFile, sourceLine); nline = replaceMacro(MACRO_REVISION, nline, replacementRevision, replacementType, sourceFile, sourceLine); nline = replaceMacro(MACRO_VERSION, nline, replacementVersion, replacementType, sourceFile, sourceLine); nline = replaceMacro(MACRO_ARTIFACTID, nline, replacementArtifactId, replacementType, sourceFile, sourceLine); nline = replaceMacro(MACRO_GROUPID, nline, replacementGroupId, replacementType, sourceFile, sourceLine); nline = replaceMacro(MACRO_WEBSITE, nline, replacementWebsite, replacementType, sourceFile, sourceLine); nline = replaceMacro(MACRO_ORGANIZATION, nline, replacementOrganization, replacementType, sourceFile, sourceLine); nline = replaceMacro(MACRO_DATE, nline, currentDate, replacementType, sourceFile, sourceLine); nline = replaceMacro(MACRO_YEAR, nline, year, replacementType, sourceFile, sourceLine); nline = replaceMacro(MACRO_INCEPTIONYEAR, nline, inceptionYear, replacementType, sourceFile, sourceLine); nline = replaceMacro(MACRO_FULLVERSION, nline, replacementFullVersion, replacementType, sourceFile, sourceLine); nline = replaceMacro(MACRO_FILENAME, nline, replacementFilename, replacementType, sourceFile, sourceLine); StringBuilder buffer = new StringBuilder(); buffer.setLength(0); // Split the string int "$" and "Id" to avoid the plugin to replace the tag in its own source fole buffer.append("$" + "Id: "); //$NON-NLS-1$ //$NON-NLS-2$ buffer.append(file); buffer.append(' '); if (replacementRevision != null) { buffer.append("rev:"); //$NON-NLS-1$ buffer.append(replacementRevision); buffer.append(' '); } if (replacementVersion != null) { buffer.append('v'); buffer.append(replacementVersion); buffer.append(' '); } buffer.append(currentDate); buffer.append("$"); //$NON-NLS-1$ nline = replaceMacro(MACRO_ID, nline, buffer.toString(), ReplacementType.TEXT, sourceFile, sourceLine); nline = replaceAuthor(sourceFile, sourceLine, nline, artifact, replacementType); nline = replaceProp(sourceFile, sourceLine, nline, project, replacementType); return nline; }
From source file:org.fluidity.foundation.impl.BundleJarManifest.java
License:Apache License
public SecurityPolicy processManifest(final MavenProject project, final Attributes attributes, final SecurityPolicy policy, final Logger log, final Dependencies dependencies) throws MojoExecutionException { dependencies.attribute(BUNDLE_CLASSPATH, ","); addEntry(attributes, BUNDLE_MANIFESTVERSION, "2"); addEntry(attributes, BUNDLE_NAME, project::getName); addEntry(attributes, BUNDLE_SYMBOLICNAME, project::getArtifactId); addEntry(attributes, BUNDLE_VERSION, project::getVersion); addEntry(attributes, BUNDLE_DESCRIPTION, project::getDescription); addEntry(attributes, BUNDLE_DOCURL, project::getUrl); addEntry(attributes, BUNDLE_VENDOR, () -> { return project.getOrganization().getName(); });/*from ww w . ja v a2 s. c o m*/ addEntry(attributes, BUNDLE_COPYRIGHT, () -> { final String year = project.getInceptionYear(); return year == null ? null : String.format("Copyright %s (c) %s. All rights reserved.", project.getOrganization().getName(), year); }); addEntry(attributes, REQUIRE_CAPABILITY, () -> { // https://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html final String[] version = System.getProperty("java.version").split("\\."); return String.format("osgi.ee;filter:=(&(osgi.ee=JavaSE)(version>=%s.%s))", version[0], version[1]); }); final String version = attributes.getValue(BUNDLE_VERSION); if (version != null) { attributes.putValue(BUNDLE_VERSION, verify(version)); } else { addEntry(attributes, BUNDLE_VERSION, DEFAULT_BUNDLE_VERSION); } final RegexBasedInterpolator interpolator = new RegexBasedInterpolator(); final List<String> prefixes = Collections.singletonList("project."); interpolator.addValueSource(new PropertiesBasedValueSource(System.getProperties())); interpolator.addValueSource(new PrefixedPropertiesValueSource(prefixes, project.getProperties(), true)); interpolator.addValueSource(new PrefixedObjectValueSource(prefixes, project.getModel(), true)); final RecursionInterceptor interceptor = new PrefixAwareRecursionInterceptor(prefixes, true); interpolator.setCacheAnswers(true); interpolator.setReusePatterns(true); interpolator.addPostProcessor((ignored, value) -> verify((String) value)); try { interpolateHeaders(attributes, interpolator, interceptor, EXPORT_PACKAGE, IMPORT_PACKAGE, DYNAMICIMPORT_PACKAGE, FRAGMENT_HOST, REQUIRE_BUNDLE, BUNDLE_NATIVECODE); } catch (final InterpolationException e) { throw new IllegalStateException(e); } final Collection<Artifact> artifacts = dependencies.compiler(); // if embedding project dependencies, see if Fluid Tools composition is included and if so, add a bundle activator to bootstrap the system. if (!artifacts.isEmpty()) { try { // create a class loader that sees the project's compile-time dependencies final Set<URL> urls = new HashSet<>(); final String skippedId = project.getArtifact().getId(); for (final Artifact dependency : artifacts) { // we don't need the project artifact and don't want to prevent the caller from overwriting it by locking the file... if (!skippedId.equals(dependency.getId())) { urls.add(dependency.getFile().toURI().toURL()); } } final Method method = Methods.get(BootstrapDiscovery.class, BootstrapDiscovery::activator)[0]; urls.add((Archives.containing(BootstrapDiscovery.class))); urls.add((Archives.containing(BootstrapDiscoveryImpl.class))); urls.add((Archives.containing(ComponentContainer.class))); final String activator = isolate(null, urls, BootstrapDiscoveryImpl.class, method); if (activator != null) { addEntry(attributes, BUNDLE_ACTIVATOR, activator); } if (log.active()) { final String value = attributes.getValue(BUNDLE_ACTIVATOR); log.detail("Bundle activator: %s", value == null ? "none" : value.equals(BundleBootstrap.class.getName()) ? "built in" : value); } } catch (final ClassNotFoundException e) { // that's OK } catch (final Exception e) { throw new IllegalStateException(e); } } return new OsgiLocalPermissions(policy, artifacts, attributes.getValue(DYNAMICIMPORT_PACKAGE), attributes.getValue(IMPORT_PACKAGE), attributes.getValue(EXPORT_PACKAGE)); }
From source file:se.natusoft.tools.codelicmgr.MojoUtils.java
License:Open Source License
/** * This will take config values that are not specified or specified as blank and * look for that information elsewhere in the maven project and if found, update * the configuration with that information. * <p>/*from w w w . j a va 2 s. c o m*/ * The reason for this is to minimize duplication of information in the pom. Some * of the information managed by CodeLicenseManager is also available as standard * information in a pom and is used by site:site to generate documentation. * * @param project The CLM project config. * @param mavenProject Maven project info from pom. */ public static ProjectConfig updateConfigFromMavenProject(ProjectConfig project, MavenProject mavenProject) { // Project if (project == null) { // Will be null if no <project> tag is specified! project = new ProjectConfig(); } if (isEmpty(project.getName())) { project.setName(getFirstNonEmpty(mavenProject.getName(), mavenProject.getArtifactId())); } if (isEmpty(project.getDescription())) { project.setDescription(mavenProject.getDescription()); } // License LicenseConfig licenseConf = project.getLicense(); if (licenseConf == null) { licenseConf = new LicenseConfig(); project.setLicense(licenseConf); } if (licenseConf.getType() == null) { List<org.apache.maven.model.License> lics = mavenProject.getLicenses(); if (lics != null && lics.size() >= 1) { org.apache.maven.model.License lic = lics.get(0); String licName = getLicenseName(lic.getName().replaceAll("-", " ")); if (licName.trim().length() > 0) { licenseConf.setType(licName); } String licVer = getLicenseVersion(lic.getName().replaceAll("-", " ")); if (licVer.trim().length() > 0) { licenseConf.setVersion(licVer); } } } // Copyright if (project.getCopyrights().getCopyrights().size() == 0) { CopyrightConfig copyrightConf = new CopyrightConfig(); copyrightConf.setHolder(mavenProject.getOrganization().getName()); copyrightConf.setYear(mavenProject.getInceptionYear()); project.getCopyrights().addCopyright(copyrightConf); } return project; }