public Resource getRelativeResource(String relativePath) { Check.isFalse(relativePath.startsWith("/"), "Relative path should not start with a slash"); String subPath = removeAnyLeadingDotSlashFrom(relativePath); Resource p = getPackage(); while (subPath.startsWith("../")) { p = p.getParent(); if (p == null) { throw new RuntimeException("Path '" + relativePath + "' relative to '" + getPath() + "' " + "evaluates above the root package."); } subPath = subPath.replaceFirst("../", ""); } Check.isFalse(subPath.contains("../"), "The ../ operator is currently only supported at the start of expressions"); return new Resource(p.getPath() + subPath); }
public String getPath(String resourcePath, String relativePath) { return new Resource(resourcePath).getRelativeResource(relativePath).getPath(); } }
public String getRelativePath(Resource resource) { if (resource.getPath().equals(path)) { return name; String[] therePieces = resource.getPathPieces(); String[] herePieces = getPathPieces(); if (resource.isPackage()) { return r.toString(); return r.append(resource.getName()).toString();
private String[] getPathPieces() { String packagePath = getPackage().getPath(); if ("/".equals(packagePath)) { return new String[]{""}; } return packagePath.split("/"); }
/** * Finds the test class for the specification referenced by the given href, relative to the * resource. * * @param resource the current resource * @param href the specification to find the test class for * @return test class * @throws ClassNotFoundException if test class not found */ protected Class<?> findTestClass(Resource resource, String href) throws ClassNotFoundException { Resource hrefResource = resource.getParent().getRelativeResource(href); return FixtureSpecificationMapper.findFixtureClass(hrefResource); }
public File getFile(Resource resource) { return new File(baseDir, resource.getPath()); }
public RunnerResult execute(Resource resource, String href) throws Exception { Resource hrefResource = resource.getParent().getRelativeResource(href); String name = hrefResource.getPath().replaceFirst("/", "").replace("/", ".").replaceAll("\\.html$", ""); Class<?> concordionClass; try { concordionClass = Class.forName(name); } catch (ClassNotFoundException e) { concordionClass = Class.forName(name + "Test"); } ResultSummary resultSummary = new ConcordionBuilder() .build() .process(hrefResource, concordionClass.newInstance()); Result result = Result.SUCCESS; if (resultSummary.getFailureCount() > 0) { result = Result.FAILURE; } if (resultSummary.getExceptionCount() > 0) { result = Result.EXCEPTION; } return new RunnerResult(result); } }
private Resource at(String path) { return new Resource(path); } }
private Element createBreadcrumbElement(Resource documentResource, Resource indexPageResource, SpecificationConverter specificationConverter) throws IOException { String breadcrumbWording = getBreadcrumbWordingForResource(indexPageResource, specificationConverter); Element a = new Element("a"); Resource indexPageAsHtmlResource = new Resource(indexPageResource.getPath().replaceFirst("\\..*$", "\\.html")); a.addAttribute("href", documentResource.getRelativePath(indexPageAsHtmlResource)); a.appendText(breadcrumbWording); return a; }
private void appendBreadcrumbsTo(Element breadcrumbSpan, Resource documentResource) { Resource packageResource = documentResource.getParent(); while (packageResource != null) { for (SpecificationType specificationType : specificationTypes) { Resource indexPageResource = packageResource.getRelativeResource(getIndexPageName(packageResource, specificationType.getTypeSuffix())); if (!indexPageResource.equals(documentResource) && specificationSource.canFind(indexPageResource)) { try { prependBreadcrumb(breadcrumbSpan, createBreadcrumbElement(documentResource, indexPageResource, specificationType.getConverter())); } catch (Exception e) { System.err.println("Failed to generate breadcrumb: " + e.getMessage()); } break; } } packageResource = packageResource.getParent(); } }
private String getBreadcrumbWordingForResource(Resource indexPageResource, SpecificationConverter specificationConverter) throws IOException { String breadcrumbWording = breadcrumbWordingCache.get(indexPageResource); if (breadcrumbWording == null) { InputStream inputStream = specificationSource.createInputStream(indexPageResource); try { if (specificationConverter != null) { inputStream = specificationConverter.convert(inputStream, indexPageResource.getName()); } Document document = xmlParser.parse(inputStream, SimpleFormatter.format("[%s: %s]", specificationSource, indexPageResource.getPath())); breadcrumbWording = getBreadcrumbWording(new Element(document.getRootElement()), indexPageResource); breadcrumbWordingCache.put(indexPageResource, breadcrumbWording); } finally { inputStream.close(); } } return breadcrumbWording; }
public Iterable<String> getResources() { List<String> resources = new ArrayList<String>(); List<Resource> resourceList = testRig.getCopiedResources(); for (Resource resource : resourceList) { resources.add(new Resource("/resources/test/ResourcesTest.html").getRelativePath(resource)); } return resources; }
private String getIndexPageName(Resource packageResource, String suffix) { return capitalize(packageResource.getName()) + "." + suffix; }
public void beforeProcessingSpecification(SpecificationProcessingEvent event) { Resource resource = event.getResource(); //work around with setValue() necessary for Concordion.NET Attribute hrefAttribute = new Attribute("href", ""); hrefAttribute.setValue(resource.getRelativePath(stylesheetResource)); link.addAttribute(hrefAttribute); }
public Resource(String path) { path = path.replaceAll("\\\\", "/"); Check.isTrue(path.startsWith("/"), "Internal error: Resource path should start with a slash"); this.path = path; isPackage = endsWithSlash(path); parts = path.split("/"); if (parts.length == 0) { name = ""; } else { name = parts[parts.length - 1]; } }