View Javadoc

1   /*
2    * Copyright 2016-2016 Hippo B.V. (http://www.onehippo.com)
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.onehippo.forge.gallerymagick.core.command;
17  
18  import java.io.File;
19  
20  import org.slf4j.Logger;
21  import org.slf4j.LoggerFactory;
22  
23  abstract public class AbstractImageMagickCommandTest extends AbstractMagickCommandTest {
24  
25      private static Logger log = LoggerFactory.getLogger(AbstractImageMagickCommandTest.class);
26  
27      private static boolean _convertCommandAvailable;
28  
29      static {
30          final String executableFromSysProp = ImageMagickCommand.getExecutableFromSystemProperty("convert");
31  
32          if (executableFromSysProp != null) {
33              _convertCommandAvailable = new File(executableFromSysProp).exists();
34          } else {
35              if (!_convertCommandAvailable && new File("/bin/convert").isFile()) {
36                  _convertCommandAvailable = true;
37              }
38              if (!_convertCommandAvailable && new File("/usr/bin/convert").isFile()) {
39                  _convertCommandAvailable = true;
40              }
41              if (!_convertCommandAvailable && new File("/usr/local/bin/convert").isFile()) {
42                  _convertCommandAvailable = true;
43              }
44              if (!_convertCommandAvailable && new File("/opt/local/bin/convert").isFile()) {
45                  _convertCommandAvailable = true;
46              }
47          }
48      }
49  
50      protected static boolean isImageMagickAvailable() {
51          if (_convertCommandAvailable) {
52              return true;
53          }
54  
55          log.warn("Image Magick convert command not found.");
56          return false;
57      }
58  }