Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 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 | */ |
Stuart McCulloch | c792b37 | 2008-02-17 16:12:24 +0000 | [diff] [blame] | 19 | package org.apache.felix.obrplugin; |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 20 | |
| 21 | |
| 22 | import java.io.File; |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 23 | import java.io.FileInputStream; |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 24 | import java.io.FileOutputStream; |
| 25 | import java.io.IOException; |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 26 | import java.io.InputStream; |
| 27 | import java.io.OutputStreamWriter; |
| 28 | import java.io.Writer; |
Stuart McCulloch | cfbac7a | 2011-10-16 19:56:22 +0000 | [diff] [blame] | 29 | import java.lang.reflect.Method; |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 30 | import java.net.URI; |
Stuart McCulloch | f843780 | 2011-10-16 19:20:39 +0000 | [diff] [blame] | 31 | import java.util.regex.Pattern; |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 32 | |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 33 | import org.apache.felix.bundlerepository.Resource; |
| 34 | import org.apache.felix.bundlerepository.impl.DataModelHelperImpl; |
| 35 | import org.apache.felix.bundlerepository.impl.PullParser; |
| 36 | import org.apache.felix.bundlerepository.impl.RepositoryImpl; |
| 37 | import org.apache.felix.bundlerepository.impl.RepositoryParser; |
| 38 | import org.apache.felix.bundlerepository.impl.ResourceImpl; |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 39 | import org.apache.maven.plugin.MojoExecutionException; |
| 40 | import org.apache.maven.plugin.logging.Log; |
| 41 | import org.apache.maven.project.MavenProject; |
Stuart McCulloch | 8812902 | 2009-09-03 02:52:58 +0000 | [diff] [blame] | 42 | import org.codehaus.plexus.util.FileUtils; |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 43 | import org.kxml2.io.KXmlParser; |
| 44 | import org.xmlpull.v1.XmlPullParser; |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 45 | |
| 46 | |
| 47 | /** |
| 48 | * this class parse the old repository.xml file build the bundle resource description and update the repository. |
| 49 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 50 | */ |
| 51 | public class ObrUpdate |
| 52 | { |
Stuart McCulloch | cfbac7a | 2011-10-16 19:56:22 +0000 | [diff] [blame] | 53 | private static Pattern TIMESTAMP = Pattern.compile( "-[0-9]{8}\\.[0-9]{6}-[0-9]+" ); |
| 54 | |
| 55 | private static Method setURI; |
| 56 | |
| 57 | static |
| 58 | { |
| 59 | try |
| 60 | { |
| 61 | setURI = RepositoryImpl.class.getDeclaredMethod( "setURI", String.class ); |
| 62 | setURI.setAccessible( true ); |
| 63 | } |
| 64 | catch ( Exception e ) |
| 65 | { |
| 66 | setURI = null; |
| 67 | } |
| 68 | } |
Stuart McCulloch | f843780 | 2011-10-16 19:20:39 +0000 | [diff] [blame] | 69 | |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 70 | /** |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 71 | * logger for this plugin. |
| 72 | */ |
| 73 | private Log m_logger; |
| 74 | |
| 75 | /** |
| 76 | * name and path to the repository descriptor file. |
| 77 | */ |
| 78 | private URI m_repositoryXml; |
| 79 | |
| 80 | /** |
| 81 | * name and path to the obr.xml file. |
| 82 | */ |
| 83 | private URI m_obrXml; |
| 84 | |
| 85 | /** |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 86 | * maven project description. |
| 87 | */ |
| 88 | private MavenProject m_project; |
| 89 | |
| 90 | /** |
| 91 | * user configuration information. |
| 92 | */ |
| 93 | private Config m_userConfig; |
| 94 | |
| 95 | /** |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 96 | * root on parent document. |
| 97 | */ |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 98 | private RepositoryImpl m_repository; |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 99 | |
| 100 | /** |
| 101 | * used to store bundle information. |
| 102 | */ |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 103 | private ResourceImpl m_resourceBundle; |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * base URI used to relativize bundle URIs. |
| 107 | */ |
| 108 | private URI m_baseURI; |
| 109 | |
| 110 | |
| 111 | /** |
| 112 | * initialize information. |
| 113 | * @param repositoryXml path to the repository descriptor file |
| 114 | * @param obrXml path and filename to the obr.xml file |
| 115 | * @param project maven project description |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 116 | * @param mavenRepositoryPath path to the local maven repository |
| 117 | * @param userConfig user information |
| 118 | * @param logger plugin logger |
| 119 | */ |
Stuart McCulloch | 0ae86ab | 2008-02-19 06:24:30 +0000 | [diff] [blame] | 120 | public ObrUpdate( URI repositoryXml, URI obrXml, MavenProject project, String mavenRepositoryPath, |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 121 | Config userConfig, Log logger ) |
| 122 | { |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 123 | m_repositoryXml = repositoryXml; |
| 124 | m_obrXml = obrXml; |
| 125 | m_project = project; |
| 126 | m_logger = logger; |
| 127 | |
| 128 | m_userConfig = userConfig; |
| 129 | |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 130 | if ( userConfig.isRemoteFile() ) |
| 131 | { |
| 132 | m_baseURI = ObrUtils.toFileURI( mavenRepositoryPath ); |
| 133 | } |
| 134 | else |
| 135 | { |
| 136 | m_baseURI = m_repositoryXml; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | |
| 141 | /** |
Stuart McCulloch | 0ae86ab | 2008-02-19 06:24:30 +0000 | [diff] [blame] | 142 | * update the repository descriptor file. parse the old repository descriptor file, |
| 143 | * get the old reference of the bundle or determine the id for a new bundle, extract |
| 144 | * information from bindex set the new information in descriptor file and save it. |
| 145 | * |
| 146 | * @param bundleJar path to the bundle jar file |
| 147 | * @param sourceJar path to the source jar file |
Stuart McCulloch | a1d3a29 | 2008-02-20 00:53:52 +0000 | [diff] [blame] | 148 | * @param docJar path to the docs jar file |
Stuart McCulloch | 0ae86ab | 2008-02-19 06:24:30 +0000 | [diff] [blame] | 149 | * |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 150 | * @throws MojoExecutionException if the plugin failed |
| 151 | */ |
Stuart McCulloch | a1d3a29 | 2008-02-20 00:53:52 +0000 | [diff] [blame] | 152 | public void updateRepository( URI bundleJar, URI sourceJar, URI docJar ) throws MojoExecutionException |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 153 | { |
| 154 | m_logger.debug( " (f) repositoryXml = " + m_repositoryXml ); |
Stuart McCulloch | 0ae86ab | 2008-02-19 06:24:30 +0000 | [diff] [blame] | 155 | m_logger.debug( " (f) bundleJar = " + bundleJar ); |
| 156 | m_logger.debug( " (f) sourceJar = " + sourceJar ); |
Stuart McCulloch | f843780 | 2011-10-16 19:20:39 +0000 | [diff] [blame] | 157 | m_logger.debug( " (f) docJar = " + docJar ); |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 158 | m_logger.debug( " (f) obrXml = " + m_obrXml ); |
| 159 | |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 160 | if ( m_repository == null ) |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 161 | { |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | // get the file size |
Stuart McCulloch | 0ae86ab | 2008-02-19 06:24:30 +0000 | [diff] [blame] | 166 | File bundleFile = new File( bundleJar ); |
Stuart McCulloch | f843780 | 2011-10-16 19:20:39 +0000 | [diff] [blame] | 167 | if ( !bundleFile.exists() ) |
| 168 | { |
| 169 | String snapshot = TIMESTAMP.matcher( bundleFile.getName() ).replaceFirst( "-SNAPSHOT" ); |
| 170 | bundleFile = new File( bundleFile.getParentFile(), snapshot ); |
| 171 | } |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 172 | if ( bundleFile.exists() ) |
| 173 | { |
| 174 | URI resourceURI = m_userConfig.getRemoteBundle(); |
| 175 | if ( null == resourceURI ) |
| 176 | { |
Stuart McCulloch | 0ae86ab | 2008-02-19 06:24:30 +0000 | [diff] [blame] | 177 | resourceURI = bundleJar; |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 178 | if ( m_userConfig.isPathRelative() ) |
| 179 | { |
| 180 | resourceURI = ObrUtils.getRelativeURI( m_baseURI, resourceURI ); |
| 181 | } |
| 182 | } |
| 183 | |
Stuart McCulloch | 7b6f591 | 2008-02-18 17:30:36 +0000 | [diff] [blame] | 184 | if ( m_userConfig.isRemoteFile() ) |
| 185 | { |
| 186 | m_logger.info( "Deploying " + resourceURI ); |
| 187 | } |
| 188 | else |
| 189 | { |
| 190 | m_logger.info( "Installing " + resourceURI ); |
| 191 | } |
| 192 | |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 193 | try |
| 194 | { |
Stuart McCulloch | 0eb9999 | 2011-10-23 20:16:48 +0000 | [diff] [blame] | 195 | m_resourceBundle = ( ResourceImpl ) new DataModelHelperImpl().createResource( bundleFile.toURI().toURL() ); |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 196 | if ( m_resourceBundle == null ) |
Guillaume Nodet | 127d557 | 2010-03-19 18:24:02 +0000 | [diff] [blame] | 197 | { |
| 198 | return; |
| 199 | } |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 200 | } |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 201 | catch ( IOException e ) |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 202 | { |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 203 | throw new MojoExecutionException( "Unable to load resource information", e ); |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | m_resourceBundle.put( Resource.SIZE, String.valueOf( bundleFile.length() ) ); |
| 207 | m_resourceBundle.put( Resource.URI, resourceURI.toASCIIString() ); |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 208 | } |
| 209 | else |
| 210 | { |
Stuart McCulloch | 0ae86ab | 2008-02-19 06:24:30 +0000 | [diff] [blame] | 211 | m_logger.error( "file doesn't exist: " + bundleJar ); |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 212 | return; |
| 213 | } |
| 214 | |
| 215 | // parse the obr.xml file |
| 216 | if ( m_obrXml != null ) |
| 217 | { |
| 218 | m_logger.info( "Adding " + m_obrXml ); |
| 219 | |
| 220 | // URL url = getClass().getResource("/SchemaObr.xsd"); |
| 221 | // TODO validate obr.xml file |
| 222 | |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 223 | // add contents to resource bundle |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 224 | parseObrXml(); |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Stuart McCulloch | a1d3a29 | 2008-02-20 00:53:52 +0000 | [diff] [blame] | 227 | String sourcePath = relativisePath( sourceJar ); |
| 228 | String docPath = relativisePath( docJar ); |
Stuart McCulloch | 0ae86ab | 2008-02-19 06:24:30 +0000 | [diff] [blame] | 229 | |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 230 | // m_resourceBundle.construct( m_project, bindexExtractor, sourcePath, docPath ); |
| 231 | // TODO: rebuild wrt m_project |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 232 | |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 233 | m_repository.addResource( m_resourceBundle ); |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 234 | m_repository.setLastModified( System.currentTimeMillis() ); |
Stuart McCulloch | 0ae86ab | 2008-02-19 06:24:30 +0000 | [diff] [blame] | 235 | } |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 236 | |
Stuart McCulloch | 0ae86ab | 2008-02-19 06:24:30 +0000 | [diff] [blame] | 237 | |
Stuart McCulloch | a1d3a29 | 2008-02-20 00:53:52 +0000 | [diff] [blame] | 238 | private String relativisePath( URI uri ) |
| 239 | { |
| 240 | if ( null != uri ) |
| 241 | { |
| 242 | if ( m_userConfig.isPathRelative() ) |
| 243 | { |
| 244 | return ObrUtils.getRelativeURI( m_baseURI, uri ).toASCIIString(); |
| 245 | } |
| 246 | |
| 247 | return uri.toASCIIString(); |
| 248 | } |
| 249 | |
| 250 | return null; |
| 251 | } |
| 252 | |
| 253 | |
Stuart McCulloch | 0ae86ab | 2008-02-19 06:24:30 +0000 | [diff] [blame] | 254 | public void writeRepositoryXml() throws MojoExecutionException |
| 255 | { |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 256 | m_logger.info( "Writing OBR metadata" ); |
Stuart McCulloch | 0ae86ab | 2008-02-19 06:24:30 +0000 | [diff] [blame] | 257 | |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 258 | File file = null; |
| 259 | Writer writer; |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 260 | try |
| 261 | { |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 262 | file = File.createTempFile( "repository", ".xml" ); |
| 263 | writer = new OutputStreamWriter( new FileOutputStream( file ) ); |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 264 | } |
| 265 | catch ( IOException e ) |
| 266 | { |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 267 | m_logger.error( "Unable to write to file: " + file.getName() ); |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 268 | e.printStackTrace(); |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 269 | throw new MojoExecutionException( "Unable to write to file: " + file.getName() + " : " + e.getMessage() ); |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 270 | } |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 271 | |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 272 | try |
| 273 | { |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 274 | new DataModelHelperImpl().writeRepository( m_repository, writer ); |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 275 | } |
Stuart McCulloch | 8812902 | 2009-09-03 02:52:58 +0000 | [diff] [blame] | 276 | catch ( IOException e ) |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 277 | { |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 278 | throw new MojoExecutionException( "Unable to write repository xml", e ); |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | try |
| 282 | { |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 283 | writer.flush(); |
| 284 | writer.close(); |
Stuart McCulloch | 8812902 | 2009-09-03 02:52:58 +0000 | [diff] [blame] | 285 | |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 286 | File outputFile = new File( m_repositoryXml ); |
Stuart McCulloch | 8812902 | 2009-09-03 02:52:58 +0000 | [diff] [blame] | 287 | outputFile.getParentFile().mkdirs(); |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 288 | FileUtils.rename( file, outputFile ); |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 289 | } |
| 290 | catch ( IOException e ) |
| 291 | { |
| 292 | e.printStackTrace(); |
| 293 | throw new MojoExecutionException( "IOException" ); |
| 294 | } |
| 295 | |
| 296 | } |
| 297 | |
| 298 | |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 299 | /** |
| 300 | * Parse the repository descriptor file. |
| 301 | * |
| 302 | * @throws MojoExecutionException if the plugin failed |
| 303 | */ |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 304 | public void parseRepositoryXml() throws MojoExecutionException |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 305 | { |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 306 | File fout = new File( m_repositoryXml ); |
| 307 | if ( !fout.exists() ) |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 308 | { |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 309 | m_repository = new RepositoryImpl(); |
| 310 | writeRepositoryXml(); |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 311 | } |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 312 | else |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 313 | { |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 314 | try |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 315 | { |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 316 | m_repository = ( RepositoryImpl ) new DataModelHelperImpl().repository( m_repositoryXml.toURL() ); |
Stuart McCulloch | cfbac7a | 2011-10-16 19:56:22 +0000 | [diff] [blame] | 317 | if ( setURI != null ) |
| 318 | { |
| 319 | setURI.invoke( m_repository, ( String ) null ); |
| 320 | } |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 321 | } |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 322 | catch ( Exception e ) |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 323 | { |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 324 | throw new MojoExecutionException( "Unable to read repository xml: " + m_repositoryXml, e ); |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | |
| 330 | /** |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 331 | * put the information from obr.xml into ressourceBundle object. |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 332 | */ |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 333 | private void parseObrXml() throws MojoExecutionException |
| 334 | { |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 335 | try |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 336 | { |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 337 | InputStream is = new FileInputStream( new File( m_obrXml ) ); |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 338 | try |
| 339 | { |
| 340 | KXmlParser kxp = new KXmlParser(); |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 341 | kxp.setInput( is, null ); |
Guillaume Nodet | bdc1375 | 2010-03-25 08:21:15 +0000 | [diff] [blame] | 342 | kxp.nextTag(); // skip top level element |
| 343 | kxp.nextTag(); // go to first child element |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 344 | parseObrXml( kxp ); |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 345 | } |
| 346 | finally |
| 347 | { |
| 348 | is.close(); |
| 349 | } |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 350 | } |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 351 | catch ( Exception e ) |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 352 | { |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 353 | throw new MojoExecutionException( "Unable to parse obr xml: " + m_obrXml, e ); |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 354 | } |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 355 | } |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 356 | |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 357 | |
| 358 | private void parseObrXml( KXmlParser kxp ) throws Exception |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 359 | { |
| 360 | PullParser parser = new PullParser(); |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 361 | while ( kxp.getEventType() == XmlPullParser.START_TAG ) |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 362 | { |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 363 | if ( RepositoryParser.CATEGORY.equals( kxp.getName() ) ) |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 364 | { |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 365 | m_resourceBundle.addCategory( parser.parseCategory( kxp ) ); |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 366 | } |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 367 | else if ( RepositoryParser.REQUIRE.equals( kxp.getName() ) ) |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 368 | { |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 369 | m_resourceBundle.addRequire( parser.parseRequire( kxp ) ); |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 370 | } |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 371 | else if ( RepositoryParser.CAPABILITY.equals( kxp.getName() ) ) |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 372 | { |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 373 | m_resourceBundle.addCapability( parser.parseCapability( kxp ) ); |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 374 | } |
| 375 | else |
| 376 | { |
| 377 | kxp.nextTag(); |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 378 | parseObrXml( kxp ); |
Guillaume Nodet | 8d5faf6 | 2010-03-19 15:32:17 +0000 | [diff] [blame] | 379 | } |
| 380 | kxp.nextTag(); |
| 381 | } |
| 382 | } |
| 383 | |
Stuart McCulloch | bb8b9fa | 2008-02-17 16:07:14 +0000 | [diff] [blame] | 384 | } |