Search in sources :

Example 21 with DefaultArtifactVersion

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;
}
Also used : DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) Plugin(org.apache.maven.model.Plugin)

Example 22 with DefaultArtifactVersion

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.");
        }
    }
}
Also used : DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 23 with DefaultArtifactVersion

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);
}
Also used : PluginBundle(org.bimserver.plugins.PluginBundle) SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) MavenPluginLocation(org.bimserver.plugins.MavenPluginLocation) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) UserException(org.bimserver.shared.exceptions.UserException)

Example 24 with DefaultArtifactVersion

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);
}
Also used : Path(java.nio.file.Path) JarInputStream(java.util.jar.JarInputStream) FakeClosingInputStream(org.bimserver.utils.FakeClosingInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) SPluginInformation(org.bimserver.interfaces.objects.SPluginInformation) PluginException(org.bimserver.shared.exceptions.PluginException) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) VersionRange(org.apache.maven.artifact.versioning.VersionRange) JarEntry(java.util.jar.JarEntry) DelegatingClassLoader(org.bimserver.plugins.classloaders.DelegatingClassLoader) ObjectIDMException(org.bimserver.plugins.objectidms.ObjectIDMException) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) PluginException(org.bimserver.shared.exceptions.PluginException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) UserException(org.bimserver.shared.exceptions.UserException) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) FileJarClassLoader(org.bimserver.plugins.classloaders.FileJarClassLoader) Model(org.apache.maven.model.Model) FakeClosingInputStream(org.bimserver.utils.FakeClosingInputStream)

Example 25 with DefaultArtifactVersion

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;
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) Version(org.eclipse.aether.version.Version) SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) IOException(java.io.IOException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Model(org.apache.maven.model.Model) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) File(java.io.File) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Aggregations

DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)37 ArtifactVersion (org.apache.maven.artifact.versioning.ArtifactVersion)12 File (java.io.File)8 IOException (java.io.IOException)7 Model (org.apache.maven.model.Model)5 FileNotFoundException (java.io.FileNotFoundException)4 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)4 ArrayList (java.util.ArrayList)3 Matcher (java.util.regex.Matcher)3 Artifact (org.apache.maven.artifact.Artifact)3 SPluginBundle (org.bimserver.interfaces.objects.SPluginBundle)3 SPluginBundleVersion (org.bimserver.interfaces.objects.SPluginBundleVersion)3 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)3 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)3 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)3 FileReader (java.io.FileReader)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2