private void initializeRetireJsRepo ( Settings settings , URL repoUrl ) throws UpdateException { try { final File dataDir = settings . getDataDirectory ( ) ; final File tmpDir = settings . getTempDirectory ( ) ; boolean useProxy = false ; if ( null != settings . getString ( Settings . KEYS . PROXY_SERVER ) ) { useProxy = true ; LOGGER . debug ( "Using proxy" ) ; } LOGGER . debug ( "RetireJS Repo URL: {}" , repoUrl . toExternalForm ( ) ) ; final URLConnectionFactory factory = new URLConnectionFactory ( settings ) ; final HttpURLConnection conn = factory . createHttpURLConnection ( repoUrl , useProxy ) ; final String filename = repoUrl . getFile ( ) . substring ( repoUrl . getFile ( ) . lastIndexOf ( "/" ) + 1 , repoUrl . getFile ( ) . length ( ) ) ; if ( conn . getResponseCode ( ) == HttpURLConnection . HTTP_OK ) { final File tmpFile = new File ( tmpDir , filename ) ; final File repoFile = new File ( dataDir , filename ) ; try ( InputStream inputStream = conn . getInputStream ( ) ; FileOutputStream outputStream = new FileOutputStream ( tmpFile ) ) { IOUtils . copy ( inputStream , outputStream ) ; } //using move fails if target and destination are on different disks which does happen (see #1394 and #1404) Files . copy ( tmpFile . toPath ( ) , repoFile . toPath ( ) , StandardCopyOption . REPLACE_EXISTING ) ; if ( ! tmpFile . delete ( ) ) { tmpFile . deleteOnExit ( ) ; } } } catch ( IOException e ) { throw new UpdateException ( "Failed to initialize the RetireJS repo" , e ) ; } }
Initializes the local RetireJS repository