use of org.apache.maven.artifact.versioning.VersionRange in project BIMserver by opensourceBIM.
the class PluginBundleManager method loadDependencies.
private void loadDependencies(String pluginBundleVersion, boolean strictDependencyChecking, Model model, DelegatingClassLoader delegatingClassLoader) throws DependencyCollectionException, InvalidVersionSpecificationException, Exception {
if (model.getRepositories() != null) {
for (Repository repository : model.getRepositories()) {
mavenPluginRepository.addRepository(repository.getId(), "default", repository.getUrl());
}
}
List<Dependency> dependenciesToResolve = new ArrayList<>();
for (org.apache.maven.model.Dependency mvnDependency : model.getDependencies()) {
String scope = mvnDependency.getScope();
if (scope != null && (scope.contentEquals("test"))) {
// Skip
continue;
}
Dependency d = new Dependency(new DefaultArtifact(mvnDependency.getGroupId(), mvnDependency.getArtifactId(), mvnDependency.getType(), mvnDependency.getVersion()), scope);
Set<Exclusion> exclusions = new HashSet<>();
d.setExclusions(exclusions);
exclusions.add(new Exclusion("org.opensourcebim", "pluginbase", null, "jar"));
exclusions.add(new Exclusion("org.opensourcebim", "shared", null, "jar"));
exclusions.add(new Exclusion("org.opensourcebim", "ifcplugins", null, "jar"));
if (!isDependencyProvided(mvnDependency))
dependenciesToResolve.add(d);
}
CollectRequest collectRequest = new CollectRequest(dependenciesToResolve, null, null);
collectRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList());
CollectResult collectDependencies = mavenPluginRepository.getSystem().collectDependencies(mavenPluginRepository.getSession(), collectRequest);
PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
DependencyNode rootDep = collectDependencies.getRoot();
rootDep.accept(nlg);
for (Dependency dependency : nlg.getDependencies(true)) {
if (dependency.getScope().contentEquals("test")) {
continue;
}
// LOGGER.info(dependency.getArtifact().getGroupId() + "." + dependency.getArtifact().getArtifactId());
Artifact dependencyArtifact = dependency.getArtifact();
PluginBundleIdentifier pluginBundleIdentifier = new PluginBundleIdentifier(dependencyArtifact.getGroupId(), dependencyArtifact.getArtifactId());
if (pluginBundleIdentifierToPluginBundle.containsKey(pluginBundleIdentifier)) {
if (strictDependencyChecking) {
String version = dependencyArtifact.getVersion();
if (!version.contains("[") && !version.contains("(")) {
version = "[" + version + "]";
}
VersionRange versionRange = VersionRange.createFromVersionSpec(version);
// String version =
// pluginBundleIdentifierToPluginBundle.get(pluginBundleIdentifier).getPluginBundleVersion().getVersion();
ArtifactVersion artifactVersion = new DefaultArtifactVersion(pluginBundleVersion);
if (versionRange.containsVersion(artifactVersion)) {
// OK
} else {
throw new Exception("Required dependency " + pluginBundleIdentifier + " is installed, but it's version (" + pluginBundleVersion + ") does not comply to the required version (" + dependencyArtifact.getVersion() + ")");
}
} else {
LOGGER.info("Skipping strict dependency checking for dependency " + dependencyArtifact.getArtifactId());
}
} else {
try {
if (dependencyArtifact.getGroupId().contentEquals("com.sun.xml.ws")) {
continue;
}
MavenPluginLocation mavenPluginLocation = mavenPluginRepository.getPluginLocation(dependencyArtifact.getGroupId(), dependencyArtifact.getArtifactId());
if (dependencyArtifact.getExtension().contentEquals("jar")) {
Path depJarFile = mavenPluginLocation.getVersionJar(dependencyArtifact.getVersion());
FileJarClassLoader jarClassLoader = new FileJarClassLoader(pluginManager, delegatingClassLoader, depJarFile);
jarClassLoaders.add(jarClassLoader);
delegatingClassLoader.add(jarClassLoader);
}
} catch (Exception e) {
e.printStackTrace();
throw new Exception("Required dependency " + pluginBundleIdentifier + " is not installed");
}
}
}
}
use of org.apache.maven.artifact.versioning.VersionRange in project maven-plugins by apache.
the class DependencyManagementRenderer method getDependencyRow.
@SuppressWarnings("unchecked")
private String[] getDependencyRow(Dependency dependency, boolean hasClassifier) {
Artifact artifact = artifactFactory.createProjectArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
StringBuilder licensesBuffer = new StringBuilder();
String url = null;
try {
VersionRange range = VersionRange.createFromVersionSpec(dependency.getVersion());
if (range.getRecommendedVersion() == null) {
// MPIR-216: no direct version but version range: need to choose one precise version
log.debug("Resolving range for DependencyManagement on " + artifact.getId());
List<ArtifactVersion> versions = artifactMetadataSource.retrieveAvailableVersions(artifact, localRepository, remoteRepositories);
// only use versions from range
for (Iterator<ArtifactVersion> iter = versions.iterator(); iter.hasNext(); ) {
if (!range.containsVersion(iter.next())) {
iter.remove();
}
}
// select latest, assuming pom information will be the most accurate
if (versions.size() > 0) {
ArtifactVersion maxArtifactVersion = Collections.max(versions);
artifact.setVersion(maxArtifactVersion.toString());
log.debug("DependencyManagement resolved: " + artifact.getId());
}
}
url = ProjectInfoReportUtils.getArtifactUrl(artifactFactory, artifact, mavenProjectBuilder, remoteRepositories, localRepository);
MavenProject artifactProject = repoUtils.getMavenProjectFromRepository(artifact);
List<License> licenses = artifactProject.getLicenses();
for (License license : licenses) {
String licenseCell = ProjectInfoReportUtils.getArtifactIdCell(license.getName(), license.getUrl());
if (licensesBuffer.length() > 0) {
licensesBuffer.append(", ");
}
licensesBuffer.append(licenseCell);
}
} catch (InvalidVersionSpecificationException e) {
log.warn("Unable to parse version for " + artifact.getId(), e);
} catch (ArtifactMetadataRetrievalException e) {
log.warn("Unable to retrieve versions for " + artifact.getId() + " from repository.", e);
} catch (ProjectBuildingException e) {
log.warn("Unable to create Maven project for " + artifact.getId() + " from repository.", e);
}
String artifactIdCell = ProjectInfoReportUtils.getArtifactIdCell(artifact.getArtifactId(), url);
if (hasClassifier) {
return new String[] { dependency.getGroupId(), artifactIdCell, dependency.getVersion(), dependency.getClassifier(), dependency.getType(), licensesBuffer.toString() };
}
return new String[] { dependency.getGroupId(), artifactIdCell, dependency.getVersion(), dependency.getType(), licensesBuffer.toString() };
}
use of org.apache.maven.artifact.versioning.VersionRange in project maven-plugins by apache.
the class TestSourcesMarkerFileHandler method setUp.
protected void setUp() throws Exception {
super.setUp();
ArtifactHandler ah = new DefaultArtifactHandler();
VersionRange vr = VersionRange.createFromVersion("1.1");
Artifact artifact = new DefaultArtifact("test", "1", vr, Artifact.SCOPE_COMPILE, "jar", "", ah, false);
artifacts.add(artifact);
artifact = new DefaultArtifact("test", "2", vr, Artifact.SCOPE_PROVIDED, "war", "", ah, false);
artifacts.add(artifact);
artifact = new DefaultArtifact("test", "3", vr, Artifact.SCOPE_TEST, "sources", "", ah, false);
artifacts.add(artifact);
artifact = new DefaultArtifact("test", "4", vr, Artifact.SCOPE_RUNTIME, "zip", "", ah, false);
artifacts.add(artifact);
// pick random output location
Random a = new Random();
outputFolder = new File("target/markers" + a.nextLong() + "/");
outputFolder.delete();
assertFalse(outputFolder.exists());
}
use of org.apache.maven.artifact.versioning.VersionRange in project maven-plugins 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-plugins by apache.
the class TestDependencyUtil method setUp.
protected void setUp() throws Exception {
super.setUp();
ArtifactHandler ah = new DefaultArtifactHandlerStub("jar", null);
VersionRange vr = VersionRange.createFromVersion("1.1");
release = new DefaultArtifact("test", "one", vr, Artifact.SCOPE_COMPILE, "jar", "sources", ah, false);
artifacts.add(release);
ah = new DefaultArtifactHandlerStub("war", null);
vr = VersionRange.createFromVersion("1.1-SNAPSHOT");
snap = new DefaultArtifact("test", "two", vr, Artifact.SCOPE_PROVIDED, "war", null, ah, false);
artifacts.add(snap);
ah = new DefaultArtifactHandlerStub("war", null);
vr = VersionRange.createFromVersion("1.1-SNAPSHOT");
snapResolvedVersion = new DefaultArtifact("test", "three", vr, Artifact.SCOPE_PROVIDED, "war", null, ah, false);
snapResolvedVersion.setResolvedVersion("1.1-20121003.035531-117");
artifacts.add(snapResolvedVersion);
ah = new DefaultArtifactHandlerStub("war", null);
vr = VersionRange.createFromVersion("1.1-SNAPSHOT");
sources = new DefaultArtifact("test", "two", vr, Artifact.SCOPE_PROVIDED, "sources", "sources", ah, false);
// pick random output location
Random a = new Random();
outputFolder = new File("target/copy" + a.nextLong() + "/");
outputFolder.delete();
assertFalse(outputFolder.exists());
}
Aggregations