clean up some issues and bugs highlighted by inspections

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@417674 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2006-06-28 05:45:08 +00:00
parent e0182bf24e
commit 7a5b4547af
15 changed files with 135 additions and 162 deletions

View File

@ -105,9 +105,7 @@ public class DefaultRepositoryConverter
*/
private I18N i18n;
public void convert( Artifact artifact,
ArtifactRepository targetRepository,
ArtifactReporter reporter )
public void convert( Artifact artifact, ArtifactRepository targetRepository, ArtifactReporter reporter )
throws RepositoryConversionException
{
if ( artifact.getRepository().getUrl().equals( targetRepository.getUrl() ) )
@ -165,15 +163,13 @@ public class DefaultRepositoryConverter
return metadata;
}
private void updateMetadata( RepositoryMetadata artifactMetadata,
ArtifactRepository sourceRepository,
ArtifactRepository targetRepository,
Metadata newMetadata,
private void updateMetadata( RepositoryMetadata artifactMetadata, ArtifactRepository sourceRepository,
ArtifactRepository targetRepository, Metadata newMetadata,
FileTransaction transaction )
throws RepositoryConversionException
{
Metadata metadata;
boolean changed = false;
boolean changed;
//merge with target repository metadata
File file = new File( targetRepository.getBasedir(),
@ -198,7 +194,7 @@ public class DefaultRepositoryConverter
if ( srcfile.exists() )
{
Metadata sourceMetadata = readMetadata( srcfile );
changed = changed | metadata.merge( sourceMetadata );
changed = changed || metadata.merge( sourceMetadata );
}
}
@ -256,8 +252,7 @@ public class DefaultRepositoryConverter
return metadata;
}
private boolean validateMetadata( Artifact artifact,
ArtifactReporter reporter )
private boolean validateMetadata( Artifact artifact, ArtifactReporter reporter )
throws RepositoryConversionException
{
ArtifactRepository repository = artifact.getRepository();
@ -284,9 +279,7 @@ public class DefaultRepositoryConverter
return result;
}
private boolean validateMetadata( Metadata metadata,
RepositoryMetadata repositoryMetadata,
Artifact artifact,
private boolean validateMetadata( Metadata metadata, RepositoryMetadata repositoryMetadata, Artifact artifact,
ArtifactReporter reporter )
{
String groupIdKey;
@ -388,9 +381,7 @@ public class DefaultRepositoryConverter
return result;
}
private boolean copyPom( Artifact artifact,
ArtifactRepository targetRepository,
ArtifactReporter reporter,
private boolean copyPom( Artifact artifact, ArtifactRepository targetRepository, ArtifactReporter reporter,
FileTransaction transaction )
throws RepositoryConversionException
{
@ -505,10 +496,8 @@ public class DefaultRepositoryConverter
return result;
}
private boolean doRelocation( Artifact artifact,
org.apache.maven.model.v3_0_0.Model v3Model,
ArtifactRepository repository,
FileTransaction transaction )
private boolean doRelocation( Artifact artifact, org.apache.maven.model.v3_0_0.Model v3Model,
ArtifactRepository repository, FileTransaction transaction )
throws IOException
{
Properties properties = v3Model.getProperties();
@ -551,15 +540,9 @@ public class DefaultRepositoryConverter
}
}
private void writeRelocationPom( String groupId,
String artifactId,
String version,
String newGroupId,
String newArtifactId,
String newVersion,
String message,
ArtifactRepository repository,
FileTransaction transaction )
private void writeRelocationPom( String groupId, String artifactId, String version, String newGroupId,
String newArtifactId, String newVersion, String message,
ArtifactRepository repository, FileTransaction transaction )
throws IOException
{
Model pom = new Model();
@ -592,8 +575,7 @@ public class DefaultRepositoryConverter
transaction.createFile( strWriter.toString(), pomFile );
}
private String getI18NString( String key,
String arg0 )
private String getI18NString( String key, String arg0 )
{
return i18n.format( getClass().getName(), Locale.getDefault(), key, arg0 );
}
@ -603,26 +585,19 @@ public class DefaultRepositoryConverter
return i18n.getString( getClass().getName(), Locale.getDefault(), key );
}
private boolean testChecksums( Artifact artifact,
File file,
ArtifactReporter reporter )
throws IOException, RepositoryConversionException
private boolean testChecksums( Artifact artifact, File file, ArtifactReporter reporter )
throws IOException
{
boolean result;
result = verifyChecksum( file, file.getName() + ".md5", Digester.MD5, reporter, artifact,
"failure.incorrect.md5" );
boolean result =
verifyChecksum( file, file.getName() + ".md5", Digester.MD5, reporter, artifact, "failure.incorrect.md5" );
result = result && verifyChecksum( file, file.getName() + ".sha1", Digester.SHA1, reporter, artifact,
"failure.incorrect.sha1" );
return result;
}
private boolean verifyChecksum( File file,
String fileName,
String algorithm,
ArtifactReporter reporter,
Artifact artifact,
String key )
private boolean verifyChecksum( File file, String fileName, String algorithm, ArtifactReporter reporter,
Artifact artifact, String key )
throws IOException
{
boolean result = true;
@ -644,9 +619,7 @@ public class DefaultRepositoryConverter
return result;
}
private boolean copyArtifact( Artifact artifact,
ArtifactRepository targetRepository,
ArtifactReporter reporter,
private boolean copyArtifact( Artifact artifact, ArtifactRepository targetRepository, ArtifactReporter reporter,
FileTransaction transaction )
throws RepositoryConversionException
{
@ -689,9 +662,7 @@ public class DefaultRepositoryConverter
return result;
}
public void convert( List artifacts,
ArtifactRepository targetRepository,
ArtifactReporter reporter )
public void convert( List artifacts, ArtifactRepository targetRepository, ArtifactReporter reporter )
throws RepositoryConversionException
{
for ( Iterator i = artifacts.iterator(); i.hasNext(); )

View File

@ -1,16 +1,16 @@
package org.apache.maven.repository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.repository.converter.RepositoryConversionException;
import org.apache.maven.repository.converter.RepositoryConverter;
import org.apache.maven.repository.discovery.ArtifactDiscoverer;
import org.apache.maven.repository.reporting.ArtifactReporter;
import java.io.File;
import java.util.List;
import java.net.MalformedURLException;
import java.util.List;
/**
* @author Jason van Zyl
@ -49,8 +49,7 @@ public class DefaultRepositoryManager
*/
private ArtifactReporter reporter;
public void convertLegacyRepository( File legacyRepositoryDirectory,
File repositoryDirectory,
public void convertLegacyRepository( File legacyRepositoryDirectory, File repositoryDirectory,
boolean includeSnapshots )
throws RepositoryConversionException
{

View File

@ -81,10 +81,9 @@ public abstract class AbstractArtifactDiscoverer
{
String path = artifactPaths[i];
Artifact artifact;
try
{
artifact = buildArtifactFromPath( path, repository );
Artifact artifact = buildArtifactFromPath( path, repository );
if ( includeSnapshots || !artifact.isSnapshot() )
{

View File

@ -49,7 +49,7 @@ public class DefaultArtifactDiscoverer
Collections.reverse( pathParts );
Artifact artifact = null;
Artifact artifact;
if ( pathParts.size() >= 4 )
{
// maven 2.x path
@ -111,13 +111,13 @@ public class DefaultArtifactDiscoverer
Artifact result;
if ( classifier == null )
{
result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME,
type );
result =
artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, type );
}
else
{
result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type,
classifier );
result =
artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
}
if ( result.isSnapshot() )
@ -128,9 +128,8 @@ public class DefaultArtifactDiscoverer
{
classifier = remainingFilename.substring( classifierIndex + 1 );
remainingFilename = remainingFilename.substring( 0, classifierIndex );
result = artifactFactory.createArtifactWithClassifier( groupId, artifactId,
remainingFilename, type,
classifier );
result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, remainingFilename,
type, classifier );
}
else
{
@ -145,8 +144,8 @@ public class DefaultArtifactDiscoverer
}
else if ( !result.getBaseVersion().equals( version ) )
{
throw new DiscovererException( "Built snapshot artifact base version does not match " +
"path version" );
throw new DiscovererException(
"Built snapshot artifact base version does not match " + "path version" );
}
else
{

View File

@ -21,17 +21,20 @@ package org.apache.maven.repository.discovery;
*/
public class DiscovererPath
{
private String path;
private String comment;
/**
* The path discovered.
*/
private final String path;
public DiscovererPath()
{
}
/**
* A comment about why the path is being processed.
*/
private final String comment;
public DiscovererPath( String path, String comment )
{
setPath( path );
setComment( comment );
this.path = path;
this.comment = comment;
}
public String getPath()
@ -39,18 +42,8 @@ public class DiscovererPath
return path;
}
public void setPath( String path )
{
this.path = path;
}
public String getComment()
{
return comment;
}
public void setComment( String comment )
{
this.comment = comment;
}
}

View File

@ -20,19 +20,19 @@ import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.CharTokenizer;
import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.document.Document;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.util.Collection;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.zip.ZipEntry;
/**
@ -71,8 +71,7 @@ public abstract class AbstractRepositoryIndex
}
catch ( IOException e )
{
throw new RepositoryIndexException( "Failed to validate index path: " +
getIndexPath().getAbsolutePath(), e );
throw new RepositoryIndexException( "Failed to validate index path: " + indexPath.getAbsolutePath(), e );
}
}
@ -148,7 +147,7 @@ public abstract class AbstractRepositoryIndex
/**
* @see RepositoryIndex#validate()
*/
public void validate()
public final void validate()
throws RepositoryIndexException, IOException
{
if ( indexExists() )

View File

@ -26,61 +26,62 @@ import java.util.List;
/**
* @author Edwin Punzalan
* @todo can we move all of these constants out of the interface? Perhaps they should be an enumerated type?
*/
public interface RepositoryIndex
{
static final String POM = "POM";
String POM = "POM";
static final String METADATA = "METADATA";
String METADATA = "METADATA";
static final String ARTIFACT = "ARTIFACT";
String ARTIFACT = "ARTIFACT";
static final String FLD_ID = "id";
String FLD_ID = "id";
static final String FLD_NAME = "name";
String FLD_NAME = "name";
static final String FLD_DOCTYPE = "doctype";
String FLD_DOCTYPE = "doctype";
static final String FLD_GROUPID = "groupId";
String FLD_GROUPID = "groupId";
static final String FLD_ARTIFACTID = "artifactId";
String FLD_ARTIFACTID = "artifactId";
static final String FLD_VERSION = "version";
String FLD_VERSION = "version";
static final String FLD_PACKAGING = "packaging";
String FLD_PACKAGING = "packaging";
static final String FLD_SHA1 = "sha1";
String FLD_SHA1 = "sha1";
static final String FLD_MD5 = "md5";
String FLD_MD5 = "md5";
static final String FLD_LASTUPDATE = "last update";
String FLD_LASTUPDATE = "last update";
static final String FLD_PLUGINPREFIX = "plugin prefix";
String FLD_PLUGINPREFIX = "plugin prefix";
static final String FLD_CLASSES = "class";
String FLD_CLASSES = "class";
static final String FLD_PACKAGES = "package";
String FLD_PACKAGES = "package";
static final String FLD_FILES = "file";
String FLD_FILES = "file";
static final String FLD_LICENSE_URLS = "license url";
String FLD_LICENSE_URLS = "license url";
static final String FLD_DEPENDENCIES = "dependency";
String FLD_DEPENDENCIES = "dependency";
static final String FLD_PLUGINS_BUILD = "build plugin";
String FLD_PLUGINS_BUILD = "build plugin";
static final String FLD_PLUGINS_REPORT = "report plugin";
String FLD_PLUGINS_REPORT = "report plugin";
static final String FLD_PLUGINS_ALL = "plugins_all";
String FLD_PLUGINS_ALL = "plugins_all";
static final String[] FIELDS = {FLD_ID, FLD_NAME, FLD_DOCTYPE, FLD_GROUPID, FLD_ARTIFACTID, FLD_VERSION, FLD_PACKAGING, FLD_SHA1,
String[] FIELDS = {FLD_ID, FLD_NAME, FLD_DOCTYPE, FLD_GROUPID, FLD_ARTIFACTID, FLD_VERSION, FLD_PACKAGING, FLD_SHA1,
FLD_MD5, FLD_LASTUPDATE, FLD_PLUGINPREFIX, FLD_CLASSES, FLD_PACKAGES, FLD_FILES, FLD_LICENSE_URLS,
FLD_DEPENDENCIES, FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT, FLD_PLUGINS_ALL};
static final List KEYWORD_FIELDS = Arrays.asList( new String[]{FLD_ID, FLD_PACKAGING, FLD_LICENSE_URLS, FLD_DEPENDENCIES,
List KEYWORD_FIELDS = Arrays.asList( new String[]{FLD_ID, FLD_PACKAGING, FLD_LICENSE_URLS, FLD_DEPENDENCIES,
FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT, FLD_PLUGINS_ALL} );
static final String[] MODEL_FIELDS = {FLD_PACKAGING, FLD_LICENSE_URLS, FLD_DEPENDENCIES, FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT};
String[] MODEL_FIELDS = {FLD_PACKAGING, FLD_LICENSE_URLS, FLD_DEPENDENCIES, FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT};
ArtifactRepository getRepository();
@ -117,7 +118,7 @@ public interface RepositoryIndex
*
* @throws RepositoryIndexException if the given indexPath is not valid for this type of RepositoryIndex
*/
public void validate()
void validate()
throws RepositoryIndexException, IOException;
/**
@ -127,7 +128,7 @@ public interface RepositoryIndex
* @param docList List of Lucene Documents
* @throws RepositoryIndexException when an error occurred during the indexing of the documents
*/
public void addDocuments( List docList )
void addDocuments( List docList )
throws RepositoryIndexException;
/**
@ -137,6 +138,6 @@ public interface RepositoryIndex
* @throws RepositoryIndexException
* @throws IOException
*/
public void deleteDocuments( List termList )
void deleteDocuments( List termList )
throws RepositoryIndexException, IOException;
}

View File

@ -155,7 +155,7 @@ public class ProxyConfiguration
validateDirectories();
}
private void validateRemoteRepo( )
private void validateRemoteRepo()
throws ValidationException
{
//Verify remote repository set
@ -169,7 +169,7 @@ public class ProxyConfiguration
private void validateDirectories()
throws ValidationException
{
File f = new File( getRepositoryCachePath() );
File f = new File( cachePath );
if ( !f.exists() )
{
throw new ValidationException( "Specified directory does not exist: " + f.getAbsolutePath() );

View File

@ -134,14 +134,12 @@ public class Cache
*/
public void put( Object key, Object value )
{
Object old = null;
// remove and put: this promotes it to the top since we use a linked hash map
synchronized ( cache )
{
if ( cache.containsKey( key ) )
{
old = cache.remove( key );
cache.remove( key );
}
cache.put( key, value );

View File

@ -21,9 +21,9 @@ import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.FileNotFoundException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Matcher;
@ -55,7 +55,7 @@ public class DefaultDigester
throw new DigesterException( "Specified algorithm not found: " + algorithm, e );
}
InputStream fis = null;
InputStream fis;
try
{
fis = new FileInputStream( file );
@ -79,7 +79,7 @@ public class DefaultDigester
}
while ( numRead != -1 );
}
catch( IOException e )
catch ( IOException e )
{
throw new DigesterException( "Failed to read from file: " + file.getAbsolutePath(), e );
}

View File

@ -16,16 +16,16 @@ package org.apache.maven.repository.manager.web.action;
* limitations under the License.
*/
import com.opensymphony.xwork.ActionSupport;
import com.opensymphony.webwork.interceptor.ParameterAware;
import com.opensymphony.xwork.ActionSupport;
import org.apache.maven.repository.configuration.Configuration;
import org.apache.maven.repository.manager.web.execution.DiscovererExecution;
import org.apache.maven.repository.manager.web.job.DiscovererScheduler;
import org.apache.maven.repository.manager.web.utils.ConfigurationManager;
import java.io.File;
import java.util.Map;
import java.util.HashMap;
import java.util.Map;
/**
* This is the Action class of index.jsp, which is the initial page of the web application.
@ -78,9 +78,9 @@ public class BaseAction
parameters.put( ConfigurationManager.INDEXPATH, config.getIndexPath() );
parameters.put( ConfigurationManager.MIN_INDEXPATH, config.getMinimalIndexPath() );
parameters.put( ConfigurationManager.DISCOVERY_BLACKLIST_PATTERNS, config.getDiscoveryBlackListPatterns() );
parameters.put( ConfigurationManager.DISCOVER_SNAPSHOTS, new Boolean( config.isDiscoverSnapshots() ) );
parameters.put( ConfigurationManager.DISCOVER_SNAPSHOTS, Boolean.valueOf( config.isDiscoverSnapshots() ) );
parameters.put( ConfigurationManager.DISCOVERY_CRON_EXPRESSION, config.getDiscoveryCronExpression() );
setParameters( parameters );
this.parameters = parameters;
//Configuration configuration = new Configuration(); // TODO!
execution.executeDiscovererIfIndexDoesNotExist( new File( config.getIndexPath() ) );

View File

@ -1,7 +1,7 @@
package org.apache.maven.repository.manager.web.action;
/*
* Copyright 2006 The Apache Software Foundation.
* Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,14 +16,14 @@ package org.apache.maven.repository.manager.web.action;
* limitations under the License.
*/
import com.opensymphony.xwork.Action;
import com.opensymphony.webwork.interceptor.ParameterAware;
import java.util.Map;
import java.util.HashMap;
import com.opensymphony.xwork.Action;
import org.apache.maven.repository.manager.web.utils.ConfigurationManager;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="org.apache.maven.repository.manager.web.action.IndexConfigurationAction"
@ -52,10 +52,10 @@ public class IndexConfigurationAction
* Method that is executed when the action is invoked.
*
* @return a String that specifies where to go to next
* @throws Exception
* @throws IOException
*/
public String execute()
throws Exception
throws IOException
{
String[] indexPath = (String[]) parameters.get( ConfigurationManager.INDEXPATH );
Map map = new HashMap();

View File

@ -1,16 +1,30 @@
package org.apache.maven.repository.manager.web.action;
import com.opensymphony.xwork.Action;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed 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 com.opensymphony.webwork.interceptor.ParameterAware;
import java.util.Map;
import java.util.HashMap;
import com.opensymphony.xwork.Action;
import org.apache.maven.repository.manager.web.utils.ConfigurationManager;
import java.util.HashMap;
import java.util.Map;
/**
* @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
*
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="org.apache.maven.repository.manager.web.action.SchedulerConfigurationAction"
*/
public class SchedulerConfigurationAction
@ -40,14 +54,13 @@ public class SchedulerConfigurationAction
*/
public String execute()
{
Map map;
try
{
map = new HashMap();
Map map = new HashMap();
String[] cronExpression = (String[]) parameters.get( ConfigurationManager.DISCOVERY_CRON_EXPRESSION );
if( cronExpression[0] != null )
if ( cronExpression[0] != null )
{
map.put( ConfigurationManager.DISCOVERY_CRON_EXPRESSION, cronExpression[0] );
@ -60,8 +73,9 @@ public class SchedulerConfigurationAction
return ERROR;
}
}
catch( Exception e )
catch ( Exception e )
{
// TODO: fix error handling!
e.printStackTrace();
return ERROR;
}

View File

@ -145,7 +145,7 @@ public class DiscovererExecution
* @param indexPath the path to the index file
*/
protected void indexMetadata( List metadataList, File indexPath, ArtifactRepository repository )
throws RepositoryIndexException, MalformedURLException
throws RepositoryIndexException
{
MetadataRepositoryIndex metadataIndex = indexFactory.createMetadataRepositoryIndex( indexPath, repository );
metadataIndex.indexMetadata( metadataList );

View File

@ -17,17 +17,17 @@ package org.apache.maven.repository.manager.web.utils;
*/
import org.apache.maven.repository.configuration.Configuration;
import org.apache.maven.repository.configuration.io.xpp3.ConfigurationXpp3Writer;
import org.apache.maven.repository.configuration.io.xpp3.ConfigurationXpp3Reader;
import org.apache.maven.repository.configuration.io.xpp3.ConfigurationXpp3Writer;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.io.Reader;
import java.io.FileReader;
import java.io.FileNotFoundException;
import java.io.Writer;
import java.net.URL;
import java.util.Iterator;
import java.util.Map;
@ -99,7 +99,7 @@ public class ConfigurationManager
}
if ( name.equals( DISCOVER_SNAPSHOTS ) )
{
config.setDiscoverSnapshots( Boolean.getBoolean( value ) );
config.setDiscoverSnapshots( Boolean.valueOf( value ).booleanValue() );
}
if ( name.equals( REPOSITORY_DIRECTORY ) )
{
@ -131,7 +131,6 @@ public class ConfigurationManager
public Configuration getConfiguration()
throws IOException
{
Map map = null;
File file = getConfigFile();
config = new Configuration();
@ -147,6 +146,7 @@ public class ConfigurationManager
}
catch ( XmlPullParserException xe )
{
// TODO: fix error handling!
xe.printStackTrace();
}
}