@Test public void setBuilderWithDefaultExportedResourcesValueOnlyTestResourcesTest() throws IOException { MuleArtifactContentResolver resolverMock = mock(MuleArtifactContentResolver.class); List<String> exportedResources = new ArrayList<>(); List<String> testExportedResources = new ArrayList<>(); testExportedResources.add(JAR_4); testExportedResources.add(JAR_5); testExportedResources.add(JAR_6); when(resolverMock.getExportedResources()).thenReturn(exportedResources); when(resolverMock.getTestExportedResources()).thenReturn(testExportedResources); generator.setBuilderWithDefaultExportedResourcesValue(defaultBuilder, muleArtifact, resolverMock); assertThat("Exported resources are not the expected", (List<String>) defaultBuilder.build().getClassLoaderModelLoaderDescriptor().getAttributes() .get("exportedResources"), containsInAnyOrder(JAR_4, JAR_5, JAR_6)); }
@Override protected void setBuilderWithDefaultExportedResourcesValue(MuleApplicationModel.MuleApplicationModelBuilder builder, MuleApplicationModel originalMuleArtifact, MuleArtifactContentResolver muleArtifactContentResolver) throws IOException { MuleArtifactLoaderDescriptor classLoaderModelLoaderDescriptor; if (originalMuleArtifact.getClassLoaderModelLoaderDescriptor() != null) { Map<String, Object> originalAttributes = originalMuleArtifact.getClassLoaderModelLoaderDescriptor().getAttributes(); List<String> exportedResources = new ArrayList<>(); if (originalAttributes != null && originalAttributes.get("exportedResources") != null) { exportedResources.addAll((Collection<String>) originalAttributes.get("exportedResources")); } else { exportedResources.addAll(muleArtifactContentResolver.getExportedResources()); } exportedResources.addAll(muleArtifactContentResolver.getTestExportedResources()); Map<String, Object> attributesCopy = getUpdatedAttributes(originalMuleArtifact.getClassLoaderModelLoaderDescriptor(), "exportedResources", new ArrayList<>(exportedResources)); classLoaderModelLoaderDescriptor = new MuleArtifactLoaderDescriptor(originalMuleArtifact.getClassLoaderModelLoaderDescriptor().getId(), attributesCopy); } else { Path outputDirectory = muleArtifactContentResolver.getProjectStructure().getOutputDirectory(); List<Path> allOutputFiles = Files.walk(outputDirectory) .filter(path -> Files.isRegularFile(path)) .collect(toList()); Predicate<Path> isJavaClass = path -> FilenameUtils.getExtension(path.toString()).endsWith(COMPILED_JAVA_EXTENSION); List<String> packagesFolders = allOutputFiles.stream() .filter(isJavaClass) .map(path -> { Path parent = outputDirectory.relativize(path).getParent(); return parent != null ? parent.toString() : DEFAULT_PACKAGE_EXPORT; }) .map(MuleArtifactContentResolver::escapeSlashes) .map(s -> s.replace(CLASS_PATH_SEPARATOR, PACKAGE_SEPARATOR)) .distinct() .collect(Collectors.toList()); List<String> muleConfigs = muleArtifactContentResolver.getConfigs(); List<String> resources = allOutputFiles.stream() .filter(isJavaClass.negate()) .map(path -> outputDirectory.relativize(path)) .map(Path::toString) .map(MuleArtifactContentResolver::escapeSlashes) .collect(toList()); resources.addAll(muleArtifactContentResolver.getTestExportedResources()); classLoaderModelLoaderDescriptor = new MuleArtifactLoaderDescriptorBuilder() .setId(MULE_ID) .addProperty(EXPORTED_PACKAGES, packagesFolders) .addProperty(EXPORTED_RESOURCES, resources).build(); } builder.withClassLoaderModelDescriptorLoader(classLoaderModelLoaderDescriptor); }
DefaultValuesMuleArtifactJsonGenerator extends AbstractDefaultValuesMuleArtifactJsonGenerator { @Override protected void setBuilderWithDefaultExportedResourcesValue(MuleApplicationModel.MuleApplicationModelBuilder builder, MuleApplicationModel originalMuleArtifact, MuleArtifactContentResolver muleArtifactContentResolver) throws IOException { MuleArtifactLoaderDescriptor classLoaderModelLoaderDescriptor; if (originalMuleArtifact.getClassLoaderModelLoaderDescriptor() != null) { Map<String, Object> originalAttributes = originalMuleArtifact.getClassLoaderModelLoaderDescriptor().getAttributes(); List<String> exportedResources = new ArrayList<>(); if (originalAttributes != null && originalAttributes.get("exportedResources") != null) { exportedResources.addAll((Collection<String>) originalAttributes.get("exportedResources")); } else { exportedResources.addAll(muleArtifactContentResolver.getExportedResources()); } exportedResources.addAll(muleArtifactContentResolver.getTestExportedResources()); Map<String, Object> attributesCopy = getUpdatedAttributes(originalMuleArtifact.getClassLoaderModelLoaderDescriptor(), "exportedResources", new ArrayList<>(exportedResources)); classLoaderModelLoaderDescriptor = new MuleArtifactLoaderDescriptor(originalMuleArtifact.getClassLoaderModelLoaderDescriptor().getId(), attributesCopy); } else { Path outputDirectory = muleArtifactContentResolver.getProjectStructure().getOutputDirectory(); List<Path> allOutputFiles = Files.walk(outputDirectory) .filter(path -> Files.isRegularFile(path)) .collect(toList()); Predicate<Path> isJavaClass = path -> FilenameUtils.getExtension(path.toString()).endsWith(COMPILED_JAVA_EXTENSION); List<String> packagesFolders = allOutputFiles.stream() .filter(isJavaClass) .map(path -> { Path parent = outputDirectory.relativize(path).getParent(); return parent != null ? parent.toString() : DEFAULT_PACKAGE_EXPORT; }) .map(MuleArtifactContentResolver::escapeSlashes) .map(s -> s.replace(CLASS_PATH_SEPARATOR, PACKAGE_SEPARATOR)) .distinct() .collect(Collectors.toList()); List<String> muleConfigs = muleArtifactContentResolver.getConfigs(); List<String> resources = allOutputFiles.stream() .filter(isJavaClass.negate()) .map(path -> outputDirectory.relativize(path)) .map(Path::toString) .map(MuleArtifactContentResolver::escapeSlashes) .collect(toList()); resources.addAll(muleArtifactContentResolver.getTestExportedResources()); classLoaderModelLoaderDescriptor = new MuleArtifactLoaderDescriptorBuilder() .setId(MULE_ID) .addProperty(EXPORTED_PACKAGES, packagesFolders) .addProperty(EXPORTED_RESOURCES, resources).build(); } builder.withClassLoaderModelDescriptorLoader(classLoaderModelLoaderDescriptor); } }
DefaultValuesMuleArtifactJsonGenerator extends AbstractDefaultValuesMuleArtifactJsonGenerator { @Override protected void setBuilderWithDefaultExportedResourcesValue(MuleApplicationModel.MuleApplicationModelBuilder builder, MuleApplicationModel originalMuleArtifact, MuleArtifactContentResolver muleArtifactContentResolver) throws IOException { MuleArtifactLoaderDescriptor classLoaderModelLoaderDescriptor; if (originalMuleArtifact.getClassLoaderModelLoaderDescriptor() != null) { Map<String, Object> originalAttributes = originalMuleArtifact.getClassLoaderModelLoaderDescriptor().getAttributes(); List<String> exportedResources = new ArrayList<>(); if (originalAttributes != null && originalAttributes.get("exportedResources") != null) { exportedResources.addAll((Collection<String>) originalAttributes.get("exportedResources")); } else { exportedResources.addAll(muleArtifactContentResolver.getExportedResources()); } exportedResources.addAll(muleArtifactContentResolver.getTestExportedResources()); Map<String, Object> attributesCopy = getUpdatedAttributes(originalMuleArtifact.getClassLoaderModelLoaderDescriptor(), "exportedResources", new ArrayList<>(exportedResources)); classLoaderModelLoaderDescriptor = new MuleArtifactLoaderDescriptor(originalMuleArtifact.getClassLoaderModelLoaderDescriptor().getId(), attributesCopy); } else { Path outputDirectory = muleArtifactContentResolver.getProjectStructure().getOutputDirectory(); List<Path> allOutputFiles = Files.walk(outputDirectory) .filter(path -> Files.isRegularFile(path)) .collect(toList()); Predicate<Path> isJavaClass = path -> FilenameUtils.getExtension(path.toString()).endsWith(COMPILED_JAVA_EXTENSION); List<String> packagesFolders = allOutputFiles.stream() .filter(isJavaClass) .map(path -> { Path parent = outputDirectory.relativize(path).getParent(); return parent != null ? parent.toString() : DEFAULT_PACKAGE_EXPORT; }) .map(MuleArtifactContentResolver::escapeSlashes) .map(s -> s.replace(CLASS_PATH_SEPARATOR, PACKAGE_SEPARATOR)) .distinct() .collect(Collectors.toList()); List<String> muleConfigs = muleArtifactContentResolver.getConfigs(); List<String> resources = allOutputFiles.stream() .filter(isJavaClass.negate()) .map(path -> outputDirectory.relativize(path)) .map(Path::toString) .map(MuleArtifactContentResolver::escapeSlashes) .collect(toList()); resources.addAll(muleArtifactContentResolver.getTestExportedResources()); classLoaderModelLoaderDescriptor = new MuleArtifactLoaderDescriptorBuilder() .setId(MULE_ID) .addProperty(EXPORTED_PACKAGES, packagesFolders) .addProperty(EXPORTED_RESOURCES, resources).build(); } builder.withClassLoaderModelDescriptorLoader(classLoaderModelLoaderDescriptor); }  }
DefaultValuesMuleArtifactJsonGenerator extends AbstractDefaultValuesMuleArtifactJsonGenerator { @Override protected void setBuilderWithDefaultExportedResourcesValue(MuleApplicationModel.MuleApplicationModelBuilder builder, MuleApplicationModel originalMuleArtifact, MuleArtifactContentResolver muleArtifactContentResolver) throws IOException { MuleArtifactLoaderDescriptor classLoaderModelLoaderDescriptor; if (originalMuleArtifact.getClassLoaderModelLoaderDescriptor() != null) { Map<String, Object> originalAttributes = originalMuleArtifact.getClassLoaderModelLoaderDescriptor().getAttributes(); List<String> exportedResources = new ArrayList<>(); if (originalAttributes != null && originalAttributes.get("exportedResources") != null) { exportedResources.addAll((Collection<String>) originalAttributes.get("exportedResources")); } else { exportedResources.addAll(muleArtifactContentResolver.getExportedResources()); } exportedResources.addAll(muleArtifactContentResolver.getTestExportedResources()); Map<String, Object> attributesCopy = getUpdatedAttributes(originalMuleArtifact.getClassLoaderModelLoaderDescriptor(), "exportedResources", new ArrayList<>(exportedResources)); classLoaderModelLoaderDescriptor = new MuleArtifactLoaderDescriptor(originalMuleArtifact.getClassLoaderModelLoaderDescriptor().getId(), attributesCopy); } else { Path outputDirectory = muleArtifactContentResolver.getProjectStructure().getOutputDirectory(); List<Path> allOutputFiles = Files.walk(outputDirectory) .filter(path -> Files.isRegularFile(path)) .collect(toList()); Predicate<Path> isJavaClass = path -> FilenameUtils.getExtension(path.toString()).endsWith(COMPILED_JAVA_EXTENSION); List<String> packagesFolders = allOutputFiles.stream() .filter(isJavaClass) .map(path -> { Path parent = outputDirectory.relativize(path).getParent(); return parent != null ? parent.toString() : DEFAULT_PACKAGE_EXPORT; }) .map(MuleArtifactContentResolver::escapeSlashes) .map(s -> s.replace(CLASS_PATH_SEPARATOR, PACKAGE_SEPARATOR)) .distinct() .collect(Collectors.toList()); List<String> muleConfigs = muleArtifactContentResolver.getConfigs(); List<String> resources = allOutputFiles.stream() .filter(isJavaClass.negate()) .map(path -> outputDirectory.relativize(path)) .map(Path::toString) .map(MuleArtifactContentResolver::escapeSlashes) .collect(toList()); resources.addAll(muleArtifactContentResolver.getTestExportedResources()); classLoaderModelLoaderDescriptor = new MuleArtifactLoaderDescriptorBuilder() .setId(MULE_ID) .addProperty(EXPORTED_PACKAGES, packagesFolders) .addProperty(EXPORTED_RESOURCES, resources).build(); } builder.withClassLoaderModelDescriptorLoader(classLoaderModelLoaderDescriptor); }   }
DefaultValuesMuleArtifactJsonGenerator extends AbstractDefaultValuesMuleArtifactJsonGenerator { @Override protected void setBuilderWithDefaultExportedResourcesValue(MuleApplicationModel.MuleApplicationModelBuilder builder, MuleApplicationModel originalMuleArtifact, MuleArtifactContentResolver muleArtifactContentResolver) throws IOException { MuleArtifactLoaderDescriptor classLoaderModelLoaderDescriptor; if (originalMuleArtifact.getClassLoaderModelLoaderDescriptor() != null) { Map<String, Object> originalAttributes = originalMuleArtifact.getClassLoaderModelLoaderDescriptor().getAttributes(); List<String> exportedResources = new ArrayList<>(); if (originalAttributes != null && originalAttributes.get("exportedResources") != null) { exportedResources.addAll((Collection<String>) originalAttributes.get("exportedResources")); } else { exportedResources.addAll(muleArtifactContentResolver.getExportedResources()); } exportedResources.addAll(muleArtifactContentResolver.getTestExportedResources()); Map<String, Object> attributesCopy = getUpdatedAttributes(originalMuleArtifact.getClassLoaderModelLoaderDescriptor(), "exportedResources", new ArrayList<>(exportedResources)); classLoaderModelLoaderDescriptor = new MuleArtifactLoaderDescriptor(originalMuleArtifact.getClassLoaderModelLoaderDescriptor().getId(), attributesCopy); } else { Path outputDirectory = muleArtifactContentResolver.getProjectStructure().getOutputDirectory(); List<Path> allOutputFiles = Files.walk(outputDirectory) .filter(path -> Files.isRegularFile(path)) .collect(toList()); Predicate<Path> isJavaClass = path -> FilenameUtils.getExtension(path.toString()).endsWith(COMPILED_JAVA_EXTENSION); List<String> packagesFolders = allOutputFiles.stream() .filter(isJavaClass) .map(path -> { Path parent = outputDirectory.relativize(path).getParent(); return parent != null ? parent.toString() : DEFAULT_PACKAGE_EXPORT; }) .map(MuleArtifactContentResolver::escapeSlashes) .map(s -> s.replace(CLASS_PATH_SEPARATOR, PACKAGE_SEPARATOR)) .distinct() .collect(Collectors.toList()); List<String> muleConfigs = muleArtifactContentResolver.getConfigs(); List<String> resources = allOutputFiles.stream() .filter(isJavaClass.negate()) .map(path -> outputDirectory.relativize(path)) .map(Path::toString) .map(MuleArtifactContentResolver::escapeSlashes) .collect(toList()); resources.addAll(muleArtifactContentResolver.getTestExportedResources()); classLoaderModelLoaderDescriptor = new MuleArtifactLoaderDescriptorBuilder() .setId(MULE_ID) .addProperty(EXPORTED_PACKAGES, packagesFolders) .addProperty(EXPORTED_RESOURCES, resources).build(); } builder.withClassLoaderModelDescriptorLoader(classLoaderModelLoaderDescriptor); }   static final String EXPORTED_PACKAGES; static final String EXPORTED_RESOURCES; static final String DEFAULT_PACKAGE_EXPORT; static final String COMPILED_JAVA_EXTENSION; static final String PACKAGE_SEPARATOR; }