1 package org.apache.maven.model.building;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23
24 import org.apache.maven.model.Model;
25
26
27
28
29
30
31 public class ModelProblemUtils
32 {
33
34
35
36
37
38
39
40 static String toSourceHint( Model model )
41 {
42 if ( model == null )
43 {
44 return "";
45 }
46
47 StringBuilder buffer = new StringBuilder( 192 );
48
49 buffer.append( toId( model ) );
50
51 File pomFile = model.getPomFile();
52 if ( pomFile != null )
53 {
54 buffer.append( " (" ).append( pomFile ).append( ")" );
55 }
56
57 return buffer.toString();
58 }
59
60 static String toPath( Model model )
61 {
62 String path = "";
63
64 if ( model != null )
65 {
66 File pomFile = model.getPomFile();
67
68 if ( pomFile != null )
69 {
70 path = pomFile.getAbsolutePath();
71 }
72 }
73
74 return path;
75 }
76
77 static String toId( Model model )
78 {
79 if ( model == null )
80 {
81 return "";
82 }
83
84 String groupId = model.getGroupId();
85 if ( groupId == null && model.getParent() != null )
86 {
87 groupId = model.getParent().getGroupId();
88 }
89
90 String artifactId = model.getArtifactId();
91
92 String version = model.getVersion();
93 if ( version == null && model.getParent() != null )
94 {
95 version = model.getParent().getVersion();
96 }
97
98 return toId( groupId, artifactId, version );
99 }
100
101
102
103
104
105
106
107
108
109 static String toId( String groupId, String artifactId, String version )
110 {
111 StringBuilder buffer = new StringBuilder( 96 );
112
113 buffer.append( ( groupId != null && groupId.length() > 0 ) ? groupId : "[unknown-group-id]" );
114 buffer.append( ':' );
115 buffer.append( ( artifactId != null && artifactId.length() > 0 ) ? artifactId : "[unknown-artifact-id]" );
116 buffer.append( ':' );
117 buffer.append( ( version != null && version.length() > 0 ) ? version : "[unknown-version]" );
118
119 return buffer.toString();
120 }
121
122
123
124
125
126
127
128
129
130
131
132 public static String formatLocation( ModelProblem problem, String projectId )
133 {
134 StringBuilder buffer = new StringBuilder( 256 );
135
136 if ( !problem.getModelId().equals( projectId ) )
137 {
138 buffer.append( problem.getModelId() );
139
140 if ( problem.getSource().length() > 0 )
141 {
142 if ( buffer.length() > 0 )
143 {
144 buffer.append( ", " );
145 }
146 buffer.append( problem.getSource() );
147 }
148 }
149
150 if ( problem.getLineNumber() > 0 )
151 {
152 if ( buffer.length() > 0 )
153 {
154 buffer.append( ", " );
155 }
156 buffer.append( "line " ).append( problem.getLineNumber() );
157 }
158
159 if ( problem.getColumnNumber() > 0 )
160 {
161 if ( buffer.length() > 0 )
162 {
163 buffer.append( ", " );
164 }
165 buffer.append( "column " ).append( problem.getColumnNumber() );
166 }
167
168 return buffer.toString();
169 }
170
171 }