Java Code Examples for org.apache.maven.project.MavenProject#equals()

The following examples show how to use org.apache.maven.project.MavenProject#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequirePropertyDiverges.java    From extra-enforcer-rules with Apache License 2.0 6 votes vote down vote up
/**
 * Checks the value of the project against the one given in the defining ancestor project.
 *
 * @param project
 * @param parent
 * @param helper
 * @param propValue
 * @throws EnforcerRuleException
 */
void checkAgainstParentValue( final MavenProject project, final MavenProject parent, EnforcerRuleHelper helper,
        Object propValue ) throws EnforcerRuleException
{
    final StringBuilder parentHierarchy = new StringBuilder( "project." );
    MavenProject needle = project;
    while ( !needle.equals( parent ) )
    {
        parentHierarchy.append( "parent." );
        needle = needle.getParent();
    }
    final String propertyNameInParent = property.replace( "project.", parentHierarchy.toString() );
    Object parentValue = getPropertyValue( helper, propertyNameInParent );
    if ( propValue.equals( parentValue ) )
    {
        final String errorMessage = createResultingErrorMessage( String.format(
                "Property '%s' evaluates to '%s'. This does match '%s' from parent %s",
                property, propValue, parentValue, parent ) );
        throw new EnforcerRuleException( errorMessage );
    }
}
 
Example 2
Source File: AggregatingGraphFactory.java    From depgraph-maven-plugin with Apache License 2.0 6 votes vote down vote up
private void buildModuleTree(MavenProject parentProject, GraphBuilder<DependencyNode> graphBuilder) {
  Collection<MavenProject> collectedProjects = parentProject.getCollectedProjects();
  for (MavenProject collectedProject : collectedProjects) {
    MavenProject child = collectedProject;
    MavenProject parent = collectedProject.getParent();

    while (parent != null) {
      DependencyNode parentNode = filterProject(parent);
      DependencyNode childNode = filterProject(child);

      graphBuilder.addEdge(parentNode, childNode);

      // Stop if we reached the original parent project!
      if (parent.equals(parentProject)) {
        break;
      }

      child = parent;
      parent = parent.getParent();
    }
  }
}
 
Example 3
Source File: RequirePropertyDiverges.java    From extra-enforcer-rules with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the rule.
 *
 * @param helper the helper
 * @throws EnforcerRuleException the enforcer rule exception
 */
public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException
{
    final Log log = helper.getLog();

    Object propValue = getPropertyValue( helper );
    checkPropValueNotBlank( propValue );

    final MavenProject project = getMavenProject( helper );
    log.debug( getRuleName() + ": checking property '" + property + "' for project " + project );

    final MavenProject parent = findDefiningParent( project );

    // fail fast if the defining parent could not be found due to a bug in the rule
    if ( parent == null )
    {
        throw new IllegalStateException( "Failed to find parent POM which defines the current rule" );
    }

    if ( project.equals( parent ) )
    {
        log.debug( getRuleName() + ": skip for property '" + property + "' as " + project + " defines rule." );
    }
    else
    {
        log.debug( "Check configuration defined in " + parent );
        if ( regex == null )
        {
            checkAgainstParentValue( project, parent, helper, propValue );
        }
        else
        {
            checkAgainstRegex( propValue );
        }
    }
}