View Javadoc
1   /*
2    * Copyright 2014 The Codehaus Foundation.
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.codehaus.plexus.archiver.util;
17  
18  import java.io.File;
19  import java.io.IOException;
20  
21  import org.codehaus.plexus.archiver.ArchiverException;
22  import org.codehaus.plexus.components.io.attributes.AttributeUtils;
23  import org.codehaus.plexus.util.Os;
24  import org.slf4j.Logger;
25  
26  @SuppressWarnings("JavaDoc")
27  public final class ArchiveEntryUtils {
28  
29      private ArchiveEntryUtils() {
30          // no op
31      }
32  
33      /**
34       * This method is now deprecated.
35       *
36       * The {@code useJvmChmod} flag is ignored as the JVM is always used.
37       * The {@code logger} provided is no longer used.
38       *
39       * @deprecated Use {@link #chmod(File, int)}
40       */
41      @Deprecated
42      public static void chmod(final File file, final int mode, final Logger logger, boolean useJvmChmod)
43              throws ArchiverException {
44          chmod(file, mode);
45      }
46  
47      /**
48       * This method is now deprecated.
49       *
50       * The {@code logger} provided is no longer used.
51       *
52       * @deprecated Use {@link #chmod(File, int)}
53       */
54      @Deprecated
55      public static void chmod(final File file, final int mode, final Logger logger) throws ArchiverException {
56          chmod(file, mode);
57      }
58  
59      public static void chmod(final File file, final int mode) throws ArchiverException {
60          if (!Os.isFamily(Os.FAMILY_UNIX)) {
61              return;
62          }
63  
64          try {
65              AttributeUtils.chmod(file, mode);
66          } catch (IOException e) {
67              throw new ArchiverException("Failed setting file attributes", e);
68          }
69      }
70  }