use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project felix by apache.
the class SCRDescriptorMojo method getBundlePlugin.
/**
* We need the bundle plugin with a version higher than 2.5.0!
*/
private Plugin getBundlePlugin() {
Plugin bundlePlugin = null;
final List<Plugin> plugins = this.project.getBuildPlugins();
for (final Plugin p : plugins) {
if (p.getArtifactId().equals(BUNDLE_PLUGIN_ARTIFACT_ID) && p.getGroupId().equals(BUNDLE_PLUGIN_GROUP_ID)) {
final ArtifactVersion pluginVersion = new DefaultArtifactVersion(p.getVersion());
final ArtifactVersion requiredMinVersion = new DefaultArtifactVersion("2.5.0");
if (pluginVersion.compareTo(requiredMinVersion) > 0) {
bundlePlugin = p;
break;
}
}
}
return bundlePlugin;
}
use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project felix by apache.
the class SCRDescriptorMojo method assertMinScrAnnotationArtifactVersion.
/**
* Asserts that the artifact is at least version
* {@link #SCR_ANN_MIN_VERSION} if it is
* org.apache.felix:org.apache.felix.scr.annotations. If the version is
* lower then the build fails because as of Maven SCR Plugin 1.6.0 the old
* SCR Annotation libraries do not produce descriptors any more. If the
* artifact is not this method silently returns.
*
* @param a
* The artifact to check and assert
* @see #SCR_ANN_ARTIFACTID
* @see #SCR_ANN_GROUPID
* @see #SCR_ANN_MIN_VERSION
* @throws MojoFailureException
* If the artifact refers to the SCR Annotation library with a
* version less than {@link #SCR_ANN_MIN_VERSION}
*/
@SuppressWarnings("unchecked")
private void assertMinScrAnnotationArtifactVersion(final Artifact a) throws MojoFailureException {
if (SCR_ANN_ARTIFACTID.equals(a.getArtifactId()) && SCR_ANN_GROUPID.equals(a.getGroupId())) {
// assert minimal version number
final ArtifactVersion aVersion = new DefaultArtifactVersion(a.getBaseVersion());
if (SCR_ANN_MIN_VERSION.compareTo(aVersion) > 0) {
getLog().error("Project depends on " + a);
getLog().error("Minimum required version is " + SCR_ANN_MIN_VERSION);
throw new MojoFailureException("Please use org.apache.felix:org.apache.felix.scr.annotations version " + SCR_ANN_MIN_VERSION + " or newer.");
}
}
}
use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project BIMserver by opensourceBIM.
the class GetPluginBundle method execute.
@Override
public SPluginBundle execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
if (bimServer.getVersionChecker() != null && bimServer.getVersionChecker().getLocalVersion() != null) {
bimserverVersion = new DefaultArtifactVersion(bimServer.getVersionChecker().getLocalVersion().getFullString());
}
MavenPluginLocation pluginLocation = bimServer.getMavenPluginRepository().getPluginLocation(repository, groupId, artifactId);
PluginBundle pluginBundle = bimServer.getPluginManager().getPluginBundle(pluginLocation.getPluginIdentifier());
// Skipping all plugin bundles that already have an installed version
if (pluginBundle == null) {
SPluginBundle sPluginBundle = processPluginLocation(pluginLocation, false, bimserverVersion);
if (sPluginBundle != null) {
return sPluginBundle;
}
}
throw new UserException("Plugin bundle already installed " + groupId + "." + artifactId);
}
use of org.apache.maven.artifact.versioning.DefaultArtifactVersion 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.DefaultArtifactVersion in project BIMserver by opensourceBIM.
the class MavenPluginLocation method getAllVersions.
@Override
public List<MavenPluginVersion> getAllVersions() {
List<MavenPluginVersion> pluginVersions = new ArrayList<>();
Artifact artifact = new DefaultArtifact(groupId, artifactId, null, "[0,)");
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(artifact);
rangeRequest.setRepositories(mavenPluginRepository.getRepositories());
// RemoteRepository centralRepo = newCentralRepository();
try {
VersionRangeResult rangeResult = mavenPluginRepository.getSystem().resolveVersionRange(mavenPluginRepository.getSession(), rangeRequest);
List<Version> versions = rangeResult.getVersions();
if (!versions.isEmpty()) {
for (int i = versions.size() - 1; i >= Math.max(0, versions.size() - 3); i--) {
Version version = versions.get(i);
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "pom", version.toString());
descriptorRequest.setArtifact(versionArtifact);
descriptorRequest.setRepositories(mavenPluginRepository.getRepositories());
MavenPluginVersion mavenPluginVersion = new MavenPluginVersion(versionArtifact, version);
ArtifactDescriptorResult descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(descriptorResult.getArtifact());
request.setRepositories(mavenPluginRepository.getRepositories());
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
File pomFile = resolveArtifact.getArtifact().getFile();
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
try (FileReader fileReader = new FileReader(pomFile)) {
Model model = mavenreader.read(fileReader);
mavenPluginVersion.setModel(model);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
for (org.eclipse.aether.graph.Dependency dependency : descriptorResult.getDependencies()) {
DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(dependency.getArtifact().getVersion());
mavenPluginVersion.addDependency(new MavenDependency(dependency.getArtifact(), artifactVersion));
}
pluginVersions.add(0, mavenPluginVersion);
}
}
} catch (VersionRangeResolutionException e) {
e.printStackTrace();
} catch (ArtifactDescriptorException e) {
e.printStackTrace();
} catch (ArtifactResolutionException e) {
e.printStackTrace();
}
return pluginVersions;
}
Aggregations