Skip to content

Commit fc969c2

Browse files
authored
[1.9.x][MRESOLVER-483] Fix path concatenation logic (#420)
As iterator may have more, but no file check is done --- https://issues.apache.org/jira/browse/MRESOLVER-483
1 parent a3e620d commit fc969c2

File tree

4 files changed

+91
-41
lines changed

4 files changed

+91
-41
lines changed

maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/visitor/AbstractDepthFirstNodeListGenerator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ public String getClassPath() {
135135
if (node.getDependency() != null) {
136136
Artifact artifact = node.getDependency().getArtifact();
137137
if (artifact.getFile() != null) {
138-
buffer.append(artifact.getFile().getAbsolutePath());
139-
if (it.hasNext()) {
138+
if (buffer.length() != 0) {
140139
buffer.append(File.pathSeparatorChar);
141140
}
141+
buffer.append(artifact.getFile().getAbsolutePath());
142142
}
143143
}
144144
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.eclipse.aether.util.graph.visitor;
20+
21+
import java.io.File;
22+
import java.util.List;
23+
24+
import org.eclipse.aether.graph.DependencyNode;
25+
import org.eclipse.aether.graph.DependencyVisitor;
26+
import org.eclipse.aether.internal.test.util.DependencyGraphParser;
27+
import org.junit.Test;
28+
29+
import static org.junit.Assert.assertEquals;
30+
import static org.junit.Assert.assertTrue;
31+
32+
public abstract class AbstractDepthFirstNodeListGeneratorTestSupport {
33+
34+
protected DependencyNode parse(String resource) throws Exception {
35+
return new DependencyGraphParser("visitor/ordered-list/").parseResource(resource);
36+
}
37+
38+
protected void assertSequence(List<DependencyNode> actual, String... expected) {
39+
assertEquals(actual.toString(), expected.length, actual.size());
40+
for (int i = 0; i < expected.length; i++) {
41+
DependencyNode node = actual.get(i);
42+
assertEquals(
43+
actual.toString(),
44+
expected[i],
45+
node.getDependency().getArtifact().getArtifactId());
46+
}
47+
}
48+
49+
@Test
50+
public void testClasspath() throws Exception {
51+
DependencyNode root = parse("simple.txt");
52+
53+
PreorderNodeListGenerator visitor = new PreorderNodeListGenerator();
54+
root.accept(visitor);
55+
56+
assertEquals(visitor.getClassPath(), "");
57+
}
58+
59+
@Test
60+
public void testFullyResolverClasspath() throws Exception {
61+
DependencyNode root = parse("simple.txt");
62+
63+
DependencyVisitor fileSetter = new DependencyVisitor() {
64+
@Override
65+
public boolean visitEnter(DependencyNode node) {
66+
node.setArtifact(
67+
node.getArtifact().setFile(new File(node.getArtifact().getArtifactId())));
68+
return true;
69+
}
70+
71+
@Override
72+
public boolean visitLeave(DependencyNode node) {
73+
return true;
74+
}
75+
};
76+
root.accept(fileSetter);
77+
78+
PreorderNodeListGenerator visitor = new PreorderNodeListGenerator();
79+
root.accept(visitor);
80+
81+
String classpath = visitor.getClassPath();
82+
assertEquals(5, classpath.split(File.pathSeparator).length);
83+
for (File file : visitor.getFiles()) {
84+
assertTrue("missing: " + file, classpath.contains(file.getAbsolutePath()));
85+
}
86+
}
87+
}

maven-resolver-util/src/test/java/org/eclipse/aether/util/graph/visitor/PostorderNodeListGeneratorTest.java

+1-19
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,12 @@
1818
*/
1919
package org.eclipse.aether.util.graph.visitor;
2020

21-
import java.util.List;
22-
2321
import org.eclipse.aether.graph.DependencyNode;
24-
import org.eclipse.aether.internal.test.util.DependencyGraphParser;
2522
import org.junit.Test;
2623

2724
import static org.junit.Assert.*;
2825

29-
public class PostorderNodeListGeneratorTest {
30-
31-
private DependencyNode parse(String resource) throws Exception {
32-
return new DependencyGraphParser("visitor/ordered-list/").parseResource(resource);
33-
}
34-
35-
private void assertSequence(List<DependencyNode> actual, String... expected) {
36-
assertEquals(actual.toString(), expected.length, actual.size());
37-
for (int i = 0; i < expected.length; i++) {
38-
DependencyNode node = actual.get(i);
39-
assertEquals(
40-
actual.toString(),
41-
expected[i],
42-
node.getDependency().getArtifact().getArtifactId());
43-
}
44-
}
26+
public class PostorderNodeListGeneratorTest extends AbstractDepthFirstNodeListGeneratorTestSupport {
4527

4628
@Test
4729
public void testOrdering() throws Exception {

maven-resolver-util/src/test/java/org/eclipse/aether/util/graph/visitor/PreorderNodeListGeneratorTest.java

+1-20
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,12 @@
1818
*/
1919
package org.eclipse.aether.util.graph.visitor;
2020

21-
import java.util.List;
22-
2321
import org.eclipse.aether.graph.DependencyNode;
24-
import org.eclipse.aether.internal.test.util.DependencyGraphParser;
2522
import org.junit.Test;
2623

2724
import static org.junit.Assert.*;
2825

29-
public class PreorderNodeListGeneratorTest {
30-
31-
private DependencyNode parse(String resource) throws Exception {
32-
return new DependencyGraphParser("visitor/ordered-list/").parseResource(resource);
33-
}
34-
35-
private void assertSequence(List<DependencyNode> actual, String... expected) {
36-
assertEquals(actual.toString(), expected.length, actual.size());
37-
for (int i = 0; i < expected.length; i++) {
38-
DependencyNode node = actual.get(i);
39-
assertEquals(
40-
actual.toString(),
41-
expected[i],
42-
node.getDependency().getArtifact().getArtifactId());
43-
}
44-
}
45-
26+
public class PreorderNodeListGeneratorTest extends AbstractDepthFirstNodeListGeneratorTestSupport {
4627
@Test
4728
public void testOrdering() throws Exception {
4829
DependencyNode root = parse("simple.txt");

0 commit comments

Comments
 (0)