use of org.apache.tapestry5.services.ComponentLibraryInfo in project tapestry-5 by apache.
the class MavenComponentLibraryInfoSource method find.
@Override
public ComponentLibraryInfo find(LibraryMapping libraryMapping) {
ComponentLibraryInfo info = null;
if (cache.containsKey(libraryMapping.libraryName)) {
info = cache.get(libraryMapping.libraryName);
} else {
final String pomPath = getPomPath(libraryMapping);
if (pomPath != null) {
InputStream inputStream = getClass().getResourceAsStream("/" + pomPath);
info = parse(inputStream);
info.setLibraryMapping(libraryMapping);
cache.put(libraryMapping.libraryName, info);
} else {
cache.put(libraryMapping.libraryName, null);
}
}
return info;
}
use of org.apache.tapestry5.services.ComponentLibraryInfo in project tapestry-5 by apache.
the class MavenComponentLibraryInfoSource method parse.
private ComponentLibraryInfo parse(InputStream inputStream) {
ComponentLibraryInfo info = null;
if (inputStream != null) {
Document document;
try {
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
document = documentBuilder.parse(inputStream);
} catch (Exception e) {
logger.warn("Exception while parsing pom.xml", e);
return null;
}
info = new ComponentLibraryInfo();
info.setGroupId(extractText(document, "(/project/groupId | /project/parent/groupId)[1]"));
info.setArtifactId(extractText(document, "/project/artifactId"));
info.setVersion(extractText(document, "/project/version"));
info.setName(extractText(document, "/project/name"));
info.setDescription(extractText(document, "/project/description"));
info.setDocumentationUrl(extractText(document, "/project/properties/documentationUrl"));
info.setHomepageUrl(extractText(document, "/project/properties/homepageUrl"));
info.setIssueTrackerUrl(extractText(document, "/project/issueManagement/url"));
info.setJavadocUrl(extractText(document, "/project/properties/javadocUrl"));
info.setSourceBrowseUrl(extractText(document, "/project/scm/url"));
info.setSourceRootUrl(extractText(document, "/project/properties/sourceRootUrl"));
info.setTapestryVersion(extractText(document, "(/project/dependencies/dependency[./groupId='org.apache.tapestry'][./artifactId='tapestry-core']/version | /project/properties/tapestryVersion)[1]"));
String tags = extractText(document, "/project/properties/tags");
if (tags != null && tags.length() > 0) {
info.setTags(Arrays.asList(tags.split(",")));
}
}
return info;
}
use of org.apache.tapestry5.services.ComponentLibraryInfo in project tapestry-5 by apache.
the class ComponentLibraries method generateJSONDescription.
@OnEvent("json")
Object generateJSONDescription(String libraryName) {
for (LibraryMapping mapping : componentClassResolver.getLibraryMappings()) {
if (libraryName.equalsIgnoreCase(mapping.libraryName)) {
this.libraryMapping = mapping;
break;
}
}
JSONObject object = new JSONObject();
object.put("libraryName", libraryName);
object.put("rootPackage", libraryMapping.getRootPackage());
final ComponentLibraryInfo info = getInfo();
if (info != null) {
JSONObject infoJsonObject = new JSONObject();
putIfNotNull("description", info.getDescription(), infoJsonObject);
putIfNotNull("homepage", info.getHomepageUrl(), infoJsonObject);
putIfNotNull("documentationUrl", info.getDocumentationUrl(), infoJsonObject);
putIfNotNull("javadocUrl", info.getJavadocUrl(), infoJsonObject);
putIfNotNull("groupId", info.getGroupId(), infoJsonObject);
putIfNotNull("artifactId", info.getArtifactId(), infoJsonObject);
putIfNotNull("version", info.getVersion(), infoJsonObject);
putIfNotNull("sourceBrowseUrl", info.getSourceBrowseUrl(), infoJsonObject);
putIfNotNull("sourceRootUrl", info.getSourceRootUrl(), infoJsonObject);
putIfNotNull("issueTrackerUrl", info.getIssueTrackerUrl(), infoJsonObject);
putIfNotNull("dependencyInfoUrl", info.getDependencyManagementInfoUrl(), infoJsonObject);
if (info.getTags() != null) {
for (String tag : info.getTags()) {
infoJsonObject.accumulate("tags", tag);
}
}
object.put("info", infoJsonObject);
}
addClasses("components", filter(componentClassResolver.getComponentNames()), Type.COMPONENT, info, object);
addClasses("pages", filter(componentClassResolver.getPageNames()), Type.PAGE, info, object);
addClasses("mixins", filter(componentClassResolver.getMixinNames()), Type.MIXIN, info, object);
return new TextStreamResponse("text/javascript", object.toString());
}
use of org.apache.tapestry5.services.ComponentLibraryInfo in project tapestry-5 by apache.
the class ComponentLibraries method addClasses.
private void addClasses(final String property, List<String> classes, Type type, final ComponentLibraryInfo info, JSONObject object) {
if (classes.size() > 0) {
JSONArray classesJsonArray = new JSONArray();
for (String logicalName : classes) {
logicalName = logicalName.replace("core/", "");
final String className = getClassName(logicalName, type, componentClassResolver);
JSONObject classJsonObject = new JSONObject();
classJsonObject.put("logicalName", logicalName);
classJsonObject.put("class", className);
if (info != null) {
putIfNotNull("sourceUrl", info.getSourceUrl(className), classJsonObject);
putIfNotNull("javadocUrl", info.getJavadocUrl(className), classJsonObject);
}
try {
final Description description = getClass(className);
if (description != null) {
putIfNotNull("description", description.text(), classJsonObject);
if (description.tags().length > 0) {
for (String tag : description.tags()) {
classJsonObject.accumulate("tag", tag);
}
}
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
classesJsonArray.put(classJsonObject);
}
object.put(property, classesJsonArray);
}
}
Aggregations