Search in sources :

Example 1 with PluginLocation

use of org.bimserver.plugins.PluginLocation 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)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)1 SPluginBundle (org.bimserver.interfaces.objects.SPluginBundle)1 SPluginBundleVersion (org.bimserver.interfaces.objects.SPluginBundleVersion)1 GitHubPluginRepository (org.bimserver.plugins.GitHubPluginRepository)1 PluginBundle (org.bimserver.plugins.PluginBundle)1 PluginBundleIdentifier (org.bimserver.plugins.PluginBundleIdentifier)1 PluginLocation (org.bimserver.plugins.PluginLocation)1