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.io.File; 020 021import org.nuxeo.connect.update.task.update.JarUtils.Match; 022 023/** 024 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 025 */ 026public class UpdateOptions { 027 028 public static UpdateOptions newInstance(String pkgId, File file, File targetDir) { 029 // compute JAR name without version and the the JAR version 030 String name = file.getName(); 031 Match<String> match = JarUtils.findJarVersion(name); 032 // FIXME: hack to get the Studio snapshot version... 033 if (match == null && pkgId != null && pkgId.endsWith("-" + UpdateManager.STUDIO_SNAPSHOT_VERSION)) { 034 match = new Match<String>(); 035 match.object = pkgId.substring(0, pkgId.length() - ("-" + UpdateManager.STUDIO_SNAPSHOT_VERSION).length()); 036 match.version = UpdateManager.STUDIO_SNAPSHOT_VERSION; 037 } 038 if (match == null) { 039 return null; 040 } 041 UpdateOptions up = new UpdateOptions(); 042 up.pkgId = pkgId; 043 up.file = file; 044 up.nameWithoutVersion = match.object; 045 up.version = match.version; 046 up.targetDir = targetDir; 047 up.targetFile = new File(targetDir, name); 048 return up; 049 } 050 051 /** 052 * TYhe package ID 053 */ 054 protected String pkgId; 055 056 /** 057 * The jar file to be installed for this version 058 */ 059 protected File file; 060 061 /** 062 * The file name without the version 063 */ 064 protected String nameWithoutVersion; 065 066 /** 067 * The version of this update file (including classifier) 068 */ 069 protected String version; 070 071 /** 072 * Where the update file will be installed 073 */ 074 protected File targetFile; 075 076 /** 077 * The directory where this file will be installed 078 */ 079 protected File targetDir; 080 081 /** 082 * Allow install of a lower version 083 */ 084 protected boolean allowDowngrade; 085 086 /** 087 * Install only if already installed 088 */ 089 protected boolean upgradeOnly = false; 090 091 protected boolean deleteOnExit = false; 092 093 protected UpdateOptions() { 094 } 095 096 public File getFile() { 097 return file; 098 } 099 100 public File getTargetDir() { 101 return targetDir; 102 } 103 104 public File getTargetFile() { 105 return targetFile; 106 } 107 108 public String getVersion() { 109 return version; 110 } 111 112 public boolean isSnapshotVersion() { 113 return version.contains("-SNAPSHOT"); 114 } 115 116 public String getPackageId() { 117 return pkgId; 118 } 119 120 public void setUpgradeOnly(boolean upgradeOnly) { 121 this.upgradeOnly = upgradeOnly; 122 } 123 124 public void setAllowDowngrade(boolean allowDowngrade) { 125 this.allowDowngrade = allowDowngrade; 126 } 127 128 public boolean isUpgradeOnly() { 129 return upgradeOnly; 130 } 131 132 public boolean isAllowDowngrade() { 133 return allowDowngrade; 134 } 135 136 public void setDeleteOnExit(boolean deleteOnExit) { 137 this.deleteOnExit = deleteOnExit; 138 } 139 140 public boolean isDeleteOnExit() { 141 return deleteOnExit; 142 } 143}