/** * Creates a default factory */ public ArtifactPluginDescriptorFactory() { this(new ServiceRegistryDescriptorLoaderRepository(new SpiServiceRegistry()), ArtifactDescriptorValidatorBuilder.builder()); }
/** * Creates an instance of the builder. * * @return a new builder instance. */ public static ArtifactDescriptorValidatorBuilder builder() { return new ArtifactDescriptorValidatorBuilder(); }
/** * Creates a new factory * * @param descriptorLoaderRepository contains all the {@link ClassLoaderModelLoader} registered on the container. Non null * @param artifactDescriptorValidatorBuilder {@link ArtifactDescriptorValidatorBuilder} to create the {@link ArtifactDescriptorValidator} in order to check the state of the descriptor once loaded. */ public AbstractArtifactDescriptorFactory(DescriptorLoaderRepository descriptorLoaderRepository, ArtifactDescriptorValidatorBuilder artifactDescriptorValidatorBuilder) { checkArgument(descriptorLoaderRepository != null, "descriptorLoaderRepository cannot be null"); this.descriptorLoaderRepository = descriptorLoaderRepository; this.artifactDescriptorValidator = artifactDescriptorValidatorBuilder .validateMinMuleVersion() .validateMuleProduct() .validateVersionFormat() .build(); }
/** * Sets a validation for minMuleVersion as {@link #validateMinMuleVersion()} but the validation should only consider * semantic version when checking the minMuleVersion vs Mule Runtime version. * * @return this */ public ArtifactDescriptorValidatorBuilder validateMinMuleVersionUsingSemanticVersion() { this.validateMinMuleVersion(); this.validateMinMuleVersionWithSemanticVersioning = true; return this; }
/** * Allows to avoid checking version format for {@link ArtifactDescriptor} that don't have a {@link BundleDescriptor}. * * @return this */ public ArtifactDescriptorValidatorBuilder doNotFailIfBundleDescriptorNotPresentWhenValidationVersionFormat() { this.validateVersionFormat(); this.doNotFailIfBundleDescriptorNotPresent = true; return this; }
/** * Creates a new factory * * @param descriptorLoaderRepository contains all the {@link ClassLoaderModelLoader} registered on the container. Non null * @param artifactDescriptorValidatorBuilder {@link ArtifactDescriptorValidatorBuilder} to create the {@link ArtifactDescriptorValidator} in order to check the state of the descriptor once loaded. */ public ServiceDescriptorFactory(DescriptorLoaderRepository descriptorLoaderRepository, ArtifactDescriptorValidatorBuilder artifactDescriptorValidatorBuilder) { super(descriptorLoaderRepository, artifactDescriptorValidatorBuilder.doNotFailIfBundleDescriptorNotPresentWhenValidationVersionFormat()); }
/** * Sets a validation for minMuleVersion as {@link #validateMinMuleVersion()} but the Mule Runtime version could * be provided as a supplier. Used by Tooling. * * @return this */ public ArtifactDescriptorValidatorBuilder validateMinMuleVersion(Supplier<String> muleRuntimeVersionSupplier) { this.validateMinMuleVersion(); this.muleRuntimeVersionSupplier = muleRuntimeVersionSupplier; return this; }
/** * Allows to avoid checking version format for {@link ArtifactDescriptor} that don't have a {@link BundleDescriptor}. * * @return this */ public ArtifactDescriptorValidatorBuilder doNotFailIfBundleDescriptorNotPresentWhenValidationVersionFormat() { this.validateVersionFormat(); this.doNotFailIfBundleDescriptorNotPresent = true; return this; }
/** * Creates a new factory * * @param descriptorLoaderRepository contains all the {@link ClassLoaderModelLoader} registered on the container. Non null * @param artifactDescriptorValidatorBuilder {@link ArtifactDescriptorValidatorBuilder} to create the {@link ArtifactDescriptorValidator} in order to check the state of the descriptor once loaded. */ public ServiceDescriptorFactory(DescriptorLoaderRepository descriptorLoaderRepository, ArtifactDescriptorValidatorBuilder artifactDescriptorValidatorBuilder) { super(descriptorLoaderRepository, artifactDescriptorValidatorBuilder.doNotFailIfBundleDescriptorNotPresentWhenValidationVersionFormat()); }
@Test public void discoversNoServices() throws Exception { final FileSystemServiceProviderDiscoverer serviceProviderDiscoverer = new FileSystemServiceProviderDiscoverer(containerClassLoader, serviceClassLoaderFactory, descriptorLoaderRepository, builder()); final List<ServiceAssembly> discover = serviceProviderDiscoverer.discover(); assertThat(discover, is(empty())); }
/** * Creates a new factory * * @param descriptorLoaderRepository contains all the {@link ClassLoaderModelLoader} registered on the container. Non null * @param artifactDescriptorValidatorBuilder {@link ArtifactDescriptorValidatorBuilder} to create the {@link ArtifactDescriptorValidator} in order to check the state of the descriptor once loaded. */ public AbstractArtifactDescriptorFactory(DescriptorLoaderRepository descriptorLoaderRepository, ArtifactDescriptorValidatorBuilder artifactDescriptorValidatorBuilder) { checkArgument(descriptorLoaderRepository != null, "descriptorLoaderRepository cannot be null"); this.descriptorLoaderRepository = descriptorLoaderRepository; this.artifactDescriptorValidator = artifactDescriptorValidatorBuilder .validateMinMuleVersion() .validateMuleProduct() .validateVersionFormat() .build(); }
/** * Sets a validation for minMuleVersion as {@link #validateMinMuleVersion()} but the Mule Runtime version could * be provided as a supplier. Used by Tooling. * * @return this */ public ArtifactDescriptorValidatorBuilder validateMinMuleVersion(Supplier<String> muleRuntimeVersionSupplier) { this.validateMinMuleVersion(); this.muleRuntimeVersionSupplier = muleRuntimeVersionSupplier; return this; }
/** * Creates an instance of the builder. * * @return a new builder instance. */ public static ArtifactDescriptorValidatorBuilder builder() { return new ArtifactDescriptorValidatorBuilder(); }
/** * Creates a default factory */ @SuppressWarnings({"unused"}) public PolicyTemplateDescriptorFactory() { this(new ArtifactPluginDescriptorLoader(new ArtifactPluginDescriptorFactory()), new ServiceRegistryDescriptorLoaderRepository(new SpiServiceRegistry()), ArtifactDescriptorValidatorBuilder.builder()); }
/** * Sets a validation for minMuleVersion as {@link #validateMinMuleVersion()} but the validation should only consider * semantic version when checking the minMuleVersion vs Mule Runtime version. * * @return this */ public ArtifactDescriptorValidatorBuilder validateMinMuleVersionUsingSemanticVersion() { this.validateMinMuleVersion(); this.validateMinMuleVersionWithSemanticVersioning = true; return this; }
@Before public void setUp() throws Exception { BundleDescriptorLoader bundleDescriptorLoaderMock = mock(BundleDescriptorLoader.class); when(bundleDescriptorLoaderMock.supportsArtifactType(ArtifactType.SERVICE)).thenReturn(true); when(bundleDescriptorLoaderMock.load(Mockito.any(File.class), Mockito.any(Map.class), eq(ArtifactType.SERVICE))) .thenReturn(new BundleDescriptor.Builder() .setGroupId("mockGroupId") .setArtifactId("mockArtifactId") .setVersion("1.0.0") .setClassifier("mule-service") .setType("jar") .build()); when(descriptorLoaderRepository.get(anyString(), anyObject(), argThat(equalTo(BundleDescriptorLoader.class)))) .thenReturn(bundleDescriptorLoaderMock); when(descriptorLoaderRepository.get(anyString(), anyObject(), argThat(equalTo(ClassLoaderModelLoader.class)))) .thenReturn(mock(ClassLoaderModelLoader.class)); doNothing().when(artifactDescriptorValidator).validate(anyObject()); serviceDescriptorFactory = new ServiceDescriptorFactory(descriptorLoaderRepository, builder()); }
@Test public void discoversServices() throws Exception { installService("fooService", FooServiceProvider.class); installService("barService", BarServiceProvider.class); ArtifactClassLoader serviceClassLoader = mock(ArtifactClassLoader.class); when(serviceClassLoaderFactory.create(argThat(any(String.class)), argThat(any(ServiceDescriptor.class)), argThat(any(ClassLoader.class)), argThat(any( ClassLoaderLookupPolicy.class)))) .thenReturn(serviceClassLoader); final FileSystemServiceProviderDiscoverer serviceProviderDiscoverer = new FileSystemServiceProviderDiscoverer(containerClassLoader, serviceClassLoaderFactory, descriptorLoaderRepository, builder()); final List<ServiceAssembly> assemblies = serviceProviderDiscoverer.discover(); assertThat(assemblies.size(), equalTo(2)); assertThat(FooServiceProvider.INVOKED, is(false)); assertThat(BarServiceProvider.INVOKED, is(false)); assemblies.forEach(l -> l.getServiceProvider().getServiceDefinition()); assertThat(FooServiceProvider.INVOKED, is(true)); assertThat(BarServiceProvider.INVOKED, is(true)); }
@Test public void verifiesThatPolicyDescriptorIsPresent() throws Exception { PolicyFileBuilder policyFileBuilder = new PolicyFileBuilder(POLICY_NAME).usingLibrary(echoTestJarFile.getAbsolutePath()); File tempFolder = createTempFolder(); unzip(policyFileBuilder.getArtifactFile(), tempFolder); PolicyTemplateDescriptorFactory descriptorFactory = new PolicyTemplateDescriptorFactory(artifactPluginDescriptorLoader, descriptorLoaderRepository, ArtifactDescriptorValidatorBuilder.builder()); expectedException.expect(ArtifactDescriptorCreateException.class); expectedException.expectMessage(allOf(containsString(ARTIFACT_DESCRIPTOR_DOES_NOT_EXISTS_ERROR), containsString(MULE_ARTIFACT_JSON_DESCRIPTOR_LOCATION))); descriptorFactory.create(tempFolder, empty()); }
@Before public void setUp() throws Exception { when(classLoaderFilterFactory.create(null, null)) .thenReturn(NULL_CLASSLOADER_FILTER); when(descriptorLoaderRepository.get(MULE_LOADER_ID, PLUGIN, ClassLoaderModelLoader.class)) .thenReturn(new PluginMavenClassLoaderModelLoader(mavenClientProvider.createMavenClient( newMavenConfigurationBuilder() .localMavenRepositoryLocation(mavenClientProvider .getLocalRepositorySuppliers() .environmentMavenRepositorySupplier() .get()) .build()))); when(descriptorLoaderRepository.get(FILE_SYSTEM_POLICY_MODEL_LOADER_ID, PLUGIN, ClassLoaderModelLoader.class)) .thenReturn(new FileSystemPolicyClassLoaderModelLoader()); when(descriptorLoaderRepository.get(INVALID_LOADER_ID, PLUGIN, ClassLoaderModelLoader.class)) .thenThrow(new LoaderNotFoundException(INVALID_LOADER_ID)); when(descriptorLoaderRepository.get(PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID, PLUGIN, BundleDescriptorLoader.class)) .thenReturn(new PropertiesBundleDescriptorLoader()); when(descriptorLoaderRepository.get(INVALID_LOADER_ID, PLUGIN, BundleDescriptorLoader.class)) .thenThrow(new LoaderNotFoundException(INVALID_LOADER_ID)); descriptorFactory = new ArtifactPluginDescriptorFactory(descriptorLoaderRepository, ArtifactDescriptorValidatorBuilder.builder()); }
.getArtifactPluginDescriptorLoader(), createDescriptorLoaderRepository(), ArtifactDescriptorValidatorBuilder.builder()));