Browse Source

Merge pull request #13 from gitblit/description

Add an optional description to the manifest
tags/release-0.8.0
Decebal Suiu 10 years ago
parent
commit
b5589a7d0b

+ 22
- 15
pf4j/src/main/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinder.java View File

/* /*
* 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.
public class ManifestPluginDescriptorFinder implements PluginDescriptorFinder { public class ManifestPluginDescriptorFinder implements PluginDescriptorFinder {


private static final Logger log = LoggerFactory.getLogger(ManifestPluginDescriptorFinder.class); private static final Logger log = LoggerFactory.getLogger(ManifestPluginDescriptorFinder.class);
private PluginClasspath pluginClasspath; private PluginClasspath pluginClasspath;
public ManifestPluginDescriptorFinder(PluginClasspath pluginClasspath) { public ManifestPluginDescriptorFinder(PluginClasspath pluginClasspath) {
this.pluginClasspath = pluginClasspath; this.pluginClasspath = pluginClasspath;
} }
try { try {
input = new FileInputStream(manifestFile); input = new FileInputStream(manifestFile);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
// not happening
// not happening
} }
Manifest manifest = null; Manifest manifest = null;
try { try {
manifest = new Manifest(input); manifest = new Manifest(input);
} 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 !!!
Attributes attrs = manifest.getMainAttributes(); Attributes attrs = manifest.getMainAttributes();
String id = attrs.getValue("Plugin-Id"); String id = attrs.getValue("Plugin-Id");
throw new PluginException("Plugin-Id cannot be empty"); throw new PluginException("Plugin-Id cannot be empty");
} }
pluginDescriptor.setPluginId(id); pluginDescriptor.setPluginId(id);

String description = attrs.getValue("Plugin-Description");
if (StringUtils.isEmpty(description)) {
pluginDescriptor.setPluginDescription("");
} else {
pluginDescriptor.setPluginDescription(description);
}

String clazz = attrs.getValue("Plugin-Class"); String clazz = attrs.getValue("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 = attrs.getValue("Plugin-Version"); String version = attrs.getValue("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(PluginVersion.createVersion(version));
String provider = attrs.getValue("Plugin-Provider"); String provider = attrs.getValue("Plugin-Provider");
pluginDescriptor.setProvider(provider);
pluginDescriptor.setProvider(provider);
String dependencies = attrs.getValue("Plugin-Dependencies"); String dependencies = attrs.getValue("Plugin-Dependencies");
pluginDescriptor.setDependencies(dependencies); pluginDescriptor.setDependencies(dependencies);


return pluginDescriptor; return pluginDescriptor;
} }
} }

+ 17
- 5
pf4j/src/main/java/ro/fortsoft/pf4j/PluginDescriptor.java View File

/* /*
* 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.
public class PluginDescriptor { public class PluginDescriptor {


private String pluginId; private String pluginId;
private String pluginDescription;
private String pluginClass; private String pluginClass;
private PluginVersion version; private PluginVersion version;
private String provider; private String provider;
return pluginId; return pluginId;
} }


/**
* Returns the description of this plugin.
*/
public String getPluginDescription() {
return pluginDescription;
}

/** /**
* Returns the name of the class that implements Plugin interface. * Returns the name of the class that implements Plugin interface.
*/ */
this.pluginId = pluginId; this.pluginId = pluginId;
} }


void setPluginDescription(String pluginDescription) {
this.pluginDescription = pluginDescription;
}

void setPluginClass(String pluginClassName) { void setPluginClass(String pluginClassName) {
this.pluginClass = pluginClassName; this.pluginClass = pluginClassName;
} }
void setProvider(String provider) { void setProvider(String provider) {
this.provider = provider; this.provider = provider;
} }
void setDependencies(String dependencies) { void setDependencies(String dependencies) {
if (dependencies != null) { if (dependencies != null) {
dependencies = dependencies.trim(); dependencies = dependencies.trim();
this.dependencies = Collections.emptyList(); this.dependencies = Collections.emptyList();
} else { } else {
this.dependencies = new ArrayList<PluginDependency>(); this.dependencies = new ArrayList<PluginDependency>();
String[] tokens = dependencies.split(",");
String[] tokens = dependencies.split(",");
for (String dependency : tokens) { for (String dependency : tokens) {
dependency = dependency.trim(); dependency = dependency.trim();
if (!dependency.isEmpty()) { if (!dependency.isEmpty()) {

Loading…
Cancel
Save