-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from sse-labs/feature/mock-version-range-tests
Proper mocking for tests of version range resolution
- Loading branch information
Showing
7 changed files
with
335 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/org/tudo/sse/resolution/releases/DefaultMavenReleaseListProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.tudo.sse.resolution.releases; | ||
|
||
import org.apache.maven.artifact.repository.metadata.Metadata; | ||
import org.apache.maven.artifact.repository.metadata.Versioning; | ||
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; | ||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; | ||
import org.tudo.sse.model.ArtifactIdent; | ||
import org.tudo.sse.resolution.FileNotFoundException; | ||
import org.tudo.sse.utils.MavenCentralRepository; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* This default implementation of IReleaseListProvider obtains a list of releases for a given GA-Tuple by | ||
* querying the maven-metadata.xml file hosted on Maven Central. It will throw an IOException if file | ||
* access files for any given reason. | ||
* | ||
* @author Johannes Düsing | ||
*/ | ||
public class DefaultMavenReleaseListProvider implements IReleaseListProvider{ | ||
|
||
private final MetadataXpp3Reader reader = new MetadataXpp3Reader(); | ||
private final MavenCentralRepository mavenRepo = MavenCentralRepository.getInstance(); | ||
|
||
// Singleton pattern implementation | ||
private final static DefaultMavenReleaseListProvider instance = new DefaultMavenReleaseListProvider(); | ||
|
||
/** | ||
* Access the singleton instance of DefaultMavenReleaseListProvider | ||
* @return The only instance of this class | ||
*/ | ||
public static DefaultMavenReleaseListProvider getInstance() { | ||
return instance; | ||
} | ||
|
||
// Singleton pattern implementation | ||
private DefaultMavenReleaseListProvider(){} | ||
|
||
@Override | ||
public List<String> getReleases(ArtifactIdent identifier) throws IOException { | ||
Objects.requireNonNull(identifier); | ||
|
||
try(InputStream xmlInputStream = mavenRepo.openXMLFileInputStream(identifier)) { | ||
Metadata versionListData = reader.read(new BufferedReader(new InputStreamReader(xmlInputStream))); | ||
|
||
Versioning versioning = versionListData.getVersioning(); | ||
|
||
if(versioning != null) { | ||
List<String> versions = new ArrayList<>(); | ||
for(Object version : versioning.getVersions()) { | ||
versions.add((String)version); | ||
} | ||
return versions; | ||
} else { | ||
return List.of(); | ||
} | ||
|
||
} catch (XmlPullParserException | IOException | FileNotFoundException x) { | ||
throw new IOException("Failed to obtain version list for " + identifier, x); | ||
} | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/tudo/sse/resolution/releases/IReleaseListProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.tudo.sse.resolution.releases; | ||
|
||
import org.tudo.sse.model.ArtifactIdent; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public interface IReleaseListProvider { | ||
|
||
/** | ||
* Gets the ordered list of releases (i.e. version numbers) for the given identifier. The identifier's version is | ||
* irrelevant, only the GA tuple is used to obtain a release list. | ||
* | ||
* @param identifier Identifier to obtain the release list for (GA-Tuple) | ||
* @return List of version numbers as ordered by the underlying source | ||
*/ | ||
List<String> getReleases(ArtifactIdent identifier) throws IOException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.