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