@Override public final D scan(I container, String path, Scope scope, Scanner scanner) throws IOException { ScannerContext context = scanner.getContext(); D containerDescriptor = getContainerDescriptor(container, context); String containerPath = getContainerPath(container, path); containerDescriptor.setFileName(containerPath); LOGGER.info("Entering {}", containerPath); ContainerFileResolver fileResolverStrategy = new ContainerFileResolver(containerDescriptor); context.push(FileResolver.class, fileResolverStrategy); enterContainer(container, containerDescriptor, scanner.getContext()); Stopwatch stopwatch = Stopwatch.createStarted(); try { Iterable<? extends E> entries = getEntries(container); for (E entry : entries) { String relativePath = getRelativePath(container, entry); try (Resource resource = getEntry(container, entry)) { LOGGER.debug("Scanning {}", relativePath); FileDescriptor descriptor = scanner.scan(resource, relativePath, scope); fileResolverStrategy.put(relativePath, descriptor); } } } finally { leaveContainer(container, containerDescriptor, scanner.getContext()); context.pop(FileResolver.class); } fileResolverStrategy.flush(); LOGGER.info( "Leaving {} ({} entries, {} ms)", containerPath, fileResolverStrategy.size(), stopwatch.elapsed(MILLISECONDS)); return containerDescriptor; }
@Override public FileDescriptor scan(VirtualFile item, String path, Scope scope, Scanner scanner) throws IOException { Persistence persistence; try (InputStream stream = item.createStream()) { Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); persistence = unmarshaller.unmarshal(new StreamSource(stream), Persistence.class).getValue(); } catch (JAXBException e) { throw new IOException("Cannot read model descriptor.", e); } Store store = scanner.getContext().getStore(); PersistenceDescriptor persistenceDescriptor = store.create(PersistenceDescriptor.class); persistenceDescriptor.setVersion(persistence.getVersion()); // Create model units for (PersistenceUnit persistenceUnit : persistence.getPersistenceUnit()) { PersistenceUnitDescriptor persistenceUnitDescriptor = store.create(PersistenceUnitDescriptor.class); persistenceUnitDescriptor.setName(persistenceUnit.getName()); PersistenceUnitTransactionType transactionType = persistenceUnit.getTransactionType(); if (transactionType != null) { persistenceUnitDescriptor.setTransactionType(transactionType.name()); } persistenceUnitDescriptor.setDescription(persistenceUnit.getDescription()); persistenceUnitDescriptor.setJtaDataSource(persistenceUnit.getJtaDataSource()); persistenceUnitDescriptor.setNonJtaDataSource(persistenceUnit.getNonJtaDataSource()); persistenceUnitDescriptor.setProvider(persistenceUnit.getProvider()); PersistenceUnitValidationModeType validationMode = persistenceUnit.getValidationMode(); if (validationMode != null) { persistenceUnitDescriptor.setValidationMode(validationMode.name()); } PersistenceUnitCachingType sharedCacheMode = persistenceUnit.getSharedCacheMode(); if (sharedCacheMode != null) { persistenceUnitDescriptor.setSharedCacheMode(sharedCacheMode.name()); } for (String clazz : persistenceUnit.getClazz()) { TypeDescriptor typeDescriptor = descriptorResolverFactory .getTypeDescriptorResolver() .resolve(clazz, scanner.getContext()); persistenceUnitDescriptor.getContains().add(typeDescriptor); } // Create persistence unit properties PersistenceUnit.Properties properties = persistenceUnit.getProperties(); if (properties != null) { for (Property property : properties.getProperty()) { PropertyDescriptor propertyDescriptor = store.create(PropertyDescriptor.class); propertyDescriptor.setName(property.getName()); propertyDescriptor.setValue(property.getValue()); persistenceUnitDescriptor.getProperties().add(propertyDescriptor); } } // Add model unit to model descriptor persistenceDescriptor.getContains().add(persistenceUnitDescriptor); } return persistenceDescriptor; }
/** * Create the descriptor and set base information. * * @param model The model. * @param scanner The scanner. * @return The descriptor. */ protected MavenPomDescriptor createMavenPomDescriptor(Model model, Scanner scanner) { ScannerContext context = scanner.getContext(); MavenPomDescriptor pomDescriptor = context.peek(MavenPomDescriptor.class); pomDescriptor.setName(model.getName()); pomDescriptor.setGroupId(model.getGroupId()); pomDescriptor.setArtifactId(model.getArtifactId()); pomDescriptor.setPackaging(model.getPackaging()); pomDescriptor.setVersion(model.getVersion()); String pomFqn = getFullyQualifiedName(model); pomDescriptor.setFullQualifiedName(pomFqn); Coordinates artifactCoordinates = new ModelCoordinates(model); MavenArtifactDescriptor artifact = getArtifactResolver(context).resolve(artifactCoordinates, context); // if the pom describes itself as artifact then the returned artifact // descriptor must be used as pom descriptor (the old instance is // invalidated due to adding labels) if (MavenPomDescriptor.class.isAssignableFrom(artifact.getClass())) { pomDescriptor = MavenPomDescriptor.class.cast(artifact); } pomDescriptor.getDescribes().add(artifact); return pomDescriptor; }
/** {@inheritDoc} */ @Override public MavenPomDescriptor scan(Model model, String path, Scope scope, Scanner scanner) throws IOException { MavenPomDescriptor pomDescriptor = createMavenPomDescriptor(model, scanner); ScannerContext scannerContext = scanner.getContext(); Store store = scannerContext.getStore(); addParent(pomDescriptor, model, scannerContext); addProfiles(pomDescriptor, model, scannerContext); addProperties(pomDescriptor, model.getProperties(), store); addModules(pomDescriptor, model.getModules(), store); addManagedDependencies( pomDescriptor, model.getDependencyManagement(), scannerContext, PomManagesDependencyDescriptor.class); addDependencies( pomDescriptor, model.getDependencies(), PomDependsOnDescriptor.class, scannerContext); addManagedPlugins(pomDescriptor, model.getBuild(), scannerContext); addPlugins(pomDescriptor, model.getBuild(), scannerContext); addLicenses(pomDescriptor, model, store); return pomDescriptor; }
@Override public TestDescriptor1 scan(TestItem item, String path, Scope scope, Scanner scanner) throws IOException { return scanner.getContext().getStore().create(TestDescriptor1.class); }