org.apache.maven.artifact.versioning.VersionRange Java Examples
The following examples show how to use
org.apache.maven.artifact.versioning.VersionRange.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NativeRanlibMojoTest.java From maven-native with MIT License | 6 votes |
public void testMojoLookup() throws Exception { File pluginXml = new File( getBasedir(), "src/test/resources/linker/plugin-config-ranlib.xml" ); NativeRanlibMojo mojo = (NativeRanlibMojo) lookupMojo( "ranlib", pluginXml ); assertNotNull( mojo ); // simulate artifact ArtifactHandler artifactHandler = new DefaultArtifactHandler(); Artifact artifact = new DefaultArtifact( "test", "test", VersionRange.createFromVersion( "1.0-SNAPSHOT" ), "compile", "exe", null, artifactHandler ); mojo.getProject().setArtifact( artifact ); mojo.execute(); }
Example #2
Source File: LockSnapshotsMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
/** * Determine the timestamp version of the snapshot dependency used in the build. * * @param dep * @return The timestamp version if exists, otherwise the original snapshot dependency version is returned. */ private String resolveSnapshotVersion( Dependency dep ) { getLog().debug( "Resolving snapshot version for dependency: " + dep ); String lockedVersion = dep.getVersion(); try { Artifact depArtifact = artifactFactory.createDependencyArtifact( dep.getGroupId(), dep.getArtifactId(), VersionRange.createFromVersionSpec( dep.getVersion() ), dep.getType(), dep.getClassifier(), dep.getScope() ); resolver.resolve( depArtifact, getProject().getRemoteArtifactRepositories(), localRepository ); lockedVersion = depArtifact.getVersion(); } catch ( Exception e ) { getLog().error( e ); } return lockedVersion; }
Example #3
Source File: AbstractVersionsReport.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
/** * Finds the latest version of the specified artifact that matches the version range. * * @param artifact The artifact. * @param versionRange The version range. * @param allowingSnapshots <code>null</code> for no override, otherwise the local override to apply. * @param usePluginRepositories Use plugin repositories * @return The latest version of the specified artifact that matches the specified version range or * <code>null</code> if no matching version could be found. * @throws MavenReportException If the artifact metadata could not be found. * @since 1.0-alpha-1 */ protected ArtifactVersion findLatestVersion( Artifact artifact, VersionRange versionRange, boolean allowingSnapshots, boolean usePluginRepositories ) throws MavenReportException { boolean includeSnapshots = this.allowSnapshots; if ( allowingSnapshots ) { includeSnapshots = true; } if ( allowingSnapshots ) { includeSnapshots = false; } try { final ArtifactVersions artifactVersions = getHelper().lookupArtifactVersions( artifact, usePluginRepositories ); return artifactVersions.getNewestVersion( versionRange, includeSnapshots ); } catch ( ArtifactMetadataRetrievalException e ) { throw new MavenReportException( e.getMessage(), e ); } }
Example #4
Source File: DataflowDependencyManager.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
/** * Returns the encoded version range from the given project's POM, or {@code null} if no version * is specified. * * @return the version range or {@code null} if a version range is not specified * @throws IllegalStateException if the encoded version range is not a valid version specification */ private VersionRange getActualDataflowVersionRange(IProject project) { Model model = getModelFromProject(project); if (model != null) { Dependency dependency = getDataflowDependencyFromModel(model); if (dependency != null) { String version = dependency.getVersion(); if (!Strings.isNullOrEmpty(version)) { try { return VersionRange.createFromVersionSpec(version); } catch (InvalidVersionSpecificationException ex) { String message = String.format("Could not create version range from existing version %s", version); throw new IllegalStateException(message, ex); } } } } return null; }
Example #5
Source File: UseLatestReleasesMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
private ArtifactVersion[] filterVersionsWithIncludes( ArtifactVersion[] newer, Artifact artifact ) { List<ArtifactVersion> filteredNewer = new ArrayList<>( newer.length ); for ( int j = 0; j < newer.length; j++ ) { ArtifactVersion artifactVersion = newer[j]; Artifact artefactWithNewVersion = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), VersionRange.createFromVersion( artifactVersion.toString() ), artifact.getScope(), artifact.getType(), null, new DefaultArtifactHandler(), false ); if ( isIncluded( artefactWithNewVersion ) ) { filteredNewer.add( artifactVersion ); } } return filteredNewer.toArray( new ArtifactVersion[filteredNewer.size()] ); }
Example #6
Source File: TomEEEmbeddedMojo.java From tomee with Apache License 2.0 | 6 votes |
private File mvnToFile(final String lib) throws Exception { final String[] infos = lib.split(":"); final String classifier; final String type; if (infos.length < 3) { throw new MojoExecutionException("format for librairies should be <groupId>:<artifactId>:<version>[:<type>[:<classifier>]]"); } if (infos.length >= 4) { type = infos[3]; } else { type = "war"; } if (infos.length == 5) { classifier = infos[4]; } else { classifier = null; } final Artifact artifact = factory.createDependencyArtifact(infos[0], infos[1], VersionRange.createFromVersion(infos[2]), type, classifier, "compile"); resolver.resolve(artifact, remoteRepos, local); return artifact.getFile(); }
Example #7
Source File: DataflowMavenModel.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
/** * Sets the Dataflow Dependency of this model to the [current latest version, next major version). */ public void pinDataflowDependencyToCurrent(IProgressMonitor monitor) throws CoreException { try { VersionRange existingVersionRange = dependencyManager.getDataflowVersionRange(project); ArtifactVersion version = dependencyManager.getLatestDataflowDependencyInRange(existingVersionRange); VersionRange newRange = MajorVersion.truncateAtLatest(version, existingVersionRange); editPom(new SetDataflowDependencyVersion(newRange)); } catch (IOException e) { throw new CoreException( new Status( Status.ERROR, DataflowCorePlugin.PLUGIN_ID, "Exception when trying to pin Dataflow Dependency", e)); } finally { monitor.done(); } }
Example #8
Source File: ArtifactVersionsTest.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
@Test public void testSmokes() throws Exception { ArtifactVersion[] versions = versions( "1.0", "3.0", "1.1", "1.0", "1.0.1" ); final DefaultArtifact artifact = new DefaultArtifact( "group", "artifact", VersionRange.createFromVersionSpec( "[1.0,3.0]" ), "foo", "bar", "jar", new DefaultArtifactHandler() ); ArtifactVersions instance = new ArtifactVersions( artifact, Arrays.asList( versions ), new MavenVersionComparator() ); assertEquals( "artifact", instance.getArtifactId() ); assertEquals( "group", instance.getGroupId() ); assertArrayEquals( versions( "1.0", "1.0.1", "1.1", "3.0" ), instance.getVersions() ); assertArrayEquals( versions( "3.0" ), instance.getVersions( new DefaultArtifactVersion( "1.1" ), null ) ); assertArrayEquals( versions( "1.1", "3.0" ), instance.getVersions( new DefaultArtifactVersion( "1.0.1" ), null ) ); assertEquals( new DefaultArtifactVersion( "1.1" ), instance.getNewestVersion( new DefaultArtifactVersion( "1.0" ), new DefaultArtifactVersion( "3.0" ) ) ); assertNull( instance.getNewestVersion( new DefaultArtifactVersion( "1.1" ), new DefaultArtifactVersion( "3.0" ) ) ); }
Example #9
Source File: NativeInitializeMojoTest.java From maven-native with MIT License | 6 votes |
public void testMojoLookup() throws Exception { File pluginXml = new File( getBasedir(), "src/test/resources/initialize/plugin-config.xml" ); NativeInitializeMojo mojo = (NativeInitializeMojo) lookupMojo( "initialize", pluginXml ); assertNotNull( mojo ); // simulate artifact ArtifactHandler artifactHandler = new DefaultArtifactHandler(); Artifact artifact = new DefaultArtifact( "test", "test", VersionRange.createFromVersion( "1.0-SNAPSHOT" ), "compile", "exe", null, artifactHandler ); mojo.project.setArtifact( artifact ); mojo.setPluginContext( new HashMap<>() ); mojo.execute(); assertEquals( "someArtifactId", mojo.project.getBuild().getFinalName() ); }
Example #10
Source File: MajorVersionTest.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
@Test public void testTruncateVersionRange() { ArtifactVersion initialVersion = majorVersion.getInitialVersion(); ArtifactVersion newStart = new DefaultArtifactVersion( String.format( "%s.%s.%s", initialVersion.getMajorVersion(), initialVersion.getMajorVersion(), initialVersion.getIncrementalVersion() + 5)); assumeTrue(majorVersion.getMaxVersion().compareTo(newStart) > 0); VersionRange updatedRange = MajorVersion.truncateAtLatest(newStart, majorVersion.getVersionRange()); assertFalse(updatedRange.containsVersion(majorVersion.getInitialVersion())); ArtifactVersion afterStart = new DefaultArtifactVersion( String.format( "%s.%s.%s", initialVersion.getMajorVersion(), initialVersion.getMajorVersion(), initialVersion.getIncrementalVersion() + 6)); if (majorVersion.hasStableApi()) { assertTrue(updatedRange.containsVersion(afterStart)); } else { assertFalse(updatedRange.containsVersion(afterStart)); } }
Example #11
Source File: MajorVersionTest.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
@Test public void testVersionRangeFromSpec() { VersionRange versionRange = majorVersion.getVersionRange(); Restriction restriction = Iterables.getOnlyElement(versionRange.getRestrictions()); assertEquals(majorVersion.getVersionRange(), majorVersion.getVersionRange()); assertTrue(restriction.isLowerBoundInclusive()); assertEquals(majorVersion.getInitialVersion(), restriction.getLowerBound()); assertFalse(restriction.isUpperBoundInclusive()); if (majorVersion.getMaxVersion().toString().trim().isEmpty()) { assertNull( "No Upper Bound should be specified if the max version is empty", restriction.getUpperBound()); } else { assertEquals(majorVersion.getMaxVersion(), restriction.getUpperBound()); } }
Example #12
Source File: ResolvableDependency.java From java-specialagent with Apache License 2.0 | 6 votes |
List<Dependency> resolveVersions(final MavenProject project, final Log log) throws InvalidVersionSpecificationException, MojoExecutionException { if (resolvedVersions != null) return resolvedVersions; if (isSingleVersion()) return resolvedVersions = Collections.singletonList(MavenUtil.newDependency(getGroupId(), getArtifactId(), getVersion())); final ResolvableDependency versionDependency = isOwnVersion() ? this : ResolvableDependency.parse(getVersion()); resolvedVersions = new ArrayList<>(); final SortedSet<DefaultArtifactVersion> versions = resolveVersions(project, log, versionDependency); final VersionRange versionRange = VersionRange.createFromVersionSpec(versionDependency.getVersion()); for (final DefaultArtifactVersion version : versions) if (versionRange.containsVersion(version)) resolvedVersions.add(MavenUtil.newDependency(getGroupId(), getArtifactId(), version.toString())); return resolvedVersions; }
Example #13
Source File: CdiContainerUnderTest.java From deltaspike with Apache License 2.0 | 6 votes |
/** * Verify if the runtime is using the following CdiImplementation * * @param cdiImplementation * @param versionRange * optional - If not defined it will used the range defined on {@link CdiImplementation} * @return * @throws InvalidVersionSpecificationException */ public static boolean isCdiVersion(CdiImplementation cdiImplementation, String versionRange) throws InvalidVersionSpecificationException { Class implementationClass = tryToLoadClassForName(cdiImplementation.getImplementationClassName()); if (implementationClass == null) { return false; } VersionRange range = VersionRange.createFromVersionSpec(versionRange == null ? cdiImplementation .getVersionRange() : versionRange); String containerVersion = getJarSpecification(implementationClass); return containerVersion != null && range.containsVersion(new DefaultArtifactVersion(containerVersion)); }
Example #14
Source File: PomHelper.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
/** * Checks if two versions or ranges have an overlap. * * @param leftVersionOrRange the 1st version number or range to test * @param rightVersionOrRange the 2nd version number or range to test * @return true if both versions have an overlap * @throws InvalidVersionSpecificationException if the versions can't be parsed to a range */ public static boolean isVersionOverlap( String leftVersionOrRange, String rightVersionOrRange ) throws InvalidVersionSpecificationException { VersionRange pomVersionRange = createVersionRange( leftVersionOrRange ); if ( !pomVersionRange.hasRestrictions() ) { return true; } VersionRange oldVersionRange = createVersionRange( rightVersionOrRange ); if ( !oldVersionRange.hasRestrictions() ) { return true; } VersionRange result = oldVersionRange.restrict( pomVersionRange ); return result.hasRestrictions(); }
Example #15
Source File: ArtifactRetriever.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
/** * Returns the latest published release artifact version in the version range, * or null if there is no such version. */ public ArtifactVersion getLatestReleaseVersion( String groupId, String artifactId, VersionRange range) { String coordinates = idToKey(groupId, artifactId); try { NavigableSet<ArtifactVersion> versions = availableVersions.get(coordinates); for (ArtifactVersion version : versions.descendingSet()) { if (isReleased(version)) { if (range == null || range.containsVersion(version)) { return version; } } } } catch (ExecutionException ex) { logger.log( Level.WARNING, "Could not retrieve version for artifact " + coordinates, ex.getCause()); } return null; }
Example #16
Source File: MavenUtils.java From mvn-golang with Apache License 2.0 | 6 votes |
/** * Parse string containing artifact record * * @param record string containing record, must not be null * @param handler artifact handler for created artifact, must not be null * @return new created artifact from the record, must not be null * @throws InvalidVersionSpecificationException it will be thrown if version * format is wrong * @throws IllegalArgumentException it will be thrown if record can't be * recognized as artifact record */ @Nonnull public static Artifact parseArtifactRecord( @Nonnull final String record, @Nonnull final ArtifactHandler handler ) throws InvalidVersionSpecificationException { final Matcher matcher = ARTIFACT_RECORD_PATTERN.matcher(record.trim()); if (matcher.find()) { return new DefaultArtifact( matcher.group(1), matcher.group(2), VersionRange.createFromVersion(matcher.group(3)), matcher.group(4).isEmpty() ? null : matcher.group(4), matcher.group(5).isEmpty() ? null : matcher.group(5), matcher.group(6).isEmpty() ? null : matcher.group(6), handler); } throw new IllegalArgumentException("Can't recognize record as artifact: " + record); }
Example #17
Source File: DataflowMavenModelTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { MockitoAnnotations.initMocks(this); latestVersion = new DefaultArtifactVersion("1.20.0-beta1"); currentVersionSpec = VersionRange.createFromVersionSpec("[1.2.3, 1.99.0)"); when(dependencyManager.getDataflowVersionRange(project)).thenReturn(currentVersionSpec); when(dependencyManager.getLatestDataflowDependencyInRange(currentVersionSpec)) .thenReturn(latestVersion); model = new DataflowMavenModel(dependencyManager, xpath, project, domModel); when(domModel.getDocument()).thenReturn(document); when(domModel.getUndoManager()).thenReturn(undoManager); monitor = new NullProgressMonitor(); }
Example #18
Source File: MajorVersionTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Test public void testInitialMaxVersionRange() throws Exception { VersionRange expectedRange = VersionRange.createFromVersionSpec( String.format("[%s, %s)", majorVersion.getInitialVersion(), majorVersion.getMaxVersion())); assertEquals( "Major Versions should produce a version specification from " + "their initial version (inclusive) to their max version (exclusive)", expectedRange, majorVersion.getVersionRange()); }
Example #19
Source File: NativeLinkerMojoTest.java From maven-native with MIT License | 5 votes |
public void testExecute() throws Exception { NativeLinkMojo mojo = getMojo(); // simulate object files List<File> objectList = new ArrayList<>(); objectList.add( new File( "o1.o" ) ); objectList.add( new File( "o2.o" ) ); mojo.saveCompilerOutputFilePaths( objectList ); // simulate artifact ArtifactHandler artifactHandler = new DefaultArtifactHandler(); Artifact artifact = new DefaultArtifact( "test", "test", VersionRange.createFromVersion( "1.0-SNAPSHOT" ), "compile", "exe", null, artifactHandler ); mojo.getProject().setArtifact( artifact ); // simulate artifacts mojo.getProject().setArtifacts( new HashSet<Artifact>() ); // no extern libs for now String linkerFinalName = "some-final-name"; setVariableValueToObject( mojo, "linkerFinalName", linkerFinalName ); mojo.execute(); LinkerConfiguration conf = mojo.getLgetLinkerConfiguration(); // "target is set in the stub assertEquals( new File( "target" ), conf.getOutputDirectory() ); assertEquals( linkerFinalName, conf.getOutputFileName() ); assertNull( conf.getOutputFileExtension() ); // current artifactHandler mocking return null extension name assertEquals( new File( "target/some-final-name.null" ), conf.getOutputFile() ); }
Example #20
Source File: DataflowDependencyManagerTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Test public void testGetProjectMajorVersion() throws InvalidVersionSpecificationException { Dependency pinnedDep = pinnedDataflowDependency(); when(model.getDependencies()).thenReturn(ImmutableList.of(pinnedDep)); ArtifactVersion latestVersion = new DefaultArtifactVersion("1.2.3"); when( artifactRetriever.getLatestReleaseVersion(DataflowMavenCoordinates.GROUP_ID, DataflowMavenCoordinates.ARTIFACT_ID, VersionRange.createFromVersionSpec(pinnedDep.getVersion()))).thenReturn(latestVersion); assertEquals(MajorVersion.ONE, manager.getProjectMajorVersion(project)); }
Example #21
Source File: NativeLinkerMojoTest.java From maven-native with MIT License | 5 votes |
public void testExecuteWithFinalNameExtension() throws Exception { NativeLinkMojo mojo = getMojo(); // simulate object files List<File> objectList = new ArrayList<>(); objectList.add( new File( "o1.o" ) ); objectList.add( new File( "o2.o" ) ); mojo.saveCompilerOutputFilePaths( objectList ); // simulate artifact ArtifactHandler artifactHandler = new DefaultArtifactHandler(); Artifact artifact = new DefaultArtifact( "test", "test", VersionRange.createFromVersion( "1.0-SNAPSHOT" ), "compile", "exe", null, artifactHandler ); mojo.getProject().setArtifact( artifact ); // simulate artifacts mojo.getProject().setArtifacts( new HashSet<Artifact>() ); // no extern libs for now String linkerFinalName = "some-final-name"; setVariableValueToObject( mojo, "linkerFinalName", linkerFinalName ); String linkerFinalNameExt = "some-extension"; setVariableValueToObject( mojo, "linkerFinalNameExt", linkerFinalNameExt ); mojo.execute(); LinkerConfiguration conf = mojo.getLgetLinkerConfiguration(); // "target is set in the stub assertEquals( new File( "target" ), conf.getOutputDirectory() ); assertEquals( linkerFinalName, conf.getOutputFileName() ); assertEquals( linkerFinalNameExt, conf.getOutputFileExtension() ); assertEquals( new File( "target/some-final-name.some-extension" ), conf.getOutputFile() ); }
Example #22
Source File: MavenUtil.java From Decca with MIT License | 5 votes |
public Artifact getArtifact(String groupId, String artifactId, String versionRange, String type, String classifier, String scope) { try { return mojo.factory.createDependencyArtifact(groupId, artifactId, VersionRange.createFromVersionSpec(versionRange), type, classifier, scope); } catch (InvalidVersionSpecificationException e) { getLog().error("cant create Artifact!", e); return null; } }
Example #23
Source File: FlattenModelResolver.java From flatten-maven-plugin with Apache License 2.0 | 5 votes |
private static boolean isRestrictedVersionRange( String version, String groupId, String artifactId ) throws UnresolvableModelException { try { return VersionRange.createFromVersionSpec( version ).hasRestrictions(); } catch ( InvalidVersionSpecificationException e ) { throw new UnresolvableModelException( e.getMessage(), groupId, artifactId, version, e ); } }
Example #24
Source File: RangeResolver.java From pom-manipulation-ext with Apache License 2.0 | 5 votes |
private void handleVersionWithRange( Plugin p ) { try { VersionRange versionRange = VersionRange.createFromVersionSpec( p.getVersion() ); // If its a range then try to use a matching version... if ( versionRange.hasRestrictions() ) { final List<ArtifactVersion> versions = getVersions( new SimpleProjectRef( p.getGroupId(), p.getArtifactId() ) ); final ArtifactVersion result = versionRange.matchVersion( versions ); logger.debug( "Resolved range for plugin {} got versionRange {} and potential replacement of {} ", p, versionRange, result ); if ( result != null ) { p.setVersion( result.toString() ); } else { logger.warn( "Unable to find replacement for range." ); } } } catch ( InvalidVersionSpecificationException e ) { throw new ManipulationUncheckedException( new ManipulationException( "Invalid range", e ) ); } }
Example #25
Source File: RetargetDeployMojo.java From gitflow-helper-maven-plugin with Apache License 2.0 | 5 votes |
/** * Updates artifact versions for a given branch name. * @param a artifact to update (may be null) * @param branchName the branch name */ private void updateArtifactVersion(Artifact a, String branchName) { if (a != null) { a.setVersion(getAsBranchSnapshotVersion(a.getVersion(), branchName)); try { a.setVersionRange(VersionRange.createFromVersion(a.getVersion())); } catch (UnsupportedOperationException uoe) { // Some artifact types don't like this. getLog().debug("Unable to update VersionRange for artifact."); } } }
Example #26
Source File: DefaultVersionsHelper.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, String classifier, String scope, boolean optional ) { return artifactFactory.createDependencyArtifact( groupId, artifactId, versionRange, type, classifier, scope, optional ); }
Example #27
Source File: DefaultVersionsHelper.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public Artifact createDependencyArtifact( Dependency dependency ) throws InvalidVersionSpecificationException { return createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion() == null ? VersionRange.createFromVersionSpec( "[0,]" ) : VersionRange.createFromVersionSpec( dependency.getVersion() ), dependency.getType(), dependency.getClassifier(), dependency.getScope(), dependency.isOptional() ); }
Example #28
Source File: DefaultVersionsHelper.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public ArtifactVersions lookupDependencyUpdates( Dependency dependency, boolean usePluginRepositories ) throws ArtifactMetadataRetrievalException, InvalidVersionSpecificationException { getLog().debug( "Checking " + ArtifactUtils.versionlessKey( dependency.getGroupId(), dependency.getArtifactId() ) + " for updates newer than " + dependency.getVersion() ); VersionRange versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() ); return lookupArtifactVersions( createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(), versionRange, dependency.getType(), dependency.getClassifier(), dependency.getScope() ), usePluginRepositories ); }
Example #29
Source File: PomHelper.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
private static VersionRange createVersionRange( String versionOrRange ) throws InvalidVersionSpecificationException { VersionRange versionRange = VersionRange.createFromVersionSpec( versionOrRange ); if ( versionRange.getRecommendedVersion() != null ) { versionRange = VersionRange.createFromVersionSpec( "[" + versionOrRange + "]" ); } return versionRange; }
Example #30
Source File: VersionXmlGeneratorTest.java From webstart with MIT License | 5 votes |
public void testWithMultiJarResources() throws IOException, SAXException, ParserConfigurationException, MojoExecutionException { Artifact artifact1 = new DefaultArtifact( "groupId", "artifactId1", VersionRange.createFromVersion( "1.0" ), "scope", "jar", "classifier", null ); artifact1.setFile( new File( "bogus1.txt" ) ); Artifact artifact2 = new DefaultArtifact( "groupId", "artifactId2", VersionRange.createFromVersion( "1.0" ), "scope", "jar", "classifier", null ); artifact2.setFile( new File( "bogus2.txt" ) ); ResolvedJarResource jar1 = new ResolvedJarResource( artifact1 ); ResolvedJarResource jar2 = new ResolvedJarResource( artifact2 ); // jar1.setArtifact( artifact1 ); // jar2.setArtifact( artifact2 ); List<ResolvedJarResource> jarResources = new ArrayList<>( 2 ); jarResources.add( jar1 ); jarResources.add( jar2 ); new VersionXmlGenerator( "utf-8" ).generate( this.outputDir, jarResources ); String actualXml = readFileContents( this.expectedFile ); String expected = "<?xml version=\"1.0\"?><jnlp-versions>" + " <resource>" + " <pattern>" + " <name>bogus1.txt</name>" + " <version-id>1.0</version-id>" + " </pattern>" + " <file>artifactId1-1.0-classifier.jar</file>" + " </resource>" + " <resource>" + " <pattern>" + " <name>bogus2.txt</name>" + " <version-id>1.0</version-id>" + " </pattern>" + " <file>artifactId2-1.0-classifier.jar</file>" + " </resource>" + "</jnlp-versions>"; Assert.assertEquals( actualXml, expected ); Diff diff = new Diff( expected, actualXml ); Assert.assertTrue( diff.toString(), diff.similar() ); }