1 /*
2 * Copyright 2006 David Vicente
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.codehaus.mojo.dashboard.report.plugin;
17
18 import java.io.File;
19
20 import org.apache.maven.artifact.repository.ArtifactRepository;
21 import org.apache.maven.plugin.AbstractMojo;
22 import org.apache.maven.project.MavenProject;
23 import org.apache.maven.project.MavenProjectBuilder;
24 import org.codehaus.mojo.dashboard.report.plugin.hibernate.HibernateService;
25
26 /**
27 * @author <a href="dvicente72@gmail.com">David Vicente</a>
28 *
29 */
30 public abstract class AbstractDashBoardMojo extends AbstractMojo
31 {
32
33 /**
34 * The maven project
35 *
36 * @parameter expression="${project}"
37 * @readonly
38 */
39 protected MavenProject project;
40
41 /**
42 * Directory containing The generated DashBoard report Datafile "dashboard-report.xml".
43 *
44 * @parameter expression="${project.reporting.outputDirectory}"
45 * @required
46 */
47 protected File outputDirectory;
48
49 /**
50 * <p>
51 * The generated DashBoard report Datafile.
52 * </p>
53 *
54 * @parameter expression="dashboard-report.xml"
55 * @readonly
56 */
57 protected String dashboardDataFile;
58
59 /**
60 * The local repository.
61 *
62 * @parameter expression="${localRepository}"
63 * @readonly
64 */
65 protected ArtifactRepository localRepository;
66
67 /**
68 * number of XRef JDepend/Cobertura packages to export in dashboard summary page
69 *
70 * @parameter default-value="10"
71 */
72 protected int nbExportedPackagesSummary;
73
74 /**
75 * Hibernate Service
76 *
77 * @component
78 *
79 */
80 protected HibernateService hibernateService;
81
82 /**
83 * Hibernate dialect
84 *
85 * @parameter expression="${dialect}"
86 * @required
87 */
88 protected String dialect;
89
90 /**
91 * Database driver classname
92 *
93 * @parameter expression="${driverClass}"
94 * @required
95 */
96 protected String driverClass;
97
98 /**
99 * Database URL
100 *
101 * @parameter expression="${connectionUrl}"
102 * @required
103 */
104 protected String connectionUrl;
105
106 /**
107 * Database username
108 *
109 * @parameter expression="${username}"
110 * @required
111 */
112 protected String username;
113
114 /**
115 * Database password
116 *
117 * @parameter expression="${password}"
118 * @required
119 */
120 protected String password;
121
122 /**
123 * Project builder
124 *
125 * @component
126 */
127 protected MavenProjectBuilder mavenProjectBuilder;
128
129 protected boolean isPropHibernateSet = false;
130
131 protected DashBoardUtils dashBoardUtils;
132
133
134 protected void configureHibernateDriver()
135 {
136 hibernateService.setDialect( dialect );
137 hibernateService.setDriverClass( driverClass );
138 hibernateService.setConnectionUrl( connectionUrl );
139 hibernateService.setUsername( username );
140 hibernateService.setPassword( password );
141 }
142
143 protected boolean isDBAvailable(){
144 boolean isDBAvailable = false;
145 if ( ( dialect != null && dialect.length() > 0 ) && ( driverClass != null && driverClass.length() > 0 )
146 && ( connectionUrl != null && connectionUrl.length() > 0 )
147 && ( username != null && username.length() > 0 )
148 && ( password != null && password.length() > 0 ) )
149 {
150 isDBAvailable = true;
151 }
152 return isDBAvailable;
153 }
154 }