Improving the assembly problem reporting, by aggregating problems and reporting more in one single report.
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/0cf199bc Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/0cf199bc Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/0cf199bc Branch: refs/heads/develop Commit: 0cf199bc006da898d9b70c2d987875b0b4a86c22 Parents: 0321a7f Author: niclas <[email protected]> Authored: Fri Apr 7 16:22:02 2017 +0800 Committer: niclas <[email protected]> Committed: Fri Apr 7 16:22:02 2017 +0800 ---------------------------------------------------------------------- .../bootstrap/AssemblyReportException.java | 83 +++++++++++++ .../bootstrap/AssemblyResportException.java | 60 --------- .../apache/polygene/bootstrap/Energy4Java.java | 2 +- .../polygene/runtime/PolygeneRuntimeImpl.java | 2 +- .../bootstrap/CompositeAssemblyImpl.java | 6 +- .../runtime/bootstrap/ModuleAssemblyImpl.java | 122 +++++++++++++++---- .../concerns/PropertyInheritanceTest.java | 16 +-- .../polygene/library/scripting/ScriptUtil.java | 32 ----- .../library/scripting/ScriptUtilImpl.java | 35 ------ .../library/scripting/ScriptUtilImplTest.java | 41 ------- 10 files changed, 191 insertions(+), 208 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0cf199bc/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/AssemblyReportException.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/AssemblyReportException.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/AssemblyReportException.java new file mode 100644 index 0000000..e4139bd --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/AssemblyReportException.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.polygene.bootstrap; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Thrown when one or more assembly problems has occurred. + */ +public class AssemblyReportException extends AssemblyException +{ + private List<Throwable> problems; + private String modelReport; + + public AssemblyReportException( List<Throwable> problems ) + { + this.problems = problems; + } + + @Override + public String getMessage() + { + String message; + if( modelReport == null ) + { + message = "\nComposition Problems Report:\n"; + } + else + { + message = modelReport; + } + return message + problems.stream() + .map( this::composeMessage ) + .map( m -> m + "\n--\n" ) + .collect( Collectors.joining( "" ) ); + } + + public void attacheModelReport( String modelReport ) + { + this.modelReport = modelReport; + } + + private String composeMessage( Throwable exception ) + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream( baos ); + if( Boolean.getBoolean( "polygene.report.exceptions" ) ) + { + exception.printStackTrace( ps ); + } + else + { + StringBuilder indent = new StringBuilder( ); + while( exception != null ){ + indent = indent.append( " " ); + ps.println(indent.toString() + exception.getMessage()); + ps.println("---"); + exception = exception.getCause(); + } + } + return baos.toString(); + } +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0cf199bc/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/AssemblyResportException.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/AssemblyResportException.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/AssemblyResportException.java deleted file mode 100644 index 0129233..0000000 --- a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/AssemblyResportException.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.polygene.bootstrap; - -import java.util.List; -import java.util.stream.Collectors; - -/** - * Thrown when one or more assembly problems has occurred. - */ -public class AssemblyResportException extends AssemblyException -{ - private List<Throwable> problems; - private String modelReport; - - public AssemblyResportException( List<Throwable> problems ) - { - this.problems = problems; - } - - @Override - public String getMessage() - { - String message; - if( modelReport == null ) - { - message = "\nComposition Problems Report:\n"; - } - else - { - message = modelReport; - } - return message + problems.stream() - .map( Throwable::getMessage ) - .map( m -> m + "\n--\n" ) - .collect( Collectors.joining( "" ) ); - } - - public void attacheModelReport( String modelReport ) - { - this.modelReport = modelReport; - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0cf199bc/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/Energy4Java.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/Energy4Java.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/Energy4Java.java index 67b6da4..a4cf0c3 100644 --- a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/Energy4Java.java +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/Energy4Java.java @@ -80,7 +80,7 @@ public final class Energy4Java } return model; } - catch( AssemblyResportException e ) + catch( AssemblyReportException e ) { e.attacheModelReport( InvalidCompositeException.modelReport() ); throw e; http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0cf199bc/core/runtime/src/main/java/org/apache/polygene/runtime/PolygeneRuntimeImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/PolygeneRuntimeImpl.java b/core/runtime/src/main/java/org/apache/polygene/runtime/PolygeneRuntimeImpl.java index 2a0be69..372fb18 100644 --- a/core/runtime/src/main/java/org/apache/polygene/runtime/PolygeneRuntimeImpl.java +++ b/core/runtime/src/main/java/org/apache/polygene/runtime/PolygeneRuntimeImpl.java @@ -275,7 +275,7 @@ public final class PolygeneRuntimeImpl ValueInstance valueInstance = ValueInstance.valueInstanceOf( (ValueComposite) value ); return valueInstance.descriptor(); } - throw new IllegalArgumentException( "Wrong type. Must be subtype of " + ValueComposite.class ); + throw new IllegalArgumentException( "Wrong type. {" + value + "} must be subtype of " + ValueComposite.class ); } @Override http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0cf199bc/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/CompositeAssemblyImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/CompositeAssemblyImpl.java b/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/CompositeAssemblyImpl.java index bb4254d..33b16b9 100644 --- a/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/CompositeAssemblyImpl.java +++ b/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/CompositeAssemblyImpl.java @@ -68,7 +68,7 @@ import org.apache.polygene.api.util.Annotations; import org.apache.polygene.api.util.Classes; import org.apache.polygene.api.util.Fields; import org.apache.polygene.api.util.HierarchicalVisitorAdapter; -import org.apache.polygene.bootstrap.AssemblyResportException; +import org.apache.polygene.bootstrap.AssemblyReportException; import org.apache.polygene.bootstrap.StateDeclarations; import org.apache.polygene.runtime.association.AssociationModel; import org.apache.polygene.runtime.association.AssociationsModel; @@ -214,6 +214,7 @@ public abstract class CompositeAssemblyImpl Set<Class<?>> thisDependencies = new HashSet<>(); types.forEach( mixinType -> { + for( Method method : mixinType.getMethods() ) { try @@ -270,6 +271,7 @@ public abstract class CompositeAssemblyImpl } catch( Exception e ) { + System.out.println("NICLAS 2: " + e.getClass() + " - " + e.getMessage()); exceptions.add( e ); } } @@ -303,7 +305,7 @@ public abstract class CompositeAssemblyImpl } ); if( exceptions.size() > 0 ) { - throw new AssemblyResportException( exceptions ); + throw new AssemblyReportException( exceptions ); } } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0cf199bc/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/ModuleAssemblyImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/ModuleAssemblyImpl.java b/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/ModuleAssemblyImpl.java index 43478bf..011da1b 100644 --- a/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/ModuleAssemblyImpl.java +++ b/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/ModuleAssemblyImpl.java @@ -27,6 +27,7 @@ import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -49,6 +50,7 @@ import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; import org.apache.polygene.api.value.ValueComposite; import org.apache.polygene.bootstrap.Assembler; import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.AssemblyReportException; import org.apache.polygene.bootstrap.AssemblySpecifications; import org.apache.polygene.bootstrap.AssemblyVisitor; import org.apache.polygene.bootstrap.ConfigurationDeclaration; @@ -497,6 +499,7 @@ final class ModuleAssemblyImpl throws AssemblyException { addDefaultAssemblers(); + List<Throwable> exceptions = new ArrayList<>(); List<TransientModel> transientModels = new ArrayList<>(); List<ObjectModel> objectModels = new ArrayList<>(); List<ValueModel> valueModels = new ArrayList<>(); @@ -520,20 +523,56 @@ final class ModuleAssemblyImpl } transientModels.addAll(transientAssemblies.values().stream() - .map(composite -> composite.newTransientModel(moduleModel, metaInfoDeclaration, helper)) + .map( composite -> + { + try + { + return composite.newTransientModel( moduleModel, metaInfoDeclaration, helper ); + } + catch( Exception e ) + { + exceptions.add( e ); + return null; + } + } ) + .filter( Objects::nonNull ) .collect(toList())); valueModels.addAll(valueAssemblies.values().stream() - .map(value -> value.newValueModel(moduleModel, metaInfoDeclaration, helper)) + .map( value -> + { + try + { + return value.newValueModel( moduleModel, metaInfoDeclaration, helper ); + } + catch( Exception e ) + { + exceptions.add( e ); + return null; + } + } ) + .filter( Objects::nonNull ) .collect(toList())); entityModels.addAll(entityAssemblies.values().stream() - .map(entityDeclaration -> entityDeclaration.newEntityModel(moduleModel, - metaInfoDeclaration, - metaInfoDeclaration, - metaInfoDeclaration, - metaInfoDeclaration, - helper)) + .map( entityDeclaration -> + { + try + { + return entityDeclaration.newEntityModel( moduleModel, + metaInfoDeclaration, + metaInfoDeclaration, + metaInfoDeclaration, + metaInfoDeclaration, + helper ); + } + catch( Exception e ) + { + exceptions.add( e ); + return null; + } + } ) + .filter( Objects::nonNull ) .collect(Collectors.toList())); for (ObjectAssemblyImpl objectDeclaration : objectAssemblies.values()) @@ -541,15 +580,27 @@ final class ModuleAssemblyImpl objectDeclaration.addObjectModel(moduleModel, objectModels); } - for (ServiceAssemblyImpl serviceDeclaration : serviceAssemblies) - { - if (serviceDeclaration.identity == null) - { - serviceDeclaration.identity = generateId(serviceDeclaration.types()); - } - - serviceModels.add(serviceDeclaration.newServiceModel(moduleModel, metaInfoDeclaration, helper)); - } + serviceModels.addAll( + serviceAssemblies + .stream() + .map( serviceDeclaration -> + { + try + { + if( serviceDeclaration.identity == null ) + { + serviceDeclaration.identity = generateId( serviceDeclaration.types() ); + } + return ( serviceDeclaration.newServiceModel( moduleModel, metaInfoDeclaration, helper ) ); + } + catch( Exception e ) + { + exceptions.add( e ); + return null; + } + } ) + .filter( Objects::nonNull ) + .collect( Collectors.toList() ) ); for (ImportedServiceAssemblyImpl importedServiceDeclaration : importedServiceAssemblies.values()) { @@ -563,22 +614,29 @@ final class ModuleAssemblyImpl String identity = serviceModel.identity().toString(); if (identities.contains(identity)) { - throw new DuplicateServiceIdentityException( - "Duplicated service reference: " + identity + " in module " + moduleModel.name() + DuplicateServiceIdentityException exception = new DuplicateServiceIdentityException( + "Duplicated service reference: " + identity + " in module " + moduleModel.name() ); + exceptions.add( exception.fillInStackTrace() ); + } else + { + identities.add( identity ); } - identities.add(identity); } for (ImportedServiceModel serviceModel : importedServiceModels) { String identity = serviceModel.identity().toString(); if (identities.contains(identity)) { - throw new DuplicateServiceIdentityException( + DuplicateServiceIdentityException exception = new DuplicateServiceIdentityException( "Duplicated service reference: " + identity + " in module " + moduleModel.name() ); + exceptions.add( exception.fillInStackTrace() ); + } + else + { + identities.add( identity ); } - identities.add(identity); } importedServiceModels @@ -589,10 +647,22 @@ final class ModuleAssemblyImpl .equals( importedServiceModel.serviceImporter() ) ) ) .forEach( importedServiceModel -> - objectModels.add( new ObjectModel( moduleModel, importedServiceModel.serviceImporter(), - Visibility.module, new MetaInfo() ) ) ); - - return moduleModel; + { + try + { + objectModels.add( new ObjectModel( moduleModel, importedServiceModel.serviceImporter(), + Visibility.module, new MetaInfo() ) ); + } + catch( Exception e ) + { + exceptions.add( e ); + } + } ); + if( exceptions.size() == 0 ) + { + return moduleModel; + } + throw new AssemblyReportException( exceptions ); } private void addDefaultAssemblers() http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0cf199bc/core/runtime/src/test/java/org/apache/polygene/runtime/concerns/PropertyInheritanceTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/concerns/PropertyInheritanceTest.java b/core/runtime/src/test/java/org/apache/polygene/runtime/concerns/PropertyInheritanceTest.java index 12550f2..1982f2d 100644 --- a/core/runtime/src/test/java/org/apache/polygene/runtime/concerns/PropertyInheritanceTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/runtime/concerns/PropertyInheritanceTest.java @@ -21,16 +21,15 @@ package org.apache.polygene.runtime.concerns; import java.util.ArrayList; import java.util.List; -import org.apache.polygene.test.AbstractPolygeneTest; -import org.junit.Test; -import org.apache.polygene.api.common.InvalidApplicationException; import org.apache.polygene.api.common.UseDefaults; import org.apache.polygene.api.concern.ConcernOf; import org.apache.polygene.api.concern.Concerns; -import org.apache.polygene.api.property.InvalidPropertyTypeException; import org.apache.polygene.api.property.Property; import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.AssemblyReportException; import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.test.AbstractPolygeneTest; +import org.junit.Test; import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.Assert.assertThat; @@ -53,13 +52,10 @@ public class PropertyInheritanceTest extends AbstractPolygeneTest protected void assemblyException( AssemblyException exception ) throws AssemblyException { - if( exception.getCause() instanceof InvalidApplicationException ) + if( exception instanceof AssemblyReportException ) { - if( exception.getCause().getCause() instanceof InvalidPropertyTypeException ) - { - failed = true; - return; - } + failed = true; + return; } super.assemblyException( exception ); } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0cf199bc/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptUtil.java ---------------------------------------------------------------------- diff --git a/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptUtil.java b/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptUtil.java deleted file mode 100644 index c03d783..0000000 --- a/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptUtil.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.polygene.library.scripting; - -import java.io.PrintStream; -import org.apache.polygene.api.mixin.Mixins; - -/** - * JAVADOC - */ -@Mixins( ScriptUtilImpl.class ) -public interface ScriptUtil -{ - PrintStream getOut(); -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0cf199bc/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptUtilImpl.java ---------------------------------------------------------------------- diff --git a/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptUtilImpl.java b/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptUtilImpl.java deleted file mode 100644 index e8a191c..0000000 --- a/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptUtilImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.polygene.library.scripting; - -import java.io.PrintStream; - -/** - * JAVADOC - */ -public class ScriptUtilImpl - implements ScriptUtil -{ - @Override - public PrintStream getOut() - { - return System.out; - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0cf199bc/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/ScriptUtilImplTest.java ---------------------------------------------------------------------- diff --git a/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/ScriptUtilImplTest.java b/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/ScriptUtilImplTest.java deleted file mode 100644 index 92937ac..0000000 --- a/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/ScriptUtilImplTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.polygene.library.scripting; - -import org.junit.Test; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -public class ScriptUtilImplTest -{ - @Test - public void testDefaultStream() - { - ScriptUtil underTest = new ScriptUtilImpl(); - assertThat( underTest.getOut(), equalTo(System.out)); - } - - @Test( expected = ScriptException.class ) - public void testException() - { - throw new ScriptException( "This is a test exception." ); - } -}
