View Javadoc
1   /*
2    * #%L
3    * wcm.io
4    * %%
5    * Copyright (C) 2014 wcm.io
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package io.wcm.tooling.commons.packmgr.install;
21  
22  import java.io.File;
23  import java.io.IOException;
24  import java.util.Map;
25  
26  import org.apache.commons.lang3.StringUtils;
27  
28  import io.wcm.tooling.commons.packmgr.util.ContentPackageProperties;
29  
30  /**
31   * References a content package file for uploading.
32   */
33  public final class PackageFile {
34  
35    private File file;
36    private int delayAfterInstallSec;
37    private boolean install = true;
38    private Boolean force;
39    private boolean recursive = true;
40    private Integer httpSocketTimeoutSec;
41  
42    private static final int DEFAULT_DELAY_AFTER_CONTAINER_PACKAGE_SEC = 3;
43  
44    /**
45     * Content package file.
46     * @return File
47     */
48    public File getFile() {
49      return this.file;
50    }
51  
52    public void setFile(File file) {
53      this.file = file;
54    }
55  
56    /**
57     * Delay further steps after package installation by this amount of seconds
58     * @return Delay time
59     */
60    public int getDelayAfterInstallSec() {
61      return this.delayAfterInstallSec;
62    }
63  
64    public void setDelayAfterInstallSec(int delayAfterInstallSec) {
65      this.delayAfterInstallSec = delayAfterInstallSec;
66    }
67  
68    /**
69     * If not delay was configured try to detect a sensible default value:
70     * A few secs for container/mixed packages, 0 sec for others.
71     */
72    public void setDelayAfterInstallSecAutoDetect() {
73      try {
74        Map<String, Object> props = ContentPackageProperties.get(file);
75        String packageType = StringUtils.defaultString((String)props.get("packageType"), "content");
76        if (StringUtils.equals(packageType, "container") || StringUtils.equals(packageType, "mixed")) {
77          this.delayAfterInstallSec = DEFAULT_DELAY_AFTER_CONTAINER_PACKAGE_SEC;
78        }
79      }
80      catch (IOException ex) {
81        // ignore
82      }
83    }
84  
85    /**
86     * Whether to install (unpack) the uploaded package automatically or not.
87     * @return Install/unpack
88     */
89    public boolean isInstall() {
90      return this.install;
91    }
92  
93    public void setInstall(boolean install) {
94      this.install = install;
95    }
96  
97    /**
98     * Force upload and install of content package. If set to false a package is not uploaded or installed
99     * if it was already uploaded before.
100    * @return Force
101    */
102   public boolean isForce() {
103     // if no force parameter was set auto-detect best-matching force mode from file name
104     if (this.force == null) {
105       return StringUtils.contains(file.getName(), "-SNAPSHOT");
106     }
107     return this.force;
108   }
109 
110   public void setForce(Boolean force) {
111     this.force = force;
112   }
113 
114   // keep signature for backwards compatibility
115   public void setForce(boolean force) {
116     this.force = force;
117   }
118 
119   /**
120    * If set to true nested packages get installed as well.
121    * @return Recursive
122    */
123   public boolean isRecursive() {
124     return this.recursive;
125   }
126 
127   public void setRecursive(boolean recursive) {
128     this.recursive = recursive;
129   }
130 
131   /**
132    * HTTP socket timeout (in seconds).
133    * @return Timeout
134    */
135   public Integer getHttpSocketTimeoutSec() {
136     return this.httpSocketTimeoutSec;
137   }
138 
139   public void setHttpSocketTimeoutSec(Integer httpSocketTimeoutSec) {
140     this.httpSocketTimeoutSec = httpSocketTimeoutSec;
141   }
142 
143 }