mirror of https://github.com/apache/maven.git
Added checksum validator repository tool
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163387 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ad64a10685
commit
4ab7501ffb
|
@ -36,5 +36,10 @@
|
|||
<artifactId>plexus</artifactId>
|
||||
<version>0.17-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-artifact</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package org.apache.maven.repository;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2004 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 java.io.File;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
||||
/**
|
||||
* Prints all artifacts without checksum file
|
||||
*
|
||||
* @todo generate checksums for those files without it
|
||||
*
|
||||
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez </a>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
public class ChecksumValidator
|
||||
{
|
||||
|
||||
public static void main( String[] args )
|
||||
{
|
||||
if ( args.length != 1 )
|
||||
{
|
||||
System.out.println( "Usage: " + ChecksumValidator.class.getName() + " path.to.local.repository" );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ArtifactRepository localRepository = new ArtifactRepository();
|
||||
|
||||
String path = args[0];
|
||||
|
||||
File f = new File( path );
|
||||
|
||||
localRepository.setUrl( "file://" + f.getPath() );
|
||||
|
||||
List artifacts = RepositoryTools.getAllArtifacts( localRepository );
|
||||
|
||||
Iterator it = artifacts.iterator();
|
||||
|
||||
while ( it.hasNext() )
|
||||
{
|
||||
Artifact artifact = (Artifact) it.next();
|
||||
|
||||
if ( !artifact.getChecksumFile().exists() )
|
||||
{
|
||||
System.out.println( artifact );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
package org.apache.maven.repository;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2004 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 java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.DefaultArtifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
||||
/**
|
||||
* Tools to help repository management
|
||||
*
|
||||
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez </a>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
public class RepositoryTools
|
||||
{
|
||||
|
||||
/**
|
||||
* Files with these extensions will be ignored
|
||||
*/
|
||||
private static final String[] IGNORE_EXTENSIONS = { "md5" };
|
||||
|
||||
/**
|
||||
* Get all artifacts present in a file repository
|
||||
*
|
||||
* @todo make this layout independent
|
||||
*
|
||||
* @param artifactRepository
|
||||
* all files in this repository basedir will be returned as
|
||||
* artifacts
|
||||
* @return all the artifacts available in the repository
|
||||
*/
|
||||
public static List getAllArtifacts( ArtifactRepository artifactRepository )
|
||||
{
|
||||
List list = new LinkedList();
|
||||
|
||||
File basedir = new File( artifactRepository.getBasedir() );
|
||||
|
||||
File[] groups = basedir.listFiles();
|
||||
|
||||
for ( int i = 0; (groups != null) && (i < groups.length); i++ )
|
||||
{
|
||||
File[] types = groups[i].listFiles();
|
||||
|
||||
for ( int j = 0; (types != null) && (j < types.length); j++ )
|
||||
{
|
||||
|
||||
File[] artifacts = types[j].listFiles( new FilenameFilter() {
|
||||
|
||||
public boolean accept( File dir, String name )
|
||||
{
|
||||
int x = name.lastIndexOf( "." );
|
||||
|
||||
String extension = name.substring( x, name.length() );
|
||||
|
||||
for ( int y = 0; y < IGNORE_EXTENSIONS.length; y++ )
|
||||
{
|
||||
|
||||
if ( extension.equals( IGNORE_EXTENSIONS[y] ) )
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} );
|
||||
|
||||
for ( int k = 0; (artifacts != null) && (k < artifacts.length); k++ )
|
||||
{
|
||||
Artifact artifact = getArtifact( groups[i].getName(), types[j].getName().substring( 0,
|
||||
types[j].getName().length() - 1 ), artifacts[k] );
|
||||
|
||||
if ( artifact != null )
|
||||
|
||||
list.add( artifact );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an artifact object from a file
|
||||
*
|
||||
* @todo make this layout independent
|
||||
*
|
||||
* @param groupId
|
||||
* @param type
|
||||
* @param artifactFile
|
||||
* artifactId, version and path will be get from this file name
|
||||
* @return
|
||||
*/
|
||||
public static Artifact getArtifact( String groupId, String type, File artifactFile )
|
||||
{
|
||||
String name = artifactFile.getName();
|
||||
|
||||
int i = name.lastIndexOf( "-" );
|
||||
|
||||
int j = name.lastIndexOf( "." );
|
||||
|
||||
if ( (i < 0) || (j < 0) )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String version = name.substring( i + 1, j );
|
||||
|
||||
String artifactId = name.substring( 0, i );
|
||||
|
||||
Artifact artifact = new DefaultArtifact( groupId, artifactId, version, type );
|
||||
|
||||
artifact.setPath( artifactFile.getPath() );
|
||||
|
||||
return artifact;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright 2004 Carlos Sanchez.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.maven.repository;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.ArtifactComponentTestCase;
|
||||
import org.apache.maven.repository.RepositoryTools;
|
||||
|
||||
/**
|
||||
* @author Carlos Sanchez
|
||||
* @version $Revision$
|
||||
*/
|
||||
public class RepositoryToolsTest
|
||||
extends ArtifactComponentTestCase
|
||||
{
|
||||
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
protected String component()
|
||||
{
|
||||
return "repositorytools";
|
||||
}
|
||||
|
||||
public void testGetAllArtifacts() throws Exception
|
||||
{
|
||||
Artifact artifact = createLocalArtifact( "a", "1.0" );
|
||||
List artifacts = RepositoryTools.getAllArtifacts( localRepository() );
|
||||
assertEquals( 1, artifacts.size() );
|
||||
assertEquals( artifact, artifacts.get( 0 ) );
|
||||
}
|
||||
|
||||
public void testGetArtifact()
|
||||
{
|
||||
File artifactFile = new File( "whatever/maven/jars/maven-meeper-1.0.jar" );
|
||||
Artifact artifact = RepositoryTools.getArtifact( "maven", "jar", artifactFile );
|
||||
assertEquals( "maven", artifact.getGroupId() );
|
||||
assertEquals( "maven-meeper", artifact.getArtifactId() );
|
||||
assertEquals( "1.0", artifact.getVersion() );
|
||||
assertEquals( "jar", artifact.getType() );
|
||||
assertNotNull( artifact.getPath() );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue