Search in sources :

Example 1 with GitHubPluginRepository

use of org.bimserver.plugins.GitHubPluginRepository 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 2 with GitHubPluginRepository

use of org.bimserver.plugins.GitHubPluginRepository 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)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)2 SPluginBundle (org.bimserver.interfaces.objects.SPluginBundle)2 GitHubPluginRepository (org.bimserver.plugins.GitHubPluginRepository)2 PluginBundle (org.bimserver.plugins.PluginBundle)2 HashMap (java.util.HashMap)1 SPluginBundleVersion (org.bimserver.interfaces.objects.SPluginBundleVersion)1 PluginBundleIdentifier (org.bimserver.plugins.PluginBundleIdentifier)1 PluginLocation (org.bimserver.plugins.PluginLocation)1