diff options
Diffstat (limited to 'framework/src/maven/apache-maven-3.3.3/maven-embedder/src/test/java')
3 files changed, 258 insertions, 0 deletions
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerTest.java b/framework/src/maven/apache-maven-3.3.3/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerTest.java new file mode 100644 index 00000000..163d9d9d --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerTest.java @@ -0,0 +1,108 @@ +package org.apache.maven.cli; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.apache.commons.cli.Option; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.FileUtils; + +/** + * Pseudo test to generate documentation fragment about supported CLI options. + * TODO such documentation generation code should not be necessary as unit test but should be run + * during site generation (Velocity? Doxia macro?) + */ +public class CLIManagerTest + extends PlexusTestCase +{ + private final static String LS = System.getProperty( "line.separator" ); + + private static class OptionComparator + implements Comparator<Option> + { + public int compare( Option opt1, Option opt2 ) + { + return opt1.getOpt().compareToIgnoreCase( opt2.getOpt() ); + } + } + + private static class CLIManagerExtension + extends CLIManager + { + public Collection<Option> getOptions() + { + @SuppressWarnings( "unchecked" ) + List<Option> optList = new ArrayList<Option>( options.getOptions() ); + Collections.sort( optList, new OptionComparator() ); + return optList; + } + } + + public String getOptionsAsHtml() + { + StringBuilder sb = new StringBuilder(); + boolean a = true; + sb.append( "<table border='1' class='zebra-striped'><tr class='a'><th><b>Options</b></th><th><b>Description</b></th></tr>" ); + for ( Option option : new CLIManagerExtension().getOptions() ) + { + a = !a; + sb.append( "<tr class='" ).append( a ? 'a' : 'b' ).append( "'><td><code>-<a name='" ); + sb.append( option.getOpt() ); + sb.append( "'>" ); + sb.append( option.getOpt() ); + sb.append( "</a>,--<a name='" ); + sb.append( option.getLongOpt() ); + sb.append( "'>" ); + sb.append( option.getLongOpt() ); + sb.append( "</a>" ); + if ( option.hasArg() ) + { + if ( option.hasArgName() ) + { + sb.append( " <" ).append( option.getArgName() ).append( ">" ); + } + else + { + sb.append( ' ' ); + } + } + sb.append( "</code></td><td>" ); + sb.append( option.getDescription() ); + sb.append( "</td></tr>" ); + sb.append( LS ); + } + sb.append( "</table>" ); + return sb.toString(); + } + + public void testOptionsAsHtml() + throws IOException + { + File options = getTestFile( "target/test-classes/options.html" ); + FileUtils.fileWrite( options, "UTF-8", getOptionsAsHtml() ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java b/framework/src/maven/apache-maven-3.3.3/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java new file mode 100644 index 00000000..65488c7c --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-embedder/src/test/java/org/apache/maven/cli/CLIReportingUtilsTest.java @@ -0,0 +1,40 @@ +package org.apache.maven.cli; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import junit.framework.TestCase; + +public class CLIReportingUtilsTest + extends TestCase +{ + + public void testFormatDuration() + { + assertEquals( "0.001 s", CLIReportingUtils.formatDuration( 1 ) ); + assertEquals( "0.999 s", CLIReportingUtils.formatDuration( 1000 - 1 ) ); + assertEquals( "1.000 s", CLIReportingUtils.formatDuration( 1000 ) ); + assertEquals( "59.999 s", CLIReportingUtils.formatDuration( 60 * 1000 - 1 ) ); + assertEquals( "01:00 min", CLIReportingUtils.formatDuration( 60 * 1000 ) ); + assertEquals( "59:59 min", CLIReportingUtils.formatDuration( 60 * 60 * 1000 - 1 ) ); + assertEquals( "01:00 h", CLIReportingUtils.formatDuration( 60 * 60 * 1000 ) ); + assertEquals( "23:59 h", CLIReportingUtils.formatDuration( 24 * 60 * 60 * 1000 - 1 ) ); + assertEquals( "1 d 00:00 h", CLIReportingUtils.formatDuration( 24 * 60 * 60 * 1000 ) ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java b/framework/src/maven/apache-maven-3.3.3/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java new file mode 100644 index 00000000..c8d75b10 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java @@ -0,0 +1,110 @@ +package org.apache.maven.cli; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; + +import junit.framework.TestCase; + +import org.apache.commons.cli.ParseException; + +public class MavenCliTest + extends TestCase +{ + private MavenCli cli; + + private String origBasedir; + + protected void setUp() + { + cli = new MavenCli(); + origBasedir = System.getProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY ); + } + + @Override + protected void tearDown() + throws Exception + { + if ( origBasedir != null ) + { + System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY, origBasedir ); + } + else + { + System.getProperties().remove( MavenCli.MULTIMODULE_PROJECT_DIRECTORY ); + } + super.tearDown(); + } + + public void testCalculateDegreeOfConcurrencyWithCoreMultiplier() + { + int cores = Runtime.getRuntime().availableProcessors(); + // -T2.2C + assertEquals( (int) ( cores * 2.2 ), cli.calculateDegreeOfConcurrencyWithCoreMultiplier( "C2.2" ) ); + // -TC2.2 + assertEquals( (int) ( cores * 2.2 ), cli.calculateDegreeOfConcurrencyWithCoreMultiplier( "2.2C" ) ); + + try + { + cli.calculateDegreeOfConcurrencyWithCoreMultiplier( "CXXX" ); + fail( "Should have failed with a NumberFormatException" ); + } + catch ( NumberFormatException e ) + { + // carry on + } + } + + public void testMavenConfig() + throws Exception + { + System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY, new File( "src/test/projects/config" ).getCanonicalPath() ); + CliRequest request = new CliRequest( new String[0], null ); + + // read .mvn/maven.config + cli.initialize( request ); + cli.cli( request ); + assertEquals( "multithreaded", request.commandLine.getOptionValue( "builder" ) ); + assertEquals( "8", request.commandLine.getOptionValue( "threads" ) ); + + // override from command line + request = new CliRequest( new String[] { "--builder", "foobar" }, null ); + cli.cli( request ); + assertEquals( "foobar", request.commandLine.getOptionValue( "builder" ) ); + } + + public void testMavenConfigInvalid() + throws Exception + { + System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY, new File( "src/test/projects/config-illegal" ).getCanonicalPath() ); + CliRequest request = new CliRequest( new String[0], null ); + + cli.initialize( request ); + try + { + cli.cli( request ); + fail(); + } + catch ( ParseException expected ) + { + + } + } +} |