use of org.bimserver.interfaces.objects.SPluginBundle 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.SPluginBundle in project BIMserver by opensourceBIM.
the class GetPluginBundle method execute.
@Override
public SPluginBundle execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
if (bimServer.getVersionChecker() != null && bimServer.getVersionChecker().getLocalVersion() != null) {
bimserverVersion = new DefaultArtifactVersion(bimServer.getVersionChecker().getLocalVersion().getFullString());
}
MavenPluginLocation pluginLocation = bimServer.getMavenPluginRepository().getPluginLocation(repository, groupId, artifactId);
PluginBundle pluginBundle = bimServer.getPluginManager().getPluginBundle(pluginLocation.getPluginIdentifier());
// Skipping all plugin bundles that already have an installed version
if (pluginBundle == null) {
SPluginBundle sPluginBundle = processPluginLocation(pluginLocation, false, bimserverVersion);
if (sPluginBundle != null) {
return sPluginBundle;
}
}
throw new UserException("Plugin bundle already installed " + groupId + "." + artifactId);
}
use of org.bimserver.interfaces.objects.SPluginBundle 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.SPluginBundle in project BIMserver by opensourceBIM.
the class PluginManager method uninstall.
// public PluginBundle install(PluginBundleVersionIdentifier
// pluginBundleVersionIdentifier, SPluginBundle sPluginBundle,
// SPluginBundleVersion pluginBundleVersion, List<SPluginInformation>
// plugins, boolean strictDependencyChecking) throws Exception {
// MavenXpp3Reader mavenreader = new MavenXpp3Reader();
// Model model = mavenreader.read(new FileReader(pomFile.toFile()));
//
// 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 {
// try {
// MavenPluginLocation mavenPluginLocation =
// mavenPluginRepository.getPluginLocation(dependency.getGroupId(),
// dependency.getArtifactId());
// Path depJarFile =
// mavenPluginLocation.getVersionJar(dependency.getVersion());
//
// FileJarClassLoader jarClassLoader = new FileJarClassLoader(this,
// delegatingClassLoader, depJarFile);
// 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(jarFile, target);
//
// return loadPlugin(pluginBundleVersionIdentifier, target, sPluginBundle,
// pluginBundleVersion, plugins, delegatingClassLoader);
// }
public void uninstall(PluginBundleVersionIdentifier pluginBundleVersionIdentifier) {
PluginBundle pluginBundle = pluginBundleVersionIdentifierToPluginBundle.get(pluginBundleVersionIdentifier);
if (pluginBundle == null) {
return;
}
try {
pluginBundle.close();
pluginBundleVersionIdentifierToPluginBundle.remove(pluginBundleVersionIdentifier);
pluginBundleIdentifierToPluginBundle.remove(pluginBundleVersionIdentifier.getPluginBundleIdentifier());
pluginBundleIdentifierToCurrentPluginBundleVersionIdentifier.remove(pluginBundleVersionIdentifier.getPluginBundleIdentifier());
for (PluginContext pluginContext : pluginBundle) {
Set<PluginContext> set = implementations.get(pluginContext.getPluginInterface());
set.remove(pluginContext);
}
Path target = pluginsDir.resolve(pluginBundleVersionIdentifier.getFileName());
Files.delete(target);
for (PluginContext pluginContext : pluginBundle) {
pluginChangeListener.pluginUninstalled(pluginContext);
}
pluginChangeListener.pluginBundleUninstalled(pluginBundle);
} catch (IOException e) {
LOGGER.error("", e);
}
}
use of org.bimserver.interfaces.objects.SPluginBundle 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