001/* 002 * (C) Copyright 2006-2010 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * bstefanescu 016 */ 017package org.nuxeo.connect.update.task.update; 018 019import java.util.HashMap; 020import java.util.Map; 021 022import org.nuxeo.common.utils.FileVersion; 023 024/** 025 * The version correspond to a JAR version that is required by some package. An update version is defined by the JAR 026 * version, a relative path to the JAR file and a list of packages requiring this version. The path points to a copy of 027 * the JAR version in the update manager storage. (thus the path is relative to the update manager root) Let say you 028 * install a package pkg1 that requires the version 1.0 for the jar X. If this version is not yet provided by another 029 * package a new version will be created and the jar file copied in the update manager storage under the destination 030 * 'path' (e.g. bundles/X-1.0.jar). 031 * 032 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 033 */ 034public class Version { 035 036 /** 037 * The version name (including classifier) 038 */ 039 protected String version; 040 041 /** 042 * The path of the backup file 043 */ 044 protected String path; 045 046 /** 047 * The packages requiring this version 048 */ 049 protected Map<String, UpdateOptions> packages; 050 051 public Version(String version) { 052 this.version = version; 053 packages = new HashMap<String, UpdateOptions>(); 054 } 055 056 public final Map<String, UpdateOptions> getPackages() { 057 return packages; 058 } 059 060 public boolean hasPackage(String pkgId) { 061 return packages.containsKey(pkgId); 062 } 063 064 public boolean removePackage(String pkgId) { 065 return packages.remove(pkgId) != null; 066 } 067 068 public boolean addPackage(UpdateOptions opt) { 069 return packages.put(opt.getPackageId(), opt) != null; 070 } 071 072 public boolean hasPackages() { 073 return !packages.isEmpty(); 074 } 075 076 public final String getPath() { 077 return path; 078 } 079 080 public final void setPath(String path) { 081 this.path = path; 082 } 083 084 public final String getVersion() { 085 return version; 086 } 087 088 public final FileVersion getFileVersion() { 089 return new FileVersion(version); 090 } 091 092 @Override 093 public boolean equals(Object obj) { 094 if (this == obj) { 095 return true; 096 } 097 if (obj instanceof Version) { 098 return ((Version) obj).version.equals(version); 099 } 100 return false; 101 } 102 103 @Override 104 public int hashCode() { 105 return version.hashCode(); 106 } 107 108 @Override 109 public String toString() { 110 return version; 111 } 112 113}