use of org.bimserver.shared.exceptions.PluginException in project BIMserver by opensourceBIM.
the class TestSimultaniousDownloadWithCaching method start.
private void start() {
BimServerConfig config = new BimServerConfig();
Path homeDir = Paths.get("home");
try {
if (Files.isDirectory(homeDir)) {
PathUtils.removeDirectoryWithContent(homeDir);
}
} catch (IOException e) {
e.printStackTrace();
}
config.setClassPath(System.getProperty("java.class.path"));
config.setHomeDir(homeDir);
config.setPort(8080);
config.setStartEmbeddedWebServer(true);
config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
final BimServer bimServer = new BimServer(config);
try {
LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), null);
bimServer.start();
if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
bimServer.getService(AdminInterface.class).setup("http://localhost", "Administrator", "admin@bimserver.org", "admin", null, null, null);
}
} catch (PluginException e2) {
e2.printStackTrace();
} catch (ServerException e) {
e.printStackTrace();
} catch (DatabaseInitException e) {
e.printStackTrace();
} catch (BimserverDatabaseException e) {
e.printStackTrace();
} catch (DatabaseRestartRequiredException e) {
e.printStackTrace();
} catch (UserException e) {
e.printStackTrace();
}
try {
final ServiceMap serviceMap = bimServer.getServiceFactory().get(AccessMethod.INTERNAL);
ServiceInterface serviceInterface = serviceMap.get(ServiceInterface.class);
SettingsInterface settingsInterface = serviceMap.get(SettingsInterface.class);
final AuthInterface authInterface = serviceMap.get(AuthInterface.class);
serviceInterface = bimServer.getServiceFactory().get(authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL).get(ServiceInterface.class);
settingsInterface.setCacheOutputFiles(true);
settingsInterface.setGenerateGeometryOnCheckin(false);
final SProject project = serviceMap.getServiceInterface().addProject("test", "ifc2x3tc1");
SDeserializerPluginConfiguration deserializerByName = serviceMap.getServiceInterface().getDeserializerByName("IfcStepDeserializer");
Path file = Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc");
serviceInterface.checkin(project.getOid(), "test", deserializerByName.getOid(), file.toFile().length(), file.getFileName().toString(), new DataHandler(new FileDataSource(file.toFile())), false, true);
final SProject projectUpdate = serviceMap.getServiceInterface().getProjectByPoid(project.getOid());
ThreadPoolExecutor executor = new ThreadPoolExecutor(20, 20, 1, TimeUnit.HOURS, new ArrayBlockingQueue<Runnable>(1000));
for (int i = 0; i < 20; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
try {
ServiceMap serviceMap2 = bimServer.getServiceFactory().get(authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL);
SSerializerPluginConfiguration serializerPluginConfiguration = serviceMap.getServiceInterface().getSerializerByName("Ifc2x3");
Long download = serviceMap2.getServiceInterface().download(Collections.singleton(projectUpdate.getLastRevisionId()), DefaultQueries.allAsString(), serializerPluginConfiguration.getOid(), true);
SDownloadResult downloadData = serviceMap2.getServiceInterface().getDownloadData(download);
if (downloadData.getFile().getDataSource() instanceof CacheStoringEmfSerializerDataSource) {
CacheStoringEmfSerializerDataSource c = (CacheStoringEmfSerializerDataSource) downloadData.getFile().getDataSource();
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
c.writeToOutputStream(baos, null);
System.out.println(baos.size());
} catch (SerializerException e) {
e.printStackTrace();
}
} else {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(downloadData.getFile().getInputStream(), baos);
System.out.println(baos.size());
}
serviceMap2.getServiceInterface().cleanupLongAction(download);
} catch (ServerException e) {
e.printStackTrace();
} catch (UserException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e1) {
e1.printStackTrace();
}
}
});
}
executor.shutdown();
executor.awaitTermination(1, TimeUnit.HOURS);
bimServer.stop();
} catch (ServerException e1) {
e1.printStackTrace();
} catch (UserException e1) {
e1.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e2) {
e2.printStackTrace();
}
}
use of org.bimserver.shared.exceptions.PluginException in project BIMserver by opensourceBIM.
the class PluginManager method loadPlugin.
public PluginContext loadPlugin(PluginBundle pluginBundle, Class<? extends Plugin> interfaceClass, URI location, String classLocation, Plugin plugin, ClassLoader classLoader, PluginSourceType pluginType, AbstractPlugin pluginImplementation, Set<org.bimserver.plugins.Dependency> dependencies, String identifier) throws PluginException {
LOGGER.debug("Loading plugin " + plugin.getClass().getSimpleName() + " of type " + interfaceClass.getSimpleName());
if (!Plugin.class.isAssignableFrom(interfaceClass)) {
throw new PluginException("Given interface class (" + interfaceClass.getName() + ") must be a subclass of " + Plugin.class.getName());
}
if (!implementations.containsKey(interfaceClass)) {
implementations.put(interfaceClass, new LinkedHashSet<PluginContext>());
}
Set<PluginContext> set = (Set<PluginContext>) implementations.get(interfaceClass);
try {
PluginContext pluginContext = new PluginContext(this, pluginBundle, interfaceClass, classLoader, pluginType, pluginImplementation.getDescription(), location, plugin, classLocation, dependencies, identifier);
pluginToPluginContext.put(plugin, pluginContext);
set.add(pluginContext);
return pluginContext;
} catch (IOException e) {
throw new PluginException(e);
}
}
use of org.bimserver.shared.exceptions.PluginException 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);
}
use of org.bimserver.shared.exceptions.PluginException 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.shared.exceptions.PluginException 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);
}
}
Aggregations