2929import java .io .FileOutputStream ;
3030import java .io .IOException ;
3131import java .io .InputStream ;
32- import java .nio .file .Files ;
3332import java .util .ArrayList ;
3433import java .util .Arrays ;
3534import java .util .Enumeration ;
5352import org .apache .jackrabbit .vault .packaging .VersionRange ;
5453import org .apache .maven .plugin .logging .Log ;
5554import org .apache .maven .plugin .logging .SystemStreamLog ;
56- import org .jetbrains .annotations .NotNull ;
5755
58- import com .google .common .collect .ImmutableMap ;
5956import com .google .common .collect .ImmutableSet ;
6057
6158import io .wcm .devops .conga .plugins .aem .maven .AutoDependenciesMode ;
6259import io .wcm .devops .conga .plugins .aem .maven .model .ContentPackageFile ;
63- import io .wcm .devops .conga .plugins .aem .postprocessor .ContentPackagePropertiesPostProcessor ;
6460import io .wcm .tooling .commons .contentpackagebuilder .ContentPackage ;
6561import io .wcm .tooling .commons .contentpackagebuilder .ContentPackageBuilder ;
6662import io .wcm .tooling .commons .contentpackagebuilder .PackageFilter ;
67- import io .wcm .tooling .commons .packmgr .util .ContentPackageProperties ;
6863
6964/**
7065 * Builds "all" package based on given set of content packages.
@@ -404,34 +399,16 @@ private static String updateDependencies(Properties props, ContentPackageFile de
404399 existingDeps = removeReferencesToManagedPackages (existingDeps , allPackagesFromFileSets );
405400 }
406401
407- Dependency [] deps = null ;
408- if (dependencyFile == null ) {
409- deps = existingDeps ;
402+ Dependency [] deps ;
403+ if (dependencyFile != null ) {
404+ String runModeSuffix = buildRunModeSuffix (dependencyFile , environmentRunMode );
405+ Dependency newDependency = new Dependency (dependencyFile .getGroup (),
406+ dependencyFile .getName () + runModeSuffix ,
407+ VersionRange .fromString (dependencyFile .getVersion ()));
408+ deps = addDependency (existingDeps , newDependency );
410409 }
411410 else {
412- // if package is container package: check for embedded sub packages
413- List <ContentPackageFile > containerSubPackageFiles = null ;
414- if (isContainerPackage (dependencyFile )) {
415- containerSubPackageFiles = getContainerSubPackageFiles (dependencyFile );
416- }
417- // if sub packages are present: add dependencies to sub packages instead of the container package
418- // nested sub packages are referenced without any runmode suffix
419- if (containerSubPackageFiles != null ) {
420- for (ContentPackageFile subPackageFileItem : containerSubPackageFiles ) {
421- Dependency newDependency = new Dependency (subPackageFileItem .getGroup (),
422- subPackageFileItem .getName (),
423- VersionRange .fromString (subPackageFileItem .getVersion ()));
424- deps = addDependency (existingDeps , newDependency );
425- }
426- }
427- // otherwise add dependency to package itself
428- else {
429- String runModeSuffix = buildRunModeSuffix (dependencyFile , environmentRunMode );
430- Dependency newDependency = new Dependency (dependencyFile .getGroup (),
431- dependencyFile .getName () + runModeSuffix ,
432- VersionRange .fromString (dependencyFile .getVersion ()));
433- deps = addDependency (existingDeps , newDependency );
434- }
411+ deps = existingDeps ;
435412 }
436413
437414 if (deps != null ) {
@@ -453,55 +430,6 @@ private static Dependency[] addDependency(Dependency[] existingDeps, Dependency
453430 }
454431 }
455432
456- /**
457- * If the content package is a container package that contains sub packages (that are sub packages in sub packages),
458- * the cp2fm conversion eliminates the nested package container "in the middle", leading to unresolveable
459- * dependencies. So, if the dependency content package contains sub packages, we add dependencies
460- * to the contained sub packages instead.
461- * @param dependencyFile Dependency package
462- * @return List of dependency packages or null if none exist
463- * @throws IOException I/O exception
464- */
465- private static List <ContentPackageFile > getContainerSubPackageFiles (@ NotNull ContentPackageFile dependencyFile ) throws IOException {
466- // introspect container package file - check for sub packages
467- List <ContentPackageFile > dependencyFiles = new ArrayList <>();
468- try (ZipFile zipFileIn = new ZipFile (dependencyFile .getFile ())) {
469- Enumeration <? extends ZipEntry > zipInEntries = zipFileIn .entries ();
470- while (zipInEntries .hasMoreElements ()) {
471- ZipEntry zipInEntry = zipInEntries .nextElement ();
472- if (StringUtils .equals ("zip" , FilenameUtils .getExtension (zipInEntry .getName ()))) {
473- File tempFile = File .createTempFile (zipInEntry .getName () + "-subpackage-" , ".zip" );
474- try {
475- try (FileOutputStream fos = new FileOutputStream (tempFile );
476- InputStream zis = zipFileIn .getInputStream (zipInEntry )) {
477- IOUtils .copy (zis , fos );
478- }
479- Map <String , Object > props = ContentPackageProperties .get (tempFile );
480- ContentPackageFile subPackageFile = new ContentPackageFile (tempFile ,
481- ImmutableMap .of (ContentPackagePropertiesPostProcessor .MODEL_OPTIONS_PROPERTY , props ),
482- ImmutableMap .of ("variants" , dependencyFile .getVariants ()));
483- if (StringUtils .isNoneBlank (subPackageFile .getGroup (), subPackageFile .getName (), subPackageFile .getVersion ())) {
484- dependencyFiles .add (subPackageFile );
485- }
486- }
487- finally {
488- Files .delete (tempFile .toPath ());
489- }
490- }
491- }
492- }
493- if (dependencyFiles .isEmpty ()) {
494- return null ;
495- }
496- else {
497- return dependencyFiles ;
498- }
499- }
500-
501- private static boolean isContainerPackage (@ NotNull ContentPackageFile packageFile ) {
502- return StringUtils .equals (packageFile .getPackageType (), PackageType .CONTAINER .name ().toLowerCase ());
503- }
504-
505433 private static void addSuffixToPackageName (Properties props , ContentPackageFile pkg , String environmentRunMode ) {
506434 String runModeSuffix = buildRunModeSuffix (pkg , environmentRunMode );
507435 String packageName = props .getProperty (NAME_NAME ) + runModeSuffix ;
0 commit comments