// Path: cm-schema/src/main/java/com/cloudera/parcel/descriptors/ParcelDescriptor.java
// public interface ParcelDescriptor {
// 
//   @NotNull
//   @Range(min = 1, max = 1)
//   Integer getSchema_version();
// 
//   @NotBlank
//   @Pattern(regexp="^((?!-).)*$", message="{custom.validation.constraints.ParcelName.message}")
//   String getName();
// 
//   @NotBlank
//   String getVersion();
// 
//   Map<String, String> getExtraVersionInfo();
// 
//   @NotNull
//   Boolean getSetActiveSymlink();
// 
//   String getDepends();
// 
//   String getReplaces();
// 
//   String getConflicts();
// 
//   Set<String> getProvides();
// 
//   @Valid
//   @NotNull
//   ScriptsDescriptor getScripts();
// 
//   @UniqueField("name")
//   @Valid
//   @NotNull
//   Set<PackageDescriptor> getPackages();
// 
//   @UniqueField("name")
//   @Valid
//   @NotNull
//   Set<ComponentDescriptor> getComponents();
// 
//   @Valid
//   @NotNull
//   Map<String, UserDescriptor> getUsers();
// 
//   @NotNull
//   Set<String> getGroups();
// 
//   ServicesRestartDescriptor getServicesRestartInfo();
// }


import com.cloudera.common.Parser;
import com.cloudera.parcel.descriptors.AlternativeDescriptor;
import com.cloudera.parcel.descriptors.AlternativesDescriptor;
import com.cloudera.parcel.descriptors.ParcelDescriptor;
import com.cloudera.parcel.descriptors.PermissionDescriptor;
import com.cloudera.parcel.descriptors.PermissionsDescriptor;
import com.cloudera.validation.DescriptorRunner;
import com.cloudera.validation.ValidationRunner;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
// Licensed to Cloudera, Inc. under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  Cloudera, Inc. licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.cloudera.cli.validator.components;




/**
 * This {@link ValidationRunner} validates a complete parcel file.
 *
 * It validates the parcel's filename as well as the contents of the parcel,
 * ensuring consistency between the filename, directory and contained metadata.
 */
@Component
public class ParcelFileRunner implements ValidationRunner {
  /**
   * This pattern defines the expected form for a regular parcel package.
   *   [product]-[version]-[distro].parcel
   * The group for [version] is greedy so that it captures embedded '-'s.
   * The [product] and [distro] are not allowed to have embedded '-'s.
   */
  private static final Pattern PARCEL_PATTERN = Pattern.compile("^(.*?)-(.*)-(.*?)\\.parcel$");

  // This is the set of distros that CM is currently aware of. Future versions
  // of CM may understand more, and this list should be updated accordingly.
  private static final Set<String> KNOWN_DISTROS = ImmutableSet.of(
      "el5",
      "el6",
      "el7",
      "sles11",
      "sles12",
      "lucid",
      "precise",
      "trusty",
      "squeeze",
      "wheezy",
      "jessie");

  private static final String PARCEL_JSON_PATH = "/meta/parcel.json";
  private static final String ALTERNATIVES_JSON_PATH = "/meta/alternatives.json";
  private static final String PERMISSIONS_JSON_PATH = "/meta/permissions.json";

  @Autowired
  @Qualifier("parcelParser")
// Path: cm-schema/src/main/java/com/cloudera/parcel/descriptors/ParcelDescriptor.java
// public interface ParcelDescriptor {
// 
//   @NotNull
//   @Range(min = 1, max = 1)
//   Integer getSchema_version();
// 
//   @NotBlank
//   @Pattern(regexp="^((?!-).)*$", message="{custom.validation.constraints.ParcelName.message}")
//   String getName();
// 
//   @NotBlank
//   String getVersion();
// 
//   Map<String, String> getExtraVersionInfo();
// 
//   @NotNull
//   Boolean getSetActiveSymlink();
// 
//   String getDepends();
// 
//   String getReplaces();
// 
//   String getConflicts();
// 
//   Set<String> getProvides();
// 
//   @Valid
//   @NotNull
//   ScriptsDescriptor getScripts();
// 
//   @UniqueField("name")
//   @Valid
//   @NotNull
//   Set<PackageDescriptor> getPackages();
// 
//   @UniqueField("name")
//   @Valid
//   @NotNull
//   Set<ComponentDescriptor> getComponents();
// 
//   @Valid
//   @NotNull
//   Map<String, UserDescriptor> getUsers();
// 
//   @NotNull
//   Set<String> getGroups();
// 
//   ServicesRestartDescriptor getServicesRestartInfo();
// }


// Path: validator/src/main/java/com/cloudera/cli/validator/components/ParcelFileRunner.java
import com.cloudera.common.Parser;
import com.cloudera.parcel.descriptors.AlternativeDescriptor;
import com.cloudera.parcel.descriptors.AlternativesDescriptor;
import com.cloudera.parcel.descriptors.ParcelDescriptor;
import com.cloudera.parcel.descriptors.PermissionDescriptor;
import com.cloudera.parcel.descriptors.PermissionsDescriptor;
import com.cloudera.validation.DescriptorRunner;
import com.cloudera.validation.ValidationRunner;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

// Licensed to Cloudera, Inc. under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  Cloudera, Inc. licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.cloudera.cli.validator.components;




/**
 * This {@link ValidationRunner} validates a complete parcel file.
 *
 * It validates the parcel's filename as well as the contents of the parcel,
 * ensuring consistency between the filename, directory and contained metadata.
 */
@Component
public class ParcelFileRunner implements ValidationRunner {
  /**
   * This pattern defines the expected form for a regular parcel package.
   *   [product]-[version]-[distro].parcel
   * The group for [version] is greedy so that it captures embedded '-'s.
   * The [product] and [distro] are not allowed to have embedded '-'s.
   */
  private static final Pattern PARCEL_PATTERN = Pattern.compile("^(.*?)-(.*)-(.*?)\\.parcel$");

  // This is the set of distros that CM is currently aware of. Future versions
  // of CM may understand more, and this list should be updated accordingly.
  private static final Set<String> KNOWN_DISTROS = ImmutableSet.of(
      "el5",
      "el6",
      "el7",
      "sles11",
      "sles12",
      "lucid",
      "precise",
      "trusty",
      "squeeze",
      "wheezy",
      "jessie");

  private static final String PARCEL_JSON_PATH = "/meta/parcel.json";
  private static final String ALTERNATIVES_JSON_PATH = "/meta/alternatives.json";
  private static final String PERMISSIONS_JSON_PATH = "/meta/permissions.json";

  @Autowired
  @Qualifier("parcelParser")
  private Parser<ParcelDescriptor> parcelParser;