DefaultManifestReader implements ManifestReader { @Override public PluginMetadata read(Path pluginFile) throws PluginException { try { Manifest manifest = getManifest(pluginFile); PluginMetadataContainer pluginMetadata = new PluginMetadataContainer( getRequiredField(manifest, ManifestField.NAME), getRequiredField(manifest, ManifestField.VERSION), pluginFile ); pluginMetadata.setDate(getDateField(manifest, ManifestField.DATE)); pluginMetadata.setDescription(getField(manifest, ManifestField.DESCRIPTION)); pluginMetadata.setMaintainer(getField(manifest, ManifestField.MAINTAINER)); pluginMetadata.addRequiredDependencies(getDependenciesList(manifest, ManifestField.DEPENDS)); pluginMetadata.addConflictingDependencies(getDependenciesList(manifest, ManifestField.CONFLICTS)); String rawProvides = getField(manifest, ManifestField.PROVIDES); if (rawProvides != null) { pluginMetadata.setProvidedDependency(getDependency(rawProvides)); } return pluginMetadata; } catch (Exception e) { throw new PluginException("Invalid manifest in plugin file " + pluginFile.toAbsolutePath(), e); } }  @Override PluginMetadata read(Path pluginFile); static final String DEPENDENCY_DELIMITER; static final String VERSION_DELIMITER; static final DateTimeFormatter DATE_FORMATTER; }
@Test public void testRead() throws PluginException { final Path FILE = Paths.get("missing-file"); PluginMetadata pluginMetadata = read(FILE); assertThat(pluginMetadata.getName(), equalTo(NAME)); assertThat(pluginMetadata.getVersion(), equalTo(VERSION)); assertThat(pluginMetadata.getDate(), equalTo(Optional.of(ZonedDateTime.parse(DATE)))); assertThat(pluginMetadata.getDescription(), equalTo(Optional.of(DESCRIPTION))); assertThat(pluginMetadata.getMaintainer(), equalTo(Optional.of(MAINTAINER))); assertThat(pluginMetadata.getDependency(), equalTo(new DependencyContainer(NAME, VERSION))); assertThat(pluginMetadata.getPath(), equalTo(FILE)); List<Dependency> requiredDependencies = pluginMetadata.getRequiredDependencies(); assertThat(requiredDependencies, hasSize(2)); Dependency requiredDependency1 = new DependencyContainer("some-plugin"); Dependency requiredDependency2 = new DependencyContainer("another-plugin", "[0.9,)"); assertThat(requiredDependencies, contains(requiredDependency1, requiredDependency2)); List<Dependency> conflictingDependencies = pluginMetadata.getConflictingDependencies(); assertThat(conflictingDependencies, hasSize(2)); Dependency conflictingDependency1 = new DependencyContainer("some-conflicting-plugin", "(,1.0]"); Dependency conflictingDependency2 = new DependencyContainer("another-conflicting-plugin", "[1.1,1.2]"); assertThat(conflictingDependencies, contains(conflictingDependency1, conflictingDependency2)); Dependency provided = new DependencyContainer(PROVIDES); assertThat(pluginMetadata.getProvidedDependency(), equalTo(Optional.of(provided))); }