use of org.bimserver.interfaces.objects.SPluginBundleVersion in project BIMserver by opensourceBIM.
the class BimServer method start.
public void start() throws DatabaseInitException, BimserverDatabaseException, PluginException, DatabaseRestartRequiredException, ServerException {
try {
LOGGER.debug("Starting BIMserver");
if (versionChecker != null) {
SVersion localVersion = versionChecker.getLocalVersion();
if (localVersion != null) {
LOGGER.info("Version: " + localVersion.getFullString());
} else {
LOGGER.info("Unknown version");
}
} else {
LOGGER.info("Unknown version");
}
try {
pluginManager.setPluginChangeListener(new PluginChangeListener() {
@Override
public void pluginStateChanged(PluginContext pluginContext, boolean enabled) {
// Reflect this change also in the database
Condition pluginCondition = new AttributeCondition(StorePackage.eINSTANCE.getPluginDescriptor_PluginClassName(), new StringLiteral(pluginContext.getPlugin().getClass().getName()));
DatabaseSession session = bimDatabase.createSession();
try {
Map<Long, PluginDescriptor> pluginsFound = session.query(pluginCondition, PluginDescriptor.class, OldQuery.getDefault());
if (pluginsFound.size() == 0) {
LOGGER.error("Error changing plugin-state in database, plugin " + pluginContext.getPlugin().getClass().getName() + " not found");
} else if (pluginsFound.size() == 1) {
PluginDescriptor pluginConfiguration = pluginsFound.values().iterator().next();
pluginConfiguration.setEnabled(pluginContext.isEnabled());
session.store(pluginConfiguration);
} else {
LOGGER.error("Error, too many plugin-objects found in database for name " + pluginContext.getPlugin().getClass().getName());
}
session.commit();
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} catch (ServiceException e) {
LOGGER.error("", e);
} finally {
session.close();
}
}
@Override
public long pluginBundleUpdated(PluginBundle pluginBundle) {
SPluginBundleVersion sPluginBundleVersion = pluginBundle.getPluginBundleVersion();
try (DatabaseSession session = bimDatabase.createSession()) {
PluginBundleVersion current = null;
IfcModelInterface allOfType = session.getAllOfType(StorePackage.eINSTANCE.getPluginBundleVersion(), OldQuery.getDefault());
for (PluginBundleVersion pbv : allOfType.getAll(PluginBundleVersion.class)) {
if (pbv.getGroupId().equals(pluginBundle.getPluginBundleVersion().getGroupId()) && pbv.getArtifactId().equals(pluginBundle.getPluginBundleVersion().getArtifactId())) {
// Current pluginBundle found
current = pbv;
}
}
if (current != null) {
current.setDescription(sPluginBundleVersion.getArtifactId());
current.setIcon(sPluginBundleVersion.getIcon());
current.setMismatch(sPluginBundleVersion.isMismatch());
current.setRepository(sPluginBundleVersion.getRepository());
current.setType(getSConverter().convertFromSObject(sPluginBundleVersion.getType()));
current.setVersion(sPluginBundleVersion.getVersion());
current.setOrganization(sPluginBundleVersion.getOrganization());
current.setName(sPluginBundleVersion.getName());
current.setDate(sPluginBundleVersion.getDate());
session.store(current);
session.commit();
}
return current.getOid();
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} catch (ServiceException e) {
LOGGER.error("", e);
}
return -1;
}
@Override
public void pluginUpdated(long pluginBundleVersionId, PluginContext newPluginContext, SPluginInformation sPluginInformation) throws BimserverDatabaseException {
try (DatabaseSession session = bimDatabase.createSession()) {
Plugin plugin = newPluginContext.getPlugin();
Condition pluginCondition = new AttributeCondition(StorePackage.eINSTANCE.getPluginDescriptor_Identifier(), new StringLiteral(newPluginContext.getIdentifier()));
Map<Long, PluginDescriptor> pluginsFound = session.query(pluginCondition, PluginDescriptor.class, OldQuery.getDefault());
for (PluginDescriptor pluginDescriptor : pluginsFound.values()) {
pluginDescriptor.setIdentifier(newPluginContext.getIdentifier());
pluginDescriptor.setPluginClassName(plugin.getClass().getName());
pluginDescriptor.setDescription(newPluginContext.getDescription());
pluginDescriptor.setName(sPluginInformation.getName());
pluginDescriptor.setLocation(newPluginContext.getLocation().toString());
pluginDescriptor.setPluginInterfaceClassName(getPluginInterface(plugin.getClass()).getName());
pluginDescriptor.setEnabled(sPluginInformation.isEnabled());
pluginDescriptor.setInstallForNewUsers(sPluginInformation.isInstallForNewUsers());
PluginBundleVersion value = session.get(pluginBundleVersionId, OldQuery.getDefault());
pluginDescriptor.setPluginBundleVersion(value);
session.store(pluginDescriptor);
if (sPluginInformation.isInstallForAllUsers()) {
IfcModelInterface allOfType = session.getAllOfType(StorePackage.eINSTANCE.getUser(), OldQuery.getDefault());
for (User user : allOfType.getAll(User.class)) {
if (user.getState() == ObjectState.ACTIVE) {
updateUserPlugin(session, user, pluginDescriptor, newPluginContext);
}
}
}
if (newPluginContext.getPlugin() instanceof WebModulePlugin) {
ServerSettings serverSettings = getServerSettingsCache().getServerSettings();
WebModulePluginConfiguration webPluginConfiguration = find(serverSettings.getWebModules(), newPluginContext.getIdentifier());
if (webPluginConfiguration == null) {
webPluginConfiguration = session.create(WebModulePluginConfiguration.class);
serverSettings.getWebModules().add(webPluginConfiguration);
}
genericPluginConversion(newPluginContext, session, webPluginConfiguration, pluginDescriptor);
String contextPath = "";
for (Parameter parameter : webPluginConfiguration.getSettings().getParameters()) {
if (parameter.getName().equals("contextPath")) {
contextPath = ((StringType) parameter.getValue()).getValue();
}
}
String identifier = webPluginConfiguration.getPluginDescriptor().getIdentifier();
webModules.put(contextPath, (WebModulePlugin) pluginManager.getPlugin(identifier, true));
} else if (newPluginContext.getPlugin() instanceof ServicePlugin) {
IfcModelInterface allOfType = session.getAllOfType(StorePackage.eINSTANCE.getInternalServicePluginConfiguration(), OldQuery.getDefault());
List<InternalServicePluginConfiguration> all = new ArrayList<>(allOfType.getAll(InternalServicePluginConfiguration.class));
for (InternalServicePluginConfiguration internalServicePluginConfiguration : all) {
if (internalServicePluginConfiguration.getPluginDescriptor().getIdentifier().equals(newPluginContext.getIdentifier())) {
activateService(internalServicePluginConfiguration.getUserSettings().getOid(), internalServicePluginConfiguration);
}
}
}
}
try {
session.commit();
} catch (ServiceException e) {
LOGGER.error("", e);
}
}
}
@Override
public void pluginInstalled(long pluginBundleVersionId, PluginContext pluginContext, SPluginInformation sPluginInformation) throws BimserverDatabaseException {
try (DatabaseSession session = bimDatabase.createSession()) {
Plugin plugin = pluginContext.getPlugin();
Condition pluginCondition = new AttributeCondition(StorePackage.eINSTANCE.getPluginDescriptor_Identifier(), new StringLiteral(pluginContext.getIdentifier()));
Map<Long, PluginDescriptor> pluginsFound = session.query(pluginCondition, PluginDescriptor.class, OldQuery.getDefault());
PluginDescriptor pluginDescriptor = null;
if (pluginsFound.size() > 0) {
pluginDescriptor = pluginsFound.values().iterator().next();
} else {
pluginDescriptor = session.create(PluginDescriptor.class);
}
pluginDescriptor.setIdentifier(pluginContext.getIdentifier());
pluginDescriptor.setPluginClassName(plugin.getClass().getName());
pluginDescriptor.setDescription(pluginContext.getDescription());
pluginDescriptor.setName(sPluginInformation.getName());
pluginDescriptor.setLocation(pluginContext.getLocation().toString());
pluginDescriptor.setPluginInterfaceClassName(getPluginInterface(plugin.getClass()).getName());
pluginDescriptor.setEnabled(sPluginInformation.isEnabled());
pluginDescriptor.setInstallForNewUsers(sPluginInformation.isInstallForNewUsers());
pluginDescriptor.setPluginBundleVersion(session.get(pluginBundleVersionId, OldQuery.getDefault()));
if (sPluginInformation.isInstallForAllUsers()) {
IfcModelInterface allOfType = session.getAllOfType(StorePackage.eINSTANCE.getUser(), OldQuery.getDefault());
for (User user : allOfType.getAll(User.class)) {
if (user.getState() == ObjectState.ACTIVE) {
updateUserPlugin(session, user, pluginDescriptor, pluginContext);
}
}
}
if (pluginContext.getPlugin() instanceof WebModulePlugin) {
ServerSettings serverSettings = getServerSettingsCache().getServerSettings();
WebModulePluginConfiguration webPluginConfiguration = find(serverSettings.getWebModules(), pluginContext.getIdentifier());
if (webPluginConfiguration == null) {
webPluginConfiguration = session.create(WebModulePluginConfiguration.class);
serverSettings.getWebModules().add(webPluginConfiguration);
genericPluginConversion(pluginContext, session, webPluginConfiguration, pluginDescriptor);
session.store(serverSettings);
}
String contextPath = "";
for (Parameter parameter : webPluginConfiguration.getSettings().getParameters()) {
if (parameter.getName().equals("contextPath")) {
contextPath = ((StringType) parameter.getValue()).getValue();
}
}
webModules.put(contextPath, (WebModulePlugin) pluginManager.getPlugin(pluginContext.getIdentifier(), true));
}
try {
session.commit();
} catch (ServiceException e) {
LOGGER.error("", e);
}
}
}
@Override
public void pluginUninstalled(PluginContext pluginContext) {
// Reflect this change also in the database
Condition pluginCondition = new AttributeCondition(StorePackage.eINSTANCE.getPluginDescriptor_Identifier(), new StringLiteral(pluginContext.getIdentifier()));
DatabaseSession session = bimDatabase.createSession();
try {
Map<Long, PluginDescriptor> pluginsFound = session.query(pluginCondition, PluginDescriptor.class, OldQuery.getDefault());
if (pluginsFound.size() == 0) {
LOGGER.error("Error removing plugin-state in database, plugin " + pluginContext.getPlugin().getClass().getName() + " not found");
} else if (pluginsFound.size() == 1) {
PluginDescriptor pluginDescriptor = pluginsFound.values().iterator().next();
for (PluginConfiguration pluginConfiguration : pluginDescriptor.getConfigurations()) {
session.delete(pluginConfiguration, -1);
}
if (pluginContext.getPlugin() instanceof WebModulePlugin) {
ServerSettings serverSettings = getServerSettingsCache().getServerSettings();
WebModulePluginConfiguration webPluginConfiguration = find(serverSettings.getWebModules(), pluginContext.getIdentifier());
serverSettings.getWebModules().remove(webPluginConfiguration);
session.store(serverSettings);
String contextPath = "";
for (Parameter parameter : webPluginConfiguration.getSettings().getParameters()) {
if (parameter.getName().equals("contextPath")) {
contextPath = ((StringType) parameter.getValue()).getValue();
}
}
webModules.remove(contextPath);
}
session.delete(pluginDescriptor, -1);
} else {
LOGGER.error("Error, too many plugin-objects found in database for name " + pluginContext.getPlugin().getClass().getName());
}
session.commit();
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} catch (ServiceException e) {
LOGGER.error("", e);
} finally {
session.close();
}
}
@Override
public long pluginBundleInstalled(PluginBundle pluginBundle) {
try (DatabaseSession session = bimDatabase.createSession()) {
PluginBundleVersion current = null;
IfcModelInterface allOfType = session.getAllOfType(StorePackage.eINSTANCE.getPluginBundleVersion(), OldQuery.getDefault());
for (PluginBundleVersion pbv : allOfType.getAll(PluginBundleVersion.class)) {
if (pbv.getGroupId().equals(pluginBundle.getPluginBundleVersion().getGroupId()) && pbv.getArtifactId().equals(pluginBundle.getPluginBundleVersion().getArtifactId())) {
// Current pluginBundle found
current = pbv;
}
}
PluginBundleVersion pluginBundleVersion = null;
if (current != null) {
pluginBundleVersion = current;
session.store(pluginBundleVersion);
} else {
pluginBundleVersion = session.create(PluginBundleVersion.class);
}
SPluginBundleVersion sPluginBundleVersion = pluginBundle.getPluginBundleVersion();
// SConverter should be used here, but it does not seem to trigger the database session in the rights way, just copying over field for now
pluginBundleVersion.setArtifactId(sPluginBundleVersion.getArtifactId());
pluginBundleVersion.setDescription(sPluginBundleVersion.getArtifactId());
pluginBundleVersion.setGroupId(sPluginBundleVersion.getGroupId());
pluginBundleVersion.setIcon(sPluginBundleVersion.getIcon());
pluginBundleVersion.setMismatch(sPluginBundleVersion.isMismatch());
pluginBundleVersion.setRepository(sPluginBundleVersion.getRepository());
pluginBundleVersion.setType(getSConverter().convertFromSObject(sPluginBundleVersion.getType()));
pluginBundleVersion.setVersion(sPluginBundleVersion.getVersion());
pluginBundleVersion.setOrganization(sPluginBundleVersion.getOrganization());
pluginBundleVersion.setName(sPluginBundleVersion.getName());
pluginBundleVersion.setDate(sPluginBundleVersion.getDate());
session.commit();
return pluginBundleVersion.getOid();
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} catch (ServiceException e) {
LOGGER.error("", e);
}
return -1;
}
@Override
public void pluginBundleUninstalled(PluginBundle pluginBundle) {
}
});
} catch (Exception e) {
LOGGER.error("", e);
}
try {
metaDataManager.init();
pluginManager.initAllLoadedPlugins();
} catch (PluginException e) {
LOGGER.error("", e);
}
serverStartTime = new GregorianCalendar();
longActionManager = new LongActionManager();
Set<EPackage> packages = new LinkedHashSet<>();
packages.add(Ifc2x3tc1Package.eINSTANCE);
packages.add(Ifc4Package.eINSTANCE);
templateEngine = new TemplateEngine();
URL emailTemplates = config.getResourceFetcher().getResource("emailtemplates/");
if (emailTemplates != null) {
templateEngine.init(emailTemplates);
} else {
LOGGER.info("No email templates found");
}
Path databaseDir = config.getHomeDir().resolve("database");
BerkeleyKeyValueStore keyValueStore = new BerkeleyKeyValueStore(databaseDir);
schemaConverterManager.registerConverter(new Ifc2x3tc1ToIfc4SchemaConverterFactory());
schemaConverterManager.registerConverter(new Ifc4ToIfc2x3tc1SchemaConverterFactory());
metricsRegistry = new MetricsRegistry();
Path mavenPath = config.getHomeDir().resolve("maven");
if (!Files.exists(mavenPath)) {
Files.createDirectories(mavenPath);
}
mavenPluginRepository = new MavenPluginRepository(mavenPath, "http://central.maven.org/maven2", "~/.m2/repository");
OldQuery.setPackageMetaDataForDefaultQuery(metaDataManager.getPackageMetaData("store"));
bimDatabase = new Database(this, packages, keyValueStore, metaDataManager);
try {
bimDatabase.init();
} catch (DatabaseRestartRequiredException e) {
bimDatabase.close();
keyValueStore = new BerkeleyKeyValueStore(databaseDir);
bimDatabase = new Database(this, packages, keyValueStore, metaDataManager);
try {
bimDatabase.init();
} catch (InconsistentModelsException e1) {
LOGGER.error("", e);
serverInfoManager.setServerState(ServerState.FATAL_ERROR);
serverInfoManager.setErrorMessage("Inconsistent models");
}
} catch (InconsistentModelsException e) {
LOGGER.error("", e);
serverInfoManager.setServerState(ServerState.FATAL_ERROR);
serverInfoManager.setErrorMessage("Inconsistent models");
}
try (DatabaseSession encsession = bimDatabase.createSession()) {
byte[] encryptionkeyBytes = null;
if (!bimDatabase.getRegistry().has(ENCRYPTIONKEY, encsession)) {
encryptionkeyBytes = new byte[16];
new SecureRandom().nextBytes(encryptionkeyBytes);
bimDatabase.getRegistry().save(ENCRYPTIONKEY, encryptionkeyBytes, encsession);
encsession.commit();
} else {
encryptionkeyBytes = bimDatabase.getRegistry().readByteArray(ENCRYPTIONKEY, encsession);
}
encryptionkey = new SecretKeySpec(encryptionkeyBytes, "AES");
}
cleanupStaleData();
protocolBuffersMetaData = new ProtocolBuffersMetaData();
protocolBuffersMetaData.load(servicesMap, ProtocolBuffersBimServerClientFactory.class);
serverInfoManager.init(this);
webModuleManager = new WebModuleManager(this);
jsonHandler = new JsonHandler(this);
serializerFactory = new SerializerFactory();
serverSettingsCache = new ServerSettingsCache(bimDatabase);
serverInfoManager.update();
// int renderEngineProcesses = getServerSettingsCache().getServerSettings().getRenderEngineProcesses();
// RenderEnginePoolFactory renderEnginePoolFactory = new CommonsPoolingRenderEnginePoolFactory(renderEngineProcesses);
RenderEnginePoolFactory renderEnginePoolFactory = new NoPoolingRenderEnginePoolFactory();
renderEnginePools = new RenderEnginePools(this, renderEnginePoolFactory);
if (serverInfoManager.getServerState() == ServerState.MIGRATION_REQUIRED) {
serverInfoManager.registerStateChangeListener(new StateChangeListener() {
@Override
public void stateChanged(ServerState oldState, ServerState newState) {
if (oldState == ServerState.MIGRATION_REQUIRED && newState == ServerState.RUNNING) {
try {
initDatabaseDependantItems();
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
}
}
}
});
} else {
initDatabaseDependantItems();
}
mailSystem = new MailSystem(this);
diskCacheManager = new DiskCacheManager(this, config.getHomeDir().resolve("cache"));
newDiskCacheManager = new NewDiskCacheManager(this, config.getHomeDir().resolve("cache"));
mergerFactory = new MergerFactory(this);
RealtimeReflectorFactoryBuilder factoryBuilder = new RealtimeReflectorFactoryBuilder(servicesMap);
reflectorFactory = factoryBuilder.newReflectorFactory();
if (reflectorFactory == null) {
throw new RuntimeException("No reflector factory!");
}
servicesMap.setReflectorFactory(reflectorFactory);
bimScheduler = new JobScheduler(this);
bimScheduler.start();
if (config.isStartEmbeddedWebServer()) {
embeddedWebServer.start();
}
if (config.isStartCommandLine()) {
commandLine = new CommandLine(this);
commandLine.start();
}
if (getServerInfoManager().getServerState() == ServerState.SETUP) {
getServerInfoManager().setServerState(ServerState.RUNNING);
}
} catch (Throwable e) {
LOGGER.error("", e);
serverInfoManager.setErrorMessage(e.getMessage());
}
}
use of org.bimserver.interfaces.objects.SPluginBundleVersion 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.SPluginBundleVersion 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;
}
use of org.bimserver.interfaces.objects.SPluginBundleVersion in project BIMserver by opensourceBIM.
the class PluginBundleDatabaseAction method processMavenPluginLocation.
public SPluginBundle processMavenPluginLocation(MavenPluginLocation mavenPluginLocation, boolean strictVersionChecking, ArtifactVersion bimserverVersion) {
SPluginBundle pluginBundle = new SPluginBundle();
boolean usefulBundle = false;
for (PluginVersion pluginVersion : mavenPluginLocation.getAllVersions()) {
if (pluginVersion instanceof MavenPluginVersion) {
SPluginBundleVersion sPluginBundleVersion = new SPluginBundleVersion();
boolean useful = true;
MavenPluginVersion mavenPluginVersion = (MavenPluginVersion) pluginVersion;
for (MavenDependency mavenDependency : mavenPluginVersion.getDependencies()) {
if (mavenDependency.getArtifact().getGroupId().equals("org.opensourcebim")) {
String artifactId = mavenDependency.getArtifact().getArtifactId();
// for the plugin, it's version has to be ok
if (artifactId.equals("shared") || artifactId.equals("pluginbase")) {
VersionRange versionRange = VersionRange.createFromVersion(mavenDependency.getArtifact().getVersion());
if (bimserverVersion != null && versionRange.containsVersion(bimserverVersion)) {
} else {
sPluginBundleVersion.setMismatch(true);
if (strictVersionChecking) {
useful = false;
LOGGER.info("Skipping version " + mavenPluginVersion.getArtifact().getVersion() + " or artifact " + mavenPluginVersion.getArtifact().getArtifactId());
}
}
}
}
}
if (useful) {
usefulBundle = true;
sPluginBundleVersion.setName(mavenPluginVersion.getModel().getName());
sPluginBundleVersion.setOrganization(mavenPluginVersion.getModel().getOrganization().getName());
sPluginBundleVersion.setArtifactId(mavenPluginLocation.getArtifactId());
sPluginBundleVersion.setGroupId(mavenPluginLocation.getGroupId());
try {
sPluginBundleVersion.setRepository(mavenPluginLocation.getRepository(mavenPluginVersion.getVersion().toString()));
} catch (ArtifactResolutionException e) {
LOGGER.error("", e);
}
sPluginBundleVersion.setType(SPluginBundleType.MAVEN);
sPluginBundleVersion.setVersion(mavenPluginVersion.getVersion().toString());
sPluginBundleVersion.setDescription(mavenPluginVersion.getModel().getDescription());
pluginBundle.setName(mavenPluginVersion.getModel().getName());
pluginBundle.setOrganization(mavenPluginVersion.getModel().getOrganization().getName());
pluginBundle.setLatestVersion(sPluginBundleVersion);
pluginBundle.getAvailableVersions().add(sPluginBundleVersion);
try {
sPluginBundleVersion.setIcon(mavenPluginLocation.getVersionIcon(mavenPluginVersion.getVersion().toString()));
} catch (ArtifactResolutionException e) {
// This is not important
} catch (IOException e) {
LOGGER.error("", e);
}
try {
GregorianCalendar date = mavenPluginLocation.getVersionDate(mavenPluginVersion.getVersion().toString());
if (date != null) {
sPluginBundleVersion.setDate(date.getTime());
}
// byte[] bytes = Files.readAllBytes(date);
// Properties properties = new Properties();
// properties.load(new ByteArrayInputStream(bytes));
// String buildDateString = properties.getProperty("build.date");
//
// DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
// try {
// } catch (ParseException e) {
// LOGGER.error("Invalid date format for plugin " + mavenPluginVersion.getModel().getName() + ": '" + buildDateString + "'");
// }
} catch (ArtifactResolutionException e) {
// Not a problem
} catch (Exception e) {
LOGGER.error("", e);
}
}
}
}
if (usefulBundle) {
return pluginBundle;
}
return null;
}
use of org.bimserver.interfaces.objects.SPluginBundleVersion in project BIMserver by opensourceBIM.
the class PluginManager method loadJavaProject.
public PluginBundle loadJavaProject(Path projectRoot, Path pomFile, Path pluginFolder, PluginDescriptor pluginDescriptor) throws PluginException, FileNotFoundException, IOException, XmlPullParserException {
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
Model model = null;
try (FileReader reader = new FileReader(pomFile.toFile())) {
model = mavenreader.read(reader);
}
PluginBundleVersionIdentifier pluginBundleVersionIdentifier = new PluginBundleVersionIdentifier(model.getGroupId(), model.getArtifactId(), model.getVersion());
if (pluginBundleIdentifierToPluginBundle.containsKey(pluginBundleVersionIdentifier.getPluginBundleIdentifier())) {
throw new PluginException("Plugin " + pluginBundleVersionIdentifier.getPluginBundleIdentifier().getHumanReadable() + " already loaded (version " + pluginBundleIdentifierToPluginBundle.get(pluginBundleVersionIdentifier.getPluginBundleIdentifier()).getPluginBundleVersion().getVersion() + ")");
}
DelegatingClassLoader delegatingClassLoader = new DelegatingClassLoader(getClass().getClassLoader());
PublicFindClassClassLoader previous = new PublicFindClassClassLoader(getClass().getClassLoader()) {
@Override
public Class<?> findClass(String name) throws ClassNotFoundException {
return null;
}
@Override
public URL findResource(String name) {
return null;
}
@Override
public void dumpStructure(int indent) {
}
};
Set<org.bimserver.plugins.Dependency> bimServerDependencies = new HashSet<>();
pluginBundleVersionIdentifier = new PluginBundleVersionIdentifier(new PluginBundleIdentifier(model.getGroupId(), model.getArtifactId()), model.getVersion());
previous = loadDependencies(bimServerDependencies, model, previous);
delegatingClassLoader.add(previous);
// Path libFolder = projectRoot.resolve("lib");
// loadDependencies(libFolder, delegatingClassLoader);
EclipsePluginClassloader pluginClassloader = new EclipsePluginClassloader(delegatingClassLoader, projectRoot);
// pluginClassloader.dumpStructure(0);
ResourceLoader resourceLoader = new ResourceLoader() {
@Override
public InputStream load(String name) {
try {
return Files.newInputStream(pluginFolder.resolve(name));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
};
SPluginBundle sPluginBundle = new SPluginBundle();
sPluginBundle.setOrganization(model.getOrganization().getName());
sPluginBundle.setName(model.getName());
SPluginBundleVersion sPluginBundleVersion = createPluginBundleVersionFromMavenModel(model, true);
Path icon = projectRoot.resolve("icon.png");
if (Files.exists(icon)) {
byte[] iconBytes = Files.readAllBytes(icon);
sPluginBundleVersion.setIcon(iconBytes);
}
sPluginBundle.setInstalledVersion(sPluginBundleVersion);
return loadPlugins(pluginBundleVersionIdentifier, resourceLoader, pluginClassloader, projectRoot.toUri(), projectRoot.resolve("target/classes").toString(), pluginDescriptor, PluginSourceType.ECLIPSE_PROJECT, bimServerDependencies, sPluginBundle, sPluginBundleVersion);
}
Aggregations