Search in sources :

Example 11 with Optional

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");
}
Also used : ClassRefactor(org.apache.tapestry5.versionmigrator.ClassRefactor) Test(org.testng.annotations.Test)

Example 12 with Optional

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;
}
Also used : OutputStream(java.io.OutputStream) ArtifactChangeRefactorCommitParser(org.apache.tapestry5.versionmigrator.internal.ArtifactChangeRefactorCommitParser) Arrays(java.util.Arrays) Properties(java.util.Properties) Files(java.nio.file.Files) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) ArrayList(java.util.ArrayList) Formatter(java.util.Formatter) PackageAndArtifactChangeRefactorCommitParser(org.apache.tapestry5.versionmigrator.internal.PackageAndArtifactChangeRefactorCommitParser) List(java.util.List) Paths(java.nio.file.Paths) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PackageChangeRefactorCommitParser(org.apache.tapestry5.versionmigrator.internal.PackageChangeRefactorCommitParser) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) Comparator(java.util.Comparator) Path(java.nio.file.Path) InputStream(java.io.InputStream) ArtifactChangeRefactorCommitParser(org.apache.tapestry5.versionmigrator.internal.ArtifactChangeRefactorCommitParser) PackageAndArtifactChangeRefactorCommitParser(org.apache.tapestry5.versionmigrator.internal.PackageAndArtifactChangeRefactorCommitParser) ArrayList(java.util.ArrayList) PackageAndArtifactChangeRefactorCommitParser(org.apache.tapestry5.versionmigrator.internal.PackageAndArtifactChangeRefactorCommitParser) PackageChangeRefactorCommitParser(org.apache.tapestry5.versionmigrator.internal.PackageChangeRefactorCommitParser)

Example 13 with Optional

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);
}
Also used : ClassRefactor(org.apache.tapestry5.versionmigrator.ClassRefactor) Matcher(java.util.regex.Matcher)

Example 14 with Optional

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"));
}
Also used : StackExtension(org.apache.tapestry5.services.javascript.StackExtension) Contribute(org.apache.tapestry5.ioc.annotations.Contribute) Core(org.apache.tapestry5.services.Core)

Example 15 with Optional

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);
    };
}
Also used : PlasticField(org.apache.tapestry5.plastic.PlasticField) Arrays(java.util.Arrays) Array(java.lang.reflect.Array) Flow(org.apache.tapestry5.func.Flow) JSONObject(org.apache.tapestry5.json.JSONObject) MethodInvocation(org.apache.tapestry5.plastic.MethodInvocation) ComponentClassCache(org.apache.tapestry5.internal.services.ComponentClassCache) ExceptionUtils(org.apache.tapestry5.commons.util.ExceptionUtils) PublishServerSideEvents(org.apache.tapestry5.corelib.mixins.PublishServerSideEvents) CollectionFactory(org.apache.tapestry5.commons.util.CollectionFactory) Map(java.util.Map) TransformConstants(org.apache.tapestry5.services.TransformConstants) LocalVariable(org.apache.tapestry5.plastic.LocalVariable) JSONArray(org.apache.tapestry5.json.JSONArray) ValueEncoder(org.apache.tapestry5.ValueEncoder) Event(org.apache.tapestry5.runtime.Event) PageLifecycleListener(org.apache.tapestry5.runtime.PageLifecycleListener) Predicate(org.apache.tapestry5.func.Predicate) Set(java.util.Set) Invokable(org.apache.tapestry5.ioc.Invokable) ComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) MutableComponentModel(org.apache.tapestry5.model.MutableComponentModel) MethodAdvice(org.apache.tapestry5.plastic.MethodAdvice) List(java.util.List) ComponentClassTransformWorker2(org.apache.tapestry5.services.transform.ComponentClassTransformWorker2) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) EventContext(org.apache.tapestry5.EventContext) InternalConstants(org.apache.tapestry5.internal.InternalConstants) RequestBody(org.apache.tapestry5.annotations.RequestBody) PublishEvent(org.apache.tapestry5.annotations.PublishEvent) MethodParameter(org.apache.tapestry5.plastic.MethodParameter) Request(org.apache.tapestry5.http.services.Request) OnEvent(org.apache.tapestry5.annotations.OnEvent) LocalVariableCallback(org.apache.tapestry5.plastic.LocalVariableCallback) ComponentResources(org.apache.tapestry5.ComponentResources) RequestParameter(org.apache.tapestry5.annotations.RequestParameter) ValueEncoderSource(org.apache.tapestry5.services.ValueEncoderSource) RestSupport(org.apache.tapestry5.http.services.RestSupport) StaticActivationContextValue(org.apache.tapestry5.annotations.StaticActivationContextValue) PlasticMethod(org.apache.tapestry5.plastic.PlasticMethod) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) Condition(org.apache.tapestry5.plastic.Condition) MethodDescription(org.apache.tapestry5.plastic.MethodDescription) InstructionBuilderCallback(org.apache.tapestry5.plastic.InstructionBuilderCallback) InstructionBuilder(org.apache.tapestry5.plastic.InstructionBuilder) PlasticClass(org.apache.tapestry5.plastic.PlasticClass) TransformationSupport(org.apache.tapestry5.services.transform.TransformationSupport) OperationTracker(org.apache.tapestry5.ioc.OperationTracker) DisableStrictChecks(org.apache.tapestry5.annotations.DisableStrictChecks) F(org.apache.tapestry5.func.F) InternalUtils(org.apache.tapestry5.ioc.internal.util.InternalUtils) Mapper(org.apache.tapestry5.func.Mapper) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) Optional(java.util.Optional) Invokable(org.apache.tapestry5.ioc.Invokable) PlasticClass(org.apache.tapestry5.plastic.PlasticClass)

Aggregations

ClassRefactor (org.apache.tapestry5.versionmigrator.ClassRefactor)6 Test (org.testng.annotations.Test)5 List (java.util.List)3 Optional (java.util.Optional)3 Matcher (java.util.regex.Matcher)3 JSONObject (org.apache.tapestry5.json.JSONObject)3 Arrays (java.util.Arrays)2 Map (java.util.Map)2 Set (java.util.Set)2 RequestParameter (org.apache.tapestry5.annotations.RequestParameter)2 RestSupportImpl (org.apache.tapestry5.http.internal.services.RestSupportImpl)2 HttpRequestBodyConverter (org.apache.tapestry5.http.services.HttpRequestBodyConverter)2 RestSupport (org.apache.tapestry5.http.services.RestSupport)2 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)2 BeanInfo (java.beans.BeanInfo)1 IntrospectionException (java.beans.IntrospectionException)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 BufferedOutputStream (java.io.BufferedOutputStream)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1