From 835a015801c4e1608432ea62248b5466bfd9a394 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Thu, 11 May 2023 00:47:42 +0200 Subject: [PATCH] Enable spotless - code reformat --- pom.xml | 10 +- .../buildhelper/AbstractAddResourceMojo.java | 30 +- .../AbstractDefinePropertyMojo.java | 113 ++-- .../AbstractRegexPropertyMojo.java | 74 +-- .../AbstractUpToDatePropertyMojo.java | 246 ++++----- .../mojo/buildhelper/AddResourceMojo.java | 16 +- .../mojo/buildhelper/AddSourceMojo.java | 23 +- .../mojo/buildhelper/AddTestResourceMojo.java | 16 +- .../mojo/buildhelper/AddTestSourceMojo.java | 23 +- .../codehaus/mojo/buildhelper/Artifact.java | 21 +- .../mojo/buildhelper/AttachArtifactMojo.java | 54 +- .../buildhelper/BeanshellPropertyMojo.java | 87 ++- .../mojo/buildhelper/CpuCountMojo.java | 129 +++-- .../mojo/buildhelper/HostnameMojo.java | 29 +- .../mojo/buildhelper/LocalIpMojo.java | 121 ++--- .../mojo/buildhelper/MavenVersionMojo.java | 16 +- .../mojo/buildhelper/ParseVersionMojo.java | 172 +++--- .../mojo/buildhelper/RegexPropertiesMojo.java | 118 ++--- .../mojo/buildhelper/RegexPropertyMojo.java | 46 +- .../buildhelper/RegexPropertySetting.java | 313 ++++++----- .../mojo/buildhelper/ReleasedVersionMojo.java | 312 ++++++----- .../buildhelper/RemoveLocalArtifactMojo.java | 48 +- .../buildhelper/ReserveListenerPortMojo.java | 382 +++++--------- .../mojo/buildhelper/RootLocationMojo.java | 99 ++-- .../buildhelper/TimestampPropertyMojo.java | 157 ++---- .../buildhelper/UpToDatePropertiesMojo.java | 147 +++--- .../buildhelper/UpToDatePropertyMojo.java | 179 +++---- .../buildhelper/UpToDatePropertySetting.java | 260 +++++---- .../versioning/DefaultVersioning.java | 55 +- .../versioning/VersionInformation.java | 144 ++--- .../buildhelper/versioning/Versioning.java | 4 +- .../mojo/buildhelper/FixtureUtils.java | 252 +++++---- .../mojo/buildhelper/ParseVersionTest.java | 495 ++++++++---------- .../versioning/VersionInformationTest.java | 101 ++-- 34 files changed, 1900 insertions(+), 2392 deletions(-) diff --git a/pom.xml b/pom.xml index 7c7db120..e402fc9f 100644 --- a/pom.xml +++ b/pom.xml @@ -11,10 +11,10 @@ build-helper-maven-plugin 3.4.0-SNAPSHOT maven-plugin - https://www.mojohaus.org/build-helper-maven-plugin/ Build Helper Maven Plugin This plugin contains various small independent goals to assist with Maven build lifecycle + https://www.mojohaus.org/build-helper-maven-plugin/ 2005 @@ -59,8 +59,8 @@ scm:git:https://github.com/mojohaus/build-helper-maven-plugin.git scm:git:ssh://git@github.com/mojohaus/build-helper-maven-plugin.git - https://github.com/mojohaus/build-helper-maven-plugin/tree/master HEAD + https://github.com/mojohaus/build-helper-maven-plugin/tree/master @@ -115,9 +115,9 @@ compile - org.apache.maven.shared - file-management - 3.1.0 + org.apache.maven.shared + file-management + 3.1.0 compile diff --git a/src/main/java/org/codehaus/mojo/buildhelper/AbstractAddResourceMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/AbstractAddResourceMojo.java index 9acbf99b..fe65429f 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/AbstractAddResourceMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/AbstractAddResourceMojo.java @@ -34,38 +34,33 @@ /** * Abstract Mojo for adding Resources */ -public abstract class AbstractAddResourceMojo - extends AbstractMojo -{ +public abstract class AbstractAddResourceMojo extends AbstractMojo { /** * Additional resource directories. */ - @Parameter( required = true ) + @Parameter(required = true) private Resource[] resources; /** * The maven project */ - @Parameter( readonly = true, defaultValue = "${project}" ) + @Parameter(readonly = true, defaultValue = "${project}") private MavenProject project; /** * Main plugin execution */ - public void execute() - { - for ( Resource resource : resources ) - { + public void execute() { + for (Resource resource : resources) { // Check for relative paths in the resource configuration. // http://maven.apache.org/plugin-developers/common-bugs.html#Resolving_Relative_Paths - File resourceDir = new File( resource.getDirectory() ); - if ( !resourceDir.isAbsolute() ) - { - resourceDir = new File( project.getBasedir(), resource.getDirectory() ); - resource.setDirectory( resourceDir.getAbsolutePath() ); + File resourceDir = new File(resource.getDirectory()); + if (!resourceDir.isAbsolute()) { + resourceDir = new File(project.getBasedir(), resource.getDirectory()); + resource.setDirectory(resourceDir.getAbsolutePath()); } - addResource( resource ); + addResource(resource); } } @@ -74,15 +69,14 @@ public void execute() * * @param resource the resource to add */ - public abstract void addResource( Resource resource ); + public abstract void addResource(Resource resource); /** * Get the current project instance. * * @return the project */ - public MavenProject getProject() - { + public MavenProject getProject() { return this.project; } } diff --git a/src/main/java/org/codehaus/mojo/buildhelper/AbstractDefinePropertyMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/AbstractDefinePropertyMojo.java index f9459ad1..60bb4c19 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/AbstractDefinePropertyMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/AbstractDefinePropertyMojo.java @@ -1,59 +1,54 @@ -package org.codehaus.mojo.buildhelper; - -/* - * The MIT License - * - * Copyright (c) 2004, The Codehaus - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; - -public abstract class AbstractDefinePropertyMojo - extends AbstractMojo -{ - /** - * The maven project - */ - @Parameter( readonly = true, defaultValue = "${project}" ) - protected MavenProject project; - - protected void defineProperty( String name, String value ) - { - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "define property " + name + " = \"" + value + "\"" ); - } - - project.getProperties().put( name, value ); - } - - /** - * Get the current project instance. - * - * @return the project - */ - public MavenProject getProject() - { - return this.project; - } -} +package org.codehaus.mojo.buildhelper; + +/* + * The MIT License + * + * Copyright (c) 2004, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; + +public abstract class AbstractDefinePropertyMojo extends AbstractMojo { + /** + * The maven project + */ + @Parameter(readonly = true, defaultValue = "${project}") + protected MavenProject project; + + protected void defineProperty(String name, String value) { + if (getLog().isDebugEnabled()) { + getLog().debug("define property " + name + " = \"" + value + "\""); + } + + project.getProperties().put(name, value); + } + + /** + * Get the current project instance. + * + * @return the project + */ + public MavenProject getProject() { + return this.project; + } +} diff --git a/src/main/java/org/codehaus/mojo/buildhelper/AbstractRegexPropertyMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/AbstractRegexPropertyMojo.java index bab4d8eb..6e6803e6 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/AbstractRegexPropertyMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/AbstractRegexPropertyMojo.java @@ -1,7 +1,5 @@ package org.codehaus.mojo.buildhelper; -import java.util.Locale; - /* * The MIT License * @@ -26,6 +24,7 @@ * SOFTWARE. */ +import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -34,64 +33,47 @@ import org.apache.maven.plugin.MojoFailureException; import org.codehaus.plexus.util.StringUtils; -public abstract class AbstractRegexPropertyMojo - extends AbstractDefinePropertyMojo -{ +public abstract class AbstractRegexPropertyMojo extends AbstractDefinePropertyMojo { - protected void execute( RegexPropertySetting config ) - throws MojoExecutionException, MojoFailureException - { - try - { + protected void execute(RegexPropertySetting config) throws MojoExecutionException, MojoFailureException { + try { config.validate(); - } - catch ( IllegalArgumentException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); + } catch (IllegalArgumentException e) { + throw new MojoExecutionException(e.getMessage(), e); } Pattern pattern; - try - { - pattern = Pattern.compile( config.getRegex() ); + try { + pattern = Pattern.compile(config.getRegex()); + } catch (PatternSyntaxException e) { + throw new MojoExecutionException(e.getMessage(), e); } - catch ( PatternSyntaxException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } - Matcher matcher = pattern.matcher( config.getValue() ); + Matcher matcher = pattern.matcher(config.getValue()); - if ( matcher.find() ) - { + if (matcher.find()) { // if the string replacement is empty, we define the value replacement to empty. - config.setValue( ( StringUtils.isNotEmpty( config.getReplacement() ) - ? matcher.replaceAll( config.getReplacement() ) : matcher.replaceAll( "" ) ) ); - } - else - { - if ( config.isFailIfNoMatch() ) - { - throw new MojoFailureException( "No match to regex '" + config.getRegex() + "' found in '" - + config.getValue() + "'." ); - } - else - { - getLog().info( "No match to regex '" + config.getRegex() + "' found in '" + config.getValue() + "'. " - + "The initial value '" + config.getValue() + "' is left as-is..." ); + config.setValue( + (StringUtils.isNotEmpty(config.getReplacement()) + ? matcher.replaceAll(config.getReplacement()) + : matcher.replaceAll(""))); + } else { + if (config.isFailIfNoMatch()) { + throw new MojoFailureException( + "No match to regex '" + config.getRegex() + "' found in '" + config.getValue() + "'."); + } else { + getLog().info("No match to regex '" + config.getRegex() + "' found in '" + config.getValue() + "'. " + + "The initial value '" + config.getValue() + "' is left as-is..."); } } - if ( config.isToLowerCase() ) - { - config.setValue( config.getValue().toLowerCase( Locale.getDefault() ) ); + if (config.isToLowerCase()) { + config.setValue(config.getValue().toLowerCase(Locale.getDefault())); } - if ( config.isToUpperCase() ) - { - config.setValue( config.getValue().toUpperCase( Locale.getDefault() ) ); + if (config.isToUpperCase()) { + config.setValue(config.getValue().toUpperCase(Locale.getDefault())); } - defineProperty( config.getName(), config.getValue() ); - + defineProperty(config.getName(), config.getValue()); } } diff --git a/src/main/java/org/codehaus/mojo/buildhelper/AbstractUpToDatePropertyMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/AbstractUpToDatePropertyMojo.java index 7bbbaef7..5cf56ce0 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/AbstractUpToDatePropertyMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/AbstractUpToDatePropertyMojo.java @@ -1,133 +1,113 @@ -package org.codehaus.mojo.buildhelper; - -/* - * The MIT License - * - * Copyright (c) 2004, The Codehaus - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE - * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -import java.io.File; -import java.io.IOException; -import java.util.Map; -import java.util.Map.Entry; - -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.shared.model.fileset.FileSet; -import org.apache.maven.shared.model.fileset.mappers.MapperException; -import org.apache.maven.shared.model.fileset.util.FileSetManager; -import org.codehaus.plexus.util.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Abstract base for setting properties according to whether sets of source and object resources are respectively up to - * date with each other. - * - * @author Adrian Price demonfiddler@virginmedia.com - * @since 1.12 - */ -abstract class AbstractUpToDatePropertyMojo - extends AbstractDefinePropertyMojo -{ - private final Logger log = LoggerFactory.getLogger( this.getClass() ); - - protected AbstractUpToDatePropertyMojo() - { - } - - protected void execute( UpToDatePropertySetting config ) - throws MojoExecutionException, MojoFailureException - { - try - { - config.validate(); - } - catch ( IllegalArgumentException e ) - { - throw new MojoExecutionException( "Invalid UpToDateProperty configuration", e ); - } - - // Check that all target file(s) are up to date with respect to their corresponding source files. - boolean upToDate = true; - FileSet fileSet = config.getFileSet(); - if ( fileSet != null ) - { - try - { - FileSetManager fileSetManager = new FileSetManager( log ); - Map includedFiles = fileSetManager.mapIncludedFiles( fileSet ); - - // Treat a file set that yields no files as intrinsically out of date. - upToDate = !includedFiles.isEmpty(); - - for ( Entry entry : includedFiles.entrySet() ) - { - // If targetFile is out of date WRT srcFile, note the fact and stop processing. - File srcFile = getFile( fileSet, false, entry.getKey() ); - File targetFile = getFile( fileSet, true, entry.getValue() ); - upToDate = isUpToDate( srcFile, targetFile ); - - if ( getLog().isDebugEnabled() ) - { - try - { - StringBuilder msg = new StringBuilder( targetFile.getCanonicalPath() ); - if ( !targetFile.exists() ) - msg.append( " (nonexistent)" ); - msg.append( "\n\tis " ).append( upToDate ? "up to date" - : "out of date" ).append( " with respect to \n\t" ).append( srcFile.getCanonicalPath() ); - if ( !srcFile.exists() ) - msg.append( " (nonexistent)" ); - - getLog().debug( msg ); - } - catch ( IOException e ) - { - // Just a log entry so not fatal. - } - } - - if ( !upToDate ) - break; - } - } - catch ( MapperException e ) - { - throw new MojoExecutionException( "", e ); - } - } - - // Set the property to the appropriate value, depending on whether target files are up to date WRT source files. - if ( upToDate ) - defineProperty( config.getName(), config.getValue().trim() ); - else if ( !StringUtils.isBlank( config.getElse() ) ) - defineProperty( config.getName(), config.getElse().trim() ); - } - - private File getFile( FileSet fileSet, boolean useOutputDirectory, String path ) - { - String baseDir = useOutputDirectory && !StringUtils.isBlank( fileSet.getOutputDirectory() ) - ? fileSet.getOutputDirectory() : fileSet.getDirectory(); - return path == null ? null : new File( baseDir, path ); - } - - private boolean isUpToDate( File srcFile, File targetFile ) - { - return srcFile != null && srcFile.exists() - && ( targetFile == null || srcFile.lastModified() <= targetFile.lastModified() ); - } -} +package org.codehaus.mojo.buildhelper; + +/* + * The MIT License + * + * Copyright (c) 2004, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +import java.io.File; +import java.io.IOException; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.shared.model.fileset.FileSet; +import org.apache.maven.shared.model.fileset.mappers.MapperException; +import org.apache.maven.shared.model.fileset.util.FileSetManager; +import org.codehaus.plexus.util.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Abstract base for setting properties according to whether sets of source and object resources are respectively up to + * date with each other. + * + * @author Adrian Price demonfiddler@virginmedia.com + * @since 1.12 + */ +abstract class AbstractUpToDatePropertyMojo extends AbstractDefinePropertyMojo { + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + protected AbstractUpToDatePropertyMojo() {} + + protected void execute(UpToDatePropertySetting config) throws MojoExecutionException, MojoFailureException { + try { + config.validate(); + } catch (IllegalArgumentException e) { + throw new MojoExecutionException("Invalid UpToDateProperty configuration", e); + } + + // Check that all target file(s) are up to date with respect to their corresponding source files. + boolean upToDate = true; + FileSet fileSet = config.getFileSet(); + if (fileSet != null) { + try { + FileSetManager fileSetManager = new FileSetManager(log); + Map includedFiles = fileSetManager.mapIncludedFiles(fileSet); + + // Treat a file set that yields no files as intrinsically out of date. + upToDate = !includedFiles.isEmpty(); + + for (Entry entry : includedFiles.entrySet()) { + // If targetFile is out of date WRT srcFile, note the fact and stop processing. + File srcFile = getFile(fileSet, false, entry.getKey()); + File targetFile = getFile(fileSet, true, entry.getValue()); + upToDate = isUpToDate(srcFile, targetFile); + + if (getLog().isDebugEnabled()) { + try { + StringBuilder msg = new StringBuilder(targetFile.getCanonicalPath()); + if (!targetFile.exists()) msg.append(" (nonexistent)"); + msg.append("\n\tis ") + .append(upToDate ? "up to date" : "out of date") + .append(" with respect to \n\t") + .append(srcFile.getCanonicalPath()); + if (!srcFile.exists()) msg.append(" (nonexistent)"); + + getLog().debug(msg); + } catch (IOException e) { + // Just a log entry so not fatal. + } + } + + if (!upToDate) break; + } + } catch (MapperException e) { + throw new MojoExecutionException("", e); + } + } + + // Set the property to the appropriate value, depending on whether target files are up to date WRT source files. + if (upToDate) defineProperty(config.getName(), config.getValue().trim()); + else if (!StringUtils.isBlank(config.getElse())) + defineProperty(config.getName(), config.getElse().trim()); + } + + private File getFile(FileSet fileSet, boolean useOutputDirectory, String path) { + String baseDir = useOutputDirectory && !StringUtils.isBlank(fileSet.getOutputDirectory()) + ? fileSet.getOutputDirectory() + : fileSet.getDirectory(); + return path == null ? null : new File(baseDir, path); + } + + private boolean isUpToDate(File srcFile, File targetFile) { + return srcFile != null + && srcFile.exists() + && (targetFile == null || srcFile.lastModified() <= targetFile.lastModified()); + } +} diff --git a/src/main/java/org/codehaus/mojo/buildhelper/AddResourceMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/AddResourceMojo.java index 23fba018..26d269d2 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/AddResourceMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/AddResourceMojo.java @@ -34,17 +34,13 @@ * @author Paul Gier * @since 1.3 */ -@Mojo( name = "add-resource", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true ) -public class AddResourceMojo - extends AbstractAddResourceMojo -{ +@Mojo(name = "add-resource", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true) +public class AddResourceMojo extends AbstractAddResourceMojo { - public void addResource( Resource resource ) - { - getProject().addResource( resource ); - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "Added resource: " + resource.getDirectory() ); + public void addResource(Resource resource) { + getProject().addResource(resource); + if (getLog().isDebugEnabled()) { + getLog().debug("Added resource: " + resource.getDirectory()); } } } diff --git a/src/main/java/org/codehaus/mojo/buildhelper/AddSourceMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/AddSourceMojo.java index 13458e17..6ea23161 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/AddSourceMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/AddSourceMojo.java @@ -38,32 +38,27 @@ * @author Dan T. Tran * @since 1.0 */ -@Mojo( name = "add-source", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true ) -public class AddSourceMojo - extends AbstractMojo -{ +@Mojo(name = "add-source", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true) +public class AddSourceMojo extends AbstractMojo { /** * Additional source directories. * * @since 1.0 */ - @Parameter( property = "sources", required = true ) + @Parameter(property = "sources", required = true) private File[] sources; /** * @since 1.0 */ - @Parameter( readonly = true, defaultValue = "${project}" ) + @Parameter(readonly = true, defaultValue = "${project}") private MavenProject project; - public void execute() - { - for ( File source : sources ) - { - this.project.addCompileSourceRoot( source.getAbsolutePath() ); - if ( getLog().isInfoEnabled() ) - { - getLog().info( "Source directory: " + source + " added." ); + public void execute() { + for (File source : sources) { + this.project.addCompileSourceRoot(source.getAbsolutePath()); + if (getLog().isInfoEnabled()) { + getLog().info("Source directory: " + source + " added."); } } } diff --git a/src/main/java/org/codehaus/mojo/buildhelper/AddTestResourceMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/AddTestResourceMojo.java index 4a910e8b..4cfc9ea8 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/AddTestResourceMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/AddTestResourceMojo.java @@ -34,22 +34,18 @@ * @author Paul Gier * @since 1.3 */ -@Mojo( name = "add-test-resource", defaultPhase = LifecyclePhase.GENERATE_TEST_RESOURCES, threadSafe = true ) -public class AddTestResourceMojo - extends AbstractAddResourceMojo -{ +@Mojo(name = "add-test-resource", defaultPhase = LifecyclePhase.GENERATE_TEST_RESOURCES, threadSafe = true) +public class AddTestResourceMojo extends AbstractAddResourceMojo { /** * Add the resource to the project. * * @param resource the resource to add */ - public void addResource( Resource resource ) - { - getProject().addTestResource( resource ); - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "Added test resource: " + resource.getDirectory() ); + public void addResource(Resource resource) { + getProject().addTestResource(resource); + if (getLog().isDebugEnabled()) { + getLog().debug("Added test resource: " + resource.getDirectory()); } } } diff --git a/src/main/java/org/codehaus/mojo/buildhelper/AddTestSourceMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/AddTestSourceMojo.java index 64d98f2d..b2ab781d 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/AddTestSourceMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/AddTestSourceMojo.java @@ -38,32 +38,27 @@ * @author Dan T. Tran * @since 1.0 */ -@Mojo( name = "add-test-source", defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES, threadSafe = true ) -public class AddTestSourceMojo - extends AbstractMojo -{ +@Mojo(name = "add-test-source", defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES, threadSafe = true) +public class AddTestSourceMojo extends AbstractMojo { /** * Additional test source directories. * * @since 1.0 */ - @Parameter( required = true ) + @Parameter(required = true) private File[] sources; /** * @since 1.0 */ - @Parameter( readonly = true, defaultValue = "${project}" ) + @Parameter(readonly = true, defaultValue = "${project}") private MavenProject project; - public void execute() - { - for ( File source : sources ) - { - this.project.addTestCompileSourceRoot( source.getAbsolutePath() ); - if ( getLog().isInfoEnabled() ) - { - getLog().info( "Test Source directory: " + source + " added." ); + public void execute() { + for (File source : sources) { + this.project.addTestCompileSourceRoot(source.getAbsolutePath()); + if (getLog().isInfoEnabled()) { + getLog().info("Test Source directory: " + source + " added."); } } } diff --git a/src/main/java/org/codehaus/mojo/buildhelper/Artifact.java b/src/main/java/org/codehaus/mojo/buildhelper/Artifact.java index 6d8933b3..45c179ef 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/Artifact.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/Artifact.java @@ -33,8 +33,7 @@ * * @author dtran */ -public class Artifact -{ +public class Artifact { private File file; private String type = "jar"; @@ -48,8 +47,7 @@ public class Artifact * * @param localFile a {@link java.io.File} object. */ - public void setFile( File localFile ) - { + public void setFile(File localFile) { this.file = localFile; } @@ -60,8 +58,7 @@ public void setFile( File localFile ) * * @return a {@link java.io.File} object. */ - public File getFile() - { + public File getFile() { return this.file; } @@ -72,8 +69,7 @@ public File getFile() * * @param type a {@link java.lang.String} object. */ - public void setType( String type ) - { + public void setType(String type) { this.type = type; } @@ -84,8 +80,7 @@ public void setType( String type ) * * @return a {@link java.lang.String} object. */ - public String getType() - { + public String getType() { return this.type; } @@ -96,8 +91,7 @@ public String getType() * * @param classifier a {@link java.lang.String} object. */ - public void setClassifier( String classifier ) - { + public void setClassifier(String classifier) { this.classifier = classifier; } @@ -108,8 +102,7 @@ public void setClassifier( String classifier ) * * @return a {@link java.lang.String} object. */ - public String getClassifier() - { + public String getClassifier() { return this.classifier; } } diff --git a/src/main/java/org/codehaus/mojo/buildhelper/AttachArtifactMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/AttachArtifactMojo.java index 15639df6..e51c93fc 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/AttachArtifactMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/AttachArtifactMojo.java @@ -43,17 +43,15 @@ * @author Dan T. Tran * @since 1.0 */ -@Mojo( name = "attach-artifact", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true ) -public class AttachArtifactMojo - extends AbstractMojo -{ +@Mojo(name = "attach-artifact", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true) +public class AttachArtifactMojo extends AbstractMojo { /** * Attach an array of artifacts to the project. */ - @Parameter( required = true ) + @Parameter(required = true) private Artifact[] artifacts; - @Parameter( readonly = true, defaultValue = "${project}" ) + @Parameter(readonly = true, defaultValue = "${project}") private MavenProject project; /** @@ -68,7 +66,7 @@ public class AttachArtifactMojo * * @since 1.5 */ - @Parameter( property = "buildhelper.runOnlyAtExecutionRoot", defaultValue = "false" ) + @Parameter(property = "buildhelper.runOnlyAtExecutionRoot", defaultValue = "false") private boolean runOnlyAtExecutionRoot; /** @@ -77,50 +75,38 @@ public class AttachArtifactMojo * * @since 1.6 */ - @Parameter( property = "buildhelper.skipAttach", defaultValue = "false" ) + @Parameter(property = "buildhelper.skipAttach", defaultValue = "false") private boolean skipAttach; - public void execute() - throws MojoExecutionException, MojoFailureException - { + public void execute() throws MojoExecutionException, MojoFailureException { - if ( skipAttach ) - { - getLog().info( "Skip attaching artifacts" ); + if (skipAttach) { + getLog().info("Skip attaching artifacts"); return; } // Run only at the execution root - if ( runOnlyAtExecutionRoot && !project.isExecutionRoot() ) - { - getLog().info( "Skip attaching artifacts in this project because it's not the Execution Root" ); - } - else - { + if (runOnlyAtExecutionRoot && !project.isExecutionRoot()) { + getLog().info("Skip attaching artifacts in this project because it's not the Execution Root"); + } else { this.validateArtifacts(); - for ( Artifact artifact : artifacts ) - { - projectHelper.attachArtifact( this.project, artifact.getType(), artifact.getClassifier(), - artifact.getFile() ); + for (Artifact artifact : artifacts) { + projectHelper.attachArtifact( + this.project, artifact.getType(), artifact.getClassifier(), artifact.getFile()); } } - } - private void validateArtifacts() - throws MojoFailureException - { + private void validateArtifacts() throws MojoFailureException { // check unique of types and classifiers Set extensionClassifiers = new HashSet(); - for ( Artifact artifact : artifacts ) - { + for (Artifact artifact : artifacts) { String extensionClassifier = artifact.getType() + ":" + artifact.getClassifier(); - if ( !extensionClassifiers.add( extensionClassifier ) ) - { - throw new MojoFailureException( "The artifact with same type and classifier: " + extensionClassifier - + " is used more than once." ); + if (!extensionClassifiers.add(extensionClassifier)) { + throw new MojoFailureException("The artifact with same type and classifier: " + extensionClassifier + + " is used more than once."); } } } diff --git a/src/main/java/org/codehaus/mojo/buildhelper/BeanshellPropertyMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/BeanshellPropertyMojo.java index adc6026d..3f6524ff 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/BeanshellPropertyMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/BeanshellPropertyMojo.java @@ -24,6 +24,8 @@ * SOFTWARE. */ +import bsh.EvalError; +import bsh.Interpreter; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -31,9 +33,6 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.settings.Settings; -import bsh.EvalError; -import bsh.Interpreter; - /** * Define one or many properties as a result of a Beanshell script invocation. Like * gmaven-plugin, some variables are @@ -48,11 +47,9 @@ * @author Hervé Boutemy * @since 1.8 */ -@Mojo( name = "bsh-property", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true ) -public class BeanshellPropertyMojo - extends AbstractDefinePropertyMojo -{ - @Parameter( required = true ) +@Mojo(name = "bsh-property", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true) +public class BeanshellPropertyMojo extends AbstractDefinePropertyMojo { + @Parameter(required = true) private String source; /** @@ -65,77 +62,61 @@ public class BeanshellPropertyMojo /** * The Maven Session. */ - @Parameter( readonly = true, defaultValue = "${session}" ) + @Parameter(readonly = true, defaultValue = "${session}") private MavenSession mavenSession; /** * The Maven Settings. */ - @Parameter( readonly = true, defaultValue = "${settings}" ) + @Parameter(readonly = true, defaultValue = "${settings}") private Settings settings; /** * Main plugin execution */ - public void execute() - throws MojoFailureException - { + public void execute() throws MojoFailureException { Interpreter interpreter = new Interpreter(); - set( interpreter, "project", getProject() ); - set( interpreter, "session", mavenSession ); - set( interpreter, "settings", settings ); - set( interpreter, "log", getLog() ); + set(interpreter, "project", getProject()); + set(interpreter, "session", mavenSession); + set(interpreter, "settings", settings); + set(interpreter, "log", getLog()); - try - { - interpreter.eval( source ); - } - catch ( EvalError ee ) - { + try { + interpreter.eval(source); + } catch (EvalError ee) { MojoFailureException mfe = - new MojoFailureException( "error during Beanshell script execution: " + ee.getMessage() ); - mfe.initCause( ee ); + new MojoFailureException("error during Beanshell script execution: " + ee.getMessage()); + mfe.initCause(ee); throw mfe; } - if ( properties != null ) - { - for ( String property : properties ) - { + if (properties != null) { + for (String property : properties) { Object value; - try - { - value = interpreter.get( property ); + try { + value = interpreter.get(property); - if ( value != null ) - { - defineProperty( property, value.toString() ); + if (value != null) { + defineProperty(property, value.toString()); } - } - catch ( EvalError ee ) - { - MojoFailureException mfe = new MojoFailureException( "cannot get Beanshell global variable '" - + property + "': " + ee.getMessage() ); - mfe.initCause( ee ); + } catch (EvalError ee) { + MojoFailureException mfe = new MojoFailureException( + "cannot get Beanshell global variable '" + property + "': " + ee.getMessage()); + mfe.initCause(ee); throw mfe; } } } } - private void set( Interpreter interpreter, String name, Object value ) - throws MojoFailureException - { - try - { - interpreter.set( name, value ); - } - catch ( EvalError ee ) - { - MojoFailureException mfe = new MojoFailureException( "cannot define Beanshell global variable '" + name - + "': " + ee.getMessage() ); - mfe.initCause( ee ); + private void set(Interpreter interpreter, String name, Object value) throws MojoFailureException { + try { + interpreter.set(name, value); + } catch (EvalError ee) { + MojoFailureException mfe = new MojoFailureException( + "cannot define Beanshell global variable '" + name + "': " + ee.getMessage()); + mfe.initCause(ee); throw mfe; } } diff --git a/src/main/java/org/codehaus/mojo/buildhelper/CpuCountMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/CpuCountMojo.java index 0ea3db30..6602a146 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/CpuCountMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/CpuCountMojo.java @@ -1,67 +1,62 @@ -package org.codehaus.mojo.buildhelper; - -/* - * The MIT License - * - * Copyright (c) 2004, The Codehaus - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; - -/** - * Retrieve number of CPUs with project factor, and place it under a configurable project property - * - * @author Dan T. Tran - * @since 1.9 - */ -@Mojo( name = "cpu-count", defaultPhase = LifecyclePhase.INITIALIZE, threadSafe = true ) -public class CpuCountMojo - extends AbstractDefinePropertyMojo -{ - - /** - * The name of the property in which to store the CPU count. - */ - @Parameter( defaultValue = "cpu.count" ) - private String cpuCount; - - /** - * Projection factor. - */ - @Parameter( defaultValue = "1.0" ) - private float factor; - - public void execute() - throws MojoExecutionException - { - float count = Runtime.getRuntime().availableProcessors() * factor; - if ( count < 1 ) - { - count = 1; - } - - defineProperty( this.cpuCount, Integer.toString( (int) count ) ); - this.getLog().info( "CPU count: " + this.getProject().getProperties().getProperty( cpuCount ) ); - } -} +package org.codehaus.mojo.buildhelper; + +/* + * The MIT License + * + * Copyright (c) 2004, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +/** + * Retrieve number of CPUs with project factor, and place it under a configurable project property + * + * @author Dan T. Tran + * @since 1.9 + */ +@Mojo(name = "cpu-count", defaultPhase = LifecyclePhase.INITIALIZE, threadSafe = true) +public class CpuCountMojo extends AbstractDefinePropertyMojo { + + /** + * The name of the property in which to store the CPU count. + */ + @Parameter(defaultValue = "cpu.count") + private String cpuCount; + + /** + * Projection factor. + */ + @Parameter(defaultValue = "1.0") + private float factor; + + public void execute() throws MojoExecutionException { + float count = Runtime.getRuntime().availableProcessors() * factor; + if (count < 1) { + count = 1; + } + + defineProperty(this.cpuCount, Integer.toString((int) count)); + this.getLog().info("CPU count: " + this.getProject().getProperties().getProperty(cpuCount)); + } +} diff --git a/src/main/java/org/codehaus/mojo/buildhelper/HostnameMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/HostnameMojo.java index 61feceb7..4fd33cd9 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/HostnameMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/HostnameMojo.java @@ -24,41 +24,34 @@ * SOFTWARE. */ +import java.net.InetAddress; +import java.net.UnknownHostException; + import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import java.net.InetAddress; -import java.net.UnknownHostException; - /** * Retrieve current hostname and place it under a configurable project property * * @author John Patrick * @since 3.0.0 */ -@Mojo( name = "hostname", defaultPhase = LifecyclePhase.PROCESS_TEST_CLASSES, threadSafe = true ) -public class HostnameMojo - extends AbstractDefinePropertyMojo -{ +@Mojo(name = "hostname", defaultPhase = LifecyclePhase.PROCESS_TEST_CLASSES, threadSafe = true) +public class HostnameMojo extends AbstractDefinePropertyMojo { /** * The name of the property in which to store the hostname. */ - @Parameter( defaultValue = "hostname" ) + @Parameter(defaultValue = "hostname") private String hostnameProperty; - public void execute() - throws MojoExecutionException - { - try - { - defineProperty( this.hostnameProperty, InetAddress.getLocalHost().getHostName() ); - } - catch ( UnknownHostException e ) - { - throw new MojoExecutionException( "Unable to retrieve hostname.", e ); + public void execute() throws MojoExecutionException { + try { + defineProperty(this.hostnameProperty, InetAddress.getLocalHost().getHostName()); + } catch (UnknownHostException e) { + throw new MojoExecutionException("Unable to retrieve hostname.", e); } } } diff --git a/src/main/java/org/codehaus/mojo/buildhelper/LocalIpMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/LocalIpMojo.java index fb623dc8..29ef4d31 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/LocalIpMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/LocalIpMojo.java @@ -1,64 +1,57 @@ -package org.codehaus.mojo.buildhelper; - -/* - * The MIT License - * - * Copyright (c) 2004, The Codehaus - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import java.net.InetAddress; -import java.net.UnknownHostException; - -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; - -/** - * Retrieve current host IP address and place it under a configurable project property - * - * @author Dan T. Tran - * @since 1.8 - */ -@Mojo( name = "local-ip", defaultPhase = LifecyclePhase.PROCESS_TEST_CLASSES, threadSafe = true ) -public class LocalIpMojo - extends AbstractDefinePropertyMojo -{ - - /** - * The name of the property in which to store the localhost ipaddress. - */ - @Parameter( defaultValue = "local.ip" ) - private String localIpProperty; - - public void execute() - throws MojoExecutionException - { - try - { - defineProperty( this.localIpProperty, InetAddress.getLocalHost().getHostAddress() ); - } - catch ( UnknownHostException e ) - { - throw new MojoExecutionException( "Unable to retrieve localhost address.", e ); - } - } -} +package org.codehaus.mojo.buildhelper; + +/* + * The MIT License + * + * Copyright (c) 2004, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import java.net.InetAddress; +import java.net.UnknownHostException; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +/** + * Retrieve current host IP address and place it under a configurable project property + * + * @author Dan T. Tran + * @since 1.8 + */ +@Mojo(name = "local-ip", defaultPhase = LifecyclePhase.PROCESS_TEST_CLASSES, threadSafe = true) +public class LocalIpMojo extends AbstractDefinePropertyMojo { + + /** + * The name of the property in which to store the localhost ipaddress. + */ + @Parameter(defaultValue = "local.ip") + private String localIpProperty; + + public void execute() throws MojoExecutionException { + try { + defineProperty(this.localIpProperty, InetAddress.getLocalHost().getHostAddress()); + } catch (UnknownHostException e) { + throw new MojoExecutionException("Unable to retrieve localhost address.", e); + } + } +} diff --git a/src/main/java/org/codehaus/mojo/buildhelper/MavenVersionMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/MavenVersionMojo.java index 53ef0223..2483e14d 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/MavenVersionMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/MavenVersionMojo.java @@ -36,10 +36,8 @@ * @author pgier * @since 1.3 */ -@Mojo( name = "maven-version", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true ) -public class MavenVersionMojo - extends AbstractDefinePropertyMojo -{ +@Mojo(name = "maven-version", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true) +public class MavenVersionMojo extends AbstractDefinePropertyMojo { /** * The RuntimeInforamtion for the current instance of Maven. @@ -50,15 +48,13 @@ public class MavenVersionMojo /** * The name of the property in which to store the version of Maven. */ - @Parameter( defaultValue = "maven.version" ) + @Parameter(defaultValue = "maven.version") private String versionProperty; /** * Main plugin execution */ - public void execute() - { - defineProperty( versionProperty, runtime.getMavenVersion() ); + public void execute() { + defineProperty(versionProperty, runtime.getMavenVersion()); } - -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/mojo/buildhelper/ParseVersionMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/ParseVersionMojo.java index dcecd3b0..fe2ab763 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/ParseVersionMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/ParseVersionMojo.java @@ -16,60 +16,60 @@ * [propertyPrefix].qualifier * [propertyPrefix].buildNumber * - * + * * Where the propertyPrefix is the string set in the mojo parameter. The parsing of the above is based on the following * format of the version: - * + * *
  *  <majorversion [> . <minorversion [> . <incrementalversion ] ] [> - <buildnumber | qualifier ]>
  * 
- * + * * It will be tried to parse the version as an OSGi version. It this is successful the following property will be set * accordingly. If this is not possible a warning will be emitted. - * + * *
  *   [propertyPrefix].osgiVersion
  * 
- * + * * This goal also sets the following properties: - * + * *
  *   [propertyPrefix].nextMajorVersion
  *   [propertyPrefix].nextMinorVersion
  *   [propertyPrefix].nextIncrementalVersion
  *   [propertyPrefix].nextBuildNumber
  * 
- * + * * This goal also sets the following properties: - * + * *
  *   [formattedPropertyPrefix].majorVersion
  *   [formattedPropertyPrefix].minorVersion
  *   [formattedPropertyPrefix].incrementalVersion
  *   [formattedPropertyPrefix].buildNumber
  * 
- * + * * This goal also sets the following properties: - * + * *
  *   [formattedPropertyPrefix].nextMajorVersion
  *   [formattedPropertyPrefix].nextMinorVersion
  *   [formattedPropertyPrefix].nextIncrementalVersion
  *   [formattedPropertyPrefix].nextBuildNumber
  * 
- * - * There is another property set which is named [propertyPrefix].qualifier and furthermore - * another property which is named [propertyPrefix].qualifier? which contains a prefix + * + * There is another property set which is named [propertyPrefix].qualifier and furthermore + * another property which is named [propertyPrefix].qualifier? which contains a prefix * - if the qualifier contains anything otherwise the whole property is simply empty. - * + * *
  * mvn build-helper:parse-version versions:set \
  *   -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.nextMinorVersion}.\${parsedVersion.incrementalVersion}\${parsedVersion.qualifier?}
  * 
- * + * * The above properties contain simply incremented versions of the parsed version informations. Those can now be used to * update the version of your project via the following to the next Major version: - * + * *
  *   mvn build-helper:parse-version versions:set \
  *      -DnewVersion=\${parsedVersion.nextMajorVersion}.0.0 \
@@ -77,7 +77,7 @@
  * 
* * It can of course being used to increment the minor version: - * + * *
  *   mvn build-helper:parse-version versions:set \
  *      -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.nextMinorVersion}.0 \
@@ -85,62 +85,60 @@
  * 
* * This can make an upgrade of the versions of your project very convenient. - * + * * @author pgier * @since 1.3 */ -@Mojo( name = "parse-version", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true ) -public class ParseVersionMojo - extends AbstractDefinePropertyMojo -{ +@Mojo(name = "parse-version", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true) +public class ParseVersionMojo extends AbstractDefinePropertyMojo { /** * The version string to parse. */ - @Parameter( defaultValue = "${project.version}", property = "versionString") + @Parameter(defaultValue = "${project.version}", property = "versionString") private String versionString; /** * Prefix string to use for the set of version properties. */ - @Parameter( defaultValue = "parsedVersion" ) + @Parameter(defaultValue = "parsedVersion") private String propertyPrefix; /** * Prefix string to use for the set of formatted version properties. * @since 3.0.0 */ - @Parameter( defaultValue = "formattedVersion" ) + @Parameter(defaultValue = "formattedVersion") private String formattedPropertyPrefix; - + /** * This can be used to make a particular format of the major number possible like padding it with zeros etc. - * + * * @since 3.0.0 * @see Formatter syntax */ - @Parameter( defaultValue = "%02d" ) + @Parameter(defaultValue = "%02d") private String formatMajor; /** * @since 3.0.0 * @see Formatter syntax */ - @Parameter( defaultValue = "%02d" ) + @Parameter(defaultValue = "%02d") private String formatMinor; /** * @since 3.0.0 * @see Formatter syntax */ - @Parameter( defaultValue = "%02d" ) + @Parameter(defaultValue = "%02d") private String formatIncremental; /** * @since 3.0.0 * @see Formatter syntax */ - @Parameter( defaultValue = "%02d" ) + @Parameter(defaultValue = "%02d") private String formatBuildNumber; /** @@ -148,35 +146,30 @@ public class ParseVersionMojo * to prefix the qualifier if not empty. * @since 3.1.0 */ - @Parameter( defaultValue = "-") + @Parameter(defaultValue = "-") private String qualifierPrefix; - + /** * Execute the mojo. This sets the version properties on the project. */ - public void execute() - { - parseVersion( versionString ); + public void execute() { + parseVersion(versionString); } - private void defineVersionProperty( String name, String value ) - { - defineProperty( propertyPrefix + '.' + name, value ); + private void defineVersionProperty(String name, String value) { + defineProperty(propertyPrefix + '.' + name, value); } - private void defineFormattedVersionProperty( String name, String value ) - { - defineProperty( formattedPropertyPrefix + '.' + name, value ); + private void defineFormattedVersionProperty(String name, String value) { + defineProperty(formattedPropertyPrefix + '.' + name, value); } - private void defineVersionProperty( String name, int value ) - { - defineVersionProperty( name, Integer.toString( value ) ); + private void defineVersionProperty(String name, int value) { + defineVersionProperty(name, Integer.toString(value)); } - private void defineVersionProperty( String name, long value ) - { - defineVersionProperty( name, Long.toString( value ) ); + private void defineVersionProperty(String name, long value) { + defineVersionProperty(name, Long.toString(value)); } /** @@ -184,52 +177,54 @@ private void defineVersionProperty( String name, long value ) * * @param version the version to parse */ - public void parseVersion( String version ) - { - DefaultVersioning artifactVersion = new DefaultVersioning( version ); + public void parseVersion(String version) { + DefaultVersioning artifactVersion = new DefaultVersioning(version); - getLog().debug( "Parsed Version" ); - getLog().debug( " major: " + artifactVersion.getMajor() ); - getLog().debug( " minor: " + artifactVersion.getMinor() ); - getLog().debug( " incremental: " + artifactVersion.getPatch() ); - getLog().debug( " buildnumber: " + artifactVersion.getBuildNumber() ); - getLog().debug( " qualifier: " + artifactVersion.getQualifier() ); + getLog().debug("Parsed Version"); + getLog().debug(" major: " + artifactVersion.getMajor()); + getLog().debug(" minor: " + artifactVersion.getMinor()); + getLog().debug(" incremental: " + artifactVersion.getPatch()); + getLog().debug(" buildnumber: " + artifactVersion.getBuildNumber()); + getLog().debug(" qualifier: " + artifactVersion.getQualifier()); - defineVersionProperty( "majorVersion", artifactVersion.getMajor() ); - defineVersionProperty( "minorVersion", artifactVersion.getMinor() ); - defineVersionProperty( "incrementalVersion", artifactVersion.getPatch() ); - defineVersionProperty( "buildNumber", artifactVersion.getBuildNumber() ); + defineVersionProperty("majorVersion", artifactVersion.getMajor()); + defineVersionProperty("minorVersion", artifactVersion.getMinor()); + defineVersionProperty("incrementalVersion", artifactVersion.getPatch()); + defineVersionProperty("buildNumber", artifactVersion.getBuildNumber()); - defineVersionProperty( "nextMajorVersion", artifactVersion.getMajor() + 1 ); - defineVersionProperty( "nextMinorVersion", artifactVersion.getMinor() + 1 ); - defineVersionProperty( "nextIncrementalVersion", artifactVersion.getPatch() + 1 ); - defineVersionProperty( "nextBuildNumber", artifactVersion.getBuildNumber() + 1 ); + defineVersionProperty("nextMajorVersion", artifactVersion.getMajor() + 1); + defineVersionProperty("nextMinorVersion", artifactVersion.getMinor() + 1); + defineVersionProperty("nextIncrementalVersion", artifactVersion.getPatch() + 1); + defineVersionProperty("nextBuildNumber", artifactVersion.getBuildNumber() + 1); - defineFormattedVersionProperty( "majorVersion", String.format( formatMajor, artifactVersion.getMajor() ) ); - defineFormattedVersionProperty( "minorVersion", String.format( formatMinor, artifactVersion.getMinor() ) ); - defineFormattedVersionProperty( "incrementalVersion", String.format( formatIncremental, artifactVersion.getPatch() ) ); - defineFormattedVersionProperty( "buildNumber", String.format( formatBuildNumber, artifactVersion.getBuildNumber() )); + defineFormattedVersionProperty("majorVersion", String.format(formatMajor, artifactVersion.getMajor())); + defineFormattedVersionProperty("minorVersion", String.format(formatMinor, artifactVersion.getMinor())); + defineFormattedVersionProperty( + "incrementalVersion", String.format(formatIncremental, artifactVersion.getPatch())); + defineFormattedVersionProperty( + "buildNumber", String.format(formatBuildNumber, artifactVersion.getBuildNumber())); + + defineFormattedVersionProperty("nextMajorVersion", String.format(formatMajor, artifactVersion.getMajor() + 1)); + defineFormattedVersionProperty("nextMinorVersion", String.format(formatMinor, artifactVersion.getMinor() + 1)); + defineFormattedVersionProperty( + "nextIncrementalVersion", String.format(formatIncremental, artifactVersion.getPatch() + 1)); + defineFormattedVersionProperty( + "nextBuildNumber", String.format(formatBuildNumber, artifactVersion.getBuildNumber() + 1)); - defineFormattedVersionProperty( "nextMajorVersion", String.format( formatMajor, artifactVersion.getMajor() + 1 )); - defineFormattedVersionProperty( "nextMinorVersion", String.format( formatMinor, artifactVersion.getMinor() + 1 )); - defineFormattedVersionProperty( "nextIncrementalVersion", String.format( formatIncremental, artifactVersion.getPatch() + 1 )); - defineFormattedVersionProperty( "nextBuildNumber", String.format( formatBuildNumber, artifactVersion.getBuildNumber() + 1 )); - String osgi = artifactVersion.getAsOSGiVersion(); String qualifier = artifactVersion.getQualifier(); String qualifierQuestion = ""; - if ( qualifier == null ) - { + if (qualifier == null) { qualifier = ""; } else { qualifierQuestion = qualifierPrefix; } - defineVersionProperty( "qualifier", qualifier ); - defineVersionProperty( "qualifier?", qualifierQuestion + qualifier ); + defineVersionProperty("qualifier", qualifier); + defineVersionProperty("qualifier?", qualifierQuestion + qualifier); - defineVersionProperty( "osgiVersion", osgi ); + defineVersionProperty("osgiVersion", osgi); } /** @@ -237,49 +232,42 @@ public void parseVersion( String version ) * * @param prefix The prefix to be used. */ - public void setPropertyPrefix( String prefix ) - { + public void setPropertyPrefix(String prefix) { this.propertyPrefix = prefix; } /** * @param formattedPropertyPrefix The prefix used for formatted properties. */ - public void setFormattedPropertyPrefix( String formattedPropertyPrefix ) - { + public void setFormattedPropertyPrefix(String formattedPropertyPrefix) { this.formattedPropertyPrefix = formattedPropertyPrefix; } /** * @param formatMajor Set the format for major part. */ - public void setFormatMajor( String formatMajor ) - { + public void setFormatMajor(String formatMajor) { this.formatMajor = formatMajor; } /** * @param formatMinor Set the format for minor part. */ - public void setFormatMinor( String formatMinor ) - { + public void setFormatMinor(String formatMinor) { this.formatMinor = formatMinor; } /** * @param formatIncremental Set format for incremental part. */ - public void setFormatIncremental( String formatIncremental ) - { + public void setFormatIncremental(String formatIncremental) { this.formatIncremental = formatIncremental; } /** * @param formatBuildNumber Set the format for the buildNumber part. */ - public void setFormatBuildNumber( String formatBuildNumber ) - { + public void setFormatBuildNumber(String formatBuildNumber) { this.formatBuildNumber = formatBuildNumber; } - } diff --git a/src/main/java/org/codehaus/mojo/buildhelper/RegexPropertiesMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/RegexPropertiesMojo.java index c32c0e23..ce44341f 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/RegexPropertiesMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/RegexPropertiesMojo.java @@ -1,62 +1,56 @@ -package org.codehaus.mojo.buildhelper; - -/* - * The MIT License - * - * Copyright (c) 2004, The Codehaus - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import java.util.ArrayList; -import java.util.List; - -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; - -/** - * Sets a property by applying a regex replacement rule to a supplied value. This is similar to regex-property goal with - * support for multiple regex settings using RegexPropertyConfig - * - * @since 1.9 - */ -@Mojo( name = "regex-properties", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true ) -public class RegexPropertiesMojo - extends AbstractRegexPropertyMojo -{ - /** - * List of RegexPropertyConfig to apply the regex - */ - @Parameter( required = false ) - private List regexPropertySettings = new ArrayList(); - - public void execute() - throws MojoExecutionException, MojoFailureException - { - - for ( RegexPropertySetting setting : regexPropertySettings ) - { - this.execute( setting ); - } - } - -} +package org.codehaus.mojo.buildhelper; + +/* + * The MIT License + * + * Copyright (c) 2004, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +/** + * Sets a property by applying a regex replacement rule to a supplied value. This is similar to regex-property goal with + * support for multiple regex settings using RegexPropertyConfig + * + * @since 1.9 + */ +@Mojo(name = "regex-properties", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true) +public class RegexPropertiesMojo extends AbstractRegexPropertyMojo { + /** + * List of RegexPropertyConfig to apply the regex + */ + @Parameter(required = false) + private List regexPropertySettings = new ArrayList(); + + public void execute() throws MojoExecutionException, MojoFailureException { + + for (RegexPropertySetting setting : regexPropertySettings) { + this.execute(setting); + } + } +} diff --git a/src/main/java/org/codehaus/mojo/buildhelper/RegexPropertyMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/RegexPropertyMojo.java index 3ddaf0c5..a6f75fb7 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/RegexPropertyMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/RegexPropertyMojo.java @@ -36,73 +36,67 @@ * @author Stephen Connolly * @since 1.7 */ -@Mojo( name = "regex-property", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true ) -public class RegexPropertyMojo - extends AbstractRegexPropertyMojo -{ +@Mojo(name = "regex-property", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true) +public class RegexPropertyMojo extends AbstractRegexPropertyMojo { /** * The property to set. */ - @Parameter( required = true ) + @Parameter(required = true) private String name; /** * The pre-transformation value. */ - @Parameter( required = true ) + @Parameter(required = true) private String value; /** * The regex to replace. */ - @Parameter( required = true ) + @Parameter(required = true) private String regex; /** * The replacement. */ - @Parameter( defaultValue = "" ) + @Parameter(defaultValue = "") private String replacement; /** * Whether to fail if no match is found. */ - @Parameter( defaultValue = "true" ) + @Parameter(defaultValue = "true") private boolean failIfNoMatch; /** * Make the value of the resulting property upper case. - * + * * @since 1.11 */ - @Parameter( defaultValue = "false" ) + @Parameter(defaultValue = "false") private boolean toUpperCase; /** * Make the value of the resulting property lower case. - * + * * @since 1.11 */ - @Parameter( defaultValue = "false" ) + @Parameter(defaultValue = "false") private boolean toLowerCase; /** * {@inheritDoc} */ - public void execute() - throws MojoExecutionException, MojoFailureException - { + public void execute() throws MojoExecutionException, MojoFailureException { RegexPropertySetting config = new RegexPropertySetting(); - config.setName( name ); - config.setValue( value ); - config.setRegex( regex ); - config.setReplacement( replacement ); - config.setFailIfNoMatch( failIfNoMatch ); - config.setToLowerCase( toLowerCase ); - config.setToUpperCase( toUpperCase ); - - this.execute( config ); + config.setName(name); + config.setValue(value); + config.setRegex(regex); + config.setReplacement(replacement); + config.setFailIfNoMatch(failIfNoMatch); + config.setToLowerCase(toLowerCase); + config.setToUpperCase(toUpperCase); + this.execute(config); } - } diff --git a/src/main/java/org/codehaus/mojo/buildhelper/RegexPropertySetting.java b/src/main/java/org/codehaus/mojo/buildhelper/RegexPropertySetting.java index 9f9e25ea..3b27a558 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/RegexPropertySetting.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/RegexPropertySetting.java @@ -1,167 +1,146 @@ -package org.codehaus.mojo.buildhelper; - -/* - * The MIT License - * - * Copyright (c) 2004, The Codehaus - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import org.apache.maven.plugins.annotations.Parameter; -import org.codehaus.plexus.util.StringUtils; - -public class RegexPropertySetting -{ - /** - * The property to set. - */ - @Parameter( required = true ) - private String name; - - /** - * The pre-transformation value. - */ - @Parameter( required = true ) - private String value; - - /** - * The regex to replace. - */ - @Parameter( required = true ) - private String regex; - - /** - * The replacement. - */ - @Parameter( defaultValue = "" ) - private String replacement = ""; - - /** - * Whether to fail if no match is found. - */ - @Parameter( defaultValue = "true" ) - private boolean failIfNoMatch = true; - - /** - * Change the case of the value to upper case if set to true. - */ - @Parameter( defaultValue = "false" ) - private boolean toUpperCase = false; - - /** - * Change the case of the value to lower case if set to true. - */ - @Parameter( defaultValue = "false" ) - private boolean toLowerCase = false; - - public String getName() - { - return name; - } - - public void setName( String name ) - { - this.name = name; - } - - public String getValue() - { - return value; - } - - public void setValue( String value ) - { - this.value = value; - } - - public String getRegex() - { - return regex; - } - - public void setRegex( String regex ) - { - this.regex = regex; - } - - public String getReplacement() - { - return replacement; - } - - public void setReplacement( String replacement ) - { - this.replacement = replacement; - } - - public boolean isFailIfNoMatch() - { - return failIfNoMatch; - } - - public void setFailIfNoMatch( boolean failIfNoMatch ) - { - this.failIfNoMatch = failIfNoMatch; - } - - public boolean isToUpperCase() - { - return toUpperCase; - } - - public void setToUpperCase( boolean toUpperCase ) - { - this.toUpperCase = toUpperCase; - } - - public boolean isToLowerCase() - { - return toLowerCase; - } - - public void setToLowerCase( boolean toLowerCase ) - { - this.toLowerCase = toLowerCase; - } - - public void validate() - { - if ( StringUtils.isBlank( name ) ) - { - throw new IllegalArgumentException( "name required" ); - } - - if ( StringUtils.isBlank( value ) ) - { - throw new IllegalArgumentException( "value required" ); - } - - if ( StringUtils.isBlank( regex ) ) - { - throw new IllegalArgumentException( "regex required" ); - } - - if ( toLowerCase && toUpperCase ) - { - throw new IllegalArgumentException( "either toUpperCase or toLowerCase can be set, but not both." ); - } - } - -} +package org.codehaus.mojo.buildhelper; + +/* + * The MIT License + * + * Copyright (c) 2004, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import org.apache.maven.plugins.annotations.Parameter; +import org.codehaus.plexus.util.StringUtils; + +public class RegexPropertySetting { + /** + * The property to set. + */ + @Parameter(required = true) + private String name; + + /** + * The pre-transformation value. + */ + @Parameter(required = true) + private String value; + + /** + * The regex to replace. + */ + @Parameter(required = true) + private String regex; + + /** + * The replacement. + */ + @Parameter(defaultValue = "") + private String replacement = ""; + + /** + * Whether to fail if no match is found. + */ + @Parameter(defaultValue = "true") + private boolean failIfNoMatch = true; + + /** + * Change the case of the value to upper case if set to true. + */ + @Parameter(defaultValue = "false") + private boolean toUpperCase = false; + + /** + * Change the case of the value to lower case if set to true. + */ + @Parameter(defaultValue = "false") + private boolean toLowerCase = false; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getRegex() { + return regex; + } + + public void setRegex(String regex) { + this.regex = regex; + } + + public String getReplacement() { + return replacement; + } + + public void setReplacement(String replacement) { + this.replacement = replacement; + } + + public boolean isFailIfNoMatch() { + return failIfNoMatch; + } + + public void setFailIfNoMatch(boolean failIfNoMatch) { + this.failIfNoMatch = failIfNoMatch; + } + + public boolean isToUpperCase() { + return toUpperCase; + } + + public void setToUpperCase(boolean toUpperCase) { + this.toUpperCase = toUpperCase; + } + + public boolean isToLowerCase() { + return toLowerCase; + } + + public void setToLowerCase(boolean toLowerCase) { + this.toLowerCase = toLowerCase; + } + + public void validate() { + if (StringUtils.isBlank(name)) { + throw new IllegalArgumentException("name required"); + } + + if (StringUtils.isBlank(value)) { + throw new IllegalArgumentException("value required"); + } + + if (StringUtils.isBlank(regex)) { + throw new IllegalArgumentException("regex required"); + } + + if (toLowerCase && toUpperCase) { + throw new IllegalArgumentException("either toUpperCase or toLowerCase can be set, but not both."); + } + } +} diff --git a/src/main/java/org/codehaus/mojo/buildhelper/ReleasedVersionMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/ReleasedVersionMojo.java index 67260e47..f166eb61 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/ReleasedVersionMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/ReleasedVersionMojo.java @@ -1,160 +1,152 @@ -package org.codehaus.mojo.buildhelper; - -/* - * The MIT License - * - * Copyright (c) 2004, The Codehaus - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import java.util.Objects; - -import org.apache.maven.artifact.ArtifactUtils; -import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; -import org.apache.maven.artifact.versioning.DefaultArtifactVersion; -import org.apache.maven.plugins.annotations.Component; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.DefaultArtifact; -import org.eclipse.aether.resolution.VersionRangeRequest; -import org.eclipse.aether.resolution.VersionRangeResolutionException; -import org.eclipse.aether.resolution.VersionRangeResult; - -/** - * Resolve the latest released version of this project. This mojo sets the following properties: - * - *
- *   [propertyPrefix].version
- *   [propertyPrefix].majorVersion
- *   [propertyPrefix].minorVersion
- *   [propertyPrefix].incrementalVersion
- *   [propertyPrefix].buildNumber
- *   [propertyPrefix].qualifier
- * 
- * - * Where the propertyPrefix is the string set in the mojo parameter. - * - * @author Robert Scholte - * @since 1.6 - */ -@Mojo( name = "released-version", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true ) -public class ReleasedVersionMojo - extends AbstractDefinePropertyMojo -{ - - /** - * The artifact metadata source to use. - */ - - @Component - private RepositorySystem repoSystem; - - @Component - private ArtifactHandlerManager artifactHandlerManager; - - @Parameter( defaultValue = "${repositorySystemSession}", readonly = true ) - private RepositorySystemSession repoSession; - - /** - * Prefix string to use for the set of version properties. - */ - @Parameter( defaultValue = "releasedVersion" ) - private String propertyPrefix; - - private void defineVersionProperty( String name, String value ) - { - defineProperty( propertyPrefix + '.' + name, Objects.toString( value, "" ) ); - } - - private void defineVersionProperty( String name, int value ) - { - defineVersionProperty( name, Integer.toString( value ) ); - } - - @SuppressWarnings( "unchecked" ) - public void execute() - { - - /* - * We use a dummy version "0" here to check for all released version. - * Reason: The current project's version is completely irrelevant for the check to retrieve all available versions. - * But if the current project's version is a -SNAPSHOT version, only repository from maven settings are - * requested that are allowed for snapshots - but we want to query for released versions, not for snapshots. - * Using the dummy version "0" which looks like a released version, the repos with releases are requested. - * see https://github.com/mojohaus/build-helper-maven-plugin/issues/108 - */ - try - { - - DefaultArtifact artifact = - new DefaultArtifact(getProject().getGroupId(), getProject().getArtifactId(), - artifactHandlerManager.getArtifactHandler(getProject().getPackaging()).getExtension(), "[0,)"); - - getLog().debug("Artifact for lookup released version: " + artifact); - VersionRangeRequest request = new VersionRangeRequest(artifact, getProject().getRemoteProjectRepositories(), null); - - VersionRangeResult versionRangeResult = repoSystem.resolveVersionRange(repoSession, request); - - getLog().debug("Resolved versions: " + versionRangeResult.getVersions()); - - DefaultArtifactVersion releasedVersion = versionRangeResult.getVersions().stream() - .filter(v -> !ArtifactUtils.isSnapshot(v.toString())) - .map(v -> new DefaultArtifactVersion(v.toString())) - .max(DefaultArtifactVersion::compareTo) - .orElse(null); - - getLog().debug("Released version: " + releasedVersion); - - if ( releasedVersion != null ) - { - // Use ArtifactVersion.toString(), the major, minor and incrementalVersion return all an int. - String releasedVersionValue = releasedVersion.toString(); - - // This would not always reflect the expected version. - int dashIndex = releasedVersionValue.indexOf( '-' ); - if ( dashIndex >= 0 ) - { - releasedVersionValue = releasedVersionValue.substring( 0, dashIndex ); - } - - defineVersionProperty( "version", releasedVersionValue ); - defineVersionProperty( "majorVersion", releasedVersion.getMajorVersion() ); - defineVersionProperty( "minorVersion", releasedVersion.getMinorVersion() ); - defineVersionProperty( "incrementalVersion", releasedVersion.getIncrementalVersion() ); - defineVersionProperty( "buildNumber", releasedVersion.getBuildNumber() ); - defineVersionProperty( "qualifier", releasedVersion.getQualifier() ); - } - else { - getLog().debug("No released version found."); - } - - } - catch (VersionRangeResolutionException e ) - { - if ( getLog().isWarnEnabled() ) - { - getLog().warn( "Failed to retrieve artifacts metadata, cannot resolve the released version" ); - } - } - } -} +package org.codehaus.mojo.buildhelper; + +/* + * The MIT License + * + * Copyright (c) 2004, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import java.util.Objects; + +import org.apache.maven.artifact.ArtifactUtils; +import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.resolution.VersionRangeRequest; +import org.eclipse.aether.resolution.VersionRangeResolutionException; +import org.eclipse.aether.resolution.VersionRangeResult; + +/** + * Resolve the latest released version of this project. This mojo sets the following properties: + * + *
+ *   [propertyPrefix].version
+ *   [propertyPrefix].majorVersion
+ *   [propertyPrefix].minorVersion
+ *   [propertyPrefix].incrementalVersion
+ *   [propertyPrefix].buildNumber
+ *   [propertyPrefix].qualifier
+ * 
+ * + * Where the propertyPrefix is the string set in the mojo parameter. + * + * @author Robert Scholte + * @since 1.6 + */ +@Mojo(name = "released-version", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true) +public class ReleasedVersionMojo extends AbstractDefinePropertyMojo { + + /** + * The artifact metadata source to use. + */ + @Component + private RepositorySystem repoSystem; + + @Component + private ArtifactHandlerManager artifactHandlerManager; + + @Parameter(defaultValue = "${repositorySystemSession}", readonly = true) + private RepositorySystemSession repoSession; + + /** + * Prefix string to use for the set of version properties. + */ + @Parameter(defaultValue = "releasedVersion") + private String propertyPrefix; + + private void defineVersionProperty(String name, String value) { + defineProperty(propertyPrefix + '.' + name, Objects.toString(value, "")); + } + + private void defineVersionProperty(String name, int value) { + defineVersionProperty(name, Integer.toString(value)); + } + + @SuppressWarnings("unchecked") + public void execute() { + + /* + * We use a dummy version "0" here to check for all released version. + * Reason: The current project's version is completely irrelevant for the check to retrieve all available versions. + * But if the current project's version is a -SNAPSHOT version, only repository from maven settings are + * requested that are allowed for snapshots - but we want to query for released versions, not for snapshots. + * Using the dummy version "0" which looks like a released version, the repos with releases are requested. + * see https://github.com/mojohaus/build-helper-maven-plugin/issues/108 + */ + try { + + DefaultArtifact artifact = new DefaultArtifact( + getProject().getGroupId(), + getProject().getArtifactId(), + artifactHandlerManager + .getArtifactHandler(getProject().getPackaging()) + .getExtension(), + "[0,)"); + + getLog().debug("Artifact for lookup released version: " + artifact); + VersionRangeRequest request = + new VersionRangeRequest(artifact, getProject().getRemoteProjectRepositories(), null); + + VersionRangeResult versionRangeResult = repoSystem.resolveVersionRange(repoSession, request); + + getLog().debug("Resolved versions: " + versionRangeResult.getVersions()); + + DefaultArtifactVersion releasedVersion = versionRangeResult.getVersions().stream() + .filter(v -> !ArtifactUtils.isSnapshot(v.toString())) + .map(v -> new DefaultArtifactVersion(v.toString())) + .max(DefaultArtifactVersion::compareTo) + .orElse(null); + + getLog().debug("Released version: " + releasedVersion); + + if (releasedVersion != null) { + // Use ArtifactVersion.toString(), the major, minor and incrementalVersion return all an int. + String releasedVersionValue = releasedVersion.toString(); + + // This would not always reflect the expected version. + int dashIndex = releasedVersionValue.indexOf('-'); + if (dashIndex >= 0) { + releasedVersionValue = releasedVersionValue.substring(0, dashIndex); + } + + defineVersionProperty("version", releasedVersionValue); + defineVersionProperty("majorVersion", releasedVersion.getMajorVersion()); + defineVersionProperty("minorVersion", releasedVersion.getMinorVersion()); + defineVersionProperty("incrementalVersion", releasedVersion.getIncrementalVersion()); + defineVersionProperty("buildNumber", releasedVersion.getBuildNumber()); + defineVersionProperty("qualifier", releasedVersion.getQualifier()); + } else { + getLog().debug("No released version found."); + } + + } catch (VersionRangeResolutionException e) { + if (getLog().isWarnEnabled()) { + getLog().warn("Failed to retrieve artifacts metadata, cannot resolve the released version"); + } + } + } +} diff --git a/src/main/java/org/codehaus/mojo/buildhelper/RemoveLocalArtifactMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/RemoveLocalArtifactMojo.java index 9603b9cf..4ca65618 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/RemoveLocalArtifactMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/RemoveLocalArtifactMojo.java @@ -45,10 +45,8 @@ * @author Dan T. Tran * @since 1.1 */ -@Mojo( name = "remove-project-artifact", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true ) -public class RemoveLocalArtifactMojo - extends AbstractMojo -{ +@Mojo(name = "remove-project-artifact", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true) +public class RemoveLocalArtifactMojo extends AbstractMojo { /** * When true, remove all built artifacts including all versions. When false, remove all built artifacts of this @@ -56,7 +54,7 @@ public class RemoveLocalArtifactMojo * * @since 1.1 */ - @Parameter( defaultValue = "true", property = "buildhelper.removeAll" ) + @Parameter(defaultValue = "true", property = "buildhelper.removeAll") private boolean removeAll; /** @@ -64,53 +62,43 @@ public class RemoveLocalArtifactMojo * * @since 1.6 */ - @Parameter( defaultValue = "true", property = "buildhelper.failOnError" ) + @Parameter(defaultValue = "true", property = "buildhelper.failOnError") private boolean failOnError; /** * @since 1.1 */ - @Parameter( readonly = true, defaultValue = "${project}" ) + @Parameter(readonly = true, defaultValue = "${project}") private MavenProject project; - @Parameter( readonly = true, defaultValue = "${repositorySystemSession}" ) + @Parameter(readonly = true, defaultValue = "${repositorySystemSession}") private RepositorySystemSession repoSession; - public void execute() - throws MojoExecutionException - { + public void execute() throws MojoExecutionException { LocalRepositoryManager lrm = repoSession.getLocalRepositoryManager(); String artifactPath = lrm.getPathForLocalArtifact(RepositoryUtils.toArtifact(project.getArtifact())); File repoBasedir = lrm.getRepository().getBasedir(); - File localArtifactFile = new File( repoBasedir, artifactPath ); + File localArtifactFile = new File(repoBasedir, artifactPath); File localArtifactDirectory = localArtifactFile.getParentFile(); - if ( removeAll ) - { + if (removeAll) { localArtifactDirectory = localArtifactDirectory.getParentFile(); } - try - { - FileUtils.deleteDirectory( localArtifactDirectory ); + try { + FileUtils.deleteDirectory(localArtifactDirectory); - if ( getLog().isInfoEnabled() ) - { - getLog().info( localArtifactDirectory.getAbsolutePath() + " removed." ); + if (getLog().isInfoEnabled()) { + getLog().info(localArtifactDirectory.getAbsolutePath() + " removed."); } - } - catch ( IOException e ) - { + } catch (IOException e) { final String failureMessage = "Cannot delete " + localArtifactDirectory; - if ( failOnError ) - { - throw new MojoExecutionException( failureMessage ); - } - else - { - getLog().warn( failureMessage ); + if (failOnError) { + throw new MojoExecutionException(failureMessage); + } else { + getLog().warn(failureMessage); } } } diff --git a/src/main/java/org/codehaus/mojo/buildhelper/ReserveListenerPortMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/ReserveListenerPortMojo.java index 1f632630..b4392f39 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/ReserveListenerPortMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/ReserveListenerPortMojo.java @@ -56,10 +56,8 @@ * @version $Id: ReserveListnerPortMojo.java 6754 2008-04-13 15:14:04Z dantran $ * @since 1.2 */ -@Mojo( name = "reserve-network-port", defaultPhase = LifecyclePhase.PROCESS_TEST_CLASSES, threadSafe = true ) -public class ReserveListenerPortMojo - extends AbstractMojo -{ +@Mojo(name = "reserve-network-port", defaultPhase = LifecyclePhase.PROCESS_TEST_CLASSES, threadSafe = true) +public class ReserveListenerPortMojo extends AbstractMojo { private static final String BUILD_HELPER_RESERVED_PORTS = "BUILD_HELPER_MIN_PORT"; private static final int FIRST_NON_ROOT_PORT_NUMBER = 1024; @@ -80,7 +78,7 @@ public class ReserveListenerPortMojo /** * A List of urls to resource where list of name could be found. Can be in form of classpath:com/myproject/names.txt * . At least one of {@code #urls} or {@code #portNames} has to be specified. - * + * * @since 1.11 */ @Parameter @@ -124,17 +122,14 @@ public class ReserveListenerPortMojo /** * @since 1.2 */ - @Parameter( readonly = true, defaultValue = "${project}" ) + @Parameter(readonly = true, defaultValue = "${project}") private MavenProject project; @Override - public void execute() - throws MojoExecutionException - { + public void execute() throws MojoExecutionException { Properties properties = project.getProperties(); - if ( outputFile != null ) - { + if (outputFile != null) { properties = new Properties(); } @@ -142,138 +137,99 @@ public void execute() // Reserve the entire block of ports to guarantee we don't get the same port twice final List sockets = new ArrayList(); - try - { - for ( String portName : portNames ) - { - try - { + try { + for (String portName : portNames) { + try { final ServerSocket socket = getServerSocket(); - sockets.add( socket ); - - final String unusedPort = Integer.toString( socket.getLocalPort() ); - properties.put( portName, unusedPort ); - getReservedPorts().add( socket.getLocalPort() ); - this.getLog().info( "Reserved port " + unusedPort + " for " + portName ); - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Error getting an available port from system", e ); + sockets.add(socket); + + final String unusedPort = Integer.toString(socket.getLocalPort()); + properties.put(portName, unusedPort); + getReservedPorts().add(socket.getLocalPort()); + this.getLog().info("Reserved port " + unusedPort + " for " + portName); + } catch (IOException e) { + throw new MojoExecutionException("Error getting an available port from system", e); } } // Write the file -- still hold onto the ports - if ( outputFile != null ) - { - try - { - createOutputDirectoryIfNotExist( outputFile ); - } - catch ( IOException e ) - { - throw new MojoExecutionException( e.getMessage() ); + if (outputFile != null) { + try { + createOutputDirectoryIfNotExist(outputFile); + } catch (IOException e) { + throw new MojoExecutionException(e.getMessage()); } OutputStream os = null; - try - { - os = new FileOutputStream( outputFile ); - properties.store( os, null ); - } - catch ( Exception e ) - { - throw new MojoExecutionException( e.getMessage() ); - } - finally - { - IOUtil.close( os ); + try { + os = new FileOutputStream(outputFile); + properties.store(os, null); + } catch (Exception e) { + throw new MojoExecutionException(e.getMessage()); + } finally { + IOUtil.close(os); } } - } - finally - { + } finally { // Now free all the ports - for ( ServerSocket socket : sockets ) - { + for (ServerSocket socket : sockets) { final int localPort = socket.getLocalPort(); - try - { + try { socket.close(); - } - catch ( IOException e ) - { - this.getLog().error( "Cannot free reserved port " + localPort ); + } catch (IOException e) { + this.getLog().error("Cannot free reserved port " + localPort); } } } } - private void createOutputDirectoryIfNotExist( File outputFile ) - throws IOException - { - File parentDirectory = new File( outputFile.getCanonicalFile().getParent() ); - - if ( !parentDirectory.exists() ) - { - getLog().debug( "Trying to create directories: " + parentDirectory.getAbsolutePath() ); - if ( !parentDirectory.mkdirs() ) - { - getLog().error( "Failed to create folders " + parentDirectory.getAbsolutePath() ); + private void createOutputDirectoryIfNotExist(File outputFile) throws IOException { + File parentDirectory = new File(outputFile.getCanonicalFile().getParent()); + + if (!parentDirectory.exists()) { + getLog().debug("Trying to create directories: " + parentDirectory.getAbsolutePath()); + if (!parentDirectory.mkdirs()) { + getLog().error("Failed to create folders " + parentDirectory.getAbsolutePath()); } } - } - private ServerSocket getServerSocket() - throws IOException, MojoExecutionException - { - if ( minPortNumber == null && maxPortNumber != null ) - { - getLog().debug( "minPortNumber unspecified: using default value " + FIRST_NON_ROOT_PORT_NUMBER ); + private ServerSocket getServerSocket() throws IOException, MojoExecutionException { + if (minPortNumber == null && maxPortNumber != null) { + getLog().debug("minPortNumber unspecified: using default value " + FIRST_NON_ROOT_PORT_NUMBER); minPortNumber = FIRST_NON_ROOT_PORT_NUMBER; } - if ( minPortNumber != null && maxPortNumber == null ) - { - getLog().debug( "maxPortNumber unspecified: using default value " + MAX_PORT_NUMBER ); + if (minPortNumber != null && maxPortNumber == null) { + getLog().debug("maxPortNumber unspecified: using default value " + MAX_PORT_NUMBER); maxPortNumber = MAX_PORT_NUMBER; } - if ( minPortNumber == null && maxPortNumber == null ) - { - return new ServerSocket( 0 ); + if (minPortNumber == null && maxPortNumber == null) { + return new ServerSocket(0); } - if ( randomPort ) - { - synchronized ( lock ) - { + if (randomPort) { + synchronized (lock) { List availablePorts = randomPortList(); - for ( Iterator iterator = availablePorts.iterator(); iterator.hasNext(); ) - { + for (Iterator iterator = availablePorts.iterator(); iterator.hasNext(); ) { int port = iterator.next(); - ServerSocket serverSocket = reservePort( port ); + ServerSocket serverSocket = reservePort(port); iterator.remove(); - if ( serverSocket != null ) - { + if (serverSocket != null) { return serverSocket; } } - throw new MojoExecutionException( "Unable to find an available port between " + minPortNumber + " and " - + maxPortNumber ); + throw new MojoExecutionException( + "Unable to find an available port between " + minPortNumber + " and " + maxPortNumber); } - } - else - { + } else { // Might be synchronizing a bit too largely, but at least that defensive approach should prevent // threading issues (essentially possible while put/getting the plugin ctx to get the reserved ports). - synchronized ( lock ) - { + synchronized (lock) { int min = getNextPortNumber(); - for ( int port = min;; ++port ) - { + for (int port = min; ; ++port) { - ServerSocket serverSocket = reservePort( port ); - if ( serverSocket != null ) - { + ServerSocket serverSocket = reservePort(port); + if (serverSocket != null) { return serverSocket; } } @@ -281,74 +237,59 @@ private ServerSocket getServerSocket() } } - private List randomPortList() - { + private List randomPortList() { int difference = maxPortNumber - minPortNumber + 1; - List portList = new ArrayList( difference ); + List portList = new ArrayList(difference); List reservedPorts = getReservedPorts(); - for ( int i = 0; i < difference; i++ ) - { + for (int i = 0; i < difference; i++) { int port = minPortNumber + i; - if ( !reservedPorts.contains( port ) ) - { - portList.add( minPortNumber + i ); + if (!reservedPorts.contains(port)) { + portList.add(minPortNumber + i); } } - Collections.shuffle( portList ); + Collections.shuffle(portList); return portList; } - public ServerSocket reservePort( int port ) - throws MojoExecutionException - { + public ServerSocket reservePort(int port) throws MojoExecutionException { - if ( port > maxPortNumber ) - { - throw new MojoExecutionException( "Unable to find an available port between " + minPortNumber + " and " - + maxPortNumber ); + if (port > maxPortNumber) { + throw new MojoExecutionException( + "Unable to find an available port between " + minPortNumber + " and " + maxPortNumber); } - try - { - ServerSocket serverSocket = new ServerSocket( port ); - getLog().info( "Port assigned " + port ); + try { + ServerSocket serverSocket = new ServerSocket(port); + getLog().info("Port assigned " + port); return serverSocket; - } - catch ( IOException ioe ) - { - getLog().info( "Tried binding to port " + port + " without success. Trying next port.", ioe ); + } catch (IOException ioe) { + getLog().info("Tried binding to port " + port + " without success. Trying next port.", ioe); } return null; } - private int getNextPortNumber() - { + private int getNextPortNumber() { assert minPortNumber != null; List reservedPorts = getReservedPorts(); int nextPort = -1; - if ( reservedPorts.isEmpty() ) - { + if (reservedPorts.isEmpty()) { nextPort = minPortNumber; + } else { + nextPort = findAvailablePortNumber(minPortNumber, reservedPorts); } - else - { - nextPort = findAvailablePortNumber( minPortNumber, reservedPorts ); - } - reservedPorts.add( nextPort ); - getLog().debug( "Next port: " + nextPort ); + reservedPorts.add(nextPort); + getLog().debug("Next port: " + nextPort); return nextPort; } - @SuppressWarnings( "unchecked" ) - private List getReservedPorts() - { + @SuppressWarnings("unchecked") + private List getReservedPorts() { - List reservedPorts = (List) getPluginContext().get( BUILD_HELPER_RESERVED_PORTS ); - if ( reservedPorts == null ) - { + List reservedPorts = (List) getPluginContext().get(BUILD_HELPER_RESERVED_PORTS); + if (reservedPorts == null) { reservedPorts = new ArrayList(); - getPluginContext().put( BUILD_HELPER_RESERVED_PORTS, reservedPorts ); + getPluginContext().put(BUILD_HELPER_RESERVED_PORTS, reservedPorts); } return reservedPorts; } @@ -361,87 +302,63 @@ private List getReservedPorts() * @param reservedPorts the ports already reserved. * @return first number available not in the given list, starting at the given parameter. */ - private int findAvailablePortNumber( Integer portNumberStartingPoint, List reservedPorts ) - { + private int findAvailablePortNumber(Integer portNumberStartingPoint, List reservedPorts) { assert portNumberStartingPoint != null; int candidate = portNumberStartingPoint; - while ( reservedPorts.contains( candidate ) ) - { + while (reservedPorts.contains(candidate)) { candidate++; } return candidate; } - private void loadUrls() - throws MojoExecutionException - { - for ( String url : urls ) - { - load( new UrlResource( url ) ); + private void loadUrls() throws MojoExecutionException { + for (String url : urls) { + load(new UrlResource(url)); } } - private void load( UrlResource resource ) - throws MojoExecutionException - { - if ( resource.canBeOpened() ) - { - loadPortNamesFromResource( resource ); - } - else - { - throw new MojoExecutionException( "Port names could not be loaded from \"" + resource + "\"" ); + private void load(UrlResource resource) throws MojoExecutionException { + if (resource.canBeOpened()) { + loadPortNamesFromResource(resource); + } else { + throw new MojoExecutionException("Port names could not be loaded from \"" + resource + "\""); } } - private void loadPortNamesFromResource( UrlResource resource ) - throws MojoExecutionException - { - try - { - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "Loading port names from " + resource ); + private void loadPortNamesFromResource(UrlResource resource) throws MojoExecutionException { + try { + if (getLog().isDebugEnabled()) { + getLog().debug("Loading port names from " + resource); } final InputStream stream = resource.getInputStream(); - try - { - BufferedReader reader = new BufferedReader( new InputStreamReader( stream ) ); + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); List names = new ArrayList(); String line; - while ( ( line = reader.readLine() ) != null ) - { + while ((line = reader.readLine()) != null) { line = line.trim(); - if ( !line.isEmpty() && !line.replace( " ", "" ).startsWith( "#" ) ) - { - names.add( line ); + if (!line.isEmpty() && !line.replace(" ", "").startsWith("#")) { + names.add(line); } } - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "Loaded port names " + names ); + if (getLog().isDebugEnabled()) { + getLog().debug("Loaded port names " + names); } - String[] tPortNames = names.toArray( new String[portNames.length + names.size()] ); - if ( portNames.length > 0 ) - { - System.arraycopy( portNames, 0, tPortNames, names.size(), portNames.length ); + String[] tPortNames = names.toArray(new String[portNames.length + names.size()]); + if (portNames.length > 0) { + System.arraycopy(portNames, 0, tPortNames, names.size(), portNames.length); } portNames = tPortNames; - } - finally - { + } finally { stream.close(); } - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Error reading port names from \"" + resource + "\"", e ); + } catch (IOException e) { + throw new MojoExecutionException("Error reading port names from \"" + resource + "\"", e); } } - private class UrlResource - { + private class UrlResource { private static final String CLASSPATH_PREFIX = "classpath:"; private static final String SLASH_PREFIX = "/"; @@ -454,78 +371,55 @@ private class UrlResource private InputStream stream; - public UrlResource( String url ) - throws MojoExecutionException - { - if ( url.startsWith( CLASSPATH_PREFIX ) ) - { - String resource = url.substring( CLASSPATH_PREFIX.length(), url.length() ); - if ( resource.startsWith( SLASH_PREFIX ) ) - { - resource = resource.substring( 1, resource.length() ); + public UrlResource(String url) throws MojoExecutionException { + if (url.startsWith(CLASSPATH_PREFIX)) { + String resource = url.substring(CLASSPATH_PREFIX.length(), url.length()); + if (resource.startsWith(SLASH_PREFIX)) { + resource = resource.substring(1, resource.length()); } - this.url = getClass().getClassLoader().getResource( resource ); - if ( this.url == null ) - { - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "Can not load classpath resouce \"" + url + "\"" ); + this.url = getClass().getClassLoader().getResource(resource); + if (this.url == null) { + if (getLog().isDebugEnabled()) { + getLog().debug("Can not load classpath resouce \"" + url + "\""); } isMissingClasspathResouce = true; classpathUrl = url; } - } - else - { - try - { - this.url = new URL( url ); - } - catch ( MalformedURLException e ) - { - throw new MojoExecutionException( "Badly formed URL " + url + " - " + e.getMessage() ); + } else { + try { + this.url = new URL(url); + } catch (MalformedURLException e) { + throw new MojoExecutionException("Badly formed URL " + url + " - " + e.getMessage()); } } } - public InputStream getInputStream() - throws IOException - { - if ( stream == null ) - { + public InputStream getInputStream() throws IOException { + if (stream == null) { stream = openStream(); } return stream; } - public boolean canBeOpened() - { - if ( isMissingClasspathResouce ) - { + public boolean canBeOpened() { + if (isMissingClasspathResouce) { return false; } - try - { + try { openStream().close(); - } - catch ( IOException e ) - { + } catch (IOException e) { return false; } return true; } - private InputStream openStream() - throws IOException - { - return new BufferedInputStream( url.openStream() ); + private InputStream openStream() throws IOException { + return new BufferedInputStream(url.openStream()); } @Override - public String toString() - { - if ( !isMissingClasspathResouce ) - { + public String toString() { + if (!isMissingClasspathResouce) { return "URL " + url.toString(); } return classpathUrl; diff --git a/src/main/java/org/codehaus/mojo/buildhelper/RootLocationMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/RootLocationMojo.java index 644281f1..53811a8b 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/RootLocationMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/RootLocationMojo.java @@ -26,44 +26,39 @@ * @author Karl Heinz Marbaise * @since 3.0.0 */ -@Mojo( name = "rootlocation", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true, requiresProject = true ) -public class RootLocationMojo - extends AbstractDefinePropertyMojo -{ +@Mojo(name = "rootlocation", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true, requiresProject = true) +public class RootLocationMojo extends AbstractDefinePropertyMojo { - @Parameter( defaultValue = "${session}", readonly = true, required = true ) + @Parameter(defaultValue = "${session}", readonly = true, required = true) private MavenSession session; + @Component private ProjectBuilder projectBuilder; /** * This will cause the execution to be run only at the top of a given module tree. */ - @Parameter( property = "buildhelper.runOnlyAtExecutionRoot", defaultValue = "false" ) + @Parameter(property = "buildhelper.runOnlyAtExecutionRoot", defaultValue = "false") private boolean runOnlyAtExecutionRoot; /** * The name of the property in which to store the root location. */ - @Parameter( defaultValue = "rootlocation" ) + @Parameter(defaultValue = "rootlocation") private String rootLocationProperty; /** * Main plugin execution */ - public void execute() throws MojoFailureException - { - if ( runOnlyAtExecutionRoot && !getProject().isExecutionRoot() ) - { - getLog().info( "Skip getting the rootlocation in this project because it's not the Execution Root" ); - } - else - { + public void execute() throws MojoFailureException { + if (runOnlyAtExecutionRoot && !getProject().isExecutionRoot()) { + getLog().info("Skip getting the rootlocation in this project because it's not the Execution Root"); + } else { try { MavenProject topLevelProject = getLocalRoot(project); - defineProperty( rootLocationProperty, topLevelProject.getBasedir().getAbsolutePath() ); - } - catch (IOException ex) { + defineProperty( + rootLocationProperty, topLevelProject.getBasedir().getAbsolutePath()); + } catch (IOException ex) { throw new MojoFailureException("Unable to detect root location: " + ex.getMessage(), ex); } } @@ -75,51 +70,46 @@ public void execute() throws MojoFailureException * @param project The project to find the local root for. * @return The local root project (this may be the current project) */ - private MavenProject getLocalRoot( final MavenProject project ) throws IOException - { + private MavenProject getLocalRoot(final MavenProject project) throws IOException { MavenProject currentProject = project; MavenProject localRootProject = project; List parentDirs = new ArrayList<>(); - getAllParentDirectories( project.getBasedir(), parentDirs ); + getAllParentDirectories(project.getBasedir(), parentDirs); for (File parentDir : parentDirs) { - getLog().debug( "Checking to see if " + parentDir + " is an aggregator parent" ); - File parent = new File( parentDir, "pom.xml" ); - if ( parent.isFile() ) - { - try - { - final ProjectBuildingResult result = projectBuilder.build( parent, session.getProjectBuildingRequest() ); + getLog().debug("Checking to see if " + parentDir + " is an aggregator parent"); + File parent = new File(parentDir, "pom.xml"); + if (parent.isFile()) { + try { + final ProjectBuildingResult result = + projectBuilder.build(parent, session.getProjectBuildingRequest()); final MavenProject parentProject = result.getProject(); - final String currentProjectCanonicalPath = currentProject.getBasedir().getCanonicalPath(); - if ( getAllChildModules( parentProject ).contains( currentProjectCanonicalPath ) ) - { - getLog().debug( parentDir + " is an aggregator parent of current project " ); + final String currentProjectCanonicalPath = + currentProject.getBasedir().getCanonicalPath(); + if (getAllChildModules(parentProject).contains(currentProjectCanonicalPath)) { + getLog().debug(parentDir + " is an aggregator parent of current project "); localRootProject = parentProject; currentProject = parentProject; + } else { + getLog().debug(parentDir + " is not an aggregator parent of current project (" + + getAllChildModules(parentProject) + "/" + currentProjectCanonicalPath + ") "); } - else - { - getLog().debug( parentDir + " is not an aggregator parent of current project ("+getAllChildModules( parentProject )+"/"+currentProjectCanonicalPath+") " ); - } - } - catch ( ProjectBuildingException e ) - { - getLog().warn( e ); + } catch (ProjectBuildingException e) { + getLog().warn(e); } } } - getLog().debug( "Local aggregation root is " + localRootProject.getBasedir() ); + getLog().debug("Local aggregation root is " + localRootProject.getBasedir()); return localRootProject; } - private void getAllParentDirectories( File directory, List parents ) { + private void getAllParentDirectories(File directory, List parents) { File parent = directory.getParentFile(); - if ( parent != null && parent.isDirectory() ) { - parents.add( parent ); - getAllParentDirectories( parent, parents ); + if (parent != null && parent.isDirectory()) { + parents.add(parent); + getAllParentDirectories(parent, parents); } } @@ -129,25 +119,22 @@ private void getAllParentDirectories( File directory, List parents ) { * @param project The project. * @return the set of all child modules of the project (canonical paths). */ - private Set getAllChildModules( MavenProject project ) throws IOException - { + private Set getAllChildModules(MavenProject project) throws IOException { Model model = project.getOriginalModel(); Set paths = new TreeSet<>(); - paths.addAll( getChildModuleCanoncialPath( project, model.getModules() )); - for ( Profile profile : model.getProfiles() ) - { - paths.addAll( getChildModuleCanoncialPath( project, profile.getModules() )); + paths.addAll(getChildModuleCanoncialPath(project, model.getModules())); + for (Profile profile : model.getProfiles()) { + paths.addAll(getChildModuleCanoncialPath(project, profile.getModules())); } return paths; } - - private Set getChildModuleCanoncialPath( MavenProject project, List modules ) throws IOException { + + private Set getChildModuleCanoncialPath(MavenProject project, List modules) throws IOException { Set paths = new TreeSet<>(); for (String module : modules) { - File file = new File( project.getBasedir(), module ); + File file = new File(project.getBasedir(), module); paths.add(file.getCanonicalPath()); } return paths; } - -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/mojo/buildhelper/TimestampPropertyMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/TimestampPropertyMojo.java index 226ddcfa..fdefc479 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/TimestampPropertyMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/TimestampPropertyMojo.java @@ -45,15 +45,13 @@ * @author Stephen Connolly * @since 1.7 */ -@Mojo( name = "timestamp-property", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true ) -public class TimestampPropertyMojo - extends AbstractDefinePropertyMojo -{ +@Mojo(name = "timestamp-property", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true) +public class TimestampPropertyMojo extends AbstractDefinePropertyMojo { /** * The property to set. */ - @Parameter( required = true ) + @Parameter(required = true) private String name; /** @@ -65,13 +63,13 @@ public class TimestampPropertyMojo /** * The timezone to use for displaying time. The values are as defined by the Java {$link TimeZone} class. */ - @Parameter( defaultValue = "GMT" ) + @Parameter(defaultValue = "GMT") private String timeZone; /** * An offset to apply to the current time. */ - @Parameter( defaultValue = "0" ) + @Parameter(defaultValue = "0") private int offset; /** @@ -87,7 +85,7 @@ public class TimestampPropertyMojo *
  • year
  • * */ - @Parameter( defaultValue = "second" ) + @Parameter(defaultValue = "second") private String unit; /** @@ -99,7 +97,7 @@ public class TimestampPropertyMojo * * @since 3.2.0 */ - @Parameter( defaultValue = "current" ) + @Parameter(defaultValue = "current") private String timeSource; /** @@ -113,121 +111,80 @@ public class TimestampPropertyMojo * * @since 3.2.0 */ - @Parameter( readonly = true, defaultValue = "${session}" ) + @Parameter(readonly = true, defaultValue = "${session}") private MavenSession mavenSession; /** * {@inheritDoc} */ - public void execute() - throws MojoExecutionException, MojoFailureException - { + public void execute() throws MojoExecutionException, MojoFailureException { Locale locale; - if ( this.locale != null ) - { - String[] bits = this.locale.split( "[,_]" ); - if ( bits.length == 1 ) - { - locale = new Locale( bits[0].trim() ); + if (this.locale != null) { + String[] bits = this.locale.split("[,_]"); + if (bits.length == 1) { + locale = new Locale(bits[0].trim()); + } else if (bits.length == 2) { + locale = new Locale(bits[0].trim(), bits[1].trim()); + } else if (bits.length == 3) { + locale = new Locale(bits[0].trim(), bits[1].trim(), bits[2].trim()); + } else { + throw new MojoExecutionException("expecting language,country,variant but got more than three parts"); } - else if ( bits.length == 2 ) - { - locale = new Locale( bits[0].trim(), bits[1].trim() ); - } - else if ( bits.length == 3 ) - { - locale = new Locale( bits[0].trim(), bits[1].trim(), bits[2].trim() ); - } - else - { - throw new MojoExecutionException( "expecting language,country,variant but got more than three parts" ); - } - } - else - { + } else { locale = Locale.getDefault(); - getLog().warn( "Using platform locale (" + locale.toString() - + " actually) to format date/time, i.e. build is platform dependent!" ); + getLog().warn("Using platform locale (" + locale.toString() + + " actually) to format date/time, i.e. build is platform dependent!"); } DateFormat format; - if ( pattern == null ) - { - format = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT, locale ); - } - else - { - try - { - format = new SimpleDateFormat( pattern, locale ); - } - catch ( IllegalArgumentException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); + if (pattern == null) { + format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale); + } else { + try { + format = new SimpleDateFormat(pattern, locale); + } catch (IllegalArgumentException e) { + throw new MojoExecutionException(e.getMessage(), e); } } TimeZone timeZone; - if ( this.timeZone != null ) - { - timeZone = TimeZone.getTimeZone( this.timeZone ); - } - else - { - timeZone = TimeZone.getTimeZone( "GMT" ); + if (this.timeZone != null) { + timeZone = TimeZone.getTimeZone(this.timeZone); + } else { + timeZone = TimeZone.getTimeZone("GMT"); } Date now = new Date(); Calendar calendar = new GregorianCalendar(); - calendar.setTime( now ); - calendar.setTimeZone( timeZone ); - if ( offset != 0 && unit != null ) - { + calendar.setTime(now); + calendar.setTimeZone(timeZone); + if (offset != 0 && unit != null) { unit = unit.toLowerCase(); - if ( unit.indexOf( "millisecond" ) == 0 ) - { - calendar.add( Calendar.MILLISECOND, offset ); - } - else if ( unit.indexOf( "second" ) == 0 ) - { - calendar.add( Calendar.SECOND, offset ); - } - else if ( unit.indexOf( "minute" ) == 0 ) - { - calendar.add( Calendar.MINUTE, offset ); - } - else if ( unit.indexOf( "hour" ) == 0 ) - { - calendar.add( Calendar.HOUR, offset ); - } - else if ( unit.indexOf( "day" ) == 0 ) - { - calendar.add( Calendar.DAY_OF_MONTH, offset ); - } - else if ( unit.indexOf( "week" ) == 0 ) - { - calendar.add( Calendar.WEEK_OF_YEAR, offset ); - } - else if ( unit.indexOf( "month" ) == 0 ) - { - calendar.add( Calendar.MONTH, offset ); - } - else if ( unit.indexOf( "year" ) == 0 ) - { - calendar.add( Calendar.YEAR, offset ); + if (unit.indexOf("millisecond") == 0) { + calendar.add(Calendar.MILLISECOND, offset); + } else if (unit.indexOf("second") == 0) { + calendar.add(Calendar.SECOND, offset); + } else if (unit.indexOf("minute") == 0) { + calendar.add(Calendar.MINUTE, offset); + } else if (unit.indexOf("hour") == 0) { + calendar.add(Calendar.HOUR, offset); + } else if (unit.indexOf("day") == 0) { + calendar.add(Calendar.DAY_OF_MONTH, offset); + } else if (unit.indexOf("week") == 0) { + calendar.add(Calendar.WEEK_OF_YEAR, offset); + } else if (unit.indexOf("month") == 0) { + calendar.add(Calendar.MONTH, offset); + } else if (unit.indexOf("year") == 0) { + calendar.add(Calendar.YEAR, offset); } } - format.setTimeZone( timeZone ); + format.setTimeZone(timeZone); - if ("build".equals(timeSource)) - { - defineProperty( name, format.format( mavenSession.getStartTime() ) ); - } - else - { - defineProperty( name, format.format( calendar.getTime() ) ); + if ("build".equals(timeSource)) { + defineProperty(name, format.format(mavenSession.getStartTime())); + } else { + defineProperty(name, format.format(calendar.getTime())); } } - } diff --git a/src/main/java/org/codehaus/mojo/buildhelper/UpToDatePropertiesMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/UpToDatePropertiesMojo.java index 8f08f94c..cafd4be5 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/UpToDatePropertiesMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/UpToDatePropertiesMojo.java @@ -1,77 +1,70 @@ -package org.codehaus.mojo.buildhelper; - -/* - * The MIT License - * - * Copyright (c) 2004, The Codehaus - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import java.util.List; - -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; - -/** - * Sets multiple properties according to whether multiple sets of source and target resources are respectively up to - * date. - * - * @author Adrian Price demonfiddler@virginmedia.com - * @since 1.12 - */ -@Mojo( name = "uptodate-properties", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true ) -public class UpToDatePropertiesMojo - extends AbstractUpToDatePropertyMojo -{ - /** - * List of UpToDatePropertySettings to apply. - */ - @Parameter( required = false ) - private List upToDatePropertySettings; - - /** - * Disables the plug-in execution. - */ - @Parameter( property = "buildhelper.uptodateproperties.skip", defaultValue = "false" ) - private boolean skip; - - /** {@inheritDoc} */ - @Override - public void execute() - throws MojoExecutionException, MojoFailureException - { - if ( skip ) - { - getLog().info( "uptodate-properties is skipped." ); - return; - } - - if ( upToDatePropertySettings != null ) - { - for ( UpToDatePropertySetting config : upToDatePropertySettings ) - { - this.execute( config ); - } - } - } -} +package org.codehaus.mojo.buildhelper; + +/* + * The MIT License + * + * Copyright (c) 2004, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import java.util.List; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +/** + * Sets multiple properties according to whether multiple sets of source and target resources are respectively up to + * date. + * + * @author Adrian Price demonfiddler@virginmedia.com + * @since 1.12 + */ +@Mojo(name = "uptodate-properties", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true) +public class UpToDatePropertiesMojo extends AbstractUpToDatePropertyMojo { + /** + * List of UpToDatePropertySettings to apply. + */ + @Parameter(required = false) + private List upToDatePropertySettings; + + /** + * Disables the plug-in execution. + */ + @Parameter(property = "buildhelper.uptodateproperties.skip", defaultValue = "false") + private boolean skip; + + /** {@inheritDoc} */ + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + if (skip) { + getLog().info("uptodate-properties is skipped."); + return; + } + + if (upToDatePropertySettings != null) { + for (UpToDatePropertySetting config : upToDatePropertySettings) { + this.execute(config); + } + } + } +} diff --git a/src/main/java/org/codehaus/mojo/buildhelper/UpToDatePropertyMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/UpToDatePropertyMojo.java index 550a4654..5d855975 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/UpToDatePropertyMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/UpToDatePropertyMojo.java @@ -1,92 +1,87 @@ -package org.codehaus.mojo.buildhelper; - -/* - * The MIT License - * - * Copyright (c) 2004, The Codehaus - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.shared.model.fileset.FileSet; - -/** - * Sets a property according to whether one set of resources is up to date with respect to another. - * - * @author Adrian Price demonfiddler@virginmedia.com - * @since 1.12 - */ -@Mojo( name = "uptodate-property", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true ) -public class UpToDatePropertyMojo - extends AbstractUpToDatePropertyMojo -{ - /** - * The name of the property to set. - */ - @Parameter( required = true ) - private String name; - - /** - * Disables the plug-in execution. - */ - @Parameter( property = "buildhelper.uptodateproperty.skip", defaultValue = "false" ) - private boolean skip; - - /** - * The file set to check. - */ - @Parameter( required = true ) - private FileSet fileSet; - - /** - * The property value to set if the up-to-date condition is fulfilled. - */ - @Parameter( defaultValue = "true" ) - private String value; - - /** - * The property value to set if the up-to-date condition is not fulfilled. - */ - @Parameter( alias = "else" ) - private String elseValue; - - /** {@inheritDoc} */ - @Override - public void execute() - throws MojoExecutionException, MojoFailureException - { - if ( skip ) - { - getLog().info( "uptodate-property is skipped." ); - return; - } - - UpToDatePropertySetting config = new UpToDatePropertySetting(); - config.setName( name ); - config.setValue( value ); - config.setElse( elseValue ); - config.setFileSet( fileSet ); - execute( config ); - } -} +package org.codehaus.mojo.buildhelper; + +/* + * The MIT License + * + * Copyright (c) 2004, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.shared.model.fileset.FileSet; + +/** + * Sets a property according to whether one set of resources is up to date with respect to another. + * + * @author Adrian Price demonfiddler@virginmedia.com + * @since 1.12 + */ +@Mojo(name = "uptodate-property", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true) +public class UpToDatePropertyMojo extends AbstractUpToDatePropertyMojo { + /** + * The name of the property to set. + */ + @Parameter(required = true) + private String name; + + /** + * Disables the plug-in execution. + */ + @Parameter(property = "buildhelper.uptodateproperty.skip", defaultValue = "false") + private boolean skip; + + /** + * The file set to check. + */ + @Parameter(required = true) + private FileSet fileSet; + + /** + * The property value to set if the up-to-date condition is fulfilled. + */ + @Parameter(defaultValue = "true") + private String value; + + /** + * The property value to set if the up-to-date condition is not fulfilled. + */ + @Parameter(alias = "else") + private String elseValue; + + /** {@inheritDoc} */ + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + if (skip) { + getLog().info("uptodate-property is skipped."); + return; + } + + UpToDatePropertySetting config = new UpToDatePropertySetting(); + config.setName(name); + config.setValue(value); + config.setElse(elseValue); + config.setFileSet(fileSet); + execute(config); + } +} diff --git a/src/main/java/org/codehaus/mojo/buildhelper/UpToDatePropertySetting.java b/src/main/java/org/codehaus/mojo/buildhelper/UpToDatePropertySetting.java index c6b4b530..f1e23e0a 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/UpToDatePropertySetting.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/UpToDatePropertySetting.java @@ -1,139 +1,121 @@ -package org.codehaus.mojo.buildhelper; - -/* - * The MIT License - * - * Copyright (c) 2004, The Codehaus - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.shared.model.fileset.FileSet; -import org.codehaus.plexus.util.StringUtils; - -/** - * Holds settings for AbstractUpToDateProperty subclasses. - * - * @author Adrian Price demonfiddler@virginmedia.com - * @since 1.12 - */ -public final class UpToDatePropertySetting -{ - /** - * A set of source files. - */ - @Parameter - private FileSet fileSet; - - /** - * The name of the property to set. - */ - @Parameter( required = true ) - private String name; - - /** - * The property value to set if the up-to-date condition is fulfilled. - */ - @Parameter( defaultValue = "true" ) - private String value = "true"; - - /** - * The property value to set if the up-to-date condition is not fulfilled. - */ - @Parameter( alias = "else" ) - private String elseValue; - - public UpToDatePropertySetting() - { - } - - public String getName() - { - return name; - } - - public FileSet getFileSet() - { - return fileSet; - } - - public String getValue() - { - return value; - } - - public void setFileSet( FileSet fileSet ) - { - this.fileSet = fileSet; - } - - public void setName( String name ) - { - this.name = name; - } - - public void setValue( String value ) - { - this.value = value; - } - - public String getElse() - { - return elseValue; - } - - public void setElse( String elseValue ) - { - this.elseValue = elseValue; - } - - void validate() - { - if ( StringUtils.isBlank( name ) ) - { - throw new IllegalArgumentException( "name required" ); - } - - if ( StringUtils.isBlank( value ) ) - { - throw new IllegalArgumentException( "value required" ); - } - - if ( StringUtils.equals( value, elseValue ) ) - { - throw new IllegalArgumentException( "value and else cannot be the same" ); - } - - if ( fileSet == null ) - { - throw new IllegalArgumentException( "fileSet required" ); - } - - if ( StringUtils.isBlank( fileSet.getDirectory() ) ) - { - throw new IllegalArgumentException( "directory required for " + fileSet ); - } - - if ( fileSet.getMapper() == null ) - { - throw new IllegalArgumentException( "mapper required for " + fileSet ); - } - } -} \ No newline at end of file +package org.codehaus.mojo.buildhelper; + +/* + * The MIT License + * + * Copyright (c) 2004, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.shared.model.fileset.FileSet; +import org.codehaus.plexus.util.StringUtils; + +/** + * Holds settings for AbstractUpToDateProperty subclasses. + * + * @author Adrian Price demonfiddler@virginmedia.com + * @since 1.12 + */ +public final class UpToDatePropertySetting { + /** + * A set of source files. + */ + @Parameter + private FileSet fileSet; + + /** + * The name of the property to set. + */ + @Parameter(required = true) + private String name; + + /** + * The property value to set if the up-to-date condition is fulfilled. + */ + @Parameter(defaultValue = "true") + private String value = "true"; + + /** + * The property value to set if the up-to-date condition is not fulfilled. + */ + @Parameter(alias = "else") + private String elseValue; + + public UpToDatePropertySetting() {} + + public String getName() { + return name; + } + + public FileSet getFileSet() { + return fileSet; + } + + public String getValue() { + return value; + } + + public void setFileSet(FileSet fileSet) { + this.fileSet = fileSet; + } + + public void setName(String name) { + this.name = name; + } + + public void setValue(String value) { + this.value = value; + } + + public String getElse() { + return elseValue; + } + + public void setElse(String elseValue) { + this.elseValue = elseValue; + } + + void validate() { + if (StringUtils.isBlank(name)) { + throw new IllegalArgumentException("name required"); + } + + if (StringUtils.isBlank(value)) { + throw new IllegalArgumentException("value required"); + } + + if (StringUtils.equals(value, elseValue)) { + throw new IllegalArgumentException("value and else cannot be the same"); + } + + if (fileSet == null) { + throw new IllegalArgumentException("fileSet required"); + } + + if (StringUtils.isBlank(fileSet.getDirectory())) { + throw new IllegalArgumentException("directory required for " + fileSet); + } + + if (fileSet.getMapper() == null) { + throw new IllegalArgumentException("mapper required for " + fileSet); + } + } +} diff --git a/src/main/java/org/codehaus/mojo/buildhelper/versioning/DefaultVersioning.java b/src/main/java/org/codehaus/mojo/buildhelper/versioning/DefaultVersioning.java index b20305b6..d0f953ca 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/versioning/DefaultVersioning.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/versioning/DefaultVersioning.java @@ -3,65 +3,53 @@ /** * @author Karl Heinz Marbaise khmarbaise@apache.org */ -public class DefaultVersioning - implements Versioning -{ +public class DefaultVersioning implements Versioning { private VersionInformation vi; private String version; - public DefaultVersioning( String version ) - { + public DefaultVersioning(String version) { this.version = version; - this.vi = new VersionInformation( version ); - + this.vi = new VersionInformation(version); } - public String getVersion() - { + public String getVersion() { return this.version; } @Override - public int getMajor() - { + public int getMajor() { return this.vi.getMajor(); } @Override - public int getMinor() - { + public int getMinor() { return this.vi.getMinor(); } @Override - public int getPatch() - { + public int getPatch() { return this.vi.getPatch(); } @Override - public String getAsOSGiVersion() - { + public String getAsOSGiVersion() { StringBuffer osgiVersion = new StringBuffer(); - osgiVersion.append( this.getMajor() ); - osgiVersion.append( "." + this.getMinor() ); - osgiVersion.append( "." + this.getPatch() ); + osgiVersion.append(this.getMajor()); + osgiVersion.append("." + this.getMinor()); + osgiVersion.append("." + this.getPatch()); - if ( this.getQualifier() != null || this.getBuildNumber() != 0 ) - { - osgiVersion.append( "." ); + if (this.getQualifier() != null || this.getBuildNumber() != 0) { + osgiVersion.append("."); - if ( this.getBuildNumber() != 0 ) - { - osgiVersion.append( this.getBuildNumber() ); + if (this.getBuildNumber() != 0) { + osgiVersion.append(this.getBuildNumber()); } - if ( this.getQualifier() != null ) - { + if (this.getQualifier() != null) { // Do not allow having "." in it cause it's not allowed in OSGi. - String qualifier = this.getQualifier().replaceAll( "\\.", "_" ); - osgiVersion.append( qualifier ); + String qualifier = this.getQualifier().replaceAll("\\.", "_"); + osgiVersion.append(qualifier); } } @@ -69,15 +57,12 @@ public String getAsOSGiVersion() } @Override - public long getBuildNumber() - { + public long getBuildNumber() { return this.vi.getBuildNumber(); } @Override - public String getQualifier() - { + public String getQualifier() { return this.vi.getQualifier(); } - } diff --git a/src/main/java/org/codehaus/mojo/buildhelper/versioning/VersionInformation.java b/src/main/java/org/codehaus/mojo/buildhelper/versioning/VersionInformation.java index fcc5fdae..a0e3dc9d 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/versioning/VersionInformation.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/versioning/VersionInformation.java @@ -24,25 +24,23 @@ * SOFTWARE. */ - import java.util.regex.Matcher; import java.util.regex.Pattern; /** * This class will parse the version based on the given pattern in {@link org.codehaus.mojo.buildhelper.ParseVersionMojo}. - * + * * @author Karl Heinz Marbaise khmarbaise@apache.org * */ -public class VersionInformation -{ +public class VersionInformation { private static final String MAJOR_MINOR_PATCH_PATTERN = "^((\\d+)(\\.(\\d+)(\\.(\\d+))?)?)"; - private static final Pattern MAJOR_MINOR_PATCH = Pattern.compile( MAJOR_MINOR_PATCH_PATTERN ); + private static final Pattern MAJOR_MINOR_PATCH = Pattern.compile(MAJOR_MINOR_PATCH_PATTERN); - private static final Pattern DIGITS = Pattern.compile( MAJOR_MINOR_PATCH_PATTERN + "(.*)$" ); + private static final Pattern DIGITS = Pattern.compile(MAJOR_MINOR_PATCH_PATTERN + "(.*)$"); - private static final Pattern BUILD_NUMBER = Pattern.compile( "(((\\-)(\\d+)(.*))?)|(\\.(.*))|(\\-(.*))|(.*)$" ); + private static final Pattern BUILD_NUMBER = Pattern.compile("(((\\-)(\\d+)(.*))?)|(\\.(.*))|(\\-(.*))|(.*)$"); private int major; @@ -54,133 +52,101 @@ public class VersionInformation private String qualifier; - private void parseBuildNumber( String buildNumberPart ) - { - Matcher matcher = BUILD_NUMBER.matcher( buildNumberPart ); - if ( matcher.matches() ) - { - String buildNumber = matcher.group( 4 ); - String qualifier = matcher.group( 5 ); - - if ( buildNumber != null ) - { - setBuildNumber( Long.parseLong( buildNumber ) ); + private void parseBuildNumber(String buildNumberPart) { + Matcher matcher = BUILD_NUMBER.matcher(buildNumberPart); + if (matcher.matches()) { + String buildNumber = matcher.group(4); + String qualifier = matcher.group(5); + + if (buildNumber != null) { + setBuildNumber(Long.parseLong(buildNumber)); } - if ( matcher.group( 7 ) != null ) - { - qualifier = matcher.group( 7 ); + if (matcher.group(7) != null) { + qualifier = matcher.group(7); } // Starting with "-" - if ( matcher.group( 9 ) != null ) - { - qualifier = matcher.group( 9 ); + if (matcher.group(9) != null) { + qualifier = matcher.group(9); } - if ( qualifier != null ) - { - if ( qualifier.trim().length() == 0 ) - { - setQualifier( null ); + if (qualifier != null) { + if (qualifier.trim().length() == 0) { + setQualifier(null); + } else { + setQualifier(qualifier); } - else - { - setQualifier( qualifier ); - } - } - else - { - setQualifier( null ); + } else { + setQualifier(null); } } } - private void parseMajorMinorPatchVersion( String version ) - { - Matcher matcher = MAJOR_MINOR_PATCH.matcher( version ); - if ( matcher.matches() ) - { - String majorString = matcher.group( 2 ); - String minorString = matcher.group( 4 ); - String patchString = matcher.group( 6 ); - - if ( majorString != null ) - { - setMajor( Integer.parseInt( majorString ) ); + private void parseMajorMinorPatchVersion(String version) { + Matcher matcher = MAJOR_MINOR_PATCH.matcher(version); + if (matcher.matches()) { + String majorString = matcher.group(2); + String minorString = matcher.group(4); + String patchString = matcher.group(6); + + if (majorString != null) { + setMajor(Integer.parseInt(majorString)); } - if ( minorString != null ) - { - setMinor( Integer.parseInt( minorString ) ); + if (minorString != null) { + setMinor(Integer.parseInt(minorString)); } - if ( patchString != null ) - { - setPatch( Integer.parseInt( patchString ) ); + if (patchString != null) { + setPatch(Integer.parseInt(patchString)); } } - } - public VersionInformation( String version ) - { - Matcher matcherDigits = DIGITS.matcher( version ); - if ( matcherDigits.matches() ) - { - parseMajorMinorPatchVersion( matcherDigits.group( 1 ) ); - parseBuildNumber( matcherDigits.group( 7 ) ); - } - else - { - setQualifier( version ); + public VersionInformation(String version) { + Matcher matcherDigits = DIGITS.matcher(version); + if (matcherDigits.matches()) { + parseMajorMinorPatchVersion(matcherDigits.group(1)); + parseBuildNumber(matcherDigits.group(7)); + } else { + setQualifier(version); } } - public int getMajor() - { + public int getMajor() { return major; } - public void setMajor( int major ) - { + public void setMajor(int major) { this.major = major; } - public int getMinor() - { + public int getMinor() { return minor; } - public void setMinor( int minor ) - { + public void setMinor(int minor) { this.minor = minor; } - public int getPatch() - { + public int getPatch() { return patch; } - public void setPatch( int patch ) - { + public void setPatch(int patch) { this.patch = patch; } - public long getBuildNumber() - { + public long getBuildNumber() { return buildNumber; } - public void setBuildNumber( long buildNumber ) - { + public void setBuildNumber(long buildNumber) { this.buildNumber = buildNumber; } - public String getQualifier() - { + public String getQualifier() { return qualifier; } - public void setQualifier( String qualifier ) - { + public void setQualifier(String qualifier) { this.qualifier = qualifier; } - -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/mojo/buildhelper/versioning/Versioning.java b/src/main/java/org/codehaus/mojo/buildhelper/versioning/Versioning.java index 9b61cef4..056e038d 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/versioning/Versioning.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/versioning/Versioning.java @@ -1,7 +1,6 @@ package org.codehaus.mojo.buildhelper.versioning; -public interface Versioning -{ +public interface Versioning { int getMajor(); @@ -14,5 +13,4 @@ public interface Versioning long getBuildNumber(); String getQualifier(); - } diff --git a/src/test/java/org/codehaus/mojo/buildhelper/FixtureUtils.java b/src/test/java/org/codehaus/mojo/buildhelper/FixtureUtils.java index 27854d4a..ccf85134 100644 --- a/src/test/java/org/codehaus/mojo/buildhelper/FixtureUtils.java +++ b/src/test/java/org/codehaus/mojo/buildhelper/FixtureUtils.java @@ -1,132 +1,120 @@ -package org.codehaus.mojo.buildhelper; - -/* - * The MIT License - * - * Copyright (c) 2004, The Codehaus - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE - * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.Properties; - -/** - * A utility class for managing test resources - used by integration tests - groovy scripting. - * - * @author Adrian Price demonfiddler@virginmedia.com - * @since 1.12 - */ -public final class FixtureUtils -{ - /** - * Creates test resources defined by the specification file fixture.properties. The method creates all - * the files named by the properties, optionally setting the modification timestamp by adding the number of seconds - * specified by the property value (which must be an integer) to the current system time. - * - * @param basePath The path to the base directory against which to resolve relative paths (including - * fixture.properties). - * @throws IOException If unable to create a file or a missing parent directory. - * @throws NumberFormatException If a non-empty property value cannot be parsed as an integer. - */ - public static void createResources( String basePath ) - throws IOException - { - File baseDir = new File( basePath ); - createResources( baseDir, "fixture.properties", "UTF-8", System.currentTimeMillis() ); - } - - /** - * Creates test resources defined by a specification file. The method creates all the files named by the properties, - * optionally setting the modification timestamp by adding the number of seconds specified by the property value - * (which must be an integer) to a base timestamp. - * - * @param baseDir The base directory against which to resolve relative paths. - * @param propertiesPath The path (relative or absolute) to a Properties file whose property names are - * file paths (relative or absolute) and whose optional property values represent relative modification - * timestamps in seconds. - * @param baseTimestamp The base timestamp to use, in milliseconds since midnight on the 1st January 1970 GMT. - * @param encoding Encoding. - * @throws IOException If unable to create a file or a missing parent directory. - * @throws NumberFormatException If a non-empty property value cannot be parsed as an integer. - */ - public static void createResources( File baseDir, String propertiesPath, String encoding, long baseTimestamp ) - throws IOException - { - createResources( baseDir, new File( baseDir, propertiesPath ), encoding, baseTimestamp ); - } - - /** - * Creates test resources defined by a specification file. The method creates all the files named by the properties, - * optionally setting the modification timestamp by adding the number of seconds specified by the property value - * (which must be an integer) to a base timestamp. - * - * @param baseDir The base directory against which to resolve relative paths. - * @param propertiesFile A Properties file whose property names are file paths (relative or absolute) - * and whose optional property values represent relative modification timestamps in seconds. - * @param encoding Encoding. - * @param baseTimestamp The base timestamp to use, in milliseconds since midnight on the 1st January 1970 GMT. - * @throws IOException If unable to create a file or a missing parent directory. - * @throws NumberFormatException If a non-empty property value cannot be parsed as an integer. - */ - public static void createResources( File baseDir, File propertiesFile, String encoding, long baseTimestamp ) - throws IOException - { - Properties properties = new Properties(); - properties.load( new FileReader( propertiesFile ) ); - createResources( baseDir, properties, baseTimestamp ); - } - - /** - * Creates test resources defined by a specification file. The method creates all the files named by the properties, - * optionally setting the modification timestamp by adding the number of seconds specified by the property value - * (which must be an integer) to a base timestamp. - * - * @param baseDir The base directory against which to resolve relative paths. - * @param properties A Properties object whose property names are file paths (relative or absolute) and - * whose optional property values represent relative modification timestamps in seconds. - * @param baseTimestamp The base timestamp to use, in milliseconds since midnight on the 1st January 1970 GMT. - * @throws IOException If unable to create a file or a missing parent directory. - * @throws NumberFormatException If a non-empty property value cannot be parsed as an integer. - */ - public static void createResources( File baseDir, Properties properties, long baseTimestamp ) - throws IOException - { - for ( String propertyName : properties.stringPropertyNames() ) - { - File file = new File( baseDir, propertyName ); - File parent = file.getParentFile(); - if ( parent != null ) - parent.mkdirs(); - file.createNewFile(); - - // If required, set the last modification timestamp. - String propertyValue = properties.getProperty( propertyName ); - if ( !propertyValue.isEmpty() ) - { - int offset = Integer.parseInt( propertyValue ); - long ts = baseTimestamp + ( offset * 1000L); - file.setLastModified( ts ); - assert file.lastModified() == ts : "failed to set last modified timestamp for " - + file.getCanonicalPath(); - } - } - } - - private FixtureUtils() - { - } -} +package org.codehaus.mojo.buildhelper; + +/* + * The MIT License + * + * Copyright (c) 2004, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Properties; + +/** + * A utility class for managing test resources - used by integration tests - groovy scripting. + * + * @author Adrian Price demonfiddler@virginmedia.com + * @since 1.12 + */ +public final class FixtureUtils { + /** + * Creates test resources defined by the specification file fixture.properties. The method creates all + * the files named by the properties, optionally setting the modification timestamp by adding the number of seconds + * specified by the property value (which must be an integer) to the current system time. + * + * @param basePath The path to the base directory against which to resolve relative paths (including + * fixture.properties). + * @throws IOException If unable to create a file or a missing parent directory. + * @throws NumberFormatException If a non-empty property value cannot be parsed as an integer. + */ + public static void createResources(String basePath) throws IOException { + File baseDir = new File(basePath); + createResources(baseDir, "fixture.properties", "UTF-8", System.currentTimeMillis()); + } + + /** + * Creates test resources defined by a specification file. The method creates all the files named by the properties, + * optionally setting the modification timestamp by adding the number of seconds specified by the property value + * (which must be an integer) to a base timestamp. + * + * @param baseDir The base directory against which to resolve relative paths. + * @param propertiesPath The path (relative or absolute) to a Properties file whose property names are + * file paths (relative or absolute) and whose optional property values represent relative modification + * timestamps in seconds. + * @param baseTimestamp The base timestamp to use, in milliseconds since midnight on the 1st January 1970 GMT. + * @param encoding Encoding. + * @throws IOException If unable to create a file or a missing parent directory. + * @throws NumberFormatException If a non-empty property value cannot be parsed as an integer. + */ + public static void createResources(File baseDir, String propertiesPath, String encoding, long baseTimestamp) + throws IOException { + createResources(baseDir, new File(baseDir, propertiesPath), encoding, baseTimestamp); + } + + /** + * Creates test resources defined by a specification file. The method creates all the files named by the properties, + * optionally setting the modification timestamp by adding the number of seconds specified by the property value + * (which must be an integer) to a base timestamp. + * + * @param baseDir The base directory against which to resolve relative paths. + * @param propertiesFile A Properties file whose property names are file paths (relative or absolute) + * and whose optional property values represent relative modification timestamps in seconds. + * @param encoding Encoding. + * @param baseTimestamp The base timestamp to use, in milliseconds since midnight on the 1st January 1970 GMT. + * @throws IOException If unable to create a file or a missing parent directory. + * @throws NumberFormatException If a non-empty property value cannot be parsed as an integer. + */ + public static void createResources(File baseDir, File propertiesFile, String encoding, long baseTimestamp) + throws IOException { + Properties properties = new Properties(); + properties.load(new FileReader(propertiesFile)); + createResources(baseDir, properties, baseTimestamp); + } + + /** + * Creates test resources defined by a specification file. The method creates all the files named by the properties, + * optionally setting the modification timestamp by adding the number of seconds specified by the property value + * (which must be an integer) to a base timestamp. + * + * @param baseDir The base directory against which to resolve relative paths. + * @param properties A Properties object whose property names are file paths (relative or absolute) and + * whose optional property values represent relative modification timestamps in seconds. + * @param baseTimestamp The base timestamp to use, in milliseconds since midnight on the 1st January 1970 GMT. + * @throws IOException If unable to create a file or a missing parent directory. + * @throws NumberFormatException If a non-empty property value cannot be parsed as an integer. + */ + public static void createResources(File baseDir, Properties properties, long baseTimestamp) throws IOException { + for (String propertyName : properties.stringPropertyNames()) { + File file = new File(baseDir, propertyName); + File parent = file.getParentFile(); + if (parent != null) parent.mkdirs(); + file.createNewFile(); + + // If required, set the last modification timestamp. + String propertyValue = properties.getProperty(propertyName); + if (!propertyValue.isEmpty()) { + int offset = Integer.parseInt(propertyValue); + long ts = baseTimestamp + (offset * 1000L); + file.setLastModified(ts); + assert file.lastModified() == ts + : "failed to set last modified timestamp for " + file.getCanonicalPath(); + } + } + } + + private FixtureUtils() {} +} diff --git a/src/test/java/org/codehaus/mojo/buildhelper/ParseVersionTest.java b/src/test/java/org/codehaus/mojo/buildhelper/ParseVersionTest.java index 141c03a7..4ecb55b2 100644 --- a/src/test/java/org/codehaus/mojo/buildhelper/ParseVersionTest.java +++ b/src/test/java/org/codehaus/mojo/buildhelper/ParseVersionTest.java @@ -24,410 +24,371 @@ * SOFTWARE. */ +import java.util.Properties; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import java.util.Properties; - import static org.junit.jupiter.api.Assertions.assertEquals; -public class ParseVersionTest -{ - public static class TestParseVersionMojo - extends ParseVersionMojo - { +public class ParseVersionTest { + public static class TestParseVersionMojo extends ParseVersionMojo { private final Properties properties; - public TestParseVersionMojo( Properties properties ) - { + public TestParseVersionMojo(Properties properties) { this.properties = properties; } - protected void defineProperty( String name, String value ) - { - properties.put( name, value ); + protected void defineProperty(String name, String value) { + properties.put(name, value); } } @Nested - public class TestParseVersion - { + public class TestParseVersion { private Properties props; private ParseVersionMojo mojo; @BeforeEach - public void beforeClass() - { + public void beforeClass() { props = new Properties(); mojo = new TestParseVersionMojo(props); - mojo.setPropertyPrefix( "parsed" ); + mojo.setPropertyPrefix("parsed"); - mojo.setFormattedPropertyPrefix( "formatted" ); + mojo.setFormattedPropertyPrefix("formatted"); // The settings should in line with the given defaultValues of the parameters // in the mojo definition. - mojo.setFormatMajor( "%02d" ); - mojo.setFormatMinor( "%02d" ); - mojo.setFormatIncremental( "%02d" ); - mojo.setFormatBuildNumber( "%02d" ); + mojo.setFormatMajor("%02d"); + mojo.setFormatMinor("%02d"); + mojo.setFormatIncremental("%02d"); + mojo.setFormatBuildNumber("%02d"); } @Test public void checkJunkVersion() { // Test a junk version string - mojo.parseVersion( "junk" ); - - assertEquals( "0", props.getProperty( "parsed.majorVersion" ) ); - assertEquals( "0", props.getProperty( "parsed.minorVersion" ) ); - assertEquals( "0", props.getProperty( "parsed.incrementalVersion" ) ); - assertEquals( "junk", props.getProperty( "parsed.qualifier" ) ); - assertEquals( "0", props.getProperty( "parsed.buildNumber" ) ); - assertEquals( "0.0.0.junk", props.getProperty( "parsed.osgiVersion" ) ); + mojo.parseVersion("junk"); + + assertEquals("0", props.getProperty("parsed.majorVersion")); + assertEquals("0", props.getProperty("parsed.minorVersion")); + assertEquals("0", props.getProperty("parsed.incrementalVersion")); + assertEquals("junk", props.getProperty("parsed.qualifier")); + assertEquals("0", props.getProperty("parsed.buildNumber")); + assertEquals("0.0.0.junk", props.getProperty("parsed.osgiVersion")); } @Test public void checkBasicMavenVersionString() { // Test a basic maven version string - mojo.parseVersion( "1.0.0" ); - - assertEquals( "1", props.getProperty( "parsed.majorVersion" ) ); - assertEquals( "0", props.getProperty( "parsed.minorVersion" ) ); - assertEquals( "0", props.getProperty( "parsed.incrementalVersion" ) ); - assertEquals( "", props.getProperty( "parsed.qualifier" ) ); - assertEquals( "0", props.getProperty( "parsed.buildNumber" ) ); - assertEquals( "1.0.0", props.getProperty( "parsed.osgiVersion" ) ); + mojo.parseVersion("1.0.0"); + + assertEquals("1", props.getProperty("parsed.majorVersion")); + assertEquals("0", props.getProperty("parsed.minorVersion")); + assertEquals("0", props.getProperty("parsed.incrementalVersion")); + assertEquals("", props.getProperty("parsed.qualifier")); + assertEquals("0", props.getProperty("parsed.buildNumber")); + assertEquals("1.0.0", props.getProperty("parsed.osgiVersion")); } @Test - public void checkVersionStringWithQualifier() - { + public void checkVersionStringWithQualifier() { // Test a version string with qualifier - mojo.parseVersion( "2.3.4-beta-5" ); - - assertEquals( "2", props.getProperty( "parsed.majorVersion" ) ); - assertEquals( "3", props.getProperty( "parsed.minorVersion" ) ); - assertEquals( "4", props.getProperty( "parsed.incrementalVersion" ) ); - assertEquals( "beta-5", props.getProperty( "parsed.qualifier" ) ); - assertEquals( "0", props.getProperty( "parsed.buildNumber" ) ); - assertEquals( "2.3.4.beta-5", props.getProperty( "parsed.osgiVersion" ) ); + mojo.parseVersion("2.3.4-beta-5"); + + assertEquals("2", props.getProperty("parsed.majorVersion")); + assertEquals("3", props.getProperty("parsed.minorVersion")); + assertEquals("4", props.getProperty("parsed.incrementalVersion")); + assertEquals("beta-5", props.getProperty("parsed.qualifier")); + assertEquals("0", props.getProperty("parsed.buildNumber")); + assertEquals("2.3.4.beta-5", props.getProperty("parsed.osgiVersion")); } @Test - public void checkOSGiVersionStringWithQualifier() - { + public void checkOSGiVersionStringWithQualifier() { // Test an osgi version string - mojo.parseVersion( "2.3.4.beta_5" ); - - assertEquals( "2", props.getProperty( "parsed.majorVersion" ) ); - assertEquals( "3", props.getProperty( "parsed.minorVersion" ) ); - assertEquals( "4", props.getProperty( "parsed.incrementalVersion" ) ); - assertEquals( "beta_5", props.getProperty( "parsed.qualifier" ) ); - assertEquals( "0", props.getProperty( "parsed.buildNumber" ) ); - assertEquals( "2.3.4.beta_5", props.getProperty( "parsed.osgiVersion" ) ); + mojo.parseVersion("2.3.4.beta_5"); + + assertEquals("2", props.getProperty("parsed.majorVersion")); + assertEquals("3", props.getProperty("parsed.minorVersion")); + assertEquals("4", props.getProperty("parsed.incrementalVersion")); + assertEquals("beta_5", props.getProperty("parsed.qualifier")); + assertEquals("0", props.getProperty("parsed.buildNumber")); + assertEquals("2.3.4.beta_5", props.getProperty("parsed.osgiVersion")); } @Test - public void checkSnapshotVersion() - { + public void checkSnapshotVersion() { // Test a snapshot version string - mojo.parseVersion( "1.2.3-SNAPSHOT" ); - - assertEquals( "1", props.getProperty( "parsed.majorVersion" ) ); - assertEquals( "2", props.getProperty( "parsed.minorVersion" ) ); - assertEquals( "3", props.getProperty( "parsed.incrementalVersion" ) ); - assertEquals( "SNAPSHOT", props.getProperty( "parsed.qualifier" ) ); - assertEquals( "0", props.getProperty( "parsed.buildNumber" ) ); - assertEquals( "1.2.3.SNAPSHOT", props.getProperty( "parsed.osgiVersion" ) ); + mojo.parseVersion("1.2.3-SNAPSHOT"); + + assertEquals("1", props.getProperty("parsed.majorVersion")); + assertEquals("2", props.getProperty("parsed.minorVersion")); + assertEquals("3", props.getProperty("parsed.incrementalVersion")); + assertEquals("SNAPSHOT", props.getProperty("parsed.qualifier")); + assertEquals("0", props.getProperty("parsed.buildNumber")); + assertEquals("1.2.3.SNAPSHOT", props.getProperty("parsed.osgiVersion")); } @Test - public void checkSnapshotVersion2() - { + public void checkSnapshotVersion2() { // Test a snapshot version string - mojo.parseVersion( "2.0.17-SNAPSHOT" ); - - assertEquals( "2", props.getProperty( "parsed.majorVersion" ) ); - assertEquals( "0", props.getProperty( "parsed.minorVersion" ) ); - assertEquals( "17", props.getProperty( "parsed.incrementalVersion" ) ); - assertEquals( "SNAPSHOT", props.getProperty( "parsed.qualifier" ) ); - assertEquals( "0", props.getProperty( "parsed.buildNumber" ) ); - assertEquals( "2.0.17.SNAPSHOT", props.getProperty( "parsed.osgiVersion" ) ); + mojo.parseVersion("2.0.17-SNAPSHOT"); + + assertEquals("2", props.getProperty("parsed.majorVersion")); + assertEquals("0", props.getProperty("parsed.minorVersion")); + assertEquals("17", props.getProperty("parsed.incrementalVersion")); + assertEquals("SNAPSHOT", props.getProperty("parsed.qualifier")); + assertEquals("0", props.getProperty("parsed.buildNumber")); + assertEquals("2.0.17.SNAPSHOT", props.getProperty("parsed.osgiVersion")); } @Test - public void checkVersionStringWithBuildNumber() - { + public void checkVersionStringWithBuildNumber() { // Test a version string with a build number - mojo.parseVersion( "1.2.3-4" ); - - assertEquals( "1", props.getProperty( "parsed.majorVersion" ) ); - assertEquals( "2", props.getProperty( "parsed.minorVersion" ) ); - assertEquals( "3", props.getProperty( "parsed.incrementalVersion" ) ); - assertEquals( "", props.getProperty( "parsed.qualifier" ) ); - assertEquals( "4", props.getProperty( "parsed.buildNumber" ) ); - assertEquals( "1.2.3.4", props.getProperty( "parsed.osgiVersion" ) ); - + mojo.parseVersion("1.2.3-4"); + + assertEquals("1", props.getProperty("parsed.majorVersion")); + assertEquals("2", props.getProperty("parsed.minorVersion")); + assertEquals("3", props.getProperty("parsed.incrementalVersion")); + assertEquals("", props.getProperty("parsed.qualifier")); + assertEquals("4", props.getProperty("parsed.buildNumber")); + assertEquals("1.2.3.4", props.getProperty("parsed.osgiVersion")); } @Test - public void checkSnapshotVersionStringWithBuildNumber() - { + public void checkSnapshotVersionStringWithBuildNumber() { // Test a version string with a build number - mojo.parseVersion( "1.2.3-4-SNAPSHOT" ); - - assertEquals( "1", props.getProperty( "parsed.majorVersion" ) ); - assertEquals( "2", props.getProperty( "parsed.minorVersion" ) ); - assertEquals( "3", props.getProperty( "parsed.incrementalVersion" ) ); - assertEquals( "-SNAPSHOT", props.getProperty( "parsed.qualifier" ) ); - assertEquals( "4", props.getProperty( "parsed.buildNumber" ) ); - assertEquals( "1.2.3.4-SNAPSHOT", props.getProperty( "parsed.osgiVersion" ) ); + mojo.parseVersion("1.2.3-4-SNAPSHOT"); + + assertEquals("1", props.getProperty("parsed.majorVersion")); + assertEquals("2", props.getProperty("parsed.minorVersion")); + assertEquals("3", props.getProperty("parsed.incrementalVersion")); + assertEquals("-SNAPSHOT", props.getProperty("parsed.qualifier")); + assertEquals("4", props.getProperty("parsed.buildNumber")); + assertEquals("1.2.3.4-SNAPSHOT", props.getProperty("parsed.osgiVersion")); } - } @Nested - class TestParseNextVersion - { + class TestParseNextVersion { private Properties props; private ParseVersionMojo mojo; @BeforeEach - public void beforeClass() - { + public void beforeClass() { props = new Properties(); mojo = new TestParseVersionMojo(props); - mojo.setPropertyPrefix( "parsed" ); - mojo.setFormattedPropertyPrefix( "formatted" ); + mojo.setPropertyPrefix("parsed"); + mojo.setFormattedPropertyPrefix("formatted"); // The settings should in line with the given defaultValues of the parameters // in the mojo definition. - mojo.setFormatMajor( "%02d" ); - mojo.setFormatMinor( "%02d" ); - mojo.setFormatIncremental( "%02d" ); - mojo.setFormatBuildNumber( "%02d" ); + mojo.setFormatMajor("%02d"); + mojo.setFormatMinor("%02d"); + mojo.setFormatIncremental("%02d"); + mojo.setFormatBuildNumber("%02d"); } @Test - public void checkJunkVersion() - { - mojo.parseVersion( "junk" ); - - assertEquals( "1", props.getProperty( "parsed.nextMajorVersion" ) ); - assertEquals( "1", props.getProperty( "parsed.nextMinorVersion" ) ); - assertEquals( "1", props.getProperty( "parsed.nextIncrementalVersion" ) ); - assertEquals( "1", props.getProperty( "parsed.nextBuildNumber" ) ); + public void checkJunkVersion() { + mojo.parseVersion("junk"); + + assertEquals("1", props.getProperty("parsed.nextMajorVersion")); + assertEquals("1", props.getProperty("parsed.nextMinorVersion")); + assertEquals("1", props.getProperty("parsed.nextIncrementalVersion")); + assertEquals("1", props.getProperty("parsed.nextBuildNumber")); } @Test - public void testBasicMavenVersion() - { - mojo.parseVersion( "1.0.0" ); - - assertEquals( "2", props.getProperty( "parsed.nextMajorVersion" ) ); - assertEquals( "1", props.getProperty( "parsed.nextMinorVersion" ) ); - assertEquals( "1", props.getProperty( "parsed.nextIncrementalVersion" ) ); - assertEquals( "1", props.getProperty( "parsed.nextBuildNumber" ) ); + public void testBasicMavenVersion() { + mojo.parseVersion("1.0.0"); + + assertEquals("2", props.getProperty("parsed.nextMajorVersion")); + assertEquals("1", props.getProperty("parsed.nextMinorVersion")); + assertEquals("1", props.getProperty("parsed.nextIncrementalVersion")); + assertEquals("1", props.getProperty("parsed.nextBuildNumber")); } @Test - public void testVersionStringWithQualifier() - { - mojo.parseVersion( "2.3.4-beta-5" ); - - assertEquals( "3", props.getProperty( "parsed.nextMajorVersion" ) ); - assertEquals( "4", props.getProperty( "parsed.nextMinorVersion" ) ); - assertEquals( "5", props.getProperty( "parsed.nextIncrementalVersion" ) ); - assertEquals( "1", props.getProperty( "parsed.nextBuildNumber" ) ); + public void testVersionStringWithQualifier() { + mojo.parseVersion("2.3.4-beta-5"); + + assertEquals("3", props.getProperty("parsed.nextMajorVersion")); + assertEquals("4", props.getProperty("parsed.nextMinorVersion")); + assertEquals("5", props.getProperty("parsed.nextIncrementalVersion")); + assertEquals("1", props.getProperty("parsed.nextBuildNumber")); } @Test - public void testOSGiVersion() - { - mojo.parseVersion( "2.3.4.beta_5" ); - - assertEquals( "3", props.getProperty( "parsed.nextMajorVersion" ) ); - assertEquals( "4", props.getProperty( "parsed.nextMinorVersion" ) ); - assertEquals( "5", props.getProperty( "parsed.nextIncrementalVersion" ) ); - assertEquals( "1", props.getProperty( "parsed.nextBuildNumber" ) ); + public void testOSGiVersion() { + mojo.parseVersion("2.3.4.beta_5"); + + assertEquals("3", props.getProperty("parsed.nextMajorVersion")); + assertEquals("4", props.getProperty("parsed.nextMinorVersion")); + assertEquals("5", props.getProperty("parsed.nextIncrementalVersion")); + assertEquals("1", props.getProperty("parsed.nextBuildNumber")); } @Test - public void testSnapshotVersion() - { + public void testSnapshotVersion() { // Test a snapshot version string - mojo.parseVersion( "1.2.3-SNAPSHOT" ); + mojo.parseVersion("1.2.3-SNAPSHOT"); - assertEquals( "2", props.getProperty( "parsed.nextMajorVersion" ) ); - assertEquals( "3", props.getProperty( "parsed.nextMinorVersion" ) ); - assertEquals( "4", props.getProperty( "parsed.nextIncrementalVersion" ) ); - assertEquals( "1", props.getProperty( "parsed.nextBuildNumber" ) ); + assertEquals("2", props.getProperty("parsed.nextMajorVersion")); + assertEquals("3", props.getProperty("parsed.nextMinorVersion")); + assertEquals("4", props.getProperty("parsed.nextIncrementalVersion")); + assertEquals("1", props.getProperty("parsed.nextBuildNumber")); } @Test - public void testSnapshotVersion2() - { + public void testSnapshotVersion2() { // Test a snapshot version string - mojo.parseVersion( "2.0.17-SNAPSHOT" ); + mojo.parseVersion("2.0.17-SNAPSHOT"); - assertEquals( "3", props.getProperty( "parsed.nextMajorVersion" ) ); - assertEquals( "1", props.getProperty( "parsed.nextMinorVersion" ) ); - assertEquals( "18", props.getProperty( "parsed.nextIncrementalVersion" ) ); - assertEquals( "1", props.getProperty( "parsed.nextBuildNumber" ) ); + assertEquals("3", props.getProperty("parsed.nextMajorVersion")); + assertEquals("1", props.getProperty("parsed.nextMinorVersion")); + assertEquals("18", props.getProperty("parsed.nextIncrementalVersion")); + assertEquals("1", props.getProperty("parsed.nextBuildNumber")); } @Test - public void testVersionStringWithBuildNumber() - { - mojo.parseVersion( "1.2.3-4" ); - - assertEquals( "2", props.getProperty( "parsed.nextMajorVersion" ) ); - assertEquals( "3", props.getProperty( "parsed.nextMinorVersion" ) ); - assertEquals( "4", props.getProperty( "parsed.nextIncrementalVersion" ) ); - assertEquals( "5", props.getProperty( "parsed.nextBuildNumber" ) ); - } + public void testVersionStringWithBuildNumber() { + mojo.parseVersion("1.2.3-4"); + assertEquals("2", props.getProperty("parsed.nextMajorVersion")); + assertEquals("3", props.getProperty("parsed.nextMinorVersion")); + assertEquals("4", props.getProperty("parsed.nextIncrementalVersion")); + assertEquals("5", props.getProperty("parsed.nextBuildNumber")); + } } @Nested - class TestFormattedVersion - { + class TestFormattedVersion { private Properties props; private ParseVersionMojo mojo; @BeforeEach - public void beforeClass() - { + public void beforeClass() { props = new Properties(); mojo = new TestParseVersionMojo(props); - mojo.setPropertyPrefix( "parsed" ); - mojo.setFormattedPropertyPrefix( "formatted" ); + mojo.setPropertyPrefix("parsed"); + mojo.setFormattedPropertyPrefix("formatted"); // The settings should in line with the given defaultValues of the parameters // in the mojo definition. - mojo.setFormatMajor( "%02d" ); - mojo.setFormatMinor( "%02d" ); - mojo.setFormatIncremental( "%02d" ); - mojo.setFormatBuildNumber( "%02d" ); + mojo.setFormatMajor("%02d"); + mojo.setFormatMinor("%02d"); + mojo.setFormatIncremental("%02d"); + mojo.setFormatBuildNumber("%02d"); } @Test - public void testJunkVersion() - { - mojo.parseVersion( "junk" ); - - assertEquals( "00", props.getProperty( "formatted.majorVersion" ) ); - assertEquals( "00", props.getProperty( "formatted.minorVersion" ) ); - assertEquals( "00", props.getProperty( "formatted.incrementalVersion" ) ); - assertEquals( "00", props.getProperty( "formatted.buildNumber" ) ); - - assertEquals( "01", props.getProperty( "formatted.nextMajorVersion" ) ); - assertEquals( "01", props.getProperty( "formatted.nextMinorVersion" ) ); - assertEquals( "01", props.getProperty( "formatted.nextIncrementalVersion" ) ); - assertEquals( "01", props.getProperty( "formatted.nextBuildNumber" ) ); + public void testJunkVersion() { + mojo.parseVersion("junk"); + + assertEquals("00", props.getProperty("formatted.majorVersion")); + assertEquals("00", props.getProperty("formatted.minorVersion")); + assertEquals("00", props.getProperty("formatted.incrementalVersion")); + assertEquals("00", props.getProperty("formatted.buildNumber")); + + assertEquals("01", props.getProperty("formatted.nextMajorVersion")); + assertEquals("01", props.getProperty("formatted.nextMinorVersion")); + assertEquals("01", props.getProperty("formatted.nextIncrementalVersion")); + assertEquals("01", props.getProperty("formatted.nextBuildNumber")); } @Test - public void testBasicMavenVersion() - { - mojo.parseVersion( "1.0.0" ); - - assertEquals( "01", props.getProperty( "formatted.majorVersion" ) ); - assertEquals( "00", props.getProperty( "formatted.minorVersion" ) ); - assertEquals( "00", props.getProperty( "formatted.incrementalVersion" ) ); - assertEquals( "00", props.getProperty( "formatted.buildNumber" ) ); - - assertEquals( "02", props.getProperty( "formatted.nextMajorVersion" ) ); - assertEquals( "01", props.getProperty( "formatted.nextMinorVersion" ) ); - assertEquals( "01", props.getProperty( "formatted.nextIncrementalVersion" ) ); - assertEquals( "01", props.getProperty( "formatted.nextBuildNumber" ) ); + public void testBasicMavenVersion() { + mojo.parseVersion("1.0.0"); + + assertEquals("01", props.getProperty("formatted.majorVersion")); + assertEquals("00", props.getProperty("formatted.minorVersion")); + assertEquals("00", props.getProperty("formatted.incrementalVersion")); + assertEquals("00", props.getProperty("formatted.buildNumber")); + + assertEquals("02", props.getProperty("formatted.nextMajorVersion")); + assertEquals("01", props.getProperty("formatted.nextMinorVersion")); + assertEquals("01", props.getProperty("formatted.nextIncrementalVersion")); + assertEquals("01", props.getProperty("formatted.nextBuildNumber")); } @Test - public void testVersionStringWithQualifier() - { - mojo.parseVersion( "2.3.4-beta-5" ); - - assertEquals( "02", props.getProperty( "formatted.majorVersion" ) ); - assertEquals( "03", props.getProperty( "formatted.minorVersion" ) ); - assertEquals( "04", props.getProperty( "formatted.incrementalVersion" ) ); - assertEquals( "00", props.getProperty( "formatted.buildNumber" ) ); - - assertEquals( "03", props.getProperty( "formatted.nextMajorVersion" ) ); - assertEquals( "04", props.getProperty( "formatted.nextMinorVersion" ) ); - assertEquals( "05", props.getProperty( "formatted.nextIncrementalVersion" ) ); - assertEquals( "01", props.getProperty( "formatted.nextBuildNumber" ) ); - + public void testVersionStringWithQualifier() { + mojo.parseVersion("2.3.4-beta-5"); + + assertEquals("02", props.getProperty("formatted.majorVersion")); + assertEquals("03", props.getProperty("formatted.minorVersion")); + assertEquals("04", props.getProperty("formatted.incrementalVersion")); + assertEquals("00", props.getProperty("formatted.buildNumber")); + + assertEquals("03", props.getProperty("formatted.nextMajorVersion")); + assertEquals("04", props.getProperty("formatted.nextMinorVersion")); + assertEquals("05", props.getProperty("formatted.nextIncrementalVersion")); + assertEquals("01", props.getProperty("formatted.nextBuildNumber")); } @Test - public void testOSGiVersion() - { - mojo.parseVersion( "2.3.4.beta_5" ); - - assertEquals( "02", props.getProperty( "formatted.majorVersion" ) ); - assertEquals( "03", props.getProperty( "formatted.minorVersion" ) ); - assertEquals( "04", props.getProperty( "formatted.incrementalVersion" ) ); - assertEquals( "00", props.getProperty( "formatted.buildNumber" ) ); - - assertEquals( "03", props.getProperty( "formatted.nextMajorVersion" ) ); - assertEquals( "04", props.getProperty( "formatted.nextMinorVersion" ) ); - assertEquals( "05", props.getProperty( "formatted.nextIncrementalVersion" ) ); - assertEquals( "01", props.getProperty( "formatted.nextBuildNumber" ) ); - + public void testOSGiVersion() { + mojo.parseVersion("2.3.4.beta_5"); + + assertEquals("02", props.getProperty("formatted.majorVersion")); + assertEquals("03", props.getProperty("formatted.minorVersion")); + assertEquals("04", props.getProperty("formatted.incrementalVersion")); + assertEquals("00", props.getProperty("formatted.buildNumber")); + + assertEquals("03", props.getProperty("formatted.nextMajorVersion")); + assertEquals("04", props.getProperty("formatted.nextMinorVersion")); + assertEquals("05", props.getProperty("formatted.nextIncrementalVersion")); + assertEquals("01", props.getProperty("formatted.nextBuildNumber")); } @Test - public void testSnapshotVersion() - { + public void testSnapshotVersion() { // Test a snapshot version string - mojo.parseVersion( "1.2.3-SNAPSHOT" ); - - assertEquals( "01", props.getProperty( "formatted.majorVersion" ) ); - assertEquals( "02", props.getProperty( "formatted.minorVersion" ) ); - assertEquals( "03", props.getProperty( "formatted.incrementalVersion" ) ); - assertEquals( "00", props.getProperty( "formatted.buildNumber" ) ); + mojo.parseVersion("1.2.3-SNAPSHOT"); - assertEquals( "02", props.getProperty( "formatted.nextMajorVersion" ) ); - assertEquals( "03", props.getProperty( "formatted.nextMinorVersion" ) ); - assertEquals( "04", props.getProperty( "formatted.nextIncrementalVersion" ) ); - assertEquals( "01", props.getProperty( "formatted.nextBuildNumber" ) ); + assertEquals("01", props.getProperty("formatted.majorVersion")); + assertEquals("02", props.getProperty("formatted.minorVersion")); + assertEquals("03", props.getProperty("formatted.incrementalVersion")); + assertEquals("00", props.getProperty("formatted.buildNumber")); + assertEquals("02", props.getProperty("formatted.nextMajorVersion")); + assertEquals("03", props.getProperty("formatted.nextMinorVersion")); + assertEquals("04", props.getProperty("formatted.nextIncrementalVersion")); + assertEquals("01", props.getProperty("formatted.nextBuildNumber")); } @Test - public void testSnapshotVersion2() - { + public void testSnapshotVersion2() { // Test a snapshot version string - mojo.parseVersion( "2.0.17-SNAPSHOT" ); + mojo.parseVersion("2.0.17-SNAPSHOT"); - assertEquals( "02", props.getProperty( "formatted.majorVersion" ) ); - assertEquals( "00", props.getProperty( "formatted.minorVersion" ) ); - assertEquals( "17", props.getProperty( "formatted.incrementalVersion" ) ); - assertEquals( "00", props.getProperty( "formatted.buildNumber" ) ); + assertEquals("02", props.getProperty("formatted.majorVersion")); + assertEquals("00", props.getProperty("formatted.minorVersion")); + assertEquals("17", props.getProperty("formatted.incrementalVersion")); + assertEquals("00", props.getProperty("formatted.buildNumber")); - assertEquals( "03", props.getProperty( "formatted.nextMajorVersion" ) ); - assertEquals( "01", props.getProperty( "formatted.nextMinorVersion" ) ); - assertEquals( "18", props.getProperty( "formatted.nextIncrementalVersion" ) ); - assertEquals( "01", props.getProperty( "formatted.nextBuildNumber" ) ); + assertEquals("03", props.getProperty("formatted.nextMajorVersion")); + assertEquals("01", props.getProperty("formatted.nextMinorVersion")); + assertEquals("18", props.getProperty("formatted.nextIncrementalVersion")); + assertEquals("01", props.getProperty("formatted.nextBuildNumber")); } @Test - public void testVersionStringWithBuildNumber() - { - mojo.parseVersion( "1.2.3-4" ); - - assertEquals( "01", props.getProperty( "formatted.majorVersion" ) ); - assertEquals( "02", props.getProperty( "formatted.minorVersion" ) ); - assertEquals( "03", props.getProperty( "formatted.incrementalVersion" ) ); - assertEquals( "04", props.getProperty( "formatted.buildNumber" ) ); - - assertEquals( "02", props.getProperty( "formatted.nextMajorVersion" ) ); - assertEquals( "03", props.getProperty( "formatted.nextMinorVersion" ) ); - assertEquals( "04", props.getProperty( "formatted.nextIncrementalVersion" ) ); - assertEquals( "05", props.getProperty( "formatted.nextBuildNumber" ) ); + public void testVersionStringWithBuildNumber() { + mojo.parseVersion("1.2.3-4"); + + assertEquals("01", props.getProperty("formatted.majorVersion")); + assertEquals("02", props.getProperty("formatted.minorVersion")); + assertEquals("03", props.getProperty("formatted.incrementalVersion")); + assertEquals("04", props.getProperty("formatted.buildNumber")); + + assertEquals("02", props.getProperty("formatted.nextMajorVersion")); + assertEquals("03", props.getProperty("formatted.nextMinorVersion")); + assertEquals("04", props.getProperty("formatted.nextIncrementalVersion")); + assertEquals("05", props.getProperty("formatted.nextBuildNumber")); } - } - } diff --git a/src/test/java/org/codehaus/mojo/buildhelper/versioning/VersionInformationTest.java b/src/test/java/org/codehaus/mojo/buildhelper/versioning/VersionInformationTest.java index 9bc09e8e..664f5ec6 100644 --- a/src/test/java/org/codehaus/mojo/buildhelper/versioning/VersionInformationTest.java +++ b/src/test/java/org/codehaus/mojo/buildhelper/versioning/VersionInformationTest.java @@ -29,62 +29,59 @@ /** * @author Karl Heinz Marbaise khmarbaise@apache.org */ -public class VersionInformationTest -{ +public class VersionInformationTest { // @formatter:off - private static Object[][] createVersions() { - return new Object[][] { - { "1", 1, 0, 0, 0, null }, - { "1-23", 1, 0, 0, 23, null }, - { "1-23.heger", 1, 0, 0, 23, ".heger" }, - { "1.2-45", 1, 2, 0, 45, null }, - { "1.2-45.qual", 1, 2, 0, 45, ".qual" }, - { "1.2-45-qual", 1, 2, 0, 45, "-qual" }, - { "3.2", 3, 2, 0, 0, null }, - { "5.7.1", 5, 7, 1, 0, null }, - { "1.9.04-0012", 1, 9, 4, 12, null }, - { "01.9.04-0012", 1, 9, 4, 12, null }, - { "20.03.5-22", 20, 3, 5, 22, null }, - { "20.03.5-056", 20, 3, 5, 56, null }, - { "20.4.06.0-SNAPSHOT", 20, 4, 6, 0, "0-SNAPSHOT" }, - { "1.2.3-SNAPSHOT", 1, 2, 3, 0, "SNAPSHOT" }, - { "1.2.3-01-SNAPSHOT", 1, 2, 3, 1, "-SNAPSHOT" }, - { "1.2.3-1-SNAPSHOT", 1, 2, 3, 1, "-SNAPSHOT" }, - { "20.03.5.2016060708", 20, 3, 5, 0, "2016060708" }, - { "20.03.5-23-2016060708", 20, 3, 5, 23, "-2016060708" }, - { "20.03.5-23.2016060708", 20, 3, 5, 23, ".2016060708" }, - { "20.03.5-111.anton", 20, 3, 5, 111, ".anton" }, - { "20.03.5.22-SNAPSHOT", 20, 3, 5, 0, "22-SNAPSHOT" }, - { "20.03.5.XYZ.345", 20, 3, 5, 0, "XYZ.345" }, - { "20-88.03.5.XYZ.345", 20, 0, 0, 88, ".03.5.XYZ.345" }, - { "20.4-88.03.5.XYZ.345", 20, 4, 0, 88, ".03.5.XYZ.345" }, - { "020.04-88.03.5.XYZ.345", 20, 4, 0, 88, ".03.5.XYZ.345" }, - { "20.7.12-88.03.5.XYZ.345", 20, 7, 12, 88, ".03.5.XYZ.345" }, - { "20.03.5-111-34-anton", 20, 3, 5, 111, "-34-anton" }, - { "20.03.5-111-34.anton", 20, 3, 5, 111, "-34.anton" }, - { "junk", 0, 0, 0, 0, "junk" }, - { "2.3.4-beta_5", 2, 3, 4, 0, "beta_5" }, - { "2.3.4.beta_5", 2, 3, 4, 0, "beta_5" }, - { "1.2.3-20171002135756", 1, 2, 3, 20171002135756L, null } - }; - } - // @formatter:on + private static Object[][] createVersions() { + return new Object[][] { + {"1", 1, 0, 0, 0, null}, + {"1-23", 1, 0, 0, 23, null}, + {"1-23.heger", 1, 0, 0, 23, ".heger"}, + {"1.2-45", 1, 2, 0, 45, null}, + {"1.2-45.qual", 1, 2, 0, 45, ".qual"}, + {"1.2-45-qual", 1, 2, 0, 45, "-qual"}, + {"3.2", 3, 2, 0, 0, null}, + {"5.7.1", 5, 7, 1, 0, null}, + {"1.9.04-0012", 1, 9, 4, 12, null}, + {"01.9.04-0012", 1, 9, 4, 12, null}, + {"20.03.5-22", 20, 3, 5, 22, null}, + {"20.03.5-056", 20, 3, 5, 56, null}, + {"20.4.06.0-SNAPSHOT", 20, 4, 6, 0, "0-SNAPSHOT"}, + {"1.2.3-SNAPSHOT", 1, 2, 3, 0, "SNAPSHOT"}, + {"1.2.3-01-SNAPSHOT", 1, 2, 3, 1, "-SNAPSHOT"}, + {"1.2.3-1-SNAPSHOT", 1, 2, 3, 1, "-SNAPSHOT"}, + {"20.03.5.2016060708", 20, 3, 5, 0, "2016060708"}, + {"20.03.5-23-2016060708", 20, 3, 5, 23, "-2016060708"}, + {"20.03.5-23.2016060708", 20, 3, 5, 23, ".2016060708"}, + {"20.03.5-111.anton", 20, 3, 5, 111, ".anton"}, + {"20.03.5.22-SNAPSHOT", 20, 3, 5, 0, "22-SNAPSHOT"}, + {"20.03.5.XYZ.345", 20, 3, 5, 0, "XYZ.345"}, + {"20-88.03.5.XYZ.345", 20, 0, 0, 88, ".03.5.XYZ.345"}, + {"20.4-88.03.5.XYZ.345", 20, 4, 0, 88, ".03.5.XYZ.345"}, + {"020.04-88.03.5.XYZ.345", 20, 4, 0, 88, ".03.5.XYZ.345"}, + {"20.7.12-88.03.5.XYZ.345", 20, 7, 12, 88, ".03.5.XYZ.345"}, + {"20.03.5-111-34-anton", 20, 3, 5, 111, "-34-anton"}, + {"20.03.5-111-34.anton", 20, 3, 5, 111, "-34.anton"}, + {"junk", 0, 0, 0, 0, "junk"}, + {"2.3.4-beta_5", 2, 3, 4, 0, "beta_5"}, + {"2.3.4.beta_5", 2, 3, 4, 0, "beta_5"}, + {"1.2.3-20171002135756", 1, 2, 3, 20171002135756L, null} + }; + } + // @formatter:on @ParameterizedTest - @MethodSource("createVersions") - public void checkVersions( String version, int major, int minor, int patch, long buildNumber, String qualifier ) - { - VersionInformation vi = new VersionInformation(version); - assertEquals( vi.getMajor(), major); - assertEquals( vi.getMinor(), minor); - assertEquals( vi.getPatch(), patch); - assertEquals( vi.getBuildNumber(), buildNumber); - assertEquals( vi.getQualifier(), qualifier); - } + @MethodSource("createVersions") + public void checkVersions(String version, int major, int minor, int patch, long buildNumber, String qualifier) { + VersionInformation vi = new VersionInformation(version); + assertEquals(vi.getMajor(), major); + assertEquals(vi.getMinor(), minor); + assertEquals(vi.getPatch(), patch); + assertEquals(vi.getBuildNumber(), buildNumber); + assertEquals(vi.getQualifier(), qualifier); + } @Test - public void shouldFaileWithNumberFormatException() - { - assertThrows(NumberFormatException.class, () -> new VersionInformation("999999999999.12345678.12.beta_5")); + public void shouldFaileWithNumberFormatException() { + assertThrows(NumberFormatException.class, () -> new VersionInformation("999999999999.12345678.12.beta_5")); } }