Search in sources :

Example 1 with DefaultArtifactVersion

use of org.apache.maven.artifact.versioning.DefaultArtifactVersion 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);
    }
}
Also used : Path(java.nio.file.Path) PluginException(org.bimserver.shared.exceptions.PluginException) ZipEntry(java.util.zip.ZipEntry) SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) VersionRange(org.apache.maven.artifact.versioning.VersionRange) JarFile(java.util.jar.JarFile) 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)

Example 2 with DefaultArtifactVersion

use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project BIMserver by opensourceBIM.

the class GetAvailablePluginBundles method execute.

@Override
public List<SPluginBundle> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    List<SPluginBundle> result = new ArrayList<>();
    GitHubPluginRepository repository = new GitHubPluginRepository(bimServer.getMavenPluginRepository(), bimServer.getServerSettingsCache().getServerSettings().getServiceRepositoryUrl());
    bimserverVersion = new DefaultArtifactVersion(bimServer.getVersionChecker().getLocalVersion().getFullString());
    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(32, 32, 1L, TimeUnit.HOURS, new ArrayBlockingQueue<>(100));
    for (PluginLocation<?> pluginLocation : repository.listPluginLocations()) {
        PluginBundle pluginBundle = bimServer.getPluginManager().getPluginBundle(pluginLocation.getPluginIdentifier());
        // Skipping all plugin bundles that already have an installed version
        if (pluginBundle == null) {
            threadPoolExecutor.submit(new Runnable() {

                @Override
                public void run() {
                    SPluginBundle sPluginBundle = processPluginLocation(pluginLocation, strictVersionChecking, bimserverVersion);
                    if (sPluginBundle != null) {
                        result.add(sPluginBundle);
                    }
                }
            });
        }
    }
    threadPoolExecutor.shutdown();
    try {
        threadPoolExecutor.awaitTermination(1, TimeUnit.HOURS);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    Collections.sort(result, new Comparator<SPluginBundle>() {

        @Override
        public int compare(SPluginBundle o1, SPluginBundle o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    return result;
}
Also used : SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) ArrayList(java.util.ArrayList) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) PluginBundle(org.bimserver.plugins.PluginBundle) SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) GitHubPluginRepository(org.bimserver.plugins.GitHubPluginRepository)

Example 3 with DefaultArtifactVersion

use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project BIMserver by opensourceBIM.

the class GetInstalledPluginBundles method execute.

@Override
public List<SPluginBundle> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    List<SPluginBundle> result = new ArrayList<>();
    bimserverVersion = new DefaultArtifactVersion(bimServer.getVersionChecker().getLocalVersion().getFullString());
    GitHubPluginRepository repository = new GitHubPluginRepository(bimServer.getMavenPluginRepository(), bimServer.getServerSettingsCache().getServerSettings().getServiceRepositoryUrl());
    Map<PluginBundleIdentifier, PluginLocation<?>> repositoryKnownLocation = new HashMap<>();
    for (PluginLocation<?> pluginLocation : repository.listPluginLocations()) {
        repositoryKnownLocation.put(pluginLocation.getPluginIdentifier(), pluginLocation);
    }
    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(32, 32, 1L, TimeUnit.HOURS, new ArrayBlockingQueue<>(100));
    for (PluginBundle pluginBundle : bimServer.getPluginManager().getPluginBundles()) {
        SPluginBundleVersion installedVersion = pluginBundle.getPluginBundleVersion();
        PluginBundleIdentifier pluginBundleIdentifier = new PluginBundleIdentifier(installedVersion.getGroupId(), installedVersion.getArtifactId());
        PluginLocation<?> pluginLocation = repositoryKnownLocation.get(pluginBundleIdentifier);
        threadPoolExecutor.submit(new Runnable() {

            @Override
            public void run() {
                SPluginBundle sPluginBundle = processPluginLocation(pluginLocation, strictVersionChecking, bimserverVersion);
                if (sPluginBundle == null) {
                    // No versions found on repository
                    sPluginBundle = pluginBundle.getPluginBundle();
                }
                boolean found = false;
                for (SPluginBundleVersion sPluginBundleVersion : sPluginBundle.getAvailableVersions()) {
                    if (sPluginBundleVersion.getVersion().equals(pluginBundle.getPluginBundleVersion().getVersion())) {
                        found = true;
                    }
                }
                if (!found) {
                    sPluginBundle.getAvailableVersions().add(pluginBundle.getPluginBundleVersion());
                }
                sPluginBundle.setInstalledVersion(installedVersion);
                result.add(sPluginBundle);
            }
        });
    }
    threadPoolExecutor.shutdown();
    try {
        threadPoolExecutor.awaitTermination(1, TimeUnit.HOURS);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    Collections.sort(result, new Comparator<SPluginBundle>() {

        @Override
        public int compare(SPluginBundle o1, SPluginBundle o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    return result;
}
Also used : SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) HashMap(java.util.HashMap) SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) ArrayList(java.util.ArrayList) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) PluginBundleIdentifier(org.bimserver.plugins.PluginBundleIdentifier) PluginBundle(org.bimserver.plugins.PluginBundle) SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) PluginLocation(org.bimserver.plugins.PluginLocation) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) GitHubPluginRepository(org.bimserver.plugins.GitHubPluginRepository)

Example 4 with DefaultArtifactVersion

use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project sling by apache.

the class NewSlingBundleWizard method acceptsArchetype.

@Override
public boolean acceptsArchetype(Archetype archetype) {
    boolean isSlingBundleArchetype = archetype.getGroupId().equals("org.apache.sling") && archetype.getArtifactId().equals("sling-bundle-archetype");
    if (!isSlingBundleArchetype) {
        return false;
    }
    DefaultArtifactVersion version = new DefaultArtifactVersion(archetype.getVersion());
    // release 1.0.2 is the first known good release
    if (version.compareTo(new DefaultArtifactVersion("1.0.2")) < 0) {
        return false;
    }
    return true;
}
Also used : DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion)

Example 5 with DefaultArtifactVersion

use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project maven-git-versioning-extension by qoomon.

the class App method main.

public static void main(String[] args) throws Exception {
    Repository repository = new FileRepositoryBuilder().findGitDir(new File("/Users/bengt.brodersen/Workspace/git-sandbox")).build();
    ObjectId head = repository.resolve(Constants.HEAD);
    Optional<String> headTag = repository.getTags().values().stream().map(repository::peel).filter(ref -> {
        ObjectId objectId;
        if (ref.getPeeledObjectId() != null) {
            objectId = ref.getPeeledObjectId();
        } else {
            objectId = ref.getObjectId();
        }
        return objectId.equals(head);
    }).map(ref -> ref.getName().replaceFirst("^refs/tags/", "")).sorted((tagLeft, tagRight) -> {
        DefaultArtifactVersion tagVersionLeft = new DefaultArtifactVersion(tagLeft);
        DefaultArtifactVersion tagVersionRight = new DefaultArtifactVersion(tagRight);
        return Math.negateExact(tagVersionLeft.compareTo(tagVersionRight));
    }).findFirst();
    if (headTag.isPresent()) {
        System.out.println(headTag.get());
    } else {
        System.out.println("no tag");
    }
}
Also used : FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) Optional(java.util.Optional) Constants(org.eclipse.jgit.lib.Constants) Repository(org.eclipse.jgit.lib.Repository) File(java.io.File) ObjectId(org.eclipse.jgit.lib.ObjectId) Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder) File(java.io.File)

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