tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ted Steen" <ted.st...@gmail.com>
Subject Re: svn commit: r501138 - in /tapestry/tapestry5/tapestry-core/trunk/src: main/java/org/apache/tapestry/internal/services/ main/java/org/apache/tapestry/internal/test/ main/java/org/apache/tapestry/services/ main/java/org/apache/tapestry/test/ test/j
Date Mon, 29 Jan 2007 19:00:36 GMT
yay!

2007/1/29, hlship@apache.org <hlship@apache.org>:
> Author: hlship
> Date: Mon Jan 29 10:23:26 2007
> New Revision: 501138
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=501138
> Log:
> Ensure that removed fields do not show up as unclaimed fields, which cause class load
errors.
>
> Added:
>     tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/base/
>     tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/base/BaseComponent.java
>     tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/RemoveFieldBean.java
> Modified:
>     tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformationImpl.java
>     tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/UnclaimedFieldWorker.java
>     tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java
>     tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ClassTransformation.java
>     tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
>     tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/FlashDemo.java
>     tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InternalClassTransformationImplTest.java
>
> Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformationImpl.java
> URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformationImpl.java?view=diff&rev=501138&r1=501137&r2=501138
> ==============================================================================
> --- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformationImpl.java
(original)
> +++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformationImpl.java
Mon Jan 29 10:23:26 2007
> @@ -197,7 +197,7 @@
>
>          _constructor.append(");\n");
>
> -        // The "}" will be added later, inside
> +        // The "}" will be added later, inside
>      }
>
>      private void freeze()
> @@ -930,12 +930,20 @@
>          return result;
>      }
>
> -    public String[] findUnclaimedFields()
> +    public List<String> findUnclaimedFields()
>      {
>          failIfFrozen();
>
>          List<String> names = newList();
>
> +        Set<String> skipped = newSet();
> +
> +        skipped.addAll(_claimedFields.keySet());
> +        skipped.addAll(_addedFieldNames);
> +
> +        if (_removedFieldNames != null)
> +            skipped.addAll(_removedFieldNames);
> +
>          for (CtField field : _ctClass.getDeclaredFields())
>          {
>              if (!isInstanceField(field))
> @@ -943,7 +951,7 @@
>
>              String name = field.getName();
>
> -            if (_claimedFields.containsKey(name) || _addedFieldNames.contains(name))
> +            if (skipped.contains(name))
>                  continue;
>
>              // May need to add a filter to edit out explicitly added fields.
> @@ -953,7 +961,7 @@
>
>          Collections.sort(names);
>
> -        return names.toArray(new String[names.size()]);
> +        return names;
>      }
>
>      private boolean isInstanceField(CtField field)
> @@ -1169,7 +1177,7 @@
>          _constructor.append(initializer);
>
>          // This finally matches the "{" added inside the constructor
> -
> +
>          _constructor.append("();\n\n}");
>
>          String constructorBody = _constructor.toString();
>
> Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/UnclaimedFieldWorker.java
> URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/UnclaimedFieldWorker.java?view=diff&rev=501138&r1=501137&r2=501138
> ==============================================================================
> --- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/UnclaimedFieldWorker.java
(original)
> +++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/UnclaimedFieldWorker.java
Mon Jan 29 10:23:26 2007
> @@ -12,50 +12,49 @@
>  // See the License for the specific language governing permissions and
>  // limitations under the License.
>
> -package org.apache.tapestry.internal.services;
> -
> -import static org.apache.tapestry.services.TransformConstants.CONTAINING_PAGE_DID_DETACH_SIGNATURE;
> -import static org.apache.tapestry.services.TransformConstants.CONTAINING_PAGE_DID_LOAD_SIGNATURE;
> -
> -import java.lang.reflect.Modifier;
> -
> -import org.apache.tapestry.model.MutableComponentModel;
> -import org.apache.tapestry.services.ClassTransformation;
> -import org.apache.tapestry.services.ComponentClassTransformWorker;
> -
> -/**
> - * Designed to be just about the last worker in the pipeline. Its job is to add cleanup
code that
> - * restores transient fields back to their initial (null) value.
> - *
> - *
> - */
> -public final class UnclaimedFieldWorker implements ComponentClassTransformWorker
> -{
> -
> -    public void transform(ClassTransformation transformation, MutableComponentModel
model)
> -    {
> -        String[] fieldNames = transformation.findUnclaimedFields();
> -
> -        for (String fieldName : fieldNames)
> -        {
> -            transformField(fieldName, transformation);
> -        }
> -    }
> -
> -    private void transformField(String fieldName, ClassTransformation transformation)
> -    {
> -        String type = transformation.getFieldType(fieldName);
> -
> -        String defaultFieldName = transformation.addField(Modifier.PRIVATE, type, fieldName
> -                + "_default");
> -
> -        transformation.extendMethod(CONTAINING_PAGE_DID_LOAD_SIGNATURE, defaultFieldName
+ " = "
> -                + fieldName + ";");
> -
> -        // At the end of the request, we want to move the default value back over the
> -        // active field value. This will most often be null.
> -
> -        transformation.extendMethod(CONTAINING_PAGE_DID_DETACH_SIGNATURE, fieldName
+ " = "
> -                + defaultFieldName + ";");
> -    }
> -}
> +package org.apache.tapestry.internal.services;
> +
> +import static org.apache.tapestry.services.TransformConstants.CONTAINING_PAGE_DID_DETACH_SIGNATURE;
> +import static org.apache.tapestry.services.TransformConstants.CONTAINING_PAGE_DID_LOAD_SIGNATURE;
> +
> +import java.lang.reflect.Modifier;
> +import java.util.List;
> +
> +import org.apache.tapestry.model.MutableComponentModel;
> +import org.apache.tapestry.services.ClassTransformation;
> +import org.apache.tapestry.services.ComponentClassTransformWorker;
> +
> +/**
> + * Designed to be just about the last worker in the pipeline. Its job is to add cleanup
code that
> + * restores transient fields back to their initial (null) value.
> + */
> +public final class UnclaimedFieldWorker implements ComponentClassTransformWorker
> +{
> +
> +    public void transform(ClassTransformation transformation, MutableComponentModel
model)
> +    {
> +        List<String> fieldNames = transformation.findUnclaimedFields();
> +
> +        for (String fieldName : fieldNames)
> +        {
> +            transformField(fieldName, transformation);
> +        }
> +    }
> +
> +    private void transformField(String fieldName, ClassTransformation transformation)
> +    {
> +        String type = transformation.getFieldType(fieldName);
> +
> +        String defaultFieldName = transformation.addField(Modifier.PRIVATE, type, fieldName
> +                + "_default");
> +
> +        transformation.extendMethod(CONTAINING_PAGE_DID_LOAD_SIGNATURE, defaultFieldName
+ " = "
> +                + fieldName + ";");
> +
> +        // At the end of the request, we want to move the default value back over the
> +        // active field value. This will most often be null.
> +
> +        transformation.extendMethod(CONTAINING_PAGE_DID_DETACH_SIGNATURE, fieldName
+ " = "
> +                + defaultFieldName + ";");
> +    }
> +}
>
> Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java
> URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java?view=diff&rev=501138&r1=501137&r2=501138
> ==============================================================================
> --- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java
(original)
> +++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java
Mon Jan 29 10:23:26 2007
> @@ -1,4 +1,4 @@
> -// Copyright , 2007 The Apache Software Foundation
> +// Copyright 2006, 2007 The Apache Software Foundation
>  //
>  // Licensed under the Apache License, Version 2.0 (the "License");
>  // you may not use this file except in compliance with the License.
>
> Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ClassTransformation.java
> URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ClassTransformation.java?view=diff&rev=501138&r1=501137&r2=501138
> ==============================================================================
> --- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ClassTransformation.java
(original)
> +++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ClassTransformation.java
Mon Jan 29 10:23:26 2007
> @@ -159,7 +159,7 @@
>       * {@link #claimField(String, Object)}) and returns the names of those fields. May
return an
>       * empty array.
>       */
> -    String[] findUnclaimedFields();
> +    List<String> findUnclaimedFields();
>
>      /**
>       * Obtains the type of a declared instance field.
>
> Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
> URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java?view=diff&rev=501138&r1=501137&r2=501138
> ==============================================================================
> --- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
(original)
> +++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
Mon Jan 29 10:23:26 2007
> @@ -127,7 +127,7 @@
>      protected final void train_findUnclaimedFields(ClassTransformation transformation,
>              String... fieldNames)
>      {
> -        expect(transformation.findUnclaimedFields()).andReturn(fieldNames);
> +        expect(transformation.findUnclaimedFields()).andReturn(Arrays.asList(fieldNames));
>      }
>
>      /** Writes a change to a file. */
> @@ -743,7 +743,8 @@
>          return newMock(ApplicationStatePersistenceStrategySource.class);
>      }
>
> -    protected final <T> void train_get(ApplicationStatePersistenceStrategy strategy,
Class<T> asoClass, ApplicationStateCreator<T> creator, T aso)
> +    protected final <T> void train_get(ApplicationStatePersistenceStrategy strategy,
> +            Class<T> asoClass, ApplicationStateCreator<T> creator, T aso)
>      {
>          expect(strategy.get(asoClass, creator)).andReturn(aso);
>      }
> @@ -753,7 +754,8 @@
>          expect(creator.create()).andReturn(aso);
>      }
>
> -    protected final void train_get(ApplicationStatePersistenceStrategySource source,
String strategyName, ApplicationStatePersistenceStrategy strategy)
> +    protected final void train_get(ApplicationStatePersistenceStrategySource source,
> +            String strategyName, ApplicationStatePersistenceStrategy strategy)
>      {
>          expect(source.get(strategyName)).andReturn(strategy).atLeastOnce();
>      }
>
> Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/base/BaseComponent.java
> URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/base/BaseComponent.java?view=auto&rev=501138
> ==============================================================================
> --- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/base/BaseComponent.java
(added)
> +++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/base/BaseComponent.java
Mon Jan 29 10:23:26 2007
> @@ -0,0 +1,37 @@
> +// Copyright 2007 The Apache Software Foundation
> +//
> +// Licensed under the Apache License, Version 2.0 (the "License");
> +// you may not use this file except in compliance with the License.
> +// You may obtain a copy of the License at
> +//
> +//     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 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.
> +
> +package org.apache.tapestry.integration.app1.base;
> +
> +import org.apache.tapestry.annotations.ApplicationState;
> +import org.apache.tapestry.annotations.ComponentClass;
> +import org.apache.tapestry.integration.app1.data.IncidentData;
> +
> +@ComponentClass
> +public class BaseComponent
> +{
> +    @ApplicationState
> +    private IncidentData _incidentData;
> +
> +    public IncidentData getIncidentData()
> +    {
> +        return _incidentData;
> +    }
> +
> +    public void setIncidentData(IncidentData incidentData)
> +    {
> +        _incidentData = incidentData;
> +    }
> +
> +}
>
> Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/FlashDemo.java
> URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/FlashDemo.java?view=diff&rev=501138&r1=501137&r2=501138
> ==============================================================================
> --- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/FlashDemo.java
(original)
> +++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/FlashDemo.java
Mon Jan 29 10:23:26 2007
> @@ -16,9 +16,10 @@
>
>  import org.apache.tapestry.annotations.ComponentClass;
>  import org.apache.tapestry.annotations.Persist;
> +import org.apache.tapestry.integration.app1.base.BaseComponent;
>
>  @ComponentClass(meta = "tapestry.persistence-strategy=flash")
> -public class FlashDemo
> +public class FlashDemo extends BaseComponent
>  {
>      @Persist
>      private String _message;
>
> Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InternalClassTransformationImplTest.java
> URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InternalClassTransformationImplTest.java?view=diff&rev=501138&r1=501137&r2=501138
> ==============================================================================
> --- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InternalClassTransformationImplTest.java
(original)
> +++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InternalClassTransformationImplTest.java
Mon Jan 29 10:23:26 2007
> @@ -1,4 +1,4 @@
> -// Copyright 2006 The Apache Software Foundation
> +// Copyright 2006, 2007 The Apache Software Foundation
>  //
>  // Licensed under the Apache License, Version 2.0 (the "License");
>  // you may not use this file except in compliance with the License.
> @@ -313,15 +313,15 @@
>
>          ClassTransformation ct = createClassTransformation(ClaimedFields.class, log);
>
> -        String[] unclaimed = ct.findUnclaimedFields();
> +        List<String> unclaimed = ct.findUnclaimedFields();
>
> -        assertEquals(Arrays.asList(unclaimed), asList("_field1", "_field4", "_zzfield"));
> +        assertEquals(unclaimed, asList("_field1", "_field4", "_zzfield"));
>
>          ct.claimField("_field4", "Fred");
>
>          unclaimed = ct.findUnclaimedFields();
>
> -        assertEquals(Arrays.asList(unclaimed), asList("_field1", "_zzfield"));
> +        assertEquals(unclaimed, asList("_field1", "_zzfield"));
>
>          try
>          {
> @@ -349,9 +349,9 @@
>
>          ct.addField(Modifier.PRIVATE, "int", "newField");
>
> -        String[] unclaimed = ct.findUnclaimedFields();
> +        List<String> unclaimed = ct.findUnclaimedFields();
>
> -        assertEquals(Arrays.asList(unclaimed), asList("_field1", "_field4", "_zzfield"));
> +        assertEquals(unclaimed, asList("_field1", "_field4", "_zzfield"));
>
>          verify();
>      }
> @@ -671,6 +671,27 @@
>                      ex.getCause().getMessage(),
>                      "Field org.apache.tapestry.internal.services.ReadOnlyBean._value
is read-only.");
>          }
> +
> +        verify();
> +    }
> +
> +    @Test
> +    public void removed_fields_should_not_show_up_as_unclaimed() throws Exception
> +    {
> +        InternalComponentResources resources = newInternalComponentResources();
> +
> +        Log log = newLog();
> +
> +        replay();
> +
> +        CtClass targetObjectCtClass = findCtClass(RemoveFieldBean.class);
> +
> +        InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass,
> +                _contextClassLoader, log, null);
> +
> +        ct.removeField("_barney");
> +
> +        assertEquals(ct.findUnclaimedFields(), asList("_fred"));
>
>          verify();
>      }
>
> Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/RemoveFieldBean.java
> URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/RemoveFieldBean.java?view=auto&rev=501138
> ==============================================================================
> --- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/RemoveFieldBean.java
(added)
> +++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/RemoveFieldBean.java
Mon Jan 29 10:23:26 2007
> @@ -0,0 +1,24 @@
> +// Copyright 2007 The Apache Software Foundation
> +//
> +// Licensed under the Apache License, Version 2.0 (the "License");
> +// you may not use this file except in compliance with the License.
> +// You may obtain a copy of the License at
> +//
> +//     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 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.
> +
> +package org.apache.tapestry.internal.services;
> +
> +public class RemoveFieldBean
> +{
> +    @SuppressWarnings("unused")
> +    private String _fred;
> +
> +    @SuppressWarnings("unused")
> +    private String _barney;
> +}
>
>
>


-- 
/ted

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Mime
View raw message