View Javadoc

1   /*
2    * Copyright 2024 Bloomreach B.V. (http://www.bloomreach.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 AbstractGraphicsMagickCommandTest extends AbstractMagickCommandTest {
24  
25      private static Logger log = LoggerFactory.getLogger(AbstractGraphicsMagickCommandTest.class);
26  
27      private static boolean _gmCommandAvailable;
28  
29      static {
30          final String executableFromSysProp = GraphicsMagickCommand.getExecutableFromSystemProperty();
31  
32          if (executableFromSysProp != null) {
33              _gmCommandAvailable = new File(executableFromSysProp).exists();
34          } else {
35              if (!_gmCommandAvailable && new File("/bin/gm").isFile()) {
36                  _gmCommandAvailable = true;
37              }
38              if (!_gmCommandAvailable && new File("/usr/bin/gm").isFile()) {
39                  _gmCommandAvailable = true;
40              }
41              if (!_gmCommandAvailable && new File("/usr/local/bin/gm").isFile()) {
42                  _gmCommandAvailable = true;
43              }
44              if (!_gmCommandAvailable && new File("/opt/local/bin/gm").isFile()) {
45                  _gmCommandAvailable = true;
46              }
47          }
48      }
49  
50      protected static boolean isGraphicsMagickAvailable() {
51          if (_gmCommandAvailable) {
52              return true;
53          }
54  
55          log.warn("Graphics Magick command not found.");
56          return false;
57      }
58  }