From: olivier lamy Date: Mon, 21 Aug 2017 01:13:43 +0000 (+1000) Subject: get rid of some System.out X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=33b66d1493a034b4f0211580db4f6d26942d7914;p=archiva.git get rid of some System.out Signed-off-by: olivier lamy --- diff --git a/archiva-cli/src/main/java/org/apache/archiva/cli/AbstractProgressConsumer.java b/archiva-cli/src/main/java/org/apache/archiva/cli/AbstractProgressConsumer.java index f53789c0c..c415face4 100644 --- a/archiva-cli/src/main/java/org/apache/archiva/cli/AbstractProgressConsumer.java +++ b/archiva-cli/src/main/java/org/apache/archiva/cli/AbstractProgressConsumer.java @@ -58,7 +58,7 @@ public abstract class AbstractProgressConsumer count++; if ( ( count % 1000 ) == 0 ) { - System.out.println( "Files Processed: " + count ); + logger.info( "Files Processed: {}", count ); } } @@ -73,7 +73,7 @@ public abstract class AbstractProgressConsumer @Override public void completeScan() { - System.out.println( "Final Count of Artifacts processed by " + getId() + ": " + count ); + logger.info( "Final Count of Artifacts processed by {} : {}", getId(), count ); } @Override diff --git a/archiva-cli/src/main/java/org/apache/archiva/cli/ArchivaCli.java b/archiva-cli/src/main/java/org/apache/archiva/cli/ArchivaCli.java index 1d15b636a..880c5f17a 100644 --- a/archiva-cli/src/main/java/org/apache/archiva/cli/ArchivaCli.java +++ b/archiva-cli/src/main/java/org/apache/archiva/cli/ArchivaCli.java @@ -32,6 +32,8 @@ import org.apache.archiva.repository.scanner.RepositoryScanStatistics; 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; @@ -50,7 +52,7 @@ import java.util.Properties; /** * ArchivaCli - * + *

* TODO add back reading of archiva.xml from a given location */ public class ArchivaCli @@ -67,6 +69,8 @@ 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 { @@ -102,7 +106,7 @@ public class ArchivaCli } catch ( IllegalArgumentException e ) { - System.err.println( e.getMessage() ); + LOGGER.error( e.getMessage(), e ); Args.usage( command ); return; } @@ -132,7 +136,7 @@ public class ArchivaCli } else if ( command.version ) { - System.out.print( "Version: " + getVersion() ); + LOGGER.info( "Version: {}", getVersion() ); } else if ( command.convert ) { @@ -142,7 +146,7 @@ public class ArchivaCli { if ( command.repository == null ) { - System.err.println( "The repository must be specified." ); + LOGGER.error( "The repository must be specified." ); Args.usage( command ); return; } @@ -183,11 +187,11 @@ public class ArchivaCli 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 ); } } @@ -202,7 +206,7 @@ public class ArchivaCli { if ( !availableConsumers.containsKey( specifiedConsumer ) ) { - System.err.println( "Specified consumer [" + specifiedConsumer + "] not found." ); + LOGGER.error( "Specified consumer [{}] not found.", specifiedConsumer ); dumpAvailableConsumers(); System.exit( 1 ); } @@ -217,14 +221,14 @@ public class ArchivaCli { Map availableConsumers = getConsumers(); - System.out.println( ".\\ Available Consumer List \\.______________________________" ); + LOGGER.info( ".\\ Available Consumer List \\.______________________________" ); for ( Map.Entry 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() ); } } @@ -249,11 +253,12 @@ public class ArchivaCli 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 ); } @@ -262,7 +267,7 @@ public class ArchivaCli File newRepositoryPath = new File( p.getProperty( TARGET_REPO_PATH ) ); - System.out.println( "Converting " + oldRepositoryPath + " to " + newRepositoryPath ); + LOGGER.info( "Converting {} to {}", oldRepositoryPath, newRepositoryPath ); List fileExclusionPatterns = null; @@ -294,9 +299,7 @@ public class ArchivaCli @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" ) diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/AbstractMonitoredConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/AbstractMonitoredConsumer.java index 5b9155460..170847865 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/AbstractMonitoredConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/AbstractMonitoredConsumer.java @@ -20,6 +20,8 @@ package org.apache.archiva.consumers; */ import org.apache.archiva.common.FileTypeUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.HashSet; import java.util.List; @@ -33,6 +35,9 @@ import java.util.Set; public abstract class AbstractMonitoredConsumer implements Consumer { + + protected final Logger logger = LoggerFactory.getLogger( getClass() ); + private final Set monitors = new HashSet(); @Override diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java index 9fca6b848..a4d5d5d6c 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java @@ -19,6 +19,7 @@ package org.apache.archiva.metadata.repository.jcr; * 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; @@ -40,13 +41,9 @@ import org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics; 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; @@ -66,7 +63,6 @@ import javax.jcr.query.QueryManager; 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; @@ -86,7 +82,7 @@ import java.util.Set; * TODO revise reference storage */ public class JcrMetadataRepository - implements MetadataRepository,RepositoryStatisticsProvider + implements MetadataRepository, RepositoryStatisticsProvider { private static final String JCR_LAST_MODIFIED = "jcr:lastModified"; @@ -146,7 +142,6 @@ public class JcrMetadataRepository registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.DEPENDENCY_NODE_TYPE ); - } private static void registerMixinNodeType( NodeTypeManager nodeTypeManager, String name ) @@ -165,7 +160,6 @@ public class JcrMetadataRepository } - @Override public void updateProject( String repositoryId, ProjectMetadata project ) throws MetadataRepositoryException @@ -750,7 +744,7 @@ public class JcrMetadataRepository 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(); @@ -765,9 +759,10 @@ public class JcrMetadataRepository { 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; } @@ -789,9 +784,8 @@ public class JcrMetadataRepository public List 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 ) ); } @@ -860,8 +854,8 @@ public class JcrMetadataRepository 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 @@ -1109,8 +1103,8 @@ public class JcrMetadataRepository List 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 + "'"; @@ -1361,7 +1355,9 @@ public class JcrMetadataRepository 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 ); } @@ -1391,7 +1387,7 @@ public class JcrMetadataRepository } @Override - public T obtainAccess( Class aClass ) + public T obtainAccess( Class aClass ) throws MetadataRepositoryException { if ( aClass == Session.class ) @@ -1440,10 +1436,10 @@ public class JcrMetadataRepository 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 ) ); } @@ -1454,7 +1450,7 @@ public class JcrMetadataRepository 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(); @@ -1605,7 +1601,7 @@ public class JcrMetadataRepository 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( "/" ) ) { @@ -1626,10 +1622,10 @@ public class JcrMetadataRepository 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; } @@ -1711,11 +1707,13 @@ public class JcrMetadataRepository @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 @@ -1762,14 +1760,14 @@ public class JcrMetadataRepository repositoryStatistics.setTotalArtifactFileSize( totalSize ); for ( Map.Entry 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( diff --git a/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java b/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java index be07e2e73..4ae7aacd8 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java @@ -35,6 +35,8 @@ import org.junit.Before; 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; @@ -55,7 +57,8 @@ import java.util.zip.GZIPInputStream; @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; @@ -73,11 +76,13 @@ public class JcrRepositoryStatisticsGatheringTest extends TestCase 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() ) @@ -102,7 +107,6 @@ public class JcrRepositoryStatisticsGatheringTest extends TestCase // TODO: probably don't need to use Spring for this JcrMetadataRepository jcrMetadataRepository = new JcrMetadataRepository( factories, jcrRepository ); - session = jcrMetadataRepository.getJcrSession(); try @@ -136,9 +140,9 @@ public class JcrRepositoryStatisticsGatheringTest extends TestCase public void tearDown() throws Exception { - if (repository!=null) + if ( repository != null ) { - repository.close( ); + repository.close(); } } @@ -181,9 +185,9 @@ public class JcrRepositoryStatisticsGatheringTest extends TestCase 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() );