001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *        http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 */
019package org.apache.isis.tool.mavenplugin;
020
021import java.util.Collection;
022import org.apache.maven.plugin.MojoExecutionException;
023import org.apache.maven.plugin.MojoFailureException;
024import org.apache.maven.plugins.annotations.LifecyclePhase;
025import org.apache.maven.plugins.annotations.Mojo;
026import org.apache.maven.plugins.annotations.ResolutionScope;
027import org.apache.isis.core.metamodel.app.IsisMetaModel;
028import org.apache.isis.core.metamodel.spec.ObjectSpecification;
029import org.apache.isis.core.metamodel.specloader.validator.ValidationFailures;
030
031@Mojo(
032        name = "validate",
033        defaultPhase = LifecyclePhase.TEST,
034        requiresProject = true,
035        requiresDependencyResolution = ResolutionScope.COMPILE,
036        requiresDependencyCollection = ResolutionScope.COMPILE
037)
038public class IsisMojoValidate extends IsisMojoAbstract {
039
040    protected IsisMojoValidate() {
041        super(new ValidateMetaModelProcessor());
042    }
043
044    static class ValidateMetaModelProcessor implements MetaModelProcessor {
045        @Override
046        public void process(final IsisMetaModel isisMetaModel, final Context context) throws MojoFailureException, MojoExecutionException {
047            final Collection<ObjectSpecification> objectSpecifications = isisMetaModel.getSpecificationLoader().allSpecifications();
048            for (ObjectSpecification objectSpecification : objectSpecifications) {
049                context.getLog().debug("loaded: " + objectSpecification.getFullIdentifier());
050            }
051
052            final ValidationFailures validationFailures = isisMetaModel.getValidationFailures();
053            if (validationFailures.occurred()) {
054                context.throwFailureException(validationFailures.getNumberOfMessages() + " problems found.", validationFailures.getMessages());
055            }
056        }
057    }
058
059}