diff --git a/maven-plugin-testing-harness/pom.xml b/maven-plugin-testing-harness/pom.xml index 6450422a..cb222af3 100644 --- a/maven-plugin-testing-harness/pom.xml +++ b/maven-plugin-testing-harness/pom.xml @@ -1,5 +1,4 @@ - - 4.0.0 diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/ConfigurationException.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/ConfigurationException.java index 6d2ea581..dd13791c 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/ConfigurationException.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/ConfigurationException.java @@ -1,5 +1,3 @@ -package org.apache.maven.api.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,40 +16,36 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.api.plugin.testing; /** * ConfigurationException * * @author jesse */ -public class ConfigurationException - extends Exception -{ +public class ConfigurationException extends Exception { /** serialVersionUID */ static final long serialVersionUID = -6180939638742159065L; /** * @param message The detailed message. */ - public ConfigurationException( String message ) - { - super( message ); + public ConfigurationException(String message) { + super(message); } /** * @param cause The detailed cause. */ - public ConfigurationException( Throwable cause ) - { - super( cause ); + public ConfigurationException(Throwable cause) { + super(cause); } /** * @param message The detailed message. * @param cause The detailed cause. */ - public ConfigurationException( String message, Throwable cause ) - { - super( message, cause ); + public ConfigurationException(String message, Throwable cause) { + super(message, cause); } } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/InjectMojo.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/InjectMojo.java index 313dbba5..e094d065 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/InjectMojo.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/InjectMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.api.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 + * 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 @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.api.plugin.testing; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -25,14 +24,12 @@ /** * */ -@Retention( RetentionPolicy.RUNTIME ) -public @interface InjectMojo -{ +@Retention(RetentionPolicy.RUNTIME) +public @interface InjectMojo { String goal(); String pom(); boolean empty() default false; - } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java index 030e135e..4a326902 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java @@ -1,5 +1,3 @@ -package org.apache.maven.api.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 + * 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 @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.api.plugin.testing; import java.io.BufferedReader; import java.io.File; @@ -80,273 +79,228 @@ /** * */ -public class MojoExtension extends PlexusExtension implements ParameterResolver -{ +public class MojoExtension extends PlexusExtension implements ParameterResolver { @Override - public boolean supportsParameter( ParameterContext parameterContext, ExtensionContext extensionContext ) - throws ParameterResolutionException - { - return parameterContext.isAnnotated( InjectMojo.class ) - || parameterContext.getDeclaringExecutable().isAnnotationPresent( InjectMojo.class ); + public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) + throws ParameterResolutionException { + return parameterContext.isAnnotated(InjectMojo.class) + || parameterContext.getDeclaringExecutable().isAnnotationPresent(InjectMojo.class); } @Override - public Object resolveParameter( ParameterContext parameterContext, ExtensionContext extensionContext ) - throws ParameterResolutionException - { - try - { - InjectMojo injectMojo = parameterContext.findAnnotation( InjectMojo.class ).orElseGet( - () -> parameterContext.getDeclaringExecutable().getAnnotation( InjectMojo.class ) ); - List mojoParameters = parameterContext.findRepeatableAnnotations( MojoParameter.class ); + public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) + throws ParameterResolutionException { + try { + InjectMojo injectMojo = parameterContext + .findAnnotation(InjectMojo.class) + .orElseGet(() -> parameterContext.getDeclaringExecutable().getAnnotation(InjectMojo.class)); + List mojoParameters = parameterContext.findRepeatableAnnotations(MojoParameter.class); Class holder = parameterContext.getTarget().get().getClass(); - PluginDescriptor descriptor = extensionContext.getStore( ExtensionContext.Namespace.GLOBAL ) - .get( PluginDescriptor.class, PluginDescriptor.class ); - return lookupMojo( holder, injectMojo, mojoParameters, descriptor ); - } - catch ( Exception e ) - { - throw new ParameterResolutionException( "Unable to resolve parameter", e ); + PluginDescriptor descriptor = extensionContext + .getStore(ExtensionContext.Namespace.GLOBAL) + .get(PluginDescriptor.class, PluginDescriptor.class); + return lookupMojo(holder, injectMojo, mojoParameters, descriptor); + } catch (Exception e) { + throw new ParameterResolutionException("Unable to resolve parameter", e); } } @Override - public void beforeEach( ExtensionContext context ) - throws Exception - { - Field field = PlexusExtension.class.getDeclaredField( "basedir" ); - field.setAccessible( true ); - field.set( null, getBasedir() ); - field = PlexusExtension.class.getDeclaredField( "context" ); - field.setAccessible( true ); - field.set( this, context ); - - getContainer().addComponent( getContainer(), PlexusContainer.class.getName() ); - - ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), - binder -> - { - binder.install( ProviderMethodsModule.forObject( context.getRequiredTestInstance() ) ); - binder.requestInjection( context.getRequiredTestInstance() ); - binder.bind( Log.class ).toInstance( new DefaultLog( - LoggerFactory.getLogger( "anonymous" ) ) ); - } ); + public void beforeEach(ExtensionContext context) throws Exception { + Field field = PlexusExtension.class.getDeclaredField("basedir"); + field.setAccessible(true); + field.set(null, getBasedir()); + field = PlexusExtension.class.getDeclaredField("context"); + field.setAccessible(true); + field.set(this, context); + + getContainer().addComponent(getContainer(), PlexusContainer.class.getName()); + + ((DefaultPlexusContainer) getContainer()).addPlexusInjector(Collections.emptyList(), binder -> { + binder.install(ProviderMethodsModule.forObject(context.getRequiredTestInstance())); + binder.requestInjection(context.getRequiredTestInstance()); + binder.bind(Log.class).toInstance(new DefaultLog(LoggerFactory.getLogger("anonymous"))); + }); Map map = getContainer().getContext().getContextData(); ClassLoader classLoader = context.getRequiredTestClass().getClassLoader(); - try ( InputStream is = Objects.requireNonNull( classLoader.getResourceAsStream( getPluginDescriptorLocation() ), - "Unable to find plugin descriptor: " + getPluginDescriptorLocation() ); - Reader reader = new BufferedReader( new XmlStreamReader( is ) ); - InterpolationFilterReader interpolationReader = new InterpolationFilterReader( reader, map, "${", "}" ) ) - { - - PluginDescriptor pluginDescriptor = new PluginDescriptorBuilder().build( interpolationReader ); - -// Artifact artifact = -// lookup( RepositorySystem.class ).createArtifact( pluginDescriptor.getGroupId(), -// pluginDescriptor.getArtifactId(), -// pluginDescriptor.getVersion(), ".jar" ); -// -// artifact.setFile( getPluginArtifactFile() ); -// pluginDescriptor.setPluginArtifact( artifact ); -// pluginDescriptor.setArtifacts( Collections.singletonList( artifact ) ); - - context.getStore( ExtensionContext.Namespace.GLOBAL ) - .put( PluginDescriptor.class, pluginDescriptor ); - - for ( ComponentDescriptor desc : pluginDescriptor.getComponents() ) - { - getContainer().addComponentDescriptor( desc ); + try (InputStream is = Objects.requireNonNull( + classLoader.getResourceAsStream(getPluginDescriptorLocation()), + "Unable to find plugin descriptor: " + getPluginDescriptorLocation()); + Reader reader = new BufferedReader(new XmlStreamReader(is)); + InterpolationFilterReader interpolationReader = new InterpolationFilterReader(reader, map, "${", "}")) { + + PluginDescriptor pluginDescriptor = new PluginDescriptorBuilder().build(interpolationReader); + + // Artifact artifact = + // lookup( RepositorySystem.class ).createArtifact( pluginDescriptor.getGroupId(), + // pluginDescriptor.getArtifactId(), + // pluginDescriptor.getVersion(), ".jar" ); + // + // artifact.setFile( getPluginArtifactFile() ); + // pluginDescriptor.setPluginArtifact( artifact ); + // pluginDescriptor.setArtifacts( Collections.singletonList( artifact ) ); + + context.getStore(ExtensionContext.Namespace.GLOBAL).put(PluginDescriptor.class, pluginDescriptor); + + for (ComponentDescriptor desc : pluginDescriptor.getComponents()) { + getContainer().addComponentDescriptor(desc); } } } - protected String getPluginDescriptorLocation() - { + protected String getPluginDescriptorLocation() { return "META-INF/maven/plugin.xml"; } - private Mojo lookupMojo( Class holder, InjectMojo injectMojo, List mojoParameters, - PluginDescriptor descriptor ) throws Exception - { + private Mojo lookupMojo( + Class holder, InjectMojo injectMojo, List mojoParameters, PluginDescriptor descriptor) + throws Exception { String goal = injectMojo.goal(); String pom = injectMojo.pom(); - String[] coord = mojoCoordinates( goal ); + String[] coord = mojoCoordinates(goal); Xpp3Dom pomDom; - if ( pom.startsWith( "file:" ) ) - { - Path path = Paths.get( getBasedir() ).resolve( pom.substring( "file:".length() ) ); - pomDom = Xpp3DomBuilder.build( ReaderFactory.newXmlReader( path.toFile() ) ); - } - else if ( pom.startsWith( "classpath:" ) ) - { - URL url = holder.getResource( pom.substring( "classpath:".length() ) ); - if ( url == null ) - { - throw new IllegalStateException( "Unable to find pom on classpath: " + pom ); + if (pom.startsWith("file:")) { + Path path = Paths.get(getBasedir()).resolve(pom.substring("file:".length())); + pomDom = Xpp3DomBuilder.build(ReaderFactory.newXmlReader(path.toFile())); + } else if (pom.startsWith("classpath:")) { + URL url = holder.getResource(pom.substring("classpath:".length())); + if (url == null) { + throw new IllegalStateException("Unable to find pom on classpath: " + pom); } - pomDom = Xpp3DomBuilder.build( ReaderFactory.newXmlReader( url.openStream() ) ); - } - else if ( pom.contains( "" ) ) - { - pomDom = Xpp3DomBuilder.build( new StringReader( pom ) ); - } - else - { - Path path = Paths.get( getBasedir() ).resolve( pom ); - pomDom = Xpp3DomBuilder.build( ReaderFactory.newXmlReader( path.toFile() ) ); + pomDom = Xpp3DomBuilder.build(ReaderFactory.newXmlReader(url.openStream())); + } else if (pom.contains("")) { + pomDom = Xpp3DomBuilder.build(new StringReader(pom)); + } else { + Path path = Paths.get(getBasedir()).resolve(pom); + pomDom = Xpp3DomBuilder.build(ReaderFactory.newXmlReader(path.toFile())); } - XmlNode pluginConfiguration = extractPluginConfiguration( coord[1], pomDom ); - if ( !mojoParameters.isEmpty() ) - { + XmlNode pluginConfiguration = extractPluginConfiguration(coord[1], pomDom); + if (!mojoParameters.isEmpty()) { List children = mojoParameters.stream() - .map( mp -> new XmlNodeImpl( mp.name(), mp.value() ) ) - .collect( Collectors.toList() ); - XmlNode config = new XmlNodeImpl( "configuration", - null, null, children, null ); - pluginConfiguration = XmlNode.merge( config, pluginConfiguration ); + .map(mp -> new XmlNodeImpl(mp.name(), mp.value())) + .collect(Collectors.toList()); + XmlNode config = new XmlNodeImpl("configuration", null, null, children, null); + pluginConfiguration = XmlNode.merge(config, pluginConfiguration); } - Mojo mojo = lookupMojo( coord, pluginConfiguration, descriptor ); + Mojo mojo = lookupMojo(coord, pluginConfiguration, descriptor); return mojo; } - protected String[] mojoCoordinates( String goal ) - throws Exception - { - if ( goal.matches( ".*:.*:.*:.*" ) ) - { - return goal.split( ":" ); - } - else - { - Path pluginPom = Paths.get( getBasedir(), "pom.xml" ); - Xpp3Dom pluginPomDom = Xpp3DomBuilder.build( ReaderFactory.newXmlReader( pluginPom.toFile() ) ); - String artifactId = pluginPomDom.getChild( "artifactId" ).getValue(); - String groupId = resolveFromRootThenParent( pluginPomDom, "groupId" ); - String version = resolveFromRootThenParent( pluginPomDom, "version" ); - return new String[] { groupId, artifactId, version, goal }; + protected String[] mojoCoordinates(String goal) throws Exception { + if (goal.matches(".*:.*:.*:.*")) { + return goal.split(":"); + } else { + Path pluginPom = Paths.get(getBasedir(), "pom.xml"); + Xpp3Dom pluginPomDom = Xpp3DomBuilder.build(ReaderFactory.newXmlReader(pluginPom.toFile())); + String artifactId = pluginPomDom.getChild("artifactId").getValue(); + String groupId = resolveFromRootThenParent(pluginPomDom, "groupId"); + String version = resolveFromRootThenParent(pluginPomDom, "version"); + return new String[] {groupId, artifactId, version, goal}; } } /** * lookup the mojo while we have all of the relavent information */ - protected Mojo lookupMojo( String[] coord, XmlNode pluginConfiguration, PluginDescriptor descriptor ) - throws Exception - { + protected Mojo lookupMojo(String[] coord, XmlNode pluginConfiguration, PluginDescriptor descriptor) + throws Exception { // pluginkey = groupId : artifactId : version : goal - Mojo mojo = lookup( Mojo.class, coord[0] + ":" + coord[1] + ":" + coord[2] + ":" + coord[3] ); - for ( MojoDescriptor mojoDescriptor : descriptor.getMojos() ) - { - if ( Objects.equals( mojoDescriptor.getImplementation(), mojo.getClass().getName() ) ) - { - if ( pluginConfiguration != null ) - { - pluginConfiguration = finalizeConfig( pluginConfiguration, mojoDescriptor ); + Mojo mojo = lookup(Mojo.class, coord[0] + ":" + coord[1] + ":" + coord[2] + ":" + coord[3]); + for (MojoDescriptor mojoDescriptor : descriptor.getMojos()) { + if (Objects.equals( + mojoDescriptor.getImplementation(), mojo.getClass().getName())) { + if (pluginConfiguration != null) { + pluginConfiguration = finalizeConfig(pluginConfiguration, mojoDescriptor); } } } - if ( pluginConfiguration != null ) - { - Session session = getContainer().lookup( Session.class ); + if (pluginConfiguration != null) { + Session session = getContainer().lookup(Session.class); Project project; - try - { - project = getContainer().lookup( Project.class ); - } - catch ( ComponentLookupException e ) - { + try { + project = getContainer().lookup(Project.class); + } catch (ComponentLookupException e) { project = null; } org.apache.maven.plugin.MojoExecution mojoExecution; - try - { - MojoExecution me = getContainer().lookup( MojoExecution.class ); + try { + MojoExecution me = getContainer().lookup(MojoExecution.class); mojoExecution = new org.apache.maven.plugin.MojoExecution( - new org.apache.maven.model.Plugin( me.getPlugin() ), - me.getGoal(), - me.getExecutionId() - ); - } - catch ( ComponentLookupException e ) - { + new org.apache.maven.model.Plugin(me.getPlugin()), me.getGoal(), me.getExecutionId()); + } catch (ComponentLookupException e) { mojoExecution = null; } - ExpressionEvaluator evaluator = new WrapEvaluator( getContainer(), - new PluginParameterExpressionEvaluatorV4( session, project, mojoExecution ) ); + ExpressionEvaluator evaluator = new WrapEvaluator( + getContainer(), new PluginParameterExpressionEvaluatorV4(session, project, mojoExecution)); ComponentConfigurator configurator = new EnhancedComponentConfigurator(); - configurator.configureComponent( mojo, new XmlPlexusConfiguration( new Xpp3Dom( pluginConfiguration ) ), - evaluator, getContainer().getContainerRealm() ); + configurator.configureComponent( + mojo, + new XmlPlexusConfiguration(new Xpp3Dom(pluginConfiguration)), + evaluator, + getContainer().getContainerRealm()); } return mojo; } - private XmlNode finalizeConfig( XmlNode config, MojoDescriptor mojoDescriptor ) - { + private XmlNode finalizeConfig(XmlNode config, MojoDescriptor mojoDescriptor) { List children = new ArrayList<>(); - if ( mojoDescriptor != null && mojoDescriptor.getParameters() != null ) - { - XmlNode defaultConfiguration = MojoDescriptorCreator.convert( mojoDescriptor ).getDom(); - for ( Parameter parameter : mojoDescriptor.getParameters() ) - { - XmlNode parameterConfiguration = config.getChild( parameter.getName() ); - if ( parameterConfiguration == null ) - { - parameterConfiguration = config.getChild( parameter.getAlias() ); + if (mojoDescriptor != null && mojoDescriptor.getParameters() != null) { + XmlNode defaultConfiguration = + MojoDescriptorCreator.convert(mojoDescriptor).getDom(); + for (Parameter parameter : mojoDescriptor.getParameters()) { + XmlNode parameterConfiguration = config.getChild(parameter.getName()); + if (parameterConfiguration == null) { + parameterConfiguration = config.getChild(parameter.getAlias()); } - XmlNode parameterDefaults = defaultConfiguration.getChild( parameter.getName() ); - parameterConfiguration = XmlNode.merge( parameterConfiguration, parameterDefaults, Boolean.TRUE ); - if ( parameterConfiguration != null ) - { - Map attributes = new HashMap<>( parameterConfiguration.getAttributes() ); - if ( isEmpty( parameterConfiguration.getAttribute( "implementation" ) ) - && !isEmpty( parameter.getImplementation() ) ) - { - attributes.put( "implementation", parameter.getImplementation() ); + XmlNode parameterDefaults = defaultConfiguration.getChild(parameter.getName()); + parameterConfiguration = XmlNode.merge(parameterConfiguration, parameterDefaults, Boolean.TRUE); + if (parameterConfiguration != null) { + Map attributes = new HashMap<>(parameterConfiguration.getAttributes()); + if (isEmpty(parameterConfiguration.getAttribute("implementation")) + && !isEmpty(parameter.getImplementation())) { + attributes.put("implementation", parameter.getImplementation()); } parameterConfiguration = new XmlNodeImpl( - parameter.getName(), parameterConfiguration.getValue(), - attributes, parameterConfiguration.getChildren(), - parameterConfiguration.getInputLocation() ); + parameter.getName(), + parameterConfiguration.getValue(), + attributes, + parameterConfiguration.getChildren(), + parameterConfiguration.getInputLocation()); - children.add( parameterConfiguration ); + children.add(parameterConfiguration); } } } - return new XmlNodeImpl( "configuration", null, null, children, null ); + return new XmlNodeImpl("configuration", null, null, children, null); } - private boolean isEmpty( String str ) - { + private boolean isEmpty(String str) { return str == null || str.isEmpty(); } - private static Optional child( Xpp3Dom element, String name ) - { - return Optional.ofNullable( element.getChild( name ) ); + private static Optional child(Xpp3Dom element, String name) { + return Optional.ofNullable(element.getChild(name)); } - private static Stream children( Xpp3Dom element ) - { - return Stream.of( element.getChildren() ); + private static Stream children(Xpp3Dom element) { + return Stream.of(element.getChildren()); } - public static XmlNode extractPluginConfiguration( String artifactId, Xpp3Dom pomDom ) - throws Exception - { - Xpp3Dom pluginConfigurationElement = child( pomDom, "build" ) - .flatMap( buildElement -> child( buildElement, "plugins" ) ) - .map( MojoExtension::children ) - .orElseGet( Stream::empty ) - .filter( e -> e.getChild( "artifactId" ).getValue().equals( artifactId ) ) + public static XmlNode extractPluginConfiguration(String artifactId, Xpp3Dom pomDom) throws Exception { + Xpp3Dom pluginConfigurationElement = child(pomDom, "build") + .flatMap(buildElement -> child(buildElement, "plugins")) + .map(MojoExtension::children) + .orElseGet(Stream::empty) + .filter(e -> e.getChild("artifactId").getValue().equals(artifactId)) .findFirst() - .flatMap( buildElement -> child( buildElement, "configuration" ) ) - .orElseThrow( () -> new ConfigurationException( - "Cannot find a configuration element for a plugin with an " - + "artifactId of " + artifactId + "." ) ); + .flatMap(buildElement -> child(buildElement, "configuration")) + .orElseThrow( + () -> new ConfigurationException("Cannot find a configuration element for a plugin with an " + + "artifactId of " + artifactId + ".")); return pluginConfigurationElement.getDom(); } @@ -355,19 +309,14 @@ public static XmlNode extractPluginConfiguration( String artifactId, Xpp3Dom pom * * TODO find out where this is probably done elsewhere */ - private static String resolveFromRootThenParent( Xpp3Dom pluginPomDom, String element ) - throws Exception - { - return Optional.ofNullable( - child( pluginPomDom, element ) - .orElseGet( () -> child( pluginPomDom, "parent" ) - .flatMap( e -> child( e, element ) ) - .orElse( null ) ) ) - .map( Xpp3Dom::getValue ) - .orElseThrow( () -> new Exception( "unable to determine " + element ) ); + private static String resolveFromRootThenParent(Xpp3Dom pluginPomDom, String element) throws Exception { + return Optional.ofNullable(child(pluginPomDom, element).orElseGet(() -> child(pluginPomDom, "parent") + .flatMap(e -> child(e, element)) + .orElse(null))) + .map(Xpp3Dom::getValue) + .orElseThrow(() -> new Exception("unable to determine " + element)); } - /** * Convenience method to obtain the value of a variable on a mojo that might not have a getter. * @@ -378,12 +327,10 @@ private static String resolveFromRootThenParent( Xpp3Dom pluginPomDom, String el * @return object value of variable * @throws IllegalArgumentException */ - public static Object getVariableValueFromObject( Object object, String variable ) - throws IllegalAccessException - { - Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses( variable, object.getClass() ); - field.setAccessible( true ); - return field.get( object ); + public static Object getVariableValueFromObject(Object object, String variable) throws IllegalAccessException { + Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses(variable, object.getClass()); + field.setAccessible(true); + return field.get(object); } /** @@ -394,10 +341,8 @@ public static Object getVariableValueFromObject( Object object, String variable * @param object * @return map of variable names and values */ - public static Map getVariablesAndValuesFromObject( Object object ) - throws IllegalAccessException - { - return getVariablesAndValuesFromObject( object.getClass(), object ); + public static Map getVariablesAndValuesFromObject(Object object) throws IllegalAccessException { + return getVariablesAndValuesFromObject(object.getClass(), object); } /** @@ -409,20 +354,17 @@ public static Map getVariablesAndValuesFromObject( Object object * @param object * @return map of variable names and values */ - public static Map getVariablesAndValuesFromObject( Class clazz, Object object ) - throws IllegalAccessException - { + public static Map getVariablesAndValuesFromObject(Class clazz, Object object) + throws IllegalAccessException { Map map = new HashMap<>(); Field[] fields = clazz.getDeclaredFields(); - AccessibleObject.setAccessible( fields, true ); - for ( Field field : fields ) - { - map.put( field.getName(), field.get( object ) ); + AccessibleObject.setAccessible(fields, true); + for (Field field : fields) { + map.put(field.getName(), field.get(object)); } Class superclass = clazz.getSuperclass(); - if ( !Object.class.equals( superclass ) ) - { - map.putAll( getVariablesAndValuesFromObject( superclass, object ) ); + if (!Object.class.equals(superclass)) { + map.putAll(getVariablesAndValuesFromObject(superclass, object)); } return map; } @@ -435,48 +377,38 @@ public static Map getVariablesAndValuesFromObject( Class claz * @param value * @throws IllegalAccessException */ - public static void setVariableValueToObject( Object object, String variable, Object value ) - throws IllegalAccessException - { - Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses( variable, object.getClass() ); - Objects.requireNonNull( field, "Field " + variable + " not found" ); - field.setAccessible( true ); - field.set( object, value ); + public static void setVariableValueToObject(Object object, String variable, Object value) + throws IllegalAccessException { + Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses(variable, object.getClass()); + Objects.requireNonNull(field, "Field " + variable + " not found"); + field.setAccessible(true); + field.set(object, value); } - static class WrapEvaluator implements TypeAwareExpressionEvaluator - { + static class WrapEvaluator implements TypeAwareExpressionEvaluator { private final PlexusContainer container; private final TypeAwareExpressionEvaluator evaluator; - WrapEvaluator( PlexusContainer container, TypeAwareExpressionEvaluator evaluator ) - { + WrapEvaluator(PlexusContainer container, TypeAwareExpressionEvaluator evaluator) { this.container = container; this.evaluator = evaluator; } @Override - public Object evaluate( String expression ) throws ExpressionEvaluationException - { - return evaluate( expression, null ); + public Object evaluate(String expression) throws ExpressionEvaluationException { + return evaluate(expression, null); } @Override - public Object evaluate( String expression, Class type ) throws ExpressionEvaluationException - { - Object value = evaluator.evaluate( expression, type ); - if ( value == null ) - { - String expr = stripTokens( expression ); - if ( expr != null ) - { - try - { - value = container.lookup( type, expr ); - } - catch ( ComponentLookupException e ) - { + public Object evaluate(String expression, Class type) throws ExpressionEvaluationException { + Object value = evaluator.evaluate(expression, type); + if (value == null) { + String expr = stripTokens(expression); + if (expr != null) { + try { + value = container.lookup(type, expr); + } catch (ComponentLookupException e) { // nothing } } @@ -484,20 +416,16 @@ public Object evaluate( String expression, Class type ) throws ExpressionEval return value; } - private String stripTokens( String expr ) - { - if ( expr.startsWith( "${" ) && expr.endsWith( "}" ) ) - { - return expr.substring( 2, expr.length() - 1 ); + private String stripTokens(String expr) { + if (expr.startsWith("${") && expr.endsWith("}")) { + return expr.substring(2, expr.length() - 1); } return null; } @Override - public File alignToBaseDirectory( File path ) - { - return evaluator.alignToBaseDirectory( path ); + public File alignToBaseDirectory(File path) { + return evaluator.alignToBaseDirectory(path); } } - } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoParameter.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoParameter.java index ebd284d2..2a28f489 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoParameter.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoParameter.java @@ -1,5 +1,3 @@ -package org.apache.maven.api.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 + * 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 @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.api.plugin.testing; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; @@ -26,10 +25,10 @@ /** * Mojo parameter */ -@Retention( RetentionPolicy.RUNTIME ) -@Repeatable( MojoParameters.class ) -public @interface MojoParameter -{ +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(MojoParameters.class) +public @interface MojoParameter { String name(); + String value(); } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoParameters.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoParameters.java index 53c8dd9e..434abe19 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoParameters.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoParameters.java @@ -1,5 +1,3 @@ -package org.apache.maven.api.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 + * 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 @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.api.plugin.testing; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -25,8 +24,7 @@ /** * Mojo parameters container */ -@Retention( RetentionPolicy.RUNTIME ) -public @interface MojoParameters -{ +@Retention(RetentionPolicy.RUNTIME) +public @interface MojoParameters { MojoParameter[] value(); } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoTest.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoTest.java index 4f4b1a94..eb94c091 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoTest.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.api.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 + * 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 @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.api.plugin.testing; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -29,9 +28,7 @@ /** * */ -@Retention( RetentionPolicy.RUNTIME ) -@ExtendWith( MojoExtension.class ) -@Target( ElementType.TYPE ) -public @interface MojoTest -{ -} +@Retention(RetentionPolicy.RUNTIME) +@ExtendWith(MojoExtension.class) +@Target(ElementType.TYPE) +public @interface MojoTest {} diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/ResolverExpressionEvaluatorStub.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/ResolverExpressionEvaluatorStub.java index b35b2b0a..4461071c 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/ResolverExpressionEvaluatorStub.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/ResolverExpressionEvaluatorStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.api.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.api.plugin.testing; import java.io.File; import java.util.Map; @@ -34,101 +33,74 @@ * * @author jesse */ -public class ResolverExpressionEvaluatorStub - implements TypeAwareExpressionEvaluator -{ +public class ResolverExpressionEvaluatorStub implements TypeAwareExpressionEvaluator { private final Map properties; - public ResolverExpressionEvaluatorStub( Map properties ) - { + public ResolverExpressionEvaluatorStub(Map properties) { this.properties = properties; } /** {@inheritDoc} */ @Override - public Object evaluate( String expr ) - throws ExpressionEvaluationException - { - return evaluate( expr, null ); + public Object evaluate(String expr) throws ExpressionEvaluationException { + return evaluate(expr, null); } /** {@inheritDoc} */ @Override - public Object evaluate( String expr, Class type ) - throws ExpressionEvaluationException - { + public Object evaluate(String expr, Class type) throws ExpressionEvaluationException { Object value = null; - if ( expr == null ) - { + if (expr == null) { return null; } - String expression = stripTokens( expr ); - - if ( expression.equals( expr ) ) - { - int index = expr.indexOf( "${" ); - if ( index >= 0 ) - { - int lastIndex = expr.indexOf( "}", index ); - if ( lastIndex >= 0 ) - { - String retVal = expr.substring( 0, index ); - - if ( index > 0 && expr.charAt( index - 1 ) == '$' ) - { - retVal += expr.substring( index + 1, lastIndex + 1 ); - } - else - { - retVal += evaluate( expr.substring( index, lastIndex + 1 ) ); + String expression = stripTokens(expr); + + if (expression.equals(expr)) { + int index = expr.indexOf("${"); + if (index >= 0) { + int lastIndex = expr.indexOf("}", index); + if (lastIndex >= 0) { + String retVal = expr.substring(0, index); + + if (index > 0 && expr.charAt(index - 1) == '$') { + retVal += expr.substring(index + 1, lastIndex + 1); + } else { + retVal += evaluate(expr.substring(index, lastIndex + 1)); } - retVal += evaluate( expr.substring( lastIndex + 1 ) ); + retVal += evaluate(expr.substring(lastIndex + 1)); return retVal; } } // Was not an expression - return expression.contains( "$$" ) - ? expression.replaceAll( "\\$\\$", "\\$" ) - : expression; - } - else - { - if ( "basedir".equals( expression ) || "project.basedir".equals( expression ) ) - { + return expression.contains("$$") ? expression.replaceAll("\\$\\$", "\\$") : expression; + } else { + if ("basedir".equals(expression) || "project.basedir".equals(expression)) { value = PlexusExtension.getBasedir(); - } - else if ( expression.startsWith( "basedir" ) || expression.startsWith( "project.basedir" ) ) - { - int pathSeparator = expression.indexOf( "/" ); - if ( pathSeparator > 0 ) - { - value = PlexusTestCase.getBasedir() + expression.substring( pathSeparator ); + } else if (expression.startsWith("basedir") || expression.startsWith("project.basedir")) { + int pathSeparator = expression.indexOf("/"); + if (pathSeparator > 0) { + value = PlexusTestCase.getBasedir() + expression.substring(pathSeparator); } + } else if ("localRepository".equals(expression)) { + File localRepo = new File(PlexusTestCase.getBasedir(), "target/local-repo"); + return new LocalRepository("file://" + localRepo.getAbsolutePath()); } - else if ( "localRepository".equals( expression ) ) - { - File localRepo = new File( PlexusTestCase.getBasedir(), "target/local-repo" ); - return new LocalRepository( "file://" + localRepo.getAbsolutePath() ); - } - if ( value == null && properties != null && properties.containsKey( expression ) ) - { - value = properties.get( expression ); + if (value == null && properties != null && properties.containsKey(expression)) { + value = properties.get(expression); } return value; } } - private String stripTokens( String expr ) - { - if ( expr.startsWith( "${" ) && expr.indexOf( "}" ) == expr.length() - 1 ) - { - expr = expr.substring( 2, expr.length() - 1 ); + private String stripTokens(String expr) { + if (expr.startsWith("${") && expr.indexOf("}") == expr.length() - 1) { + expr = expr.substring(2, expr.length() - 1); } return expr; @@ -136,19 +108,13 @@ private String stripTokens( String expr ) /** {@inheritDoc} */ @Override - public File alignToBaseDirectory( File file ) - { - if ( file.getAbsolutePath().startsWith( PlexusExtension.getBasedir() ) ) - { + public File alignToBaseDirectory(File file) { + if (file.getAbsolutePath().startsWith(PlexusExtension.getBasedir())) { return file; - } - else if ( file.isAbsolute() ) - { + } else if (file.isAbsolute()) { return file; - } - else - { - return new File( PlexusExtension.getBasedir(), file.getPath() ); + } else { + return new File(PlexusExtension.getBasedir(), file.getPath()); } } } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/stubs/ArtifactStub.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/stubs/ArtifactStub.java index 70b7d896..59be14f8 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/stubs/ArtifactStub.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/stubs/ArtifactStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.api.plugin.testing.stubs; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 + * 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 @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.api.plugin.testing.stubs; import java.util.Objects; @@ -31,16 +30,14 @@ /** * */ -public class ArtifactStub implements Artifact -{ +public class ArtifactStub implements Artifact { private String groupId; private String artifactId; private String classifier; private String version; private String extension; - public ArtifactStub() - { + public ArtifactStub() { groupId = ""; artifactId = ""; version = ""; @@ -48,8 +45,7 @@ public ArtifactStub() extension = ""; } - public ArtifactStub( String groupId, String artifactId, String classifier, String version, String extension ) - { + public ArtifactStub(String groupId, String artifactId, String classifier, String version, String extension) { this.groupId = groupId; this.artifactId = artifactId; this.classifier = classifier; @@ -59,110 +55,91 @@ public ArtifactStub( String groupId, String artifactId, String classifier, Strin @Nonnull @Override - public String getGroupId() - { + public String getGroupId() { return groupId; } - public void setGroupId( String groupId ) - { + public void setGroupId(String groupId) { this.groupId = groupId; } @Nonnull @Override - public String getArtifactId() - { + public String getArtifactId() { return artifactId; } - public void setArtifactId( String artifactId ) - { + public void setArtifactId(String artifactId) { this.artifactId = artifactId; } @Nonnull @Override - public String getClassifier() - { + public String getClassifier() { return classifier; } - public void setClassifier( String classifier ) - { + public void setClassifier(String classifier) { this.classifier = classifier; } @Nonnull @Override - public Version getVersion() - { - return new DefaultVersionParser().parseVersion( version ); + public Version getVersion() { + return new DefaultVersionParser().parseVersion(version); } - public void setVersion( String version ) - { + public void setVersion(String version) { this.version = version; } @Nonnull @Override - public String getExtension() - { + public String getExtension() { return extension; } - public void setExtension( String extension ) - { + public void setExtension(String extension) { this.extension = extension; } @Override - public boolean isSnapshot() - { + public boolean isSnapshot() { return false; } @Override - public ArtifactCoordinate toCoordinate() - { - return new ArtifactCoordinate() - { + public ArtifactCoordinate toCoordinate() { + return new ArtifactCoordinate() { @Override - public String getGroupId() - { + public String getGroupId() { return groupId; } @Override - public String getArtifactId() - { + public String getArtifactId() { return artifactId; } @Override - public String getClassifier() - { + public String getClassifier() { return classifier; } @Override - public VersionRange getVersion() - { - return new DefaultVersionParser().parseVersionRange( version ); + public VersionRange getVersion() { + return new DefaultVersionParser().parseVersionRange(version); } @Override - public String getExtension() - { + public String getExtension() { return extension; } }; } @Override - public String toString() - { + public String toString() { return "ArtifactStub[" + "groupId='" + groupId + '\'' + ", artifactId='" + artifactId + '\'' @@ -173,28 +150,23 @@ public String toString() } @Override - public boolean equals( Object o ) - { - if ( this == o ) - { + public boolean equals(Object o) { + if (this == o) { return true; } - if ( !( o instanceof ArtifactStub ) ) - { + if (!(o instanceof ArtifactStub)) { return false; } - ArtifactStub that = ( ArtifactStub ) o; - return Objects.equals( groupId, that.groupId ) - && Objects.equals( artifactId, that.artifactId ) - && Objects.equals( classifier, that.classifier ) - && Objects.equals( version, that.version ) - && Objects.equals( extension, that.extension ); + ArtifactStub that = (ArtifactStub) o; + return Objects.equals(groupId, that.groupId) + && Objects.equals(artifactId, that.artifactId) + && Objects.equals(classifier, that.classifier) + && Objects.equals(version, that.version) + && Objects.equals(extension, that.extension); } @Override - public int hashCode() - { - return Objects.hash( groupId, artifactId, classifier, version, extension ); + public int hashCode() { + return Objects.hash(groupId, artifactId, classifier, version, extension); } - } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/stubs/MojoExecutionStub.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/stubs/MojoExecutionStub.java index 8b3dddde..a2d2b5b2 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/stubs/MojoExecutionStub.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/stubs/MojoExecutionStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.api.plugin.testing.stubs; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.api.plugin.testing.stubs; import java.util.Optional; @@ -28,20 +27,17 @@ /** * Stub for {@link MojoExecution}. */ -public class MojoExecutionStub implements MojoExecution -{ +public class MojoExecutionStub implements MojoExecution { private final String artifactId; private final String executionId; private final String goal; private final XmlNode dom; - public MojoExecutionStub( String artifactId, String executionId, String goal ) - { - this( artifactId, executionId, goal, null ); + public MojoExecutionStub(String artifactId, String executionId, String goal) { + this(artifactId, executionId, goal, null); } - public MojoExecutionStub( String artifactId, String executionId, String goal, XmlNode dom ) - { + public MojoExecutionStub(String artifactId, String executionId, String goal, XmlNode dom) { this.artifactId = artifactId; this.executionId = executionId; this.goal = goal; @@ -49,28 +45,22 @@ public MojoExecutionStub( String artifactId, String executionId, String goal, Xm } @Override - public Plugin getPlugin() - { - return Plugin.newBuilder() - .artifactId( artifactId ) - .build(); + public Plugin getPlugin() { + return Plugin.newBuilder().artifactId(artifactId).build(); } @Override - public String getExecutionId() - { + public String getExecutionId() { return executionId; } @Override - public String getGoal() - { + public String getGoal() { return goal; } @Override - public Optional getConfiguration() - { - return Optional.ofNullable( dom ); + public Optional getConfiguration() { + return Optional.ofNullable(dom); } } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/stubs/ProjectStub.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/stubs/ProjectStub.java index 283959ae..433386a5 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/stubs/ProjectStub.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/stubs/ProjectStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.api.plugin.testing.stubs; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 + * 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 @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.api.plugin.testing.stubs; import java.io.File; import java.nio.file.Path; @@ -37,9 +36,7 @@ * @since 1.0-beta-1 * */ -public class ProjectStub - implements Project -{ +public class ProjectStub implements Project { private Model model = Model.newInstance(); private Path basedir; @@ -47,156 +44,130 @@ public class ProjectStub private boolean executionRoot; private Artifact artifact; - public void setModel( Model model ) - { + public void setModel(Model model) { this.model = model; } @Nonnull @Override - public String getGroupId() - { + public String getGroupId() { return model.getGroupId(); } @Nonnull @Override - public String getArtifactId() - { + public String getArtifactId() { return model.getArtifactId(); } @Nonnull @Override - public String getVersion() - { + public String getVersion() { return model.getVersion(); } - public String getName() - { + public String getName() { return model.getName(); } @Nonnull @Override - public String getPackaging() - { + public String getPackaging() { return model.getPackaging(); } @Nonnull @Override - public Artifact getArtifact() - { + public Artifact getArtifact() { return artifact; } @Nonnull @Override - public Model getModel() - { + public Model getModel() { return model; } @Nonnull @Override - public Optional getPomPath() - { - return Optional.ofNullable( pomPath ).map( File::toPath ); + public Optional getPomPath() { + return Optional.ofNullable(pomPath).map(File::toPath); } @Nonnull @Override - public List getDependencies() - { + public List getDependencies() { return null; } @Nonnull @Override - public List getManagedDependencies() - { + public List getManagedDependencies() { return null; } @Override - public Optional getBasedir() - { - return Optional.ofNullable( basedir ); + public Optional getBasedir() { + return Optional.ofNullable(basedir); } - public void setBasedir( Path basedir ) - { + public void setBasedir(Path basedir) { this.basedir = basedir; } @Override - public boolean isExecutionRoot() - { + public boolean isExecutionRoot() { return executionRoot; } @Override - public Optional getParent() - { + public Optional getParent() { return Optional.empty(); } @Override - public List getRemoteProjectRepositories() - { + public List getRemoteProjectRepositories() { return Collections.emptyList(); } @Override - public List getRemotePluginRepositories() - { + public List getRemotePluginRepositories() { return Collections.emptyList(); } - public void setGroupId( String groupId ) - { - model = model.withGroupId( groupId ); + public void setGroupId(String groupId) { + model = model.withGroupId(groupId); } - public void setArtifactId( String artifactId ) - { - model = model.withArtifactId( artifactId ); + public void setArtifactId(String artifactId) { + model = model.withArtifactId(artifactId); } - public void setVersion( String version ) - { - model = model.withVersion( version ); + public void setVersion(String version) { + model = model.withVersion(version); } - public void setName( String name ) - { - model = model.withName( name ); + public void setName(String name) { + model = model.withName(name); } - public void setPackaging( String packaging ) - { - model = model.withPackaging( packaging ); + public void setPackaging(String packaging) { + model = model.withPackaging(packaging); } - public void setArtifact( Artifact artifact ) - { + public void setArtifact(Artifact artifact) { this.artifact = artifact; } - public void setPomPath( File pomPath ) - { + public void setPomPath(File pomPath) { this.pomPath = pomPath; } - public void setExecutionRoot( boolean executionRoot ) - { + public void setExecutionRoot(boolean executionRoot) { this.executionRoot = executionRoot; } - public void setMavenModel( org.apache.maven.model.Model model ) - { + public void setMavenModel(org.apache.maven.model.Model model) { this.model = model.getDelegate(); } } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/stubs/SessionStub.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/stubs/SessionStub.java index c6d23054..6e069c06 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/stubs/SessionStub.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/stubs/SessionStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.api.plugin.testing.stubs; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 + * 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 @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.api.plugin.testing.stubs; import java.net.URI; import java.nio.file.Path; @@ -66,234 +65,216 @@ /** * */ -public class SessionStub -{ +public class SessionStub { - public static Session getMockSession( String localRepo ) - { - LocalRepository localRepository = mock( LocalRepository.class ); - when( localRepository.getId() ).thenReturn( "local" ); - when( localRepository.getPath() ).thenReturn( Paths.get( localRepo ) ); - return getMockSession( localRepository ); + public static Session getMockSession(String localRepo) { + LocalRepository localRepository = mock(LocalRepository.class); + when(localRepository.getId()).thenReturn("local"); + when(localRepository.getPath()).thenReturn(Paths.get(localRepo)); + return getMockSession(localRepository); } - public static Session getMockSession( LocalRepository localRepository ) - { - Session session = mock( Session.class ); + public static Session getMockSession(LocalRepository localRepository) { + Session session = mock(Session.class); - RepositoryFactory repositoryFactory = mock( RepositoryFactory.class ); - when( repositoryFactory.createRemote( any( Repository.class ) ) ) - .thenAnswer( iom -> - { - Repository repository = iom.getArgument( 0, Repository.class ); - return repositoryFactory.createRemote( repository.getId(), repository.getUrl() ); - } ); - when( repositoryFactory.createRemote( anyString(), anyString() ) ) - .thenAnswer( iom -> - { - String id = iom.getArgument( 0, String.class ); - String url = iom.getArgument( 1, String.class ); - RemoteRepository remoteRepository = mock( RemoteRepository.class, withSettings().lenient() ); - when( remoteRepository.getId() ).thenReturn( id ); - when( remoteRepository.getUrl() ).thenReturn( url ); - when( remoteRepository.getProtocol() ).thenReturn( URI.create( url ).getScheme() ); - return remoteRepository; - } ); + RepositoryFactory repositoryFactory = mock(RepositoryFactory.class); + when(repositoryFactory.createRemote(any(Repository.class))).thenAnswer(iom -> { + Repository repository = iom.getArgument(0, Repository.class); + return repositoryFactory.createRemote(repository.getId(), repository.getUrl()); + }); + when(repositoryFactory.createRemote(anyString(), anyString())).thenAnswer(iom -> { + String id = iom.getArgument(0, String.class); + String url = iom.getArgument(1, String.class); + RemoteRepository remoteRepository = + mock(RemoteRepository.class, withSettings().lenient()); + when(remoteRepository.getId()).thenReturn(id); + when(remoteRepository.getUrl()).thenReturn(url); + when(remoteRepository.getProtocol()).thenReturn(URI.create(url).getScheme()); + return remoteRepository; + }); - LocalRepositoryManager localRepositoryManager = mock( LocalRepositoryManager.class ); - when( localRepositoryManager.getPathForLocalArtifact( any(), any(), any() ) ) - .thenAnswer( iom -> - { - LocalRepository localRepo = iom.getArgument( 1, LocalRepository.class ); - Artifact artifact = iom.getArgument( 2, Artifact.class ); - return localRepo.getPath().resolve( getPathForArtifact( artifact, true ) ); - } ); + LocalRepositoryManager localRepositoryManager = mock(LocalRepositoryManager.class); + when(localRepositoryManager.getPathForLocalArtifact(any(), any(), any())) + .thenAnswer(iom -> { + LocalRepository localRepo = iom.getArgument(1, LocalRepository.class); + Artifact artifact = iom.getArgument(2, Artifact.class); + return localRepo.getPath().resolve(getPathForArtifact(artifact, true)); + }); - ArtifactInstaller artifactInstaller = mock( ArtifactInstaller.class ); - doAnswer( iom -> - { - artifactInstaller.install( ArtifactInstallerRequest.build( - iom.getArgument( 0, Session.class ), - iom.getArgument( 1, Collection.class ) ) ); + ArtifactInstaller artifactInstaller = mock(ArtifactInstaller.class); + doAnswer(iom -> { + artifactInstaller.install(ArtifactInstallerRequest.build( + iom.getArgument(0, Session.class), iom.getArgument(1, Collection.class))); return null; - } ) - .when( artifactInstaller ) - .install( any( Session.class ), ArgumentMatchers.>any() ); + }) + .when(artifactInstaller) + .install(any(Session.class), ArgumentMatchers.>any()); - ArtifactDeployer artifactDeployer = mock( ArtifactDeployer.class ); - doAnswer( iom -> - { - artifactDeployer.deploy( ArtifactDeployerRequest.build( - iom.getArgument( 0, Session.class ), - iom.getArgument( 1, RemoteRepository.class ), - iom.getArgument( 2, Collection.class ) ) ); + ArtifactDeployer artifactDeployer = mock(ArtifactDeployer.class); + doAnswer(iom -> { + artifactDeployer.deploy(ArtifactDeployerRequest.build( + iom.getArgument(0, Session.class), + iom.getArgument(1, RemoteRepository.class), + iom.getArgument(2, Collection.class))); return null; - } ) - .when( artifactDeployer ).deploy( any(), any(), any() ); + }) + .when(artifactDeployer) + .deploy(any(), any(), any()); - ArtifactManager artifactManager = mock( ArtifactManager.class ); + ArtifactManager artifactManager = mock(ArtifactManager.class); Map paths = new HashMap<>(); - doAnswer( iom -> - { - paths.put( iom.getArgument( 0 ), iom.getArgument( 1 ) ); return null; - } ) - .when( artifactManager ).setPath( any(), any() ); - doAnswer( iom -> Optional.ofNullable( paths.get( iom.getArgument( 0, Artifact.class ) ) ) ) - .when( artifactManager ).getPath( any() ); + doAnswer(iom -> { + paths.put(iom.getArgument(0), iom.getArgument(1)); + return null; + }) + .when(artifactManager) + .setPath(any(), any()); + doAnswer(iom -> Optional.ofNullable(paths.get(iom.getArgument(0, Artifact.class)))) + .when(artifactManager) + .getPath(any()); - ProjectManager projectManager = mock( ProjectManager.class ); + ProjectManager projectManager = mock(ProjectManager.class); Map> attachedArtifacts = new HashMap<>(); - doAnswer( iom -> - { - Project project = iom.getArgument( 1, Project.class ); - String type = iom.getArgument( 2, String.class ); - Path path = iom.getArgument( 3, Path.class ); + doAnswer(iom -> { + Project project = iom.getArgument(1, Project.class); + String type = iom.getArgument(2, String.class); + Path path = iom.getArgument(3, Path.class); Artifact artifact = session.createArtifact( - project.getGroupId(), project.getArtifactId(), project.getVersion(), - null, null, type ); - artifactManager.setPath( artifact, path ); - attachedArtifacts.computeIfAbsent( project, p -> new ArrayList<>() ) - .add( artifact ); + project.getGroupId(), project.getArtifactId(), project.getVersion(), null, null, type); + artifactManager.setPath(artifact, path); + attachedArtifacts + .computeIfAbsent(project, p -> new ArrayList<>()) + .add(artifact); return null; - } ) - .when( projectManager ).attachArtifact( same( session ), any( Project.class ), any(), any() ); - doAnswer( iom -> - { - Project project = iom.getArgument( 0, Project.class ); - Artifact artifact = iom.getArgument( 1, Artifact.class ); - Path path = iom.getArgument( 2, Path.class ); - artifactManager.setPath( artifact, path ); - attachedArtifacts.computeIfAbsent( project, p -> new ArrayList<>() ) - .add( artifact ); + }) + .when(projectManager) + .attachArtifact(same(session), any(Project.class), any(), any()); + doAnswer(iom -> { + Project project = iom.getArgument(0, Project.class); + Artifact artifact = iom.getArgument(1, Artifact.class); + Path path = iom.getArgument(2, Path.class); + artifactManager.setPath(artifact, path); + attachedArtifacts + .computeIfAbsent(project, p -> new ArrayList<>()) + .add(artifact); return null; - } ) - .when( projectManager ) - .attachArtifact( any( Project.class ), any( Artifact.class ), any( Path.class ) ); - when( projectManager.getAttachedArtifacts( any() ) ) - .then( iom -> attachedArtifacts.computeIfAbsent( - iom.getArgument( 0, Project.class ), p -> new ArrayList<>() ) ); + }) + .when(projectManager) + .attachArtifact(any(Project.class), any(Artifact.class), any(Path.class)); + when(projectManager.getAttachedArtifacts(any())) + .then(iom -> + attachedArtifacts.computeIfAbsent(iom.getArgument(0, Project.class), p -> new ArrayList<>())); - ArtifactFactory artifactFactory = mock( ArtifactFactory.class ); - when( artifactFactory.create( any() ) ) - .then( iom -> - { - ArtifactFactoryRequest request = iom.getArgument( 0, ArtifactFactoryRequest.class ); - String classifier = request.getClassifier(); - String extension = request.getExtension(); - String type = request.getType(); - if ( classifier == null ) - { - classifier = ""; - } - if ( extension == null ) - { - extension = type != null ? type : ""; - } - return new ArtifactStub( request.getGroupId(), request.getArtifactId(), - classifier, request.getVersion(), extension ); - } ); + ArtifactFactory artifactFactory = mock(ArtifactFactory.class); + when(artifactFactory.create(any())).then(iom -> { + ArtifactFactoryRequest request = iom.getArgument(0, ArtifactFactoryRequest.class); + String classifier = request.getClassifier(); + String extension = request.getExtension(); + String type = request.getType(); + if (classifier == null) { + classifier = ""; + } + if (extension == null) { + extension = type != null ? type : ""; + } + return new ArtifactStub( + request.getGroupId(), request.getArtifactId(), classifier, request.getVersion(), extension); + }); - ProjectBuilder projectBuilder = mock( ProjectBuilder.class ); - when( projectBuilder.build( any( ProjectBuilderRequest.class ) ) ).then( iom -> - { - ProjectBuilderRequest request = iom.getArgument( 0, ProjectBuilderRequest.class ); - ProjectBuilderResult result = mock( ProjectBuilderResult.class ); - Model model = new MavenXpp3Reader().read( - request.getSource().get().getInputStream() ).getDelegate(); - ProjectStub projectStub = new ProjectStub(); - projectStub.setModel( model ); - ArtifactStub artifactStub = new ArtifactStub( model.getGroupId(), model.getArtifactId(), - "", model.getVersion(), model.getPackaging() ); - projectStub.setArtifact( artifactStub ); - when( result.getProject() ).thenReturn( Optional.of( projectStub ) ); - return result; - } ); + ProjectBuilder projectBuilder = mock(ProjectBuilder.class); + when(projectBuilder.build(any(ProjectBuilderRequest.class))).then(iom -> { + ProjectBuilderRequest request = iom.getArgument(0, ProjectBuilderRequest.class); + ProjectBuilderResult result = mock(ProjectBuilderResult.class); + Model model = new MavenXpp3Reader() + .read(request.getSource().get().getInputStream()) + .getDelegate(); + ProjectStub projectStub = new ProjectStub(); + projectStub.setModel(model); + ArtifactStub artifactStub = new ArtifactStub( + model.getGroupId(), model.getArtifactId(), "", model.getVersion(), model.getPackaging()); + projectStub.setArtifact(artifactStub); + when(result.getProject()).thenReturn(Optional.of(projectStub)); + return result; + }); Properties sysProps = new Properties(); Properties usrProps = new Properties(); - doReturn( sysProps ).when( session ).getSystemProperties(); - doReturn( usrProps ).when( session ).getUserProperties(); + doReturn(sysProps).when(session).getSystemProperties(); + doReturn(usrProps).when(session).getUserProperties(); - when( session.getLocalRepository() ).thenReturn( localRepository ); - when( session.getService( RepositoryFactory.class ) ).thenReturn( repositoryFactory ); - when( session.getService( ProjectBuilder.class ) ).thenReturn( projectBuilder ); - when( session.getService( LocalRepositoryManager.class ) ).thenReturn( localRepositoryManager ); - when( session.getService( ProjectManager.class ) ).thenReturn( projectManager ); - when( session.getService( ArtifactManager.class ) ).thenReturn( artifactManager ); - when( session.getService( ArtifactInstaller.class ) ).thenReturn( artifactInstaller ); - when( session.getService( ArtifactDeployer.class ) ).thenReturn( artifactDeployer ); - when( session.getService( ArtifactFactory.class ) ).thenReturn( artifactFactory ); - when( session.getService( ModelXmlFactory.class ) ).thenReturn( new DefaultModelXmlFactory() ); + when(session.getLocalRepository()).thenReturn(localRepository); + when(session.getService(RepositoryFactory.class)).thenReturn(repositoryFactory); + when(session.getService(ProjectBuilder.class)).thenReturn(projectBuilder); + when(session.getService(LocalRepositoryManager.class)).thenReturn(localRepositoryManager); + when(session.getService(ProjectManager.class)).thenReturn(projectManager); + when(session.getService(ArtifactManager.class)).thenReturn(artifactManager); + when(session.getService(ArtifactInstaller.class)).thenReturn(artifactInstaller); + when(session.getService(ArtifactDeployer.class)).thenReturn(artifactDeployer); + when(session.getService(ArtifactFactory.class)).thenReturn(artifactFactory); + when(session.getService(ModelXmlFactory.class)).thenReturn(new DefaultModelXmlFactory()); - when( session.getPathForLocalArtifact( any( Artifact.class ) ) ) - .then( iom -> localRepositoryManager.getPathForLocalArtifact( session, - session.getLocalRepository(), iom.getArgument( 0, Artifact.class ) ) ); - when( session.createArtifact( any(), any(), any(), any(), any(), any() ) ) - .thenAnswer( iom -> - { - String groupId = iom.getArgument( 0, String.class ); - String artifactId = iom.getArgument( 1, String.class ); - String version = iom.getArgument( 2, String.class ); - String classifier = iom.getArgument( 3, String.class ); - String extension = iom.getArgument( 4, String.class ); - String type = iom.getArgument( 5, String.class ); - return session.getService( ArtifactFactory.class ).create( ArtifactFactoryRequest.builder() - .session( session ) - .groupId( groupId ) - .artifactId( artifactId ) - .version( version ) - .classifier( classifier ) - .extension( extension ) - .type( type ) - .build() ); - } ); - when( session.createArtifact( any(), any(), any(), any() ) ) - .thenAnswer( iom -> - { - String groupId = iom.getArgument( 0, String.class ); - String artifactId = iom.getArgument( 1, String.class ); - String version = iom.getArgument( 2, String.class ); - String extension = iom.getArgument( 3, String.class ); - return session.getService( ArtifactFactory.class ).create( ArtifactFactoryRequest.builder() - .session( session ) - .groupId( groupId ) - .artifactId( artifactId ) - .version( version ) - .extension( extension ) - .build() ); - } ); - when ( session.createRemoteRepository( anyString(), anyString() ) ) - .thenAnswer( iom -> - { - String id = iom.getArgument( 0, String.class ); - String url = iom.getArgument( 1, String.class ); - return session.getService( RepositoryFactory.class ).createRemote( id, url ); - } ); - doAnswer( iom -> artifactManager.getPath( iom.getArgument( 0, Artifact.class ) ) ) - .when( session ).getArtifactPath( any() ); + when(session.getPathForLocalArtifact(any(Artifact.class))) + .then(iom -> localRepositoryManager.getPathForLocalArtifact( + session, session.getLocalRepository(), iom.getArgument(0, Artifact.class))); + when(session.createArtifact(any(), any(), any(), any(), any(), any())).thenAnswer(iom -> { + String groupId = iom.getArgument(0, String.class); + String artifactId = iom.getArgument(1, String.class); + String version = iom.getArgument(2, String.class); + String classifier = iom.getArgument(3, String.class); + String extension = iom.getArgument(4, String.class); + String type = iom.getArgument(5, String.class); + return session.getService(ArtifactFactory.class) + .create(ArtifactFactoryRequest.builder() + .session(session) + .groupId(groupId) + .artifactId(artifactId) + .version(version) + .classifier(classifier) + .extension(extension) + .type(type) + .build()); + }); + when(session.createArtifact(any(), any(), any(), any())).thenAnswer(iom -> { + String groupId = iom.getArgument(0, String.class); + String artifactId = iom.getArgument(1, String.class); + String version = iom.getArgument(2, String.class); + String extension = iom.getArgument(3, String.class); + return session.getService(ArtifactFactory.class) + .create(ArtifactFactoryRequest.builder() + .session(session) + .groupId(groupId) + .artifactId(artifactId) + .version(version) + .extension(extension) + .build()); + }); + when(session.createRemoteRepository(anyString(), anyString())).thenAnswer(iom -> { + String id = iom.getArgument(0, String.class); + String url = iom.getArgument(1, String.class); + return session.getService(RepositoryFactory.class).createRemote(id, url); + }); + doAnswer(iom -> artifactManager.getPath(iom.getArgument(0, Artifact.class))) + .when(session) + .getArtifactPath(any()); - when( session.withLocalRepository( any() ) ) - .thenAnswer( iom -> getMockSession( iom.getArgument( 0, LocalRepository.class ) ) ); + when(session.withLocalRepository(any())) + .thenAnswer(iom -> getMockSession(iom.getArgument(0, LocalRepository.class))); return session; } - static String getPathForArtifact( Artifact artifact, boolean local ) - { - StringBuilder path = new StringBuilder( 128 ); - path.append( artifact.getGroupId().replace( '.', '/' ) ).append( '/' ); - path.append( artifact.getArtifactId() ).append( '/' ); - path.append( artifact.getVersion() ).append( '/' ); - path.append( artifact.getArtifactId() ).append( '-' ); - path.append( artifact.getVersion() ); - if ( artifact.getClassifier().length() > 0 ) - { - path.append( '-' ).append( artifact.getClassifier() ); + static String getPathForArtifact(Artifact artifact, boolean local) { + StringBuilder path = new StringBuilder(128); + path.append(artifact.getGroupId().replace('.', '/')).append('/'); + path.append(artifact.getArtifactId()).append('/'); + path.append(artifact.getVersion()).append('/'); + path.append(artifact.getArtifactId()).append('-'); + path.append(artifact.getVersion()); + if (artifact.getClassifier().length() > 0) { + path.append('-').append(artifact.getClassifier()); } - if ( artifact.getExtension().length() > 0 ) - { - path.append( '.' ).append( artifact.getExtension() ); + if (artifact.getExtension().length() > 0) { + path.append('.').append(artifact.getExtension()); } return path.toString(); } - } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java index acea6ec1..8c465731 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; import java.io.BufferedReader; import java.io.File; @@ -91,31 +90,23 @@ * * @author jesse */ -public abstract class AbstractMojoTestCase - extends PlexusTestCase -{ +public abstract class AbstractMojoTestCase extends PlexusTestCase { private static final DefaultArtifactVersion MAVEN_VERSION; - static - { + static { DefaultArtifactVersion version = null; String path = "/META-INF/maven/org.apache.maven/maven-core/pom.properties"; - - try ( InputStream is = AbstractMojoTestCase.class.getResourceAsStream( path ) ) - { + + try (InputStream is = AbstractMojoTestCase.class.getResourceAsStream(path)) { Properties properties = new Properties(); - if ( is != null ) - { - properties.load( is ); + if (is != null) { + properties.load(is); } - String property = properties.getProperty( "version" ); - if ( property != null ) - { - version = new DefaultArtifactVersion( property ); + String property = properties.getProperty("version"); + if (property != null) { + version = new DefaultArtifactVersion(property); } - } - catch ( IOException e ) - { + } catch (IOException e) { // odd, where did this come from } MAVEN_VERSION = version; @@ -126,49 +117,47 @@ public abstract class AbstractMojoTestCase private PlexusContainer container; private Map mojoDescriptors; - + /* * for the harness I think we have decided against going the route of using the maven project builder. * instead I think we are going to try and make an instance of the localrespository and assign that * to either the project stub or into the mojo directly with injection...not sure yet though. */ - //private MavenProjectBuilder projectBuilder; + // private MavenProjectBuilder projectBuilder; @Override - protected void setUp() - throws Exception - { - assertTrue( "Maven 3.2.4 or better is required", - MAVEN_VERSION == null || new DefaultArtifactVersion( "3.2.3" ).compareTo( MAVEN_VERSION ) < 0 ); + protected void setUp() throws Exception { + assertTrue( + "Maven 3.2.4 or better is required", + MAVEN_VERSION == null || new DefaultArtifactVersion("3.2.3").compareTo(MAVEN_VERSION) < 0); - configurator = getContainer().lookup( ComponentConfigurator.class, "basic" ); + configurator = getContainer().lookup(ComponentConfigurator.class, "basic"); Context context = container.getContext(); Map map = context.getContextData(); - try ( InputStream is = getClass().getResourceAsStream( "/" + getPluginDescriptorLocation() ); - Reader reader = new BufferedReader( new XmlStreamReader( is ) ); - InterpolationFilterReader interpolationReader = new InterpolationFilterReader( reader, map, "${", "}" ) ) - { - - PluginDescriptor pluginDescriptor = new PluginDescriptorBuilder().build( interpolationReader ); - - Artifact artifact = - lookup( RepositorySystem.class ).createArtifact( pluginDescriptor.getGroupId(), - pluginDescriptor.getArtifactId(), - pluginDescriptor.getVersion(), ".jar" ); - - artifact.setFile( getPluginArtifactFile() ); - pluginDescriptor.setPluginArtifact( artifact ); - pluginDescriptor.setArtifacts( Arrays.asList( artifact ) ); - - for ( ComponentDescriptor desc : pluginDescriptor.getComponents() ) - { - getContainer().addComponentDescriptor( desc ); + try (InputStream is = getClass().getResourceAsStream("/" + getPluginDescriptorLocation()); + Reader reader = new BufferedReader(new XmlStreamReader(is)); + InterpolationFilterReader interpolationReader = new InterpolationFilterReader(reader, map, "${", "}")) { + + PluginDescriptor pluginDescriptor = new PluginDescriptorBuilder().build(interpolationReader); + + Artifact artifact = lookup(RepositorySystem.class) + .createArtifact( + pluginDescriptor.getGroupId(), + pluginDescriptor.getArtifactId(), + pluginDescriptor.getVersion(), + ".jar"); + + artifact.setFile(getPluginArtifactFile()); + pluginDescriptor.setPluginArtifact(artifact); + pluginDescriptor.setArtifacts(Arrays.asList(artifact)); + + for (ComponentDescriptor desc : pluginDescriptor.getComponents()) { + getContainer().addComponentDescriptor(desc); } - + mojoDescriptors = new HashMap<>(); - for ( MojoDescriptor mojoDescriptor : pluginDescriptor.getMojos() ) - { - mojoDescriptors.put( mojoDescriptor.getGoal(), mojoDescriptor ); + for (MojoDescriptor mojoDescriptor : pluginDescriptor.getMojos()) { + mojoDescriptors.put(mojoDescriptor.getGoal(), mojoDescriptor); } } } @@ -179,122 +168,97 @@ protected void setUp() * First, attempts to determine parent directory of META-INF directory holding the plugin descriptor. If META-INF * parent directory cannot be determined, falls back to test basedir. */ - private File getPluginArtifactFile() - throws IOException - { + private File getPluginArtifactFile() throws IOException { final String pluginDescriptorLocation = getPluginDescriptorLocation(); - final URL resource = getClass().getResource( "/" + pluginDescriptorLocation ); + final URL resource = getClass().getResource("/" + pluginDescriptorLocation); File file = null; // attempt to resolve relative to META-INF/maven/plugin.xml first - if ( resource != null ) - { - if ( "file".equalsIgnoreCase( resource.getProtocol() ) ) - { + if (resource != null) { + if ("file".equalsIgnoreCase(resource.getProtocol())) { String path = resource.getPath(); - if ( path.endsWith( pluginDescriptorLocation ) ) - { - file = new File( path.substring( 0, path.length() - pluginDescriptorLocation.length() ) ); + if (path.endsWith(pluginDescriptorLocation)) { + file = new File(path.substring(0, path.length() - pluginDescriptorLocation.length())); } - } - else if ( "jar".equalsIgnoreCase( resource.getProtocol() ) ) - { + } else if ("jar".equalsIgnoreCase(resource.getProtocol())) { // TODO is there a helper for this somewhere? - try - { - URL jarfile = new URL( resource.getPath() ); - if ( "file".equalsIgnoreCase( jarfile.getProtocol() ) ) - { + try { + URL jarfile = new URL(resource.getPath()); + if ("file".equalsIgnoreCase(jarfile.getProtocol())) { String path = jarfile.getPath(); - if ( path.endsWith( pluginDescriptorLocation ) ) - { - file = - new File( path.substring( 0, path.length() - pluginDescriptorLocation.length() - 2 ) ); + if (path.endsWith(pluginDescriptorLocation)) { + file = new File(path.substring(0, path.length() - pluginDescriptorLocation.length() - 2)); } } - } - catch ( MalformedURLException e ) - { + } catch (MalformedURLException e) { // not jar:file:/ URL, too bad } } } // fallback to test project basedir if couldn't resolve relative to META-INF/maven/plugin.xml - if ( file == null || ! file.exists() ) - { - file = new File( getBasedir() ); + if (file == null || !file.exists()) { + file = new File(getBasedir()); } return file.getCanonicalFile(); } - protected InputStream getPublicDescriptorStream() - throws Exception - { - return new FileInputStream( new File( getPluginDescriptorPath() ) ); + protected InputStream getPublicDescriptorStream() throws Exception { + return new FileInputStream(new File(getPluginDescriptorPath())); } - protected String getPluginDescriptorPath() - { + protected String getPluginDescriptorPath() { return getBasedir() + "/target/classes/META-INF/maven/plugin.xml"; } - protected String getPluginDescriptorLocation() - { + protected String getPluginDescriptorLocation() { return "META-INF/maven/plugin.xml"; } @Override - protected void setupContainer() - { + protected void setupContainer() { ContainerConfiguration cc = setupContainerConfiguration(); - try - { + try { List modules = new ArrayList<>(); - addGuiceModules( modules ); - container = new DefaultPlexusContainer( cc, modules.toArray( new Module[0] ) ); - } - catch ( PlexusContainerException e ) - { + addGuiceModules(modules); + container = new DefaultPlexusContainer(cc, modules.toArray(new Module[0])); + } catch (PlexusContainerException e) { e.printStackTrace(); - fail( "Failed to create plexus container." ); - } + fail("Failed to create plexus container."); + } } /** * @since 3.0.0 */ - protected void addGuiceModules( List modules ) - { + protected void addGuiceModules(List modules) { // no custom guice modules by default } - protected ContainerConfiguration setupContainerConfiguration() - { - ClassWorld classWorld = new ClassWorld( "plexus.core", Thread.currentThread().getContextClassLoader() ); + protected ContainerConfiguration setupContainerConfiguration() { + ClassWorld classWorld = + new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader()); ContainerConfiguration cc = new DefaultContainerConfiguration() - .setClassWorld( classWorld ) - .setClassPathScanning( PlexusConstants.SCANNING_INDEX ) - .setAutoWiring( true ) - .setName( "maven" ); + .setClassWorld(classWorld) + .setClassPathScanning(PlexusConstants.SCANNING_INDEX) + .setAutoWiring(true) + .setName("maven"); return cc; } - + @Override - protected PlexusContainer getContainer() - { - if ( container == null ) - { + protected PlexusContainer getContainer() { + if (container == null) { setupContainer(); } return container; - } - + } + /** * Lookup the mojo leveraging the subproject pom * @@ -303,10 +267,8 @@ protected PlexusContainer getContainer() * @return a Mojo instance * @throws Exception */ - protected T lookupMojo( String goal, String pluginPom ) - throws Exception - { - return lookupMojo( goal, new File( pluginPom ) ); + protected T lookupMojo(String goal, String pluginPom) throws Exception { + return lookupMojo(goal, new File(pluginPom)); } /** @@ -317,10 +279,8 @@ protected T lookupMojo( String goal, String pluginPom ) * @return a Mojo instance * @throws Exception */ - protected T lookupEmptyMojo( String goal, String pluginPom ) - throws Exception - { - return lookupEmptyMojo( goal, new File( pluginPom ) ); + protected T lookupEmptyMojo(String goal, String pluginPom) throws Exception { + return lookupEmptyMojo(goal, new File(pluginPom)); } /** @@ -331,22 +291,20 @@ protected T lookupEmptyMojo( String goal, String pluginPom ) * @return a Mojo instance * @throws Exception */ - protected T lookupMojo( String goal, File pom ) - throws Exception - { - File pluginPom = new File( getBasedir(), "pom.xml" ); + protected T lookupMojo(String goal, File pom) throws Exception { + File pluginPom = new File(getBasedir(), "pom.xml"); - Xpp3Dom pluginPomDom = Xpp3DomBuilder.build( ReaderFactory.newXmlReader( pluginPom ) ); + Xpp3Dom pluginPomDom = Xpp3DomBuilder.build(ReaderFactory.newXmlReader(pluginPom)); - String artifactId = pluginPomDom.getChild( "artifactId" ).getValue(); + String artifactId = pluginPomDom.getChild("artifactId").getValue(); - String groupId = resolveFromRootThenParent( pluginPomDom, "groupId" ); + String groupId = resolveFromRootThenParent(pluginPomDom, "groupId"); - String version = resolveFromRootThenParent( pluginPomDom, "version" ); + String version = resolveFromRootThenParent(pluginPomDom, "version"); - PlexusConfiguration pluginConfiguration = extractPluginConfiguration( artifactId, pom ); + PlexusConfiguration pluginConfiguration = extractPluginConfiguration(artifactId, pom); - return lookupMojo( groupId, artifactId, version, goal, pluginConfiguration ); + return lookupMojo(groupId, artifactId, version, goal, pluginConfiguration); } /** @@ -357,31 +315,29 @@ protected T lookupMojo( String goal, File pom ) * @return a Mojo instance * @throws Exception */ - protected T lookupEmptyMojo( String goal, File pom ) - throws Exception - { - File pluginPom = new File( getBasedir(), "pom.xml" ); + protected T lookupEmptyMojo(String goal, File pom) throws Exception { + File pluginPom = new File(getBasedir(), "pom.xml"); - Xpp3Dom pluginPomDom = Xpp3DomBuilder.build( ReaderFactory.newXmlReader( pluginPom ) ); + Xpp3Dom pluginPomDom = Xpp3DomBuilder.build(ReaderFactory.newXmlReader(pluginPom)); - String artifactId = pluginPomDom.getChild( "artifactId" ).getValue(); + String artifactId = pluginPomDom.getChild("artifactId").getValue(); - String groupId = resolveFromRootThenParent( pluginPomDom, "groupId" ); + String groupId = resolveFromRootThenParent(pluginPomDom, "groupId"); - String version = resolveFromRootThenParent( pluginPomDom, "version" ); + String version = resolveFromRootThenParent(pluginPomDom, "version"); - return lookupMojo( groupId, artifactId, version, goal, null ); + return lookupMojo(groupId, artifactId, version, goal, null); } /* - protected Mojo lookupMojo( String groupId, String artifactId, String version, String goal, File pom ) - throws Exception - { - PlexusConfiguration pluginConfiguration = extractPluginConfiguration( artifactId, pom ); + protected Mojo lookupMojo( String groupId, String artifactId, String version, String goal, File pom ) + throws Exception + { + PlexusConfiguration pluginConfiguration = extractPluginConfiguration( artifactId, pom ); - return lookupMojo( groupId, artifactId, version, goal, pluginConfiguration ); - } - */ + return lookupMojo( groupId, artifactId, version, goal, pluginConfiguration ); + } + */ /** * lookup the mojo while we have all of the relavent information * @@ -393,25 +349,24 @@ protected Mojo lookupMojo( String groupId, String artifactId, String version, St * @return a Mojo instance * @throws Exception */ - protected T lookupMojo( String groupId, String artifactId, String version, String goal, - PlexusConfiguration pluginConfiguration ) - throws Exception - { + protected T lookupMojo( + String groupId, String artifactId, String version, String goal, PlexusConfiguration pluginConfiguration) + throws Exception { validateContainerStatus(); // pluginkey = groupId : artifactId : version : goal - T mojo = (T) lookup( Mojo.class, groupId + ":" + artifactId + ":" + version + ":" + goal ); + T mojo = (T) lookup(Mojo.class, groupId + ":" + artifactId + ":" + version + ":" + goal); - if ( pluginConfiguration != null ) - { + if (pluginConfiguration != null) { /* requires v10 of plexus container for lookup on expression evaluator - ExpressionEvaluator evaluator = (ExpressionEvaluator) getContainer().lookup( ExpressionEvaluator.ROLE, - "stub-evaluator" ); - */ + ExpressionEvaluator evaluator = (ExpressionEvaluator) getContainer().lookup( ExpressionEvaluator.ROLE, + "stub-evaluator" ); + */ ExpressionEvaluator evaluator = new ResolverExpressionEvaluatorStub(); - configurator.configureComponent( mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm() ); + configurator.configureComponent( + mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm()); } return mojo; @@ -425,10 +380,8 @@ protected T lookupMojo( String groupId, String artifactId, Stri * @throws Exception * @since 2.0 */ - protected T lookupConfiguredMojo( MavenProject project, String goal ) - throws Exception - { - return lookupConfiguredMojo( newMavenSession( project ), newMojoExecution( goal ) ); + protected T lookupConfiguredMojo(MavenProject project, String goal) throws Exception { + return lookupConfiguredMojo(newMavenSession(project), newMojoExecution(goal)); } /** @@ -440,120 +393,107 @@ protected T lookupConfiguredMojo( MavenProject project, String * @throws ComponentConfigurationException * @since 2.0 */ - protected T lookupConfiguredMojo( MavenSession session, MojoExecution execution ) - throws Exception, ComponentConfigurationException - { + protected T lookupConfiguredMojo(MavenSession session, MojoExecution execution) + throws Exception, ComponentConfigurationException { MavenProject project = session.getCurrentProject(); MojoDescriptor mojoDescriptor = execution.getMojoDescriptor(); - T mojo = (T) lookup( mojoDescriptor.getRole(), mojoDescriptor.getRoleHint() ); + T mojo = (T) lookup(mojoDescriptor.getRole(), mojoDescriptor.getRoleHint()); - ExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator( session, execution ); + ExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator(session, execution); Xpp3Dom configuration = null; - Plugin plugin = project.getPlugin( mojoDescriptor.getPluginDescriptor().getPluginLookupKey() ); - if ( plugin != null ) - { + Plugin plugin = project.getPlugin(mojoDescriptor.getPluginDescriptor().getPluginLookupKey()); + if (plugin != null) { configuration = (Xpp3Dom) plugin.getConfiguration(); } - if ( configuration == null ) - { - configuration = new Xpp3Dom( "configuration" ); + if (configuration == null) { + configuration = new Xpp3Dom("configuration"); } - configuration = Xpp3Dom.mergeXpp3Dom( configuration, execution.getConfiguration() ); + configuration = Xpp3Dom.mergeXpp3Dom(configuration, execution.getConfiguration()); - PlexusConfiguration pluginConfiguration = new XmlPlexusConfiguration( configuration ); + PlexusConfiguration pluginConfiguration = new XmlPlexusConfiguration(configuration); - if ( mojoDescriptor.getComponentConfigurator() != null ) - { + if (mojoDescriptor.getComponentConfigurator() != null) { configurator = - getContainer().lookup( ComponentConfigurator.class, mojoDescriptor.getComponentConfigurator() ); - } - - configurator.configureComponent( mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm() ); + getContainer().lookup(ComponentConfigurator.class, mojoDescriptor.getComponentConfigurator()); + } + + configurator.configureComponent( + mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm()); return mojo; } /** - * + * * @param project * @return * @since 2.0 */ - protected MavenSession newMavenSession( MavenProject project ) - { + protected MavenSession newMavenSession(MavenProject project) { MavenExecutionRequest request = new DefaultMavenExecutionRequest(); MavenExecutionResult result = new DefaultMavenExecutionResult(); - MavenSession session = new MavenSession( container, MavenRepositorySystemUtils.newSession(), request, result ); - session.setCurrentProject( project ); - session.setProjects( Arrays.asList( project ) ); + MavenSession session = new MavenSession(container, MavenRepositorySystemUtils.newSession(), request, result); + session.setCurrentProject(project); + session.setProjects(Arrays.asList(project)); return session; } /** - * + * * @param goal * @return * @since 2.0 */ - protected MojoExecution newMojoExecution( String goal ) - { - MojoDescriptor mojoDescriptor = mojoDescriptors.get( goal ); - assertNotNull( String.format( "The MojoDescriptor for the goal %s cannot be null.", goal ), mojoDescriptor ); - MojoExecution execution = new MojoExecution( mojoDescriptor ); - finalizeMojoConfiguration( execution ); + protected MojoExecution newMojoExecution(String goal) { + MojoDescriptor mojoDescriptor = mojoDescriptors.get(goal); + assertNotNull(String.format("The MojoDescriptor for the goal %s cannot be null.", goal), mojoDescriptor); + MojoExecution execution = new MojoExecution(mojoDescriptor); + finalizeMojoConfiguration(execution); return execution; } // copy&paste from o.a.m.l.i.DefaultLifecycleExecutionPlanCalculator.finalizeMojoConfiguration(MojoExecution) - private void finalizeMojoConfiguration( MojoExecution mojoExecution ) - { + private void finalizeMojoConfiguration(MojoExecution mojoExecution) { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); Xpp3Dom executionConfiguration = mojoExecution.getConfiguration(); - if ( executionConfiguration == null ) - { - executionConfiguration = new Xpp3Dom( "configuration" ); + if (executionConfiguration == null) { + executionConfiguration = new Xpp3Dom("configuration"); } - Xpp3Dom defaultConfiguration = new Xpp3Dom( MojoDescriptorCreator.convert( mojoDescriptor ) ); + Xpp3Dom defaultConfiguration = new Xpp3Dom(MojoDescriptorCreator.convert(mojoDescriptor)); - Xpp3Dom finalConfiguration = new Xpp3Dom( "configuration" ); + Xpp3Dom finalConfiguration = new Xpp3Dom("configuration"); - if ( mojoDescriptor.getParameters() != null ) - { - for ( Parameter parameter : mojoDescriptor.getParameters() ) - { - Xpp3Dom parameterConfiguration = executionConfiguration.getChild( parameter.getName() ); + if (mojoDescriptor.getParameters() != null) { + for (Parameter parameter : mojoDescriptor.getParameters()) { + Xpp3Dom parameterConfiguration = executionConfiguration.getChild(parameter.getName()); - if ( parameterConfiguration == null ) - { - parameterConfiguration = executionConfiguration.getChild( parameter.getAlias() ); + if (parameterConfiguration == null) { + parameterConfiguration = executionConfiguration.getChild(parameter.getAlias()); } - Xpp3Dom parameterDefaults = defaultConfiguration.getChild( parameter.getName() ); + Xpp3Dom parameterDefaults = defaultConfiguration.getChild(parameter.getName()); - parameterConfiguration = - Xpp3Dom.mergeXpp3Dom( parameterConfiguration, parameterDefaults, Boolean.TRUE ); + parameterConfiguration = Xpp3Dom.mergeXpp3Dom(parameterConfiguration, parameterDefaults, Boolean.TRUE); - if ( parameterConfiguration != null ) - { - parameterConfiguration = new Xpp3Dom( parameterConfiguration, parameter.getName() ); + if (parameterConfiguration != null) { + parameterConfiguration = new Xpp3Dom(parameterConfiguration, parameter.getName()); - if ( StringUtils.isEmpty( parameterConfiguration.getAttribute( "implementation" ) ) - && StringUtils.isNotEmpty( parameter.getImplementation() ) ) - { - parameterConfiguration.setAttribute( "implementation", parameter.getImplementation() ); + if (StringUtils.isEmpty(parameterConfiguration.getAttribute("implementation")) + && StringUtils.isNotEmpty(parameter.getImplementation())) { + parameterConfiguration.setAttribute("implementation", parameter.getImplementation()); } - finalConfiguration.addChild( parameterConfiguration ); + finalConfiguration.addChild(parameterConfiguration); } } } - mojoExecution.setConfiguration( finalConfiguration ); + mojoExecution.setConfiguration(finalConfiguration); } /** @@ -562,14 +502,11 @@ private void finalizeMojoConfiguration( MojoExecution mojoExecution ) * @return the plexus configuration * @throws Exception */ - protected PlexusConfiguration extractPluginConfiguration( String artifactId, File pom ) - throws Exception - { - - try ( Reader reader = ReaderFactory.newXmlReader( pom ) ) - { - Xpp3Dom pomDom = Xpp3DomBuilder.build( reader ); - return extractPluginConfiguration( artifactId, pomDom ); + protected PlexusConfiguration extractPluginConfiguration(String artifactId, File pom) throws Exception { + + try (Reader reader = ReaderFactory.newXmlReader(pom)) { + Xpp3Dom pomDom = Xpp3DomBuilder.build(reader); + return extractPluginConfiguration(artifactId, pomDom); } } @@ -579,47 +516,40 @@ protected PlexusConfiguration extractPluginConfiguration( String artifactId, Fil * @return the plexus configuration * @throws Exception */ - protected PlexusConfiguration extractPluginConfiguration( String artifactId, Xpp3Dom pomDom ) - throws Exception - { + protected PlexusConfiguration extractPluginConfiguration(String artifactId, Xpp3Dom pomDom) throws Exception { Xpp3Dom pluginConfigurationElement = null; - Xpp3Dom buildElement = pomDom.getChild( "build" ); - if ( buildElement != null ) - { - Xpp3Dom pluginsRootElement = buildElement.getChild( "plugins" ); + Xpp3Dom buildElement = pomDom.getChild("build"); + if (buildElement != null) { + Xpp3Dom pluginsRootElement = buildElement.getChild("plugins"); - if ( pluginsRootElement != null ) - { + if (pluginsRootElement != null) { Xpp3Dom[] pluginElements = pluginsRootElement.getChildren(); - for ( Xpp3Dom pluginElement : pluginElements ) - { - String pluginElementArtifactId = pluginElement.getChild( "artifactId" ).getValue(); + for (Xpp3Dom pluginElement : pluginElements) { + String pluginElementArtifactId = + pluginElement.getChild("artifactId").getValue(); - if ( pluginElementArtifactId.equals( artifactId ) ) - { - pluginConfigurationElement = pluginElement.getChild( "configuration" ); + if (pluginElementArtifactId.equals(artifactId)) { + pluginConfigurationElement = pluginElement.getChild("configuration"); break; } } - if ( pluginConfigurationElement == null ) - { - throw new ConfigurationException( "Cannot find a configuration element for a plugin with an " - + "artifactId of " + artifactId + "." ); + if (pluginConfigurationElement == null) { + throw new ConfigurationException("Cannot find a configuration element for a plugin with an " + + "artifactId of " + artifactId + "."); } } } - if ( pluginConfigurationElement == null ) - { - throw new ConfigurationException( "Cannot find a configuration element for a plugin with an artifactId of " - + artifactId + "." ); + if (pluginConfigurationElement == null) { + throw new ConfigurationException( + "Cannot find a configuration element for a plugin with an artifactId of " + artifactId + "."); } - return new XmlPlexusConfiguration( pluginConfigurationElement ); + return new XmlPlexusConfiguration(pluginConfigurationElement); } /** @@ -631,16 +561,15 @@ protected PlexusConfiguration extractPluginConfiguration( String artifactId, Xpp * @return a Mojo instance * @throws Exception */ - protected T configureMojo( T mojo, String artifactId, File pom ) - throws Exception - { + protected T configureMojo(T mojo, String artifactId, File pom) throws Exception { validateContainerStatus(); - PlexusConfiguration pluginConfiguration = extractPluginConfiguration( artifactId, pom ); + PlexusConfiguration pluginConfiguration = extractPluginConfiguration(artifactId, pom); ExpressionEvaluator evaluator = new ResolverExpressionEvaluatorStub(); - configurator.configureComponent( mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm() ); + configurator.configureComponent( + mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm()); return mojo; } @@ -653,14 +582,13 @@ protected T configureMojo( T mojo, String artifactId, File pom * @return a Mojo instance * @throws Exception */ - protected T configureMojo( T mojo, PlexusConfiguration pluginConfiguration ) - throws Exception - { + protected T configureMojo(T mojo, PlexusConfiguration pluginConfiguration) throws Exception { validateContainerStatus(); ExpressionEvaluator evaluator = new ResolverExpressionEvaluatorStub(); - configurator.configureComponent( mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm() ); + configurator.configureComponent( + mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm()); return mojo; } @@ -675,14 +603,12 @@ protected T configureMojo( T mojo, PlexusConfiguration pluginCo * @return object value of variable * @throws IllegalArgumentException */ - protected T getVariableValueFromObject( Object object, String variable ) - throws IllegalAccessException - { - Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses( variable, object.getClass() ); + protected T getVariableValueFromObject(Object object, String variable) throws IllegalAccessException { + Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses(variable, object.getClass()); - field.setAccessible( true ); + field.setAccessible(true); - return (T) field.get( object ); + return (T) field.get(object); } /** @@ -693,10 +619,8 @@ protected T getVariableValueFromObject( Object object, String variable ) * @param object * @return map of variable names and values */ - protected Map getVariablesAndValuesFromObject( Object object ) - throws IllegalAccessException - { - return getVariablesAndValuesFromObject( object.getClass(), object ); + protected Map getVariablesAndValuesFromObject(Object object) throws IllegalAccessException { + return getVariablesAndValuesFromObject(object.getClass(), object); } /** @@ -708,25 +632,22 @@ protected Map getVariablesAndValuesFromObject( Object object ) * @param object * @return map of variable names and values */ - protected Map getVariablesAndValuesFromObject( Class clazz, Object object ) - throws IllegalAccessException - { + protected Map getVariablesAndValuesFromObject(Class clazz, Object object) + throws IllegalAccessException { Map map = new HashMap<>(); Field[] fields = clazz.getDeclaredFields(); - AccessibleObject.setAccessible( fields, true ); + AccessibleObject.setAccessible(fields, true); - for ( Field field : fields ) - { - map.put( field.getName(), field.get( object ) ); + for (Field field : fields) { + map.put(field.getName(), field.get(object)); } Class superclass = clazz.getSuperclass(); - if ( !Object.class.equals( superclass ) ) - { - map.putAll( getVariablesAndValuesFromObject( superclass, object ) ); + if (!Object.class.equals(superclass)) { + map.putAll(getVariablesAndValuesFromObject(superclass, object)); } return map; @@ -740,14 +661,12 @@ protected Map getVariablesAndValuesFromObject( Class clazz, O * @param value * @throws IllegalAccessException */ - protected void setVariableValueToObject( Object object, String variable, T value ) - throws IllegalAccessException - { - Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses( variable, object.getClass() ); + protected void setVariableValueToObject(Object object, String variable, T value) throws IllegalAccessException { + Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses(variable, object.getClass()); - field.setAccessible( true ); + field.setAccessible(true); - field.set( object, value ); + field.set(object, value); } /** @@ -760,29 +679,24 @@ protected void setVariableValueToObject( Object object, String variable, T v * @return * @throws Exception */ - private String resolveFromRootThenParent( Xpp3Dom pluginPomDom, String element ) - throws Exception - { - Xpp3Dom elementDom = pluginPomDom.getChild( element ); + private String resolveFromRootThenParent(Xpp3Dom pluginPomDom, String element) throws Exception { + Xpp3Dom elementDom = pluginPomDom.getChild(element); // parent might have the group Id so resolve it - if ( elementDom == null ) - { - Xpp3Dom pluginParentDom = pluginPomDom.getChild( "parent" ); + if (elementDom == null) { + Xpp3Dom pluginParentDom = pluginPomDom.getChild("parent"); - if ( pluginParentDom != null ) - { - elementDom = pluginParentDom.getChild( element ); + if (pluginParentDom != null) { + elementDom = pluginParentDom.getChild(element); - if ( elementDom == null ) - { - throw new Exception( "unable to determine " + element ); + if (elementDom == null) { + throw new Exception("unable to determine " + element); } return elementDom.getValue(); } - throw new Exception( "unable to determine " + element ); + throw new Exception("unable to determine " + element); } return elementDom.getValue(); @@ -796,14 +710,11 @@ private String resolveFromRootThenParent( Xpp3Dom pluginPomDom, String element ) * * @throws Exception */ - private void validateContainerStatus() - throws Exception - { - if ( getContainer() != null ) - { + private void validateContainerStatus() throws Exception { + if (getContainer() != null) { return; } - throw new Exception( "container is null, make sure super.setUp() is called" ); - } + throw new Exception("container is null, make sure super.setUp() is called"); + } } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java index 73bc8eea..c490845e 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 + * 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 @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; import java.io.File; import java.io.IOException; @@ -48,8 +47,7 @@ * * @author Brian Fox */ -public class ArtifactStubFactory -{ +public class ArtifactStubFactory { private File workingDir; private boolean createFiles; @@ -63,8 +61,7 @@ public class ArtifactStubFactory /** * Default constructor. This should be used only if real files aren't needed...just the artifact objects */ - public ArtifactStubFactory() - { + public ArtifactStubFactory() { this.workingDir = null; this.createFiles = false; } @@ -75,9 +72,8 @@ public ArtifactStubFactory() * @param workingDir * @param createFiles */ - public ArtifactStubFactory( File workingDir, boolean createFiles ) - { - this.workingDir = new File( workingDir, "localTestRepo" ); + public ArtifactStubFactory(File workingDir, boolean createFiles) { + this.workingDir = new File(workingDir, "localTestRepo"); this.createFiles = createFiles; } @@ -87,8 +83,7 @@ public ArtifactStubFactory( File workingDir, boolean createFiles ) * * @param archiverManager */ - public void setUnpackableFile( ArchiverManager archiverManager ) - { + public void setUnpackableFile(ArchiverManager archiverManager) { this.createUnpackableFile = true; this.archiverManager = archiverManager; } @@ -101,10 +96,8 @@ public void setUnpackableFile( ArchiverManager archiverManager ) * @throws IOException if any * @see #createArtifact(String, String, String, String, String, String) */ - public Artifact createArtifact( String groupId, String artifactId, String version ) - throws IOException - { - return createArtifact( groupId, artifactId, version, Artifact.SCOPE_COMPILE, "jar", "" ); + public Artifact createArtifact(String groupId, String artifactId, String version) throws IOException { + return createArtifact(groupId, artifactId, version, Artifact.SCOPE_COMPILE, "jar", ""); } /** @@ -116,10 +109,8 @@ public Artifact createArtifact( String groupId, String artifactId, String versio * @throws IOException if any * @see #createArtifact(String, String, String, String, String, String) */ - public Artifact createArtifact( String groupId, String artifactId, String version, String scope ) - throws IOException - { - return createArtifact( groupId, artifactId, version, scope, "jar", "" ); + public Artifact createArtifact(String groupId, String artifactId, String version, String scope) throws IOException { + return createArtifact(groupId, artifactId, version, scope, "jar", ""); } /** @@ -133,12 +124,11 @@ public Artifact createArtifact( String groupId, String artifactId, String versio * @throws IOException if any * @see #createArtifact(String, String, VersionRange, String, String, String, boolean) */ - public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type, - String classifier ) - throws IOException - { - VersionRange vr = VersionRange.createFromVersion( version ); - return createArtifact( groupId, artifactId, vr, scope, type, classifier, false ); + public Artifact createArtifact( + String groupId, String artifactId, String version, String scope, String type, String classifier) + throws IOException { + VersionRange vr = VersionRange.createFromVersion(version); + return createArtifact(groupId, artifactId, vr, scope, type, classifier, false); } /** @@ -152,21 +142,25 @@ public Artifact createArtifact( String groupId, String artifactId, String versio * @return a DefaultArtifact instance * @throws IOException if any */ - public Artifact createArtifact( String groupId, String artifactId, VersionRange versionRange, String scope, - String type, String classifier, boolean optional ) - throws IOException - { - ArtifactHandler ah = new DefaultArtifactHandlerStub( type, classifier ); + public Artifact createArtifact( + String groupId, + String artifactId, + VersionRange versionRange, + String scope, + String type, + String classifier, + boolean optional) + throws IOException { + ArtifactHandler ah = new DefaultArtifactHandlerStub(type, classifier); Artifact artifact = - new DefaultArtifact( groupId, artifactId, versionRange, scope, type, classifier, ah, optional ); + new DefaultArtifact(groupId, artifactId, versionRange, scope, type, classifier, ah, optional); // i have no idea why this needs to be done manually when isSnapshot is able to figure it out. - artifact.setRelease( !artifact.isSnapshot() ); + artifact.setRelease(!artifact.isSnapshot()); - if ( createFiles ) - { - setArtifactFile( artifact, this.workingDir, this.srcFile, this.createUnpackableFile ); + if (createFiles) { + setArtifactFile(artifact, this.workingDir, this.srcFile, this.createUnpackableFile); } return artifact; } @@ -178,10 +172,8 @@ public Artifact createArtifact( String groupId, String artifactId, VersionRange * @param workingDir where to locate the new file * @throws IOException */ - public void setArtifactFile( Artifact artifact, File workingDir ) - throws IOException - { - setArtifactFile( artifact, workingDir, null, false ); + public void setArtifactFile(Artifact artifact, File workingDir) throws IOException { + setArtifactFile(artifact, workingDir, null, false); } /** @@ -193,10 +185,8 @@ public void setArtifactFile( Artifact artifact, File workingDir ) * @param srcFile file to be attached. * @throws IOException */ - public void setArtifactFile( Artifact artifact, File workingDir, File srcFile ) - throws IOException - { - setArtifactFile( artifact, workingDir, srcFile, false ); + public void setArtifactFile(Artifact artifact, File workingDir, File srcFile) throws IOException { + setArtifactFile(artifact, workingDir, srcFile, false); } /** @@ -206,10 +196,8 @@ public void setArtifactFile( Artifact artifact, File workingDir, File srcFile ) * @param workingDir where to create the file. * @throws IOException */ - public void setUnpackableArtifactFile( Artifact artifact, File workingDir ) - throws IOException - { - setArtifactFile( artifact, workingDir, null, true ); + public void setUnpackableArtifactFile(Artifact artifact, File workingDir) throws IOException { + setArtifactFile(artifact, workingDir, null, true); } /** @@ -221,10 +209,8 @@ public void setUnpackableArtifactFile( Artifact artifact, File workingDir ) * @param srcFile * @throws IOException if any */ - public void setUnpackableArtifactFile( Artifact artifact, File workingDir, File srcFile ) - throws IOException - { - setArtifactFile( artifact, workingDir, srcFile, true ); + public void setUnpackableArtifactFile(Artifact artifact, File workingDir, File srcFile) throws IOException { + setArtifactFile(artifact, workingDir, srcFile, true); } /** @@ -236,55 +222,41 @@ public void setUnpackableArtifactFile( Artifact artifact, File workingDir, File * @param createUnpackableFile * @throws IOException if any */ - private void setArtifactFile( Artifact artifact, File workingDir, File srcFile, boolean createUnpackableFile ) - throws IOException - { - if ( workingDir == null ) - { - throw new IllegalArgumentException( - "The workingDir must be set." ); + private void setArtifactFile(Artifact artifact, File workingDir, File srcFile, boolean createUnpackableFile) + throws IOException { + if (workingDir == null) { + throw new IllegalArgumentException("The workingDir must be set."); } - String fileName = getFormattedFileName( artifact, false ); + String fileName = getFormattedFileName(artifact, false); - File theFile = new File( workingDir, fileName ); + File theFile = new File(workingDir, fileName); theFile.getParentFile().mkdirs(); - if ( srcFile == null ) - { + if (srcFile == null) { theFile.createNewFile(); - } - else if ( createUnpackableFile ) - { - try - { - createUnpackableFile( artifact, theFile ); - } - catch ( NoSuchArchiverException e ) - { - throw new IOException( "NoSuchArchiverException: " + e.getMessage() ); - } - catch ( ArchiverException e ) - { - throw new IOException( "ArchiverException: " + e.getMessage() ); + } else if (createUnpackableFile) { + try { + createUnpackableFile(artifact, theFile); + } catch (NoSuchArchiverException e) { + throw new IOException("NoSuchArchiverException: " + e.getMessage()); + } catch (ArchiverException e) { + throw new IOException("ArchiverException: " + e.getMessage()); } - } - else - { - FileUtils.copyFile( srcFile, theFile ); + } else { + FileUtils.copyFile(srcFile, theFile); } - artifact.setFile( theFile ); + artifact.setFile(theFile); } /** * @param artifact * @return */ - public static String getUnpackableFileName( Artifact artifact ) - { + public static String getUnpackableFileName(Artifact artifact) { return "" + artifact.getGroupId() + "-" + artifact.getArtifactId() + "-" + artifact.getVersion() + "-" - + artifact.getClassifier() + "-" + artifact.getType() + ".txt"; + + artifact.getClassifier() + "-" + artifact.getType() + ".txt"; } /** @@ -294,29 +266,24 @@ public static String getUnpackableFileName( Artifact artifact ) * @throws ArchiverException if any * @throws IOException if any */ - public void createUnpackableFile( Artifact artifact, File destFile ) - throws NoSuchArchiverException, ArchiverException, IOException - { - Archiver archiver = archiverManager.getArchiver( destFile ); + public void createUnpackableFile(Artifact artifact, File destFile) + throws NoSuchArchiverException, ArchiverException, IOException { + Archiver archiver = archiverManager.getArchiver(destFile); - archiver.setDestFile( destFile ); - archiver.addFile( srcFile, getUnpackableFileName( artifact ) ); + archiver.setDestFile(destFile); + archiver.addFile(srcFile, getUnpackableFileName(artifact)); - try - { - setVariableValueToObject( archiver, "logger", new SilentLog() ); - } - catch ( IllegalAccessException e ) - { - System.out.println( "Unable to override logger with silent log." ); + try { + setVariableValueToObject(archiver, "logger", new SilentLog()); + } catch (IllegalAccessException e) { + System.out.println("Unable to override logger with silent log."); e.printStackTrace(); } - if ( archiver instanceof WarArchiver ) - { + if (archiver instanceof WarArchiver) { WarArchiver war = (WarArchiver) archiver; // the use of this is counter-intuitive: // http://jira.codehaus.org/browse/PLX-286 - war.setIgnoreWebxml( false ); + war.setIgnoreWebxml(false); } archiver.createArchive(); } @@ -325,20 +292,16 @@ public void createUnpackableFile( Artifact artifact, File destFile ) * @return a DefaultArtifact instance for testGroupId:release:jar:1.0 * @throws IOException if any */ - public Artifact getReleaseArtifact() - throws IOException - { - return createArtifact( "testGroupId", "release", "1.0" ); + public Artifact getReleaseArtifact() throws IOException { + return createArtifact("testGroupId", "release", "1.0"); } /** * @return a default DefaultArtifact instance for testGroupId:snapshot:jar:2.0-SNAPSHOT * @throws IOException if any */ - public Artifact getSnapshotArtifact() - throws IOException - { - return createArtifact( "testGroupId", "snapshot", "2.0-SNAPSHOT" ); + public Artifact getSnapshotArtifact() throws IOException { + return createArtifact("testGroupId", "snapshot", "2.0-SNAPSHOT"); } /** @@ -348,12 +311,10 @@ public Artifact getSnapshotArtifact() * @see #getReleaseArtifact() * @see #getSnapshotArtifact() */ - public Set getReleaseAndSnapshotArtifacts() - throws IOException - { + public Set getReleaseAndSnapshotArtifacts() throws IOException { Set set = new HashSet<>(); - set.add( getReleaseArtifact() ); - set.add( getSnapshotArtifact() ); + set.add(getReleaseArtifact()); + set.add(getSnapshotArtifact()); return set; } @@ -362,15 +323,13 @@ public Set getReleaseAndSnapshotArtifacts() * g:provided:jar:1.0, g:compile:jar:1.0, g:system:jar:1.0, g:test:jar:1.0, g:runtime:jar:1.0 * @throws IOException if any */ - public Set getScopedArtifacts() - throws IOException - { + public Set getScopedArtifacts() throws IOException { Set set = new HashSet<>(); - set.add( createArtifact( "g", "compile", "1.0", Artifact.SCOPE_COMPILE ) ); - set.add( createArtifact( "g", "provided", "1.0", Artifact.SCOPE_PROVIDED ) ); - set.add( createArtifact( "g", "test", "1.0", Artifact.SCOPE_TEST ) ); - set.add( createArtifact( "g", "runtime", "1.0", Artifact.SCOPE_RUNTIME ) ); - set.add( createArtifact( "g", "system", "1.0", Artifact.SCOPE_SYSTEM ) ); + set.add(createArtifact("g", "compile", "1.0", Artifact.SCOPE_COMPILE)); + set.add(createArtifact("g", "provided", "1.0", Artifact.SCOPE_PROVIDED)); + set.add(createArtifact("g", "test", "1.0", Artifact.SCOPE_TEST)); + set.add(createArtifact("g", "runtime", "1.0", Artifact.SCOPE_RUNTIME)); + set.add(createArtifact("g", "system", "1.0", Artifact.SCOPE_SYSTEM)); return set; } @@ -379,15 +338,13 @@ public Set getScopedArtifacts() * g:d:zip:1.0, g:a:war:1.0, g:b:jar:1.0, g:c:sources:1.0, g:e:rar:1.0 * @throws IOException if any */ - public Set getTypedArtifacts() - throws IOException - { + public Set getTypedArtifacts() throws IOException { Set set = new HashSet<>(); - set.add( createArtifact( "g", "a", "1.0", Artifact.SCOPE_COMPILE, "war", null ) ); - set.add( createArtifact( "g", "b", "1.0", Artifact.SCOPE_COMPILE, "jar", null ) ); - set.add( createArtifact( "g", "c", "1.0", Artifact.SCOPE_COMPILE, "sources", null ) ); - set.add( createArtifact( "g", "d", "1.0", Artifact.SCOPE_COMPILE, "zip", null ) ); - set.add( createArtifact( "g", "e", "1.0", Artifact.SCOPE_COMPILE, "rar", null ) ); + set.add(createArtifact("g", "a", "1.0", Artifact.SCOPE_COMPILE, "war", null)); + set.add(createArtifact("g", "b", "1.0", Artifact.SCOPE_COMPILE, "jar", null)); + set.add(createArtifact("g", "c", "1.0", Artifact.SCOPE_COMPILE, "sources", null)); + set.add(createArtifact("g", "d", "1.0", Artifact.SCOPE_COMPILE, "zip", null)); + set.add(createArtifact("g", "e", "1.0", Artifact.SCOPE_COMPILE, "rar", null)); return set; } @@ -396,14 +353,12 @@ public Set getTypedArtifacts() * g:c:jar:three:1.0, g:b:jar:two:1.0, g:d:jar:four:1.0, g:a:jar:one:1.0 * @throws IOException if any */ - public Set getClassifiedArtifacts() - throws IOException - { + public Set getClassifiedArtifacts() throws IOException { Set set = new HashSet<>(); - set.add( createArtifact( "g", "a", "1.0", Artifact.SCOPE_COMPILE, "jar", "one" ) ); - set.add( createArtifact( "g", "b", "1.0", Artifact.SCOPE_COMPILE, "jar", "two" ) ); - set.add( createArtifact( "g", "c", "1.0", Artifact.SCOPE_COMPILE, "jar", "three" ) ); - set.add( createArtifact( "g", "d", "1.0", Artifact.SCOPE_COMPILE, "jar", "four" ) ); + set.add(createArtifact("g", "a", "1.0", Artifact.SCOPE_COMPILE, "jar", "one")); + set.add(createArtifact("g", "b", "1.0", Artifact.SCOPE_COMPILE, "jar", "two")); + set.add(createArtifact("g", "c", "1.0", Artifact.SCOPE_COMPILE, "jar", "three")); + set.add(createArtifact("g", "d", "1.0", Artifact.SCOPE_COMPILE, "jar", "four")); return set; } @@ -412,14 +367,12 @@ public Set getClassifiedArtifacts() * g:d:zip:1.0, g:a:war:1.0, g:b:jar:1.0, g:e:rar:1.0 * @throws IOException if any */ - public Set getTypedArchiveArtifacts() - throws IOException - { + public Set getTypedArchiveArtifacts() throws IOException { Set set = new HashSet<>(); - set.add( createArtifact( "g", "a", "1.0", Artifact.SCOPE_COMPILE, "war", null ) ); - set.add( createArtifact( "g", "b", "1.0", Artifact.SCOPE_COMPILE, "jar", null ) ); - set.add( createArtifact( "g", "d", "1.0", Artifact.SCOPE_COMPILE, "zip", null ) ); - set.add( createArtifact( "g", "e", "1.0", Artifact.SCOPE_COMPILE, "rar", null ) ); + set.add(createArtifact("g", "a", "1.0", Artifact.SCOPE_COMPILE, "war", null)); + set.add(createArtifact("g", "b", "1.0", Artifact.SCOPE_COMPILE, "jar", null)); + set.add(createArtifact("g", "d", "1.0", Artifact.SCOPE_COMPILE, "zip", null)); + set.add(createArtifact("g", "e", "1.0", Artifact.SCOPE_COMPILE, "rar", null)); return set; } @@ -428,14 +381,12 @@ public Set getTypedArchiveArtifacts() * g:one:jar:a:1.0, g:two:jar:a:1.0, g:four:jar:a:1.0, g:three:jar:a:1.0 * @throws IOException if any */ - public Set getArtifactArtifacts() - throws IOException - { + public Set getArtifactArtifacts() throws IOException { Set set = new HashSet<>(); - set.add( createArtifact( "g", "one", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) ); - set.add( createArtifact( "g", "two", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) ); - set.add( createArtifact( "g", "three", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) ); - set.add( createArtifact( "g", "four", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) ); + set.add(createArtifact("g", "one", "1.0", Artifact.SCOPE_COMPILE, "jar", "a")); + set.add(createArtifact("g", "two", "1.0", Artifact.SCOPE_COMPILE, "jar", "a")); + set.add(createArtifact("g", "three", "1.0", Artifact.SCOPE_COMPILE, "jar", "a")); + set.add(createArtifact("g", "four", "1.0", Artifact.SCOPE_COMPILE, "jar", "a")); return set; } @@ -445,14 +396,12 @@ public Set getArtifactArtifacts() * two:group-two:jar:a:1.0 * @throws IOException if any */ - public Set getGroupIdArtifacts() - throws IOException - { + public Set getGroupIdArtifacts() throws IOException { Set set = new HashSet<>(); - set.add( createArtifact( "one", "group-one", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) ); - set.add( createArtifact( "two", "group-two", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) ); - set.add( createArtifact( "three", "group-three", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) ); - set.add( createArtifact( "four", "group-four", "1.0", Artifact.SCOPE_COMPILE, "jar", "a" ) ); + set.add(createArtifact("one", "group-one", "1.0", Artifact.SCOPE_COMPILE, "jar", "a")); + set.add(createArtifact("two", "group-two", "1.0", Artifact.SCOPE_COMPILE, "jar", "a")); + set.add(createArtifact("three", "group-three", "1.0", Artifact.SCOPE_COMPILE, "jar", "a")); + set.add(createArtifact("four", "group-four", "1.0", Artifact.SCOPE_COMPILE, "jar", "a")); return set; } @@ -463,61 +412,53 @@ public Set getGroupIdArtifacts() * @see #getScopedArtifacts() * @see #getReleaseAndSnapshotArtifacts() */ - public Set getMixedArtifacts() - throws IOException - { + public Set getMixedArtifacts() throws IOException { Set set = new HashSet<>(); - set.addAll( getTypedArtifacts() ); - set.addAll( getScopedArtifacts() ); - set.addAll( getReleaseAndSnapshotArtifacts() ); + set.addAll(getTypedArtifacts()); + set.addAll(getScopedArtifacts()); + set.addAll(getReleaseAndSnapshotArtifacts()); return set; } /** * @return Returns the createFiles. */ - public boolean isCreateFiles() - { + public boolean isCreateFiles() { return this.createFiles; } /** * @param createFiles The createFiles to set. */ - public void setCreateFiles( boolean createFiles ) - { + public void setCreateFiles(boolean createFiles) { this.createFiles = createFiles; } /** * @return Returns the workingDir. */ - public File getWorkingDir() - { + public File getWorkingDir() { return this.workingDir; } /** * @param workingDir The workingDir to set. */ - public void setWorkingDir( File workingDir ) - { + public void setWorkingDir(File workingDir) { this.workingDir = workingDir; } /** * @return Returns the srcFile. */ - public File getSrcFile() - { + public File getSrcFile() { return this.srcFile; } /** * @param srcFile The srcFile to set. */ - public void setSrcFile( File srcFile ) - { + public void setSrcFile(File srcFile) { this.srcFile = srcFile; } @@ -529,14 +470,13 @@ public void setSrcFile( File srcFile ) * @param value * @throws IllegalAccessException */ - public static void setVariableValueToObject( Object object, String variable, Object value ) - throws IllegalAccessException - { - Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses( variable, object.getClass() ); + public static void setVariableValueToObject(Object object, String variable, Object value) + throws IllegalAccessException { + Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses(variable, object.getClass()); - field.setAccessible( true ); + field.setAccessible(true); - field.set( object, value ); + field.set(object, value); } /** @@ -547,40 +487,32 @@ public static void setVariableValueToObject( Object object, String variable, Obj * @param removeVersion Specifies if the version should be removed from the file name. * @return Formatted file name in the format artifactId-[version]-[classifier].[type] */ - public static String getFormattedFileName( Artifact artifact, boolean removeVersion ) - { + public static String getFormattedFileName(Artifact artifact, boolean removeVersion) { String destFileName = null; // if there is a file and we aren't stripping the version, just get the // name directly - if ( artifact.getFile() != null && !removeVersion ) - { + if (artifact.getFile() != null && !removeVersion) { destFileName = artifact.getFile().getName(); - } - else + } else // if offline { String versionString = null; - if ( !removeVersion ) - { + if (!removeVersion) { versionString = "-" + artifact.getVersion(); - } - else - { + } else { versionString = ""; } String classifierString = ""; - if ( StringUtils.isNotEmpty( artifact.getClassifier() ) ) - { + if (StringUtils.isNotEmpty(artifact.getClassifier())) { classifierString = "-" + artifact.getClassifier(); } destFileName = artifact.getArtifactId() + versionString + classifierString + "." - + artifact.getArtifactHandler().getExtension(); + + artifact.getArtifactHandler().getExtension(); } return destFileName; } - } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ConfigurationException.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ConfigurationException.java index 6b9c11fb..9b8150cf 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ConfigurationException.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ConfigurationException.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,40 +16,36 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; /** * ConfigurationException * * @author jesse */ -public class ConfigurationException - extends Exception -{ +public class ConfigurationException extends Exception { /** serialVersionUID */ static final long serialVersionUID = -6180939638742159065L; /** * @param message The detailed message. */ - public ConfigurationException( String message ) - { - super( message ); + public ConfigurationException(String message) { + super(message); } /** * @param cause The detailed cause. */ - public ConfigurationException( Throwable cause ) - { - super( cause ); + public ConfigurationException(Throwable cause) { + super(cause); } /** * @param message The detailed message. * @param cause The detailed cause. */ - public ConfigurationException( String message, Throwable cause ) - { - super( message, cause ); + public ConfigurationException(String message, Throwable cause) { + super(message, cause); } } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoLogWrapper.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoLogWrapper.java index 6fb4f247..869525c3 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoLogWrapper.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoLogWrapper.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 + * 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 @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; import org.apache.maven.plugin.logging.Log; import org.slf4j.Logger; @@ -27,120 +26,97 @@ /** * @author jdcasey */ -public class MojoLogWrapper - implements Log -{ +public class MojoLogWrapper implements Log { private final Logger logger; - public MojoLogWrapper( Logger logger ) - { - this.logger = requireNonNull( logger ); + public MojoLogWrapper(Logger logger) { + this.logger = requireNonNull(logger); } - public void debug( CharSequence content ) - { - logger.debug( toString( content ) ); + public void debug(CharSequence content) { + logger.debug(toString(content)); } - private String toString( CharSequence content ) - { - if ( content == null ) - { + private String toString(CharSequence content) { + if (content == null) { return ""; - } - else - { + } else { return content.toString(); } } @Override - public void debug( CharSequence content, Throwable error ) - { - logger.debug( toString( content ), error ); + public void debug(CharSequence content, Throwable error) { + logger.debug(toString(content), error); } @Override - public void debug( Throwable error ) - { - logger.debug( "", error ); + public void debug(Throwable error) { + logger.debug("", error); } @Override - public void info( CharSequence content ) - { - logger.info( toString( content ) ); + public void info(CharSequence content) { + logger.info(toString(content)); } @Override - public void info( CharSequence content, Throwable error ) - { - logger.info( toString( content ), error ); + public void info(CharSequence content, Throwable error) { + logger.info(toString(content), error); } @Override - public void info( Throwable error ) - { - logger.info( "", error ); + public void info(Throwable error) { + logger.info("", error); } @Override - public void warn( CharSequence content ) - { - logger.warn( toString( content ) ); + public void warn(CharSequence content) { + logger.warn(toString(content)); } @Override - public void warn( CharSequence content, Throwable error ) - { - logger.warn( toString( content ), error ); + public void warn(CharSequence content, Throwable error) { + logger.warn(toString(content), error); } @Override - public void warn( Throwable error ) - { - logger.warn( "", error ); + public void warn(Throwable error) { + logger.warn("", error); } @Override - public void error( CharSequence content ) - { - logger.error( toString( content ) ); + public void error(CharSequence content) { + logger.error(toString(content)); } @Override - public void error( CharSequence content, Throwable error ) - { - logger.error( toString( content ), error ); + public void error(CharSequence content, Throwable error) { + logger.error(toString(content), error); } @Override - public void error( Throwable error ) - { - logger.error( "", error ); + public void error(Throwable error) { + logger.error("", error); } @Override - public boolean isDebugEnabled() - { + public boolean isDebugEnabled() { return logger.isDebugEnabled(); } @Override - public boolean isInfoEnabled() - { + public boolean isInfoEnabled() { return logger.isInfoEnabled(); } @Override - public boolean isWarnEnabled() - { + public boolean isWarnEnabled() { return logger.isWarnEnabled(); } @Override - public boolean isErrorEnabled() - { + public boolean isErrorEnabled() { return logger.isErrorEnabled(); } } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoParameters.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoParameters.java index 2ac2e14c..842fba63 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoParameters.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoParameters.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,20 +16,19 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; import org.codehaus.plexus.util.xml.Xpp3Dom; /** * Static helpers to create and manipulate mojo execution configuration parameters - * + * * @since 3.2.0 */ -public class MojoParameters -{ - public static Xpp3Dom newParameter( String name, String value ) - { - Xpp3Dom child = new Xpp3Dom( name ); - child.setValue( value ); +public class MojoParameters { + public static Xpp3Dom newParameter(String name, String value) { + Xpp3Dom child = new Xpp3Dom(name); + child.setValue(value); return child; } } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java index b430bd83..878d7505 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; import java.io.File; import java.io.InputStream; @@ -49,7 +48,7 @@ import org.junit.runners.model.Statement; /** - * {@link TestRule} for usage with Junit-4.10ff. This is just a wrapper for an embedded + * {@link TestRule} for usage with Junit-4.10ff. This is just a wrapper for an embedded * {@link AbstractMojoTestCase}, so all {@code protected} methods of the TestCase are * exhibited as {@code public} in the rule. You may annotate single tests methods with * {@link WithoutMojo} to prevent the rule from firing. @@ -57,73 +56,54 @@ * @author Mirko Friedenhagen * @since 2.2 */ -public class MojoRule - implements TestRule -{ +public class MojoRule implements TestRule { private final AbstractMojoTestCase testCase; - - public MojoRule() - { - this( new AbstractMojoTestCase() - { - } ); + + public MojoRule() { + this(new AbstractMojoTestCase() {}); } - public MojoRule( AbstractMojoTestCase testCase ) - { + public MojoRule(AbstractMojoTestCase testCase) { this.testCase = testCase; } /** - * May be overridden in the implementation to do stuff after the embedded test case + * May be overridden in the implementation to do stuff after the embedded test case * is set up but before the current test is actually run. * * @throws Throwable */ - protected void before() throws Throwable - { - - } - + protected void before() throws Throwable {} + /** * May be overridden in the implementation to do stuff after the current test was run. */ - protected void after() - { - - } + protected void after() {} - public InputStream getPublicDescriptorStream() - throws Exception - { + public InputStream getPublicDescriptorStream() throws Exception { return testCase.getPublicDescriptorStream(); } - public String getPluginDescriptorPath() - { + public String getPluginDescriptorPath() { return testCase.getPluginDescriptorPath(); } - public String getPluginDescriptorLocation() - { + public String getPluginDescriptorLocation() { return testCase.getPluginDescriptorLocation(); } - public void setupContainer() - { + public void setupContainer() { testCase.setupContainer(); } - public ContainerConfiguration setupContainerConfiguration() - { + public ContainerConfiguration setupContainerConfiguration() { return testCase.setupContainerConfiguration(); } - - public PlexusContainer getContainer() - { + + public PlexusContainer getContainer() { return testCase.getContainer(); - } - + } + /** * Lookup the mojo leveraging the subproject pom * @@ -132,10 +112,8 @@ public PlexusContainer getContainer() * @return a Mojo instance * @throws Exception */ - public T lookupMojo( String goal, String pluginPom ) - throws Exception - { - return testCase.lookupMojo( goal, pluginPom ); + public T lookupMojo(String goal, String pluginPom) throws Exception { + return testCase.lookupMojo(goal, pluginPom); } /** @@ -146,10 +124,8 @@ public T lookupMojo( String goal, String pluginPom ) * @return a Mojo instance * @throws Exception */ - public T lookupEmptyMojo( String goal, String pluginPom ) - throws Exception - { - return testCase.lookupEmptyMojo( goal, new File( pluginPom ) ); + public T lookupEmptyMojo(String goal, String pluginPom) throws Exception { + return testCase.lookupEmptyMojo(goal, new File(pluginPom)); } /** @@ -160,10 +136,8 @@ public T lookupEmptyMojo( String goal, String pluginPom ) * @return a Mojo instance * @throws Exception */ - public T lookupMojo( String goal, File pom ) - throws Exception - { - return testCase.lookupMojo( goal, pom ); + public T lookupMojo(String goal, File pom) throws Exception { + return testCase.lookupMojo(goal, pom); } /** @@ -174,63 +148,47 @@ public T lookupMojo( String goal, File pom ) * @return a Mojo instance * @throws Exception */ - public T lookupEmptyMojo( String goal, File pom ) - throws Exception - { - return testCase.lookupEmptyMojo( goal, pom ); + public T lookupEmptyMojo(String goal, File pom) throws Exception { + return testCase.lookupEmptyMojo(goal, pom); } - public T lookupMojo( String groupId, String artifactId, String version, String goal, - PlexusConfiguration pluginConfiguration ) - throws Exception - { - return testCase.lookupMojo( groupId, artifactId, version, goal, pluginConfiguration ); + public T lookupMojo( + String groupId, String artifactId, String version, String goal, PlexusConfiguration pluginConfiguration) + throws Exception { + return testCase.lookupMojo(groupId, artifactId, version, goal, pluginConfiguration); } - public T lookupConfiguredMojo( MavenProject project, String goal ) - throws Exception - { - return testCase.lookupConfiguredMojo( project, goal ); + public T lookupConfiguredMojo(MavenProject project, String goal) throws Exception { + return testCase.lookupConfiguredMojo(project, goal); } - public T lookupConfiguredMojo( MavenSession session, MojoExecution execution ) - throws Exception, ComponentConfigurationException - { - return testCase.lookupConfiguredMojo( session, execution ); + public T lookupConfiguredMojo(MavenSession session, MojoExecution execution) + throws Exception, ComponentConfigurationException { + return testCase.lookupConfiguredMojo(session, execution); } - public MavenSession newMavenSession( MavenProject project ) - { - return testCase.newMavenSession( project ); + public MavenSession newMavenSession(MavenProject project) { + return testCase.newMavenSession(project); } - public MojoExecution newMojoExecution( String goal ) - { - return testCase.newMojoExecution( goal ); + public MojoExecution newMojoExecution(String goal) { + return testCase.newMojoExecution(goal); } - public PlexusConfiguration extractPluginConfiguration( String artifactId, File pom ) - throws Exception - { - return testCase.extractPluginConfiguration( artifactId, pom ); + public PlexusConfiguration extractPluginConfiguration(String artifactId, File pom) throws Exception { + return testCase.extractPluginConfiguration(artifactId, pom); } - public PlexusConfiguration extractPluginConfiguration( String artifactId, Xpp3Dom pomDom ) - throws Exception - { - return testCase.extractPluginConfiguration( artifactId, pomDom ); + public PlexusConfiguration extractPluginConfiguration(String artifactId, Xpp3Dom pomDom) throws Exception { + return testCase.extractPluginConfiguration(artifactId, pomDom); } - public T configureMojo( T mojo, String artifactId, File pom ) - throws Exception - { - return testCase.configureMojo( mojo, artifactId, pom ); + public T configureMojo(T mojo, String artifactId, File pom) throws Exception { + return testCase.configureMojo(mojo, artifactId, pom); } - public T configureMojo( T mojo, PlexusConfiguration pluginConfiguration ) - throws Exception - { - return testCase.configureMojo( mojo, pluginConfiguration ); + public T configureMojo(T mojo, PlexusConfiguration pluginConfiguration) throws Exception { + return testCase.configureMojo(mojo, pluginConfiguration); } /** @@ -243,10 +201,8 @@ public T configureMojo( T mojo, PlexusConfiguration pluginConfi * @return object value of variable * @throws IllegalArgumentException */ - public T getVariableValueFromObject( Object object, String variable ) - throws IllegalAccessException - { - return testCase.getVariableValueFromObject( object, variable ); + public T getVariableValueFromObject(Object object, String variable) throws IllegalAccessException { + return testCase.getVariableValueFromObject(object, variable); } /** @@ -257,10 +213,8 @@ public T getVariableValueFromObject( Object object, String variable ) * @param object * @return map of variable names and values */ - public Map getVariablesAndValuesFromObject( Object object ) - throws IllegalAccessException - { - return testCase.getVariablesAndValuesFromObject( object ); + public Map getVariablesAndValuesFromObject(Object object) throws IllegalAccessException { + return testCase.getVariablesAndValuesFromObject(object); } /** @@ -272,10 +226,9 @@ public Map getVariablesAndValuesFromObject( Object object ) * @param object * @return map of variable names and values */ - public Map getVariablesAndValuesFromObject( Class clazz, Object object ) - throws IllegalAccessException - { - return testCase.getVariablesAndValuesFromObject( clazz, object ); + public Map getVariablesAndValuesFromObject(Class clazz, Object object) + throws IllegalAccessException { + return testCase.getVariablesAndValuesFromObject(clazz, object); } /** @@ -286,33 +239,24 @@ public Map getVariablesAndValuesFromObject( Class clazz, Obje * @param value * @throws IllegalAccessException */ - public void setVariableValueToObject( Object object, String variable, T value ) - throws IllegalAccessException - { - testCase.setVariableValueToObject( object, variable, value ); + public void setVariableValueToObject(Object object, String variable, T value) throws IllegalAccessException { + testCase.setVariableValueToObject(object, variable, value); } @Override - public Statement apply( final Statement base, Description description ) - { - if ( description.getAnnotation( WithoutMojo.class ) != null ) // skip. + public Statement apply(final Statement base, Description description) { + if (description.getAnnotation(WithoutMojo.class) != null) // skip. { return base; } - return new Statement() - { + return new Statement() { @Override - public void evaluate() - throws Throwable - { + public void evaluate() throws Throwable { testCase.setUp(); before(); - try - { + try { base.evaluate(); - } - finally - { + } finally { after(); } } @@ -322,119 +266,98 @@ public void evaluate() /** * @since 3.1.0 */ - public MavenProject readMavenProject( File basedir ) - throws Exception - { - File pom = new File( basedir, "pom.xml" ); + public MavenProject readMavenProject(File basedir) throws Exception { + File pom = new File(basedir, "pom.xml"); MavenExecutionRequest request = new DefaultMavenExecutionRequest(); - request.setBaseDirectory( basedir ); + request.setBaseDirectory(basedir); ProjectBuildingRequest configuration = request.getProjectBuildingRequest(); - configuration.setRepositorySession( new DefaultRepositorySystemSession() ); - MavenProject project = lookup( ProjectBuilder.class ).build( pom, configuration ).getProject(); - Assert.assertNotNull( project ); + configuration.setRepositorySession(new DefaultRepositorySystemSession()); + MavenProject project = + lookup(ProjectBuilder.class).build(pom, configuration).getProject(); + Assert.assertNotNull(project); return project; } /** * @since 3.1.0 */ - public void executeMojo( File basedir, String goal ) - throws Exception - { - MavenProject project = readMavenProject( basedir ); - MavenSession session = newMavenSession( project ); - MojoExecution execution = newMojoExecution( goal ); - executeMojo( session, project, execution ); + public void executeMojo(File basedir, String goal) throws Exception { + MavenProject project = readMavenProject(basedir); + MavenSession session = newMavenSession(project); + MojoExecution execution = newMojoExecution(goal); + executeMojo(session, project, execution); } /** * @since 3.1.0 */ - public T lookupConfiguredMojo( File basedir, String goal ) - throws Exception, ComponentConfigurationException - { - MavenProject project = readMavenProject( basedir ); - MavenSession session = newMavenSession( project ); - MojoExecution execution = newMojoExecution( goal ); - return lookupConfiguredMojo( session, execution ); + public T lookupConfiguredMojo(File basedir, String goal) + throws Exception, ComponentConfigurationException { + MavenProject project = readMavenProject(basedir); + MavenSession session = newMavenSession(project); + MojoExecution execution = newMojoExecution(goal); + return lookupConfiguredMojo(session, execution); } /** * @since 3.1.0 */ - public final T lookup( final Class role ) - throws ComponentLookupException - { - return getContainer().lookup( role ); + public final T lookup(final Class role) throws ComponentLookupException { + return getContainer().lookup(role); } /** * @since 3.2.0 */ - public void executeMojo( MavenProject project, String goal, Xpp3Dom... parameters ) - throws Exception - { - MavenSession session = newMavenSession( project ); - executeMojo( session, project, goal, parameters ); + public void executeMojo(MavenProject project, String goal, Xpp3Dom... parameters) throws Exception { + MavenSession session = newMavenSession(project); + executeMojo(session, project, goal, parameters); } /** * @since 3.2.0 */ - public void executeMojo( MavenSession session, MavenProject project, String goal, Xpp3Dom... parameters ) - throws Exception - { - MojoExecution execution = newMojoExecution( goal ); - if ( parameters != null ) - { + public void executeMojo(MavenSession session, MavenProject project, String goal, Xpp3Dom... parameters) + throws Exception { + MojoExecution execution = newMojoExecution(goal); + if (parameters != null) { Xpp3Dom configuration = execution.getConfiguration(); - for ( Xpp3Dom parameter : parameters ) - { - configuration.addChild( parameter ); + for (Xpp3Dom parameter : parameters) { + configuration.addChild(parameter); } } - executeMojo( session, project, execution ); + executeMojo(session, project, execution); } /** * @since 3.2.0 */ - public void executeMojo( MavenSession session, MavenProject project, MojoExecution execution ) - throws Exception - { - SessionScope sessionScope = lookup( SessionScope.class ); - try - { + public void executeMojo(MavenSession session, MavenProject project, MojoExecution execution) throws Exception { + SessionScope sessionScope = lookup(SessionScope.class); + try { sessionScope.enter(); - sessionScope.seed( MavenSession.class, session ); - sessionScope.seed( Session.class, session.getSession() ); + sessionScope.seed(MavenSession.class, session); + sessionScope.seed(Session.class, session.getSession()); - MojoExecutionScope executionScope = lookup( MojoExecutionScope.class ); - try - { + MojoExecutionScope executionScope = lookup(MojoExecutionScope.class); + try { executionScope.enter(); - executionScope.seed( MavenProject.class, project ); - executionScope.seed( MojoExecution.class, execution ); + executionScope.seed(MavenProject.class, project); + executionScope.seed(MojoExecution.class, execution); - Mojo mojo = lookupConfiguredMojo( session, execution ); + Mojo mojo = lookupConfiguredMojo(session, execution); mojo.execute(); - MojoExecutionEvent event = new MojoExecutionEvent( session, project, execution, mojo ); - for ( MojoExecutionListener listener : getContainer().lookupList( MojoExecutionListener.class ) ) - { - listener.afterMojoExecutionSuccess( event ); + MojoExecutionEvent event = new MojoExecutionEvent(session, project, execution, mojo); + for (MojoExecutionListener listener : getContainer().lookupList(MojoExecutionListener.class)) { + listener.afterMojoExecutionSuccess(event); } - } - finally - { + } finally { executionScope.exit(); } - } - finally - { + } finally { sessionScope.exit(); } } - } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ResolverExpressionEvaluatorStub.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ResolverExpressionEvaluatorStub.java index 3fed91fe..f4af2e77 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ResolverExpressionEvaluatorStub.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ResolverExpressionEvaluatorStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; import java.io.File; @@ -32,90 +31,70 @@ * * @author jesse */ -public class ResolverExpressionEvaluatorStub - implements ExpressionEvaluator -{ +public class ResolverExpressionEvaluatorStub implements ExpressionEvaluator { /** {@inheritDoc} */ @Override - public Object evaluate( String expr ) - throws ExpressionEvaluationException - { + public Object evaluate(String expr) throws ExpressionEvaluationException { Object value = null; - if ( expr == null ) - { + if (expr == null) { return null; } - String expression = stripTokens( expr ); + String expression = stripTokens(expr); - if ( expression.equals( expr ) ) - { - int index = expr.indexOf( "${" ); - if ( index >= 0 ) - { - int lastIndex = expr.indexOf( "}", index ); - if ( lastIndex >= 0 ) - { - String retVal = expr.substring( 0, index ); + if (expression.equals(expr)) { + int index = expr.indexOf("${"); + if (index >= 0) { + int lastIndex = expr.indexOf("}", index); + if (lastIndex >= 0) { + String retVal = expr.substring(0, index); - if ( index > 0 && expr.charAt( index - 1 ) == '$' ) - { - retVal += expr.substring( index + 1, lastIndex + 1 ); - } - else - { - retVal += evaluate( expr.substring( index, lastIndex + 1 ) ); + if (index > 0 && expr.charAt(index - 1) == '$') { + retVal += expr.substring(index + 1, lastIndex + 1); + } else { + retVal += evaluate(expr.substring(index, lastIndex + 1)); } - retVal += evaluate( expr.substring( lastIndex + 1 ) ); + retVal += evaluate(expr.substring(lastIndex + 1)); return retVal; } } // Was not an expression - if ( expression.indexOf( "$$" ) > -1 ) - { - return expression.replaceAll( "\\$\\$", "\\$" ); + if (expression.indexOf("$$") > -1) { + return expression.replaceAll("\\$\\$", "\\$"); } } - if ( "basedir".equals( expression ) || "project.basedir".equals( expression ) ) - { + if ("basedir".equals(expression) || "project.basedir".equals(expression)) { return PlexusTestCase.getBasedir(); - } - else if ( expression.startsWith( "basedir" ) || expression.startsWith( "project.basedir" ) ) - { - int pathSeparator = expression.indexOf( "/" ); + } else if (expression.startsWith("basedir") || expression.startsWith("project.basedir")) { + int pathSeparator = expression.indexOf("/"); - if ( pathSeparator > 0 ) - { - value = PlexusTestCase.getBasedir() + expression.substring( pathSeparator ); - } - else - { - System.out.println( "Got expression '" + expression + "' that was not recognised" ); + if (pathSeparator > 0) { + value = PlexusTestCase.getBasedir() + expression.substring(pathSeparator); + } else { + System.out.println("Got expression '" + expression + "' that was not recognised"); } return value; - } - else if ( "localRepository".equals( expression ) ) - { - File localRepo = new File( PlexusTestCase.getBasedir(), "target/local-repo" ); - return new MavenArtifactRepository( "localRepository", "file://" + localRepo.getAbsolutePath(), - new DefaultRepositoryLayout(), null, null ); - } - else - { + } else if ("localRepository".equals(expression)) { + File localRepo = new File(PlexusTestCase.getBasedir(), "target/local-repo"); + return new MavenArtifactRepository( + "localRepository", + "file://" + localRepo.getAbsolutePath(), + new DefaultRepositoryLayout(), + null, + null); + } else { return expr; } } - private String stripTokens( String expr ) - { - if ( expr.startsWith( "${" ) && expr.indexOf( "}" ) == expr.length() - 1 ) - { - expr = expr.substring( 2, expr.length() - 1 ); + private String stripTokens(String expr) { + if (expr.startsWith("${") && expr.indexOf("}") == expr.length() - 1) { + expr = expr.substring(2, expr.length() - 1); } return expr; @@ -123,19 +102,13 @@ private String stripTokens( String expr ) /** {@inheritDoc} */ @Override - public File alignToBaseDirectory( File file ) - { - if ( file.getAbsolutePath().startsWith( PlexusTestCase.getBasedir() ) ) - { + public File alignToBaseDirectory(File file) { + if (file.getAbsolutePath().startsWith(PlexusTestCase.getBasedir())) { return file; - } - else if ( file.isAbsolute() ) - { + } else if (file.isAbsolute()) { return file; - } - else - { - return new File( PlexusTestCase.getBasedir(), file.getPath() ); + } else { + return new File(PlexusTestCase.getBasedir(), file.getPath()); } } } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/SilentLog.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/SilentLog.java index a44120a0..e94d81b9 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/SilentLog.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/SilentLog.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 + * 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 @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; import org.apache.maven.plugin.logging.Log; import org.codehaus.plexus.logging.Logger; @@ -28,16 +27,13 @@ * * @author Brian Fox */ -public class SilentLog - implements Log, Logger -{ +public class SilentLog implements Log, Logger { /** * @return false * @see org.apache.maven.plugin.logging.Log#isDebugEnabled() */ @Override - public boolean isDebugEnabled() - { + public boolean isDebugEnabled() { return false; } @@ -47,8 +43,7 @@ public boolean isDebugEnabled() * @see org.apache.maven.plugin.logging.Log#debug(java.lang.CharSequence) */ @Override - public void debug( CharSequence content ) - { + public void debug(CharSequence content) { // nop } @@ -58,8 +53,7 @@ public void debug( CharSequence content ) * @see org.apache.maven.plugin.logging.Log#debug(java.lang.CharSequence, java.lang.Throwable) */ @Override - public void debug( CharSequence content, Throwable error ) - { + public void debug(CharSequence content, Throwable error) { // nop } @@ -69,8 +63,7 @@ public void debug( CharSequence content, Throwable error ) * @see org.apache.maven.plugin.logging.Log#debug(java.lang.Throwable) */ @Override - public void debug( Throwable error ) - { + public void debug(Throwable error) { // nop } @@ -79,8 +72,7 @@ public void debug( Throwable error ) * @see org.apache.maven.plugin.logging.Log#isInfoEnabled() */ @Override - public boolean isInfoEnabled() - { + public boolean isInfoEnabled() { return false; } @@ -90,8 +82,7 @@ public boolean isInfoEnabled() * @see org.apache.maven.plugin.logging.Log#info(java.lang.CharSequence) */ @Override - public void info( CharSequence content ) - { + public void info(CharSequence content) { // nop } @@ -101,8 +92,7 @@ public void info( CharSequence content ) * @see org.apache.maven.plugin.logging.Log#info(java.lang.CharSequence, java.lang.Throwable) */ @Override - public void info( CharSequence content, Throwable error ) - { + public void info(CharSequence content, Throwable error) { // nop } @@ -112,8 +102,7 @@ public void info( CharSequence content, Throwable error ) * @see org.apache.maven.plugin.logging.Log#info(java.lang.Throwable) */ @Override - public void info( Throwable error ) - { + public void info(Throwable error) { // nop } @@ -123,8 +112,7 @@ public void info( Throwable error ) * @see org.apache.maven.plugin.logging.Log#isWarnEnabled() */ @Override - public boolean isWarnEnabled() - { + public boolean isWarnEnabled() { // nop return false; } @@ -135,8 +123,7 @@ public boolean isWarnEnabled() * @see org.apache.maven.plugin.logging.Log#warn(java.lang.CharSequence) */ @Override - public void warn( CharSequence content ) - { + public void warn(CharSequence content) { // nop } @@ -146,8 +133,7 @@ public void warn( CharSequence content ) * @see org.apache.maven.plugin.logging.Log#warn(java.lang.CharSequence, java.lang.Throwable) */ @Override - public void warn( CharSequence content, Throwable error ) - { + public void warn(CharSequence content, Throwable error) { // nop } @@ -157,8 +143,7 @@ public void warn( CharSequence content, Throwable error ) * @see org.apache.maven.plugin.logging.Log#warn(java.lang.Throwable) */ @Override - public void warn( Throwable error ) - { + public void warn(Throwable error) { // nop } @@ -167,8 +152,7 @@ public void warn( Throwable error ) * @see org.apache.maven.plugin.logging.Log#isErrorEnabled() */ @Override - public boolean isErrorEnabled() - { + public boolean isErrorEnabled() { return false; } @@ -178,8 +162,7 @@ public boolean isErrorEnabled() * @see org.apache.maven.plugin.logging.Log#error(java.lang.CharSequence) */ @Override - public void error( CharSequence content ) - { + public void error(CharSequence content) { // nop } @@ -189,8 +172,7 @@ public void error( CharSequence content ) * @see org.apache.maven.plugin.logging.Log#error(java.lang.CharSequence, java.lang.Throwable) */ @Override - public void error( CharSequence content, Throwable error ) - { + public void error(CharSequence content, Throwable error) { // nop } @@ -200,8 +182,7 @@ public void error( CharSequence content, Throwable error ) * @see org.apache.maven.plugin.logging.Log#error(java.lang.Throwable) */ @Override - public void error( Throwable error ) - { + public void error(Throwable error) { // nop } @@ -211,8 +192,7 @@ public void error( Throwable error ) * @see org.codehaus.plexus.logging.Logger#debug(java.lang.String) */ @Override - public void debug( String message ) - { + public void debug(String message) { // nop } @@ -222,8 +202,7 @@ public void debug( String message ) * @see org.codehaus.plexus.logging.Logger#debug(java.lang.String, java.lang.Throwable) */ @Override - public void debug( String message, Throwable throwable ) - { + public void debug(String message, Throwable throwable) { // nop } @@ -233,8 +212,7 @@ public void debug( String message, Throwable throwable ) * @see org.codehaus.plexus.logging.Logger#info(java.lang.String) */ @Override - public void info( String message ) - { + public void info(String message) { // nop } @@ -244,8 +222,7 @@ public void info( String message ) * @see org.codehaus.plexus.logging.Logger#info(java.lang.String, java.lang.Throwable) */ @Override - public void info( String message, Throwable throwable ) - { + public void info(String message, Throwable throwable) { // nop } @@ -255,8 +232,7 @@ public void info( String message, Throwable throwable ) * @see org.codehaus.plexus.logging.Logger#warn(java.lang.String) */ @Override - public void warn( String message ) - { + public void warn(String message) { // nop } @@ -266,8 +242,7 @@ public void warn( String message ) * @see org.codehaus.plexus.logging.Logger#warn(java.lang.String, java.lang.Throwable) */ @Override - public void warn( String message, Throwable throwable ) - { + public void warn(String message, Throwable throwable) { // nop } @@ -277,8 +252,7 @@ public void warn( String message, Throwable throwable ) * @see org.codehaus.plexus.logging.Logger#error(java.lang.String) */ @Override - public void error( String message ) - { + public void error(String message) { // nop } @@ -288,8 +262,7 @@ public void error( String message ) * @see org.codehaus.plexus.logging.Logger#error(java.lang.String, java.lang.Throwable) */ @Override - public void error( String message, Throwable throwable ) - { + public void error(String message, Throwable throwable) { // nop } @@ -299,8 +272,7 @@ public void error( String message, Throwable throwable ) * @see org.codehaus.plexus.logging.Logger#fatalError(java.lang.String) */ @Override - public void fatalError( String message ) - { + public void fatalError(String message) { // nop } @@ -310,8 +282,7 @@ public void fatalError( String message ) * @see org.codehaus.plexus.logging.Logger#fatalError(java.lang.String, java.lang.Throwable) */ @Override - public void fatalError( String message, Throwable throwable ) - { + public void fatalError(String message, Throwable throwable) { // nop } @@ -320,8 +291,7 @@ public void fatalError( String message, Throwable throwable ) * @see org.codehaus.plexus.logging.Logger#isFatalErrorEnabled() */ @Override - public boolean isFatalErrorEnabled() - { + public boolean isFatalErrorEnabled() { return false; } @@ -330,8 +300,7 @@ public boolean isFatalErrorEnabled() * @see org.codehaus.plexus.logging.Logger#getChildLogger(java.lang.String) */ @Override - public Logger getChildLogger( String name ) - { + public Logger getChildLogger(String name) { return null; } @@ -340,8 +309,7 @@ public Logger getChildLogger( String name ) * @see org.codehaus.plexus.logging.Logger#getThreshold() */ @Override - public int getThreshold() - { + public int getThreshold() { return 0; } @@ -350,15 +318,13 @@ public int getThreshold() * @see org.codehaus.plexus.logging.Logger#getName() */ @Override - public String getName() - { + public String getName() { return null; } @Override - public void setThreshold( int threshold ) - { + public void setThreshold(int threshold) { // TODO Auto-generated method stub - + } } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/WithoutMojo.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/WithoutMojo.java index afd0f348..4fa6bbf4 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/WithoutMojo.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/WithoutMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,24 +16,22 @@ * specific language governing permissions and limitations * under the License. */ - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +package org.apache.maven.plugin.testing; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + /** - * + * * An annotation for test methods that do not require the {@link MojoRule} to create and tear down the instance. * * @author Mirko Friedenhagen */ -@Retention( RUNTIME ) +@Retention(RUNTIME) @Documented -@Target( METHOD ) -public @interface WithoutMojo -{ - -} +@Target(METHOD) +public @interface WithoutMojo {} diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/resources/TestResources.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/resources/TestResources.java index f8712923..54343f12 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/resources/TestResources.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/resources/TestResources.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing.resources; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 + * 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 @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing.resources; import java.io.File; import java.io.IOException; @@ -34,24 +33,20 @@ /** * Junit4 test {@link Rule} to extract and assert test resources. - * + * * @since 3.1.0 */ -public class TestResources - extends TestWatcher -{ +public class TestResources extends TestWatcher { private final String projectsDir; private final String workDir; - public TestResources() - { - this( "src/test/projects", "target/test-projects" ); + public TestResources() { + this("src/test/projects", "target/test-projects"); } - public TestResources( String projectsDir, String workDir ) - { + public TestResources(String projectsDir, String workDir) { this.projectsDir = projectsDir; this.workDir = workDir; } @@ -59,12 +54,10 @@ public TestResources( String projectsDir, String workDir ) private String name; @Override - protected void starting( Description d ) - { + protected void starting(Description d) { String methodName = d.getMethodName(); - if ( methodName != null ) - { - methodName = methodName.replace( '/', '_' ).replace( '\\', '_' ); + if (methodName != null) { + methodName = methodName.replace('/', '_').replace('\\', '_'); } name = d.getTestClass().getSimpleName() + "_" + methodName; } @@ -76,129 +69,102 @@ protected void starting( Description d ) *

* TODO Provide alternative working directory naming for Windows, which still limits path names to ~250 charecters */ - public File getBasedir( String project ) - throws IOException - { - if ( name == null ) - { - throw new IllegalStateException( getClass().getSimpleName() - + " must be a test class field annotated with org.junit.Rule" ); + public File getBasedir(String project) throws IOException { + if (name == null) { + throw new IllegalStateException( + getClass().getSimpleName() + " must be a test class field annotated with org.junit.Rule"); } - File src = new File( projectsDir, project ).getCanonicalFile(); - Assert.assertTrue( "Test project directory does not exist: " + src.getPath(), src.isDirectory() ); - File basedir = new File( workDir, name + "_" + project ).getCanonicalFile(); - FileUtils.deleteDirectory( basedir ); - Assert.assertTrue( "Test project working directory created", basedir.mkdirs() ); - FileUtils.copyDirectoryStructure( src, basedir ); + File src = new File(projectsDir, project).getCanonicalFile(); + Assert.assertTrue("Test project directory does not exist: " + src.getPath(), src.isDirectory()); + File basedir = new File(workDir, name + "_" + project).getCanonicalFile(); + FileUtils.deleteDirectory(basedir); + Assert.assertTrue("Test project working directory created", basedir.mkdirs()); + FileUtils.copyDirectoryStructure(src, basedir); return basedir; } // static helpers - public static void cp( File basedir, String from, String to ) - throws IOException - { + public static void cp(File basedir, String from, String to) throws IOException { // TODO ensure destination lastModified timestamp changes - FileUtils.copyFile( new File( basedir, from ), new File( basedir, to ) ); + FileUtils.copyFile(new File(basedir, from), new File(basedir, to)); } - public static void assertFileContents( File basedir, String expectedPath, String actualPath ) - throws IOException - { - String expected = FileUtils.fileRead( new File( basedir, expectedPath ) ); - String actual = FileUtils.fileRead( new File( basedir, actualPath ) ); - Assert.assertEquals( expected, actual ); + public static void assertFileContents(File basedir, String expectedPath, String actualPath) throws IOException { + String expected = FileUtils.fileRead(new File(basedir, expectedPath)); + String actual = FileUtils.fileRead(new File(basedir, actualPath)); + Assert.assertEquals(expected, actual); } - public static void assertDirectoryContents( File dir, String... expectedPaths ) - { + public static void assertDirectoryContents(File dir, String... expectedPaths) { DirectoryScanner scanner = new DirectoryScanner(); - scanner.setBasedir( dir ); + scanner.setBasedir(dir); scanner.addDefaultExcludes(); scanner.scan(); Set actual = new TreeSet<>(); - for ( String path : scanner.getIncludedFiles() ) - { - actual.add( path ); + for (String path : scanner.getIncludedFiles()) { + actual.add(path); } - for ( String path : scanner.getIncludedDirectories() ) - { - if ( path.length() > 0 ) - { - actual.add( path + "/" ); + for (String path : scanner.getIncludedDirectories()) { + if (path.length() > 0) { + actual.add(path + "/"); } } Set expected = new TreeSet<>(); - if ( expectedPaths != null ) - { - for ( String path : expectedPaths ) - { - expected.add( path ); + if (expectedPaths != null) { + for (String path : expectedPaths) { + expected.add(path); } } // compare textual representation to make diff easier to understand - Assert.assertEquals( toString( expected ), toString( actual ) ); + Assert.assertEquals(toString(expected), toString(actual)); } - private static String toString( Collection strings ) - { + private static String toString(Collection strings) { StringBuilder sb = new StringBuilder(); - for ( String string : strings ) - { - sb.append( string ).append( '\n' ); + for (String string : strings) { + sb.append(string).append('\n'); } return sb.toString(); } - public static void touch( File basedir, String path ) - throws InterruptedException - { - touch( new File( basedir, path ) ); + public static void touch(File basedir, String path) throws InterruptedException { + touch(new File(basedir, path)); } - public static void touch( File file ) - throws InterruptedException - { - if ( !file.isFile() ) - { - throw new IllegalArgumentException( "Not a file " + file ); + public static void touch(File file) throws InterruptedException { + if (!file.isFile()) { + throw new IllegalArgumentException("Not a file " + file); } long lastModified = file.lastModified(); - file.setLastModified( System.currentTimeMillis() ); + file.setLastModified(System.currentTimeMillis()); // TODO do modern filesystems still have this silly lastModified resolution? - if ( lastModified == file.lastModified() ) - { - Thread.sleep( 1000L ); - file.setLastModified( System.currentTimeMillis() ); + if (lastModified == file.lastModified()) { + Thread.sleep(1000L); + file.setLastModified(System.currentTimeMillis()); } } - public static void rm( File basedir, String path ) - { - Assert.assertTrue( "delete " + path, new File( basedir, path ).delete() ); + public static void rm(File basedir, String path) { + Assert.assertTrue("delete " + path, new File(basedir, path).delete()); } /** * @since 3.2.0 */ - public static void create( File basedir, String... paths ) - throws IOException - { - if ( paths == null || paths.length == 0 ) - { + public static void create(File basedir, String... paths) throws IOException { + if (paths == null || paths.length == 0) { throw new IllegalArgumentException(); } - for ( String path : paths ) - { - File file = new File( basedir, path ); - Assert.assertTrue( file.getParentFile().mkdirs() ); + for (String path : paths) { + File file = new File(basedir, path); + Assert.assertTrue(file.getParentFile().mkdirs()); file.createNewFile(); - Assert.assertTrue( file.isFile() && file.canRead() ); + Assert.assertTrue(file.isFile() && file.canRead()); } } - } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/ArtifactStub.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/ArtifactStub.java index 63f15c51..edbaa9e3 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/ArtifactStub.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/ArtifactStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing.stubs; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing.stubs; import java.io.File; import java.util.Collection; @@ -37,9 +36,7 @@ * * @author jesse */ -public class ArtifactStub - implements Artifact -{ +public class ArtifactStub implements Artifact { private String groupId; private String artifactId; @@ -62,50 +59,43 @@ public class ArtifactStub * @see java.lang.Comparable#compareTo(java.lang.Object) */ @Override - public int compareTo( Artifact artifact ) - { + public int compareTo(Artifact artifact) { return 0; } /** {@inheritDoc} */ @Override - public String getGroupId() - { + public String getGroupId() { return groupId; } /** {@inheritDoc} */ @Override - public String getArtifactId() - { + public String getArtifactId() { return artifactId; } /** {@inheritDoc} */ @Override - public String getVersion() - { + public String getVersion() { return version; } /** {@inheritDoc} */ @Override - public void setVersion( String version ) - { + public void setVersion(String version) { this.version = version; } /** {@inheritDoc} */ @Override - public String getScope() - { + public String getScope() { return scope; } /** {@inheritDoc} */ @Override - public String getType() - { + public String getType() { return type; } @@ -114,36 +104,31 @@ public String getType() * * @param type */ - public void setType( String type ) - { + public void setType(String type) { this.type = type; } /** {@inheritDoc} */ @Override - public String getClassifier() - { + public String getClassifier() { return classifier; } /** {@inheritDoc} */ @Override - public boolean hasClassifier() - { + public boolean hasClassifier() { return classifier != null; } /** {@inheritDoc} */ @Override - public File getFile() - { + public File getFile() { return file; } /** {@inheritDoc} */ @Override - public void setFile( File file ) - { + public void setFile(File file) { this.file = file; } @@ -152,8 +137,7 @@ public void setFile( File file ) * @see org.apache.maven.artifact.Artifact#getBaseVersion() */ @Override - public String getBaseVersion() - { + public String getBaseVersion() { return null; } @@ -163,8 +147,7 @@ public String getBaseVersion() * @see org.apache.maven.artifact.Artifact#setBaseVersion(java.lang.String) */ @Override - public void setBaseVersion( String string ) - { + public void setBaseVersion(String string) { // nop } @@ -173,8 +156,7 @@ public void setBaseVersion( String string ) * @see org.apache.maven.artifact.Artifact#getId() */ @Override - public String getId() - { + public String getId() { return null; } @@ -183,14 +165,13 @@ public String getId() * @see org.apache.maven.artifact.Artifact#getDependencyConflictId() */ @Override - public String getDependencyConflictId() - { + public String getDependencyConflictId() { StringBuffer buffer = new StringBuffer(); - buffer.append( getGroupId() ); - buffer.append( ":" ).append( getArtifactId() ); - buffer.append( ":" ).append( getType() ); - buffer.append( ":" ).append( getClassifier() ); + buffer.append(getGroupId()); + buffer.append(":").append(getArtifactId()); + buffer.append(":").append(getType()); + buffer.append(":").append(getClassifier()); return buffer.toString(); } @@ -201,8 +182,7 @@ public String getDependencyConflictId() * @see org.apache.maven.artifact.Artifact#addMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata) */ @Override - public void addMetadata( ArtifactMetadata artifactMetadata ) - { + public void addMetadata(ArtifactMetadata artifactMetadata) { // nop } @@ -211,22 +191,19 @@ public void addMetadata( ArtifactMetadata artifactMetadata ) * @see org.apache.maven.artifact.Artifact#getMetadataList() */ @Override - public Collection getMetadataList() - { + public Collection getMetadataList() { return null; } /** {@inheritDoc} */ @Override - public void setRepository( ArtifactRepository artifactRepository ) - { + public void setRepository(ArtifactRepository artifactRepository) { this.artifactRepository = artifactRepository; } /** {@inheritDoc} */ @Override - public ArtifactRepository getRepository() - { + public ArtifactRepository getRepository() { return artifactRepository; } @@ -236,8 +213,7 @@ public ArtifactRepository getRepository() * @see org.apache.maven.artifact.Artifact#updateVersion(java.lang.String, org.apache.maven.artifact.repository.ArtifactRepository) */ @Override - public void updateVersion( String string, ArtifactRepository artifactRepository ) - { + public void updateVersion(String string, ArtifactRepository artifactRepository) { // nop } @@ -246,8 +222,7 @@ public void updateVersion( String string, ArtifactRepository artifactRepository * @see org.apache.maven.artifact.Artifact#getDownloadUrl() */ @Override - public String getDownloadUrl() - { + public String getDownloadUrl() { return null; } @@ -257,8 +232,7 @@ public String getDownloadUrl() * @see org.apache.maven.artifact.Artifact#setDownloadUrl(java.lang.String) */ @Override - public void setDownloadUrl( String string ) - { + public void setDownloadUrl(String string) { // nop } @@ -267,8 +241,7 @@ public void setDownloadUrl( String string ) * @see org.apache.maven.artifact.Artifact#getDependencyFilter() */ @Override - public ArtifactFilter getDependencyFilter() - { + public ArtifactFilter getDependencyFilter() { return null; } @@ -278,8 +251,7 @@ public ArtifactFilter getDependencyFilter() * @see org.apache.maven.artifact.Artifact#setDependencyFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) */ @Override - public void setDependencyFilter( ArtifactFilter artifactFilter ) - { + public void setDependencyFilter(ArtifactFilter artifactFilter) { // nop } @@ -288,8 +260,7 @@ public void setDependencyFilter( ArtifactFilter artifactFilter ) * @see org.apache.maven.artifact.Artifact#getArtifactHandler() */ @Override - public ArtifactHandler getArtifactHandler() - { + public ArtifactHandler getArtifactHandler() { return null; } @@ -298,8 +269,7 @@ public ArtifactHandler getArtifactHandler() * @see org.apache.maven.artifact.Artifact#getDependencyTrail() */ @Override - public List getDependencyTrail() - { + public List getDependencyTrail() { return null; } @@ -309,15 +279,13 @@ public List getDependencyTrail() * @see org.apache.maven.artifact.Artifact#setDependencyTrail(java.util.List) */ @Override - public void setDependencyTrail( List list ) - { + public void setDependencyTrail(List list) { // nop } /** {@inheritDoc} */ @Override - public void setScope( String scope ) - { + public void setScope(String scope) { this.scope = scope; } @@ -326,8 +294,7 @@ public void setScope( String scope ) * @see org.apache.maven.artifact.Artifact#getVersionRange() */ @Override - public VersionRange getVersionRange() - { + public VersionRange getVersionRange() { return null; } @@ -337,8 +304,7 @@ public VersionRange getVersionRange() * @see org.apache.maven.artifact.Artifact#setVersionRange(org.apache.maven.artifact.versioning.VersionRange) */ @Override - public void setVersionRange( VersionRange versionRange ) - { + public void setVersionRange(VersionRange versionRange) { // nop } @@ -348,22 +314,19 @@ public void setVersionRange( VersionRange versionRange ) * @see org.apache.maven.artifact.Artifact#selectVersion(java.lang.String) */ @Override - public void selectVersion( String string ) - { + public void selectVersion(String string) { // nop } /** {@inheritDoc} */ @Override - public void setGroupId( String groupId ) - { + public void setGroupId(String groupId) { this.groupId = groupId; } /** {@inheritDoc} */ @Override - public void setArtifactId( String artifactId ) - { + public void setArtifactId(String artifactId) { this.artifactId = artifactId; } @@ -372,10 +335,9 @@ public void setArtifactId( String artifactId ) * @see org.apache.maven.artifact.Artifact#isSnapshot() */ @Override - public boolean isSnapshot() - { - return Artifact.VERSION_FILE_PATTERN.matcher( getVersion() ).matches() - || getVersion().endsWith( Artifact.SNAPSHOT_VERSION ); + public boolean isSnapshot() { + return Artifact.VERSION_FILE_PATTERN.matcher(getVersion()).matches() + || getVersion().endsWith(Artifact.SNAPSHOT_VERSION); } /** @@ -384,8 +346,7 @@ public boolean isSnapshot() * @see org.apache.maven.artifact.Artifact#setResolved(boolean) */ @Override - public void setResolved( boolean b ) - { + public void setResolved(boolean b) { // nop } @@ -394,8 +355,7 @@ public void setResolved( boolean b ) * @see org.apache.maven.artifact.Artifact#isResolved() */ @Override - public boolean isResolved() - { + public boolean isResolved() { return false; } @@ -405,8 +365,7 @@ public boolean isResolved() * @see org.apache.maven.artifact.Artifact#setResolvedVersion(java.lang.String) */ @Override - public void setResolvedVersion( String string ) - { + public void setResolvedVersion(String string) { // nop } @@ -416,8 +375,7 @@ public void setResolvedVersion( String string ) * @see org.apache.maven.artifact.Artifact#setArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) */ @Override - public void setArtifactHandler( ArtifactHandler artifactHandler ) - { + public void setArtifactHandler(ArtifactHandler artifactHandler) { // nop } @@ -426,8 +384,7 @@ public void setArtifactHandler( ArtifactHandler artifactHandler ) * @see org.apache.maven.artifact.Artifact#isRelease() */ @Override - public boolean isRelease() - { + public boolean isRelease() { return !isSnapshot(); } @@ -437,8 +394,7 @@ public boolean isRelease() * @see org.apache.maven.artifact.Artifact#setRelease(boolean) */ @Override - public void setRelease( boolean b ) - { + public void setRelease(boolean b) { // nop } @@ -447,8 +403,7 @@ public void setRelease( boolean b ) * @see org.apache.maven.artifact.Artifact#getAvailableVersions() */ @Override - public List getAvailableVersions() - { + public List getAvailableVersions() { return null; } @@ -458,8 +413,7 @@ public List getAvailableVersions() * @see org.apache.maven.artifact.Artifact#setAvailableVersions(java.util.List) */ @Override - public void setAvailableVersions( List list ) - { + public void setAvailableVersions(List list) { // nop } @@ -468,8 +422,7 @@ public void setAvailableVersions( List list ) * @see org.apache.maven.artifact.Artifact#isOptional() */ @Override - public boolean isOptional() - { + public boolean isOptional() { return false; } @@ -479,8 +432,7 @@ public boolean isOptional() * @param b */ @Override - public void setOptional( boolean b ) - { + public void setOptional(boolean b) { // nop } @@ -489,9 +441,7 @@ public void setOptional( boolean b ) * @see org.apache.maven.artifact.Artifact#getSelectedVersion() */ @Override - public ArtifactVersion getSelectedVersion() - throws OverConstrainedVersionException - { + public ArtifactVersion getSelectedVersion() throws OverConstrainedVersionException { return null; } @@ -500,9 +450,7 @@ public ArtifactVersion getSelectedVersion() * @see org.apache.maven.artifact.Artifact#isSelectedVersionKnown() */ @Override - public boolean isSelectedVersionKnown() - throws OverConstrainedVersionException - { + public boolean isSelectedVersionKnown() throws OverConstrainedVersionException { return false; } @@ -510,47 +458,39 @@ public boolean isSelectedVersionKnown() * @see java.lang.Object#toString() */ @Override - public String toString() - { + public String toString() { StringBuffer sb = new StringBuffer(); - if ( getGroupId() != null ) - { - sb.append( getGroupId() ); - sb.append( ":" ); + if (getGroupId() != null) { + sb.append(getGroupId()); + sb.append(":"); } - appendArtifactTypeClassifierString( sb ); - if ( version != null ) - { - sb.append( ":" ); - sb.append( getVersion() ); + appendArtifactTypeClassifierString(sb); + if (version != null) { + sb.append(":"); + sb.append(getVersion()); } - if ( scope != null ) - { - sb.append( ":" ); - sb.append( scope ); + if (scope != null) { + sb.append(":"); + sb.append(scope); } return sb.toString(); } - private void appendArtifactTypeClassifierString( StringBuffer sb ) - { - sb.append( getArtifactId() ); - sb.append( ":" ); - sb.append( getType() ); - if ( hasClassifier() ) - { - sb.append( ":" ); - sb.append( getClassifier() ); + private void appendArtifactTypeClassifierString(StringBuffer sb) { + sb.append(getArtifactId()); + sb.append(":"); + sb.append(getType()); + if (hasClassifier()) { + sb.append(":"); + sb.append(getClassifier()); } } - public boolean isFromAuthoritativeRepository() - { + public boolean isFromAuthoritativeRepository() { return true; } - public void setFromAuthoritativeRepository( boolean fromAuthoritativeRepository ) - { + public void setFromAuthoritativeRepository(boolean fromAuthoritativeRepository) { // nothing } } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/DefaultArtifactHandlerStub.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/DefaultArtifactHandlerStub.java index 926a9be8..5c5fe7a0 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/DefaultArtifactHandlerStub.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/DefaultArtifactHandlerStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing.stubs; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 + * 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 @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing.stubs; import org.apache.maven.artifact.handler.ArtifactHandler; @@ -26,9 +25,7 @@ * * @author Brian Fox */ -public class DefaultArtifactHandlerStub - implements ArtifactHandler -{ +public class DefaultArtifactHandlerStub implements ArtifactHandler { private String extension; private String type; @@ -49,31 +46,25 @@ public class DefaultArtifactHandlerStub * @param t the artifact handler type * @param c the artifact handler classifier */ - public DefaultArtifactHandlerStub( String t, String c ) - { + public DefaultArtifactHandlerStub(String t, String c) { type = t; classifier = c; - if ( t.equals( "test-jar" ) ) - { + if (t.equals("test-jar")) { extension = "jar"; } - } /** * @param type the artifact handler type */ - public DefaultArtifactHandlerStub( String type ) - { + public DefaultArtifactHandlerStub(String type) { this.type = type; } /** {@inheritDoc} */ @Override - public String getExtension() - { - if ( extension == null ) - { + public String getExtension() { + if (extension == null) { extension = type; } return extension; @@ -82,24 +73,20 @@ public String getExtension() /** * @return the artifact handler type */ - public String getType() - { + public String getType() { return type; } /** {@inheritDoc} */ @Override - public String getClassifier() - { + public String getClassifier() { return classifier; } /** {@inheritDoc} */ @Override - public String getDirectory() - { - if ( directory == null ) - { + public String getDirectory() { + if (directory == null) { directory = getPackaging() + "s"; } return directory; @@ -107,10 +94,8 @@ public String getDirectory() /** {@inheritDoc} */ @Override - public String getPackaging() - { - if ( packaging == null ) - { + public String getPackaging() { + if (packaging == null) { packaging = getType(); } return packaging; @@ -118,17 +103,14 @@ public String getPackaging() /** {@inheritDoc} */ @Override - public boolean isIncludesDependencies() - { + public boolean isIncludesDependencies() { return includesDependencies; } /** {@inheritDoc} */ @Override - public String getLanguage() - { - if ( language == null ) - { + public String getLanguage() { + if (language == null) { language = "none"; } @@ -137,72 +119,63 @@ public String getLanguage() /** {@inheritDoc} */ @Override - public boolean isAddedToClasspath() - { + public boolean isAddedToClasspath() { return addedToClasspath; } /** * @param theAddedToClasspath The addedToClasspath to set. */ - public void setAddedToClasspath( boolean theAddedToClasspath ) - { + public void setAddedToClasspath(boolean theAddedToClasspath) { this.addedToClasspath = theAddedToClasspath; } /** * @param theClassifier The classifier to set. */ - public void setClassifier( String theClassifier ) - { + public void setClassifier(String theClassifier) { this.classifier = theClassifier; } /** * @param theDirectory The directory to set. */ - public void setDirectory( String theDirectory ) - { + public void setDirectory(String theDirectory) { this.directory = theDirectory; } /** * @param theExtension The extension to set. */ - public void setExtension( String theExtension ) - { + public void setExtension(String theExtension) { this.extension = theExtension; } /** * @param theIncludesDependencies The includesDependencies to set. */ - public void setIncludesDependencies( boolean theIncludesDependencies ) - { + public void setIncludesDependencies(boolean theIncludesDependencies) { this.includesDependencies = theIncludesDependencies; } /** * @param theLanguage The language to set. */ - public void setLanguage( String theLanguage ) - { + public void setLanguage(String theLanguage) { this.language = theLanguage; } /** * @param thePackaging The packaging to set. */ - public void setPackaging( String thePackaging ) - { + public void setPackaging(String thePackaging) { this.packaging = thePackaging; } /** * @param theType The type to set. */ - public void setType( String theType ) - { + public void setType(String theType) { this.type = theType; } } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/MavenProjectStub.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/MavenProjectStub.java index aacb6e73..513629b5 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/MavenProjectStub.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/MavenProjectStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing.stubs; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing.stubs; import java.io.File; import java.io.IOException; @@ -69,9 +68,7 @@ * * @author jesse */ -public class MavenProjectStub - extends MavenProject -{ +public class MavenProjectStub extends MavenProject { private String groupId; private String artifactId; @@ -165,44 +162,35 @@ public class MavenProjectStub /** * Default constructor */ - public MavenProjectStub() - { - this( new Model() ); + public MavenProjectStub() { + this(new Model()); } /** * @param model the given model */ - public MavenProjectStub( Model model ) - { - super( (Model) null ); + public MavenProjectStub(Model model) { + super((Model) null); this.model = model; } /** * Loads the model for this stub from the specified POM. For convenience, any checked exception caused by I/O or * parser errors will be wrapped into an unchecked exception. - * + * * @param pomFile The path to the POM file to load, must not be null. If this path is relative, it * is resolved against the return value of {@link #getBasedir()}. */ - protected void readModel( File pomFile ) - { - if ( !pomFile.isAbsolute() ) - { - pomFile = new File( getBasedir(), pomFile.getPath() ); - } - try - { - setModel( new MavenXpp3Reader().read( ReaderFactory.newXmlReader( pomFile ) ) ); + protected void readModel(File pomFile) { + if (!pomFile.isAbsolute()) { + pomFile = new File(getBasedir(), pomFile.getPath()); } - catch ( IOException e ) - { - throw new RuntimeException( "Failed to read POM file: " + pomFile, e ); - } - catch ( XmlPullParserException e ) - { - throw new RuntimeException( "Failed to parse POM file: " + pomFile, e ); + try { + setModel(new MavenXpp3Reader().read(ReaderFactory.newXmlReader(pomFile))); + } catch (IOException e) { + throw new RuntimeException("Failed to read POM file: " + pomFile, e); + } catch (XmlPullParserException e) { + throw new RuntimeException("Failed to parse POM file: " + pomFile, e); } } @@ -211,9 +199,8 @@ protected void readModel( File pomFile ) * * @param project the given project */ - public MavenProjectStub( MavenProject project ) - { - super( (Model) null ); + public MavenProjectStub(MavenProject project) { + super((Model) null); } /** @@ -222,44 +209,37 @@ public MavenProjectStub( MavenProject project ) * @throws IOException if any */ @Override - public String getModulePathAdjustment( MavenProject mavenProject ) - throws IOException - { + public String getModulePathAdjustment(MavenProject mavenProject) throws IOException { return ""; } /** {@inheritDoc} */ @Override - public Artifact getArtifact() - { + public Artifact getArtifact() { return artifact; } /** {@inheritDoc} */ @Override - public void setArtifact( Artifact artifact ) - { + public void setArtifact(Artifact artifact) { this.artifact = artifact; } /** {@inheritDoc} */ @Override - public Model getModel() - { + public Model getModel() { return model; } /** {@inheritDoc} */ @Override - public MavenProject getParent() - { + public MavenProject getParent() { return parent; } /** {@inheritDoc} */ @Override - public void setParent( MavenProject mavenProject ) - { + public void setParent(MavenProject mavenProject) { this.parent = mavenProject; } @@ -269,8 +249,7 @@ public void setParent( MavenProject mavenProject ) * @see org.apache.maven.project.MavenProject#setRemoteArtifactRepositories(java.util.List) */ @Override - public void setRemoteArtifactRepositories( List list ) - { + public void setRemoteArtifactRepositories(List list) { // nop } @@ -280,17 +259,14 @@ public void setRemoteArtifactRepositories( List list ) * @see org.apache.maven.project.MavenProject#getRemoteArtifactRepositories() */ @Override - public List getRemoteArtifactRepositories() - { + public List getRemoteArtifactRepositories() { return Collections.emptyList(); } /** {@inheritDoc} */ @Override - public boolean hasParent() - { - if ( parent != null ) - { + public boolean hasParent() { + if (parent != null) { return true; } @@ -299,23 +275,20 @@ public boolean hasParent() /** {@inheritDoc} */ @Override - public File getFile() - { + public File getFile() { return file; } /** {@inheritDoc} */ @Override - public void setFile( File file ) - { + public void setFile(File file) { this.file = file; } /** {@inheritDoc} */ @Override - public File getBasedir() - { - return new File( PlexusTestCase.getBasedir() ); + public File getBasedir() { + return new File(PlexusTestCase.getBasedir()); } /** @@ -324,8 +297,7 @@ public File getBasedir() * @see org.apache.maven.project.MavenProject#setDependencies(java.util.List) */ @Override - public void setDependencies( List list ) - { + public void setDependencies(List list) { // nop } @@ -335,8 +307,7 @@ public void setDependencies( List list ) * @see org.apache.maven.project.MavenProject#getDependencies() */ @Override - public List getDependencies() - { + public List getDependencies() { return Collections.emptyList(); } @@ -346,168 +317,135 @@ public List getDependencies() * @see org.apache.maven.project.MavenProject#getDependencyManagement() */ @Override - public DependencyManagement getDependencyManagement() - { + public DependencyManagement getDependencyManagement() { return null; } /** {@inheritDoc} */ @Override - public void addCompileSourceRoot( String string ) - { - if ( compileSourceRoots == null ) - { - compileSourceRoots = new ArrayList<>( Collections.singletonList( string ) ); - } - else - { - compileSourceRoots.add( string ); + public void addCompileSourceRoot(String string) { + if (compileSourceRoots == null) { + compileSourceRoots = new ArrayList<>(Collections.singletonList(string)); + } else { + compileSourceRoots.add(string); } } /** {@inheritDoc} */ @Override - public void addScriptSourceRoot( String string ) - { - if ( scriptSourceRoots == null ) - { - scriptSourceRoots = new ArrayList<>( Collections.singletonList( string ) ); - } - else - { - scriptSourceRoots.add( string ); + public void addScriptSourceRoot(String string) { + if (scriptSourceRoots == null) { + scriptSourceRoots = new ArrayList<>(Collections.singletonList(string)); + } else { + scriptSourceRoots.add(string); } } /** {@inheritDoc} */ @Override - public void addTestCompileSourceRoot( String string ) - { - if ( testCompileSourceRoots == null ) - { - testCompileSourceRoots = new ArrayList<>( Collections.singletonList( string ) ); - } - else - { - testCompileSourceRoots.add( string ); + public void addTestCompileSourceRoot(String string) { + if (testCompileSourceRoots == null) { + testCompileSourceRoots = new ArrayList<>(Collections.singletonList(string)); + } else { + testCompileSourceRoots.add(string); } } /** {@inheritDoc} */ @Override - public List getCompileSourceRoots() - { + public List getCompileSourceRoots() { return compileSourceRoots; } /** {@inheritDoc} */ @Override - public List getScriptSourceRoots() - { + public List getScriptSourceRoots() { return scriptSourceRoots; } /** {@inheritDoc} */ @Override - public List getTestCompileSourceRoots() - { + public List getTestCompileSourceRoots() { return testCompileSourceRoots; } /** {@inheritDoc} */ @Override - public List getCompileClasspathElements() - throws DependencyResolutionRequiredException - { + public List getCompileClasspathElements() throws DependencyResolutionRequiredException { return compileSourceRoots; } /** * @param compileArtifacts */ - public void setCompileArtifacts( List compileArtifacts ) - { + public void setCompileArtifacts(List compileArtifacts) { this.compileArtifacts = compileArtifacts; } /** {@inheritDoc} */ @Override - public List getCompileArtifacts() - { + public List getCompileArtifacts() { return compileArtifacts; } /** {@inheritDoc} */ @Override - public List getCompileDependencies() - { + public List getCompileDependencies() { return compileDependencies; } /** {@inheritDoc} */ @Override - public List getTestClasspathElements() - throws DependencyResolutionRequiredException - { + public List getTestClasspathElements() throws DependencyResolutionRequiredException { return testClasspathElements; } /** {@inheritDoc} */ @Override - public List getTestArtifacts() - { + public List getTestArtifacts() { return testArtifacts; } /** {@inheritDoc} */ @Override - public List getTestDependencies() - { + public List getTestDependencies() { return testDependencies; } /** {@inheritDoc} */ @Override - public List getRuntimeClasspathElements() - throws DependencyResolutionRequiredException - { + public List getRuntimeClasspathElements() throws DependencyResolutionRequiredException { return runtimeClasspathElements; } /** {@inheritDoc} */ @Override - public List getRuntimeArtifacts() - { + public List getRuntimeArtifacts() { return runtimeArtifacts; } /** {@inheritDoc} */ @Override - public List getRuntimeDependencies() - { + public List getRuntimeDependencies() { return runtimeDependencies; } /** {@inheritDoc} */ @Override - public List getSystemClasspathElements() - throws DependencyResolutionRequiredException - { + public List getSystemClasspathElements() throws DependencyResolutionRequiredException { return systemClasspathElements; } /** {@inheritDoc} */ @Override - public List getSystemArtifacts() - { + public List getSystemArtifacts() { return systemArtifacts; } /** * @param runtimeClasspathElements */ - public void setRuntimeClasspathElements( List runtimeClasspathElements ) - { + public void setRuntimeClasspathElements(List runtimeClasspathElements) { this.runtimeClasspathElements = runtimeClasspathElements; } @@ -515,8 +453,7 @@ public void setRuntimeClasspathElements( List runtimeClasspathElements ) * @param attachedArtifacts */ @Override - public void setAttachedArtifacts( List attachedArtifacts ) - { + public void setAttachedArtifacts(List attachedArtifacts) { this.attachedArtifacts = attachedArtifacts; } @@ -524,8 +461,7 @@ public void setAttachedArtifacts( List attachedArtifacts ) * @param compileSourceRoots */ @Override - public void setCompileSourceRoots( List compileSourceRoots ) - { + public void setCompileSourceRoots(List compileSourceRoots) { this.compileSourceRoots = compileSourceRoots; } @@ -533,8 +469,7 @@ public void setCompileSourceRoots( List compileSourceRoots ) * @param testCompileSourceRoots */ @Override - public void setTestCompileSourceRoots( List testCompileSourceRoots ) - { + public void setTestCompileSourceRoots(List testCompileSourceRoots) { this.testCompileSourceRoots = testCompileSourceRoots; } @@ -542,128 +477,112 @@ public void setTestCompileSourceRoots( List testCompileSourceRoots ) * @param scriptSourceRoots */ @Override - public void setScriptSourceRoots( List scriptSourceRoots ) - { + public void setScriptSourceRoots(List scriptSourceRoots) { this.scriptSourceRoots = scriptSourceRoots; } /** * @param artifactMap */ - public void setArtifactMap( Map artifactMap ) - { + public void setArtifactMap(Map artifactMap) { this.artifactMap = artifactMap; } /** * @param pluginArtifactMap */ - public void setPluginArtifactMap( Map pluginArtifactMap ) - { + public void setPluginArtifactMap(Map pluginArtifactMap) { this.pluginArtifactMap = pluginArtifactMap; } /** * @param reportArtifactMap */ - public void setReportArtifactMap( Map reportArtifactMap ) - { + public void setReportArtifactMap(Map reportArtifactMap) { this.reportArtifactMap = reportArtifactMap; } /** * @param extensionArtifactMap */ - public void setExtensionArtifactMap( Map extensionArtifactMap ) - { + public void setExtensionArtifactMap(Map extensionArtifactMap) { this.extensionArtifactMap = extensionArtifactMap; } /** * @param projectReferences */ - public void setProjectReferences( Map projectReferences ) - { + public void setProjectReferences(Map projectReferences) { this.projectReferences = projectReferences; } /** * @param buildOverlay */ - public void setBuildOverlay( Build buildOverlay ) - { + public void setBuildOverlay(Build buildOverlay) { this.buildOverlay = buildOverlay; } /** * @param compileDependencies */ - public void setCompileDependencies( List compileDependencies ) - { + public void setCompileDependencies(List compileDependencies) { this.compileDependencies = compileDependencies; } /** * @param systemDependencies */ - public void setSystemDependencies( List systemDependencies ) - { + public void setSystemDependencies(List systemDependencies) { this.systemDependencies = systemDependencies; } /** * @param testClasspathElements */ - public void setTestClasspathElements( List testClasspathElements ) - { + public void setTestClasspathElements(List testClasspathElements) { this.testClasspathElements = testClasspathElements; } /** * @param testDependencies */ - public void setTestDependencies( List testDependencies ) - { + public void setTestDependencies(List testDependencies) { this.testDependencies = testDependencies; } /** * @param systemClasspathElements */ - public void setSystemClasspathElements( List systemClasspathElements ) - { + public void setSystemClasspathElements(List systemClasspathElements) { this.systemClasspathElements = systemClasspathElements; } /** * @param systemArtifacts */ - public void setSystemArtifacts( List systemArtifacts ) - { + public void setSystemArtifacts(List systemArtifacts) { this.systemArtifacts = systemArtifacts; } /** * @param testArtifacts */ - public void setTestArtifacts( List testArtifacts ) - { + public void setTestArtifacts(List testArtifacts) { this.testArtifacts = testArtifacts; } /** * @param runtimeArtifacts */ - public void setRuntimeArtifacts( List runtimeArtifacts ) - { + public void setRuntimeArtifacts(List runtimeArtifacts) { this.runtimeArtifacts = runtimeArtifacts; } /** * @param runtimeDependencies */ - public void setRuntimeDependencies( List runtimeDependencies ) - { + public void setRuntimeDependencies(List runtimeDependencies) { this.runtimeDependencies = runtimeDependencies; } @@ -671,29 +590,25 @@ public void setRuntimeDependencies( List runtimeDependencies ) * @param model */ @Override - public void setModel( Model model ) - { + public void setModel(Model model) { this.model = model; } /** {@inheritDoc} */ @Override - public List getSystemDependencies() - { + public List getSystemDependencies() { return systemDependencies; } /** {@inheritDoc} */ @Override - public void setModelVersion( String string ) - { + public void setModelVersion(String string) { this.modelVersion = string; } /** {@inheritDoc} */ @Override - public String getModelVersion() - { + public String getModelVersion() { return modelVersion; } @@ -703,106 +618,91 @@ public String getModelVersion() * @see org.apache.maven.project.MavenProject#getId() */ @Override - public String getId() - { + public String getId() { return ""; } /** {@inheritDoc} */ @Override - public void setGroupId( String string ) - { + public void setGroupId(String string) { this.groupId = string; } /** {@inheritDoc} */ @Override - public String getGroupId() - { + public String getGroupId() { return groupId; } /** {@inheritDoc} */ @Override - public void setArtifactId( String string ) - { + public void setArtifactId(String string) { this.artifactId = string; } /** {@inheritDoc} */ @Override - public String getArtifactId() - { + public String getArtifactId() { return artifactId; } /** {@inheritDoc} */ @Override - public void setName( String string ) - { + public void setName(String string) { this.name = string; } /** {@inheritDoc} */ @Override - public String getName() - { + public String getName() { return name; } /** {@inheritDoc} */ @Override - public void setVersion( String string ) - { + public void setVersion(String string) { this.version = string; } /** {@inheritDoc} */ @Override - public String getVersion() - { + public String getVersion() { return version; } /** {@inheritDoc} */ @Override - public String getPackaging() - { + public String getPackaging() { return packaging; } /** {@inheritDoc} */ @Override - public void setPackaging( String string ) - { + public void setPackaging(String string) { this.packaging = string; } /** {@inheritDoc} */ @Override - public void setInceptionYear( String string ) - { + public void setInceptionYear(String string) { this.inceptionYear = string; } /** {@inheritDoc} */ @Override - public String getInceptionYear() - { + public String getInceptionYear() { return inceptionYear; } /** {@inheritDoc} */ @Override - public void setUrl( String string ) - { + public void setUrl(String string) { this.url = string; } /** {@inheritDoc} */ @Override - public String getUrl() - { + public String getUrl() { return url; } @@ -812,8 +712,7 @@ public String getUrl() * @see org.apache.maven.project.MavenProject#getPrerequisites() */ @Override - public Prerequisites getPrerequisites() - { + public Prerequisites getPrerequisites() { return null; } @@ -823,8 +722,7 @@ public Prerequisites getPrerequisites() * @see org.apache.maven.project.MavenProject#setIssueManagement(org.apache.maven.model.IssueManagement) */ @Override - public void setIssueManagement( IssueManagement issueManagement ) - { + public void setIssueManagement(IssueManagement issueManagement) { // nop } @@ -834,8 +732,7 @@ public void setIssueManagement( IssueManagement issueManagement ) * @see org.apache.maven.project.MavenProject#getCiManagement() */ @Override - public CiManagement getCiManagement() - { + public CiManagement getCiManagement() { return null; } @@ -845,8 +742,7 @@ public CiManagement getCiManagement() * @see org.apache.maven.project.MavenProject#setCiManagement(org.apache.maven.model.CiManagement) */ @Override - public void setCiManagement( CiManagement ciManagement ) - { + public void setCiManagement(CiManagement ciManagement) { // nop } @@ -856,8 +752,7 @@ public void setCiManagement( CiManagement ciManagement ) * @see org.apache.maven.project.MavenProject#getIssueManagement() */ @Override - public IssueManagement getIssueManagement() - { + public IssueManagement getIssueManagement() { return null; } @@ -867,8 +762,7 @@ public IssueManagement getIssueManagement() * @see org.apache.maven.project.MavenProject#setDistributionManagement(org.apache.maven.model.DistributionManagement) */ @Override - public void setDistributionManagement( DistributionManagement distributionManagement ) - { + public void setDistributionManagement(DistributionManagement distributionManagement) { // nop } @@ -878,22 +772,19 @@ public void setDistributionManagement( DistributionManagement distributionManage * @see org.apache.maven.project.MavenProject#getDistributionManagement() */ @Override - public DistributionManagement getDistributionManagement() - { + public DistributionManagement getDistributionManagement() { return null; } /** {@inheritDoc} */ @Override - public void setDescription( String string ) - { + public void setDescription(String string) { this.description = string; } /** {@inheritDoc} */ @Override - public String getDescription() - { + public String getDescription() { return description; } @@ -903,8 +794,7 @@ public String getDescription() * @see org.apache.maven.project.MavenProject#setOrganization(org.apache.maven.model.Organization) */ @Override - public void setOrganization( Organization organization ) - { + public void setOrganization(Organization organization) { // nop } @@ -914,8 +804,7 @@ public void setOrganization( Organization organization ) * @see org.apache.maven.project.MavenProject#getOrganization() */ @Override - public Organization getOrganization() - { + public Organization getOrganization() { return null; } @@ -925,8 +814,7 @@ public Organization getOrganization() * @see org.apache.maven.project.MavenProject#setScm(org.apache.maven.model.Scm) */ @Override - public void setScm( Scm scm ) - { + public void setScm(Scm scm) { // nop } @@ -936,8 +824,7 @@ public void setScm( Scm scm ) * @see org.apache.maven.project.MavenProject#getScm() */ @Override - public Scm getScm() - { + public Scm getScm() { return null; } @@ -947,8 +834,7 @@ public Scm getScm() * @see org.apache.maven.project.MavenProject#setMailingLists(java.util.List) */ @Override - public void setMailingLists( List list ) - { + public void setMailingLists(List list) { // nop } @@ -958,8 +844,7 @@ public void setMailingLists( List list ) * @see org.apache.maven.project.MavenProject#getMailingLists() */ @Override - public List getMailingLists() - { + public List getMailingLists() { return Collections.emptyList(); } @@ -969,8 +854,7 @@ public List getMailingLists() * @see org.apache.maven.project.MavenProject#addMailingList(org.apache.maven.model.MailingList) */ @Override - public void addMailingList( MailingList mailingList ) - { + public void addMailingList(MailingList mailingList) { // nop } @@ -980,8 +864,7 @@ public void addMailingList( MailingList mailingList ) * @see org.apache.maven.project.MavenProject#setDevelopers(java.util.List) */ @Override - public void setDevelopers( List list ) - { + public void setDevelopers(List list) { // nop } @@ -991,8 +874,7 @@ public void setDevelopers( List list ) * @see org.apache.maven.project.MavenProject#getDevelopers() */ @Override - public List getDevelopers() - { + public List getDevelopers() { return Collections.emptyList(); } @@ -1002,8 +884,7 @@ public List getDevelopers() * @see org.apache.maven.project.MavenProject#addDeveloper(org.apache.maven.model.Developer) */ @Override - public void addDeveloper( Developer developer ) - { + public void addDeveloper(Developer developer) { // nop } @@ -1013,8 +894,7 @@ public void addDeveloper( Developer developer ) * @see org.apache.maven.project.MavenProject#setContributors(java.util.List) */ @Override - public void setContributors( List list ) - { + public void setContributors(List list) { // nop } @@ -1024,8 +904,7 @@ public void setContributors( List list ) * @see org.apache.maven.project.MavenProject#getContributors() */ @Override - public List getContributors() - { + public List getContributors() { return Collections.emptyList(); } @@ -1035,22 +914,19 @@ public List getContributors() * @see org.apache.maven.project.MavenProject#addContributor(org.apache.maven.model.Contributor) */ @Override - public void addContributor( Contributor contributor ) - { + public void addContributor(Contributor contributor) { // nop } /** {@inheritDoc} */ @Override - public void setBuild( Build build ) - { + public void setBuild(Build build) { this.build = build; } /** {@inheritDoc} */ @Override - public Build getBuild() - { + public Build getBuild() { return build; } @@ -1060,8 +936,7 @@ public Build getBuild() * @see org.apache.maven.project.MavenProject#getResources() */ @Override - public List getResources() - { + public List getResources() { return Collections.emptyList(); } @@ -1071,8 +946,7 @@ public List getResources() * @see org.apache.maven.project.MavenProject#getTestResources() */ @Override - public List getTestResources() - { + public List getTestResources() { return Collections.emptyList(); } @@ -1082,8 +956,7 @@ public List getTestResources() * @see org.apache.maven.project.MavenProject#addResource(org.apache.maven.model.Resource) */ @Override - public void addResource( Resource resource ) - { + public void addResource(Resource resource) { // nop } @@ -1093,8 +966,7 @@ public void addResource( Resource resource ) * @see org.apache.maven.project.MavenProject#addTestResource(org.apache.maven.model.Resource) */ @Override - public void addTestResource( Resource resource ) - { + public void addTestResource(Resource resource) { // nop } @@ -1104,8 +976,7 @@ public void addTestResource( Resource resource ) * @see org.apache.maven.project.MavenProject#setReporting(org.apache.maven.model.Reporting) */ @Override - public void setReporting( Reporting reporting ) - { + public void setReporting(Reporting reporting) { // nop } @@ -1115,22 +986,19 @@ public void setReporting( Reporting reporting ) * @see org.apache.maven.project.MavenProject#getReporting() */ @Override - public Reporting getReporting() - { + public Reporting getReporting() { return null; } /** {@inheritDoc} */ @Override - public void setLicenses( List licenses ) - { + public void setLicenses(List licenses) { this.licenses = licenses; } /** {@inheritDoc} */ @Override - public List getLicenses() - { + public List getLicenses() { return licenses; } @@ -1140,8 +1008,7 @@ public List getLicenses() * @see org.apache.maven.project.MavenProject#addLicense(org.apache.maven.model.License) */ @Override - public void addLicense( License license ) - { + public void addLicense(License license) { // nop } @@ -1151,8 +1018,7 @@ public void addLicense( License license ) * @see org.apache.maven.project.MavenProject#setArtifacts(java.util.Set) */ @Override - public void setArtifacts( Set set ) - { + public void setArtifacts(Set set) { // nop } @@ -1162,8 +1028,7 @@ public void setArtifacts( Set set ) * @see org.apache.maven.project.MavenProject#getArtifacts() */ @Override - public Set getArtifacts() - { + public Set getArtifacts() { return Collections.emptySet(); } @@ -1173,8 +1038,7 @@ public Set getArtifacts() * @see org.apache.maven.project.MavenProject#getArtifactMap() */ @Override - public Map getArtifactMap() - { + public Map getArtifactMap() { return Collections.emptyMap(); } @@ -1184,8 +1048,7 @@ public Map getArtifactMap() * @see org.apache.maven.project.MavenProject#setPluginArtifacts(java.util.Set) */ @Override - public void setPluginArtifacts( Set set ) - { + public void setPluginArtifacts(Set set) { // nop } @@ -1195,8 +1058,7 @@ public void setPluginArtifacts( Set set ) * @see org.apache.maven.project.MavenProject#getPluginArtifacts() */ @Override - public Set getPluginArtifacts() - { + public Set getPluginArtifacts() { return Collections.emptySet(); } @@ -1206,8 +1068,7 @@ public Set getPluginArtifacts() * @see org.apache.maven.project.MavenProject#getPluginArtifactMap() */ @Override - public Map getPluginArtifactMap() - { + public Map getPluginArtifactMap() { return Collections.emptyMap(); } @@ -1217,8 +1078,7 @@ public Map getPluginArtifactMap() * @see org.apache.maven.project.MavenProject#setReportArtifacts(java.util.Set) */ @Override - public void setReportArtifacts( Set set ) - { + public void setReportArtifacts(Set set) { // nop } @@ -1228,8 +1088,7 @@ public void setReportArtifacts( Set set ) * @see org.apache.maven.project.MavenProject#getReportArtifacts() */ @Override - public Set getReportArtifacts() - { + public Set getReportArtifacts() { return Collections.emptySet(); } @@ -1239,8 +1098,7 @@ public Set getReportArtifacts() * @see org.apache.maven.project.MavenProject#getReportArtifactMap() */ @Override - public Map getReportArtifactMap() - { + public Map getReportArtifactMap() { return Collections.emptyMap(); } @@ -1250,8 +1108,7 @@ public Map getReportArtifactMap() * @see org.apache.maven.project.MavenProject#setExtensionArtifacts(java.util.Set) */ @Override - public void setExtensionArtifacts( Set set ) - { + public void setExtensionArtifacts(Set set) { // nop } @@ -1261,8 +1118,7 @@ public void setExtensionArtifacts( Set set ) * @see org.apache.maven.project.MavenProject#getExtensionArtifacts() */ @Override - public Set getExtensionArtifacts() - { + public Set getExtensionArtifacts() { return Collections.emptySet(); } @@ -1272,8 +1128,7 @@ public Set getExtensionArtifacts() * @see org.apache.maven.project.MavenProject#getExtensionArtifactMap() */ @Override - public Map getExtensionArtifactMap() - { + public Map getExtensionArtifactMap() { return Collections.emptyMap(); } @@ -1283,8 +1138,7 @@ public Map getExtensionArtifactMap() * @see org.apache.maven.project.MavenProject#setParentArtifact(org.apache.maven.artifact.Artifact) */ @Override - public void setParentArtifact( Artifact artifact ) - { + public void setParentArtifact(Artifact artifact) { // nop } @@ -1294,8 +1148,7 @@ public void setParentArtifact( Artifact artifact ) * @see org.apache.maven.project.MavenProject#getParentArtifact() */ @Override - public Artifact getParentArtifact() - { + public Artifact getParentArtifact() { return null; } @@ -1305,8 +1158,7 @@ public Artifact getParentArtifact() * @see org.apache.maven.project.MavenProject#getRepositories() */ @Override - public List getRepositories() - { + public List getRepositories() { return Collections.emptyList(); } @@ -1316,8 +1168,7 @@ public List getRepositories() * @see org.apache.maven.project.MavenProject#getReportPlugins() */ @Override - public List getReportPlugins() - { + public List getReportPlugins() { return Collections.emptyList(); } @@ -1327,8 +1178,7 @@ public List getReportPlugins() * @see org.apache.maven.project.MavenProject#getBuildPlugins() */ @Override - public List getBuildPlugins() - { + public List getBuildPlugins() { return Collections.emptyList(); } @@ -1338,8 +1188,7 @@ public List getBuildPlugins() * @see org.apache.maven.project.MavenProject#getModules() */ @Override - public List getModules() - { + public List getModules() { return Collections.emptyList(); } @@ -1349,16 +1198,14 @@ public List getModules() * @see org.apache.maven.project.MavenProject#getPluginManagement() */ @Override - public PluginManagement getPluginManagement() - { + public PluginManagement getPluginManagement() { return null; } /** * By default, do nothing. */ - public void addPlugin( Plugin plugin ) - { + public void addPlugin(Plugin plugin) { // nop } @@ -1367,36 +1214,31 @@ public void addPlugin( Plugin plugin ) * * @param plugin */ - public void injectPluginManagementInfo( Plugin plugin ) - { + public void injectPluginManagementInfo(Plugin plugin) { // nop } /** {@inheritDoc} */ @Override - public List getCollectedProjects() - { + public List getCollectedProjects() { return collectedProjects; } /** {@inheritDoc} */ @Override - public void setCollectedProjects( List list ) - { + public void setCollectedProjects(List list) { this.collectedProjects = list; } /** {@inheritDoc} */ @Override - public void setPluginArtifactRepositories( List list ) - { + public void setPluginArtifactRepositories(List list) { this.pluginArtifactRepositories = list; } /** {@inheritDoc} */ @Override - public List getPluginArtifactRepositories() - { + public List getPluginArtifactRepositories() { return pluginArtifactRepositories; } @@ -1406,8 +1248,7 @@ public List getPluginArtifactRepositories() * @see org.apache.maven.project.MavenProject#getDistributionManagementArtifactRepository() */ @Override - public ArtifactRepository getDistributionManagementArtifactRepository() - { + public ArtifactRepository getDistributionManagementArtifactRepository() { return null; } @@ -1417,43 +1258,35 @@ public ArtifactRepository getDistributionManagementArtifactRepository() * @see org.apache.maven.project.MavenProject#getPluginRepositories() */ @Override - public List getPluginRepositories() - { + public List getPluginRepositories() { return Collections.emptyList(); } /** {@inheritDoc} */ @Override - public void setActiveProfiles( List list ) - { + public void setActiveProfiles(List list) { activeProfiles = list; } /** {@inheritDoc} */ @Override - public List getActiveProfiles() - { + public List getActiveProfiles() { return activeProfiles; } /** {@inheritDoc} */ @Override - public void addAttachedArtifact( Artifact artifact ) - { - if ( attachedArtifacts == null ) - { - this.attachedArtifacts = new ArrayList<>( Collections.singletonList( artifact ) ); - } - else - { - attachedArtifacts.add( artifact ); + public void addAttachedArtifact(Artifact artifact) { + if (attachedArtifacts == null) { + this.attachedArtifacts = new ArrayList<>(Collections.singletonList(artifact)); + } else { + attachedArtifacts.add(artifact); } } /** {@inheritDoc} */ @Override - public List getAttachedArtifacts() - { + public List getAttachedArtifacts() { return attachedArtifacts; } @@ -1463,8 +1296,7 @@ public List getAttachedArtifacts() * @see org.apache.maven.project.MavenProject#getGoalConfiguration(java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @Override - public Xpp3Dom getGoalConfiguration( String string, String string1, String string2, String string3 ) - { + public Xpp3Dom getGoalConfiguration(String string, String string1, String string2, String string3) { return null; } @@ -1474,8 +1306,7 @@ public Xpp3Dom getGoalConfiguration( String string, String string1, String strin * @see org.apache.maven.project.MavenProject#getReportConfiguration(java.lang.String, java.lang.String, java.lang.String) */ @Override - public Xpp3Dom getReportConfiguration( String string, String string1, String string2 ) - { + public Xpp3Dom getReportConfiguration(String string, String string1, String string2) { return null; } @@ -1485,8 +1316,7 @@ public Xpp3Dom getReportConfiguration( String string, String string1, String str * @see org.apache.maven.project.MavenProject#getExecutionProject() */ @Override - public MavenProject getExecutionProject() - { + public MavenProject getExecutionProject() { return null; } @@ -1496,8 +1326,7 @@ public MavenProject getExecutionProject() * @see org.apache.maven.project.MavenProject#setExecutionProject(org.apache.maven.project.MavenProject) */ @Override - public void setExecutionProject( MavenProject mavenProject ) - { + public void setExecutionProject(MavenProject mavenProject) { // nop } @@ -1507,9 +1336,7 @@ public void setExecutionProject( MavenProject mavenProject ) * @see org.apache.maven.project.MavenProject#writeModel(java.io.Writer) */ @Override - public void writeModel( Writer writer ) - throws IOException - { + public void writeModel(Writer writer) throws IOException { // nop } @@ -1519,51 +1346,43 @@ public void writeModel( Writer writer ) * @see org.apache.maven.project.MavenProject#writeOriginalModel(java.io.Writer) */ @Override - public void writeOriginalModel( Writer writer ) - throws IOException - { + public void writeOriginalModel(Writer writer) throws IOException { // nop } /** {@inheritDoc} */ @Override - public Set getDependencyArtifacts() - { + public Set getDependencyArtifacts() { return dependencyArtifacts; } /** {@inheritDoc} */ @Override - public void setDependencyArtifacts( Set set ) - { + public void setDependencyArtifacts(Set set) { this.dependencyArtifacts = set; } /** {@inheritDoc} */ @Override - public void setReleaseArtifactRepository( ArtifactRepository artifactRepository ) - { + public void setReleaseArtifactRepository(ArtifactRepository artifactRepository) { this.releaseArtifactRepository = artifactRepository; } /** {@inheritDoc} */ @Override - public void setSnapshotArtifactRepository( ArtifactRepository artifactRepository ) - { + public void setSnapshotArtifactRepository(ArtifactRepository artifactRepository) { this.snapshotArtifactRepository = artifactRepository; } /** {@inheritDoc} */ @Override - public void setOriginalModel( Model model ) - { + public void setOriginalModel(Model model) { this.originalModel = model; } /** {@inheritDoc} */ @Override - public Model getOriginalModel() - { + public Model getOriginalModel() { return originalModel; } @@ -1573,8 +1392,7 @@ public Model getOriginalModel() * @see org.apache.maven.project.MavenProject#getBuildExtensions() */ @Override - public List getBuildExtensions() - { + public List getBuildExtensions() { return Collections.emptyList(); } @@ -1584,9 +1402,8 @@ public List getBuildExtensions() * @see org.apache.maven.project.MavenProject#createArtifacts(org.apache.maven.artifact.factory.ArtifactFactory, java.lang.String, org.apache.maven.artifact.resolver.filter.ArtifactFilter) */ @Override - public Set createArtifacts( ArtifactFactory artifactFactory, String string, - ArtifactFilter artifactFilter ) - { + public Set createArtifacts( + ArtifactFactory artifactFactory, String string, ArtifactFilter artifactFilter) { return Collections.emptySet(); } @@ -1596,8 +1413,7 @@ public Set createArtifacts( ArtifactFactory artifactFactory, String st * @see org.apache.maven.project.MavenProject#addProjectReference(org.apache.maven.project.MavenProject) */ @Override - public void addProjectReference( MavenProject mavenProject ) - { + public void addProjectReference(MavenProject mavenProject) { // nop } @@ -1607,8 +1423,7 @@ public void addProjectReference( MavenProject mavenProject ) * @see org.apache.maven.project.MavenProject#attachArtifact(java.lang.String, java.lang.String, java.io.File) */ @Override - public void attachArtifact( String string, String string1, File file ) - { + public void attachArtifact(String string, String string1, File file) { // nop } @@ -1618,8 +1433,7 @@ public void attachArtifact( String string, String string1, File file ) * @see org.apache.maven.project.MavenProject#getProperties() */ @Override - public Properties getProperties() - { + public Properties getProperties() { return new Properties(); } @@ -1629,8 +1443,7 @@ public Properties getProperties() * @see org.apache.maven.project.MavenProject#getFilters() */ @Override - public List getFilters() - { + public List getFilters() { return Collections.emptyList(); } @@ -1640,29 +1453,25 @@ public List getFilters() * @see org.apache.maven.project.MavenProject#getProjectReferences() */ @Override - public Map getProjectReferences() - { + public Map getProjectReferences() { return Collections.emptyMap(); } /** {@inheritDoc} */ @Override - public boolean isExecutionRoot() - { + public boolean isExecutionRoot() { return executionRoot; } /** {@inheritDoc} */ @Override - public void setExecutionRoot( boolean b ) - { + public void setExecutionRoot(boolean b) { this.executionRoot = b; } /** {@inheritDoc} */ @Override - public String getDefaultGoal() - { + public String getDefaultGoal() { return defaultGoal; } @@ -1672,8 +1481,7 @@ public String getDefaultGoal() * @see org.apache.maven.project.MavenProject#replaceWithActiveArtifact(org.apache.maven.artifact.Artifact) */ @Override - public Artifact replaceWithActiveArtifact( Artifact artifact ) - { + public Artifact replaceWithActiveArtifact(Artifact artifact) { return null; } } diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java index 3a5d7cb9..f680709a 100644 --- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java +++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing.stubs; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 + * 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 @@ -18,6 +16,11 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing.stubs; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.ArtifactMetadata; @@ -27,16 +30,10 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.repository.Proxy; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - /** * @author Brian Fox */ -public class StubArtifactRepository - implements ArtifactRepository -{ +public class StubArtifactRepository implements ArtifactRepository { private String baseDir = null; /** @@ -44,8 +41,7 @@ public class StubArtifactRepository * * @param dir the basedir */ - public StubArtifactRepository( String dir ) - { + public StubArtifactRepository(String dir) { baseDir = dir; } @@ -54,8 +50,7 @@ public StubArtifactRepository( String dir ) * @see org.apache.maven.artifact.repository.ArtifactRepository#pathOf(org.apache.maven.artifact.Artifact) */ @Override - public String pathOf( Artifact artifact ) - { + public String pathOf(Artifact artifact) { return artifact.getId(); } @@ -64,8 +59,7 @@ public String pathOf( Artifact artifact ) * @see org.apache.maven.artifact.repository.ArtifactRepository#pathOfRemoteRepositoryMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata) */ @Override - public String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata ) - { + public String pathOfRemoteRepositoryMetadata(ArtifactMetadata artifactMetadata) { return null; } @@ -74,9 +68,8 @@ public String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata * @see org.apache.maven.artifact.repository.ArtifactRepository#pathOfLocalRepositoryMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata, org.apache.maven.artifact.repository.ArtifactRepository) */ @Override - public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository ) - { - return metadata.getLocalFilename( repository ); + public String pathOfLocalRepositoryMetadata(ArtifactMetadata metadata, ArtifactRepository repository) { + return metadata.getLocalFilename(repository); } /** @@ -84,8 +77,7 @@ public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, Artifact * @see org.apache.maven.artifact.repository.ArtifactRepository#getUrl() */ @Override - public String getUrl() - { + public String getUrl() { return null; } @@ -94,8 +86,7 @@ public String getUrl() * @see org.apache.maven.artifact.repository.ArtifactRepository#getBasedir() */ @Override - public String getBasedir() - { + public String getBasedir() { return baseDir; } @@ -104,8 +95,7 @@ public String getBasedir() * @see org.apache.maven.artifact.repository.ArtifactRepository#getProtocol() */ @Override - public String getProtocol() - { + public String getProtocol() { return null; } @@ -114,8 +104,7 @@ public String getProtocol() * @see org.apache.maven.artifact.repository.ArtifactRepository#getId() */ @Override - public String getId() - { + public String getId() { return null; } @@ -124,8 +113,7 @@ public String getId() * @see org.apache.maven.artifact.repository.ArtifactRepository#getSnapshots() */ @Override - public ArtifactRepositoryPolicy getSnapshots() - { + public ArtifactRepositoryPolicy getSnapshots() { return null; } @@ -134,8 +122,7 @@ public ArtifactRepositoryPolicy getSnapshots() * @see org.apache.maven.artifact.repository.ArtifactRepository#getReleases() */ @Override - public ArtifactRepositoryPolicy getReleases() - { + public ArtifactRepositoryPolicy getReleases() { return null; } @@ -144,8 +131,7 @@ public ArtifactRepositoryPolicy getReleases() * @see org.apache.maven.artifact.repository.ArtifactRepository#getLayout() */ @Override - public ArtifactRepositoryLayout getLayout() - { + public ArtifactRepositoryLayout getLayout() { return null; } @@ -154,8 +140,7 @@ public ArtifactRepositoryLayout getLayout() * @see org.apache.maven.artifact.repository.ArtifactRepository#getKey() */ @Override - public String getKey() - { + public String getKey() { return null; } @@ -164,8 +149,7 @@ public String getKey() * @see org.apache.maven.artifact.repository.ArtifactRepository#isUniqueVersion() */ @Override - public boolean isUniqueVersion() - { + public boolean isUniqueVersion() { return false; } @@ -175,8 +159,7 @@ public boolean isUniqueVersion() * @see org.apache.maven.artifact.repository.ArtifactRepository#setBlacklisted(boolean) */ @Override - public void setBlacklisted( boolean blackListed ) - { + public void setBlacklisted(boolean blackListed) { // nop } @@ -185,105 +168,74 @@ public void setBlacklisted( boolean blackListed ) * @see org.apache.maven.artifact.repository.ArtifactRepository#isBlacklisted() */ @Override - public boolean isBlacklisted() - { + public boolean isBlacklisted() { return false; } @Override - public Artifact find( Artifact artifact ) - { + public Artifact find(Artifact artifact) { // TODO Auto-generated method stub return null; } @Override - public Authentication getAuthentication() - { + public Authentication getAuthentication() { return null; } @Override - public Proxy getProxy() - { + public Proxy getProxy() { return null; } @Override - public void setAuthentication( Authentication authentication ) - { - - } + public void setAuthentication(Authentication authentication) {} @Override - public void setId( String id ) - { - - } + public void setId(String id) {} @Override - public void setLayout( ArtifactRepositoryLayout layout ) - { - - } + public void setLayout(ArtifactRepositoryLayout layout) {} @Override - public void setProxy( Proxy proxy ) - { - - } + public void setProxy(Proxy proxy) {} @Override - public void setReleaseUpdatePolicy( ArtifactRepositoryPolicy policy ) - { - - } + public void setReleaseUpdatePolicy(ArtifactRepositoryPolicy policy) {} @Override - public void setSnapshotUpdatePolicy( ArtifactRepositoryPolicy policy ) - { - - } + public void setSnapshotUpdatePolicy(ArtifactRepositoryPolicy policy) {} @Override - public void setUrl( String url ) - { - - } + public void setUrl(String url) {} @Override - public List findVersions( Artifact artifact ) - { + public List findVersions(Artifact artifact) { return Collections.emptyList(); } @Override - public boolean isProjectAware() - { + public boolean isProjectAware() { return false; } @Override - public List getMirroredRepositories() - { - return new ArrayList<>( 0 ); + public List getMirroredRepositories() { + return new ArrayList<>(0); } @Override - public void setMirroredRepositories( List artifactRepositories ) - { + public void setMirroredRepositories(List artifactRepositories) { // no op } @Override - public boolean isBlocked() - { + public boolean isBlocked() { return false; } @Override - public void setBlocked( boolean blocked ) - { + public void setBlocked(boolean blocked) { // no op } } diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/api/plugin/testing/ExpressionEvaluatorTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/api/plugin/testing/ExpressionEvaluatorTest.java index b86a8d07..f461ef3d 100644 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/api/plugin/testing/ExpressionEvaluatorTest.java +++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/api/plugin/testing/ExpressionEvaluatorTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.api.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.api.plugin.testing; import javax.inject.Named; @@ -27,8 +26,6 @@ import com.google.inject.Provides; import org.apache.maven.api.Session; import org.apache.maven.api.plugin.MojoException; -import org.apache.maven.api.plugin.testing.InjectMojo; -import org.apache.maven.api.plugin.testing.MojoTest; import org.apache.maven.api.plugin.testing.stubs.SessionStub; import org.codehaus.plexus.util.StringUtils; import org.junit.jupiter.api.Test; @@ -41,14 +38,12 @@ * @author Edwin Punzalan */ @MojoTest -public class ExpressionEvaluatorTest -{ +public class ExpressionEvaluatorTest { private static final String LOCAL_REPO = "target/local-repo/"; private static final String ARTIFACT_ID = "maven-test-mojo"; private static final String COORDINATES = "groupId:" + ARTIFACT_ID + ":version:goal"; - private static final String CONFIG = - "\n" + private static final String CONFIG = "\n" + " \n" + " \n" + " \n" @@ -63,49 +58,39 @@ public class ExpressionEvaluatorTest + "\n"; @Test - @InjectMojo( goal = COORDINATES, pom = CONFIG ) - public void testInjection( ExpressionEvaluatorMojo mojo ) - { - assertDoesNotThrow( mojo::execute ); + @InjectMojo(goal = COORDINATES, pom = CONFIG) + public void testInjection(ExpressionEvaluatorMojo mojo) { + assertDoesNotThrow(mojo::execute); } - @Named( COORDINATES ) - public static class ExpressionEvaluatorMojo - implements org.apache.maven.api.plugin.Mojo - { + @Named(COORDINATES) + public static class ExpressionEvaluatorMojo implements org.apache.maven.api.plugin.Mojo { private String basedir; private String workdir; /** {@inheritDoc} */ @Override - public void execute() - throws MojoException - { - if ( StringUtils.isEmpty( basedir ) ) - { - throw new MojoException( "basedir was not injected." ); + public void execute() throws MojoException { + if (StringUtils.isEmpty(basedir)) { + throw new MojoException("basedir was not injected."); } - if ( StringUtils.isEmpty( workdir ) ) - { - throw new MojoException( "workdir was not injected." ); - } - else if ( !workdir.startsWith( basedir ) ) - { - throw new MojoException( "workdir does not start with basedir." ); + if (StringUtils.isEmpty(workdir)) { + throw new MojoException("workdir was not injected."); + } else if (!workdir.startsWith(basedir)) { + throw new MojoException("workdir does not start with basedir."); } } } - @Provides @SuppressWarnings( "unused" ) - Session session() - { - Session session = SessionStub.getMockSession( LOCAL_REPO ); - doReturn( new Properties() ).when( session ).getSystemProperties(); - doReturn( new Properties() ).when( session ).getUserProperties(); - doAnswer( iom -> Paths.get( MojoExtension.getBasedir() ) ).when( session ).getExecutionRootDirectory(); + @Provides + @SuppressWarnings("unused") + Session session() { + Session session = SessionStub.getMockSession(LOCAL_REPO); + doReturn(new Properties()).when(session).getSystemProperties(); + doReturn(new Properties()).when(session).getUserProperties(); + doAnswer(iom -> Paths.get(MojoExtension.getBasedir())).when(session).getExecutionRootDirectory(); return session; } - } diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ArtifactStubFactoryTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ArtifactStubFactoryTest.java index 52070bf2..b7c90972 100644 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ArtifactStubFactoryTest.java +++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ArtifactStubFactoryTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,20 +16,18 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; import java.io.IOException; -import junit.framework.TestCase; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -public class ArtifactStubFactoryTest -{ +public class ArtifactStubFactoryTest { @Test - public void testVersionChecks() throws IOException - { + public void testVersionChecks() throws IOException { ArtifactStubFactory factory = new ArtifactStubFactory(); assertTrue(factory.getReleaseArtifact().isRelease()); assertFalse(factory.getReleaseArtifact().isSnapshot()); @@ -40,8 +36,7 @@ public void testVersionChecks() throws IOException } @Test - public void testCreateFiles() throws IOException - { + public void testCreateFiles() throws IOException { ArtifactStubFactory factory = new ArtifactStubFactory(); assertFalse(factory.isCreateFiles()); } diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorMojo.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorMojo.java index 2d4faa0d..f199e6d7 100644 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorMojo.java +++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.plugin.AbstractMojo; @@ -28,9 +27,7 @@ /** * @author Edwin Punzalan */ -public class ExpressionEvaluatorMojo - extends AbstractMojo -{ +public class ExpressionEvaluatorMojo extends AbstractMojo { private String basedir; private ArtifactRepository localRepository; @@ -39,26 +36,19 @@ public class ExpressionEvaluatorMojo /** {@inheritDoc} */ @Override - public void execute() - throws MojoExecutionException, MojoFailureException - { - if ( StringUtils.isEmpty( basedir ) ) - { - throw new MojoExecutionException( "basedir was not injected." ); + public void execute() throws MojoExecutionException, MojoFailureException { + if (StringUtils.isEmpty(basedir)) { + throw new MojoExecutionException("basedir was not injected."); } - if ( localRepository == null ) - { - throw new MojoExecutionException( "localRepository was not injected." ); + if (localRepository == null) { + throw new MojoExecutionException("localRepository was not injected."); } - if ( StringUtils.isEmpty( workdir ) ) - { - throw new MojoExecutionException( "workdir was not injected." ); - } - else if ( !workdir.startsWith( basedir ) ) - { - throw new MojoExecutionException( "workdir does not start with basedir." ); + if (StringUtils.isEmpty(workdir)) { + throw new MojoExecutionException("workdir was not injected."); + } else if (!workdir.startsWith(basedir)) { + throw new MojoExecutionException("workdir does not start with basedir."); } } } diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorTest.java index 3939bd2b..08849c5b 100644 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorTest.java +++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,70 +16,63 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; + +import java.io.StringReader; import org.apache.maven.plugin.MojoExecutionException; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.Xpp3DomBuilder; -import java.io.StringReader; - /** * @author Edwin Punzalan */ -public class ExpressionEvaluatorTest - extends AbstractMojoTestCase -{ +public class ExpressionEvaluatorTest extends AbstractMojoTestCase { private Xpp3Dom pomDom; private PlexusConfiguration pluginConfiguration; /** {@inheritDoc} */ @Override - protected void setUp() - throws Exception - { + protected void setUp() throws Exception { super.setUp(); StringBuffer pom = new StringBuffer(); - pom.append( "" ).append( "\n" ); - pom.append( " " ).append( "\n" ); - pom.append( " " ).append( "\n" ); - pom.append( " " ).append( "\n" ); - pom.append( " maven-test-mojo" ).append( "\n" ); - pom.append( " " ).append( "\n" ); - pom.append( " ${basedir}" ).append( "\n" ); - pom.append( " ${basedir}/workDirectory" ).append( "\n" ); - pom.append( " ${localRepository}" ).append( "\n" ); - pom.append( " " ).append( "\n" ); - pom.append( " " ).append( "\n" ); - pom.append( " " ).append( "\n" ); - pom.append( " " ).append( "\n" ); - pom.append( "" ).append( "\n" ); + pom.append("").append("\n"); + pom.append(" ").append("\n"); + pom.append(" ").append("\n"); + pom.append(" ").append("\n"); + pom.append(" maven-test-mojo").append("\n"); + pom.append(" ").append("\n"); + pom.append(" ${basedir}").append("\n"); + pom.append(" ${basedir}/workDirectory").append("\n"); + pom.append(" ${localRepository}") + .append("\n"); + pom.append(" ").append("\n"); + pom.append(" ").append("\n"); + pom.append(" ").append("\n"); + pom.append(" ").append("\n"); + pom.append("").append("\n"); - pomDom = Xpp3DomBuilder.build( new StringReader( pom.toString() ) ); + pomDom = Xpp3DomBuilder.build(new StringReader(pom.toString())); - pluginConfiguration = extractPluginConfiguration( "maven-test-mojo", pomDom ); + pluginConfiguration = extractPluginConfiguration("maven-test-mojo", pomDom); } /** * @throws Exception if any */ - public void testInjection() - throws Exception - { + public void testInjection() throws Exception { ExpressionEvaluatorMojo mojo = new ExpressionEvaluatorMojo(); - mojo = (ExpressionEvaluatorMojo) configureMojo( mojo, pluginConfiguration ); + mojo = (ExpressionEvaluatorMojo) configureMojo(mojo, pluginConfiguration); - try - { + try { mojo.execute(); - } - catch ( MojoExecutionException e ) - { - fail( e.getMessage() ); + } catch (MojoExecutionException e) { + fail(e.getMessage()); } } } diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoRuleTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoRuleTest.java index 86a3902a..105623d5 100644 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoRuleTest.java +++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoRuleTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; import java.io.File; import java.io.StringReader; @@ -37,21 +36,19 @@ /** * @author Mirko Friedenhagen */ -public class MojoRuleTest - -{ +public class MojoRuleTest { + private boolean beforeWasCalled = false; @Rule public MojoRule rule = new MojoRule() { @Override - protected void before() throws Throwable - { + protected void before() throws Throwable { beforeWasCalled = true; - } + } }; - + private String pom; private Xpp3Dom pomDom; @@ -60,136 +57,114 @@ protected void before() throws Throwable /** {@inheritDoc} */ @Before - public void setUp() - throws Exception - { - - pom = - "" + - "" + - "" + - "" + - "maven-simple-plugin" + - "" + - "valueOne" + - "valueTwo" + - "" + - "" + - "" + - "" + - ""; - - pomDom = Xpp3DomBuilder.build( new StringReader( pom ) ); - - pluginConfiguration = rule.extractPluginConfiguration( "maven-simple-plugin", pomDom ); + public void setUp() throws Exception { + + pom = "" + "" + + "" + + "" + + "maven-simple-plugin" + + "" + + "valueOne" + + "valueTwo" + + "" + + "" + + "" + + "" + + ""; + + pomDom = Xpp3DomBuilder.build(new StringReader(pom)); + + pluginConfiguration = rule.extractPluginConfiguration("maven-simple-plugin", pomDom); } /** * @throws Exception if any */ @Test - public void testPluginConfigurationExtraction() - throws Exception - { - assertEquals( "valueOne", pluginConfiguration.getChild( "keyOne" ).getValue() ); + public void testPluginConfigurationExtraction() throws Exception { + assertEquals("valueOne", pluginConfiguration.getChild("keyOne").getValue()); - assertEquals( "valueTwo", pluginConfiguration.getChild( "keyTwo" ).getValue() ); + assertEquals("valueTwo", pluginConfiguration.getChild("keyTwo").getValue()); } /** * @throws Exception if any */ @Test - public void testMojoConfiguration() - throws Exception - { + public void testMojoConfiguration() throws Exception { SimpleMojo mojo = new SimpleMojo(); - mojo = rule.configureMojo( mojo, pluginConfiguration ); + mojo = rule.configureMojo(mojo, pluginConfiguration); - assertEquals( "valueOne", mojo.getKeyOne() ); + assertEquals("valueOne", mojo.getKeyOne()); - assertEquals( "valueTwo", mojo.getKeyTwo() ); + assertEquals("valueTwo", mojo.getKeyTwo()); } /** * @throws Exception if any */ @Test - public void testVariableAccessWithoutGetter() - throws Exception - { + public void testVariableAccessWithoutGetter() throws Exception { SimpleMojo mojo = new SimpleMojo(); - mojo = rule.configureMojo( mojo, pluginConfiguration ); + mojo = rule.configureMojo(mojo, pluginConfiguration); - assertEquals( "valueOne", rule.getVariableValueFromObject( mojo, "keyOne" ) ); + assertEquals("valueOne", rule.getVariableValueFromObject(mojo, "keyOne")); - assertEquals( "valueTwo", rule.getVariableValueFromObject( mojo, "keyTwo" ) ); + assertEquals("valueTwo", rule.getVariableValueFromObject(mojo, "keyTwo")); } /** * @throws Exception if any */ - @Test - public void testVariableAccessWithoutGetter2() - throws Exception - { + @Test + public void testVariableAccessWithoutGetter2() throws Exception { SimpleMojo mojo = new SimpleMojo(); - mojo = rule.configureMojo( mojo, pluginConfiguration ); + mojo = rule.configureMojo(mojo, pluginConfiguration); - Map map = rule.getVariablesAndValuesFromObject( mojo ); + Map map = rule.getVariablesAndValuesFromObject(mojo); - assertEquals( "valueOne", map.get( "keyOne" ) ); + assertEquals("valueOne", map.get("keyOne")); - assertEquals( "valueTwo", map.get( "keyTwo" ) ); + assertEquals("valueTwo", map.get("keyTwo")); } /** * @throws Exception if any */ @Test - public void testSettingMojoVariables() - throws Exception - { + public void testSettingMojoVariables() throws Exception { SimpleMojo mojo = new SimpleMojo(); - mojo = rule.configureMojo( mojo, pluginConfiguration ); - - rule.setVariableValueToObject( mojo, "keyOne", "myValueOne" ); + mojo = rule.configureMojo(mojo, pluginConfiguration); - assertEquals( "myValueOne", rule.getVariableValueFromObject( mojo, "keyOne" ) ); + rule.setVariableValueToObject(mojo, "keyOne", "myValueOne"); + assertEquals("myValueOne", rule.getVariableValueFromObject(mojo, "keyOne")); } @Test @WithoutMojo - public void testNoRuleWrapper() - throws Exception - { - assertFalse( "before executed although WithMojo annotation was added", beforeWasCalled ); + public void testNoRuleWrapper() throws Exception { + assertFalse("before executed although WithMojo annotation was added", beforeWasCalled); } - @Test - public void testWithRuleWrapper() - throws Exception - { - assertTrue( "before executed because WithMojo annotation was not added", beforeWasCalled ); + @Test + public void testWithRuleWrapper() throws Exception { + assertTrue("before executed because WithMojo annotation was not added", beforeWasCalled); } /** * @throws Exception if any */ @Test - public void testLookupInitializedMojo() - throws Exception - { - File pomBaseDir = new File( "src/test/projects/property" ); - ParametersMojo mojo = rule.lookupConfiguredMojo( pomBaseDir, "parameters" ); - assertEquals( "default", rule.getVariableValueFromObject( mojo, "withDefault" ) ); - assertEquals( "propertyValue", rule.getVariableValueFromObject( mojo, "withProperty" ) ); - assertEquals( "propertyValue", rule.getVariableValueFromObject( mojo, "withPropertyAndDefault" ) ); + public void testLookupInitializedMojo() throws Exception { + File pomBaseDir = new File("src/test/projects/property"); + ParametersMojo mojo = rule.lookupConfiguredMojo(pomBaseDir, "parameters"); + assertEquals("default", rule.getVariableValueFromObject(mojo, "withDefault")); + assertEquals("propertyValue", rule.getVariableValueFromObject(mojo, "withProperty")); + assertEquals("propertyValue", rule.getVariableValueFromObject(mojo, "withPropertyAndDefault")); } - } diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoTestCaseTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoTestCaseTest.java index 8cf1f23d..1fa89472 100644 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoTestCaseTest.java +++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoTestCaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,22 +16,21 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; + +import java.io.StringReader; +import java.util.Map; import org.apache.maven.api.plugin.testing.MojoTest; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.Xpp3DomBuilder; -import java.io.StringReader; -import java.util.Map; - /** * @author Jason van Zyl */ @MojoTest -public class MojoTestCaseTest - extends AbstractMojoTestCase -{ +public class MojoTestCaseTest extends AbstractMojoTestCase { private String pom; private Xpp3Dom pomDom; @@ -42,103 +39,87 @@ public class MojoTestCaseTest /** {@inheritDoc} */ @Override - protected void setUp() - throws Exception - { + protected void setUp() throws Exception { super.setUp(); - pom = - "" + - "" + - "" + - "" + - "maven-simple-plugin" + - "" + - "valueOne" + - "valueTwo" + - "" + - "" + - "" + - "" + - ""; - - pomDom = Xpp3DomBuilder.build( new StringReader( pom ) ); - - pluginConfiguration = extractPluginConfiguration( "maven-simple-plugin", pomDom ); + pom = "" + "" + + "" + + "" + + "maven-simple-plugin" + + "" + + "valueOne" + + "valueTwo" + + "" + + "" + + "" + + "" + + ""; + + pomDom = Xpp3DomBuilder.build(new StringReader(pom)); + + pluginConfiguration = extractPluginConfiguration("maven-simple-plugin", pomDom); } /** * @throws Exception if any */ - public void testPluginConfigurationExtraction() - throws Exception - { - assertEquals( "valueOne", pluginConfiguration.getChild( "keyOne" ).getValue() ); + public void testPluginConfigurationExtraction() throws Exception { + assertEquals("valueOne", pluginConfiguration.getChild("keyOne").getValue()); - assertEquals( "valueTwo", pluginConfiguration.getChild( "keyTwo" ).getValue() ); + assertEquals("valueTwo", pluginConfiguration.getChild("keyTwo").getValue()); } /** * @throws Exception if any */ - public void testMojoConfiguration() - throws Exception - { + public void testMojoConfiguration() throws Exception { SimpleMojo mojo = new SimpleMojo(); - mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration ); + mojo = (SimpleMojo) configureMojo(mojo, pluginConfiguration); - assertEquals( "valueOne", mojo.getKeyOne() ); + assertEquals("valueOne", mojo.getKeyOne()); - assertEquals( "valueTwo", mojo.getKeyTwo() ); + assertEquals("valueTwo", mojo.getKeyTwo()); } /** * @throws Exception if any */ - public void testVariableAccessWithoutGetter() - throws Exception - { + public void testVariableAccessWithoutGetter() throws Exception { SimpleMojo mojo = new SimpleMojo(); - mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration ); + mojo = (SimpleMojo) configureMojo(mojo, pluginConfiguration); - assertEquals( "valueOne", (String)getVariableValueFromObject( mojo, "keyOne" ) ); + assertEquals("valueOne", (String) getVariableValueFromObject(mojo, "keyOne")); - assertEquals( "valueTwo", (String)getVariableValueFromObject( mojo, "keyTwo" ) ); + assertEquals("valueTwo", (String) getVariableValueFromObject(mojo, "keyTwo")); } /** * @throws Exception if any */ - public void testVariableAccessWithoutGetter2() - throws Exception - { + public void testVariableAccessWithoutGetter2() throws Exception { SimpleMojo mojo = new SimpleMojo(); - mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration ); + mojo = (SimpleMojo) configureMojo(mojo, pluginConfiguration); - Map map = getVariablesAndValuesFromObject( mojo ); + Map map = getVariablesAndValuesFromObject(mojo); - assertEquals( "valueOne", (String)map.get( "keyOne" ) ); + assertEquals("valueOne", (String) map.get("keyOne")); - assertEquals( "valueTwo", (String)map.get( "keyTwo" ) ); + assertEquals("valueTwo", (String) map.get("keyTwo")); } /** * @throws Exception if any */ - public void testSettingMojoVariables() - throws Exception - { + public void testSettingMojoVariables() throws Exception { SimpleMojo mojo = new SimpleMojo(); - mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration ); + mojo = (SimpleMojo) configureMojo(mojo, pluginConfiguration); - setVariableValueToObject( mojo, "keyOne", "myValueOne" ); - - assertEquals( "myValueOne", (String)getVariableValueFromObject( mojo, "keyOne" ) ); + setVariableValueToObject(mojo, "keyOne", "myValueOne"); + assertEquals("myValueOne", (String) getVariableValueFromObject(mojo, "keyOne")); } - } diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojo.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojo.java index 13d30298..255f3e3f 100644 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojo.java +++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,14 +16,13 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -public class ParametersMojo - extends AbstractMojo -{ +public class ParametersMojo extends AbstractMojo { public String plain; public String withProperty; @@ -35,8 +32,5 @@ public class ParametersMojo public String withPropertyAndDefault; @Override - public void execute() - throws MojoExecutionException, MojoFailureException - { - } + public void execute() throws MojoExecutionException, MojoFailureException {} } diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojoTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojoTest.java index c009a5b6..ce7869c0 100644 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojoTest.java +++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojoTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; import java.io.File; @@ -31,78 +30,66 @@ import org.apache.maven.project.ProjectBuildingRequest; import org.eclipse.aether.DefaultRepositorySystemSession; -public class ParametersMojoTest - extends AbstractMojoTestCase -{ - public void testDefault() - throws Exception - { - MavenProject project = readMavenProject( new File( "src/test/projects/default" ) ); +public class ParametersMojoTest extends AbstractMojoTestCase { + public void testDefault() throws Exception { + MavenProject project = readMavenProject(new File("src/test/projects/default")); - ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo( project, "parameters" ); + ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo(project, "parameters"); - assertNull( mojo.plain ); - assertNull( mojo.withProperty ); - assertEquals( "default", mojo.withDefault ); - assertEquals( "default", mojo.withPropertyAndDefault ); + assertNull(mojo.plain); + assertNull(mojo.withProperty); + assertEquals("default", mojo.withDefault); + assertEquals("default", mojo.withPropertyAndDefault); } - public void testExplicit() - throws Exception - { - MavenProject project = readMavenProject( new File( "src/test/projects/explicit" ) ); + public void testExplicit() throws Exception { + MavenProject project = readMavenProject(new File("src/test/projects/explicit")); - ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo( project, "parameters" ); + ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo(project, "parameters"); - assertEquals( "explicitValue", mojo.plain ); - assertEquals( "explicitWithPropertyValue", mojo.withProperty ); - assertEquals( "explicitWithDefaultValue", mojo.withDefault ); - assertEquals( "explicitWithPropertyAndDefaultValue", mojo.withPropertyAndDefault ); + assertEquals("explicitValue", mojo.plain); + assertEquals("explicitWithPropertyValue", mojo.withProperty); + assertEquals("explicitWithDefaultValue", mojo.withDefault); + assertEquals("explicitWithPropertyAndDefaultValue", mojo.withPropertyAndDefault); } - public void testDefaultWithProperty() - throws Exception - { - MavenProject project = readMavenProject( new File( "src/test/projects/default" ) ); - MavenSession session = newMavenSession( project ); - MojoExecution execution = newMojoExecution( "parameters" ); + public void testDefaultWithProperty() throws Exception { + MavenProject project = readMavenProject(new File("src/test/projects/default")); + MavenSession session = newMavenSession(project); + MojoExecution execution = newMojoExecution("parameters"); - session.getUserProperties().put( "property", "propertyValue" ); - ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo( session, execution ); + session.getUserProperties().put("property", "propertyValue"); + ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo(session, execution); - assertNull( mojo.plain ); - assertEquals( "propertyValue", mojo.withProperty ); - assertEquals( "default", mojo.withDefault ); - assertEquals( "propertyValue", mojo.withPropertyAndDefault ); + assertNull(mojo.plain); + assertEquals("propertyValue", mojo.withProperty); + assertEquals("default", mojo.withDefault); + assertEquals("propertyValue", mojo.withPropertyAndDefault); } - public void testExplicitWithProperty() - throws Exception - { - MavenProject project = readMavenProject( new File( "src/test/projects/explicit" ) ); - MavenSession session = newMavenSession( project ); - MojoExecution execution = newMojoExecution( "parameters" ); + public void testExplicitWithProperty() throws Exception { + MavenProject project = readMavenProject(new File("src/test/projects/explicit")); + MavenSession session = newMavenSession(project); + MojoExecution execution = newMojoExecution("parameters"); - session.getUserProperties().put( "property", "propertyValue" ); - ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo( session, execution ); + session.getUserProperties().put("property", "propertyValue"); + ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo(session, execution); - assertEquals( "explicitValue", mojo.plain ); - assertEquals( "explicitWithPropertyValue", mojo.withProperty ); - assertEquals( "explicitWithDefaultValue", mojo.withDefault ); - assertEquals( "explicitWithPropertyAndDefaultValue", mojo.withPropertyAndDefault ); + assertEquals("explicitValue", mojo.plain); + assertEquals("explicitWithPropertyValue", mojo.withProperty); + assertEquals("explicitWithDefaultValue", mojo.withDefault); + assertEquals("explicitWithPropertyAndDefaultValue", mojo.withPropertyAndDefault); } - protected MavenProject readMavenProject( File basedir ) - throws ProjectBuildingException, Exception - { - File pom = new File( basedir, "pom.xml" ); + protected MavenProject readMavenProject(File basedir) throws ProjectBuildingException, Exception { + File pom = new File(basedir, "pom.xml"); MavenExecutionRequest request = new DefaultMavenExecutionRequest(); - request.setBaseDirectory( basedir ); + request.setBaseDirectory(basedir); ProjectBuildingRequest configuration = request.getProjectBuildingRequest(); - configuration.setRepositorySession( new DefaultRepositorySystemSession() ); - MavenProject project = lookup( ProjectBuilder.class ).build( pom, configuration ).getProject(); - assertNotNull( project ); + configuration.setRepositorySession(new DefaultRepositorySystemSession()); + MavenProject project = + lookup(ProjectBuilder.class).build(pom, configuration).getProject(); + assertNotNull(project); return project; } - } diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/PluginArtifactFileTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/PluginArtifactFileTest.java index c4f32be6..6025f21c 100644 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/PluginArtifactFileTest.java +++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/PluginArtifactFileTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,31 +16,29 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; import java.util.List; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecution; -public class PluginArtifactFileTest - extends AbstractMojoTestCase -{ - private static final String FS = System.getProperty( "file.separator" ); - - public void testArtifact() - throws Exception - { - MojoExecution execution = newMojoExecution( "parameters" ); // TODO dedicated test mojo - - List artifacts = execution.getMojoDescriptor().getPluginDescriptor().getArtifacts(); - - assertEquals( 1, artifacts.size() ); - - Artifact artifact = artifacts.get( 0 ); - assertEquals( "test", artifact.getGroupId() ); - assertEquals( "test-plugin", artifact.getArtifactId() ); - assertEquals( "0.0.1-SNAPSHOT", artifact.getBaseVersion() ); - assertTrue( artifact.getFile().getAbsolutePath().endsWith( FS + "target" + FS + "test-classes" ) ); +public class PluginArtifactFileTest extends AbstractMojoTestCase { + private static final String FS = System.getProperty("file.separator"); + + public void testArtifact() throws Exception { + MojoExecution execution = newMojoExecution("parameters"); // TODO dedicated test mojo + + List artifacts = + execution.getMojoDescriptor().getPluginDescriptor().getArtifacts(); + + assertEquals(1, artifacts.size()); + + Artifact artifact = artifacts.get(0); + assertEquals("test", artifact.getGroupId()); + assertEquals("test-plugin", artifact.getArtifactId()); + assertEquals("0.0.1-SNAPSHOT", artifact.getBaseVersion()); + assertTrue(artifact.getFile().getAbsolutePath().endsWith(FS + "target" + FS + "test-classes")); } // TODO find a way to automate testing of jar:file:/ test plugin URLs diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/SimpleMojo.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/SimpleMojo.java index 85ea293b..e284ea2b 100644 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/SimpleMojo.java +++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/SimpleMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -25,26 +24,19 @@ /** * @author Jason van Zyl */ -public class SimpleMojo - extends AbstractMojo -{ +public class SimpleMojo extends AbstractMojo { private String keyOne; private String keyTwo; - public String getKeyOne() - { + public String getKeyOne() { return keyOne; } - public String getKeyTwo() - { + public String getKeyTwo() { return keyTwo; } @Override - public void execute() - throws MojoExecutionException - { - } + public void execute() throws MojoExecutionException {} } diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/TestSilentLog.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/TestSilentLog.java index 4d782df0..69b2ed3e 100644 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/TestSilentLog.java +++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/TestSilentLog.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 + * 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 @@ -18,57 +16,53 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing; import junit.framework.TestCase; - import org.apache.maven.plugin.logging.Log; import org.codehaus.plexus.logging.Logger; -public class TestSilentLog - extends TestCase -{ +public class TestSilentLog extends TestCase { - public void testLog() - { + public void testLog() { Log log = new SilentLog(); - String text = new String( "Text" ); + String text = new String("Text"); Throwable e = new RuntimeException(); - log.debug( text ); - log.debug( text, e ); - log.debug( e ); - log.info( text ); - log.info( text, e ); - log.info( e ); - log.warn( text ); - log.warn( text, e ); - log.warn( e ); - log.error( text ); - log.error( text, e ); - log.error( e ); + log.debug(text); + log.debug(text, e); + log.debug(e); + log.info(text); + log.info(text, e); + log.info(e); + log.warn(text); + log.warn(text, e); + log.warn(e); + log.error(text); + log.error(text, e); + log.error(e); log.isDebugEnabled(); log.isErrorEnabled(); log.isWarnEnabled(); log.isInfoEnabled(); } - public void testLogger() - { + public void testLogger() { Logger log = new SilentLog(); - String text = new String( "Text" ); + String text = new String("Text"); Throwable e = new RuntimeException(); - log.debug( text ); - log.debug( text, e ); - log.error( text ); - log.error( text, e ); - log.warn( text ); - log.warn( text, e ); - log.info( text ); - log.info( text, e ); + log.debug(text); + log.debug(text, e); + log.error(text); + log.error(text, e); + log.warn(text); + log.warn(text, e); + log.info(text); + log.info(text, e); - log.fatalError( text ); - log.fatalError( text, e ); - log.getChildLogger( text ); + log.fatalError(text); + log.fatalError(text, e); + log.getChildLogger(text); log.getName(); log.getThreshold(); log.isDebugEnabled(); @@ -77,5 +71,4 @@ public void testLogger() log.isInfoEnabled(); log.isWarnEnabled(); } - } diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/resources/TestResourcesTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/resources/TestResourcesTest.java index c7a78e31..8ce1ecbf 100644 --- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/resources/TestResourcesTest.java +++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/resources/TestResourcesTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugin.testing.resources; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 + * 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 @@ -18,17 +16,15 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugin.testing.resources; import org.junit.Test; -public class TestResourcesTest -{ +public class TestResourcesTest { public TestResources resources = new TestResources(); - @Test( expected = IllegalStateException.class ) - public void testNoRuleAnnotation() - throws Exception - { - resources.getBasedir( "dummy" ); + @Test(expected = IllegalStateException.class) + public void testNoRuleAnnotation() throws Exception { + resources.getBasedir("dummy"); } } diff --git a/pom.xml b/pom.xml index 8fa30c73..aa07d4a9 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,4 @@ - - 4.0.0 - maven-parent org.apache.maven - 36 - + maven-parent + 39 + org.apache.maven.plugin-testing @@ -47,8 +45,8 @@ under the License. scm:git:https://gitbox.apache.org/repos/asf/maven-plugin-testing.git scm:git:https://gitbox.apache.org/repos/asf/maven-plugin-testing.git - https://github.com/apache/maven-plugin-testing/tree/${project.scm.tag} master + https://github.com/apache/maven-plugin-testing/tree/${project.scm.tag} jira