CPD Results
The following document contains the results of PMD's CPD 7.0.0.
Duplications
File | Line |
---|---|
org/apache/maven/internal/impl/Graph.java | 30 |
org/apache/maven/project/Graph.java | 30 |
class Graph { private enum DfsState { VISITING, VISITED } final Map<String, Vertex> vertices = new LinkedHashMap<>(); public Vertex getVertex(String id) { return vertices.get(id); } public Collection<Vertex> getVertices() { return vertices.values(); } Vertex addVertex(String label) { return vertices.computeIfAbsent(label, Vertex::new); } void addEdge(Vertex from, Vertex to) throws CycleDetectedException { from.children.add(to); to.parents.add(from); List<String> cycle = findCycle(to); if (cycle != null) { // remove edge which introduced cycle removeEdge(from, to); throw new CycleDetectedException( "Edge between '" + from.label + "' and '" + to.label + "' introduces to cycle in the graph", cycle); } } void removeEdge(Vertex from, Vertex to) { from.children.remove(to); to.parents.remove(from); } List<String> visitAll() { return visitAll(vertices.values(), new HashMap<>(), new ArrayList<>()); } List<String> findCycle(Vertex vertex) { return visitCycle(Collections.singleton(vertex), new HashMap<>(), new LinkedList<>()); } private static List<String> visitAll( Collection<Vertex> children, Map<Vertex, DfsState> stateMap, List<String> list) { for (Vertex v : children) { DfsState state = stateMap.putIfAbsent(v, DfsState.VISITING); if (state == null) { visitAll(v.children, stateMap, list); stateMap.put(v, DfsState.VISITED); list.add(v.label); } } return list; } private static List<String> visitCycle( Collection<Vertex> children, Map<Vertex, DfsState> stateMap, LinkedList<String> cycle) { for (Vertex v : children) { DfsState state = stateMap.putIfAbsent(v, DfsState.VISITING); if (state == null) { cycle.addLast(v.label); List<String> ret = visitCycle(v.children, stateMap, cycle); if (ret != null) { return ret; } cycle.removeLast(); stateMap.put(v, DfsState.VISITED); } else if (state == DfsState.VISITING) { // we are already visiting this vertex, this mean we have a cycle int pos = cycle.lastIndexOf(v.label); List<String> ret = cycle.subList(pos, cycle.size()); ret.add(v.label); return ret; } } return null; } static class Vertex { final String label; final List<Vertex> children = new ArrayList<>(); final List<Vertex> parents = new ArrayList<>(); Vertex(String label) { this.label = label; } String getLabel() { return label; } List<Vertex> getChildren() { return children; } List<Vertex> getParents() { return parents; } } |
File | Line |
---|---|
org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java | 276 |
org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutor.java | 809 |
return delegate.calculateLifecycleMappings(session, project, lifecycle, lifecyclePhase); } /** * Post-processes the effective configuration for the specified mojo execution. This step discards all parameters * from the configuration that are not applicable to the mojo and injects the default values for any missing * parameters. * * @param mojoExecution The mojo execution whose configuration should be finalized, must not be {@code null}. */ private void finalizeMojoConfiguration(MojoExecution mojoExecution) { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); XmlNode executionConfiguration = mojoExecution.getConfiguration() != null ? mojoExecution.getConfiguration().getDom() : null; if (executionConfiguration == null) { executionConfiguration = new XmlNodeImpl("configuration"); } XmlNode defaultConfiguration = getMojoConfiguration(mojoDescriptor); List<XmlNode> children = new ArrayList<>(); if (mojoDescriptor.getParameters() != null) { for (Parameter parameter : mojoDescriptor.getParameters()) { XmlNode parameterConfiguration = executionConfiguration.getChild(parameter.getName()); if (parameterConfiguration == null) { parameterConfiguration = executionConfiguration.getChild(parameter.getAlias()); } XmlNode parameterDefaults = defaultConfiguration.getChild(parameter.getName()); if (parameterConfiguration != null) { parameterConfiguration = parameterConfiguration.merge(parameterDefaults, Boolean.TRUE); } else { parameterConfiguration = parameterDefaults; } if (parameterConfiguration != null) { Map<String, String> attributes = new HashMap<>(parameterConfiguration.getAttributes()); String attributeForImplementation = parameterConfiguration.getAttribute("implementation"); String parameterForImplementation = parameter.getImplementation(); if ((attributeForImplementation == null || attributeForImplementation.isEmpty()) && ((parameterForImplementation != null) && !parameterForImplementation.isEmpty())) { attributes.put("implementation", parameter.getImplementation()); } parameterConfiguration = new XmlNodeImpl( parameter.getName(), parameterConfiguration.getValue(), attributes, parameterConfiguration.getChildren(), parameterConfiguration.getInputLocation()); children.add(parameterConfiguration); } } } XmlNode finalConfiguration = new XmlNodeImpl("configuration", null, null, children, null); mojoExecution.setConfiguration(finalConfiguration); } private XmlNode getMojoConfiguration(MojoDescriptor mojoDescriptor) { if (mojoDescriptor.isV4Api()) { return MojoDescriptorCreator.convert(mojoDescriptor.getMojoDescriptorV4()); } else { return MojoDescriptorCreator.convert(mojoDescriptor).getDom(); } } |
File | Line |
---|---|
org/apache/maven/plugin/PluginParameterExpressionEvaluator.java | 308 |
org/apache/maven/plugin/PluginParameterExpressionEvaluatorV4.java | 188 |
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 | 117 |
org/apache/maven/plugin/PluginParameterExpressionEvaluatorV4.java | 87 |
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 return expression.replace("$$", "$"); } |
File | Line |
---|---|
org/apache/maven/artifact/factory/DefaultArtifactFactory.java | 149 |
org/apache/maven/bridge/MavenRepositorySystem.java | 486 |
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/lifecycle/internal/DefaultLifecycleTaskSegmentCalculator.java | 92 |
org/apache/maven/lifecycle/internal/concurrent/ConcurrentLifecycleStarter.java | 135 |
PluginVersionResolutionException { List<TaskSegment> taskSegments = new ArrayList<>(tasks.size()); TaskSegment currentSegment = null; for (String task : tasks) { if (isGoalSpecification(task)) { // "pluginPrefix[:version]:goal" or "groupId:artifactId[:version]:goal" lifecyclePluginResolver.resolveMissingPluginVersions(session.getTopLevelProject(), session); MojoDescriptor mojoDescriptor = mojoDescriptorCreator.getMojoDescriptor(task, session, session.getTopLevelProject()); boolean aggregating = mojoDescriptor.isAggregator() || !mojoDescriptor.isProjectRequired(); if (currentSegment == null || currentSegment.isAggregating() != aggregating) { currentSegment = new TaskSegment(aggregating); taskSegments.add(currentSegment); } currentSegment.getTasks().add(new GoalTask(task)); } else { // lifecycle phase if (currentSegment == null || currentSegment.isAggregating()) { currentSegment = new TaskSegment(false); taskSegments.add(currentSegment); } currentSegment.getTasks().add(new LifecycleTask(task)); } } return taskSegments; } |
File | Line |
---|---|
org/apache/maven/plugin/prefix/NoPluginFoundForPrefixException.java | 38 |
org/apache/maven/plugin/version/PluginVersionResolutionException.java | 76 |
} 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/execution/scope/internal/MojoExecutionScope.java | 43 |
org/apache/maven/session/scope/internal/SessionScope.java | 37 |
public <T> Provider<T> scope(final Key<T> key, Provider<T> unscoped) { Object qualifier = key.getAnnotation() instanceof Named n ? n.value() : key.getAnnotation(); org.apache.maven.di.Key<T> k = org.apache.maven.di.Key.ofType(key.getTypeLiteral().getType(), qualifier); return scope(k, unscoped::get)::get; } public static <T> Provider<T> seededKeyProvider(Class<? extends T> clazz) { return MojoExecutionScope.<T>seededKeySupplier(clazz)::get; |
File | Line |
---|---|
org/apache/maven/lifecycle/internal/DefaultLifecycleTaskSegmentCalculator.java | 71 |
org/apache/maven/lifecycle/internal/concurrent/ConcurrentLifecycleStarter.java | 118 |
PluginVersionResolutionException, LifecyclePhaseNotFoundException, LifecycleNotFoundException { MavenProject rootProject = session.getTopLevelProject(); List<String> tasks = requireNonNull(session.getGoals()); // session never returns null, but empty list if (tasks.isEmpty() && (rootProject.getDefaultGoal() != null && !rootProject.getDefaultGoal().isEmpty())) { tasks = Stream.of(rootProject.getDefaultGoal().split("\\s+")) .filter(g -> !g.isEmpty()) .collect(Collectors.toList()); } return calculateTaskSegments(session, tasks); } |
File | Line |
---|---|
org/apache/maven/project/DefaultProjectBuilder.java | 679 |
org/apache/maven/project/DefaultProjectBuilder.java | 703 |
.getRepository(); if (r.getId() != null && !r.getId().isEmpty() && r.getUrl() != null && !r.getUrl().isEmpty()) { ArtifactRepository repo = MavenRepositorySystem.buildArtifactRepository( new org.apache.maven.model.DeploymentRepository(r)); repositorySystem.injectProxy(request.getRepositorySession(), List.of(repo)); repositorySystem.injectAuthentication(request.getRepositorySession(), List.of(repo)); project.setReleaseArtifactRepository(repo); |