Skip to content

Commit cf997f7

Browse files
authored
[MDEP-839] Avoid extra blank lines in file (#495)
* Avoid control characters in file
1 parent dc591cd commit cf997f7

File tree

5 files changed

+128
-3
lines changed

5 files changed

+128
-3
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:list
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
21+
<project xmlns="http://maven.apache.org/POM/4.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
26+
<groupId>org.apache.maven.its.dependency</groupId>
27+
<artifactId>test</artifactId>
28+
<version>1.0-SNAPSHOT</version>
29+
30+
<name>Test</name>
31+
<description>
32+
Test dependency:list-repositories
33+
</description>
34+
35+
<properties>
36+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
37+
</properties>
38+
39+
<repositories>
40+
<repository>
41+
<id>fake-remote-repository</id>
42+
<url>http://localhost:2345</url>
43+
</repository>
44+
</repositories>
45+
46+
<dependencies>
47+
<dependency>
48+
<groupId>org.apache.maven</groupId>
49+
<artifactId>maven-core</artifactId>
50+
<version>3.9.9</version>
51+
</dependency>
52+
</dependencies>
53+
54+
</project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
outputFile = classpath.txt
19+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
20+
File file = new File( basedir, "classpath.txt" )
21+
assert file.exists() : "output file $file does not exist"
22+
23+
String output = file.getText( "UTF-8" )
24+
assert output.startsWith( 'The following files have been resolved:')
25+
// no escape codes
26+
assert !output.contains( '\u001B' )
27+
28+

src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ protected ArtifactsFilter getMarkedArtifactFilter() {
175175
*/
176176
public String getOutput(boolean outputAbsoluteArtifactFilename, boolean theOutputScope, boolean theSort) {
177177
StringBuilder sb = new StringBuilder();
178-
sb.append(System.lineSeparator());
178+
if (outputFile == null) {
179+
sb.append(System.lineSeparator());
180+
}
179181
sb.append("The following files have been resolved:");
180182
sb.append(System.lineSeparator());
181183
if (results.getResolvedDependencies() == null
@@ -215,9 +217,13 @@ private StringBuilder buildArtifactListOutput(
215217
Set<Artifact> artifacts, boolean outputAbsoluteArtifactFilename, boolean theOutputScope, boolean theSort) {
216218
StringBuilder sb = new StringBuilder();
217219
List<String> artifactStringList = new ArrayList<>();
220+
/* if (outputFile != null) {
221+
MessageUtils.setColorEnabled(false);
222+
} else {
223+
MessageUtils.setColorEnabled(true);
224+
} */
218225
for (Artifact artifact : artifacts) {
219226
MessageBuilder messageBuilder = MessageUtils.buffer();
220-
221227
messageBuilder.a(" ");
222228

223229
if (theOutputScope) {
@@ -257,7 +263,7 @@ private StringBuilder buildArtifactListOutput(
257263
}
258264
}
259265
}
260-
artifactStringList.add(messageBuilder + System.lineSeparator());
266+
artifactStringList.add(messageBuilder.build() + System.lineSeparator());
261267
}
262268
if (theSort) {
263269
Collections.sort(artifactStringList);

0 commit comments

Comments
 (0)