|
|
@ -1,11 +1,11 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2012 Decebal Suiu |
|
|
|
* Copyright 2012 Decebal Suiu |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with |
|
|
|
* the License. You may obtain a copy of the License in the LICENSE file, or at: |
|
|
|
* the License. You may obtain a copy of the License in the LICENSE file, or at: |
|
|
|
* |
|
|
|
* |
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* |
|
|
|
* |
|
|
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
|
|
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
|
|
|
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
|
|
|
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
|
|
|
* specific language governing permissions and limitations under the License. |
|
|
|
* specific language governing permissions and limitations under the License. |
|
|
@ -26,15 +26,15 @@ import ro.fortsoft.pf4j.util.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Find a plugin descriptor in a properties file (in plugin repository). |
|
|
|
* Find a plugin descriptor in a properties file (in plugin repository). |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Decebal Suiu |
|
|
|
* @author Decebal Suiu |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class PropertiesPluginDescriptorFinder implements PluginDescriptorFinder { |
|
|
|
public class PropertiesPluginDescriptorFinder implements PluginDescriptorFinder { |
|
|
|
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(PropertiesPluginDescriptorFinder.class); |
|
|
|
private static final Logger log = LoggerFactory.getLogger(PropertiesPluginDescriptorFinder.class); |
|
|
|
|
|
|
|
|
|
|
|
private static final String DEFAULT_PROPERTIES_FILE_NAME = "plugin.properties"; |
|
|
|
private static final String DEFAULT_PROPERTIES_FILE_NAME = "plugin.properties"; |
|
|
|
|
|
|
|
|
|
|
|
private String propertiesFileName; |
|
|
|
private String propertiesFileName; |
|
|
|
|
|
|
|
|
|
|
|
public PropertiesPluginDescriptorFinder() { |
|
|
|
public PropertiesPluginDescriptorFinder() { |
|
|
@ -44,7 +44,7 @@ public class PropertiesPluginDescriptorFinder implements PluginDescriptorFinder |
|
|
|
public PropertiesPluginDescriptorFinder(String propertiesFileName) { |
|
|
|
public PropertiesPluginDescriptorFinder(String propertiesFileName) { |
|
|
|
this.propertiesFileName = propertiesFileName; |
|
|
|
this.propertiesFileName = propertiesFileName; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public PluginDescriptor find(File pluginRepository) throws PluginException { |
|
|
|
public PluginDescriptor find(File pluginRepository) throws PluginException { |
|
|
|
File propertiesFile = new File(pluginRepository, propertiesFileName); |
|
|
|
File propertiesFile = new File(pluginRepository, propertiesFileName); |
|
|
@ -57,9 +57,9 @@ public class PropertiesPluginDescriptorFinder implements PluginDescriptorFinder |
|
|
|
try { |
|
|
|
try { |
|
|
|
input = new FileInputStream(propertiesFile); |
|
|
|
input = new FileInputStream(propertiesFile); |
|
|
|
} catch (FileNotFoundException e) { |
|
|
|
} catch (FileNotFoundException e) { |
|
|
|
// not happening
|
|
|
|
// not happening
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Properties properties = new Properties(); |
|
|
|
Properties properties = new Properties(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
properties.load(input); |
|
|
|
properties.load(input); |
|
|
@ -71,31 +71,31 @@ public class PropertiesPluginDescriptorFinder implements PluginDescriptorFinder |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
throw new PluginException(e.getMessage(), e); |
|
|
|
throw new PluginException(e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PluginDescriptor pluginDescriptor = new PluginDescriptor(); |
|
|
|
PluginDescriptor pluginDescriptor = new PluginDescriptor(); |
|
|
|
|
|
|
|
|
|
|
|
// TODO validate !!!
|
|
|
|
// TODO validate !!!
|
|
|
|
String id = properties.getProperty("plugin.id"); |
|
|
|
String id = properties.getProperty("plugin.id"); |
|
|
|
if (StringUtils.isEmpty(id)) { |
|
|
|
if (StringUtils.isEmpty(id)) { |
|
|
|
throw new PluginException("plugin.id cannot be empty"); |
|
|
|
throw new PluginException("plugin.id cannot be empty"); |
|
|
|
} |
|
|
|
} |
|
|
|
pluginDescriptor.setPluginId(id); |
|
|
|
pluginDescriptor.setPluginId(id); |
|
|
|
|
|
|
|
|
|
|
|
String clazz = properties.getProperty("plugin.class"); |
|
|
|
String clazz = properties.getProperty("plugin.class"); |
|
|
|
if (StringUtils.isEmpty(clazz)) { |
|
|
|
if (StringUtils.isEmpty(clazz)) { |
|
|
|
throw new PluginException("plugin.class cannot be empty"); |
|
|
|
throw new PluginException("plugin.class cannot be empty"); |
|
|
|
} |
|
|
|
} |
|
|
|
pluginDescriptor.setPluginClass(clazz); |
|
|
|
pluginDescriptor.setPluginClass(clazz); |
|
|
|
|
|
|
|
|
|
|
|
String version = properties.getProperty("plugin.version"); |
|
|
|
String version = properties.getProperty("plugin.version"); |
|
|
|
if (StringUtils.isEmpty(version)) { |
|
|
|
if (StringUtils.isEmpty(version)) { |
|
|
|
throw new PluginException("plugin.version cannot be empty"); |
|
|
|
throw new PluginException("plugin.version cannot be empty"); |
|
|
|
} |
|
|
|
} |
|
|
|
pluginDescriptor.setPluginVersion(PluginVersion.createVersion(version)); |
|
|
|
pluginDescriptor.setPluginVersion(Version.createVersion(version)); |
|
|
|
|
|
|
|
|
|
|
|
String provider = properties.getProperty("plugin.provider"); |
|
|
|
String provider = properties.getProperty("plugin.provider"); |
|
|
|
pluginDescriptor.setProvider(provider); |
|
|
|
pluginDescriptor.setProvider(provider); |
|
|
|
String dependencies = properties.getProperty("plugin.dependencies"); |
|
|
|
String dependencies = properties.getProperty("plugin.dependencies"); |
|
|
|
pluginDescriptor.setDependencies(dependencies); |
|
|
|
pluginDescriptor.setDependencies(dependencies); |
|
|
|
|
|
|
|
|
|
|
|