From 31e79ea14f6e1480d8a552224c22f1488c847b77 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Mon, 5 Sep 2005 02:12:44 +0000 Subject: [PATCH] minor clean up git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@278662 13f79535-47bb-0310-9956-ffa450edef68 --- maven-mboot2/src/main/java/MBoot.java | 6 +- .../src/main/java/compile/JavacCompiler.java | 3 +- .../src/main/java/download/HttpUtils.java | 92 ++++++------ .../src/main/java/util/FileUtils.java | 64 ++++---- .../activation/FileProfileActivator.java | 1 - .../injection/DefaultProfileInjectorTest.java | 142 +++++++++--------- maven-site/src/site/apt/ant-tasks.apt | 2 +- 7 files changed, 149 insertions(+), 161 deletions(-) diff --git a/maven-mboot2/src/main/java/MBoot.java b/maven-mboot2/src/main/java/MBoot.java index b9714e45dc..8234ee75ad 100644 --- a/maven-mboot2/src/main/java/MBoot.java +++ b/maven-mboot2/src/main/java/MBoot.java @@ -316,11 +316,11 @@ public class MBoot reader.parse( new File( basedir, "maven-plugins/maven-surefire-plugin/pom.xml" ) ); List surefireDependencies = new ArrayList(); - // TODO: while we have maven-artifact in there, it needs to be filtered... + // while we have maven-artifact in there, it needs to be filtered... for ( Iterator i = reader.getDependencies().iterator(); i.hasNext(); ) { Dependency d = (Dependency) i.next(); - if ( d.getGroupId().equals( "surefire" ) || d.getGroupId().equals( "junit" ) ) + if ( "surefire".equals( d.getGroupId() ) || "junit".equals( d.getGroupId() ) ) { surefireDependencies.add( d ); } @@ -817,6 +817,7 @@ public class MBoot if ( version.indexOf( "SNAPSHOT" ) >= 0 ) { + // TODO: replace File metadata = localRepository.getMetadataFile( groupId, artifactId, version, type, finalName + ".version.txt" ); @@ -827,6 +828,7 @@ public class MBoot FileUtils.copyFile( new File( basedir, BUILD_DIR + "/" + finalName + ".jar" ), file ); + // TODO: replace file = localRepository.getMetadataFile( groupId, artifactId, null, type, artifactId + "-RELEASE.version.txt" ); IOUtil.copy( new StringReader( version ), new FileWriter( file ) ); } diff --git a/maven-mboot2/src/main/java/compile/JavacCompiler.java b/maven-mboot2/src/main/java/compile/JavacCompiler.java index f31f9af711..ab50756ed9 100644 --- a/maven-mboot2/src/main/java/compile/JavacCompiler.java +++ b/maven-mboot2/src/main/java/compile/JavacCompiler.java @@ -60,9 +60,8 @@ public class JavacCompiler return Collections.EMPTY_LIST; } - // TODO: use getLogger() - but for some reason it is null when this is used System.out.println( "Compiling " + sources.length + " source file" + ( sources.length == 1 ? "" : "s" ) + - " to " + destinationDir.getAbsolutePath() ); + " to " + destinationDir.getAbsolutePath() ); Map compilerOptions = config.getCompilerOptions(); diff --git a/maven-mboot2/src/main/java/download/HttpUtils.java b/maven-mboot2/src/main/java/download/HttpUtils.java index ae1667e9c9..c3652f6361 100644 --- a/maven-mboot2/src/main/java/download/HttpUtils.java +++ b/maven-mboot2/src/main/java/download/HttpUtils.java @@ -34,23 +34,20 @@ import java.net.URLConnection; * @author costin@dnt.ro * @author gg@grtmail.com (Added Java 1.1 style HTTP basic auth) * @author Jason van Zyl - * @todo Need to add a timeout so we can flip to a backup repository. - * @todo Download everything in a single session. - * @todo Throw meaningful exception when authentication fails. */ public class HttpUtils { /** * Use a proxy to bypass the firewall with or without authentication * - * @param proxyHost Proxy Host (if proxy is required), or null - * @param proxyPort Proxy Port (if proxy is required), or null + * @param proxyHost Proxy Host (if proxy is required), or null + * @param proxyPort Proxy Port (if proxy is required), or null * @param proxyUserName Proxy Username (if authentification is required), - * or null + * or null * @param proxyPassword Proxy Password (if authentification is required), - * or null + * or null * @throws SecurityException if an operation is not authorized by the - * SecurityManager + * SecurityManager */ public static void useProxyUser( final String proxyHost, final String proxyPort, final String proxyUserName, final String proxyPassword ) @@ -67,8 +64,8 @@ public class HttpUtils { protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication( proxyUserName, proxyPassword == null - ? new char[0] : proxyPassword.toCharArray() ); + return new PasswordAuthentication( proxyUserName, proxyPassword == null ? new char[0] + : proxyPassword.toCharArray() ); } } ); } @@ -79,20 +76,20 @@ public class HttpUtils * Retrieve a remote file. Throws an Exception on errors unless the * ifnoreErrors flag is set to True * - * @param url the of the file to retrieve + * @param url the of the file to retrieve * @param destinationFile where to store it - * @param ignoreErrors whether to ignore errors during I/O or throw an - * exception when they happen - * @param useTimestamp whether to check the modified timestamp on the - * destinationFile against the remote source - * @param proxyHost Proxy Host (if proxy is required), or null - * @param proxyPort Proxy Port (if proxy is required), or null - * @param proxyUserName Proxy Username (if authentification is required), - * or null. - * @param proxyPassword Proxy Password (if authentification is required), - * or null. - * @param useChecksum Flag to indicate the use of the checksum for the retrieved - * artifact if it is available. + * @param ignoreErrors whether to ignore errors during I/O or throw an + * exception when they happen + * @param useTimestamp whether to check the modified timestamp on the + * destinationFile against the remote source + * @param proxyHost Proxy Host (if proxy is required), or null + * @param proxyPort Proxy Port (if proxy is required), or null + * @param proxyUserName Proxy Username (if authentification is required), + * or null. + * @param proxyPassword Proxy Password (if authentification is required), + * or null. + * @param useChecksum Flag to indicate the use of the checksum for the retrieved + * artifact if it is available. * @throws IOException If an I/O exception occurs. */ public static void getFile( String url, File destinationFile, boolean ignoreErrors, boolean useTimestamp, @@ -125,18 +122,18 @@ public class HttpUtils * Retrieve a remote file. Throws an Exception on errors unless the * ifnoreErrors flag is set to True * - * @param url the of the file to retrieve + * @param url the of the file to retrieve * @param destinationFile where to store it - * @param ignoreErrors whether to ignore errors during I/O or throw an - * exception when they happen - * @param useTimestamp whether to check the modified timestamp on the - * destinationFile against the remote source - * @param proxyHost Proxy Host (if proxy is required), or null - * @param proxyPort Proxy Port (if proxy is required), or null - * @param proxyUserName Proxy Username (if authentification is required), - * or null - * @param proxyPassword Proxy Password (if authentification is required), - * or null + * @param ignoreErrors whether to ignore errors during I/O or throw an + * exception when they happen + * @param useTimestamp whether to check the modified timestamp on the + * destinationFile against the remote source + * @param proxyHost Proxy Host (if proxy is required), or null + * @param proxyPort Proxy Port (if proxy is required), or null + * @param proxyUserName Proxy Username (if authentification is required), + * or null + * @param proxyPassword Proxy Password (if authentification is required), + * or null * @throws IOException If an I/O exception occurs. */ public static void getFile( String url, File destinationFile, boolean ignoreErrors, boolean useTimestamp, @@ -166,17 +163,17 @@ public class HttpUtils /** * Retrieve a remote file. * - * @param url the URL of the file to retrieve + * @param url the URL of the file to retrieve * @param destinationFile where to store it - * @param timestamp if provided, the remote URL is only retrieved if it was - * modified more recently than timestamp. Otherwise, negative value indicates that - * the remote URL should be retrieved unconditionally. - * @param proxyHost Proxy Host (if proxy is required), or null - * @param proxyPort Proxy Port (if proxy is required), or null - * @param proxyUserName Proxy Username (if authentification is required), - * or null - * @param proxyPassword Proxy Password (if authentification is required), - * or null + * @param timestamp if provided, the remote URL is only retrieved if it was + * modified more recently than timestamp. Otherwise, negative value indicates that + * the remote URL should be retrieved unconditionally. + * @param proxyHost Proxy Host (if proxy is required), or null + * @param proxyPort Proxy Port (if proxy is required), or null + * @param proxyUserName Proxy Username (if authentification is required), + * or null + * @param proxyPassword Proxy Password (if authentification is required), + * or null * @throws IOException If an I/O exception occurs. */ public static void getFile( String url, File destinationFile, long timestamp, String proxyHost, String proxyPort, @@ -223,8 +220,7 @@ public class HttpUtils if ( httpConnection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND ) { throw new FileNotFoundException( url.toString() + " (HTTP Error: " + httpConnection.getResponseCode() + - " " + - httpConnection.getResponseMessage() + ")" ); + " " + httpConnection.getResponseMessage() + ")" ); } if ( httpConnection.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED ) { @@ -338,12 +334,12 @@ public class HttpUtils /** * set the timestamp of a named file to a specified time. * - * @param file the file to touch + * @param file the file to touch * @param timemillis in milliseconds since the start of the era * @return true if it succeeded. False means that this is a java1.1 system * and that file times can not be set * @throws RuntimeException Thrown in unrecoverable error. Likely this - * comes from file access failures. + * comes from file access failures. */ private static boolean touchFile( File file, long timemillis ) { diff --git a/maven-mboot2/src/main/java/util/FileUtils.java b/maven-mboot2/src/main/java/util/FileUtils.java index 871735fe45..f6f95c337e 100644 --- a/maven-mboot2/src/main/java/util/FileUtils.java +++ b/maven-mboot2/src/main/java/util/FileUtils.java @@ -236,7 +236,7 @@ public class FileUtils * Writes data to a file. The file will be created if it does not exist. * * @param fileName The name of the file to write. - * @param data The content to write to the file. + * @param data The content to write to the file. */ public static void fileWrite( String fileName, String data ) throws IOException @@ -261,7 +261,7 @@ public class FileUtils * Waits for NFS to propagate a file creation, imposing a timeout. * * @param fileName The name of the file. - * @param seconds The maximum time in seconds to wait. + * @param seconds The maximum time in seconds to wait. * @return True if file exists. */ public static boolean waitFor( String fileName, int seconds ) @@ -308,9 +308,6 @@ public class FileUtils /** * Given a directory and an array of extensions return an array of compliant files. *

- * TODO Should an ignore list be passed in? - * TODO Should a recurse flag be passed in? - *

* The given extensions should be like "java" and not like ".java" */ public static String[] getFilesFromExtension( String directory, String[] extensions ) @@ -341,7 +338,6 @@ public class FileUtils continue; } - //ok... transverse into this directory and get all the files... then combine //them with the current list. @@ -650,12 +646,12 @@ public class FileUtils * (and any parent directories) will be created. If a file source in * destinationDirectory exists, it will be overwritten. * - * @param source An existing File to copy. + * @param source An existing File to copy. * @param destinationDirectory A directory to copy source into. * @throws java.io.FileNotFoundException if source isn't a normal file. - * @throws IllegalArgumentException if destinationDirectory isn't a directory. - * @throws IOException if source does not exist, the file in - * destinationDirectory cannot be written to, or an IO error occurs during copying. + * @throws IllegalArgumentException if destinationDirectory isn't a directory. + * @throws IOException if source does not exist, the file in + * destinationDirectory cannot be written to, or an IO error occurs during copying. */ public static void copyFileToDirectory( final String source, final String destinationDirectory ) throws IOException @@ -668,12 +664,12 @@ public class FileUtils * (and any parent directories) will be created. If a file source in * destinationDirectory exists, it will be overwritten. * - * @param source An existing File to copy. + * @param source An existing File to copy. * @param destinationDirectory A directory to copy source into. * @throws java.io.FileNotFoundException if source isn't a normal file. - * @throws IllegalArgumentException if destinationDirectory isn't a directory. - * @throws IOException if source does not exist, the file in - * destinationDirectory cannot be written to, or an IO error occurs during copying. + * @throws IllegalArgumentException if destinationDirectory isn't a directory. + * @throws IOException if source does not exist, the file in + * destinationDirectory cannot be written to, or an IO error occurs during copying. */ public static void copyFileToDirectory( final File source, final File destinationDirectory ) throws IOException @@ -691,13 +687,13 @@ public class FileUtils * created if they don't already exist. destination will be overwritten if it * already exists. * - * @param source An existing non-directory File to copy bytes from. + * @param source An existing non-directory File to copy bytes from. * @param destination A non-directory File to write bytes to (possibly - * overwriting). - * @throws IOException if source does not exist, destination cannot be - * written to, or an IO error occurs during copying. + * overwriting). + * @throws IOException if source does not exist, destination cannot be + * written to, or an IO error occurs during copying. * @throws java.io.FileNotFoundException if destination is a directory - * (use {@link #copyFileToDirectory}). + * (use {@link #copyFileToDirectory}). */ public static void copyFile( final File source, final File destination ) throws IOException @@ -741,15 +737,15 @@ public class FileUtils * The directories up to destination will be created if they don't already exist. * destination will be overwritten if it already exists. * - * @param source A URL to copy bytes from. + * @param source A URL to copy bytes from. * @param destination A non-directory File to write bytes to (possibly - * overwriting). + * overwriting). * @throws IOException if - *

+ * */ public static void copyURLToFile( final URL source, final File destination ) throws IOException @@ -884,7 +880,7 @@ public class FileUtils * baseFile, otherwise it is treated as a normal root-relative path. * * @param baseFile Where to resolve filename from, if filename is - * relative. + * relative. * @param filename Absolute or relative file path to resolve. * @return The canonical File of filename. */ @@ -916,8 +912,6 @@ public class FileUtils return file; } - // FIXME: I'm almost certain this // removal is unnecessary, as getAbsoluteFile() strips - // them. However, I'm not sure about this UNC stuff. (JT) final char[] chars = filename.toCharArray(); final StringBuffer sb = new StringBuffer(); @@ -1374,10 +1368,10 @@ public class FileUtils * well.

* * @param from the file to move - * @param to the new file name + * @param to the new file name * @throws IOException if anything bad happens during this - * process. Note that to may have been deleted - * already when this happens. + * process. Note that to may have been deleted + * already when this happens. */ public static void rename( File from, File to ) throws IOException @@ -1418,10 +1412,10 @@ public class FileUtils * when the parentDir attribute is * null.

* - * @param prefix prefix before the random number - * @param suffix file extension; include the '.' + * @param prefix prefix before the random number + * @param suffix file extension; include the '.' * @param parentDir Directory to create the temporary file in - - * java.io.tmpdir used if not specificed + * java.io.tmpdir used if not specificed * @return a File reference to the new temporary file. */ public static File createTempFile( String prefix, String suffix, File parentDir ) diff --git a/maven-project/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java b/maven-project/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java index 99a890c7f7..55a9939cfd 100644 --- a/maven-project/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java +++ b/maven-project/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java @@ -2,7 +2,6 @@ package org.apache.maven.profiles.activation; import org.apache.maven.model.Activation; import org.apache.maven.model.ActivationFile; -import org.apache.maven.model.BuildBase; import org.apache.maven.model.Profile; import org.codehaus.plexus.util.FileUtils; diff --git a/maven-project/src/test/java/org/apache/maven/project/injection/DefaultProfileInjectorTest.java b/maven-project/src/test/java/org/apache/maven/project/injection/DefaultProfileInjectorTest.java index 3fe79f93dd..dc12f6e55a 100644 --- a/maven-project/src/test/java/org/apache/maven/project/injection/DefaultProfileInjectorTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/injection/DefaultProfileInjectorTest.java @@ -1,117 +1,115 @@ package org.apache.maven.project.injection; +import junit.framework.TestCase; import org.apache.maven.model.Build; import org.apache.maven.model.BuildBase; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; import org.apache.maven.model.Profile; import org.apache.maven.model.Repository; -import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; import org.codehaus.plexus.util.xml.Xpp3Dom; import java.util.List; -import junit.framework.TestCase; - public class DefaultProfileInjectorTest extends TestCase { - + public void testProfilePluginConfigurationShouldOverrideModelPluginConfiguration() { Plugin mPlugin = new Plugin(); - mPlugin.setGroupId("test"); - mPlugin.setArtifactId("test-artifact"); - mPlugin.setVersion("1.0-SNAPSHOT"); - - Xpp3Dom mConfigChild = new Xpp3Dom("test"); - mConfigChild.setValue("value"); - - Xpp3Dom mConfig = new Xpp3Dom("configuration"); + mPlugin.setGroupId( "test" ); + mPlugin.setArtifactId( "test-artifact" ); + mPlugin.setVersion( "1.0-SNAPSHOT" ); + + Xpp3Dom mConfigChild = new Xpp3Dom( "test" ); + mConfigChild.setValue( "value" ); + + Xpp3Dom mConfig = new Xpp3Dom( "configuration" ); mConfig.addChild( mConfigChild ); - - mPlugin.setConfiguration(mConfig); - + + mPlugin.setConfiguration( mConfig ); + Build mBuild = new Build(); - mBuild.addPlugin(mPlugin); - + mBuild.addPlugin( mPlugin ); + Model model = new Model(); - model.setBuild(mBuild); - + model.setBuild( mBuild ); + Plugin pPlugin = new Plugin(); - pPlugin.setGroupId("test"); - pPlugin.setArtifactId("test-artifact"); - pPlugin.setVersion("1.0-SNAPSHOT"); - - Xpp3Dom pConfigChild = new Xpp3Dom("test"); - pConfigChild.setValue("replacedValue"); - - Xpp3Dom pConfig = new Xpp3Dom("configuration"); + pPlugin.setGroupId( "test" ); + pPlugin.setArtifactId( "test-artifact" ); + pPlugin.setVersion( "1.0-SNAPSHOT" ); + + Xpp3Dom pConfigChild = new Xpp3Dom( "test" ); + pConfigChild.setValue( "replacedValue" ); + + Xpp3Dom pConfig = new Xpp3Dom( "configuration" ); pConfig.addChild( pConfigChild ); - - pPlugin.setConfiguration(pConfig); - + + pPlugin.setConfiguration( pConfig ); + BuildBase pBuild = new BuildBase(); - pBuild.addPlugin(pPlugin); - + pBuild.addPlugin( pPlugin ); + Profile profile = new Profile(); - profile.setId("testId"); - - profile.setBuild(pBuild); - - new DefaultProfileInjector().inject(profile, model); - + profile.setId( "testId" ); + + profile.setBuild( pBuild ); + + new DefaultProfileInjector().inject( profile, model ); + Build rBuild = model.getBuild(); - Plugin rPlugin = (Plugin) rBuild.getPlugins().get(0); + Plugin rPlugin = (Plugin) rBuild.getPlugins().get( 0 ); Xpp3Dom rConfig = (Xpp3Dom) rPlugin.getConfiguration(); - - Xpp3Dom rChild = rConfig.getChild("test"); - - assertEquals("replacedValue", rChild.getValue()); + + Xpp3Dom rChild = rConfig.getChild( "test" ); + + assertEquals( "replacedValue", rChild.getValue() ); } public void testProfileRepositoryShouldOverrideModelRepository() { Repository mRepository = new Repository(); - mRepository.setId("testId"); - mRepository.setName("Test repository"); - mRepository.setUrl("http://www.google.com"); - + mRepository.setId( "testId" ); + mRepository.setName( "Test repository" ); + mRepository.setUrl( "http://www.google.com" ); + Model model = new Model(); - model.addRepository(mRepository); - + model.addRepository( mRepository ); + Repository pRepository = new Repository(); - pRepository.setId("testId"); - pRepository.setName("Test repository"); - pRepository.setUrl("http://www.yahoo.com"); - + pRepository.setId( "testId" ); + pRepository.setName( "Test repository" ); + pRepository.setUrl( "http://www.yahoo.com" ); + Profile profile = new Profile(); - profile.setId("testId"); - - profile.addRepository(pRepository); - - new DefaultProfileInjector().inject(profile, model); - - Repository rRepository = (Repository) model.getRepositories().get(0); - - assertEquals("http://www.yahoo.com", rRepository.getUrl()); + profile.setId( "testId" ); + + profile.addRepository( pRepository ); + + new DefaultProfileInjector().inject( profile, model ); + + Repository rRepository = (Repository) model.getRepositories().get( 0 ); + + assertEquals( "http://www.yahoo.com", rRepository.getUrl() ); } public void testShouldPreserveModelModulesWhenProfileHasNone() { Model model = new Model(); - - model.addModule("module1"); - + + model.addModule( "module1" ); + Profile profile = new Profile(); - profile.setId("testId"); - - new DefaultProfileInjector().inject(profile, model); - + profile.setId( "testId" ); + + new DefaultProfileInjector().inject( profile, model ); + List rModules = model.getModules(); - - assertEquals( 1, rModules.size()); - assertEquals("module1", rModules.get(0)); + + assertEquals( 1, rModules.size() ); + assertEquals( "module1", rModules.get( 0 ) ); } } diff --git a/maven-site/src/site/apt/ant-tasks.apt b/maven-site/src/site/apt/ant-tasks.apt index 340d7240f7..4c91dd4a7d 100755 --- a/maven-site/src/site/apt/ant-tasks.apt +++ b/maven-site/src/site/apt/ant-tasks.apt @@ -390,7 +390,7 @@ Type Reference *----------------------+--------------------------------------------------------+ | <<>> | The layout of the remote repository. The valid options are <<>> (Maven 1), or <<>> (Maven 2). *----------------------+--------------------------------------------------------+ -| <<>> | How often to check for updates on dependencies with a version that includes <<>>. Valid values are <<>>, <<>>, <<>> (, <<>>. +| <<>> | How often to check for updates on dependencies with a version that includes <<>>. Valid values are <<>>, <<>>, <<>> (, <<>>. *----------------------+--------------------------------------------------------+ | <<>> | How to treat missing or incorrect checksums for the dependencies that are downloaded. Valid values are <<>> () and <<>>. *----------------------+--------------------------------------------------------+