maven-shared-io-1.1/0000755000175000017500000000000011116577017014276 5ustar twernertwernermaven-shared-io-1.1/src/0000755000175000017500000000000011116577017015065 5ustar twernertwernermaven-shared-io-1.1/src/test/0000755000175000017500000000000011116577017016044 5ustar twernertwernermaven-shared-io-1.1/src/test/java/0000755000175000017500000000000011116577017016765 5ustar twernertwernermaven-shared-io-1.1/src/test/java/org/0000755000175000017500000000000011116577017017554 5ustar twernertwernermaven-shared-io-1.1/src/test/java/org/apache/0000755000175000017500000000000011116577017020775 5ustar twernertwernermaven-shared-io-1.1/src/test/java/org/apache/maven/0000755000175000017500000000000011116577017022103 5ustar twernertwernermaven-shared-io-1.1/src/test/java/org/apache/maven/shared/0000755000175000017500000000000011116577017023351 5ustar twernertwernermaven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/0000755000175000017500000000000011116577017023760 5ustar twernertwernermaven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/scan/0000755000175000017500000000000011116577017024704 5ustar twernertwernermaven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/scan/mapping/0000755000175000017500000000000011116577017026337 5ustar twernertwernermaven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/scan/mapping/SuffixMappingTest.java0000644000175000017500000000746410717551366032642 0ustar twernertwernerpackage org.apache.maven.shared.io.scan.mapping; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 junit.framework.TestCase; import org.apache.maven.shared.io.scan.InclusionScanException; import java.io.File; import java.util.HashSet; import java.util.Set; /** * @author jdcasey */ public class SuffixMappingTest extends TestCase { public void testShouldReturnSingleClassFileForSingleJavaFile() throws InclusionScanException { String base = "path/to/file"; File basedir = new File( "." ); SuffixMapping mapping = new SuffixMapping( ".java", ".class" ); Set results = mapping.getTargetFiles( basedir, base + ".java" ); assertEquals( "Returned wrong number of target files.", 1, results.size() ); assertEquals( "Target file is wrong.", new File( basedir, base + ".class" ), results.iterator().next() ); } public void testShouldNotReturnClassFileWhenSourceFileHasWrongSuffix() throws InclusionScanException { String base = "path/to/file"; File basedir = new File( "." ); SuffixMapping mapping = new SuffixMapping( ".java", ".class" ); Set results = mapping.getTargetFiles( basedir, base + ".xml" ); assertTrue( "Returned wrong number of target files.", results.isEmpty() ); } public void testShouldReturnOneClassFileAndOneXmlFileForSingleJavaFile() throws InclusionScanException { String base = "path/to/file"; File basedir = new File( "." ); Set targets = new HashSet(); targets.add( ".class" ); targets.add( ".xml" ); SuffixMapping mapping = new SuffixMapping( ".java", targets ); Set results = mapping.getTargetFiles( basedir, base + ".java" ); assertEquals( "Returned wrong number of target files.", 2, results.size() ); assertTrue( "Targets do not contain class target.", results.contains( new File( basedir, base + ".class" ) ) ); assertTrue( "Targets do not contain class target.", results.contains( new File( basedir, base + ".xml" ) ) ); } public void testShouldReturnNoTargetFilesWhenSourceFileHasWrongSuffix() throws InclusionScanException { String base = "path/to/file"; File basedir = new File( "." ); Set targets = new HashSet(); targets.add( ".class" ); targets.add( ".xml" ); SuffixMapping mapping = new SuffixMapping( ".java", targets ); Set results = mapping.getTargetFiles( basedir, base + ".apt" ); assertTrue( "Returned wrong number of target files.", results.isEmpty() ); } public void testSingleTargetMapper() throws InclusionScanException { String base = "path/to/file"; File basedir = new File( "target/" ); SingleTargetMapping mapping = new SingleTargetMapping( ".cs", "/foo" ); Set results = mapping.getTargetFiles( basedir, base + ".apt" ); assertTrue( results.isEmpty() ); results = mapping.getTargetFiles( basedir, base + ".cs" ); assertEquals( 1, results.size() ); } } maven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/logging/0000755000175000017500000000000011116577017025406 5ustar twernertwernermaven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/logging/DefaultMessageHolderTest.java0000644000175000017500000002014710717551366033151 0ustar twernertwernerpackage org.apache.maven.shared.io.logging; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.PrintWriter; import java.io.StringWriter; import junit.framework.TestCase; public class DefaultMessageHolderTest extends TestCase { // MessageHolder newMessage(); // int size(); // String render(); public void testNewMessageIncrementsSizeWhenEmpty() { MessageHolder mh = new DefaultMessageHolder(); assertEquals( 0, mh.size() ); MessageHolder test = mh.newMessage(); assertSame( mh, test ); assertEquals( 1, mh.size() ); assertEquals( "", mh.render() ); } // MessageHolder append( CharSequence messagePart ); // int size(); // String render(); public void testAppendCreatesNewMessageIfNoneCurrent() { MessageHolder mh = new DefaultMessageHolder(); assertEquals( 0, mh.size() ); MessageHolder test = mh.append( "test" ); assertSame( mh, test ); assertEquals( 1, mh.size() ); assertEquals( "[1] [INFO] test", mh.render() ); } // MessageHolder append( Throwable error ); // int size(); // String render(); public void testAppendErrorCreatesNewMessageIfNoneCurrent() { MessageHolder mh = new DefaultMessageHolder(); assertEquals( 0, mh.size() ); NullPointerException npe = new NullPointerException(); MessageHolder test = mh.append( npe ); assertSame( mh, test ); assertEquals( 1, mh.size() ); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter( sw ); npe.printStackTrace( pw ); assertEquals( "[1] [INFO] Error:\n" + sw.toString(), mh.render() ); } // MessageHolder newMessage(); // MessageHolder append( CharSequence messagePart ); // int size(); // String render(); public void testNewMessageThenAppendOnlyIncrementsSizeByOne() { MessageHolder mh = new DefaultMessageHolder(); assertEquals( 0, mh.size() ); MessageHolder test = mh.newMessage(); assertSame( mh, test ); test = mh.append( "test" ); assertSame( mh, test ); assertEquals( 1, mh.size() ); assertEquals( "[1] [INFO] test", mh.render() ); } // MessageHolder newMessage(); // MessageHolder append( CharSequence messagePart ); // MessageHolder append( CharSequence messagePart ); // int size(); // String render(); public void testNewMessageThenAppendTwiceOnlyIncrementsSizeByOne() { MessageHolder mh = new DefaultMessageHolder(); assertEquals( 0, mh.size() ); MessageHolder test = mh.newMessage(); assertSame( mh, test ); test = mh.append( "test" ); assertSame( mh, test ); test = mh.append( " again" ); assertSame( mh, test ); assertEquals( 1, mh.size() ); assertEquals( "[1] [INFO] test again", mh.render() ); } // MessageHolder newMessage(); // MessageHolder append( CharSequence messagePart ); // MessageHolder append( Throwable error ); // int size(); // String render(); public void testNewMessageThenAppendBothMessageAndErrorOnlyIncrementsSizeByOne() { MessageHolder mh = new DefaultMessageHolder(); assertEquals( 0, mh.size() ); MessageHolder test = mh.newMessage(); assertSame( mh, test ); test = mh.append( "test" ); assertSame( mh, test ); NullPointerException npe = new NullPointerException(); test = mh.append( npe ); assertSame( mh, test ); assertEquals( 1, mh.size() ); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter( sw ); npe.printStackTrace( pw ); assertEquals( "[1] [INFO] test\nError:\n" + sw.toString(), mh.render() ); } // MessageHolder addMessage( CharSequence messagePart ); // int size(); // String render(); public void testAddMessageIncrementsSizeByOne() { MessageHolder mh = new DefaultMessageHolder(); MessageHolder check = mh.addMessage( "test" ); assertSame( mh, check ); assertEquals( 1, mh.size() ); assertEquals( "[1] [INFO] test", mh.render() ); } // MessageHolder addMessage( CharSequence messagePart ); // int size(); // String render(); public void testAddMessageTwiceIncrementsSizeByTwo() { MessageHolder mh = new DefaultMessageHolder(); MessageHolder check = mh.addMessage( "test" ); assertSame( mh, check ); check = mh.addMessage( "test2" ); assertSame( mh, check ); assertEquals( 2, mh.size() ); assertEquals( "[1] [INFO] test\n\n[2] [INFO] test2", mh.render() ); } // MessageHolder addMessage( CharSequence messagePart, Throwable error ); // int size(); // String render(); public void testAddMessageWithErrorIncrementsSizeByOne() { MessageHolder mh = new DefaultMessageHolder(); NullPointerException npe = new NullPointerException(); MessageHolder check = mh.addMessage( "test", npe ); assertSame( mh, check ); assertEquals( 1, mh.size() ); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter( sw ); npe.printStackTrace( pw ); assertEquals( "[1] [INFO] test\nError:\n" + sw.toString(), mh.render() ); } // MessageHolder addMessage( CharSequence messagePart, Throwable error ); // MessageHolder addMessage( CharSequence messagePart ); // int size(); // String render(); public void testAddMessageWithErrorThenWithJustMessageIncrementsSizeByTwo() { MessageHolder mh = new DefaultMessageHolder(); NullPointerException npe = new NullPointerException(); MessageHolder check = mh.addMessage( "test", npe ); assertSame( mh, check ); check = mh.addMessage( "test2" ); assertSame( mh, check ); assertEquals( 2, mh.size() ); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter( sw ); npe.printStackTrace( pw ); assertEquals( "[1] [INFO] test\nError:\n" + sw.toString() + "\n\n[2] [INFO] test2", mh.render() ); } // MessageHolder addMessage( Throwable error ); // int size(); // String render(); public void testAddMessageWithJustErrorIncrementsSizeByOne() { MessageHolder mh = new DefaultMessageHolder(); NullPointerException npe = new NullPointerException(); MessageHolder check = mh.addMessage( npe ); assertSame( mh, check ); assertEquals( 1, mh.size() ); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter( sw ); npe.printStackTrace( pw ); assertEquals( "[1] [INFO] Error:\n" + sw.toString(), mh.render() ); } // boolean isEmpty(); public void testIsEmptyAfterConstruction() { assertTrue( new DefaultMessageHolder().isEmpty() ); } // boolean isEmpty(); public void testIsNotEmptyAfterConstructionAndNewMessageCall() { assertFalse( new DefaultMessageHolder().newMessage().isEmpty() ); } public void testAppendCharSequence() { MessageHolder mh = new DefaultMessageHolder(); mh.newMessage().append( new StringBuffer( "This is a test" ) ); assertTrue( mh.render().indexOf( "This is a test" ) > -1 ); } } maven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/MockManager.java0000644000175000017500000000304410717551366027015 0ustar twernertwernerpackage org.apache.maven.shared.io; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.util.ArrayList; import java.util.Iterator; import java.util.List; import org.easymock.MockControl; public class MockManager { private List mockControls = new ArrayList(); public void add( MockControl control ) { mockControls.add( control ); } public void replayAll() { for ( Iterator it = mockControls.iterator(); it.hasNext(); ) { MockControl control = (MockControl) it.next(); control.replay(); } } public void verifyAll() { for ( Iterator it = mockControls.iterator(); it.hasNext(); ) { MockControl control = (MockControl) it.next(); control.verify(); } } } maven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/TestUtils.java0000644000175000017500000001041710717575361026574 0ustar twernertwernerpackage org.apache.maven.shared.io; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.BufferedReader; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.WriterFactory; public final class TestUtils { private TestUtils() { } private static void write( Writer writer, String content ) throws IOException { try { writer.write( content ); } finally { IOUtil.close( writer ); } } public static void writePlatformFile( File file, String content ) throws IOException { write( WriterFactory.newPlatformWriter( file ), content ); } public static void writeFileWithEncoding( File file, String content, String encoding ) throws IOException { write( WriterFactory.newWriter( file, encoding ), content ); } public static void writeXmlFile( File file, String content ) throws IOException { write( WriterFactory.newXmlWriter( file ), content ); } /** * writes content to a file, using platform encoding. * @deprecated this API isn't explicit about encoding, use writePlatformFile() or writeXmlFile() * depending on your need */ public static void writeToFile( File file, String testStr ) throws IOException { writePlatformFile( file, testStr ); } /** * reads content from a file and normalize EOLs to simple line feed (\\n), using platform encoding. * @deprecated this API isn't explicit about encoding nor EOL normalization, use readPlatformFile() or * readXmlFile() depending on your need, in conjunction with normalizeEndOfLine() */ public static String readFile( File file ) throws IOException { return normalizeEndOfLine( readPlatformFile( file ) ); } public static String readPlatformFile( File file ) throws IOException { StringWriter buffer = new StringWriter(); Reader reader = ReaderFactory.newPlatformReader( file ); IOUtil.copy( reader, buffer ); return buffer.toString(); } public static String readXmlFile( File file ) throws IOException { StringWriter buffer = new StringWriter(); Reader reader = ReaderFactory.newXmlReader( file ); IOUtil.copy( reader, buffer ); return buffer.toString(); } /** * normalize EOLs to simple line feed (\\n). */ public static String normalizeEndOfLine( String content ) { StringBuffer buffer = new StringBuffer(); BufferedReader reader = new BufferedReader( new StringReader( content ) ); String line = null; try { while( ( line = reader.readLine() ) != null ) { if ( buffer.length() > 0 ) { buffer.append( '\n' ); } buffer.append( line ); } } catch ( IOException ioe ) { // should not occur since everything happens in-memory } return buffer.toString(); } public static String toString( Throwable error ) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter( sw ); error.printStackTrace( pw ); return sw.toString(); } } maven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/download/0000755000175000017500000000000011116577017025567 5ustar twernertwerner././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootmaven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/download/DefaultDownloadManagerTest.javamaven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/download/DefaultDownloadManagerTest.jav0000644000175000017500000004505410717551366033515 0ustar twernertwernerpackage org.apache.maven.shared.io.download; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.IOException; import java.util.Collections; import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.shared.io.MockManager; import org.apache.maven.shared.io.TestUtils; import org.apache.maven.shared.io.logging.DefaultMessageHolder; import org.apache.maven.shared.io.logging.MessageHolder; import org.apache.maven.wagon.ConnectionException; import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.UnsupportedProtocolException; import org.apache.maven.wagon.Wagon; import org.apache.maven.wagon.authentication.AuthenticationException; import org.apache.maven.wagon.authentication.AuthenticationInfo; import org.apache.maven.wagon.authorization.AuthorizationException; import org.apache.maven.wagon.events.TransferListener; import org.apache.maven.wagon.proxy.ProxyInfo; import org.apache.maven.wagon.repository.Repository; import org.codehaus.plexus.PlexusTestCase; import org.easymock.MockControl; public class DefaultDownloadManagerTest extends PlexusTestCase { private MockManager mockManager; private MockControl wagonManagerControl; private WagonManager wagonManager; private MockControl wagonControl; private Wagon wagon; public void setUp() throws Exception { super.setUp(); mockManager = new MockManager(); wagonManagerControl = MockControl.createControl( WagonManager.class ); mockManager.add( wagonManagerControl ); wagonManager = (WagonManager) wagonManagerControl.getMock(); wagonControl = MockControl.createControl( Wagon.class ); mockManager.add( wagonControl ); wagon = (Wagon) wagonControl.getMock(); } public void testShouldConstructWithNoParamsAndHaveNonNullMessageHolder() { new DefaultDownloadManager(); } public void testShouldConstructWithWagonManager() { MockManager mockManager = new MockManager(); MockControl ctl = MockControl.createControl( WagonManager.class ); mockManager.add( ctl ); WagonManager wagonManager = (WagonManager) ctl.getMock(); mockManager.replayAll(); new DefaultDownloadManager( wagonManager ); mockManager.verifyAll(); } public void testShouldLookupInstanceDefaultRoleHint() throws Exception { lookup( DownloadManager.ROLE, DefaultDownloadManager.ROLE_HINT ); } public void testShouldFailToDownloadMalformedURL() { MockManager mockManager = new MockManager(); MockControl ctl = MockControl.createControl( WagonManager.class ); mockManager.add( ctl ); WagonManager wagonManager = (WagonManager) ctl.getMock(); mockManager.replayAll(); DownloadManager mgr = new DefaultDownloadManager( wagonManager ); try { mgr.download( "://nothing.com/index.html", new DefaultMessageHolder() ); fail( "Should not download with invalid URL." ); } catch ( DownloadFailedException e ) { assertTrue( e.getMessage().indexOf( "invalid URL" ) > -1 ); } mockManager.verifyAll(); } public void testShouldDownloadFromTempFileWithNoTransferListeners() throws IOException, DownloadFailedException { File tempFile = File.createTempFile( "download-source", "test" ); tempFile.deleteOnExit(); setupDefaultMockConfiguration(); mockManager.replayAll(); DownloadManager downloadManager = new DefaultDownloadManager( wagonManager ); downloadManager.download( tempFile.toURL().toExternalForm(), new DefaultMessageHolder() ); mockManager.verifyAll(); } public void testShouldDownloadFromTempFileTwiceAndUseCache() throws IOException, DownloadFailedException { File tempFile = File.createTempFile( "download-source", "test" ); tempFile.deleteOnExit(); setupDefaultMockConfiguration(); mockManager.replayAll(); DownloadManager downloadManager = new DefaultDownloadManager( wagonManager ); File first = downloadManager.download( tempFile.toURL().toExternalForm(), new DefaultMessageHolder() ); MessageHolder mh = new DefaultMessageHolder(); File second = downloadManager.download( tempFile.toURL().toExternalForm(), mh ); assertSame( first, second ); assertEquals( 1, mh.size() ); assertTrue( mh.render().indexOf( "Using cached" ) > -1 ); mockManager.verifyAll(); } public void testShouldDownloadFromTempFileWithOneTransferListener() throws IOException, DownloadFailedException { File tempFile = File.createTempFile( "download-source", "test" ); tempFile.deleteOnExit(); setupDefaultMockConfiguration(); MockControl transferListenerControl = MockControl.createControl( TransferListener.class ); mockManager.add( transferListenerControl ); TransferListener transferListener = (TransferListener) transferListenerControl.getMock(); wagon.addTransferListener( transferListener ); wagon.removeTransferListener( transferListener ); mockManager.replayAll(); DownloadManager downloadManager = new DefaultDownloadManager( wagonManager ); downloadManager.download( tempFile.toURL().toExternalForm(), Collections.singletonList( transferListener ), new DefaultMessageHolder() ); mockManager.verifyAll(); } public void testShouldFailToDownloadWhenWagonProtocolNotFound() throws IOException { File tempFile = File.createTempFile( "download-source", "test" ); tempFile.deleteOnExit(); setupMocksWithWagonManagerGetException( new UnsupportedProtocolException( "not supported" ) ); mockManager.replayAll(); DownloadManager downloadManager = new DefaultDownloadManager( wagonManager ); try { downloadManager.download( tempFile.toURL().toExternalForm(), new DefaultMessageHolder() ); fail( "should have failed to retrieve wagon." ); } catch ( DownloadFailedException e ) { assertTrue( TestUtils.toString( e ).indexOf( "UnsupportedProtocolException" ) > -1 ); } mockManager.verifyAll(); } public void testShouldFailToDownloadWhenWagonConnectThrowsConnectionException() throws IOException { File tempFile = File.createTempFile( "download-source", "test" ); tempFile.deleteOnExit(); setupMocksWithWagonConnectionException( new ConnectionException( "connect error" ) ); mockManager.replayAll(); DownloadManager downloadManager = new DefaultDownloadManager( wagonManager ); try { downloadManager.download( tempFile.toURL().toExternalForm(), new DefaultMessageHolder() ); fail( "should have failed to connect wagon." ); } catch ( DownloadFailedException e ) { assertTrue( TestUtils.toString( e ).indexOf( "ConnectionException" ) > -1 ); } mockManager.verifyAll(); } public void testShouldFailToDownloadWhenWagonConnectThrowsAuthenticationException() throws IOException { File tempFile = File.createTempFile( "download-source", "test" ); tempFile.deleteOnExit(); setupMocksWithWagonConnectionException( new AuthenticationException( "bad credentials" ) ); mockManager.replayAll(); DownloadManager downloadManager = new DefaultDownloadManager( wagonManager ); try { downloadManager.download( tempFile.toURL().toExternalForm(), new DefaultMessageHolder() ); fail( "should have failed to connect wagon." ); } catch ( DownloadFailedException e ) { assertTrue( TestUtils.toString( e ).indexOf( "AuthenticationException" ) > -1 ); } mockManager.verifyAll(); } public void testShouldFailToDownloadWhenWagonGetThrowsTransferFailedException() throws IOException { File tempFile = File.createTempFile( "download-source", "test" ); tempFile.deleteOnExit(); setupMocksWithWagonGetException( new TransferFailedException( "bad transfer" ) ); mockManager.replayAll(); DownloadManager downloadManager = new DefaultDownloadManager( wagonManager ); try { downloadManager.download( tempFile.toURL().toExternalForm(), new DefaultMessageHolder() ); fail( "should have failed to get resource." ); } catch ( DownloadFailedException e ) { assertTrue( TestUtils.toString( e ).indexOf( "TransferFailedException" ) > -1 ); } mockManager.verifyAll(); } public void testShouldFailToDownloadWhenWagonGetThrowsResourceDoesNotExistException() throws IOException { File tempFile = File.createTempFile( "download-source", "test" ); tempFile.deleteOnExit(); setupMocksWithWagonGetException( new ResourceDoesNotExistException( "bad resource" ) ); mockManager.replayAll(); DownloadManager downloadManager = new DefaultDownloadManager( wagonManager ); try { downloadManager.download( tempFile.toURL().toExternalForm(), new DefaultMessageHolder() ); fail( "should have failed to get resource." ); } catch ( DownloadFailedException e ) { assertTrue( TestUtils.toString( e ).indexOf( "ResourceDoesNotExistException" ) > -1 ); } mockManager.verifyAll(); } public void testShouldFailToDownloadWhenWagonGetThrowsAuthorizationException() throws IOException { File tempFile = File.createTempFile( "download-source", "test" ); tempFile.deleteOnExit(); setupMocksWithWagonGetException( new AuthorizationException( "bad transfer" ) ); mockManager.replayAll(); DownloadManager downloadManager = new DefaultDownloadManager( wagonManager ); try { downloadManager.download( tempFile.toURL().toExternalForm(), new DefaultMessageHolder() ); fail( "should have failed to get resource." ); } catch ( DownloadFailedException e ) { assertTrue( TestUtils.toString( e ).indexOf( "AuthorizationException" ) > -1 ); } mockManager.verifyAll(); } public void testShouldFailToDownloadWhenWagonDisconnectThrowsConnectionException() throws IOException, DownloadFailedException { File tempFile = File.createTempFile( "download-source", "test" ); tempFile.deleteOnExit(); setupMocksWithWagonDisconnectException( new ConnectionException( "not connected" ) ); mockManager.replayAll(); DownloadManager downloadManager = new DefaultDownloadManager( wagonManager ); MessageHolder mh = new DefaultMessageHolder(); downloadManager.download( tempFile.toURL().toExternalForm(), mh ); assertTrue( mh.render().indexOf( "ConnectionException" ) > -1 ); mockManager.verifyAll(); } private void setupDefaultMockConfiguration() { try { wagonManager.getWagon( "file" ); wagonManagerControl.setReturnValue( wagon ); } catch ( UnsupportedProtocolException e ) { fail( "This shouldn't happen!!" ); } wagonManager.getAuthenticationInfo( "" ); wagonManagerControl.setMatcher( MockControl.ALWAYS_MATCHER ); wagonManagerControl.setReturnValue( null ); wagonManager.getProxy( "" ); wagonManagerControl.setMatcher( MockControl.ALWAYS_MATCHER ); wagonManagerControl.setReturnValue( null ); try { wagon.connect( new Repository(), new AuthenticationInfo(), new ProxyInfo() ); wagonControl.setMatcher( MockControl.ALWAYS_MATCHER ); } catch ( ConnectionException e ) { fail( "This shouldn't happen!!" ); } catch ( AuthenticationException e ) { fail( "This shouldn't happen!!" ); } try { wagon.get( "file:///some/path", new File( "." ) ); wagonControl.setMatcher( MockControl.ALWAYS_MATCHER ); } catch ( TransferFailedException e ) { fail( "This shouldn't happen!!" ); } catch ( ResourceDoesNotExistException e ) { fail( "This shouldn't happen!!" ); } catch ( AuthorizationException e ) { fail( "This shouldn't happen!!" ); } try { wagon.disconnect(); } catch ( ConnectionException e ) { fail( "This shouldn't happen!!" ); } } private void setupMocksWithWagonManagerGetException( Throwable error ) { try { wagonManager.getWagon( "file" ); wagonManagerControl.setThrowable( error ); } catch ( UnsupportedProtocolException e ) { fail( "This shouldn't happen!!" ); } } private void setupMocksWithWagonConnectionException( Throwable error ) { try { wagonManager.getWagon( "file" ); wagonManagerControl.setReturnValue( wagon ); } catch ( UnsupportedProtocolException e ) { fail( "This shouldn't happen!!" ); } wagonManager.getAuthenticationInfo( "" ); wagonManagerControl.setMatcher( MockControl.ALWAYS_MATCHER ); wagonManagerControl.setReturnValue( null ); wagonManager.getProxy( "" ); wagonManagerControl.setMatcher( MockControl.ALWAYS_MATCHER ); wagonManagerControl.setReturnValue( null ); try { wagon.connect( new Repository(), new AuthenticationInfo(), new ProxyInfo() ); wagonControl.setMatcher( MockControl.ALWAYS_MATCHER ); wagonControl.setThrowable( error ); } catch ( ConnectionException e ) { fail( "This shouldn't happen!!" ); } catch ( AuthenticationException e ) { fail( "This shouldn't happen!!" ); } } private void setupMocksWithWagonGetException( Throwable error ) { try { wagonManager.getWagon( "file" ); wagonManagerControl.setReturnValue( wagon ); } catch ( UnsupportedProtocolException e ) { fail( "This shouldn't happen!!" ); } wagonManager.getAuthenticationInfo( "" ); wagonManagerControl.setMatcher( MockControl.ALWAYS_MATCHER ); wagonManagerControl.setReturnValue( null ); wagonManager.getProxy( "" ); wagonManagerControl.setMatcher( MockControl.ALWAYS_MATCHER ); wagonManagerControl.setReturnValue( null ); try { wagon.connect( new Repository(), new AuthenticationInfo(), new ProxyInfo() ); wagonControl.setMatcher( MockControl.ALWAYS_MATCHER ); } catch ( ConnectionException e ) { fail( "This shouldn't happen!!" ); } catch ( AuthenticationException e ) { fail( "This shouldn't happen!!" ); } try { wagon.get( "file:///some/path", new File( "." ) ); wagonControl.setMatcher( MockControl.ALWAYS_MATCHER ); wagonControl.setThrowable( error ); } catch ( TransferFailedException e ) { fail( "This shouldn't happen!!" ); } catch ( ResourceDoesNotExistException e ) { fail( "This shouldn't happen!!" ); } catch ( AuthorizationException e ) { fail( "This shouldn't happen!!" ); } try { wagon.disconnect(); } catch ( ConnectionException e ) { fail( "This shouldn't happen!!" ); } } private void setupMocksWithWagonDisconnectException( Throwable error ) { try { wagonManager.getWagon( "file" ); wagonManagerControl.setReturnValue( wagon ); } catch ( UnsupportedProtocolException e ) { fail( "This shouldn't happen!!" ); } wagonManager.getAuthenticationInfo( "" ); wagonManagerControl.setMatcher( MockControl.ALWAYS_MATCHER ); wagonManagerControl.setReturnValue( null ); wagonManager.getProxy( "" ); wagonManagerControl.setMatcher( MockControl.ALWAYS_MATCHER ); wagonManagerControl.setReturnValue( null ); try { wagon.connect( new Repository(), new AuthenticationInfo(), new ProxyInfo() ); wagonControl.setMatcher( MockControl.ALWAYS_MATCHER ); } catch ( ConnectionException e ) { fail( "This shouldn't happen!!" ); } catch ( AuthenticationException e ) { fail( "This shouldn't happen!!" ); } try { wagon.get( "file:///some/path", new File( "." ) ); wagonControl.setMatcher( MockControl.ALWAYS_MATCHER ); } catch ( TransferFailedException e ) { fail( "This shouldn't happen!!" ); } catch ( ResourceDoesNotExistException e ) { fail( "This shouldn't happen!!" ); } catch ( AuthorizationException e ) { fail( "This shouldn't happen!!" ); } try { wagon.disconnect(); wagonControl.setThrowable( error ); } catch ( ConnectionException e ) { fail( "This shouldn't happen!!" ); } } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootmaven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/download/DownloadFailedExceptionTest.javamaven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/download/DownloadFailedExceptionTest.ja0000644000175000017500000000272210717551366033506 0ustar twernertwernerpackage org.apache.maven.shared.io.download; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 junit.framework.TestCase; public class DownloadFailedExceptionTest extends TestCase { public void testShouldConstructWithUrlAndMessage() { new DownloadFailedException( "http://www.google.com", "can't find." ); } public void testShouldConstructWithUrlMessageAndException() { new DownloadFailedException( "http://www.google.com", "can't find.", new NullPointerException() ); } public void testShouldRetrieveUrlFromConstructor() { String url = "http://www.google.com"; assertEquals( url, new DownloadFailedException( url, "can't find." ).getUrl() ); } } maven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/location/0000755000175000017500000000000011116577017025570 5ustar twernertwernermaven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/location/URLLocationTest.java0000644000175000017500000000461710717575361031444 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.IOException; import java.net.URL; import org.apache.maven.shared.io.TestUtils; import junit.framework.TestCase; public class URLLocationTest extends TestCase { public void testShouldConstructFromUrlAndTempFileSpecifications() throws IOException { File f = File.createTempFile( "url-location.", ".test" ); f.deleteOnExit(); URL url = f.toURL(); new URLLocation( url, f.getAbsolutePath(), "prefix.", ".suffix", true ); } public void testShouldTransferFromTempFile() throws IOException { File f = File.createTempFile( "url-location.", ".test" ); f.deleteOnExit(); URL url = f.toURL(); URLLocation location = new URLLocation( url, f.getAbsolutePath(), "prefix.", ".suffix", true ); assertNotNull( location.getFile() ); assertFalse( f.equals( location.getFile() ) ); } public void testShouldTransferFromTempFileThenRead() throws IOException { File f = File.createTempFile( "url-location.", ".test" ); f.deleteOnExit(); String testStr = "This is a test"; TestUtils.writeFileWithEncoding( f, testStr, "US-ASCII" ); URL url = f.toURL(); URLLocation location = new URLLocation( url, f.getAbsolutePath(), "prefix.", ".suffix", true ); location.open(); byte[] buffer = new byte[ testStr.length() ]; int read = location.read( buffer ); assertEquals( testStr.length(), read ); assertEquals( testStr, new String( buffer, "US-ASCII" ) ); } } maven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/location/LocatorTest.java0000644000175000017500000001127510717551366030711 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.util.ArrayList; import java.util.Collections; import java.util.List; import org.apache.maven.shared.io.MockManager; import org.apache.maven.shared.io.logging.DefaultMessageHolder; import org.apache.maven.shared.io.logging.MessageHolder; import org.easymock.MockControl; import junit.framework.TestCase; public class LocatorTest extends TestCase { public void testShouldConstructWithNoParams() { new Locator(); } public void testShouldConstructWithStrategyStackAndMessageHolder() { new Locator( Collections.EMPTY_LIST, new DefaultMessageHolder() ); } public void testShouldAllowModificationOfStrategiesAfterConstructionWithUnmodifiableStack() { Locator locator = new Locator( Collections.unmodifiableList( Collections.EMPTY_LIST ), new DefaultMessageHolder() ); locator.addStrategy( new FileLocatorStrategy() ); assertEquals( 1, locator.getStrategies().size() ); } public void testShouldRetrieveNonNullMessageHolderWhenConstructedWithoutParams() { assertNotNull( new Locator().getMessageHolder() ); } public void testSetStrategiesShouldClearAnyPreExistingStrategiesOut() { MockManager mgr = new MockManager(); MockControl originalStrategyControl = MockControl.createControl( LocatorStrategy.class ); mgr.add( originalStrategyControl ); LocatorStrategy originalStrategy = (LocatorStrategy) originalStrategyControl.getMock(); MockControl replacementStrategyControl = MockControl.createControl( LocatorStrategy.class ); mgr.add( replacementStrategyControl ); LocatorStrategy replacementStrategy = (LocatorStrategy) replacementStrategyControl.getMock(); mgr.replayAll(); Locator locator = new Locator(); locator.addStrategy( originalStrategy ); locator.setStrategies( Collections.singletonList( replacementStrategy ) ); List strategies = locator.getStrategies(); assertFalse( strategies.contains( originalStrategy ) ); assertTrue( strategies.contains( replacementStrategy ) ); mgr.verifyAll(); } public void testShouldRemovePreviouslyAddedStrategy() { MockManager mgr = new MockManager(); MockControl originalStrategyControl = MockControl.createControl( LocatorStrategy.class ); mgr.add( originalStrategyControl ); LocatorStrategy originalStrategy = (LocatorStrategy) originalStrategyControl.getMock(); mgr.replayAll(); Locator locator = new Locator(); locator.addStrategy( originalStrategy ); List strategies = locator.getStrategies(); assertTrue( strategies.contains( originalStrategy ) ); locator.removeStrategy( originalStrategy ); strategies = locator.getStrategies(); assertFalse( strategies.contains( originalStrategy ) ); mgr.verifyAll(); } public void testResolutionFallsThroughStrategyStackAndReturnsNullIfNotResolved() { List strategies = new ArrayList(); strategies.add( new LoggingLocatorStrategy() ); strategies.add( new LoggingLocatorStrategy() ); strategies.add( new LoggingLocatorStrategy() ); MessageHolder mh = new DefaultMessageHolder(); Locator locator = new Locator( strategies, mh ); Location location = locator.resolve( "some-specification" ); assertNull( location ); assertEquals( 3, mh.size() ); } public static final class LoggingLocatorStrategy implements LocatorStrategy { static int instanceCounter = 0; int counter = instanceCounter++; public Location resolve( String locationSpecification, MessageHolder messageHolder ) { messageHolder.addMessage( "resolve hit on strategy-" + (counter) ); return null; } } } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootmaven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/location/ClasspathResourceLocatorStrategyTest.javamaven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/location/ClasspathResourceLocatorStrate0000644000175000017500000000371110717551366033663 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 org.apache.maven.shared.io.logging.DefaultMessageHolder; import org.apache.maven.shared.io.logging.MessageHolder; import junit.framework.TestCase; public class ClasspathResourceLocatorStrategyTest extends TestCase { public void testShouldConstructWithNoParams() { new ClasspathResourceLocatorStrategy(); } public void testShouldConstructWithTempFileOptions() { new ClasspathResourceLocatorStrategy( "prefix.", ".suffix", true ); } public void testShouldFailToResolveMissingClasspathResource() { MessageHolder mh = new DefaultMessageHolder(); Location location = new ClasspathResourceLocatorStrategy().resolve( "/some/missing/path", mh ); assertNull( location ); assertEquals( 1, mh.size() ); } public void testShouldResolveExistingClasspathResourceWithoutPrecedingSlash() { MessageHolder mh = new DefaultMessageHolder(); Location location = new ClasspathResourceLocatorStrategy().resolve( "META-INF/maven/test.properties", mh ); assertNotNull( location ); assertEquals( 0, mh.size() ); } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootmaven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/location/ArtifactLocatorStrategyTest.javamaven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/location/ArtifactLocatorStrategyTest.ja0000644000175000017500000004671410717551366033571 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.IOException; import java.util.Collections; import junit.framework.TestCase; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.shared.io.MockManager; import org.apache.maven.shared.io.logging.DefaultMessageHolder; import org.apache.maven.shared.io.logging.MessageHolder; import org.easymock.MockControl; public class ArtifactLocatorStrategyTest extends TestCase { private MockManager mockManager = new MockManager(); private MockControl factoryControl; private ArtifactFactory factory; private MockControl resolverControl; private ArtifactResolver resolver; private MockControl localRepositoryControl; private ArtifactRepository localRepository; public void setUp() { factoryControl = MockControl.createControl( ArtifactFactory.class ); mockManager.add( factoryControl ); factory = (ArtifactFactory) factoryControl.getMock(); resolverControl = MockControl.createControl( ArtifactResolver.class ); mockManager.add( resolverControl ); resolver = (ArtifactResolver) resolverControl.getMock(); localRepositoryControl = MockControl.createControl( ArtifactRepository.class ); mockManager.add( localRepositoryControl ); localRepository = (ArtifactRepository) localRepositoryControl.getMock(); } public void testShouldConstructWithoutDefaultArtifactType() { mockManager.replayAll(); new ArtifactLocatorStrategy( factory, resolver, localRepository, Collections.EMPTY_LIST ); mockManager.verifyAll(); } public void testShouldConstructWithDefaultArtifactType() { mockManager.replayAll(); new ArtifactLocatorStrategy( factory, resolver, localRepository, Collections.EMPTY_LIST, "zip" ); mockManager.verifyAll(); } public void testShouldFailToResolveSpecWithOneToken() { mockManager.replayAll(); LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository, Collections.EMPTY_LIST, "zip" ); MessageHolder mh = new DefaultMessageHolder(); Location location = strategy.resolve( "one-token", mh ); assertNull( location ); assertEquals( 1, mh.size() ); mockManager.verifyAll(); } public void testShouldFailToResolveSpecWithTwoTokens() { mockManager.replayAll(); LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository, Collections.EMPTY_LIST, "zip" ); MessageHolder mh = new DefaultMessageHolder(); Location location = strategy.resolve( "two:tokens", mh ); assertNull( location ); assertEquals( 1, mh.size() ); mockManager.verifyAll(); } public void testShouldResolveSpecWithThreeTokensUsingDefaultType() throws IOException { File tempFile = File.createTempFile( "artifact-location.", ".temp" ); tempFile.deleteOnExit(); MockControl artifactControl = MockControl.createControl( Artifact.class ); mockManager.add( artifactControl ); Artifact artifact = (Artifact) artifactControl.getMock(); artifact.getFile(); artifactControl.setReturnValue( tempFile ); artifact.getFile(); artifactControl.setReturnValue( tempFile ); factory.createArtifact( "group", "artifact", "version", null, "jar" ); factoryControl.setReturnValue( artifact ); try { resolver.resolve( artifact, Collections.EMPTY_LIST, localRepository ); } catch ( ArtifactResolutionException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } catch ( ArtifactNotFoundException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } mockManager.replayAll(); LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository, Collections.EMPTY_LIST ); MessageHolder mh = new DefaultMessageHolder(); Location location = strategy.resolve( "group:artifact:version", mh ); assertNotNull( location ); assertEquals( 0, mh.size() ); assertSame( tempFile, location.getFile() ); mockManager.verifyAll(); } public void testShouldResolveSpecWithThreeTokensUsingCustomizedDefaultType() throws IOException { File tempFile = File.createTempFile( "artifact-location.", ".temp" ); tempFile.deleteOnExit(); MockControl artifactControl = MockControl.createControl( Artifact.class ); mockManager.add( artifactControl ); Artifact artifact = (Artifact) artifactControl.getMock(); artifact.getFile(); artifactControl.setReturnValue( tempFile ); artifact.getFile(); artifactControl.setReturnValue( tempFile ); factory.createArtifact( "group", "artifact", "version", null, "zip" ); factoryControl.setReturnValue( artifact ); try { resolver.resolve( artifact, Collections.EMPTY_LIST, localRepository ); } catch ( ArtifactResolutionException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } catch ( ArtifactNotFoundException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } mockManager.replayAll(); LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository, Collections.EMPTY_LIST, "zip" ); MessageHolder mh = new DefaultMessageHolder(); Location location = strategy.resolve( "group:artifact:version", mh ); assertNotNull( location ); assertEquals( 0, mh.size() ); assertSame( tempFile, location.getFile() ); mockManager.verifyAll(); } public void testShouldResolveSpecWithFourTokens() throws IOException { File tempFile = File.createTempFile( "artifact-location.", ".temp" ); tempFile.deleteOnExit(); MockControl artifactControl = MockControl.createControl( Artifact.class ); mockManager.add( artifactControl ); Artifact artifact = (Artifact) artifactControl.getMock(); artifact.getFile(); artifactControl.setReturnValue( tempFile ); artifact.getFile(); artifactControl.setReturnValue( tempFile ); factory.createArtifact( "group", "artifact", "version", null, "zip" ); factoryControl.setReturnValue( artifact ); try { resolver.resolve( artifact, Collections.EMPTY_LIST, localRepository ); } catch ( ArtifactResolutionException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } catch ( ArtifactNotFoundException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } mockManager.replayAll(); LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository, Collections.EMPTY_LIST ); MessageHolder mh = new DefaultMessageHolder(); Location location = strategy.resolve( "group:artifact:version:zip", mh ); assertNotNull( location ); assertEquals( 0, mh.size() ); assertSame( tempFile, location.getFile() ); mockManager.verifyAll(); } public void testShouldResolveSpecWithFiveTokens() throws IOException { File tempFile = File.createTempFile( "artifact-location.", ".temp" ); tempFile.deleteOnExit(); MockControl artifactControl = MockControl.createControl( Artifact.class ); mockManager.add( artifactControl ); Artifact artifact = (Artifact) artifactControl.getMock(); artifact.getFile(); artifactControl.setReturnValue( tempFile ); artifact.getFile(); artifactControl.setReturnValue( tempFile ); factory.createArtifactWithClassifier( "group", "artifact", "version", "zip", "classifier" ); factoryControl.setReturnValue( artifact ); try { resolver.resolve( artifact, Collections.EMPTY_LIST, localRepository ); } catch ( ArtifactResolutionException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } catch ( ArtifactNotFoundException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } mockManager.replayAll(); LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository, Collections.EMPTY_LIST ); MessageHolder mh = new DefaultMessageHolder(); Location location = strategy.resolve( "group:artifact:version:zip:classifier", mh ); assertNotNull( location ); assertEquals( 0, mh.size() ); assertSame( tempFile, location.getFile() ); mockManager.verifyAll(); } public void testShouldResolveSpecWithFiveTokensAndEmptyTypeToken() throws IOException { File tempFile = File.createTempFile( "artifact-location.", ".temp" ); tempFile.deleteOnExit(); MockControl artifactControl = MockControl.createControl( Artifact.class ); mockManager.add( artifactControl ); Artifact artifact = (Artifact) artifactControl.getMock(); artifact.getFile(); artifactControl.setReturnValue( tempFile ); artifact.getFile(); artifactControl.setReturnValue( tempFile ); factory.createArtifactWithClassifier( "group", "artifact", "version", "jar", "classifier" ); factoryControl.setReturnValue( artifact ); try { resolver.resolve( artifact, Collections.EMPTY_LIST, localRepository ); } catch ( ArtifactResolutionException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } catch ( ArtifactNotFoundException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } mockManager.replayAll(); LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository, Collections.EMPTY_LIST ); MessageHolder mh = new DefaultMessageHolder(); Location location = strategy.resolve( "group:artifact:version::classifier", mh ); assertNotNull( location ); assertEquals( 0, mh.size() ); assertSame( tempFile, location.getFile() ); mockManager.verifyAll(); } public void testShouldResolveSpecWithMoreThanFiveTokens() throws IOException { File tempFile = File.createTempFile( "artifact-location.", ".temp" ); tempFile.deleteOnExit(); MockControl artifactControl = MockControl.createControl( Artifact.class ); mockManager.add( artifactControl ); Artifact artifact = (Artifact) artifactControl.getMock(); artifact.getFile(); artifactControl.setReturnValue( tempFile ); artifact.getFile(); artifactControl.setReturnValue( tempFile ); factory.createArtifactWithClassifier( "group", "artifact", "version", "zip", "classifier" ); factoryControl.setReturnValue( artifact ); try { resolver.resolve( artifact, Collections.EMPTY_LIST, localRepository ); } catch ( ArtifactResolutionException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } catch ( ArtifactNotFoundException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } mockManager.replayAll(); LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository, Collections.EMPTY_LIST ); MessageHolder mh = new DefaultMessageHolder(); Location location = strategy.resolve( "group:artifact:version:zip:classifier:six:seven", mh ); assertNotNull( location ); assertEquals( 1, mh.size() ); assertTrue( mh.render().indexOf( ":six:seven" ) > -1 ); assertSame( tempFile, location.getFile() ); mockManager.verifyAll(); } public void testShouldNotResolveSpecToArtifactWithNullFile() throws IOException { MockControl artifactControl = MockControl.createControl( Artifact.class ); mockManager.add( artifactControl ); Artifact artifact = (Artifact) artifactControl.getMock(); artifact.getFile(); artifactControl.setReturnValue( null ); artifact.getId(); artifactControl.setReturnValue( "" ); factory.createArtifact( "group", "artifact", "version", null, "jar" ); factoryControl.setReturnValue( artifact ); try { resolver.resolve( artifact, Collections.EMPTY_LIST, localRepository ); } catch ( ArtifactResolutionException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } catch ( ArtifactNotFoundException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } mockManager.replayAll(); LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository, Collections.EMPTY_LIST ); MessageHolder mh = new DefaultMessageHolder(); Location location = strategy.resolve( "group:artifact:version", mh ); assertNull( location ); assertEquals( 1, mh.size() ); assertTrue( mh.render().indexOf( "" ) > -1 ); mockManager.verifyAll(); } public void testShouldNotResolveWhenArtifactNotFoundExceptionThrown() throws IOException { MockControl artifactControl = MockControl.createControl( Artifact.class ); mockManager.add( artifactControl ); Artifact artifact = (Artifact) artifactControl.getMock(); artifact.getId(); artifactControl.setReturnValue( "" ); factory.createArtifact( "group", "artifact", "version", null, "jar" ); factoryControl.setReturnValue( artifact ); try { resolver.resolve( artifact, Collections.EMPTY_LIST, localRepository ); resolverControl.setThrowable( new ArtifactNotFoundException( "not found", "group", "artifact", "version", "jar", Collections.EMPTY_LIST, "http://nowhere.com", Collections.EMPTY_LIST, new NullPointerException() ) ); } catch ( ArtifactResolutionException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } catch ( ArtifactNotFoundException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } mockManager.replayAll(); LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository, Collections.EMPTY_LIST ); MessageHolder mh = new DefaultMessageHolder(); Location location = strategy.resolve( "group:artifact:version", mh ); assertNull( location ); assertEquals( 1, mh.size() ); assertTrue( mh.render().indexOf( "" ) > -1 ); assertTrue( mh.render().indexOf( "not found" ) > -1 ); mockManager.verifyAll(); } public void testShouldNotResolveWhenArtifactResolutionExceptionThrown() throws IOException { MockControl artifactControl = MockControl.createControl( Artifact.class ); mockManager.add( artifactControl ); Artifact artifact = (Artifact) artifactControl.getMock(); artifact.getId(); artifactControl.setReturnValue( "" ); factory.createArtifact( "group", "artifact", "version", null, "jar" ); factoryControl.setReturnValue( artifact ); try { resolver.resolve( artifact, Collections.EMPTY_LIST, localRepository ); resolverControl.setThrowable( new ArtifactResolutionException( "resolution failed", "group", "artifact", "version", "jar", Collections.EMPTY_LIST, Collections.EMPTY_LIST, new NullPointerException() ) ); } catch ( ArtifactResolutionException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } catch ( ArtifactNotFoundException e ) { // should never happen fail( "This should NEVER happen. It's a mock!" ); } mockManager.replayAll(); LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository, Collections.EMPTY_LIST ); MessageHolder mh = new DefaultMessageHolder(); Location location = strategy.resolve( "group:artifact:version", mh ); assertNull( location ); assertEquals( 1, mh.size() ); assertTrue( mh.render().indexOf( "" ) > -1 ); assertTrue( mh.render().indexOf( "resolution failed" ) > -1 ); mockManager.verifyAll(); } } maven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/location/ArtifactLocationTest.java0000644000175000017500000000511510717575361032531 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.IOException; import junit.framework.TestCase; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.shared.io.TestUtils; public class ArtifactLocationTest extends TestCase { public void testShouldConstructFromTempFileSpecification() throws IOException { File f = File.createTempFile( "artifact-location.", ".test" ); f.deleteOnExit(); Artifact a = new DefaultArtifact( "group", "artifact", VersionRange.createFromVersion( "1" ), null, "jar", null, new DefaultArtifactHandler() ); a.setFile( f ); ArtifactLocation location = new ArtifactLocation( a, f.getAbsolutePath() ); assertSame( f, location.getFile() ); } public void testShouldRead() throws IOException { File f = File.createTempFile( "url-location.", ".test" ); f.deleteOnExit(); String testStr = "This is a test"; TestUtils.writeFileWithEncoding( f, testStr, "US-ASCII" ); Artifact a = new DefaultArtifact( "group", "artifact", VersionRange.createFromVersion( "1" ), null, "jar", null, new DefaultArtifactHandler() ); a.setFile( f ); ArtifactLocation location = new ArtifactLocation( a, f.getAbsolutePath() ); location.open(); byte[] buffer = new byte[testStr.length()]; int read = location.read( buffer ); assertEquals( testStr.length(), read ); assertEquals( testStr, new String( buffer, "US-ASCII" ) ); } } maven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/location/FileLocatorStrategyTest.java0000644000175000017500000000406610717551366033234 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.IOException; import org.apache.maven.shared.io.logging.DefaultMessageHolder; import org.apache.maven.shared.io.logging.MessageHolder; import junit.framework.TestCase; public class FileLocatorStrategyTest extends TestCase { public void testShouldResolveExistingTempFileLocation() throws IOException { File f = File.createTempFile( "file-locator.", ".test" ); f.deleteOnExit(); FileLocatorStrategy fls = new FileLocatorStrategy(); MessageHolder mh = new DefaultMessageHolder(); Location location = fls.resolve( f.getAbsolutePath(), mh ); assertNotNull( location ); assertTrue( mh.isEmpty() ); assertEquals( f, location.getFile() ); } public void testShouldFailToResolveNonExistentFileLocation() throws IOException { File f = File.createTempFile( "file-locator.", ".test" ); f.delete(); FileLocatorStrategy fls = new FileLocatorStrategy(); MessageHolder mh = new DefaultMessageHolder(); Location location = fls.resolve( f.getAbsolutePath(), mh ); assertNull( location ); System.out.println( mh.render() ); assertEquals( 1, mh.size() ); } } maven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/location/FileLocationTest.java0000644000175000017500000001244610717575361031660 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 org.apache.maven.shared.io.TestUtils; import org.codehaus.plexus.util.IOUtil; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; import java.nio.ByteBuffer; import junit.framework.TestCase; public class FileLocationTest extends TestCase { public void testShouldConstructWithFileThenRetrieveSameFile() throws IOException { File file = File.createTempFile( "test.", ".file-location" ); file.deleteOnExit(); FileLocation location = new FileLocation( file, file.getAbsolutePath() ); assertSame( file, location.getFile() ); assertEquals( file.getAbsolutePath(), location.getSpecification() ); } public void testShouldReadFileContentsUsingByteBuffer() throws IOException { File file = File.createTempFile( "test.", ".file-location" ); file.deleteOnExit(); String testStr = "This is a test"; TestUtils.writeFileWithEncoding( file, testStr, "US-ASCII" ); FileLocation location = new FileLocation( file, file.getAbsolutePath() ); location.open(); ByteBuffer buffer = ByteBuffer.allocate( testStr.length() ); location.read( buffer ); assertEquals( testStr, new String( buffer.array(), "US-ASCII" ) ); } public void testShouldReadFileContentsUsingStream() throws IOException { File file = File.createTempFile( "test.", ".file-location" ); file.deleteOnExit(); String testStr = "This is a test"; TestUtils.writeFileWithEncoding( file, testStr, "US-ASCII" ); FileLocation location = new FileLocation( file, file.getAbsolutePath() ); location.open(); InputStream stream = location.getInputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtil.copy( stream, out ); assertEquals( testStr, new String(out.toByteArray(), "US-ASCII" ) ); } public void testShouldReadFileContentsUsingByteArray() throws IOException { File file = File.createTempFile( "test.", ".file-location" ); file.deleteOnExit(); String testStr = "This is a test"; TestUtils.writeFileWithEncoding( file, testStr, "US-ASCII" ); FileLocation location = new FileLocation( file, file.getAbsolutePath() ); location.open(); byte[] buffer = new byte[ testStr.length() ]; location.read( buffer ); assertEquals( testStr, new String( buffer, "US-ASCII" ) ); } public void testShouldReadThenClose() throws IOException { File file = File.createTempFile( "test.", ".file-location" ); file.deleteOnExit(); String testStr = "This is a test"; TestUtils.writeFileWithEncoding( file, testStr, "US-ASCII" ); FileLocation location = new FileLocation( file, file.getAbsolutePath() ); location.open(); byte[] buffer = new byte[ testStr.length() ]; location.read( buffer ); assertEquals( testStr, new String( buffer, "US-ASCII" ) ); location.close(); } public void testShouldOpenThenFailToSetFile() throws IOException { File file = File.createTempFile( "test.", ".file-location" ); file.deleteOnExit(); TestFileLocation location = new TestFileLocation( file.getAbsolutePath() ); location.open(); try { location.setFile( file ); fail( "should not succeed." ); } catch( IllegalStateException e ) { } } public void testShouldConstructWithoutFileThenSetFileThenOpen() throws IOException { File file = File.createTempFile( "test.", ".file-location" ); file.deleteOnExit(); TestFileLocation location = new TestFileLocation( file.getAbsolutePath() ); location.setFile( file ); location.open(); } public void testShouldConstructWithLocationThenRetrieveEquivalentFile() throws IOException { File file = File.createTempFile( "test.", ".file-location" ); file.deleteOnExit(); Location location = new TestFileLocation( file.getAbsolutePath() ); assertEquals( file, location.getFile() ); assertEquals( file.getAbsolutePath(), location.getSpecification() ); } private static final class TestFileLocation extends FileLocation { TestFileLocation( String specification ) { super( specification ); } } } maven-shared-io-1.1/src/test/java/org/apache/maven/shared/io/location/URLLocatorStrategyTest.java0000644000175000017500000000454210717575361033017 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.IOException; import junit.framework.TestCase; import org.apache.maven.shared.io.TestUtils; import org.apache.maven.shared.io.logging.DefaultMessageHolder; import org.apache.maven.shared.io.logging.MessageHolder; public class URLLocatorStrategyTest extends TestCase { public void testShouldConstructWithNoParams() { new URLLocatorStrategy(); } public void testShouldConstructWithTempFileOptions() { new URLLocatorStrategy( "prefix.", ".suffix", true ); } public void testShouldFailToResolveWithMalformedUrl() { MessageHolder mh = new DefaultMessageHolder(); Location location = new URLLocatorStrategy().resolve( "://www.google.com", mh ); assertNull( location ); assertEquals( 1, mh.size() ); } public void testShouldResolveUrlForTempFile() throws IOException { File tempFile = File.createTempFile( "prefix.", ".suffix" ); tempFile.deleteOnExit(); String testStr = "This is a test."; TestUtils.writeFileWithEncoding( tempFile, testStr, "US-ASCII" ); MessageHolder mh = new DefaultMessageHolder(); Location location = new URLLocatorStrategy().resolve( tempFile.toURL().toExternalForm(), mh ); assertNotNull( location ); assertEquals( 0, mh.size() ); location.open(); byte[] buffer = new byte[testStr.length()]; location.read( buffer ); assertEquals( testStr, new String( buffer, "US-ASCII" ) ); } } maven-shared-io-1.1/src/test/resources/0000755000175000017500000000000011116577017020056 5ustar twernertwernermaven-shared-io-1.1/src/test/resources/META-INF/0000755000175000017500000000000011116577017021216 5ustar twernertwernermaven-shared-io-1.1/src/test/resources/META-INF/maven/0000755000175000017500000000000011116577017022324 5ustar twernertwernermaven-shared-io-1.1/src/test/resources/META-INF/maven/test.properties0000644000175000017500000000144010717551366025425 0ustar twernertwerner# Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you 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. test=successful maven-shared-io-1.1/src/main/0000755000175000017500000000000011116577017016011 5ustar twernertwernermaven-shared-io-1.1/src/main/java/0000755000175000017500000000000011116577017016732 5ustar twernertwernermaven-shared-io-1.1/src/main/java/org/0000755000175000017500000000000011116577017017521 5ustar twernertwernermaven-shared-io-1.1/src/main/java/org/apache/0000755000175000017500000000000011116577017020742 5ustar twernertwernermaven-shared-io-1.1/src/main/java/org/apache/maven/0000755000175000017500000000000011116577017022050 5ustar twernertwernermaven-shared-io-1.1/src/main/java/org/apache/maven/shared/0000755000175000017500000000000011116577017023316 5ustar twernertwernermaven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/0000755000175000017500000000000011116577017023725 5ustar twernertwernermaven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/scan/0000755000175000017500000000000011116577017024651 5ustar twernertwernermaven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/scan/mapping/0000755000175000017500000000000011116577017026304 5ustar twernertwernermaven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/scan/mapping/SuffixMapping.java0000644000175000017500000000416110717551366031736 0ustar twernertwernerpackage org.apache.maven.shared.io.scan.mapping; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.Set; /** * @author jdcasey * @version $Id: SuffixMapping.java 595935 2007-11-17 11:39:34Z vsiveton $ */ public final class SuffixMapping implements SourceMapping { private final String sourceSuffix; private final Set targetSuffixes; public SuffixMapping( String sourceSuffix, String targetSuffix ) { this.sourceSuffix = sourceSuffix; this.targetSuffixes = Collections.singleton( targetSuffix ); } public SuffixMapping( String sourceSuffix, Set targetSuffixes ) { this.sourceSuffix = sourceSuffix; this.targetSuffixes = Collections.unmodifiableSet( targetSuffixes ); } public Set getTargetFiles( File targetDir, String source ) { Set targetFiles = new HashSet(); if ( source.endsWith( sourceSuffix ) ) { String base = source.substring( 0, source.length() - sourceSuffix.length() ); for ( Iterator it = targetSuffixes.iterator(); it.hasNext(); ) { String suffix = (String) it.next(); targetFiles.add( new File( targetDir, base + suffix ) ); } } return targetFiles; } } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/scan/mapping/SourceMapping.java0000644000175000017500000000225710717551366031736 0ustar twernertwernerpackage org.apache.maven.shared.io.scan.mapping; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 org.apache.maven.shared.io.scan.InclusionScanException; import java.io.File; import java.util.Set; /** * @author jdcasey * @version $Id: SourceMapping.java 595935 2007-11-17 11:39:34Z vsiveton $ */ public interface SourceMapping { Set getTargetFiles( File targetDir, String source ) throws InclusionScanException; } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/scan/mapping/SingleTargetMapping.java0000644000175000017500000000342510717551366033064 0ustar twernertwernerpackage org.apache.maven.shared.io.scan.mapping; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 org.apache.maven.shared.io.scan.InclusionScanException; import java.util.Set; import java.util.Collections; import java.io.File; /** * Maps a set of input files to a single output file. * * @author Trygve Laugstøl * @version $Id: SingleTargetMapping.java 595935 2007-11-17 11:39:34Z vsiveton $ */ public class SingleTargetMapping implements SourceMapping { private String sourceSuffix; private String outputFile; public SingleTargetMapping( String sourceSuffix, String outputFile ) { this.sourceSuffix = sourceSuffix; this.outputFile = outputFile; } public Set getTargetFiles( File targetDir, String source ) throws InclusionScanException { if ( !source.endsWith( sourceSuffix ) ) { return Collections.EMPTY_SET; } return Collections.singleton( new File( targetDir, outputFile ) ); } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootmaven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/scan/AbstractResourceInclusionScanner.javamaven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/scan/AbstractResourceInclusionScanner.j0000644000175000017500000000473610717551366033514 0ustar twernertwernerpackage org.apache.maven.shared.io.scan; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 org.apache.maven.shared.io.scan.mapping.SourceMapping; import org.codehaus.plexus.util.DirectoryScanner; import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; /** * @author jdcasey * @version $Id: AbstractResourceInclusionScanner.java 595935 2007-11-17 11:39:34Z vsiveton $ */ public abstract class AbstractResourceInclusionScanner implements ResourceInclusionScanner { private final List sourceMappings = new ArrayList(); public final void addSourceMapping( SourceMapping sourceMapping ) { sourceMappings.add( sourceMapping ); } protected final List getSourceMappings() { return Collections.unmodifiableList( sourceMappings ); } protected String[] scanForSources( File sourceDir, Set sourceIncludes, Set sourceExcludes ) { DirectoryScanner ds = new DirectoryScanner(); ds.setFollowSymlinks( true ); ds.setBasedir( sourceDir ); String[] includes; if ( sourceIncludes.isEmpty() ) { includes = new String[0]; } else { includes = (String[]) sourceIncludes.toArray( new String[sourceIncludes.size()] ); } ds.setIncludes( includes ); String[] excludes; if ( sourceExcludes.isEmpty() ) { excludes = new String[0]; } else { excludes = (String[]) sourceExcludes.toArray( new String[sourceExcludes.size()] ); } ds.setExcludes( excludes ); ds.addDefaultExcludes(); ds.scan(); return ds.getIncludedFiles(); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootmaven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/scan/SimpleResourceInclusionScanner.javamaven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/scan/SimpleResourceInclusionScanner.jav0000644000175000017500000000345510717551366033526 0ustar twernertwernerpackage org.apache.maven.shared.io.scan; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.Collections; import java.util.List; import java.util.Set; /** * @author Trygve Laugstøl * @version $Id: SimpleResourceInclusionScanner.java 595935 2007-11-17 11:39:34Z vsiveton $ */ public class SimpleResourceInclusionScanner extends AbstractResourceInclusionScanner { private Set sourceIncludes; private Set sourceExcludes; public SimpleResourceInclusionScanner( Set sourceIncludes, Set sourceExcludes ) { this.sourceIncludes = sourceIncludes; this.sourceExcludes = sourceExcludes; } public Set getIncludedSources( File sourceDir, File targetDir ) throws InclusionScanException { List srcMappings = getSourceMappings(); if ( srcMappings.isEmpty() ) { return Collections.EMPTY_SET; } return Collections.singleton( scanForSources( sourceDir, sourceIncludes, sourceExcludes ) ); } } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/scan/ResourceInclusionScanner.java0000644000175000017500000000237410717551366032514 0ustar twernertwernerpackage org.apache.maven.shared.io.scan; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 org.apache.maven.shared.io.scan.mapping.SourceMapping; import java.io.File; import java.util.Set; /** * @author jdcasey * @version $Id: ResourceInclusionScanner.java 595935 2007-11-17 11:39:34Z vsiveton $ */ public interface ResourceInclusionScanner { void addSourceMapping( SourceMapping sourceMapping ); Set getIncludedSources( File sourceDir, File targetDir ) throws InclusionScanException; } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/scan/InclusionScanException.java0000644000175000017500000000231510717551366032151 0ustar twernertwernerpackage org.apache.maven.shared.io.scan; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * @author jdcasey * @version $Id: InclusionScanException.java 595935 2007-11-17 11:39:34Z vsiveton $ */ public class InclusionScanException extends Exception { public InclusionScanException( String message ) { super( message ); } public InclusionScanException( String message, Throwable cause ) { super( message, cause ); } } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/scan/StaleResourceScanner.java0000644000175000017500000000757410717551366031630 0ustar twernertwernerpackage org.apache.maven.shared.io.scan; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 org.apache.maven.shared.io.scan.mapping.SourceMapping; import java.io.File; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; /** * @author jdcasey * @version $Id: StaleResourceScanner.java 595935 2007-11-17 11:39:34Z vsiveton $ */ public class StaleResourceScanner extends AbstractResourceInclusionScanner { private final long lastUpdatedWithinMsecs; private final Set sourceIncludes; private final Set sourceExcludes; // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- public StaleResourceScanner() { this( 0, Collections.singleton( "**/*" ), Collections.EMPTY_SET ); } public StaleResourceScanner( long lastUpdatedWithinMsecs ) { this( lastUpdatedWithinMsecs, Collections.singleton( "**/*" ), Collections.EMPTY_SET ); } public StaleResourceScanner( long lastUpdatedWithinMsecs, Set sourceIncludes, Set sourceExcludes ) { this.lastUpdatedWithinMsecs = lastUpdatedWithinMsecs; this.sourceIncludes = sourceIncludes; this.sourceExcludes = sourceExcludes; } // ---------------------------------------------------------------------- // SourceInclusionScanner Implementation // ---------------------------------------------------------------------- public Set getIncludedSources( File sourceDir, File targetDir ) throws InclusionScanException { List srcMappings = getSourceMappings(); if ( srcMappings.isEmpty() ) { return Collections.EMPTY_SET; } String[] potentialIncludes = scanForSources( sourceDir, sourceIncludes, sourceExcludes ); Set matchingSources = new HashSet(); for ( int i = 0; i < potentialIncludes.length; i++ ) { String path = potentialIncludes[i]; File sourceFile = new File( sourceDir, path ); staleSourceFileTesting: for ( Iterator patternIt = srcMappings.iterator(); patternIt.hasNext(); ) { SourceMapping mapping = (SourceMapping) patternIt.next(); Set targetFiles = mapping.getTargetFiles( targetDir, path ); // never include files that don't have corresponding target mappings. // the targets don't have to exist on the filesystem, but the // mappers must tell us to look for them. for ( Iterator targetIt = targetFiles.iterator(); targetIt.hasNext(); ) { File targetFile = (File) targetIt.next(); if ( !targetFile.exists() || ( targetFile.lastModified() + lastUpdatedWithinMsecs < sourceFile.lastModified() ) ) { matchingSources.add( sourceFile ); break staleSourceFileTesting; } } } } return matchingSources; } } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/logging/0000755000175000017500000000000011116577017025353 5ustar twernertwernermaven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/logging/MessageLevels.java0000644000175000017500000000503610717551366030766 0ustar twernertwernerpackage org.apache.maven.shared.io.logging; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; public final class MessageLevels { public static final int LEVEL_DEBUG = 0; public static final int LEVEL_INFO = 1; public static final int LEVEL_WARNING = 2; public static final int LEVEL_ERROR = 3; public static final int LEVEL_SEVERE = 4; public static final int LEVEL_DISABLED = 5; private static final List LEVEL_NAMES; static { List names = new ArrayList(); names.add( "DEBUG" ); names.add( "INFO" ); names.add( "WARN" ); names.add( "ERROR" ); names.add( "SEVERE" ); LEVEL_NAMES = Collections.unmodifiableList( names ); } private MessageLevels() { } public static boolean[] getLevelStates( int maxMessageLevel ) { boolean[] states = new boolean[5]; Arrays.fill( states, false ); switch ( maxMessageLevel ) { case (LEVEL_DEBUG): { states[LEVEL_DEBUG] = true; } case (LEVEL_INFO): { states[LEVEL_INFO] = true; } case (LEVEL_WARNING): { states[LEVEL_WARNING] = true; } case (LEVEL_ERROR): { states[LEVEL_ERROR] = true; } case (LEVEL_SEVERE): { states[LEVEL_SEVERE] = true; } } return states; } public static String getLevelLabel( int messageLevel ) { if ( messageLevel > -1 && LEVEL_NAMES.size() > messageLevel ) { return (String) LEVEL_NAMES.get( messageLevel ); } throw new IllegalArgumentException( "Invalid message level: " + messageLevel ); } } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/logging/MessageHolder.java0000644000175000017500000000603310717551366030747 0ustar twernertwernerpackage org.apache.maven.shared.io.logging; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public interface MessageHolder { MessageHolder newMessage(); MessageHolder newDebugMessage(); MessageHolder newInfoMessage(); MessageHolder newWarningMessage(); MessageHolder newErrorMessage(); MessageHolder newSevereMessage(); MessageHolder append( CharSequence messagePart ); MessageHolder append( Throwable error ); MessageHolder addMessage( CharSequence messagePart, Throwable error ); MessageHolder addMessage( CharSequence messagePart ); MessageHolder addMessage( Throwable error ); MessageHolder addDebugMessage( CharSequence messagePart, Throwable error ); MessageHolder addDebugMessage( CharSequence messagePart ); MessageHolder addDebugMessage( Throwable error ); MessageHolder addInfoMessage( CharSequence messagePart, Throwable error ); MessageHolder addInfoMessage( CharSequence messagePart ); MessageHolder addInfoMessage( Throwable error ); MessageHolder addWarningMessage( CharSequence messagePart, Throwable error ); MessageHolder addWarningMessage( CharSequence messagePart ); MessageHolder addWarningMessage( Throwable error ); MessageHolder addErrorMessage( CharSequence messagePart, Throwable error ); MessageHolder addErrorMessage( CharSequence messagePart ); MessageHolder addErrorMessage( Throwable error ); MessageHolder addSevereMessage( CharSequence messagePart, Throwable error ); MessageHolder addSevereMessage( CharSequence messagePart ); MessageHolder addSevereMessage( Throwable error ); int size(); int countMessages(); int countDebugMessages(); int countInfoMessages(); int countWarningMessages(); int countErrorMessages(); int countSevereMessages(); boolean isDebugEnabled(); void setDebugEnabled( boolean enabled ); boolean isInfoEnabled(); void setInfoEnabled( boolean enabled ); boolean isWarningEnabled(); void setWarningEnabled( boolean enabled ); boolean isErrorEnabled(); void setErrorEnabled( boolean enabled ); boolean isSevereEnabled(); void setSevereEnabled( boolean enabled ); boolean isEmpty(); String render(); void render( MessageSink sink ); void flush(); } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/logging/DefaultMessageHolder.java0000644000175000017500000003211110721032157032233 0ustar twernertwernerpackage org.apache.maven.shared.io.logging; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class DefaultMessageHolder implements MessageHolder { private List messages = new ArrayList(); private Message currentMessage; private int defaultMessageLevel = MessageLevels.LEVEL_INFO; private boolean[] messageLevelStates; private MessageSink onDemandSink; public DefaultMessageHolder() { this.messageLevelStates = MessageLevels.getLevelStates( MessageLevels.LEVEL_INFO ); } public DefaultMessageHolder( int maxMessageLevel, int defaultMessageLevel ) { this.defaultMessageLevel = defaultMessageLevel; this.messageLevelStates = MessageLevels.getLevelStates( maxMessageLevel ); } public DefaultMessageHolder( int maxMessageLevel, int defaultMessageLevel, MessageSink onDemandSink ) { this.defaultMessageLevel = defaultMessageLevel; this.onDemandSink = onDemandSink; this.messageLevelStates = MessageLevels.getLevelStates( maxMessageLevel ); } public MessageHolder addMessage( CharSequence messagePart, Throwable error ) { return addMessage( defaultMessageLevel, messagePart, error ); } protected MessageHolder addMessage( int level, CharSequence messagePart, Throwable error ) { newMessage( level ); append( messagePart.toString() ); append( error ); return this; } public MessageHolder addMessage( CharSequence messagePart ) { return addMessage( defaultMessageLevel, messagePart ); } protected MessageHolder addMessage( int level, CharSequence messagePart ) { newMessage( level ); append( messagePart.toString() ); return this; } public MessageHolder addMessage( Throwable error ) { return addMessage( defaultMessageLevel, error ); } protected MessageHolder addMessage( int level, Throwable error ) { newMessage( level ); append( error ); return this; } public MessageHolder append( CharSequence messagePart ) { if ( currentMessage == null ) { newMessage(); } currentMessage.append( messagePart.toString() ); return this; } public MessageHolder append( Throwable error ) { if ( currentMessage == null ) { newMessage(); } currentMessage.setError( error ); return this; } public boolean isEmpty() { return messages.isEmpty(); } public MessageHolder newMessage() { newMessage( defaultMessageLevel ); return this; } protected void newMessage( int messageLevel ) { if ( onDemandSink != null && currentMessage != null ) { renderTo( currentMessage, onDemandSink ); } currentMessage = new Message( messageLevel, onDemandSink ); messages.add( currentMessage ); } public String render() { StringBuffer buffer = new StringBuffer(); int counter = 1; for ( Iterator it = messages.iterator(); it.hasNext(); ) { Message message = (Message) it.next(); int ml = message.getMessageLevel(); if ( ml >= messageLevelStates.length || ml < 0 ) { ml = MessageLevels.LEVEL_DEBUG; } if ( !messageLevelStates[ml] ) { continue; } CharSequence content = message.render(); String label = MessageLevels.getLevelLabel( message.getMessageLevel() ); if ( content.length() > label.length() + 3 ) { buffer.append( '[' ).append( counter++ ).append( "] " ); buffer.append( content.toString() ); if ( it.hasNext() ) { buffer.append( "\n\n" ); } } } return buffer.toString(); } public int size() { return messages.size(); } private static final class Message { private StringBuffer message = new StringBuffer(); private Throwable error; private final int messageLevel; private final MessageSink onDemandSink; public Message( int messageLevel, MessageSink onDemandSink ) { this.messageLevel = messageLevel; this.onDemandSink = onDemandSink; } public Message setError( Throwable error ) { this.error = error; return this; } public Message append( CharSequence message ) { this.message.append( message.toString() ); return this; } public int getMessageLevel() { return messageLevel; } public CharSequence render() { StringBuffer buffer = new StringBuffer(); if ( onDemandSink == null ) { buffer.append( '[' ).append( MessageLevels.getLevelLabel( messageLevel ) ).append( "] " ); } if ( message != null && message.length() > 0 ) { buffer.append( message ); if ( error != null ) { buffer.append( '\n' ); } } if ( error != null ) { buffer.append( "Error:\n" ); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter( sw ); error.printStackTrace( pw ); buffer.append( sw.toString() ); } return buffer; } } public MessageHolder addDebugMessage( CharSequence messagePart, Throwable error ) { return addMessage( MessageLevels.LEVEL_DEBUG, messagePart, error ); } public MessageHolder addDebugMessage( CharSequence messagePart ) { return addMessage( MessageLevels.LEVEL_DEBUG, messagePart ); } public MessageHolder addDebugMessage( Throwable error ) { return addMessage( MessageLevels.LEVEL_DEBUG, error ); } public MessageHolder addErrorMessage( CharSequence messagePart, Throwable error ) { return addMessage( MessageLevels.LEVEL_ERROR, messagePart, error ); } public MessageHolder addErrorMessage( CharSequence messagePart ) { return addMessage( MessageLevels.LEVEL_ERROR, messagePart ); } public MessageHolder addErrorMessage( Throwable error ) { return addMessage( MessageLevels.LEVEL_ERROR, error ); } public MessageHolder addInfoMessage( CharSequence messagePart, Throwable error ) { return addMessage( MessageLevels.LEVEL_INFO, messagePart, error ); } public MessageHolder addInfoMessage( CharSequence messagePart ) { return addMessage( MessageLevels.LEVEL_INFO, messagePart ); } public MessageHolder addInfoMessage( Throwable error ) { return addMessage( MessageLevels.LEVEL_INFO, error ); } public MessageHolder addSevereMessage( CharSequence messagePart, Throwable error ) { return addMessage( MessageLevels.LEVEL_SEVERE, messagePart, error ); } public MessageHolder addSevereMessage( CharSequence messagePart ) { return addMessage( MessageLevels.LEVEL_SEVERE, messagePart ); } public MessageHolder addSevereMessage( Throwable error ) { return addMessage( MessageLevels.LEVEL_SEVERE, error ); } public MessageHolder addWarningMessage( CharSequence messagePart, Throwable error ) { return addMessage( MessageLevels.LEVEL_WARNING, messagePart, error ); } public MessageHolder addWarningMessage( CharSequence messagePart ) { return addMessage( MessageLevels.LEVEL_WARNING, messagePart ); } public MessageHolder addWarningMessage( Throwable error ) { return addMessage( MessageLevels.LEVEL_WARNING, error ); } public int countDebugMessages() { return countMessagesOfType( MessageLevels.LEVEL_DEBUG ); } public int countErrorMessages() { return countMessagesOfType( MessageLevels.LEVEL_ERROR ); } public int countInfoMessages() { return countMessagesOfType( MessageLevels.LEVEL_INFO ); } public int countMessages() { return size(); } public int countSevereMessages() { return countMessagesOfType( MessageLevels.LEVEL_SEVERE ); } public int countWarningMessages() { return countMessagesOfType( MessageLevels.LEVEL_WARNING ); } private int countMessagesOfType( int messageLevel ) { int count = 0; for ( Iterator it = messages.iterator(); it.hasNext(); ) { Message message = (Message) it.next(); if ( messageLevel == message.getMessageLevel() ) { count++; } } return count; } public boolean isDebugEnabled() { return messageLevelStates[MessageLevels.LEVEL_DEBUG]; } public boolean isErrorEnabled() { return messageLevelStates[MessageLevels.LEVEL_ERROR]; } public boolean isInfoEnabled() { return messageLevelStates[MessageLevels.LEVEL_INFO]; } public boolean isSevereEnabled() { return messageLevelStates[MessageLevels.LEVEL_SEVERE]; } public boolean isWarningEnabled() { return messageLevelStates[MessageLevels.LEVEL_WARNING]; } public MessageHolder newDebugMessage() { if ( isDebugEnabled() ) { newMessage( MessageLevels.LEVEL_DEBUG ); } return this; } public MessageHolder newErrorMessage() { if ( isErrorEnabled() ) { newMessage( MessageLevels.LEVEL_ERROR ); } return this; } public MessageHolder newInfoMessage() { if ( isInfoEnabled() ) { newMessage( MessageLevels.LEVEL_INFO ); } return this; } public MessageHolder newSevereMessage() { if ( isSevereEnabled() ) { newMessage( MessageLevels.LEVEL_SEVERE ); } return this; } public MessageHolder newWarningMessage() { if ( isWarningEnabled() ) { newMessage( MessageLevels.LEVEL_WARNING ); } return this; } public void setDebugEnabled( boolean enabled ) { messageLevelStates[MessageLevels.LEVEL_DEBUG] = enabled; } public void setErrorEnabled( boolean enabled ) { messageLevelStates[MessageLevels.LEVEL_ERROR] = enabled; } public void setInfoEnabled( boolean enabled ) { messageLevelStates[MessageLevels.LEVEL_INFO] = enabled; } public void setSevereEnabled( boolean enabled ) { messageLevelStates[MessageLevels.LEVEL_SEVERE] = enabled; } public void setWarningEnabled( boolean enabled ) { messageLevelStates[MessageLevels.LEVEL_WARNING] = enabled; } public void flush() { if ( onDemandSink != null && currentMessage != null ) { renderTo( currentMessage, onDemandSink ); currentMessage = null; } } public void render( MessageSink sink ) { for ( Iterator it = messages.iterator(); it.hasNext(); ) { Message message = (Message) it.next(); renderTo( message, sink ); } } protected void renderTo( Message message, MessageSink sink ) { switch( message.getMessageLevel() ) { case( MessageLevels.LEVEL_SEVERE ): { sink.severe( message.render().toString() ); break; } case( MessageLevels.LEVEL_ERROR ): { sink.error( message.render().toString() ); break; } case( MessageLevels.LEVEL_WARNING ): { sink.warning( message.render().toString() ); break; } case( MessageLevels.LEVEL_INFO ): { sink.info( message.render().toString() ); break; } default: { sink.debug( message.render().toString() ); break; } } } } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/logging/PlexusLoggerSink.java0000644000175000017500000000275610717551366031502 0ustar twernertwernerpackage org.apache.maven.shared.io.logging; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 org.codehaus.plexus.logging.Logger; public class PlexusLoggerSink implements MessageSink { private final Logger logger; public PlexusLoggerSink( Logger logger ) { this.logger = logger; } public void debug( String message ) { logger.debug( message ); } public void error( String message ) { logger.error( message ); } public void info( String message ) { logger.info( message ); } public void severe( String message ) { logger.fatalError( message ); } public void warning( String message ) { logger.warn( message ); } } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/logging/MessageSink.java0000644000175000017500000000205210717551366030433 0ustar twernertwernerpackage org.apache.maven.shared.io.logging; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public interface MessageSink { void debug( String message ); void info( String message ); void warning( String message ); void error( String message ); void severe( String message ); } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/logging/MultiChannelMessageHolder.java0000644000175000017500000000160710717551366033255 0ustar twernertwernerpackage org.apache.maven.shared.io.logging; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public interface MultiChannelMessageHolder { } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/logging/MojoLogSink.java0000644000175000017500000000273210717551366030422 0ustar twernertwernerpackage org.apache.maven.shared.io.logging; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 org.apache.maven.plugin.logging.Log; public class MojoLogSink implements MessageSink { private final Log logger; public MojoLogSink( Log logger ) { this.logger = logger; } public void debug( String message ) { logger.debug( message ); } public void error( String message ) { logger.error( message ); } public void info( String message ) { logger.info( message ); } public void severe( String message ) { logger.error( message ); } public void warning( String message ) { logger.warn( message ); } } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/download/0000755000175000017500000000000011116577017025534 5ustar twernertwernermaven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/download/DownloadManager.java0000644000175000017500000000237210717551366031452 0ustar twernertwernerpackage org.apache.maven.shared.io.download; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.List; import org.apache.maven.shared.io.logging.MessageHolder; public interface DownloadManager { String ROLE = DownloadManager.class.getName(); File download( String url, MessageHolder messageHolder ) throws DownloadFailedException; File download( String url, List transferListeners, MessageHolder messageHolder ) throws DownloadFailedException; }maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/download/DefaultDownloadManager.java0000644000175000017500000001535410717551366032763 0ustar twernertwernerpackage org.apache.maven.shared.io.download; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.shared.io.logging.MessageHolder; import org.apache.maven.wagon.ConnectionException; import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.UnsupportedProtocolException; import org.apache.maven.wagon.Wagon; import org.apache.maven.wagon.authentication.AuthenticationException; import org.apache.maven.wagon.authorization.AuthorizationException; import org.apache.maven.wagon.events.TransferListener; import org.apache.maven.wagon.repository.Repository; public class DefaultDownloadManager implements DownloadManager { public static final String ROLE_HINT = "default"; private WagonManager wagonManager; private Map cache = new HashMap(); public DefaultDownloadManager() { } public DefaultDownloadManager( WagonManager wagonManager ) { this.wagonManager = wagonManager; } public File download( String url, MessageHolder messageHolder ) throws DownloadFailedException { return download( url, Collections.EMPTY_LIST, messageHolder ); } public File download( String url, List transferListeners, MessageHolder messageHolder ) throws DownloadFailedException { File downloaded = (File) cache.get( url ); if ( downloaded != null && downloaded.exists() ) { messageHolder.addMessage( "Using cached download: " + downloaded.getAbsolutePath() ); return downloaded; } URL sourceUrl; try { sourceUrl = new URL( url ); } catch ( MalformedURLException e ) { throw new DownloadFailedException( url, "Download failed due to invalid URL. Reason: " + e.getMessage(), e ); } Wagon wagon = null; // Retrieve the correct Wagon instance used to download the remote archive try { wagon = wagonManager.getWagon( sourceUrl.getProtocol() ); } catch ( UnsupportedProtocolException e ) { throw new DownloadFailedException( url, "Download failed. Reason: " + e.getMessage(), e ); } messageHolder.addMessage( "Using wagon: " + wagon + " to download: " + url ); try { // create the landing file in /tmp for the downloaded source archive downloaded = File.createTempFile( "download-", null ); // delete when the JVM exits, to avoid polluting the temp dir... downloaded.deleteOnExit(); } catch ( IOException e ) { throw new DownloadFailedException( url, "Failed to create temporary file target for download. Reason: " + e.getMessage(), e ); } messageHolder.addMessage( "Download target is: " + downloaded.getAbsolutePath() ); // split the download URL into base URL and remote path for connecting, then retrieving. String remotePath = sourceUrl.getPath(); String baseUrl = url.substring( 0, url.length() - remotePath.length() ); for ( Iterator it = transferListeners.iterator(); it.hasNext(); ) { TransferListener listener = (TransferListener) it.next(); wagon.addTransferListener( listener ); } // connect to the remote site, and retrieve the archive. Note the separate methods in which // base URL and remote path are used. Repository repo = new Repository( sourceUrl.getHost(), baseUrl ); messageHolder.addMessage( "Connecting to: " + repo.getHost() + "(baseUrl: " + repo.getUrl() + ")" ); try { wagon.connect( repo, wagonManager.getAuthenticationInfo( repo.getId() ), wagonManager.getProxy( sourceUrl .getProtocol() ) ); } catch ( ConnectionException e ) { throw new DownloadFailedException( url, "Download failed. Reason: " + e.getMessage(), e ); } catch ( AuthenticationException e ) { throw new DownloadFailedException( url, "Download failed. Reason: " + e.getMessage(), e ); } messageHolder.addMessage( "Getting: " + remotePath ); try { wagon.get( remotePath, downloaded ); // cache this for later download requests to the same instance... cache.put( url, downloaded ); return downloaded; } catch ( TransferFailedException e ) { throw new DownloadFailedException( url, "Download failed. Reason: " + e.getMessage(), e ); } catch ( ResourceDoesNotExistException e ) { throw new DownloadFailedException( url, "Download failed. Reason: " + e.getMessage(), e ); } catch ( AuthorizationException e ) { throw new DownloadFailedException( url, "Download failed. Reason: " + e.getMessage(), e ); } finally { // ensure the Wagon instance is closed out properly. if ( wagon != null ) { try { messageHolder.addMessage( "Disconnecting." ); wagon.disconnect(); } catch ( ConnectionException e ) { messageHolder.addMessage( "Failed to disconnect wagon for: " + url, e ); } for ( Iterator it = transferListeners.iterator(); it.hasNext(); ) { TransferListener listener = (TransferListener) it.next(); wagon.removeTransferListener( listener ); } } } } } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/download/DownloadFailedException.java0000644000175000017500000000247210717551366033144 0ustar twernertwernerpackage org.apache.maven.shared.io.download; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ public class DownloadFailedException extends Exception { private static final long serialVersionUID = 1L; private String url; public DownloadFailedException( String url, String message, Throwable cause ) { super( message, cause ); this.url = url; } public DownloadFailedException( String url, String message ) { super( message ); this.url = url; } public String getUrl() { return url; } } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/location/0000755000175000017500000000000011116577017025535 5ustar twernertwernermaven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/location/Location.java0000644000175000017500000000240010717551366030151 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.IOException; import java.io.InputStream; import java.nio.ByteBuffer; public interface Location { File getFile() throws IOException; void open() throws IOException; void close(); int read( ByteBuffer buffer ) throws IOException; int read( byte[] buffer ) throws IOException; InputStream getInputStream() throws IOException; String getSpecification(); } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/location/Locator.java0000644000175000017500000000453310717551366030015 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.util.ArrayList; import java.util.Iterator; import java.util.List; import org.apache.maven.shared.io.logging.DefaultMessageHolder; import org.apache.maven.shared.io.logging.MessageHolder; public final class Locator { private List strategies; private final MessageHolder messageHolder; public Locator( List strategies, MessageHolder messageHolder ) { this.messageHolder = messageHolder; this.strategies = new ArrayList( strategies ); } public Locator() { this.messageHolder = new DefaultMessageHolder(); this.strategies = new ArrayList(); } public MessageHolder getMessageHolder() { return messageHolder; } public void addStrategy( LocatorStrategy strategy ) { this.strategies.add( strategy ); } public void removeStrategy( LocatorStrategy strategy ) { this.strategies.remove( strategy ); } public void setStrategies( List strategies ) { this.strategies.clear(); this.strategies.addAll( strategies ); } public List getStrategies() { return strategies; } public Location resolve( String locationSpecification ) { Location location = null; for ( Iterator it = strategies.iterator(); location == null && it.hasNext(); ) { LocatorStrategy strategy = (LocatorStrategy) it.next(); location = strategy.resolve( locationSpecification, messageHolder ); } return location; } } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/location/ArtifactLocation.java0000644000175000017500000000213210717551366031631 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 org.apache.maven.artifact.Artifact; public class ArtifactLocation extends FileLocation { public ArtifactLocation( Artifact artifact, String specification ) { super( specification ); setFile( artifact.getFile() ); } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootmaven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/location/ClasspathResourceLocatorStrategy.javamaven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/location/ClasspathResourceLocatorStrate0000644000175000017500000000426610717551366033636 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.net.URL; import org.apache.maven.shared.io.logging.MessageHolder; public class ClasspathResourceLocatorStrategy implements LocatorStrategy { private String tempFilePrefix = "location."; private String tempFileSuffix = ".cpurl"; private boolean tempFileDeleteOnExit = true; public ClasspathResourceLocatorStrategy() { } public ClasspathResourceLocatorStrategy( String tempFilePrefix, String tempFileSuffix, boolean tempFileDeleteOnExit ) { this.tempFilePrefix = tempFilePrefix; this.tempFileSuffix = tempFileSuffix; this.tempFileDeleteOnExit = tempFileDeleteOnExit; } public Location resolve( String locationSpecification, MessageHolder messageHolder ) { ClassLoader cloader = Thread.currentThread().getContextClassLoader(); URL resource = cloader.getResource( locationSpecification ); Location location = null; if ( resource != null ) { location = new URLLocation( resource, locationSpecification, tempFilePrefix, tempFileSuffix, tempFileDeleteOnExit ); } else { messageHolder.addMessage( "Failed to resolve classpath resource: " + locationSpecification + " from classloader: " + cloader ); } return location; } } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/location/ArtifactLocatorStrategy.java0000644000175000017500000001352710717551366033221 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.util.List; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.shared.io.logging.MessageHolder; public class ArtifactLocatorStrategy implements LocatorStrategy { private final ArtifactFactory factory; private final ArtifactResolver resolver; private String defaultArtifactType = "jar"; private final ArtifactRepository localRepository; private final List remoteRepositories; private String defaultClassifier = null; public ArtifactLocatorStrategy( ArtifactFactory factory, ArtifactResolver resolver, ArtifactRepository localRepository, List remoteRepositories ) { this.factory = factory; this.resolver = resolver; this.localRepository = localRepository; this.remoteRepositories = remoteRepositories; } public ArtifactLocatorStrategy( ArtifactFactory factory, ArtifactResolver resolver, ArtifactRepository localRepository, List remoteRepositories, String defaultArtifactType ) { this.factory = factory; this.resolver = resolver; this.localRepository = localRepository; this.remoteRepositories = remoteRepositories; this.defaultArtifactType = defaultArtifactType; } public ArtifactLocatorStrategy( ArtifactFactory factory, ArtifactResolver resolver, ArtifactRepository localRepository, List remoteRepositories, String defaultArtifactType, String defaultClassifier ) { this.factory = factory; this.resolver = resolver; this.localRepository = localRepository; this.remoteRepositories = remoteRepositories; this.defaultArtifactType = defaultArtifactType; this.defaultClassifier = defaultClassifier; } /** * Assumes artifact identity is given in a set of comma-delimited tokens of * the form: groupId:artifactId:version:type:classifier, where * type and classifier are optional. */ public Location resolve( String locationSpecification, MessageHolder messageHolder ) { String[] parts = locationSpecification.split( ":" ); Location location = null; if ( parts.length > 2 ) { String groupId = parts[0]; String artifactId = parts[1]; String version = parts[2]; String type = defaultArtifactType; if ( parts.length > 3 ) { if ( parts[3].trim().length() > 0 ) { type = parts[3]; } } String classifier = defaultClassifier; if ( parts.length > 4 ) { classifier = parts[4]; } if ( parts.length > 5 ) { messageHolder.newMessage().append( "Location specification has unused tokens: \'" ); for ( int i = 5; i < parts.length; i++ ) { messageHolder.append( ":" + parts[i] ); } } Artifact artifact; if ( classifier == null ) { artifact = factory.createArtifact( groupId, artifactId, version, null, type ); } else { artifact = factory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier ); } try { resolver.resolve( artifact, remoteRepositories, localRepository ); if ( artifact.getFile() != null ) { location = new ArtifactLocation( artifact, locationSpecification ); } else { messageHolder.addMessage( "Supposedly resolved artifact: " + artifact.getId() + " does not have an associated file." ); } } catch ( ArtifactResolutionException e ) { messageHolder.addMessage( "Failed to resolve artifact: " + artifact.getId() + " for location: " + locationSpecification, e ); } catch ( ArtifactNotFoundException e ) { messageHolder.addMessage( "Failed to resolve artifact: " + artifact.getId() + " for location: " + locationSpecification, e ); } } else { messageHolder.addMessage( "Invalid artifact specification: \'" + locationSpecification + "\'. Must contain at least three fields, separated by ':'." ); } return location; } } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/location/FileLocatorStrategy.java0000644000175000017500000000270110717551366032333 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 org.apache.maven.shared.io.logging.MessageHolder; public class FileLocatorStrategy implements LocatorStrategy { public Location resolve( String locationSpecification, MessageHolder messageHolder ) { File file = new File( locationSpecification ); Location location = null; if ( file.exists() ) { location = new FileLocation( file, locationSpecification ); } else { messageHolder.addMessage( "File: " + file.getAbsolutePath() + " does not exist." ); } return location; } } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/location/LocatorStrategy.java0000644000175000017500000000201310717551366031527 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 org.apache.maven.shared.io.logging.MessageHolder; public interface LocatorStrategy { Location resolve( String locationSpecification, MessageHolder messageHolder ); } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/location/FileLocation.java0000644000175000017500000000637210717551366030765 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class FileLocation implements Location { private File file; private FileChannel channel; private final String specification; private FileInputStream stream; public FileLocation( File file, String specification ) { this.file = file; this.specification = specification; } protected FileLocation( String specification ) { this.specification = specification; } public void close() { if ( ( channel != null ) && channel.isOpen() ) { try { channel.close(); } catch ( IOException e ) { //swallow it. } } if ( stream != null ) { try { stream.close(); } catch( IOException e ) { // swallow it. } } } public File getFile() throws IOException { initFile(); return unsafeGetFile(); } protected File unsafeGetFile() { return file; } protected void initFile() throws IOException { // TODO: Log this in the debug log-level... if ( file == null ) { file = new File( specification ); } } protected void setFile( File file ) { if ( channel != null ) { throw new IllegalStateException( "Location is already open; cannot setFile(..)." ); } this.file = file; } public String getSpecification() { return specification; } public void open() throws IOException { if ( stream == null ) { initFile(); stream = new FileInputStream( file ); channel = stream.getChannel(); } } public int read( ByteBuffer buffer ) throws IOException { open(); return channel.read( buffer ); } public int read( byte[] buffer ) throws IOException { open(); return channel.read( ByteBuffer.wrap( buffer ) ); } public InputStream getInputStream() throws IOException { open(); return stream; } } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/location/URLLocation.java0000644000175000017500000000375110717551366030546 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.IOException; import java.net.URL; import org.codehaus.plexus.util.FileUtils; public class URLLocation extends FileLocation { private final URL url; private final String tempFilePrefix; private final String tempFileSuffix; private final boolean tempFileDeleteOnExit; public URLLocation( URL url, String specification, String tempFilePrefix, String tempFileSuffix, boolean tempFileDeleteOnExit ) { super( specification ); this.url = url; this.tempFilePrefix = tempFilePrefix; this.tempFileSuffix = tempFileSuffix; this.tempFileDeleteOnExit = tempFileDeleteOnExit; } protected void initFile() throws IOException { // TODO: Log this in the debug log-level... if ( unsafeGetFile() == null ) { File tempFile = File.createTempFile( tempFilePrefix, tempFileSuffix ); if ( tempFileDeleteOnExit ) { tempFile.deleteOnExit(); } FileUtils.copyURLToFile( url, tempFile ); setFile( tempFile ); } } } maven-shared-io-1.1/src/main/java/org/apache/maven/shared/io/location/URLLocatorStrategy.java0000644000175000017500000000404010717551366032114 0ustar twernertwernerpackage org.apache.maven.shared.io.location; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.net.MalformedURLException; import java.net.URL; import org.apache.maven.shared.io.logging.MessageHolder; public class URLLocatorStrategy implements LocatorStrategy { private String tempFilePrefix = "location."; private String tempFileSuffix = ".url"; private boolean tempFileDeleteOnExit = true; public URLLocatorStrategy() { } public URLLocatorStrategy( String tempFilePrefix, String tempFileSuffix, boolean tempFileDeleteOnExit ) { this.tempFilePrefix = tempFilePrefix; this.tempFileSuffix = tempFileSuffix; this.tempFileDeleteOnExit = tempFileDeleteOnExit; } public Location resolve( String locationSpecification, MessageHolder messageHolder ) { Location location = null; try { URL url = new URL( locationSpecification ); location = new URLLocation( url, locationSpecification, tempFilePrefix, tempFileSuffix, tempFileDeleteOnExit ); } catch ( MalformedURLException e ) { messageHolder.addMessage( "Building URL from location: " + locationSpecification, e ); } return location; } } maven-shared-io-1.1/src/main/resources/0000755000175000017500000000000011116577017020023 5ustar twernertwernermaven-shared-io-1.1/src/main/resources/META-INF/0000755000175000017500000000000011116577017021163 5ustar twernertwernermaven-shared-io-1.1/src/main/resources/META-INF/plexus/0000755000175000017500000000000011116577017022503 5ustar twernertwernermaven-shared-io-1.1/src/main/resources/META-INF/plexus/components.xml0000644000175000017500000000241110717551366025415 0ustar twernertwerner org.apache.maven.shared.io.download.DownloadManager default org.apache.maven.shared.io.download.DefaultDownloadManager org.apache.maven.artifact.manager.WagonManager maven-shared-io-1.1/pom.xml0000644000175000017500000000754410721032157015615 0ustar twernertwerner 4.0.0 org.apache.maven.shared maven-shared-components 8 maven-shared-io 1.1 Maven Shared I/O API API for I/O support like logging, download or file scanning. 2.0.6 Joakim Erdfelt joakim@erdfelt.com org.apache.maven maven-artifact 2.0.2 org.apache.maven maven-artifact-manager 2.0.2 org.apache.maven.wagon wagon-provider-api 1.0-alpha-6 org.apache.maven maven-plugin-api 2.0 true org.codehaus.plexus plexus-utils 1.4.6 org.codehaus.plexus plexus-container-default 1.0-alpha-9 true easymock easymock 1.2_Java1.3 test maven-surefire-plugin 2.3 **/TestUtils* scm:svn:http://svn.apache.org/repos/asf/maven/shared/tags/maven-shared-io-1.1 scm:svn:https://svn.apache.org/repos/asf/maven/shared/tags/maven-shared-io-1.1 http://svn.apache.org/viewcvs.cgi/maven/shared/tags/maven-shared-io-1.1 apache.snapshots scp://people.apache.org/www/people.apache.org/repo/m2-snapshot-repository apache scp://people.apache.org/www/people.apache.org/repo/m2-ibiblio-rsync-repository