use of org.apache.maven.artifact.versioning.VersionRange in project karaf by apache.
the class MojoSupport method createManagedVersionMap.
protected Map createManagedVersionMap(String projectId, DependencyManagement dependencyManagement) throws ProjectBuildingException {
Map map;
if (dependencyManagement != null && dependencyManagement.getDependencies() != null) {
map = new HashMap();
for (Dependency d : dependencyManagement.getDependencies()) {
try {
VersionRange versionRange = VersionRange.createFromVersionSpec(d.getVersion());
Artifact artifact = factory.createDependencyArtifact(d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), d.getClassifier(), d.getScope());
map.put(d.getManagementKey(), artifact);
} catch (InvalidVersionSpecificationException e) {
throw new ProjectBuildingException(projectId, "Unable to parse version '" + d.getVersion() + "' for dependency '" + d.getManagementKey() + "': " + e.getMessage(), e);
}
}
} else {
map = Collections.EMPTY_MAP;
}
return map;
}
use of org.apache.maven.artifact.versioning.VersionRange in project camel by apache.
the class RunMojo method getAllDependencies.
// generic method to retrieve all the transitive dependencies
private Collection<Artifact> getAllDependencies() throws MojoExecutionException {
List<Artifact> artifacts = new ArrayList<Artifact>();
for (Iterator<?> dependencies = project.getDependencies().iterator(); dependencies.hasNext(); ) {
Dependency dependency = (Dependency) dependencies.next();
String groupId = dependency.getGroupId();
String artifactId = dependency.getArtifactId();
VersionRange versionRange;
try {
versionRange = VersionRange.createFromVersionSpec(dependency.getVersion());
} catch (InvalidVersionSpecificationException e) {
throw new MojoExecutionException("unable to parse version", e);
}
String type = dependency.getType();
if (type == null) {
type = "jar";
}
String classifier = dependency.getClassifier();
boolean optional = dependency.isOptional();
String scope = dependency.getScope();
if (scope == null) {
scope = Artifact.SCOPE_COMPILE;
}
Artifact art = this.artifactFactory.createDependencyArtifact(groupId, artifactId, versionRange, type, classifier, scope, null, optional);
if (scope.equalsIgnoreCase(Artifact.SCOPE_SYSTEM)) {
art.setFile(new File(dependency.getSystemPath()));
}
List<String> exclusions = new ArrayList<String>();
for (Exclusion exclusion : dependency.getExclusions()) {
exclusions.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId());
}
ArtifactFilter newFilter = new ExcludesArtifactFilter(exclusions);
art.setDependencyFilter(newFilter);
artifacts.add(art);
}
return artifacts;
}
use of org.apache.maven.artifact.versioning.VersionRange in project BIMserver by opensourceBIM.
the class PluginManager method loadFromPluginDir.
public PluginBundle loadFromPluginDir(PluginBundleVersionIdentifier pluginBundleVersionIdentifier, SPluginBundleVersion pluginBundleVersion, List<SPluginInformation> plugins, boolean strictDependencyChecking) throws Exception {
Path target = pluginsDir.resolve(pluginBundleVersionIdentifier.getFileName());
if (!Files.exists(target)) {
throw new PluginException(target.toString() + " not found");
}
SPluginBundle sPluginBundle = new SPluginBundle();
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
try (JarFile jarFile = new JarFile(target.toFile())) {
ZipEntry entry = jarFile.getEntry("META-INF/maven/" + pluginBundleVersion.getGroupId() + "/" + pluginBundleVersion.getArtifactId() + "/pom.xml");
Model model = mavenreader.read(jarFile.getInputStream(entry));
sPluginBundle.setOrganization(model.getOrganization().getName());
sPluginBundle.setName(model.getName());
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(version);
if (versionRange.containsVersion(artifactVersion)) {
// OK
} else {
throw new Exception("Required dependency " + pluginBundleIdentifier + " is installed, but it's version (" + version + ") does not comply to the required version (" + dependency.getVersion() + ")");
}
} else {
LOGGER.info("Skipping strict dependency checking for dependency " + dependency.getArtifactId());
}
} else {
if (dependency.getGroupId().equals("org.opensourcebim") && (dependency.getArtifactId().equals("shared") || dependency.getArtifactId().equals("pluginbase"))) {
} else {
MavenPluginLocation mavenPluginLocation = mavenPluginRepository.getPluginLocation(dependency.getGroupId(), dependency.getArtifactId());
try {
Path depJarFile = mavenPluginLocation.getVersionJar(dependency.getVersion());
FileJarClassLoader jarClassLoader = new FileJarClassLoader(this, delegatingClassLoader, depJarFile);
jarClassLoaders.add(jarClassLoader);
delegatingClassLoader.add(jarClassLoader);
} catch (Exception e) {
}
}
}
}
}
return loadPlugin(pluginBundleVersionIdentifier, target, sPluginBundle, pluginBundleVersion, plugins, delegatingClassLoader);
}
}
use of org.apache.maven.artifact.versioning.VersionRange in project BIMserver by opensourceBIM.
the class PluginBundleDatabaseAction method processMavenPluginLocation.
public SPluginBundle processMavenPluginLocation(MavenPluginLocation mavenPluginLocation, boolean strictVersionChecking, ArtifactVersion bimserverVersion) {
SPluginBundle pluginBundle = new SPluginBundle();
boolean usefulBundle = false;
for (PluginVersion pluginVersion : mavenPluginLocation.getAllVersions()) {
if (pluginVersion instanceof MavenPluginVersion) {
SPluginBundleVersion sPluginBundleVersion = new SPluginBundleVersion();
boolean useful = true;
MavenPluginVersion mavenPluginVersion = (MavenPluginVersion) pluginVersion;
for (MavenDependency mavenDependency : mavenPluginVersion.getDependencies()) {
if (mavenDependency.getArtifact().getGroupId().equals("org.opensourcebim")) {
String artifactId = mavenDependency.getArtifact().getArtifactId();
// for the plugin, it's version has to be ok
if (artifactId.equals("shared") || artifactId.equals("pluginbase")) {
VersionRange versionRange = VersionRange.createFromVersion(mavenDependency.getArtifact().getVersion());
if (bimserverVersion != null && versionRange.containsVersion(bimserverVersion)) {
} else {
sPluginBundleVersion.setMismatch(true);
if (strictVersionChecking) {
useful = false;
LOGGER.info("Skipping version " + mavenPluginVersion.getArtifact().getVersion() + " or artifact " + mavenPluginVersion.getArtifact().getArtifactId());
}
}
}
}
}
if (useful) {
usefulBundle = true;
sPluginBundleVersion.setName(mavenPluginVersion.getModel().getName());
sPluginBundleVersion.setOrganization(mavenPluginVersion.getModel().getOrganization().getName());
sPluginBundleVersion.setArtifactId(mavenPluginLocation.getArtifactId());
sPluginBundleVersion.setGroupId(mavenPluginLocation.getGroupId());
try {
sPluginBundleVersion.setRepository(mavenPluginLocation.getRepository(mavenPluginVersion.getVersion().toString()));
} catch (ArtifactResolutionException e) {
LOGGER.error("", e);
}
sPluginBundleVersion.setType(SPluginBundleType.MAVEN);
sPluginBundleVersion.setVersion(mavenPluginVersion.getVersion().toString());
sPluginBundleVersion.setDescription(mavenPluginVersion.getModel().getDescription());
pluginBundle.setName(mavenPluginVersion.getModel().getName());
pluginBundle.setOrganization(mavenPluginVersion.getModel().getOrganization().getName());
pluginBundle.setLatestVersion(sPluginBundleVersion);
pluginBundle.getAvailableVersions().add(sPluginBundleVersion);
try {
sPluginBundleVersion.setIcon(mavenPluginLocation.getVersionIcon(mavenPluginVersion.getVersion().toString()));
} catch (ArtifactResolutionException e) {
// This is not important
} catch (IOException e) {
LOGGER.error("", e);
}
try {
GregorianCalendar date = mavenPluginLocation.getVersionDate(mavenPluginVersion.getVersion().toString());
if (date != null) {
sPluginBundleVersion.setDate(date.getTime());
}
// byte[] bytes = Files.readAllBytes(date);
// Properties properties = new Properties();
// properties.load(new ByteArrayInputStream(bytes));
// String buildDateString = properties.getProperty("build.date");
//
// DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
// try {
// } catch (ParseException e) {
// LOGGER.error("Invalid date format for plugin " + mavenPluginVersion.getModel().getName() + ": '" + buildDateString + "'");
// }
} catch (ArtifactResolutionException e) {
// Not a problem
} catch (Exception e) {
LOGGER.error("", e);
}
}
}
}
if (usefulBundle) {
return pluginBundle;
}
return null;
}
use of org.apache.maven.artifact.versioning.VersionRange in project felix by apache.
the class BundleAllPlugin method resolveArtifact.
private Artifact resolveArtifact(Artifact artifact) throws MojoExecutionException, ArtifactNotFoundException {
VersionRange versionRange;
if (artifact.getVersion() != null) {
versionRange = VersionRange.createFromVersion(artifact.getVersion());
} else {
versionRange = artifact.getVersionRange();
}
/*
* there's a bug with ArtifactFactory#createDependencyArtifact(String, String, VersionRange,
* String, String, String) that ignores the scope parameter, that's why we use the one with
* the extra null parameter
*/
Artifact resolvedArtifact = m_factory.createDependencyArtifact(artifact.getGroupId(), artifact.getArtifactId(), versionRange, artifact.getType(), artifact.getClassifier(), artifact.getScope(), null);
try {
m_artifactResolver.resolve(resolvedArtifact, remoteRepositories, localRepository);
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException("Error resolving artifact " + resolvedArtifact, e);
}
return resolvedArtifact;
}
Aggregations