import org.apache.archiva.repository.scanner.RepositoryScanner;
import org.apache.archiva.repository.scanner.RepositoryScannerException;
import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.io.File;
/**
* ArchivaCli
- *
+ * <p>
* TODO add back reading of archiva.xml from a given location
*/
public class ArchivaCli
public static final String POM_PROPERTIES = "/META-INF/maven/org.apache.archiva/archiva-cli/pom.properties";
+ private static final Logger LOGGER = LoggerFactory.getLogger( ArchivaCli.class );
+
private static String getVersion()
throws IOException
{
}
catch ( IllegalArgumentException e )
{
- System.err.println( e.getMessage() );
+ LOGGER.error( e.getMessage(), e );
Args.usage( command );
return;
}
}
else if ( command.version )
{
- System.out.print( "Version: " + getVersion() );
+ LOGGER.info( "Version: {}", getVersion() );
}
else if ( command.convert )
{
{
if ( command.repository == null )
{
- System.err.println( "The repository must be specified." );
+ LOGGER.error( "The repository must be specified." );
Args.usage( command );
return;
}
RepositoryScanStatistics stats = scanner.scan( repo, knownConsumerList, invalidConsumerList, ignoredContent,
RepositoryScanner.FRESH_SCAN );
- System.out.println( "\n" + stats.toDump( repo ) );
+ LOGGER.info( stats.toDump( repo ) );
}
catch ( RepositoryScannerException e )
{
- e.printStackTrace( System.err );
+ LOGGER.error( e.getMessage(), e );
}
}
{
if ( !availableConsumers.containsKey( specifiedConsumer ) )
{
- System.err.println( "Specified consumer [" + specifiedConsumer + "] not found." );
+ LOGGER.error( "Specified consumer [{}] not found.", specifiedConsumer );
dumpAvailableConsumers();
System.exit( 1 );
}
{
Map<String, KnownRepositoryContentConsumer> availableConsumers = getConsumers();
- System.out.println( ".\\ Available Consumer List \\.______________________________" );
+ LOGGER.info( ".\\ Available Consumer List \\.______________________________" );
for ( Map.Entry<String, KnownRepositoryContentConsumer> entry : availableConsumers.entrySet() )
{
String consumerHint = entry.getKey();
RepositoryContentConsumer consumer = entry.getValue();
- System.out.println(
- " " + consumerHint + ": " + consumer.getDescription() + " (" + consumer.getClass().getName() + ")" );
+ LOGGER.info( " {} : {} ({})", //
+ consumerHint, consumer.getDescription(), consumer.getClass().getName() );
}
}
private void doConversion( String properties )
throws IOException, RepositoryConversionException
{
- LegacyRepositoryConverter legacyRepositoryConverter = applicationContext.getBean( LegacyRepositoryConverter.class );
+ LegacyRepositoryConverter legacyRepositoryConverter =
+ applicationContext.getBean( LegacyRepositoryConverter.class );
Properties p = new Properties();
- try (InputStream fis = Files.newInputStream( Paths.get(properties)))
+ try (InputStream fis = Files.newInputStream( Paths.get( properties ) ))
{
p.load( fis );
}
File newRepositoryPath = new File( p.getProperty( TARGET_REPO_PATH ) );
- System.out.println( "Converting " + oldRepositoryPath + " to " + newRepositoryPath );
+ LOGGER.info( "Converting {} to {}", oldRepositoryPath, newRepositoryPath );
List<String> fileExclusionPatterns = null;
@Argument( description = "Scan the specified repository", value = "scan", alias = "s" )
private boolean scan;
- @Argument(
- description = "Convert a legacy Maven 1.x repository to a Maven 2.x repository using a properties file to describe the conversion",
- value = "convert", alias = "c" )
+ @Argument( description = "Convert a legacy Maven 1.x repository to a Maven 2.x repository using a properties file to describe the conversion", value = "convert", alias = "c" )
private boolean convert;
@Argument( description = "The properties file for the conversion", value = "properties" )
* under the License.
*/
+import com.google.common.collect.ImmutableMap;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.CiManagement;
import org.apache.archiva.metadata.model.Dependency;
import org.apache.archiva.metadata.repository.stats.model.RepositoryStatisticsProvider;
import org.apache.commons.lang.StringUtils;
import org.apache.jackrabbit.commons.JcrUtils;
-import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
-import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.ImmutableMap;
-
import javax.jcr.InvalidItemStateException;
import javax.jcr.NamespaceRegistry;
import javax.jcr.Node;
import javax.jcr.query.QueryResult;
import javax.jcr.query.Row;
import javax.jcr.query.RowIterator;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
* TODO revise reference storage
*/
public class JcrMetadataRepository
- implements MetadataRepository,RepositoryStatisticsProvider
+ implements MetadataRepository, RepositoryStatisticsProvider
{
private static final String JCR_LAST_MODIFIED = "jcr:lastModified";
registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.DEPENDENCY_NODE_TYPE );
-
}
private static void registerMixinNodeType( NodeTypeManager nodeTypeManager, String name )
}
-
@Override
public void updateProject( String repositoryId, ProjectMetadata project )
throws MetadataRepositoryException
long start = Calendar.getInstance().getTimeInMillis();
QueryResult result = query.execute();
long end = Calendar.getInstance().getTimeInMillis();
- log.info( "JCR Query ran in {} milliseconds: {}", end - start , q );
+ log.info( "JCR Query ran in {} milliseconds: {}", end - start, q );
artifacts = new ArrayList<>();
RowIterator rows = result.getRows();
{
throw new MetadataRepositoryException( e.getMessage(), e );
}
- log.info("Artifacts found {}", artifacts.size());
- for (ArtifactMetadata meta : artifacts) {
- log.info("Artifact: "+meta.getVersion()+" "+meta.getFacetList());
+ log.info( "Artifacts found {}", artifacts.size() );
+ for ( ArtifactMetadata meta : artifacts )
+ {
+ log.info( "Artifact: " + meta.getVersion() + " " + meta.getFacetList() );
}
return artifacts;
}
public List<ArtifactMetadata> getArtifactsByMetadata( String key, String value, String repositoryId )
throws MetadataRepositoryException
{
- String q =
- "SELECT * FROM [" + ARTIFACT_NODE_TYPE + "] AS artifact INNER JOIN [" + FACET_NODE_TYPE
- + "] AS facet ON ISCHILDNODE(facet, artifact) WHERE ([facet].[" + key + "] = $value)";
+ String q = "SELECT * FROM [" + ARTIFACT_NODE_TYPE + "] AS artifact INNER JOIN [" + FACET_NODE_TYPE
+ + "] AS facet ON ISCHILDNODE(facet, artifact) WHERE ([facet].[" + key + "] = $value)";
return runJcrQuery( repositoryId, q, ImmutableMap.of( "value", value ) );
}
private static String getArtifactQuery( String repositoryId )
{
- return "SELECT * FROM [" + ARTIFACT_NODE_TYPE + "] AS artifact WHERE ISDESCENDANTNODE(artifact,'/" +
- getRepositoryContentPath( repositoryId ) + "')";
+ return "SELECT * FROM [" + ARTIFACT_NODE_TYPE + "] AS artifact WHERE ISDESCENDANTNODE(artifact,'/"
+ + getRepositoryContentPath( repositoryId ) + "')";
}
@Override
List<ProjectVersionReference> references = new ArrayList<>();
// TODO: bind variables instead
- String q = "SELECT * FROM [archiva:dependency] WHERE ISDESCENDANTNODE([/repositories/" + repositoryId +
- "/content]) AND [groupId]='" + namespace + "' AND [artifactId]='" + projectId + "'";
+ String q = "SELECT * FROM [archiva:dependency] WHERE ISDESCENDANTNODE([/repositories/" + repositoryId
+ + "/content]) AND [groupId]='" + namespace + "' AND [artifactId]='" + projectId + "'";
if ( projectVersion != null )
{
q += " AND [version]='" + projectVersion + "'";
try
{
getJcrSession().save();
- } catch ( InvalidItemStateException e ) {
+ }
+ catch ( InvalidItemStateException e )
+ {
// olamy this might happen when deleting a repo while is under scanning
log.warn( "skip InvalidItemStateException:{}", e.getMessage(), e );
}
}
@Override
- public <T>T obtainAccess( Class<T> aClass )
+ public <T> T obtainAccess( Class<T> aClass )
throws MetadataRepositoryException
{
if ( aClass == Session.class )
e ? "(projectVersion." + theKey + " = $value)" : "contains([projectVersion]." + theKey + ", $value)";
String facetCondition = e ? "(facet." + theKey + " = $value)" : "contains([facet]." + theKey + ", $value)";
String q =
- "SELECT * FROM [" + PROJECT_VERSION_NODE_TYPE + "] AS projectVersion LEFT OUTER JOIN ["
- + ARTIFACT_NODE_TYPE + "] AS artifact ON ISCHILDNODE(artifact, projectVersion) LEFT OUTER JOIN ["
- + FACET_NODE_TYPE + "] AS facet ON ISCHILDNODE(facet, projectVersion) WHERE ("
- + projectVersionCondition + " OR " + facetCondition + ")";
+ "SELECT * FROM [" + PROJECT_VERSION_NODE_TYPE + "] AS projectVersion LEFT OUTER JOIN [" + ARTIFACT_NODE_TYPE
+ + "] AS artifact ON ISCHILDNODE(artifact, projectVersion) LEFT OUTER JOIN [" + FACET_NODE_TYPE
+ + "] AS facet ON ISCHILDNODE(facet, projectVersion) WHERE (" + projectVersionCondition + " OR "
+ + facetCondition + ")";
return runJcrQuery( repositoryId, q, ImmutableMap.of( "value", text ) );
}
ArtifactMetadata artifact = new ArtifactMetadata();
artifact.setId( id );
- artifact.setRepositoryId( repositoryId == null ? artifactNode.getAncestor(2).getName() : repositoryId );
+ artifact.setRepositoryId( repositoryId == null ? artifactNode.getAncestor( 2 ).getName() : repositoryId );
Node projectVersionNode = artifactNode.getParent();
Node projectNode = projectVersionNode.getParent();
private Node getOrAddNodeByPath( Node baseNode, String name, String nodeType )
throws RepositoryException
{
- log.debug("getOrAddNodeByPath"+baseNode+" "+name+" "+nodeType);
+ log.debug( "getOrAddNodeByPath" + baseNode + " " + name + " " + nodeType );
Node node = baseNode;
for ( String n : name.split( "/" ) )
{
private Node getOrAddRepositoryNode( String repositoryId )
throws RepositoryException
{
- log.debug("getOrAddRepositoryNode "+repositoryId);
+ log.debug( "getOrAddRepositoryNode " + repositoryId );
Node root = getJcrSession().getRootNode();
Node node = JcrUtils.getOrAddNode( root, "repositories" );
- log.debug("Repositories "+node);
+ log.debug( "Repositories " + node );
node = JcrUtils.getOrAddNode( node, repositoryId );
return node;
}
@Override
public void populateStatistics( MetadataRepository repository, String repositoryId,
- RepositoryStatistics repositoryStatistics )
+ RepositoryStatistics repositoryStatistics )
throws MetadataRepositoryException
{
- if (!(repository instanceof JcrMetadataRepository)) {
- throw new MetadataRepositoryException( "The statistics population is only possible for JcrMetdataRepository implementations" );
+ if ( !( repository instanceof JcrMetadataRepository ) )
+ {
+ throw new MetadataRepositoryException(
+ "The statistics population is only possible for JcrMetdataRepository implementations" );
}
Session session = (Session) repository.obtainAccess( Session.class );
// TODO: these may be best as running totals, maintained by observations on the properties in JCR
repositoryStatistics.setTotalArtifactFileSize( totalSize );
for ( Map.Entry<String, Integer> entry : totalByType.entrySet() )
{
- System.out.println("Setting count for type: "+entry.getKey()+" = "+entry.getValue());
+ log.info( "Setting count for type: {} = {}", entry.getKey(), entry.getValue() );
repositoryStatistics.setTotalCountForType( entry.getKey(), entry.getValue() );
}
// The query ordering is a trick to ensure that the size is correct, otherwise due to lazy init it will be -1
// query = queryManager.createQuery( "SELECT * FROM [archiva:project] " + whereClause, Query.JCR_SQL2 );
query = queryManager.createQuery( "SELECT * FROM archiva:project " + whereClause + " ORDER BY jcr:score",
- Query.SQL );
+ Query.SQL );
repositoryStatistics.setTotalProjectCount( query.execute().getRows().getSize() );
// query = queryManager.createQuery(
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
@RunWith( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
-public class JcrRepositoryStatisticsGatheringTest extends TestCase
+public class JcrRepositoryStatisticsGatheringTest
+ extends TestCase
{
private static final int TOTAL_FILE_COUNT = 1000;
Session session;
-
private static Repository jcrRepository;
+ Logger logger = LoggerFactory.getLogger( getClass() );
+
@BeforeClass
- public static void setupSpec() throws IOException, InvalidFileStoreVersionException
+ public static void setupSpec()
+ throws IOException, InvalidFileStoreVersionException
{
File directory = new File( "target/test-repositories" );
if ( directory.exists() )
// TODO: probably don't need to use Spring for this
JcrMetadataRepository jcrMetadataRepository = new JcrMetadataRepository( factories, jcrRepository );
-
session = jcrMetadataRepository.getJcrSession();
try
public void tearDown()
throws Exception
{
- if (repository!=null)
+ if ( repository != null )
{
- repository.close( );
+ repository.close();
}
}
expectedStatistics.setTotalCountForType( "pom", 144 );
expectedStatistics.setRepositoryId( TEST_REPO );
- System.out.println(testedStatistics.getTotalCountForType());
+ logger.info("getTotalCountForType: {}", testedStatistics.getTotalCountForType() );
- assertEquals( NEW_FILE_COUNT, testedStatistics.getNewFileCount());
+ assertEquals( NEW_FILE_COUNT, testedStatistics.getNewFileCount() );
assertEquals( TOTAL_FILE_COUNT, testedStatistics.getTotalFileCount() );
assertEquals( endTime, testedStatistics.getScanEndTime() );
assertEquals( startTime, testedStatistics.getScanStartTime() );