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.standalone.commands; 020 021import java.io.File; 022import java.util.Map; 023 024import org.nuxeo.connect.update.PackageException; 025import org.nuxeo.connect.update.ValidationStatus; 026import org.nuxeo.connect.update.task.Command; 027import org.nuxeo.connect.update.task.Task; 028import org.nuxeo.connect.update.xml.XmlWriter; 029import org.w3c.dom.Element; 030 031/** 032 * Install bundle, flush any application cache and perform Nuxeo preprocessing on the bundle. 033 * <p> 034 * The inverse of this command is Undeploy. 035 * 036 * @author <a href="mailto:[email protected]">Bogdan Stefanescu</a> 037 */ 038public class DeployPlaceholder extends AbstractCommand { 039 040 public static final String ID = "deploy"; 041 042 protected File file; 043 044 public DeployPlaceholder() { 045 super(ID); 046 } 047 048 public DeployPlaceholder(File file) { 049 super(ID); 050 this.file = file; 051 } 052 053 @Override 054 protected void doValidate(Task task, ValidationStatus status) throws PackageException { 055 // nothing to do 056 } 057 058 @Override 059 protected Command doRun(Task task, Map<String, String> prefs) throws PackageException { 060 if (!file.isFile()) { 061 // avoid throwing errors - this may happen at uninstall for broken 062 // packages 063 return null; 064 } 065 // standalone mode: nothing to do 066 return new UndeployPlaceholder(file); 067 } 068 069 public void readFrom(Element element) throws PackageException { 070 String v = element.getAttribute("file"); 071 if (v.length() > 0) { 072 file = new File(v); 073 guardVars.put("file", file); 074 } 075 } 076 077 public void writeTo(XmlWriter writer) { 078 writer.start(ID); 079 if (file != null) { 080 writer.attr("file", file.getAbsolutePath()); 081 } 082 writer.end(); 083 } 084}