CPD Results
The following document contains the results of PMD's CPD 6.46.0.
Duplications
File |
Line |
org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java |
243 |
org/apache/maven/project/DefaultProjectDependenciesResolver.java |
257 |
public boolean visitEnter( DependencyNode node )
{
StringBuilder buffer = new StringBuilder( 128 );
buffer.append( indent );
org.eclipse.aether.graph.Dependency dep = node.getDependency();
if ( dep != null )
{
org.eclipse.aether.artifact.Artifact art = dep.getArtifact();
buffer.append( art );
if ( StringUtils.isNotEmpty( dep.getScope() ) )
{
buffer.append( ':' ).append( dep.getScope() );
}
if ( dep.isOptional() )
{
buffer.append( " (optional)" );
}
// TODO We currently cannot tell which <dependencyManagement> section contained the management
// information. When the resolver provides this information, these log messages should be updated
// to contain it.
if ( ( node.getManagedBits() & DependencyNode.MANAGED_SCOPE ) == DependencyNode.MANAGED_SCOPE )
{
final String premanagedScope = DependencyManagerUtils.getPremanagedScope( node );
buffer.append( " (scope managed from " );
buffer.append( Objects.toString( premanagedScope, "default" ) );
buffer.append( ')' );
}
if ( ( node.getManagedBits() & DependencyNode.MANAGED_VERSION ) == DependencyNode.MANAGED_VERSION )
{
final String premanagedVersion = DependencyManagerUtils.getPremanagedVersion( node );
buffer.append( " (version managed from " );
buffer.append( Objects.toString( premanagedVersion, "default" ) );
buffer.append( ')' );
}
if ( ( node.getManagedBits() & DependencyNode.MANAGED_OPTIONAL ) == DependencyNode.MANAGED_OPTIONAL )
{
final Boolean premanagedOptional = DependencyManagerUtils.getPremanagedOptional( node );
buffer.append( " (optionality managed from " );
buffer.append( Objects.toString( premanagedOptional, "default" ) );
buffer.append( ')' );
}
if ( ( node.getManagedBits() & DependencyNode.MANAGED_EXCLUSIONS )
== DependencyNode.MANAGED_EXCLUSIONS )
{
final Collection<org.eclipse.aether.graph.Exclusion> premanagedExclusions =
DependencyManagerUtils.getPremanagedExclusions( node );
buffer.append( " (exclusions managed from " );
buffer.append( Objects.toString( premanagedExclusions, "default" ) );
buffer.append( ')' );
}
if ( ( node.getManagedBits() & DependencyNode.MANAGED_PROPERTIES )
== DependencyNode.MANAGED_PROPERTIES )
{
final Map<String, String> premanagedProperties =
DependencyManagerUtils.getPremanagedProperties( node );
buffer.append( " (properties managed from " );
buffer.append( Objects.toString( premanagedProperties, "default" ) );
buffer.append( ')' );
}
} |
File |
Line |
org/apache/maven/plugin/PluginParameterExpressionEvaluator.java |
397 |
org/apache/maven/plugin/PluginParameterExpressionEvaluatorV4.java |
405 |
value = project.getProperties().getProperty( expression );
}
}
if ( value instanceof String )
{
// TODO without #, this could just be an evaluate call...
String val = (String) value;
int exprStartDelimiter = val.indexOf( "${" );
if ( exprStartDelimiter >= 0 )
{
if ( exprStartDelimiter > 0 )
{
value = val.substring( 0, exprStartDelimiter ) + evaluate( val.substring( exprStartDelimiter ) );
}
else
{
value = evaluate( val.substring( exprStartDelimiter ) );
}
}
}
return value;
}
private static boolean isTypeCompatible( Class<?> type, Object value )
{
if ( type.isInstance( value ) )
{
return true;
}
// likely Boolean -> boolean, Short -> int etc. conversions, it's not the problem case we try to avoid
return ( ( type.isPrimitive() || type.getName().startsWith( "java.lang." ) )
&& value.getClass().getName().startsWith( "java.lang." ) );
}
private String stripTokens( String expr )
{
if ( expr.startsWith( "${" ) && ( expr.indexOf( '}' ) == expr.length() - 1 ) )
{
expr = expr.substring( 2, expr.length() - 1 );
}
return expr;
}
@Override
public File alignToBaseDirectory( File file )
{
// TODO Copied from the DefaultInterpolator. We likely want to resurrect the PathTranslator or at least a
// similar component for re-usage
if ( file != null )
{
if ( file.isAbsolute() )
{
// path was already absolute, just normalize file separator and we're done
}
else if ( file.getPath().startsWith( File.separator ) )
{
// drive-relative Windows path, don't align with project directory but with drive root
file = file.getAbsoluteFile();
}
else
{
// an ordinary relative path, align with project directory
file = new File( new File( basedir, file.getPath() ).toURI().normalize() ).getAbsoluteFile(); |
File |
Line |
org/apache/maven/plugin/PluginParameterExpressionEvaluator.java |
125 |
org/apache/maven/plugin/PluginParameterExpressionEvaluatorV4.java |
128 |
basedir = System.getProperty( "user.dir" );
}
this.basedir = basedir;
}
@Override
public Object evaluate( String expr )
throws ExpressionEvaluationException
{
return evaluate( expr, null );
}
@Override
@SuppressWarnings( "checkstyle:methodlength" )
public Object evaluate( String expr, Class<?> type )
throws ExpressionEvaluationException
{
Object value = null;
if ( expr == null )
{
return null;
}
String expression = stripTokens( expr );
if ( expression.equals( expr ) )
{
int index = expr.indexOf( "${" );
if ( index >= 0 )
{
int lastIndex = expr.indexOf( '}', index );
if ( lastIndex >= 0 )
{
String retVal = expr.substring( 0, index );
if ( ( index > 0 ) && ( expr.charAt( index - 1 ) == '$' ) )
{
retVal += expr.substring( index + 1, lastIndex + 1 );
}
else
{
Object subResult = evaluate( expr.substring( index, lastIndex + 1 ) );
if ( subResult != null )
{
retVal += subResult;
}
else
{
retVal += "$" + expr.substring( index + 1, lastIndex + 1 );
}
}
retVal += evaluate( expr.substring( lastIndex + 1 ) );
return retVal;
}
}
// Was not an expression
if ( expression.contains( "$$" ) )
{
return expression.replaceAll( "\\$\\$", "\\$" );
}
else
{
return expression;
}
} |
File |
Line |
org/apache/maven/plugin/PluginParameterExpressionEvaluator.java |
307 |
org/apache/maven/plugin/PluginParameterExpressionEvaluatorV4.java |
315 |
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
if ( pathSeparator > 0 )
{
String pathExpression = expression.substring( 1, pathSeparator );
value = ReflectionValueExtractor.evaluate( pathExpression, pluginDescriptor );
value = value + expression.substring( pathSeparator );
}
else
{
value = ReflectionValueExtractor.evaluate( expression.substring( 1 ), pluginDescriptor );
}
}
catch ( Exception e )
{
throw new ExpressionEvaluationException( "Error evaluating plugin parameter expression: " + expression,
e );
}
}
else if ( "settings".equals( expression ) )
{
value = session.getSettings();
}
else if ( expression.startsWith( "settings" ) )
{
try
{
int pathSeparator = expression.indexOf( '/' );
if ( pathSeparator > 0 )
{
String pathExpression = expression.substring( 1, pathSeparator );
value = ReflectionValueExtractor.evaluate( pathExpression, session.getSettings() );
value = value + expression.substring( pathSeparator );
}
else
{
value = ReflectionValueExtractor.evaluate( expression.substring( 1 ), session.getSettings() );
}
}
catch ( Exception e )
{
// TODO don't catch exception
throw new ExpressionEvaluationException( "Error evaluating plugin parameter expression: " + expression,
e );
}
}
else if ( "basedir".equals( expression ) )
{
value = basedir; |
File |
Line |
org/apache/maven/artifact/factory/DefaultArtifactFactory.java |
133 |
org/apache/maven/bridge/MavenRepositorySystem.java |
532 |
private Artifact createArtifact( String groupId, String artifactId, VersionRange versionRange, String type,
String classifier, String scope, String inheritedScope, boolean optional )
{
String desiredScope = Artifact.SCOPE_RUNTIME;
if ( inheritedScope == null )
{
desiredScope = scope;
}
else if ( Artifact.SCOPE_TEST.equals( scope ) || Artifact.SCOPE_PROVIDED.equals( scope ) )
{
return null;
}
else if ( Artifact.SCOPE_COMPILE.equals( scope ) && Artifact.SCOPE_COMPILE.equals( inheritedScope ) )
{
// added to retain compile artifactScope. Remove if you want compile inherited as runtime
desiredScope = Artifact.SCOPE_COMPILE;
}
if ( Artifact.SCOPE_TEST.equals( inheritedScope ) )
{
desiredScope = Artifact.SCOPE_TEST;
}
if ( Artifact.SCOPE_PROVIDED.equals( inheritedScope ) )
{
desiredScope = Artifact.SCOPE_PROVIDED;
}
if ( Artifact.SCOPE_SYSTEM.equals( scope ) )
{
// system scopes come through unchanged...
desiredScope = Artifact.SCOPE_SYSTEM;
}
ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( type );
return new DefaultArtifact( groupId, artifactId, versionRange, desiredScope, type, classifier, handler,
optional );
} |
File |
Line |
org/apache/maven/plugin/PluginParameterExpressionEvaluator.java |
197 |
org/apache/maven/plugin/PluginParameterExpressionEvaluatorV4.java |
198 |
if ( "localRepository".equals( expression ) )
{
value = session.getLocalRepository();
}
else if ( "session".equals( expression ) )
{
value = session;
}
else if ( expression.startsWith( "session" ) )
{
try
{
int pathSeparator = expression.indexOf( '/' );
if ( pathSeparator > 0 )
{
String pathExpression = expression.substring( 1, pathSeparator );
value = ReflectionValueExtractor.evaluate( pathExpression, session );
value = value + expression.substring( pathSeparator );
}
else
{
value = ReflectionValueExtractor.evaluate( expression.substring( 1 ), session );
}
}
catch ( Exception e )
{
// TODO don't catch exception
throw new ExpressionEvaluationException( "Error evaluating plugin parameter expression: " + expression,
e );
}
}
else if ( "reactorProjects".equals( expression ) )
{
value = session.getProjects();
}
else if ( "project".equals( expression ) )
{
value = project;
}
else if ( "executedProject".equals( expression ) )
{
value = project.getExecutionProject(); |
File |
Line |
org/apache/maven/plugin/prefix/NoPluginFoundForPrefixException.java |
39 |
org/apache/maven/plugin/version/PluginVersionResolutionException.java |
81 |
}
private static String format( LocalRepository localRepository, List<RemoteRepository> remoteRepositories )
{
StringBuilder repos = new StringBuilder( "[" );
if ( localRepository != null )
{
repos.append( localRepository.getId() ).append( " (" ).append( localRepository.getBasedir() ).append( ")" );
}
if ( remoteRepositories != null && !remoteRepositories.isEmpty() )
{
for ( RemoteRepository repository : remoteRepositories )
{
repos.append( ", " );
if ( repository != null )
{
repos.append( repository.getId() ).append( " (" ).append( repository.getUrl() ).append( ")" );
}
}
}
repos.append( "]" );
return repos.toString();
}
} |
File |
Line |
org/apache/maven/plugin/PluginParameterExpressionEvaluator.java |
239 |
org/apache/maven/plugin/PluginParameterExpressionEvaluatorV4.java |
243 |
value = project.getExecutionProject();
}
else if ( expression.startsWith( "project" ) || expression.startsWith( "pom" ) )
{
try
{
int pathSeparator = expression.indexOf( '/' );
if ( pathSeparator > 0 )
{
String pathExpression = expression.substring( 0, pathSeparator );
value = ReflectionValueExtractor.evaluate( pathExpression, project );
value = value + expression.substring( pathSeparator );
}
else
{
value = ReflectionValueExtractor.evaluate( expression.substring( 1 ), project );
}
}
catch ( Exception e )
{
// TODO don't catch exception
throw new ExpressionEvaluationException( "Error evaluating plugin parameter expression: " + expression,
e );
}
}
else if ( expression.equals( "repositorySystemSession" ) )
{ |
File |
Line |
org/apache/maven/plugin/PluginParameterExpressionEvaluator.java |
272 |
org/apache/maven/plugin/PluginParameterExpressionEvaluatorV4.java |
277 |
}
else if ( expression.startsWith( "mojo" ) )
{
try
{
int pathSeparator = expression.indexOf( '/' );
if ( pathSeparator > 0 )
{
String pathExpression = expression.substring( 1, pathSeparator );
value = ReflectionValueExtractor.evaluate( pathExpression, mojoExecution );
value = value + expression.substring( pathSeparator );
}
else
{
value = ReflectionValueExtractor.evaluate( expression.substring( 1 ), mojoExecution );
}
}
catch ( Exception e )
{
// TODO don't catch exception
throw new ExpressionEvaluationException( "Error evaluating plugin parameter expression: " + expression,
e );
}
}
else if ( expression.equals( "plugin" ) )
{
value = mojoDescriptor.getPluginDescriptor(); |
File |
Line |
org/apache/maven/plugin/internal/DefaultPluginManager.java |
103 |
org/apache/maven/plugin/internal/DefaultPluginManager.java |
135 |
{
MavenSession session = legacySupport.getSession();
PluginDescriptor pluginDescriptor;
try
{
pluginDescriptor =
pluginManager.getPluginDescriptor( plugin, session.getCurrentProject().getRemotePluginRepositories(),
session.getRepositorySession() );
pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null );
}
catch ( Exception e )
{
throw new PluginManagerException( plugin, e.getMessage(), e );
}
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try
{
Thread.currentThread().setContextClassLoader( pluginDescriptor.getClassRealm() );
return container.lookup( role, roleHint ); |
File |
Line |
org/apache/maven/project/MavenProject.java |
1629 |
org/apache/maven/project/MavenProject.java |
1705 |
|| Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
{
Dependency dependency = new Dependency();
dependency.setArtifactId( a.getArtifactId() );
dependency.setGroupId( a.getGroupId() );
dependency.setVersion( a.getVersion() );
dependency.setScope( a.getScope() );
dependency.setType( a.getType() );
dependency.setClassifier( a.getClassifier() );
list.add( dependency );
}
}
return Collections.unmodifiableList( list );
}
@Deprecated
public List<Artifact> getTestArtifacts() |
File |
Line |
org/apache/maven/project/MavenProject.java |
1629 |
org/apache/maven/project/MavenProject.java |
1801 |
|| Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
{
Dependency dependency = new Dependency();
dependency.setArtifactId( a.getArtifactId() );
dependency.setGroupId( a.getGroupId() );
dependency.setVersion( a.getVersion() );
dependency.setScope( a.getScope() );
dependency.setType( a.getType() );
dependency.setClassifier( a.getClassifier() );
list.add( dependency );
}
}
return Collections.unmodifiableList( list );
}
@Deprecated
public List<Artifact> getTestArtifacts() |