Skip to content

Commit

Permalink
House keeping
Browse files Browse the repository at this point in the history
  • Loading branch information
rubendel committed Oct 20, 2015
1 parent 918c1c6 commit 0aa371f
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 376 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Set;
Expand Down
90 changes: 0 additions & 90 deletions Shared/src/org/bimserver/plugins/PathJavaFileObject.java

This file was deleted.

64 changes: 0 additions & 64 deletions Shared/src/org/bimserver/plugins/PluginContext.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
package org.bimserver.plugins;

/******************************************************************************
* Copyright (C) 2009-2015 BIMserver.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;

import javax.tools.JavaCompiler;
import javax.tools.JavaFileManager;
import javax.tools.ToolProvider;

import org.bimserver.models.store.Parameter;

public class PluginContext {
Expand All @@ -41,7 +19,6 @@ public class PluginContext {
private final PluginImplementation pluginImplementation;
private final String classLocation;
private boolean enabled = true;
private JavaFileManager javaFileManager;
private FileSystem fileSystem;
private Path rootPath;

Expand Down Expand Up @@ -92,26 +69,6 @@ public boolean isEnabled() {
return enabled;
}

// public InputStream getResourceAsInputStream(String name) throws FileNotFoundException {
// InputStream resourceAsStream = classLoader.getResourceAsStream(name);
// if (resourceAsStream == null) {
// File file = new File(location + File.separator + name);
// if (file.exists()) {
// resourceAsStream = new FileInputStream(file);
// }
// }
// if (resourceAsStream == null && !pluginImplementation.getRequires().isEmpty()) {
// for (String dep : pluginImplementation.getRequires()) {
// WebModulePlugin webModulePlugin = pluginManager.getWebModulePlugin(dep, true);
// InputStream resourceAsInputStream = pluginManager.getPluginContext(webModulePlugin).getResourceAsInputStream(name);
// if (resourceAsInputStream != null) {
// return resourceAsInputStream;
// }
// }
// }
// return resourceAsStream;
// }

public String getClassLocation() {
return classLocation;
}
Expand All @@ -120,27 +77,6 @@ public ClassLoader getClassLoader() {
return classLoader;
}

private JavaFileManager getFileManager() {
JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler();
if (systemJavaCompiler == null) {
throw new RuntimeException("JDK needed");
}
switch (pluginType) {
case ECLIPSE_PROJECT:
this.javaFileManager = new EclipseProjectPluginFileManager(systemJavaCompiler.getStandardFileManager(null, null, null), classLoader, new File(location.toString(), "bin"));
break;
case INTERNAL:
this.javaFileManager = systemJavaCompiler.getStandardFileManager(null, null, null);
break;
case JAR_FILE:
this.javaFileManager = new VirtualFileManager2(systemJavaCompiler.getStandardFileManager(null, null, null), classLoader, fileSystem, rootPath);
break;
default:
break;
}
return javaFileManager;
}

public Path getRootPath() {
return rootPath;
}
Expand Down
39 changes: 16 additions & 23 deletions Shared/src/org/bimserver/plugins/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
Expand Down Expand Up @@ -71,14 +70,15 @@

public class PluginManager {
private static final Logger LOGGER = LoggerFactory.getLogger(PluginManager.class);
private final Map<Class<? extends Plugin>, Set<PluginContext>> implementations = new LinkedHashMap<Class<? extends Plugin>, Set<PluginContext>>();
private final Map<Class<? extends Plugin>, Set<PluginContext>> implementations = new LinkedHashMap<Class<? extends Plugin>, Set<PluginContext>>();
private final Map<Plugin, PluginContext> pluginToPluginContext = new HashMap<>();
private final Set<Path> loadedLocations = new HashSet<>();
private final Set<PluginChangeListener> pluginChangeListeners = new HashSet<PluginChangeListener>();
private Path tempDir;
private final Path tempDir;
private final String baseClassPath;
private ServiceFactory serviceFactory;
private NotificationsManagerInterface notificationsManagerInterface;
private SServicesMap servicesMap;
private final ServiceFactory serviceFactory;
private final NotificationsManagerInterface notificationsManagerInterface;
private final SServicesMap servicesMap;
private BimServerClientFactory bimServerClientFactory;
private MetaDataManager metaDataManager;

Expand All @@ -91,11 +91,6 @@ public PluginManager(Path tempDir, String baseClassPath, ServiceFactory serviceF
this.servicesMap = servicesMap;
}

public PluginManager() {
this.tempDir = Paths.get(System.getProperty("java.io.tmpdir"));
this.baseClassPath = null;
}

public void loadPluginsFromEclipseProjectNoExceptions(Path projectRoot) {
try {
loadPluginsFromEclipseProject(projectRoot);
Expand Down Expand Up @@ -323,15 +318,11 @@ public Collection<Plugin> getAllPlugins(boolean onlyEnabled) {
}

public PluginContext getPluginContext(Plugin plugin) {
// TODO make more efficient
for (Set<PluginContext> pluginContexts : implementations.values()) {
for (PluginContext pluginContext : pluginContexts) {
if (pluginContext.getPlugin() == plugin) {
return pluginContext;
}
}
PluginContext pluginContext = pluginToPluginContext.get(plugin);
if (pluginContext == null) {
throw new RuntimeException("No plugin context found for " + plugin);
}
throw new RuntimeException("No plugin context found for " + plugin);
return pluginContext;
}

/**
Expand Down Expand Up @@ -475,12 +466,14 @@ public void loadPlugin(Class<? extends Plugin> interfaceClass, URI location, Str
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)) {
if (!implementations.containsKey(interfaceClass)) {
implementations.put(interfaceClass, new LinkedHashSet<PluginContext>());
}
}
Set<PluginContext> set = (Set<PluginContext>) implementations.get(interfaceClass);
try {
set.add(new PluginContext(this, classLoader, pluginType, location, plugin, pluginImplementation, classLocation));
try {
PluginContext pluginContext = new PluginContext(this, classLoader, pluginType, location, plugin, pluginImplementation, classLocation);
pluginToPluginContext.put(plugin, pluginContext);
set.add(pluginContext);
} catch (IOException e) {
throw new PluginException(e);
}
Expand Down
Loading

0 comments on commit 0aa371f

Please sign in to comment.