use of org.apache.tapestry5.ioc.annotations.Optional in project tapestry-5 by apache.
the class PackageChangeRefactorCommitParserTest method valid_line.
@Test
public void valid_line() {
// commons/src/main/java/org/apache/tapestry5/{ioc => commons}/Messages.java (98%)
PackageChangeRefactorCommitParser parser = new PackageChangeRefactorCommitParser();
Optional<ClassRefactor> optionalRefactor = parser.apply(PackageChangeRefactorCommitParser.EXAMPLE);
Assert.assertTrue(optionalRefactor.isPresent(), "Line not detected as a change of package.");
ClassRefactor refactor = optionalRefactor.get();
Assert.assertEquals(refactor.getNewClassName(), "org.apache.tapestry5.commons.Messages");
Assert.assertEquals(refactor.getOldClassName(), "org.apache.tapestry5.ioc.Messages");
Assert.assertEquals(refactor.getDestinationArtifact(), "commons");
Assert.assertEquals(refactor.getSourceArtifact(), "commons");
}
use of org.apache.tapestry5.ioc.annotations.Optional in project tapestry-5 by apache.
the class Main method parse.
private static List<ClassRefactor> parse(List<String> lines) {
System.out.println("Lines to process: " + lines.size());
lines = lines.stream().map(s -> s.trim()).filter(s -> s.startsWith("rename")).filter(s -> !s.contains("test")).filter(s -> !s.contains("package-info")).filter(s -> !s.contains("/resources/")).filter(s -> !s.contains("/filtered-resources/")).map(s -> s.replaceFirst("rename", "").trim()).collect(Collectors.toList());
List<ClassRefactor> refactors = new ArrayList<>(lines.size());
for (String line : lines) {
PackageAndArtifactChangeRefactorCommitParser packageAndArtifactParser = new PackageAndArtifactChangeRefactorCommitParser();
ArtifactChangeRefactorCommitParser artifactParser = new ArtifactChangeRefactorCommitParser();
PackageChangeRefactorCommitParser packageParser = new PackageChangeRefactorCommitParser();
Optional<ClassRefactor> maybeMove = packageAndArtifactParser.apply(line);
if (!maybeMove.isPresent()) {
maybeMove = packageParser.apply(line);
}
if (!maybeMove.isPresent()) {
maybeMove = artifactParser.apply(line);
}
ClassRefactor move = maybeMove.orElseThrow(() -> new RuntimeException("Commit not handled: " + line));
refactors.add(move);
}
return refactors;
}
use of org.apache.tapestry5.ioc.annotations.Optional in project tapestry-5 by apache.
the class ArtifactChangeRefactorCommitParser method apply.
@Override
public Optional<ClassRefactor> apply(String line) {
final Matcher matcher = PATTERN.matcher(line);
ClassRefactor move = null;
if (matcher.matches()) {
// System.out.printf("1(%s) 2(%s) 3(%s)\n", otherMatcher.group(1), otherMatcher.group(2), otherMatcher.group(3));
final String className = FileRefactorCommitParser.extractPackageOrClassName(matcher.group(3));
final String sourceArtifactName = matcher.group(1);
final String destinationArtifactName = matcher.group(2);
move = new ClassRefactor(className, className, sourceArtifactName, destinationArtifactName);
}
return Optional.ofNullable(move);
}
use of org.apache.tapestry5.ioc.annotations.Optional in project tapestry-5 by apache.
the class JavaScriptModule method setupCoreJavaScriptStack.
/**
* The core JavaScriptStack has a number of entries:
* <dl>
* <dt>requirejs</dt> <dd>The RequireJS AMD JavaScript library</dd>
* <dt>scriptaculous.js, effects.js</dt> <dd>Optional JavaScript libraries in compatibility mode (see {@link Trait#SCRIPTACULOUS})</dd>
* <dt>t53-compatibility.js</dt> <dd>Optional JavaScript library (see {@link Trait#INITIALIZERS})</dd>
* <dt>underscore-library, underscore-module</dt>
* <dt>The Underscore JavaScript library, and the shim that allows underscore to be injected</dt>
* <dt>t5/core/init</dt> <dd>Optional module related to t53-compatibility.js</dd>
* <dt>jquery-library</dt> <dd>The jQuery library</dd>
* <dt>jquery-noconflict</dt> <dd>Switches jQuery to no-conflict mode (only present when the infrastructure is "prototype").</dd>
* <dt>jquery</dt> <dd>A module shim that allows jQuery to be injected (and also switches jQuery to no-conflict mode)</dd>
* <dt>bootstrap.css, tapestry.css, exception-frame.css, tapestry-console.css, tree.css</dt>
* <dd>CSS files</dd>
* <dt>t5/core/[...]</dt>
* <dd>Additional JavaScript modules</dd>
* <dt>jquery</dt>
* <dd>Added if the infrastructure provider is "jquery".</dd>
* </dl>
*
* User modules may replace or extend this list.
*/
@Contribute(JavaScriptStack.class)
@Core
public static void setupCoreJavaScriptStack(OrderedConfiguration<StackExtension> configuration, Compatibility compatibility, @Symbol(SymbolConstants.JAVASCRIPT_INFRASTRUCTURE_PROVIDER) String provider) {
configuration.add("requirejs", StackExtension.library(ROOT + "/require.js"));
configuration.add("underscore-library", StackExtension.library(ROOT + "/underscore-1.8.3.js"));
if (provider.equals("prototype")) {
final String SCRIPTY = "${tapestry.scriptaculous}";
add(configuration, StackExtensionType.LIBRARY, SCRIPTY + "/prototype.js");
if (compatibility.enabled(Trait.SCRIPTACULOUS)) {
add(configuration, StackExtensionType.LIBRARY, SCRIPTY + "/scriptaculous.js", SCRIPTY + "/effects.js");
}
}
if (compatibility.enabled(Trait.INITIALIZERS)) {
add(configuration, StackExtensionType.LIBRARY, ROOT + "/t53-compatibility.js");
configuration.add("t5/core/init", new StackExtension(StackExtensionType.MODULE, "t5/core/init"));
}
configuration.add("jquery-library", StackExtension.library(ROOT + "/jquery.js"));
if (provider.equals("prototype")) {
configuration.add("jquery-noconflict", StackExtension.library(ROOT + "/jquery-noconflict.js"));
}
add(configuration, StackExtensionType.MODULE, "jquery");
add(configuration, StackExtensionType.STYLESHEET, "${" + SymbolConstants.FONT_AWESOME_ROOT + "}/css/font-awesome.css");
if (compatibility.enabled(Trait.BOOTSTRAP_3) && compatibility.enabled(Trait.BOOTSTRAP_4)) {
throw new RuntimeException("You cannot have Trait.BOOTSTRAP_3 and Trait.BOOTSTRAP_4 enabled at the same time. Check your contributions to the Compatibility service.");
}
if (compatibility.enabled(Trait.BOOTSTRAP_3)) {
addCoreStylesheets(configuration, "${" + SymbolConstants.BOOTSTRAP_ROOT + "}/css/bootstrap.css");
}
if (compatibility.enabled(Trait.BOOTSTRAP_4)) {
addCoreStylesheets(configuration, "${" + SymbolConstants.BOOTSTRAP_ROOT + "}/css/bootstrap.css");
add(configuration, StackExtensionType.STYLESHEET, "${" + SymbolConstants.BOOTSTRAP_ROOT + "}/css/bootstrap-grid.css");
}
if (!compatibility.enabled(Trait.BOOTSTRAP_3) && !compatibility.enabled(Trait.BOOTSTRAP_4)) {
configuration.add("defaultcss", StackExtension.stylesheet("${" + SymbolConstants.DEFAULT_STYLESHEET + "}"));
}
for (String name : bundledModules) {
String full = "t5/core/" + name;
configuration.add(full, StackExtension.module(full));
}
configuration.add("underscore-module", StackExtension.module("underscore"));
}
use of org.apache.tapestry5.ioc.annotations.Optional in project tapestry-5 by apache.
the class OnEventWorker method createRequestBodyProvider.
@SuppressWarnings({ "unchecked", "rawtypes" })
private EventHandlerMethodParameterProvider createRequestBodyProvider(PlasticMethod method, final int parameterIndex, final String parameterTypeName, final boolean allowEmpty) {
final String methodIdentifier = method.getMethodIdentifier();
return (event) -> {
Invokable<Object> operation = () -> {
Class parameterType = classCache.forName(parameterTypeName);
Optional result = restSupport.getRequestBodyAs(parameterType);
if (!allowEmpty && !result.isPresent()) {
throw new RuntimeException(String.format("The request has an empty body and %s has one parameter with @RequestBody(allowEmpty=false)", methodIdentifier));
}
return result.orElse(null);
};
return operationTracker.invoke("Converting HTTP request body for @RequestBody parameter", operation);
};
}
Aggregations