use of org.apache.maven.artifact.versioning.VersionRange in project felix by apache.
the class AbstractBundlePluginTest method getMavenProjectStub.
protected MavenProjectStub getMavenProjectStub() {
MavenProjectStub project = new MavenProjectStub();
project.setGroupId("group");
project.setArtifactId("project");
project.setVersion("1.2.3.4");
VersionRange versionRange = VersionRange.createFromVersion(project.getVersion());
ArtifactHandler artifactHandler = new DefaultArtifactHandler("pom");
Artifact artifact = new DefaultArtifact(project.getGroupId(), project.getArtifactId(), versionRange, null, "pom", null, artifactHandler);
artifact.setResolved(true);
project.setArtifact(artifact);
ProjectBuilderConfiguration projectBuilderConfiguration = new DefaultProjectBuilderConfiguration();
ArtifactRepositoryLayout layout = new LegacyRepositoryLayout();
ArtifactRepository artifactRepository = new DefaultArtifactRepository("scratch", new File(getBasedir(), "target" + File.separatorChar + "scratch").toURI().toString(), layout);
projectBuilderConfiguration.setLocalRepository(artifactRepository);
project.setProjectBuilderConfiguration(projectBuilderConfiguration);
return project;
}
use of org.apache.maven.artifact.versioning.VersionRange in project felix by apache.
the class AbstractBaselinePlugin method getPreviousArtifact.
private Artifact getPreviousArtifact() throws MojoFailureException, MojoExecutionException {
// Find the previous version JAR and resolve it, and it's dependencies
final VersionRange range;
try {
range = VersionRange.createFromVersionSpec(comparisonVersion);
} catch (InvalidVersionSpecificationException e) {
throw new MojoFailureException("Invalid comparison version: " + e.getMessage());
}
final Artifact previousArtifact;
try {
previousArtifact = factory.createDependencyArtifact(comparisonGroupId, comparisonArtifactId, range, comparisonPackaging, comparisonClassifier, Artifact.SCOPE_COMPILE);
if (!previousArtifact.getVersionRange().isSelectedVersionKnown(previousArtifact)) {
getLog().debug("Searching for versions in range: " + previousArtifact.getVersionRange());
@SuppressWarnings("unchecked") List<ArtifactVersion> // type is konwn
availableVersions = metadataSource.retrieveAvailableVersions(previousArtifact, session.getLocalRepository(), project.getRemoteArtifactRepositories());
filterSnapshots(availableVersions);
ArtifactVersion version = range.matchVersion(availableVersions);
if (version != null) {
previousArtifact.selectVersion(version.toString());
}
}
} catch (OverConstrainedVersionException ocve) {
throw new MojoFailureException("Invalid comparison version: " + ocve.getMessage());
} catch (ArtifactMetadataRetrievalException amre) {
throw new MojoExecutionException("Error determining previous version: " + amre.getMessage(), amre);
}
if (previousArtifact.getVersion() == null) {
getLog().info("Unable to find a previous version of the project in the repository");
return null;
}
try {
resolver.resolve(previousArtifact, project.getRemoteArtifactRepositories(), session.getLocalRepository());
} catch (ArtifactResolutionException are) {
throw new MojoExecutionException("Artifact " + previousArtifact + " cannot be resolved : " + are.getMessage(), are);
} catch (ArtifactNotFoundException anfe) {
throw new MojoExecutionException("Artifact " + previousArtifact + " does not exist on local/remote repositories", anfe);
}
return previousArtifact;
}
use of org.apache.maven.artifact.versioning.VersionRange in project BIMserver by opensourceBIM.
the class PluginManager method install.
public PluginBundle install(MavenPluginBundle mavenPluginBundle, List<SPluginInformation> plugins, boolean strictDependencyChecking) throws Exception {
PluginBundleVersionIdentifier pluginBundleVersionIdentifier = mavenPluginBundle.getPluginVersionIdentifier();
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
Model model = null;
try (InputStream pomInputStream = mavenPluginBundle.getPomInputStream()) {
model = mavenreader.read(pomInputStream);
}
if (plugins == null) {
try (JarInputStream jarInputStream = new JarInputStream(mavenPluginBundle.getJarInputStream())) {
JarEntry nextJarEntry = jarInputStream.getNextJarEntry();
while (nextJarEntry != null) {
if (nextJarEntry.getName().equals("plugin/plugin.xml")) {
// Install all plugins
PluginDescriptor pluginDescriptor = getPluginDescriptor(new FakeClosingInputStream(jarInputStream));
plugins = new ArrayList<>();
processPluginDescriptor(pluginDescriptor, plugins);
for (SPluginInformation info : plugins) {
info.setInstallForAllUsers(true);
info.setInstallForNewUsers(true);
}
break;
}
nextJarEntry = jarInputStream.getNextJarEntry();
}
}
}
DelegatingClassLoader delegatingClassLoader = new DelegatingClassLoader(getClass().getClassLoader());
for (org.apache.maven.model.Dependency dependency : model.getDependencies()) {
if (dependency.getGroupId().equals("org.opensourcebim") && (dependency.getArtifactId().equals("shared") || dependency.getArtifactId().equals("pluginbase"))) {
// TODO Skip, we should also check the version though
} else {
PluginBundleIdentifier pluginBundleIdentifier = new PluginBundleIdentifier(dependency.getGroupId(), dependency.getArtifactId());
if (pluginBundleIdentifierToPluginBundle.containsKey(pluginBundleIdentifier)) {
if (strictDependencyChecking) {
VersionRange versionRange = VersionRange.createFromVersion(dependency.getVersion());
// String version =
// pluginBundleIdentifierToPluginBundle.get(pluginBundleIdentifier).getPluginBundleVersion().getVersion();
ArtifactVersion artifactVersion = new DefaultArtifactVersion(mavenPluginBundle.getVersion());
if (versionRange.containsVersion(artifactVersion)) {
// OK
} else {
throw new Exception("Required dependency " + pluginBundleIdentifier + " is installed, but it's version (" + mavenPluginBundle.getVersion() + ") does not comply to the required version (" + dependency.getVersion() + ")");
}
} else {
LOGGER.info("Skipping strict dependency checking for dependency " + dependency.getArtifactId());
}
} else {
try {
MavenPluginLocation mavenPluginLocation = mavenPluginRepository.getPluginLocation(dependency.getGroupId(), dependency.getArtifactId());
Path depJarFile = mavenPluginLocation.getVersionJar(dependency.getVersion());
FileJarClassLoader jarClassLoader = new FileJarClassLoader(this, delegatingClassLoader, depJarFile);
jarClassLoaders.add(jarClassLoader);
delegatingClassLoader.add(jarClassLoader);
} catch (Exception e) {
throw new Exception("Required dependency " + pluginBundleIdentifier + " is not installed");
}
}
}
}
Path target = pluginsDir.resolve(pluginBundleVersionIdentifier.getFileName());
if (Files.exists(target)) {
throw new PluginException("This plugin has already been installed " + target.getFileName().toString());
}
Files.copy(mavenPluginBundle.getJarInputStream(), target);
return loadPlugin(pluginBundleVersionIdentifier, target, mavenPluginBundle.getPluginBundle(), mavenPluginBundle.getPluginBundleVersion(), plugins, delegatingClassLoader);
}
use of org.apache.maven.artifact.versioning.VersionRange in project maven-dependency-plugin by apache.
the class TestDependencyUtil method testFileNameClassifierWithFile.
public void testFileNameClassifierWithFile() throws MojoExecutionException {
// specifically testing the default operation that getFormattedFileName
// returns
// the actual name of the file if available unless remove version is
// set.
ArtifactHandler ah = new DefaultArtifactHandlerStub("war", "sources");
VersionRange vr = VersionRange.createFromVersion("1.1-SNAPSHOT");
Artifact artifact = new DefaultArtifact("test", "two", vr, Artifact.SCOPE_PROVIDED, "war", "sources", ah, false);
File file = new File("/target", "test-file-name.jar");
artifact.setFile(file);
String name = DependencyUtil.getFormattedFileName(artifact, false);
String expectedResult = "two-1.1-SNAPSHOT-sources.war";
assertEquals(expectedResult, name);
name = DependencyUtil.getFormattedFileName(artifact, false, false, false, true);
expectedResult = "two-1.1-SNAPSHOT.war";
assertEquals(expectedResult, name);
name = DependencyUtil.getFormattedFileName(artifact, true);
expectedResult = "two-sources.war";
assertEquals(expectedResult, name);
artifact = new DefaultArtifact("test", "two", vr, Artifact.SCOPE_PROVIDED, "war", "", ah, false);
name = DependencyUtil.getFormattedFileName(artifact, true);
expectedResult = "two.war";
assertEquals(expectedResult, name);
// test that we pickup the correct extension in the file name if set.
ah = new DefaultArtifactHandlerStub("jar", null);
artifact = new DefaultArtifact("test", "two", vr, Artifact.SCOPE_PROVIDED, "war", "", ah, false);
name = DependencyUtil.getFormattedFileName(artifact, true);
expectedResult = "two.jar";
assertEquals(expectedResult, name);
}
use of org.apache.maven.artifact.versioning.VersionRange in project maven-dependency-plugin by apache.
the class TestDependencyUtil method testFileNameClassifier.
public void testFileNameClassifier() throws MojoExecutionException {
ArtifactHandler ah = new DefaultArtifactHandlerStub("jar", "sources");
VersionRange vr = VersionRange.createFromVersion("1.1-SNAPSHOT");
Artifact artifact = new DefaultArtifact("test", "two", vr, Artifact.SCOPE_PROVIDED, "jar", "sources", ah, false);
String name = DependencyUtil.getFormattedFileName(artifact, false);
String expectedResult = "two-1.1-SNAPSHOT-sources.jar";
assertEquals(expectedResult, name);
name = DependencyUtil.getFormattedFileName(artifact, true);
expectedResult = "two-sources.jar";
assertEquals(expectedResult, name);
name = DependencyUtil.getFormattedFileName(artifact, false, false, false, true);
expectedResult = "two-1.1-SNAPSHOT.jar";
assertEquals(expectedResult, name);
ah = new DefaultArtifactHandlerStub("war", null);
artifact = new DefaultArtifact("test", "two", vr, Artifact.SCOPE_PROVIDED, "war", "", ah, false);
name = DependencyUtil.getFormattedFileName(artifact, true);
expectedResult = "two.war";
assertEquals(expectedResult, name);
}
Aggregations