use of org.bimserver.interfaces.objects.SPluginInformation in project BIMserver by opensourceBIM.
the class PluginManager method loadPlugin.
public PluginBundle loadPlugin(PluginBundleVersionIdentifier pluginBundleVersionIdentifier, Path target, SPluginBundle sPluginBundle, SPluginBundleVersion pluginBundleVersion, List<SPluginInformation> plugins, ClassLoader parentClassLoader) throws Exception {
PluginBundle pluginBundle = null;
// Stage 1, load all plugins from the JAR file and initialize them
try {
pluginBundle = loadPluginsFromJar(pluginBundleVersionIdentifier, target, sPluginBundle, pluginBundleVersion, parentClassLoader);
if (plugins.isEmpty()) {
LOGGER.warn("No plugins given to install for bundle " + sPluginBundle.getName());
}
for (SPluginInformation sPluginInformation : plugins) {
if (sPluginInformation.isEnabled()) {
PluginContext pluginContext = pluginBundle.getPluginContext(sPluginInformation.getIdentifier());
if (pluginContext == null) {
LOGGER.info("No plugin context found for " + sPluginInformation.getIdentifier());
} else {
pluginContext.getPlugin().init(pluginContext);
}
}
}
} catch (Exception e) {
e.printStackTrace();
if (pluginBundle != null) {
pluginBundle.close();
}
pluginBundleVersionIdentifierToPluginBundle.remove(pluginBundleVersionIdentifier);
pluginBundleIdentifierToPluginBundle.remove(pluginBundleVersionIdentifier.getPluginBundleIdentifier());
Files.delete(target);
LOGGER.error("", e);
throw e;
}
// uninstalled
try {
long pluginBundleVersionId = pluginChangeListener.pluginBundleInstalled(pluginBundle);
for (SPluginInformation sPluginInformation : plugins) {
if (sPluginInformation.isEnabled()) {
PluginContext pluginContext = pluginBundle.getPluginContext(sPluginInformation.getIdentifier());
pluginChangeListener.pluginInstalled(pluginBundleVersionId, pluginContext, sPluginInformation);
}
}
return pluginBundle;
} catch (Exception e) {
uninstall(pluginBundleVersionIdentifier);
LOGGER.error("", e);
throw e;
}
}
use of org.bimserver.interfaces.objects.SPluginInformation 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);
}
use of org.bimserver.interfaces.objects.SPluginInformation in project BIMserver by opensourceBIM.
the class PluginManager method loadPluginsFromEclipseProject.
public PluginBundle loadPluginsFromEclipseProject(Path projectRoot) throws PluginException {
try {
if (!Files.isDirectory(projectRoot)) {
throw new PluginException("No directory: " + projectRoot.toString());
}
final Path pluginFolder = projectRoot.resolve("plugin");
if (!Files.isDirectory(pluginFolder)) {
throw new PluginException("No 'plugin' directory found in " + projectRoot.toString());
}
Path pluginFile = pluginFolder.resolve("plugin.xml");
if (!Files.exists(pluginFile)) {
throw new PluginException("No 'plugin.xml' found in " + pluginFolder.toString());
}
PluginDescriptor pluginDescriptor = getPluginDescriptor(Files.newInputStream(pluginFile));
Path pomFile = projectRoot.resolve("pom.xml");
if (!Files.exists(pomFile)) {
throw new PluginException("No pom.xml found in " + projectRoot);
}
// Path packageFile = projectRoot.resolve("package.json");
// if (Files.exists(packageFile)) {
// return loadJavaScriptProject(projectRoot, packageFile,
// pluginFolder, pluginDescriptor);
// } else if (Files.exists(pomFile)) {
PluginBundle pluginBundle = loadJavaProject(projectRoot, pomFile, pluginFolder, pluginDescriptor);
// } else {
// throw new PluginException("No pom.xml or package.json found in "
// + projectRoot.toString());
// }
List<SPluginInformation> plugins = new ArrayList<>();
processPluginDescriptor(pluginDescriptor, plugins);
for (SPluginInformation sPluginInformation : plugins) {
if (sPluginInformation.isEnabled()) {
// For local plugins, we assume to install for all users
sPluginInformation.setInstallForAllUsers(true);
sPluginInformation.setInstallForNewUsers(true);
PluginContext pluginContext = pluginBundle.getPluginContext(sPluginInformation.getIdentifier());
if (pluginContext == null) {
throw new PluginException("No plugin context found for " + sPluginInformation.getIdentifier());
}
pluginContext.getPlugin().init(pluginContext);
}
}
try {
long pluginBundleVersionId = pluginChangeListener.pluginBundleInstalled(pluginBundle);
for (SPluginInformation sPluginInformation : plugins) {
if (sPluginInformation.isEnabled()) {
PluginContext pluginContext = pluginBundle.getPluginContext(sPluginInformation.getIdentifier());
pluginChangeListener.pluginInstalled(pluginBundleVersionId, pluginContext, sPluginInformation);
}
}
} catch (Exception e) {
LOGGER.error("", e);
throw new PluginException(e);
}
return pluginBundle;
} catch (JAXBException e) {
throw new PluginException(e);
} catch (FileNotFoundException e) {
throw new PluginException(e);
} catch (IOException e) {
throw new PluginException(e);
} catch (XmlPullParserException e) {
throw new PluginException(e);
}
}
use of org.bimserver.interfaces.objects.SPluginInformation in project BIMserver by opensourceBIM.
the class PluginManager method processPluginDescriptor.
private void processPluginDescriptor(PluginDescriptor pluginDescriptor, List<SPluginInformation> list) {
for (AbstractPlugin pluginImplementation : pluginDescriptor.getPlugins()) {
if (pluginImplementation instanceof JavaPlugin) {
JavaPlugin javaPlugin = (JavaPlugin) pluginImplementation;
SPluginInformation sPluginInformation = new SPluginInformation();
String name = javaPlugin.getName();
// TODO when all plugins have a name, this code can go
if (name == null) {
name = javaPlugin.getImplementationClass();
}
sPluginInformation.setName(name);
sPluginInformation.setDescription(javaPlugin.getDescription());
sPluginInformation.setEnabled(true);
// For java plugins we use the implementation class as
// identifier
sPluginInformation.setIdentifier(javaPlugin.getImplementationClass());
sPluginInformation.setType(getPluginTypeFromClass(javaPlugin.getInterfaceClass()));
list.add(sPluginInformation);
} else if (pluginImplementation instanceof org.bimserver.plugins.WebModulePlugin) {
org.bimserver.plugins.WebModulePlugin webModulePlugin = (org.bimserver.plugins.WebModulePlugin) pluginImplementation;
SPluginInformation sPluginInformation = new SPluginInformation();
sPluginInformation.setIdentifier(webModulePlugin.getIdentifier());
sPluginInformation.setName(webModulePlugin.getName());
sPluginInformation.setDescription(webModulePlugin.getDescription());
sPluginInformation.setType(SPluginType.WEB_MODULE);
sPluginInformation.setEnabled(true);
list.add(sPluginInformation);
}
}
}
use of org.bimserver.interfaces.objects.SPluginInformation in project BIMserver by opensourceBIM.
the class BimServer method initDatabaseDependantItems.
private void initDatabaseDependantItems() throws BimserverDatabaseException {
notificationsManager.init();
getSerializerFactory().init(pluginManager, bimDatabase, this);
try {
DatabaseSession session = bimDatabase.createSession();
try {
updatePlugins(session);
session.commit();
} catch (ServiceException e) {
LOGGER.error("", e);
} finally {
session.close();
}
session = bimDatabase.createSession();
// createDatabaseObjects(session);
ServerSettings serverSettings = serverSettingsCache.getServerSettings();
for (Entry<PluginContext, WebModulePlugin> entry : pluginManager.getAllWebPlugins(true).entrySet()) {
WebModulePluginConfiguration webPluginConfiguration = find(serverSettings.getWebModules(), entry.getKey().getIdentifier());
if (webPluginConfiguration == null) {
webPluginConfiguration = session.create(WebModulePluginConfiguration.class);
serverSettings.getWebModules().add(webPluginConfiguration);
PluginDescriptor pluginDescriptor = getPluginDescriptor(session, entry.getKey().getIdentifier());
if (pluginDescriptor == null) {
throw new BimserverDatabaseException("No plugin descriptor found: " + entry.getKey().getIdentifier());
}
genericPluginConversion(entry.getKey(), session, webPluginConfiguration, pluginDescriptor);
} else {
if (webPluginConfiguration == serverSettings.getWebModule()) {
setDefaultWebModule(entry.getValue());
}
}
}
// Set the default
// if (serverSettings.getWebModule() == null) {
// WebModulePluginConfiguration bimviewsWebModule = findWebModule(serverSettings, "BIM Views");
// if (bimviewsWebModule != null) {
// serverSettings.setWebModule(bimviewsWebModule);
// setDefaultWebModule(pluginManager.getWebModulePlugin(bimviewsWebModule.getPluginDescriptor().getPluginClassName(), true));
// } else {
// WebModulePluginConfiguration defaultWebModule = findWebModule(serverSettings, "org.bimserver.defaultwebmodule.DefaultWebModulePlugin");
// if (defaultWebModule != null) {
// serverSettings.setWebModule(defaultWebModule);
// setDefaultWebModule(pluginManager.getWebModulePlugin(defaultWebModule.getPluginDescriptor().getPluginClassName(), true));
// }
// }
// }
session.store(serverSettings);
Condition condition = new AttributeCondition(StorePackage.eINSTANCE.getUser_Username(), new StringLiteral("system"));
User systemUser = session.querySingle(condition, User.class, OldQuery.getDefault());
ServerStarted serverStarted = session.create(ServerStarted.class);
serverStarted.setDate(new Date());
serverStarted.setAccessMethod(AccessMethod.INTERNAL);
serverStarted.setExecutor(systemUser);
try {
session.store(serverStarted);
session.commit();
} catch (BimserverLockConflictException e) {
throw new BimserverDatabaseException(e);
} catch (ServiceException e) {
throw new BimserverDatabaseException(e);
} finally {
session.close();
}
webModules = new HashMap<String, WebModulePlugin>();
DatabaseSession ses = bimDatabase.createSession();
try {
List<WebModulePluginConfiguration> webModuleConfigurations = serverSettingsCache.getServerSettings().getWebModules();
for (WebModulePluginConfiguration webModulePluginConfiguration : webModuleConfigurations) {
String contextPath = "";
for (Parameter parameter : webModulePluginConfiguration.getSettings().getParameters()) {
if (parameter.getName().equals("contextPath")) {
contextPath = ((StringType) parameter.getValue()).getValue();
}
}
String identifier = webModulePluginConfiguration.getPluginDescriptor().getIdentifier();
webModules.put(contextPath, (WebModulePlugin) pluginManager.getPlugin(identifier, true));
}
// if (serverSettingsCache.getServerSettings().getWebModule() !=
// null) {
// defaultWebModule = (WebModulePlugin)
// pluginManager.getPlugin(serverSettingsCache.getServerSettings().getWebModule().getPluginDescriptor().getPluginClassName(),
// true);
// }
} finally {
ses.close();
}
Integer protocolBuffersPort = getServerSettingsCache().getServerSettings().getProtocolBuffersPort();
if (protocolBuffersPort >= 1 && protocolBuffersPort <= 65535) {
try {
protocolBuffersServer = new ProtocolBuffersServer(protocolBuffersMetaData, serviceFactory, servicesMap, protocolBuffersPort);
protocolBuffersServer.start();
} catch (Exception e) {
LOGGER.error("", e);
}
}
bimServerClientFactory = new DirectBimServerClientFactory<ServiceInterface>(serverSettingsCache.getServerSettings().getSiteAddress(), serviceFactory, servicesMap, pluginManager, metaDataManager);
pluginManager.setBimServerClientFactory(bimServerClientFactory);
try (DatabaseSession session2 = bimDatabase.createSession()) {
IfcModelInterface pluginBundleVersions = session2.getAllOfType(StorePackage.eINSTANCE.getPluginBundleVersion(), OldQuery.getDefault());
for (PluginBundleVersion pluginBundleVersion : pluginBundleVersions.getAll(PluginBundleVersion.class)) {
if (pluginBundleVersion.getType() == PluginBundleType.MAVEN || pluginBundleVersion.getType() == PluginBundleType.LOCAL) {
PluginBundleVersionIdentifier pluginBundleVersionIdentifier = new PluginBundleVersionIdentifier(pluginBundleVersion.getGroupId(), pluginBundleVersion.getArtifactId(), pluginBundleVersion.getVersion());
IfcModelInterface pluginDescriptors = session2.getAllOfType(StorePackage.eINSTANCE.getPluginDescriptor(), OldQuery.getDefault());
List<SPluginInformation> plugins = new ArrayList<>();
for (PluginDescriptor pluginDescriptor : pluginDescriptors.getAll(PluginDescriptor.class)) {
if (pluginDescriptor.getPluginBundleVersion() == pluginBundleVersion && pluginDescriptor.getEnabled()) {
SPluginInformation sPluginInformation = new SPluginInformation();
sPluginInformation.setEnabled(true);
sPluginInformation.setDescription(pluginDescriptor.getDescription());
sPluginInformation.setIdentifier(pluginDescriptor.getIdentifier());
sPluginInformation.setInstallForAllUsers(pluginDescriptor.isInstallForNewUsers());
sPluginInformation.setInstallForNewUsers(pluginDescriptor.isInstallForNewUsers());
sPluginInformation.setName(pluginDescriptor.getName());
sPluginInformation.setType(pluginManager.getPluginTypeFromClass(pluginDescriptor.getPluginClassName()));
plugins.add(sPluginInformation);
}
}
try {
pluginManager.loadFromPluginDir(pluginBundleVersionIdentifier, getSConverter().convertToSObject(pluginBundleVersion), plugins, serverSettingsCache.getServerSettings().isPluginStrictVersionChecking());
} catch (Exception e) {
LOGGER.error("", e);
}
}
}
} catch (Exception e) {
throw new BimserverDatabaseException(e);
}
} catch (BimserverLockConflictException e) {
throw new BimserverDatabaseException(e);
// } catch (PluginException e) {
// throw new BimserverDatabaseException(e);
}
}
Aggregations