Skip to content

Commit

Permalink
Merge pull request #950 from BezrukovM/plugins-loding-fixes
Browse files Browse the repository at this point in the history
Plugins loding fixes
  • Loading branch information
carlwilson authored Apr 24, 2018
2 parents 47c35ec + 09f15f6 commit 9683a73
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,18 @@ public class FeaturesPluginsLoader {
private static final Logger LOGGER = Logger
.getLogger(FeaturesPluginsLoader.class.getName());

private static String baseFolderPath = null;

private FeaturesPluginsLoader() {
}

public static void setBaseFolderPath(String baseFolderPath) {
FeaturesPluginsLoader.baseFolderPath =
baseFolderPath == null || baseFolderPath.endsWith("/") ?
baseFolderPath :
baseFolderPath + "/";
}

/**
* Configurates features reporter
*/
Expand Down Expand Up @@ -98,13 +107,20 @@ private static List<AbstractFeaturesExtractor> getAllExtractors(PluginsCollectio
}

private static AbstractFeaturesExtractor getExtractorFromConfig(PluginConfig config) {
Path pluginJar = config.getPluginJar();
String pluginJar = config.getPluginJar();
if (pluginJar == null) {
LOGGER.log(Level.WARNING, "Plugins config file contains an enabled plugin with empty path");
return null;
}
File pluginJarFile = pluginJar.toFile();
if (pluginJarFile == null || !pluginJarFile.isFile()) {
String path;
if (pluginJar.startsWith("/") || baseFolderPath == null) {
path = pluginJar;
} else {
path = baseFolderPath + pluginJar;

}
File pluginJarFile = new File(path);
if (!pluginJarFile.isFile()) {
LOGGER.log(Level.WARNING, "Plugins config file contains wrong path");
return null;
}
Expand Down
37 changes: 8 additions & 29 deletions core/src/main/java/org/verapdf/processor/plugins/PluginConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,13 @@
*/
package org.verapdf.processor.plugins;

import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* @author Maksim Bezrukov
Expand All @@ -49,13 +43,12 @@ public class PluginConfig {
@XmlElement
private final String description;
@XmlElement
@XmlJavaTypeAdapter(PluginConfig.PathAdapter.class)
private final Path pluginJar;
private final String pluginJar;
@XmlElement(name="attribute")
@XmlElementWrapper(name = "attributes")
private final List<Attribute> attributes;

private PluginConfig(boolean enabled, String name, String version, String description, Path pluginJar, List<Attribute> attributes) {
private PluginConfig(boolean enabled, String name, String version, String description, String pluginJar, List<Attribute> attributes) {
this.enabled = enabled;
this.name = name;
this.version = version;
Expand All @@ -65,10 +58,10 @@ private PluginConfig(boolean enabled, String name, String version, String descri
}

private PluginConfig() {
this(false, "", "", "", FileSystems.getDefault().getPath(""), Collections.<Attribute>emptyList()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
this(false, "", "", "","", Collections.<Attribute>emptyList()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
}

public static PluginConfig fromValues(boolean enabled, String name, String version, String description, Path pluginFolder, List<Attribute> attributes) {
public static PluginConfig fromValues(boolean enabled, String name, String version, String description, String pluginFolder, List<Attribute> attributes) {
return new PluginConfig(enabled, name, version, description, pluginFolder, attributes);
}

Expand All @@ -88,25 +81,11 @@ public String getDescription() {
return this.description;
}

public Path getPluginJar() {
public String getPluginJar() {
return this.pluginJar;
}

public List<Attribute> getAttributes() {
return this.attributes == null ? Collections.<Attribute>emptyList() : Collections.unmodifiableList(this.attributes);
}

private static class PathAdapter extends XmlAdapter<String, Path> {

@Override
public Path unmarshal(String v) throws Exception {
Path path = Paths.get(v);
return path.toAbsolutePath();
}

@Override
public String marshal(Path v) {
return v.toAbsolutePath().toString();
}
}
}

0 comments on commit 9683a73

Please sign in to comment.