TemporaryContentPackageFile.java

  1. /*
  2.  * #%L
  3.  * wcm.io
  4.  * %%
  5.  * Copyright (C) 2021 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.devops.conga.plugins.aem.maven.allpackage;

  21. import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_DEPENDENCIES;
  22. import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_GROUP;
  23. import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_NAME;
  24. import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_PACKAGE_TYPE;
  25. import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_VERSION;

  26. import java.io.File;
  27. import java.io.IOException;
  28. import java.util.Collection;
  29. import java.util.Map;

  30. import io.wcm.devops.conga.plugins.aem.maven.model.AbstractInstallableFile;
  31. import io.wcm.devops.conga.plugins.aem.maven.model.ContentPackageFile;
  32. import io.wcm.tooling.commons.packmgr.util.ContentPackageProperties;

  33. /**
  34.  * References a temporary file representing an partially processed content package to be included in the "all" package.
  35.  */
  36. final class TemporaryContentPackageFile extends AbstractInstallableFile implements ContentPackageFile {

  37.   private final String name;
  38.   private final String group;
  39.   private final String version;
  40.   private final String packageType;
  41.   private final String dependencies;

  42.   TemporaryContentPackageFile(File file, Collection<String> variants) throws IOException {
  43.     super(file, variants);
  44.     Map<String, Object> props = ContentPackageProperties.get(file);
  45.     this.name = (String)props.get(NAME_NAME);
  46.     this.group = (String)props.get(NAME_GROUP);
  47.     this.version = (String)props.get(NAME_VERSION);
  48.     this.packageType = (String)props.get(NAME_PACKAGE_TYPE);
  49.     this.dependencies = (String)props.get(NAME_DEPENDENCIES);
  50.   }

  51.   @Override
  52.   public String getName() {
  53.     return this.name;
  54.   }

  55.   @Override
  56.   public String getGroup() {
  57.     return this.group;
  58.   }

  59.   @Override
  60.   public String getVersion() {
  61.     return this.version;
  62.   }

  63.   @Override
  64.   public String getPackageType() {
  65.     return this.packageType;
  66.   }

  67.   public String getDependencies() {
  68.     return this.dependencies;
  69.   }

  70.   public String getPackageInfoWithDependencies() {
  71.     StringBuilder sb = new StringBuilder();
  72.     sb.append(getPackageInfo());
  73.     if (this.dependencies != null) {
  74.       sb.append(" (dependencies: ").append(this.dependencies).append(")");
  75.     }
  76.     return sb.toString();
  77.   }

  78. }