use of org.bimserver.interfaces.objects.SPluginBundle 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);
}
}
use of org.bimserver.interfaces.objects.SPluginBundle in project BIMserver by opensourceBIM.
the class PluginManager method update.
public PluginBundle update(PluginBundleVersionIdentifier pluginBundleVersionIdentifier, SPluginBundle sPluginBundle, SPluginBundleVersion pluginBundleVersion, Path jarFile, Path pomFile, List<SPluginInformation> plugins) throws Exception {
PluginBundle existingPluginBundle = pluginBundleIdentifierToPluginBundle.get(pluginBundleVersionIdentifier.getPluginBundleIdentifier());
if (existingPluginBundle == null) {
throw new UserException("No previous version of plugin bundle " + pluginBundleVersionIdentifier.getPluginBundleIdentifier() + " found");
}
try {
existingPluginBundle.close();
if (pluginBundleIdentifierToPluginBundle.remove(pluginBundleVersionIdentifier.getPluginBundleIdentifier()) == null) {
LOGGER.warn("Previous version of " + pluginBundleVersionIdentifier.getPluginBundleIdentifier() + " not found");
}
PluginBundleVersionIdentifier currentVersion = pluginBundleIdentifierToCurrentPluginBundleVersionIdentifier.get(pluginBundleVersionIdentifier.getPluginBundleIdentifier());
if (pluginBundleIdentifierToCurrentPluginBundleVersionIdentifier.remove(pluginBundleVersionIdentifier.getPluginBundleIdentifier()) == null) {
LOGGER.warn("Previous version of " + pluginBundleVersionIdentifier.getPluginBundleIdentifier() + " not found");
}
if (pluginBundleVersionIdentifierToPluginBundle.remove(currentVersion) == null) {
LOGGER.warn("Previous version (" + currentVersion + ") of " + pluginBundleVersionIdentifier.getPluginBundleIdentifier() + " not found");
}
for (PluginContext pluginContext : existingPluginBundle) {
Set<PluginContext> set = implementations.get(pluginContext.getPluginInterface());
set.remove(pluginContext);
}
if (existingPluginBundle.getPluginBundle().getInstalledVersion().getType() == SPluginBundleType.MAVEN) {
Path target = pluginsDir.resolve(currentVersion.getFileName());
Files.delete(target);
}
// for (PluginContext pluginContext : existingPluginBundle) {
// pluginChangeListener.pluginUninstalled(pluginContext);
// }
} catch (IOException e) {
LOGGER.error("", e);
}
Path target = pluginsDir.resolve(pluginBundleVersionIdentifier.getFileName());
if (Files.exists(target)) {
throw new PluginException("This plugin has already been installed " + target.getFileName().toString());
}
Files.copy(jarFile, target);
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
Model model = null;
try (FileReader fileReader = new FileReader(pomFile.toFile())) {
model = mavenreader.read(fileReader);
}
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 (false) {
// 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"))) {
throw new Exception("Required dependency " + pluginBundleIdentifier + " is not installed");
} else {
MavenPluginLocation mavenPluginLocation = mavenPluginRepository.getPluginLocation(model.getRepositories().get(0).getUrl(), 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) {
}
}
}
}
}
PluginBundle pluginBundle = null;
// Stage 1, load all plugins from the JAR file and initialize them
try {
pluginBundle = loadPluginsFromJar(pluginBundleVersionIdentifier, target, sPluginBundle, pluginBundleVersion, delegatingClassLoader);
for (SPluginInformation sPluginInformation : plugins) {
if (sPluginInformation.isEnabled()) {
PluginContext pluginContext = pluginBundle.getPluginContext(sPluginInformation.getIdentifier());
pluginContext.getPlugin().init(pluginContext);
}
}
} catch (Exception e) {
Files.delete(target);
LOGGER.error("", e);
throw e;
}
// uninstalled
try {
long pluginBundleVersionId = pluginChangeListener.pluginBundleUpdated(pluginBundle);
for (SPluginInformation sPluginInformation : plugins) {
if (sPluginInformation.isEnabled()) {
PluginContext pluginContext = pluginBundle.getPluginContext(sPluginInformation.getIdentifier());
pluginChangeListener.pluginUpdated(pluginBundleVersionId, pluginContext, sPluginInformation);
}
}
return pluginBundle;
} catch (Exception e) {
uninstall(pluginBundleVersionIdentifier);
LOGGER.error("", e);
throw e;
}
}
use of org.bimserver.interfaces.objects.SPluginBundle in project BIMserver by opensourceBIM.
the class PluginBundleImpl method getPluginBundle.
@Override
public SPluginBundle getPluginBundle() {
SPluginBundle result = new SPluginBundle();
result.setName(sPluginBundle.getName());
result.setOrganization(sPluginBundle.getOrganization());
if (sPluginBundle.getInstalledVersion() != null) {
SPluginBundleVersion installedVersion = new SPluginBundleVersion();
installedVersion.setArtifactId(sPluginBundle.getInstalledVersion().getArtifactId());
installedVersion.setDescription(sPluginBundle.getInstalledVersion().getDescription());
installedVersion.setGroupId(sPluginBundle.getInstalledVersion().getGroupId());
installedVersion.setIcon(sPluginBundle.getInstalledVersion().getIcon());
installedVersion.setMismatch(sPluginBundle.getInstalledVersion().isMismatch());
installedVersion.setName(sPluginBundle.getInstalledVersion().getName());
installedVersion.setOrganization(sPluginBundle.getInstalledVersion().getOrganization());
installedVersion.setRepository(sPluginBundle.getInstalledVersion().getRepository());
installedVersion.setType(sPluginBundle.getInstalledVersion().getType());
installedVersion.setVersion(sPluginBundle.getInstalledVersion().getVersion());
result.setInstalledVersion(installedVersion);
}
return result;
}
use of org.bimserver.interfaces.objects.SPluginBundle 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;
}
use of org.bimserver.interfaces.objects.SPluginBundle 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;
}
Aggregations