001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.servicemix.jbi.management.task;
018    
019    import java.io.File;
020    
021    import org.apache.servicemix.jbi.framework.AdminCommandsServiceMBean;
022    import org.apache.tools.ant.BuildException;
023    
024    /**
025     * Install a shared library
026     * 
027     * @version $Revision: 359151 $
028     */
029    public class InstallSharedLibraryTask extends JbiTask {
030    
031        private String file; // shared library URI to install
032    
033        private boolean deferExceptions;
034    
035        public boolean isDeferExceptions() {
036            return deferExceptions;
037        }
038    
039        public void setDeferExceptions(boolean deferExceptions) {
040            this.deferExceptions = deferExceptions;
041        }
042    
043        /**
044         * @return Returns the file.
045         */
046        public String getFile() {
047            return file;
048        }
049    
050        /**
051         * @param file
052         *            The shared library URI to set.
053         */
054        public void setFile(String file) {
055            this.file = file;
056        }
057    
058        /**
059         * execute the task
060         * 
061         * @throws BuildException
062         */
063        public void doExecute(AdminCommandsServiceMBean acs) throws Exception {
064            if (file == null) {
065                throw new BuildException("null file - file should be an archive");
066            }
067            if (!file.endsWith(".zip") && !file.endsWith(".jar")) {
068                throw new BuildException("file: " + file + " is not an archive");
069            }
070            File archive = new File(file);
071            String location = archive.getAbsolutePath();
072            if (!archive.isFile()) {
073                // if it's not a file, assume it's a url and pass it along
074                location = file;
075            }
076            acs.installSharedLibrary(location, deferExceptions);
077        }
078    
079    }