1 package org.apache.maven.plugins.help;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.Date;
25 import java.util.Iterator;
26 import java.util.List;
27
28 import org.apache.maven.model.Profile;
29 import org.apache.maven.plugin.MojoExecutionException;
30 import org.apache.maven.project.MavenProject;
31
32
33
34
35
36
37
38
39
40 public class ActiveProfilesMojo
41 extends AbstractHelpMojo
42 {
43
44
45
46
47
48
49
50
51
52
53
54 private List projects;
55
56
57
58
59
60
61 public void execute()
62 throws MojoExecutionException
63 {
64 StringBuffer message = new StringBuffer();
65
66 for ( Iterator it = projects.iterator(); it.hasNext(); )
67 {
68 MavenProject project = (MavenProject) it.next();
69
70 getActiveProfileStatement( project, message );
71
72 message.append( "\n\n" );
73 }
74
75 if ( output != null )
76 {
77 StringBuffer sb = new StringBuffer();
78 sb.append( "Created by: " + getClass().getName() ).append( "\n" );
79 sb.append( "Created on: " + new Date() ).append( "\n" ).append( "\n" );
80 sb.append( message.toString() );
81
82 try
83 {
84 writeFile( output, sb );
85 }
86 catch ( IOException e )
87 {
88 throw new MojoExecutionException( "Cannot write active profiles to output: " + output, e );
89 }
90
91 if ( getLog().isInfoEnabled() )
92 {
93 getLog().info( "Active profile report written to: " + output );
94 }
95 }
96 else
97 {
98 if ( getLog().isInfoEnabled() )
99 {
100 getLog().info( message );
101 }
102 }
103 }
104
105
106
107
108
109
110
111
112
113
114
115 private void getActiveProfileStatement( MavenProject project, StringBuffer message )
116 {
117
118
119 List profiles = new ArrayList( project.getActiveProfiles() );
120
121 message.append( "\n" );
122
123 message.append( "Active Profiles for Project \'" + project.getId() + "\': \n\n" );
124
125 if ( profiles == null || profiles.isEmpty() )
126 {
127 message.append( "There are no active profiles." );
128 }
129 else
130 {
131 message.append( "The following profiles are active:\n" );
132
133 for ( Iterator it = profiles.iterator(); it.hasNext(); )
134 {
135 Profile profile = (Profile) it.next();
136
137 message.append( "\n - " ).append( profile.getId() );
138 message.append( " (source: " ).append( profile.getSource() ).append( ")" );
139 }
140
141 }
142
143 message.append( "\n" );
144 }
145 }