1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.codehaus.mojo.ounce.core;
28
29 import java.io.File;
30 import java.io.FileInputStream;
31 import java.io.FileWriter;
32 import java.io.IOException;
33 import java.io.ObjectOutputStream;
34 import java.util.Arrays;
35 import java.util.Collections;
36 import java.util.List;
37 import java.util.Map;
38
39 import org.apache.maven.plugin.logging.Log;
40 import org.codehaus.mojo.ounce.ProjectOnlyMojo;
41 import org.codehaus.plexus.util.StringUtils;
42
43 import com.thoughtworks.xstream.XStream;
44
45
46
47
48
49
50 public class OunceCoreXml
51 implements OunceCore
52 {
53
54
55
56
57
58
59
60 public void createApplication( String baseDir, String theName, String theApplicationRoot, List theProjects,
61 Map ounceOptions, Log log )
62 throws OunceCoreException
63 {
64
65
66 Collections.sort( theProjects );
67 log.info( "Writing parameters to xml." );
68 OunceCoreApplication bean = new OunceCoreApplication( theName, theApplicationRoot, theProjects, ounceOptions );
69 XStream xs = new XStream();
70
71 xs.alias( "application", OunceCoreApplication.class );
72 xs.alias( "project", OunceProjectBean.class );
73 try
74 {
75 File outFile = new File( baseDir + File.separator + "target", "application.xml" );
76 outFile.getParentFile().mkdirs();
77 outFile.createNewFile();
78 ObjectOutputStream out = xs.createObjectOutputStream( new FileWriter( outFile ) );
79 out.writeObject( bean );
80 out.close();
81 }
82 catch ( IOException e )
83 {
84
85 e.printStackTrace();
86 }
87 }
88
89
90
91
92
93
94
95 public void createProject( String baseDir, String theName, String theProjectRoot, List theSourceRoots,
96 String theWebRoot, String theClassPath, String theJdkName, String theCompilerOptions,
97 String packaging, Map ounceOptions,
98 boolean analyzeStrutsFramework, boolean importStrutsValidation, Log log )
99 throws OunceCoreException
100 {
101 if ( StringUtils.isNotEmpty( theClassPath ) )
102 {
103
104
105
106
107
108 String[] classp = theClassPath.split( ";" );
109 Arrays.sort( classp );
110
111 StringBuffer sb = new StringBuffer();
112 if ( classp.length > 0 )
113 {
114
115 sb.append( classp[0] );
116
117
118
119 for ( int i = 1; i < classp.length; i++ )
120 {
121 sb.append( ProjectOnlyMojo.PATH_SEPARATOR );
122 sb.append( classp[i] );
123 }
124 theClassPath = sb.toString();
125 }
126 }
127
128 log.info( "Writing parameters to xml." );
129 OunceCoreProject bean =
130 new OunceCoreProject( theName, theProjectRoot, theSourceRoots, theWebRoot, theClassPath, theJdkName,
131 packaging, theCompilerOptions, ounceOptions );
132 XStream xs = new XStream();
133 xs.alias( "project", OunceCoreProject.class );
134 try
135 {
136 File outFile = new File( baseDir + File.separator + "target", "project.xml" );
137 outFile.getParentFile().mkdirs();
138 outFile.createNewFile();
139 ObjectOutputStream out = xs.createObjectOutputStream( new FileWriter( outFile ) );
140 out.writeObject( bean );
141 out.close();
142 }
143 catch ( IOException e )
144 {
145
146 e.printStackTrace();
147 }
148 }
149
150
151
152
153
154
155 public OunceCoreApplication readApplication( String thePath, Log log )
156 throws OunceCoreException
157 {
158 XStream xs = new XStream();
159 xs.alias( "application", OunceCoreApplication.class );
160 xs.alias( "project", OunceProjectBean.class );
161
162 File inFile = new File( thePath + File.separator + "target", "application.xml" );
163 try
164 {
165 FileInputStream is = new FileInputStream( inFile );
166 OunceCoreApplication app = (OunceCoreApplication) xs.fromXML( is );
167 is.close();
168 return app;
169 }
170 catch ( IOException e )
171 {
172 throw new OunceCoreException( "Unable to read file:" + inFile.getPath(), e );
173 }
174 }
175
176
177
178
179
180
181 public OunceCoreProject readProject( String thePath, Log log )
182 throws OunceCoreException
183 {
184 XStream xs = new XStream();
185 xs.alias( "project", OunceCoreProject.class );
186
187 File inFile = new File( thePath + File.separator + "target", "project.xml" );
188 try
189 {
190 FileInputStream is = new FileInputStream( inFile );
191 OunceCoreProject project = (OunceCoreProject) xs.fromXML( is );
192 is.close();
193 return project;
194 }
195 catch ( IOException e )
196 {
197 throw new OunceCoreException( "Unable to read file:" + inFile.getPath(), e );
198 }
199 }
200
201
202
203
204
205
206
207
208 public void scan( String theApplicationFile, String theAssessmentName, String theAssessmentOutput,
209 String theCaller, String theReportType, String theReportOutputType,
210 String theReportOutputLocation, boolean thePublish, Map theOunceOptions, String installDir,
211 boolean wait, Log theLog )
212 throws OunceCoreException
213 {
214
215 OunceCoreScan bean =
216 new OunceCoreScan( theApplicationFile, theAssessmentName, theAssessmentOutput, theCaller, theReportType,
217 theReportOutputType, theReportOutputLocation, thePublish, theOunceOptions );
218
219 {
220 XStream xs = new XStream();
221 xs.alias( "scan", OunceCoreScan.class );
222 try
223 {
224 File outFile = new File( "./target", "scan.xml" );
225 outFile.getParentFile().mkdirs();
226 outFile.createNewFile();
227 ObjectOutputStream out = xs.createObjectOutputStream( new FileWriter( outFile ) );
228 out.writeObject( bean );
229 out.close();
230 }
231 catch ( IOException e )
232 {
233
234 e.printStackTrace();
235 }
236 }
237 }
238
239 public void createPathVariables( Map pathVariableMap, String installDir, Log log )
240 throws OunceCoreException
241 {
242
243
244 }
245 }