001/* 002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bstefanescu 018 */ 019package org.nuxeo.connect.update.task.update; 020 021import java.util.HashMap; 022import java.util.Map; 023 024import org.nuxeo.common.utils.FileVersion; 025 026/** 027 * The version correspond to a JAR version that is required by some package. An update version is defined by the JAR 028 * version, a relative path to the JAR file and a list of packages requiring this version. The path points to a copy of 029 * the JAR version in the update manager storage. (thus the path is relative to the update manager root) Let say you 030 * install a package pkg1 that requires the version 1.0 for the jar X. If this version is not yet provided by another 031 * package a new version will be created and the jar file copied in the update manager storage under the destination 032 * 'path' (e.g. bundles/X-1.0.jar). 033 * 034 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 035 */ 036public class Version { 037 038 /** 039 * The version name (including classifier) 040 */ 041 protected String version; 042 043 /** 044 * The path of the backup file 045 */ 046 protected String path; 047 048 /** 049 * The packages requiring this version 050 */ 051 protected Map<String, UpdateOptions> packages; 052 053 public Version(String version) { 054 this.version = version; 055 packages = new HashMap<String, UpdateOptions>(); 056 } 057 058 public final Map<String, UpdateOptions> getPackages() { 059 return packages; 060 } 061 062 public boolean hasPackage(String pkgId) { 063 return packages.containsKey(pkgId); 064 } 065 066 public boolean removePackage(String pkgId) { 067 return packages.remove(pkgId) != null; 068 } 069 070 public boolean addPackage(UpdateOptions opt) { 071 return packages.put(opt.getPackageId(), opt) != null; 072 } 073 074 public boolean hasPackages() { 075 return !packages.isEmpty(); 076 } 077 078 public final String getPath() { 079 return path; 080 } 081 082 public final void setPath(String path) { 083 this.path = path; 084 } 085 086 public final String getVersion() { 087 return version; 088 } 089 090 public final FileVersion getFileVersion() { 091 return new FileVersion(version); 092 } 093 094 @Override 095 public boolean equals(Object obj) { 096 if (this == obj) { 097 return true; 098 } 099 if (obj instanceof Version) { 100 return ((Version) obj).version.equals(version); 101 } 102 return false; 103 } 104 105 @Override 106 public int hashCode() { 107 return version.hashCode(); 108 } 109 110 @Override 111 public String toString() { 112 return version; 113 } 114 115}