1 package org.apache.archiva.webdav;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import com.gargoylesoftware.htmlunit.HttpMethod;
23 import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
24 import com.gargoylesoftware.htmlunit.WebClient;
25 import com.gargoylesoftware.htmlunit.WebRequest;
26 import com.gargoylesoftware.htmlunit.WebResponse;
27 import junit.framework.TestCase;
28 import org.apache.archiva.configuration.ArchivaConfiguration;
29 import org.apache.archiva.configuration.Configuration;
30 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
31 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
32 import org.apache.archiva.repository.ManagedRepository;
33 import org.apache.archiva.repository.RepositoryException;
34 import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
35 import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
36 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
37 import org.apache.archiva.webdav.mock.httpunit.MkColMethodWebRequest;
38 import org.apache.commons.io.FileUtils;
39 import org.apache.commons.io.IOUtils;
40 import org.apache.commons.lang3.StringUtils;
41 import org.junit.After;
42 import org.junit.Assert;
43 import org.junit.Before;
44 import org.junit.runner.RunWith;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47 import org.springframework.beans.BeansException;
48 import org.springframework.beans.factory.BeanFactory;
49 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
50 import org.springframework.beans.factory.ObjectProvider;
51 import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
52 import org.springframework.context.ApplicationContext;
53 import org.springframework.context.ApplicationEvent;
54 import org.springframework.context.MessageSourceResolvable;
55 import org.springframework.context.NoSuchMessageException;
56 import org.springframework.core.ResolvableType;
57 import org.springframework.core.env.Environment;
58 import org.springframework.core.io.Resource;
59 import org.springframework.mock.web.MockHttpServletRequest;
60 import org.springframework.mock.web.MockHttpServletResponse;
61 import org.springframework.mock.web.MockServletConfig;
62 import org.springframework.mock.web.MockServletContext;
63 import org.springframework.test.context.ContextConfiguration;
64 import org.springframework.web.context.WebApplicationContext;
66 import javax.inject.Inject;
67 import javax.servlet.Servlet;
68 import javax.servlet.ServletContext;
69 import javax.servlet.http.HttpServletRequest;
70 import javax.servlet.http.HttpServletResponse;
71 import java.io.IOException;
72 import java.io.InputStream;
73 import java.io.UnsupportedEncodingException;
74 import java.lang.annotation.Annotation;
76 import java.nio.charset.Charset;
77 import java.nio.file.Files;
78 import java.nio.file.Path;
79 import java.nio.file.Paths;
80 import java.util.Locale;
82 import java.util.concurrent.atomic.AtomicReference;
85 * AbstractRepositoryServletTestCase
87 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
88 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:spring-context.xml",
89 "classpath*:/repository-servlet-simple.xml" } )
90 public abstract class AbstractRepositoryServletTestCase
93 protected static final String REPOID_INTERNAL = "internal";
95 protected Path repoRootInternal;
97 protected Path repoRootLegacy;
100 protected ArchivaConfiguration archivaConfiguration;
103 protected ApplicationContext applicationContext;
105 @SuppressWarnings( "unused" )
107 RepositoryHandlerDependencies repositoryHandlerDependencies;
110 ArchivaRepositoryRegistry repositoryRegistry;
112 protected Logger log = LoggerFactory.getLogger( getClass() );
114 private AtomicReference<Path> projectBase = new AtomicReference<>( );
115 private AtomicReference<Path> appserverBase = new AtomicReference<>( );
118 public Path getProjectBase() {
119 if (this.projectBase.get()==null) {
120 String pathVal = System.getProperty("mvn.project.base.dir");
122 if (StringUtils.isEmpty(pathVal)) {
123 baseDir= Paths.get("").toAbsolutePath();
125 baseDir = Paths.get(pathVal).toAbsolutePath();
127 this.projectBase.compareAndSet(null, baseDir);
129 return this.projectBase.get();
132 public Path getAppserverBase() {
133 if (appserverBase.get()==null)
135 String pathVal = System.getProperty( "appserver.base" );
137 if ( StringUtils.isNotEmpty( pathVal ) )
139 basePath = Paths.get( pathVal );
143 log.warn("Using relative path to working directory, appserver.base was not set!");
144 basePath = Paths.get( "target/appserver-base" );
146 appserverBase.set( basePath );
148 return appserverBase.get();
151 protected void saveConfiguration()
154 repositoryRegistry.setArchivaConfiguration(archivaConfiguration);
155 repositoryRegistry.reload();
156 saveConfiguration( archivaConfiguration );
168 System.setProperty( "appserver.base", getAppserverBase().toAbsolutePath().toString());
169 log.info("setUp appserverBase={}, projectBase={}, workingDir={}", getAppserverBase(), getProjectBase(), Paths.get("").toString());
171 repositoryRegistry.getRepositories().stream().forEach(r -> {
174 repositoryRegistry.removeRepository( r );
176 catch ( RepositoryException e )
178 e.printStackTrace( );
181 org.apache.archiva.common.utils.FileUtils.deleteDirectory( getAppserverBase() );
183 Path testConf = getProjectBase().resolve( "src/test/resources/repository-archiva.xml" );
184 Path testConfDest = getAppserverBase().resolve("conf/archiva.xml" );
185 if ( Files.exists(testConfDest) )
187 org.apache.archiva.common.utils.FileUtils.deleteQuietly( testConfDest );
189 FileUtils.copyFile( testConf.toFile(), testConfDest.toFile() );
191 repoRootInternal = getAppserverBase().resolve("data/repositories/internal" );
192 repoRootLegacy = getAppserverBase().resolve( "data/repositories/legacy" );
193 Configuration config = archivaConfiguration.getConfiguration();
195 config.getManagedRepositories().clear();
197 config.addManagedRepository(
198 createManagedRepository( REPOID_INTERNAL, "Internal Test Repo", repoRootInternal, true ) );
199 config.getProxyConnectors().clear();
201 config.getRemoteRepositories().clear();
203 saveConfiguration( archivaConfiguration );
204 // repositoryRegistry.reload();
206 // ArchivaIndexingContext ctx = repositoryRegistry.getManagedRepository( REPOID_INTERNAL ).getIndexingContext( );
209 // if (repositoryRegistry.getIndexManager(RepositoryType.MAVEN)!=null) {
210 // repositoryRegistry.getIndexManager(RepositoryType.MAVEN).pack(ctx);
223 protected UnauthenticatedRepositoryServlet unauthenticatedRepositoryServlet =
224 new UnauthenticatedRepositoryServlet();
226 protected void startRepository()
230 final MockServletContext mockServletContext = new MockServletContext();
232 WebApplicationContext webApplicationContext =
233 new TestWebapplicationContext( applicationContext, mockServletContext );
235 mockServletContext.setAttribute( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
236 webApplicationContext );
238 MockServletConfig mockServletConfig = new MockServletConfig()
241 public ServletContext getServletContext()
243 return mockServletContext;
247 unauthenticatedRepositoryServlet.init( mockServletConfig );
251 protected String createVersionMetadata(String groupId, String artifactId, String version) {
252 return createVersionMetadata(groupId, artifactId, version, null, null, null);
255 protected String createVersionMetadata(String groupId, String artifactId, String version, String timestamp, String buildNumber, String lastUpdated) {
256 StringBuilder buf = new StringBuilder();
257 buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n");
258 buf.append("<metadata>\n");
259 buf.append(" <groupId>").append(groupId).append("</groupId>\n");
260 buf.append(" <artifactId>").append(artifactId).append("</artifactId>\n");
261 buf.append(" <version>").append(version).append("</version>\n");
262 boolean hasSnapshot = StringUtils.isNotBlank(timestamp) || StringUtils.isNotBlank(buildNumber);
263 boolean hasLastUpdated = StringUtils.isNotBlank(lastUpdated);
264 if (hasSnapshot || hasLastUpdated) {
265 buf.append(" <versioning>\n");
267 buf.append(" <snapshot>\n");
268 buf.append(" <buildNumber>").append(buildNumber).append("</buildNumber>\n");
269 buf.append(" <timestamp>").append(timestamp).append("</timestamp>\n");
270 buf.append(" </snapshot>\n");
272 if (hasLastUpdated) {
273 buf.append(" <lastUpdated>").append(lastUpdated).append("</lastUpdated>\n");
275 buf.append(" </versioning>\n");
277 buf.append("</metadata>");
278 return buf.toString();
282 public static class TestWebapplicationContext
283 implements WebApplicationContext
285 private ApplicationContext applicationContext;
287 private ServletContext servletContext;
289 TestWebapplicationContext( ApplicationContext applicationContext, ServletContext servletContext )
291 this.applicationContext = applicationContext;
295 public ServletContext getServletContext()
297 return servletContext;
301 public String getId()
303 return applicationContext.getId();
307 public String getApplicationName()
309 return applicationContext.getApplicationName();
313 public String getDisplayName()
315 return applicationContext.getDisplayName();
319 public long getStartupDate()
321 return applicationContext.getStartupDate();
325 public ApplicationContext getParent()
327 return applicationContext.getParent();
331 public AutowireCapableBeanFactory getAutowireCapableBeanFactory()
332 throws IllegalStateException
334 return applicationContext.getAutowireCapableBeanFactory();
338 public void publishEvent( ApplicationEvent applicationEvent )
340 applicationContext.publishEvent( applicationEvent );
344 public Environment getEnvironment()
346 return applicationContext.getEnvironment();
350 public BeanFactory getParentBeanFactory()
352 return applicationContext.getParentBeanFactory();
356 public boolean containsLocalBean( String s )
358 return applicationContext.containsLocalBean( s );
362 public boolean containsBeanDefinition( String s )
364 return applicationContext.containsBeanDefinition( s );
368 public int getBeanDefinitionCount()
370 return applicationContext.getBeanDefinitionCount();
374 public String[] getBeanDefinitionNames()
376 return applicationContext.getBeanDefinitionNames();
380 public <T> ObjectProvider<T> getBeanProvider( Class<T> aClass, boolean b )
386 public <T> ObjectProvider<T> getBeanProvider( ResolvableType resolvableType, boolean b )
392 public String[] getBeanNamesForType( Class<?> aClass )
394 return applicationContext.getBeanNamesForType( aClass );
398 public String[] getBeanNamesForType( Class<?> aClass, boolean b, boolean b2 )
400 return applicationContext.getBeanNamesForType( aClass, b, b2 );
404 public <T> Map<String, T> getBeansOfType( Class<T> tClass )
405 throws BeansException
407 return applicationContext.getBeansOfType( tClass );
411 public <T> Map<String, T> getBeansOfType( Class<T> tClass, boolean b, boolean b2 )
412 throws BeansException
414 return applicationContext.getBeansOfType( tClass, b, b2 );
418 public String[] getBeanNamesForAnnotation( Class<? extends Annotation> aClass )
420 return applicationContext.getBeanNamesForAnnotation( aClass );
424 public Map<String, Object> getBeansWithAnnotation( Class<? extends Annotation> aClass )
425 throws BeansException
427 return applicationContext.getBeansWithAnnotation( aClass );
431 public <A extends Annotation> A findAnnotationOnBean( String s, Class<A> aClass )
432 throws NoSuchBeanDefinitionException
434 return applicationContext.findAnnotationOnBean( s, aClass );
438 public <A extends Annotation> A findAnnotationOnBean( String s, Class<A> aClass, boolean b ) throws NoSuchBeanDefinitionException
440 throw new UnsupportedOperationException( "No supported yet." );
444 public <T> T getBean( Class<T> aClass, Object... objects )
445 throws BeansException
447 return applicationContext.getBean( aClass, objects );
451 public <T> ObjectProvider<T> getBeanProvider( Class<T> aClass )
457 public <T> ObjectProvider<T> getBeanProvider( ResolvableType resolvableType )
463 public Object getBean( String s )
464 throws BeansException
466 return applicationContext.getBean( s );
470 public <T> T getBean( String s, Class<T> tClass )
471 throws BeansException
473 return applicationContext.getBean( s, tClass );
477 public <T> T getBean( Class<T> tClass )
478 throws BeansException
480 return applicationContext.getBean( tClass );
484 public Object getBean( String s, Object... objects )
485 throws BeansException
487 return applicationContext.getBean( s, objects );
491 public boolean containsBean( String s )
493 return applicationContext.containsBean( s );
497 public boolean isSingleton( String s )
498 throws NoSuchBeanDefinitionException
500 return applicationContext.isSingleton( s );
504 public boolean isPrototype( String s )
505 throws NoSuchBeanDefinitionException
507 return applicationContext.isPrototype( s );
511 public boolean isTypeMatch( String s, Class<?> aClass )
512 throws NoSuchBeanDefinitionException
514 return applicationContext.isTypeMatch( s, aClass );
518 public Class<?> getType( String s )
519 throws NoSuchBeanDefinitionException
521 return applicationContext.getType( s );
525 public Class<?> getType( String s, boolean b ) throws NoSuchBeanDefinitionException
531 public String[] getAliases( String s )
533 return applicationContext.getAliases( s );
537 public String getMessage( String s, Object[] objects, String s2, Locale locale )
539 return applicationContext.getMessage( s, objects, s2, locale );
543 public String getMessage( String s, Object[] objects, Locale locale )
544 throws NoSuchMessageException
546 return applicationContext.getMessage( s, objects, locale );
550 public String getMessage( MessageSourceResolvable messageSourceResolvable, Locale locale )
551 throws NoSuchMessageException
553 return applicationContext.getMessage( messageSourceResolvable, locale );
557 public Resource[] getResources( String s )
560 return applicationContext.getResources( s );
564 public void publishEvent( Object o )
570 public String[] getBeanNamesForType( ResolvableType resolvableType )
572 return new String[0];
576 public String[] getBeanNamesForType( ResolvableType resolvableType, boolean b, boolean b1 )
578 return new String[0];
582 public boolean isTypeMatch( String s, ResolvableType resolvableType )
583 throws NoSuchBeanDefinitionException
589 public Resource getResource( String s )
591 return applicationContext.getResource( s );
595 public ClassLoader getClassLoader()
597 return applicationContext.getClassLoader();
601 protected Servlet findServlet( String name )
604 return unauthenticatedRepositoryServlet;
608 protected String getSpringConfigLocation()
610 return "classpath*:/META-INF/spring-context.xml,classpath*:spring-context.xml";
614 protected static WebClient newClient()
616 final WebClient webClient = new WebClient();
617 webClient.getOptions().setJavaScriptEnabled( false );
618 webClient.getOptions().setCssEnabled( false );
619 webClient.getOptions().setAppletEnabled( false );
620 webClient.getOptions().setThrowExceptionOnFailingStatusCode( false );
621 webClient.setAjaxController( new NicelyResynchronizingAjaxController() );
626 protected WebResponse getWebResponse( String path )
629 return getWebResponse( new GetMethodWebRequest( "http://localhost" + path ) );//, false );
632 protected WebResponse getWebResponse( WebRequest webRequest ) //, boolean followRedirect )
636 MockHttpServletRequest request = new MockHttpServletRequest();
637 request.setRequestURI( webRequest.getUrl().getPath() );
638 request.addHeader( "User-Agent", "Apache Archiva unit test" );
640 request.setMethod( webRequest.getHttpMethod().name() );
642 if ( webRequest.getHttpMethod() == HttpMethod.PUT )
644 PutMethodWebRequest putRequest = PutMethodWebRequest.class.cast( webRequest );
645 request.setContentType( putRequest.contentType );
646 request.setContent( IOUtils.toByteArray( putRequest.inputStream ) );
649 if ( webRequest instanceof MkColMethodWebRequest )
651 request.setMethod( "MKCOL" );
654 final MockHttpServletResponse response = execute( request );
656 if ( response.getStatus() == HttpServletResponse.SC_MOVED_PERMANENTLY
657 || response.getStatus() == HttpServletResponse.SC_MOVED_TEMPORARILY )
659 String location = response.getHeader( "Location" );
660 log.debug( "follow redirect to {}", location );
661 return getWebResponse( new GetMethodWebRequest( location ) );
664 return new WebResponse( null, null, 1 )
667 public String getContentAsString()
671 return response.getContentAsString();
673 catch ( UnsupportedEncodingException e )
675 throw new RuntimeException( e.getMessage(), e );
680 public int getStatusCode()
682 return response.getStatus();
686 public String getResponseHeaderValue( String headerName )
688 return response.getHeader( headerName );
693 protected MockHttpServletResponse execute( HttpServletRequest request )
696 MockHttpServletResponse response = new MockHttpServletResponse()
699 public String getContentAsString()
700 throws UnsupportedEncodingException
702 String errorMessage = getErrorMessage();
703 return ( errorMessage != null ) ? errorMessage : super.getContentAsString();
706 this.unauthenticatedRepositoryServlet.service( request, response );
710 public static class GetMethodWebRequest
715 public GetMethodWebRequest( String url )
718 super( new URL( url ) );
724 public static class PutMethodWebRequest
729 InputStream inputStream;
733 public PutMethodWebRequest( String url, InputStream inputStream, String contentType )
736 super( new URL( url ), HttpMethod.PUT );
738 this.inputStream = inputStream;
739 this.contentType = contentType;
745 public static class ServletUnitClient
748 AbstractRepositoryServletTestCase abstractRepositoryServletTestCase;
750 public ServletUnitClient( AbstractRepositoryServletTestCase abstractRepositoryServletTestCase )
752 this.abstractRepositoryServletTestCase = abstractRepositoryServletTestCase;
755 public WebResponse getResponse( WebRequest request )
758 return getResponse( request, false );
761 public WebResponse getResponse( WebRequest request, boolean followRedirect )
764 // alwasy following redirect as it's normal
765 return abstractRepositoryServletTestCase.getWebResponse( request );//, followRedirect );
768 public WebResponse getResource( WebRequest request )
771 return getResponse( request );
775 public ServletUnitClient getServletUnitClient()
777 return new ServletUnitClient( this );
782 public void tearDown()
785 repositoryRegistry.getRepositories().stream().forEach(r -> r.close());
787 if ( Files.exists(repoRootInternal) )
789 org.apache.archiva.common.utils.FileUtils.deleteQuietly( repoRootInternal );
792 if ( Files.exists(repoRootLegacy) )
794 org.apache.archiva.common.utils.FileUtils.deleteQuietly( repoRootLegacy );
797 String appserverBase = System.getProperty( "appserver.base" );
798 if ( StringUtils.isNotEmpty( appserverBase ) )
800 org.apache.archiva.common.utils.FileUtils.deleteQuietly( Paths.get( appserverBase ) );
806 protected void assertFileContents( String expectedContents, Path repoRoot, String subpath )
809 String path = Paths.get(subpath).isAbsolute() ? subpath.substring( 1,subpath.length() ) : subpath;
810 Path actualFile = repoRoot.resolve( path );
811 assertTrue( "File <" + actualFile.toAbsolutePath() + "> should exist.", Files.exists(actualFile) );
812 assertTrue( "File <" + actualFile.toAbsolutePath() + "> should be a file (not a dir/link/device/etc).",
813 Files.isRegularFile( actualFile ) );
815 String actualContents = org.apache.archiva.common.utils.FileUtils.readFileToString( actualFile, Charset.defaultCharset() );
816 assertEquals( "File Contents of <" + actualFile.toAbsolutePath() + ">", expectedContents, actualContents );
819 protected void assertRepositoryValid( RepositoryServlet servlet, String repoId )
822 ManagedRepository repository = servlet.getRepository( repoId );
823 assertNotNull( "Archiva Managed Repository id:<" + repoId + "> should exist.", repository );
824 Path repoRoot = Paths.get( repository.getLocation() );
825 assertTrue( "Archiva Managed Repository id:<" + repoId + "> should have a valid location on disk.",
826 Files.exists(repoRoot) && Files.isDirectory(repoRoot) );
829 protected void assertResponseOK( WebResponse response )
831 assertNotNull( "Should have recieved a response", response );
832 Assert.assertEquals( "Should have been an OK response code", //
833 HttpServletResponse.SC_OK, //
834 response.getStatusCode() );
837 protected void assertResponseOK( WebResponse response, String path )
839 assertNotNull( "Should have recieved a response", response );
840 Assert.assertEquals( "Should have been an OK response code for path: " + path, HttpServletResponse.SC_OK,
841 response.getStatusCode() );
844 protected void assertResponseNotFound( WebResponse response )
846 assertNotNull( "Should have recieved a response", response );
847 Assert.assertEquals( "Should have been an 404/Not Found response code.", HttpServletResponse.SC_NOT_FOUND,
848 response.getStatusCode() );
851 protected void assertResponseInternalServerError( WebResponse response )
853 assertNotNull( "Should have recieved a response", response );
854 Assert.assertEquals( "Should have been an 500/Internal Server Error response code.",
855 HttpServletResponse.SC_INTERNAL_SERVER_ERROR, response.getStatusCode() );
858 protected void assertResponseConflictError( WebResponse response )
860 assertNotNull( "Should have received a response", response );
861 Assert.assertEquals( "Should have been a 409/Conflict response code.", HttpServletResponse.SC_CONFLICT,
862 response.getStatusCode() );
865 protected ManagedRepositoryConfiguration createManagedRepository( String id, String name, Path location,
866 boolean blockRedeployments )
868 ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
870 repo.setName( name );
871 repo.setLocation( location.toAbsolutePath().toString() );
872 repo.setBlockRedeployments( blockRedeployments );
873 repo.setType( "MAVEN" );
874 repo.setIndexDir(location.resolve( ".indexer" ).toAbsolutePath().toString());
875 repo.setPackedIndexDir( location.resolve( ".index" ).toAbsolutePath( ).toString( ) );
880 protected ManagedRepositoryConfiguration createManagedRepository( String id, String name, Path location,
881 String layout, boolean blockRedeployments )
883 ManagedRepositoryConfiguration repo = createManagedRepository( id, name, location, blockRedeployments );
884 repo.setLayout( layout );
888 protected RemoteRepositoryConfiguration createRemoteRepository( String id, String name, String url )
890 RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration();
892 repo.setName( name );
897 protected void saveConfiguration( ArchivaConfiguration archivaConfiguration )
900 repositoryRegistry.setArchivaConfiguration(archivaConfiguration);
901 // repositoryRegistry.reload();
902 archivaConfiguration.save( archivaConfiguration.getConfiguration() );
907 protected void setupCleanRepo( Path repoRootDir )
910 if (repoRootDir!=null)
912 org.apache.archiva.common.utils.FileUtils.deleteDirectory( repoRootDir );
913 if ( !Files.exists( repoRootDir ) )
915 Files.createDirectories( repoRootDir );
920 protected void assertManagedFileNotExists( Path repoRootInternal, String resourcePath )
922 Path repoFile = repoRootInternal.resolve( resourcePath );
923 assertFalse( "Managed Repository File <" + repoFile.toAbsolutePath() + "> should not exist.",
924 Files.exists(repoFile) );
927 protected void setupCleanInternalRepo()
930 setupCleanRepo( repoRootInternal );
933 protected Path populateRepo( Path repoRootManaged, String path, String contents )
936 Path destFile = repoRootManaged.resolve( path );
937 Files.createDirectories( destFile.getParent() );
938 org.apache.archiva.common.utils.FileUtils.writeStringToFile( destFile, Charset.defaultCharset(), contents );