| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Metadata |
|
| 2.6;2.6 |
| 1 | /* | |
| 2 | * $Id$ | |
| 3 | */ | |
| 4 | ||
| 5 | package org.apache.maven.artifact.repository.metadata; | |
| 6 | ||
| 7 | //---------------------------------/ | |
| 8 | //- Imported classes and packages -/ | |
| 9 | //---------------------------------/ | |
| 10 | ||
| 11 | import java.util.Date; | |
| 12 | ||
| 13 | /** | |
| 14 | * Class Metadata. | |
| 15 | * | |
| 16 | * @version $Revision$ $Date$ | |
| 17 | */ | |
| 18 | 0 | public class Metadata implements java.io.Serializable { |
| 19 | ||
| 20 | ||
| 21 | //--------------------------/ | |
| 22 | //- Class/Member Variables -/ | |
| 23 | //--------------------------/ | |
| 24 | ||
| 25 | /** | |
| 26 | * The groupId that this directory represents, if any. | |
| 27 | */ | |
| 28 | private String groupId; | |
| 29 | ||
| 30 | /** | |
| 31 | * The artifactId that this directory represents, if any. | |
| 32 | */ | |
| 33 | private String artifactId; | |
| 34 | ||
| 35 | /** | |
| 36 | * The version that this directory represents, if any. | |
| 37 | */ | |
| 38 | private String version; | |
| 39 | ||
| 40 | /** | |
| 41 | * Versioning information for the artifact. | |
| 42 | */ | |
| 43 | private Versioning versioning; | |
| 44 | ||
| 45 | /** | |
| 46 | * Field plugins. | |
| 47 | */ | |
| 48 | private java.util.List plugins; | |
| 49 | ||
| 50 | ||
| 51 | //-----------/ | |
| 52 | //- Methods -/ | |
| 53 | //-----------/ | |
| 54 | ||
| 55 | /** | |
| 56 | * Method addPlugin. | |
| 57 | * | |
| 58 | * @param plugin | |
| 59 | */ | |
| 60 | public void addPlugin( Plugin plugin ) | |
| 61 | { | |
| 62 | 0 | if ( !(plugin instanceof Plugin) ) |
| 63 | { | |
| 64 | 0 | throw new ClassCastException( "Metadata.addPlugins(plugin) parameter must be instanceof " + Plugin.class.getName() ); |
| 65 | } | |
| 66 | 0 | getPlugins().add( plugin ); |
| 67 | 0 | } //-- void addPlugin( Plugin ) |
| 68 | ||
| 69 | /** | |
| 70 | * Get the artifactId that this directory represents, if any. | |
| 71 | * | |
| 72 | * @return String | |
| 73 | */ | |
| 74 | public String getArtifactId() | |
| 75 | { | |
| 76 | 0 | return this.artifactId; |
| 77 | } //-- String getArtifactId() | |
| 78 | ||
| 79 | /** | |
| 80 | * Get the groupId that this directory represents, if any. | |
| 81 | * | |
| 82 | * @return String | |
| 83 | */ | |
| 84 | public String getGroupId() | |
| 85 | { | |
| 86 | 0 | return this.groupId; |
| 87 | } //-- String getGroupId() | |
| 88 | ||
| 89 | /** | |
| 90 | * Method getPlugins. | |
| 91 | * | |
| 92 | * @return java.util.List | |
| 93 | */ | |
| 94 | public java.util.List getPlugins() | |
| 95 | { | |
| 96 | 0 | if ( this.plugins == null ) |
| 97 | { | |
| 98 | 0 | this.plugins = new java.util.ArrayList(); |
| 99 | } | |
| 100 | ||
| 101 | 0 | return this.plugins; |
| 102 | } //-- java.util.List getPlugins() | |
| 103 | ||
| 104 | /** | |
| 105 | * Get the version that this directory represents, if any. | |
| 106 | * | |
| 107 | * @return String | |
| 108 | */ | |
| 109 | public String getVersion() | |
| 110 | { | |
| 111 | 0 | return this.version; |
| 112 | } //-- String getVersion() | |
| 113 | ||
| 114 | /** | |
| 115 | * Get versioning information for the artifact. | |
| 116 | * | |
| 117 | * @return Versioning | |
| 118 | */ | |
| 119 | public Versioning getVersioning() | |
| 120 | { | |
| 121 | 0 | return this.versioning; |
| 122 | } //-- Versioning getVersioning() | |
| 123 | ||
| 124 | /** | |
| 125 | * Method removePlugin. | |
| 126 | * | |
| 127 | * @param plugin | |
| 128 | */ | |
| 129 | public void removePlugin( Plugin plugin ) | |
| 130 | { | |
| 131 | 0 | if ( !(plugin instanceof Plugin) ) |
| 132 | { | |
| 133 | 0 | throw new ClassCastException( "Metadata.removePlugins(plugin) parameter must be instanceof " + Plugin.class.getName() ); |
| 134 | } | |
| 135 | 0 | getPlugins().remove( plugin ); |
| 136 | 0 | } //-- void removePlugin( Plugin ) |
| 137 | ||
| 138 | /** | |
| 139 | * Set the artifactId that this directory represents, if any. | |
| 140 | * | |
| 141 | * @param artifactId | |
| 142 | */ | |
| 143 | public void setArtifactId( String artifactId ) | |
| 144 | { | |
| 145 | 0 | this.artifactId = artifactId; |
| 146 | 0 | } //-- void setArtifactId( String ) |
| 147 | ||
| 148 | /** | |
| 149 | * Set the groupId that this directory represents, if any. | |
| 150 | * | |
| 151 | * @param groupId | |
| 152 | */ | |
| 153 | public void setGroupId( String groupId ) | |
| 154 | { | |
| 155 | 0 | this.groupId = groupId; |
| 156 | 0 | } //-- void setGroupId( String ) |
| 157 | ||
| 158 | /** | |
| 159 | * Set the set of plugin mappings for the group. | |
| 160 | * | |
| 161 | * @param plugins | |
| 162 | */ | |
| 163 | public void setPlugins( java.util.List plugins ) | |
| 164 | { | |
| 165 | 0 | this.plugins = plugins; |
| 166 | 0 | } //-- void setPlugins( java.util.List ) |
| 167 | ||
| 168 | /** | |
| 169 | * Set the version that this directory represents, if any. | |
| 170 | * | |
| 171 | * @param version | |
| 172 | */ | |
| 173 | public void setVersion( String version ) | |
| 174 | { | |
| 175 | 0 | this.version = version; |
| 176 | 0 | } //-- void setVersion( String ) |
| 177 | ||
| 178 | /** | |
| 179 | * Set versioning information for the artifact. | |
| 180 | * | |
| 181 | * @param versioning | |
| 182 | */ | |
| 183 | public void setVersioning( Versioning versioning ) | |
| 184 | { | |
| 185 | 0 | this.versioning = versioning; |
| 186 | 0 | } //-- void setVersioning( Versioning ) |
| 187 | ||
| 188 | ||
| 189 | public boolean merge( Metadata sourceMetadata ) | |
| 190 | { | |
| 191 | 0 | boolean changed = false; |
| 192 | ||
| 193 | 0 | for ( java.util.Iterator i = sourceMetadata.getPlugins().iterator(); i.hasNext(); ) |
| 194 | { | |
| 195 | 0 | Plugin plugin = (Plugin) i.next(); |
| 196 | 0 | boolean found = false; |
| 197 | ||
| 198 | 0 | for ( java.util.Iterator it = getPlugins().iterator(); it.hasNext() && !found; ) |
| 199 | { | |
| 200 | 0 | Plugin preExisting = (Plugin) it.next(); |
| 201 | ||
| 202 | 0 | if ( preExisting.getPrefix().equals( plugin.getPrefix() ) ) |
| 203 | { | |
| 204 | 0 | found = true; |
| 205 | } | |
| 206 | 0 | } |
| 207 | ||
| 208 | 0 | if ( !found ) |
| 209 | { | |
| 210 | 0 | Plugin mappedPlugin = new Plugin(); |
| 211 | ||
| 212 | 0 | mappedPlugin.setArtifactId( plugin.getArtifactId() ); |
| 213 | ||
| 214 | 0 | mappedPlugin.setPrefix( plugin.getPrefix() ); |
| 215 | ||
| 216 | 0 | mappedPlugin.setName( plugin.getName() ); |
| 217 | ||
| 218 | 0 | addPlugin( mappedPlugin ); |
| 219 | ||
| 220 | 0 | changed = true; |
| 221 | } | |
| 222 | 0 | } |
| 223 | ||
| 224 | 0 | Versioning versioning = sourceMetadata.getVersioning(); |
| 225 | 0 | if ( versioning != null ) |
| 226 | { | |
| 227 | 0 | Versioning v = getVersioning(); |
| 228 | 0 | if ( v == null ) |
| 229 | { | |
| 230 | 0 | v = new Versioning(); |
| 231 | 0 | setVersioning( v ); |
| 232 | 0 | changed = true; |
| 233 | } | |
| 234 | ||
| 235 | 0 | for ( java.util.Iterator i = versioning.getVersions().iterator(); i.hasNext(); ) |
| 236 | { | |
| 237 | 0 | String version = (String) i.next(); |
| 238 | 0 | if ( !v.getVersions().contains( version ) ) |
| 239 | { | |
| 240 | 0 | changed = true; |
| 241 | 0 | v.getVersions().add( version ); |
| 242 | } | |
| 243 | 0 | } |
| 244 | ||
| 245 | 0 | if ( "null".equals( versioning.getLastUpdated() ) ) |
| 246 | { | |
| 247 | 0 | versioning.setLastUpdated( null ); |
| 248 | } | |
| 249 | ||
| 250 | 0 | if ( "null".equals( v.getLastUpdated() ) ) |
| 251 | { | |
| 252 | 0 | v.setLastUpdated( null ); |
| 253 | } | |
| 254 | ||
| 255 | 0 | if ( versioning.getLastUpdated() == null || versioning.getLastUpdated().length() == 0 ) |
| 256 | { | |
| 257 | // this should only be for historical reasons - we assume local is newer | |
| 258 | 0 | versioning.setLastUpdated( v.getLastUpdated() ); |
| 259 | } | |
| 260 | ||
| 261 | 0 | if ( v.getLastUpdated() == null || v.getLastUpdated().length() == 0 || |
| 262 | versioning.getLastUpdated().compareTo( v.getLastUpdated() ) >= 0 ) | |
| 263 | { | |
| 264 | 0 | changed = true; |
| 265 | 0 | v.setLastUpdated( versioning.getLastUpdated() ); |
| 266 | ||
| 267 | 0 | if ( versioning.getRelease() != null ) |
| 268 | { | |
| 269 | 0 | changed = true; |
| 270 | 0 | v.setRelease( versioning.getRelease() ); |
| 271 | } | |
| 272 | 0 | if ( versioning.getLatest() != null ) |
| 273 | { | |
| 274 | 0 | changed = true; |
| 275 | 0 | v.setLatest( versioning.getLatest() ); |
| 276 | } | |
| 277 | ||
| 278 | 0 | Snapshot s = v.getSnapshot(); |
| 279 | 0 | Snapshot snapshot = versioning.getSnapshot(); |
| 280 | 0 | if ( snapshot != null ) |
| 281 | { | |
| 282 | 0 | if ( s == null ) |
| 283 | { | |
| 284 | 0 | s = new Snapshot(); |
| 285 | 0 | v.setSnapshot( s ); |
| 286 | 0 | changed = true; |
| 287 | } | |
| 288 | ||
| 289 | // overwrite | |
| 290 | 0 | if ( s.getTimestamp() == null ? snapshot.getTimestamp() != null |
| 291 | : !s.getTimestamp().equals( snapshot.getTimestamp() ) ) | |
| 292 | { | |
| 293 | 0 | s.setTimestamp( snapshot.getTimestamp() ); |
| 294 | 0 | changed = true; |
| 295 | } | |
| 296 | 0 | if ( s.getBuildNumber() != snapshot.getBuildNumber() ) |
| 297 | { | |
| 298 | 0 | s.setBuildNumber( snapshot.getBuildNumber() ); |
| 299 | 0 | changed = true; |
| 300 | } | |
| 301 | 0 | if ( s.isLocalCopy() != snapshot.isLocalCopy() ) |
| 302 | { | |
| 303 | 0 | s.setLocalCopy( snapshot.isLocalCopy() ); |
| 304 | 0 | changed = true; |
| 305 | } | |
| 306 | } | |
| 307 | } | |
| 308 | } | |
| 309 | 0 | return changed; |
| 310 | } | |
| 311 | ||
| 312 | 0 | private String modelEncoding = "UTF-8"; |
| 313 | ||
| 314 | /** | |
| 315 | * Set an encoding used for reading/writing the model. | |
| 316 | * | |
| 317 | * @param modelEncoding the encoding used when reading/writing the model. | |
| 318 | */ | |
| 319 | public void setModelEncoding( String modelEncoding ) | |
| 320 | { | |
| 321 | 0 | this.modelEncoding = modelEncoding; |
| 322 | 0 | } |
| 323 | ||
| 324 | /** | |
| 325 | * @return the current encoding used when reading/writing this model. | |
| 326 | */ | |
| 327 | public String getModelEncoding() | |
| 328 | { | |
| 329 | 0 | return modelEncoding; |
| 330 | } | |
| 331 | } |