This is an automated email from the ASF dual-hosted git repository. simonetripodi pushed a commit to branch analyzer-improvements in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git
commit becdf291e6dc4ed69b61246a465a54a78173775e Author: Simo Tripodi <[email protected]> AuthorDate: Wed Oct 3 15:10:44 2018 +0200 SLING-7976 - Track the slingfeature-maven-plugin:analyse-features activity and fail when the whole scan detects errors initial checkin --- pom.xml | 24 ++++++++++ src/it/analyzer-errors-detected/invoker.properties | 18 ++++++++ src/it/analyzer-errors-detected/pom.xml | 51 ++++++++++++++++++++++ .../src/main/features/errorsDetected.json | 23 ++++++++++ src/it/analyzer-errors-detected/verify.bsh | 42 ++++++++++++++++++ .../feature/maven/mojos/AnalyseFeaturesMojo.java | 35 ++++++++++++--- 6 files changed, 188 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 7383da1..7403abd 100644 --- a/pom.xml +++ b/pom.xml @@ -99,9 +99,33 @@ <exclude>src/test/resources/**/*.txt</exclude> <exclude>src/test/resources/**/*.feature</exclude> <exclude>src/test/resources/META-INF/services/*</exclude> + <exclude>src/it/**/*.json</exclude> </excludes> </configuration> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-invoker-plugin</artifactId> + <configuration> + <debug>true</debug> + <projectsDirectory>src/it</projectsDirectory> + <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> + <pomIncludes> + <pomInclude>**/pom.xml</pomInclude> + </pomIncludes> + <postBuildHookScript>verify</postBuildHookScript> + </configuration> + <executions> + <execution> + <id>integration-test</id> + <goals> + <goal>install</goal> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> </plugins> </build> diff --git a/src/it/analyzer-errors-detected/invoker.properties b/src/it/analyzer-errors-detected/invoker.properties new file mode 100644 index 0000000..7428e6a --- /dev/null +++ b/src/it/analyzer-errors-detected/invoker.properties @@ -0,0 +1,18 @@ +# 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. + +invoker.goals = clean org.apache.sling:slingfeature-maven-plugin:analyse-features test +invoker.buildResult = failure +invoker.debug = true diff --git a/src/it/analyzer-errors-detected/pom.xml b/src/it/analyzer-errors-detected/pom.xml new file mode 100644 index 0000000..f53d64f --- /dev/null +++ b/src/it/analyzer-errors-detected/pom.xml @@ -0,0 +1,51 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.sling</groupId> + <artifactId>slingfeature-maven-plugin-test</artifactId> + <packaging>jar</packaging> + <version>1.0.0-SNAPSHOT</version> + + <name>Apache Sling Features Maven plugin test</name> + + <build> + <plugins> + <plugin> + <groupId>@project.groupId@</groupId> + <artifactId>@project.artifactId@</artifactId> + <version>@project.version@</version> + <executions> + <execution> + <id>analyze</id> + <phase>test</phase> + <goals> + <goal>analyse-features</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + + <extensions> + <extension> + <groupId>@project.groupId@</groupId> + <artifactId>@project.artifactId@</artifactId> + <version>@project.version@</version> + </extension> + </extensions> + </build> + +</project> diff --git a/src/it/analyzer-errors-detected/src/main/features/errorsDetected.json b/src/it/analyzer-errors-detected/src/main/features/errorsDetected.json new file mode 100644 index 0000000..1c4abee --- /dev/null +++ b/src/it/analyzer-errors-detected/src/main/features/errorsDetected.json @@ -0,0 +1,23 @@ +{ + "id":"org.apache.sling:slingfeature-maven-plugin-test:1.0.0-SNAPSHOT", + "bundles":[ + { + "id":"org.osgi:org.osgi.framework:1.9.0", + "start-level":"20" + } + ], + "api-regions:JSON|false": [ + { + "name": "global", + "exports": [ + "org.osgi.util.function.doesnotexist" + ] + }, + { + "name": "asf", + "exports": [ + "org.osgi.util.function.doesnotexist" + ] + } + ] +} diff --git a/src/it/analyzer-errors-detected/verify.bsh b/src/it/analyzer-errors-detected/verify.bsh new file mode 100644 index 0000000..a3ed680 --- /dev/null +++ b/src/it/analyzer-errors-detected/verify.bsh @@ -0,0 +1,42 @@ +/* + * 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. + */ + +import java.io.*; +import java.util.*; + +import org.codehaus.plexus.util.*; + + boolean check() { + File file = new File(basedir, "build.log"); + String log = FileUtils.fileRead(file); + + if (log.indexOf("One or more features Analyzer detected Feature error(s), please read the plugin log for more datils") < 0) { + System.out.println( "FAILED!" ); + return false; + } + return true; + } + + try { + return check(); + } + catch(Throwable t) { + t.printStackTrace(); + return false; + } + + return true; diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/AnalyseFeaturesMojo.java b/src/main/java/org/apache/sling/feature/maven/mojos/AnalyseFeaturesMojo.java index 0d87a06..94b2431 100644 --- a/src/main/java/org/apache/sling/feature/maven/mojos/AnalyseFeaturesMojo.java +++ b/src/main/java/org/apache/sling/feature/maven/mojos/AnalyseFeaturesMojo.java @@ -60,21 +60,46 @@ public class AnalyseFeaturesMojo extends AbstractFeatureMojo { return ProjectHelper.getOrResolveArtifact(project, mavenSession, artifactHandlerManager, artifactResolver, id).getFile(); } }; + + boolean failed = false; + try { + getLog().debug("Setting up the Scanner..."); final Scanner scanner = new Scanner(am); + getLog().debug("Scanner successfully set up"); + + getLog().debug("Setting up the Analyser..."); final Analyser analyser = new Analyser(scanner); + getLog().debug("Analyser successfully set up"); + + getLog().debug("Retrieving Feature files..."); final Collection<Feature> features = ProjectHelper.getAssembledFeatures(this.project).values(); + + if (features.isEmpty()) { + getLog().debug("There are no assciated Feature files to current ptoject, plugin execution will be interrupted"); + return; + } else { + getLog().debug("Starting Features analysis..."); + } + for(final Feature f : features) { try { + getLog().debug("Analyzing Feature " + f.getId() + "..."); analyser.analyse(f); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + getLog().debug("Feature " + f.getId() + " succesfully passed all analysis"); + } catch (Throwable t) { + failed = true; + getLog().error("An error occurred while analyzing Feature '" + f.getId() + "', read the log for details"); } } } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + throw new MojoExecutionException("A fatal error occurred while setting up the Scanner and related Analyzer, see error cause:", e); + } finally { + getLog().debug("Features analysis complete"); + } + + if (failed) { + throw new MojoFailureException("One or more features Analyzer detected Feature error(s), please read the plugin log for more datils"); } } }
