List of usage examples for org.apache.maven.project MavenProject getArtifactId
public String getArtifactId()
From source file:org.wso2.siddhi.doc.gen.core.MkdocsGitHubPagesDeployMojo.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { // Finding the root maven project MavenProject rootMavenProject = mavenProject; while (rootMavenProject.getParent().getBasedir() != null) { rootMavenProject = rootMavenProject.getParent(); }/* w w w .jav a2s . c om*/ // Setting the relevant modules target directory if not set by user String moduleTargetPath; if (moduleTargetDirectory != null) { moduleTargetPath = moduleTargetDirectory.getAbsolutePath(); } else { moduleTargetPath = mavenProject.getBuild().getDirectory(); } // Setting the mkdocs config file path if not set by user if (mkdocsConfigFile == null) { mkdocsConfigFile = new File(rootMavenProject.getBasedir() + File.separator + Constants.MKDOCS_CONFIG_FILE_NAME + Constants.YAML_FILE_EXTENSION); } // Setting the documentation output directory if not set by user String docGenBasePath; if (docGenBaseDirectory != null) { docGenBasePath = docGenBaseDirectory.getAbsolutePath(); } else { docGenBasePath = rootMavenProject.getBasedir() + File.separator + Constants.DOCS_DIRECTORY; } // Setting the home page file name if not set by user File homePageFile; if (homePageFileName == null) { homePageFile = new File(docGenBasePath + File.separator + Constants.HOMEPAGE_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION); } else { homePageFile = new File(docGenBasePath + File.separator + homePageFileName); } // Setting the readme file name if not set by user if (readmeFile == null) { readmeFile = new File(rootMavenProject.getBasedir() + File.separator + Constants.README_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION); } // Setting the home page template file path if not set by user if (homePageTemplateFile == null) { homePageTemplateFile = new File(rootMavenProject.getBasedir() + File.separator + Constants.README_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION); } // Retrieving metadata List<NamespaceMetaData> namespaceMetaDataList; try { namespaceMetaDataList = DocumentationUtils.getExtensionMetaData(moduleTargetPath, mavenProject.getRuntimeClasspathElements(), getLog()); } catch (DependencyResolutionRequiredException e) { throw new MojoFailureException("Unable to resolve dependencies of the project", e); } // Generating the documentation if (namespaceMetaDataList.size() > 0) { DocumentationUtils.generateDocumentation(namespaceMetaDataList, docGenBasePath, mavenProject.getVersion(), getLog()); DocumentationUtils.updateHeadingsInMarkdownFile(homePageTemplateFile, homePageFile, rootMavenProject.getArtifactId(), mavenProject.getVersion(), namespaceMetaDataList); DocumentationUtils.updateHeadingsInMarkdownFile(readmeFile, readmeFile, rootMavenProject.getArtifactId(), mavenProject.getVersion(), namespaceMetaDataList); } // Delete snapshot files DocumentationUtils.removeSnapshotAPIDocs(mkdocsConfigFile, docGenBasePath, getLog()); // Updating the links in the home page to the mkdocs config try { updateAPIPagesInMkdocsConfig(mkdocsConfigFile, docGenBasePath); } catch (FileNotFoundException e) { getLog().warn("Unable to find mkdocs configuration file: " + mkdocsConfigFile.getAbsolutePath() + ". Mkdocs configuration file not updated."); } // Deploying the documentation if (DocumentationUtils.generateMkdocsSite(mkdocsConfigFile, getLog())) { // Creating the credential provider fot Git String scmUsername = System.getenv(Constants.SYSTEM_PROPERTY_SCM_USERNAME_KEY); String scmPassword = System.getenv(Constants.SYSTEM_PROPERTY_SCM_PASSWORD_KEY); if (scmUsername == null && scmPassword == null) { getLog().info("SCM_USERNAME and SCM_PASSWORD not defined!"); } String url = null; Scm scm = rootMavenProject.getScm(); if (scm != null) { url = scm.getUrl(); } // Deploying documentation DocumentationUtils.updateDocumentationOnGitHub(docGenBasePath, mkdocsConfigFile, readmeFile, mavenProject.getVersion(), getLog()); DocumentationUtils.deployMkdocsOnGitHubPages(mavenProject.getVersion(), rootMavenProject.getBasedir(), url, scmUsername, scmPassword, getLog()); } else { getLog().warn("Unable to generate documentation. Skipping documentation deployment."); } }
From source file:pl.project13.maven.git.GitDirLocator.java
License:Open Source License
/** * Find a project in the reactor by its artifact, I'm new to maven coding * so there may be a better way to do this, it would not be necessary * if project.getParent() actually worked. * * @return MavenProject parent project or NULL if no parent available *//*w w w.j a va 2s .c om*/ private Optional<MavenProject> getReactorParentProject(@NotNull MavenProject project) { Artifact parentArtifact = project.getParentArtifact(); if (parentArtifact != null) { for (MavenProject reactorProject : this.reactorProjects) { if (reactorProject.getArtifactId().equals(parentArtifact.getArtifactId())) { return Optional.of(reactorProject); } } } return Optional.absent(); }
From source file:se.jguru.nazgul.tools.codestyle.enforcer.rules.AbstractEnforcerRule.java
License:Apache License
/** * This is the interface into the rule. This method should throw an exception * containing a reason message if the rule fails the check. The plugin will * then decide based on the fail flag if it should stop or just log the * message as a warning./*from w ww . j a v a 2s .com*/ * * @param helper The helper provides access to the log, MavenSession and has * helpers to get common components. It is also able to lookup components * by class name. * @throws org.apache.maven.enforcer.rule.api.EnforcerRuleException the enforcer rule exception */ @Override @SuppressWarnings("PMD.PreserveStackTrace") public final void execute(final EnforcerRuleHelper helper) throws EnforcerRuleException { final MavenProject project; try { project = (MavenProject) helper.evaluate("${project}"); } catch (final ExpressionEvaluationException e) { // Whoops. final String msg = "Could not acquire MavenProject. (Expression lookup failure for: " + e.getLocalizedMessage() + ")"; throw new EnforcerRuleException(msg, e); } // Delegate. try { performValidation(project, helper); } catch (RuleFailureException e) { // Create a somewhat verbose failure message. String message = "\n" + "\n#" + "\n# Structure rule failure:" + "\n# " + getShortRuleDescription() + "\n# " + "\n# Message: " + e.getLocalizedMessage() + "\n# " + "\n# Offending project [" + project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion() + "]" + "\n#"; final Artifact art = e.getOffendingArtifact(); if (art != null) { message += "\n# Offending artifact [" + art.getGroupId() + ":" + art.getArtifactId() + ":" + art.getVersion() + "]" + "\n#"; } message += "\n"; // Re-throw for pretty print throw new EnforcerRuleException(message); } }
From source file:se.jguru.nazgul.tools.codestyle.enforcer.rules.ProjectType.java
License:Apache License
/** * Acquires the ProjectType instance for the provided MavenProject, * or throws an IllegalArgumentException holding an exception message * if a ProjectType could not be found for the provided MavenProject. * * @param project The MavenProject to classify. * @return The corresponding ProjectType. * @throws IllegalArgumentException if the given project could not be mapped to a [single] ProjectType. * The exception message holds *//*from w w w .jav a2s .co m*/ public static ProjectType getProjectType(final MavenProject project) throws IllegalArgumentException { Validate.notNull(project, "Cannot handle null project argument."); final List<ProjectType> matches = findCandidates(project.getGroupId(), project.getArtifactId(), project.getPackaging(), "Incorrect project type definition for [" + project.getGroupId() + " :: " + project.getArtifactId() + " :: " + project.getVersion() + "]: "); // Validate the internal requirements for the two different pom projects. final ProjectType toReturn = matches.get(0); switch (toReturn) { case PARENT: case ASSEMBLY: // This project should not contain modules. if (project.getModules() != null && !project.getModules().isEmpty()) { throw new IllegalArgumentException( ProjectType.PARENT + " projects may not contain module definitions. " + "(Modules are reserved for reactor projects)."); } break; case REACTOR: // This project not contain dependency definitions. final List<?> dependencies = project.getDependencies(); if (dependencies != null && !dependencies.isEmpty()) { throw new IllegalArgumentException( ProjectType.REACTOR + " projects may not contain dependency definitions." + " (Dependencies should be defined within parent projects)."); } final DependencyManagement dependencyManagement = project.getDependencyManagement(); if (dependencyManagement != null) { // Dig out all dependency management-defined dependencies. final List<Dependency> templateDependencies = dependencyManagement.getDependencies(); if (templateDependencies != null && !templateDependencies.isEmpty()) { throw new IllegalArgumentException( ProjectType.REACTOR + " projects may not contain dependency [management] definitions." + " (Dependencies should be defined within parent projects)."); } } break; // No action should be taken for other project types. default: break; } // All done. return toReturn; }
From source file:se.jguru.nazgul.tools.codestyle.enforcer.rules.RestrictImplDependencies.java
License:Apache License
/** * Delegate method, implemented by concrete subclasses. * * @param project The active MavenProject. * @param helper The EnforcerRuleHelper instance, from which the MavenProject has been retrieved. * @throws RuleFailureException If the enforcer rule was not satisfied. *///from w ww.j a va2 s . co m @SuppressWarnings({ "unchecked" }) @Override protected void performValidation(final MavenProject project, final EnforcerRuleHelper helper) throws RuleFailureException { // Acquire the ProjectType final ProjectType projectType; try { projectType = ProjectType.getProjectType(project); } catch (IllegalArgumentException e) { throw new RuleFailureException("Incorrect project definition for " + project, e); } // Don't evaluate for ignored project types. if (IGNORED_PROJECT_TYPES.contains(projectType)) { return; } // Don't evaluate if told not to. if (matches(project.getGroupId(), dontEvaluateGroupIds)) { // Log somewhat helper.getLog().debug("Ignored [" + project.getGroupId() + ":" + project.getArtifactId() + "] since its groupId was excluded from enforcement."); return; } // Don't evaluate if not told to. if (!matches(project.getGroupId(), evaluateGroupIds)) { // Log somewhat helper.getLog().debug("Ignored [" + project.getGroupId() + ":" + project.getArtifactId() + "] since its groupId was not included in enforcement."); return; } // Acquire all project dependencies. for (final Artifact current : ((Set<Artifact>) project.getDependencyArtifacts())) { // Don't evaluate for test-scope dependencies. if (Artifact.SCOPE_TEST.equalsIgnoreCase(current.getScope())) { continue; } // Should this Artifact be evaluated? final boolean isIncludedInEvaluation = matches(current.getGroupId(), evaluateGroupIds); final boolean isNotExplicitlyExcludedFromEvaluation = !matches(current.getGroupId(), dontEvaluateGroupIds); if (isIncludedInEvaluation && isNotExplicitlyExcludedFromEvaluation) { final ProjectType artifactProjectType = ProjectType.getProjectType(current); final String prefix = "Don't use " + artifactProjectType + " dependencies "; if (artifactProjectType == ProjectType.IMPLEMENTATION) { throw new RuleFailureException(prefix + "outside of application projects.", current); } if (artifactProjectType == ProjectType.TEST) { throw new RuleFailureException(prefix + "in compile scope for non-test artifacts.", current); } if (artifactProjectType == ProjectType.JEE_APPLICATION || artifactProjectType == ProjectType.PROOF_OF_CONCEPT) { throw new RuleFailureException(prefix + "in bundles.", current); } } } }
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 ww w.j a v a 2 s . co 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; }
From source file:sh.isaac.convert.rf2.mojo.VerifyIbdfVersionFormat.java
License:Apache License
@Override public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { try {/* w ww. ja v a 2s . c o m*/ // get the various expressions out of the helper. MavenProject project = (MavenProject) helper.evaluate("${project}"); String artifactId = project.getArtifactId(); String version = project.getVersion(); String sourceDataVersion = project.getProperties().getProperty("sourceData.version"); String sourceDataArtifactId = project.getProperties().getProperty("sourceData.artifactId"); String loaderVersion = project.getProperties().getProperty("loader.version"); if (!artifactId.equals("solor-parent")) { if (artifactId.endsWith(ARTIFACT_SUFFIX)) { if (!sourceDataArtifactId.endsWith(SOURCE_DATA_SUFFIX)) { throw new EnforcerRuleException( "To follow convention, the source data artifact id must end in: " + SOURCE_DATA_SUFFIX + " found: " + sourceDataArtifactId); } if (!version.startsWith(sourceDataVersion)) { throw new EnforcerRuleException( "To follow convention, the version must start with the source data version: " + sourceDataVersion + " found: " + version); } if (!version.contains("-loader-" + loaderVersion)) { throw new EnforcerRuleException( "To follow convention, the version must contain the loader version: " + loaderVersion + " found: " + version); } String constructedVersionStart = sourceDataVersion + "-loader-" + loaderVersion; if (!version.startsWith(constructedVersionStart)) { throw new EnforcerRuleException("To follow convention, the version must start with: " + constructedVersionStart + " found: " + version); } } } } catch (ExpressionEvaluationException e) { throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e); } }
From source file:sorcer.maven.plugin.InitializeMojo.java
License:Apache License
private void configure() throws MojoExecutionException { MavenProject mainProject = isPomProject() ? project : project.getParent(); if (providerName == null) { providerName = mainProject.getArtifactId(); }//from w w w .j ava 2 s .co m api = resolveModule(mainProject, api, "api"); }
From source file:sorcer.maven.plugin.InitializeMojo.java
License:Apache License
private String resolveModule(MavenProject project, String userData, String role) { String name = userData != null ? userData : project.getArtifactId() + "-" + role; if (project.getModules().contains(name)) { return name; }//from ww w.j a v a 2s . c om return null; }
From source file:uk.ac.ox.oucs.plugins.DiscoverMojo.java
License:Apache License
protected void deployAndDependents(Set<Artifact> artifacts) throws MojoExecutionException, MojoFailureException { loadCachedImplentations();//from www .j a v a 2 s . c o m try { toDeploy.addAll(artifacts); do { ArtifactResolutionResult arr = customResolver.resolveTransitively(artifacts, project.getArtifact(), localRepository, remoteRepositories, customMetadataSource, null); Set<Artifact> resolvedArtifacts = arr.getArtifacts(); Set<ResolutionNode> arrRes = arr.getArtifactResolutionNodes(); for (ResolutionNode node : arrRes) { getLog().info(node.getArtifact().getArtifactId()); for (String artifactId : (List<String>) node.getDependencyTrail()) { getLog().info(" +" + artifactId); } } Set<Artifact> artifactsToFind = new HashSet<Artifact>(); for (Artifact artifact : resolvedArtifacts) { if (needsImplementation(artifact)) { getLog().debug("Needed : " + artifact.toString() + " " + artifact.getDependencyTrail()); artifactsToFind.add(artifact); } else { getLog().debug("Ignored : " + artifact.toString() + " " + artifact.getDependencyTrail()); } } artifacts = new HashSet<Artifact>(); for (Artifact artifact : artifactsToFind) { String artifactKey = artifact.getGroupId() + ":" + artifact.getArtifactId(); if (!checkedArtifacts.contains(artifactKey)) { toDeploy.add(artifact); MavenProject project = findImplementation(artifact); if (project != null) { getLog().info("Found implementation: " + artifactKey + " to " + project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion()); Set<Artifact> projectArtifacts = project.createArtifacts(customArtifactFactory, null, null); //artifacts.addAll(projectArtifacts); if (shouldExpand(project)) { toDeploy.addAll(projectArtifacts); } artifacts.add(project.getArtifact()); toDeploy.add(project.getArtifact()); } else { getLog().info("Unresolved implementation: " + artifactKey); } checkedArtifacts.add(artifactKey); } } } while (artifacts.size() > 0); } catch (InvalidDependencyVersionException e1) { throw new MojoExecutionException("Failed to create artifacts", e1); } catch (ArtifactResolutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ArtifactNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { saveCachedImplmentations(); } addToDependencies(); }