Skip to content

Commit

Permalink
Ardesco#90 added synchronized keywords to parts that should be synchr…
Browse files Browse the repository at this point in the history
…onized
  • Loading branch information
ManuelB committed Aug 12, 2019
1 parent c033750 commit 833c0ee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public class SeleniumServerMojo extends AbstractMojo {
private static final Logger LOG = Logger.getLogger(SeleniumServerMojo.class);

@Override
public synchronized void execute() throws MojoExecutionException, MojoFailureException {
public void execute() throws MojoExecutionException, MojoFailureException {
BasicConfigurator.configure(new MavenLoggerLog4jBridge(getLog()));
LOG.info(" ");
LOG.info("--------------------------------------------------------");
Expand Down
32 changes: 17 additions & 15 deletions src/main/java/com/lazerycode/selenium/download/DownloadHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public DownloadHandler(File rootStandaloneServerDirectory, File downloadedZipFil
fileDownloader.setConnectTimeout(fileDownloadConnectTimeout);
}

private boolean checkFileHash(File fileToCheck, String hash, HashType hashType) throws IOException, MojoExecutionException {
private synchronized boolean checkFileHash(File fileToCheck, String hash, HashType hashType) throws IOException, MojoExecutionException {

FileHashChecker fileHashChecker = new FileHashChecker(fileToCheck);
fileHashChecker.setExpectedHash(hash, hashType);

Expand All @@ -59,30 +60,31 @@ private boolean checkFileHash(File fileToCheck, String hash, HashType hashType)
* @throws URISyntaxException Invalid URI
*/
protected File downloadFile(DriverDetails driverDetails, boolean shouldWeCheckFileHash) throws MojoExecutionException, IOException, URISyntaxException {

URL remoteFileLocation = driverDetails.fileLocation;

final String filename = FilenameUtils.getName(remoteFileLocation.getFile());
for (int retryAttempts = 1; retryAttempts <= this.fileDownloadRetryAttempts; retryAttempts++) {
File downloadedFile = fileDownloader.attemptToDownload(remoteFileLocation);
if (null != downloadedFile) {
if (!shouldWeCheckFileHash || checkFileHash(downloadedFile, driverDetails.hash, driverDetails.hashType)) {
LOG.info("Archive file '" + downloadedFile.getName() + "' is valid : true");
return downloadedFile;
} else {
LOG.info("Archive file '" + downloadedFile.getName() + "' is valid : false");
synchronized (filename.intern()) {
for (int retryAttempts = 1; retryAttempts <= this.fileDownloadRetryAttempts; retryAttempts++) {
File downloadedFile = fileDownloader.attemptToDownload(remoteFileLocation);
if (null != downloadedFile) {
if (!shouldWeCheckFileHash || checkFileHash(downloadedFile, driverDetails.hash, driverDetails.hashType)) {
LOG.info("Archive file '" + downloadedFile.getName() + "' is valid : true");
return downloadedFile;
} else {
LOG.info("Archive file '" + downloadedFile.getName() + "' is valid : false");
}
}
LOG.info("Problem downloading '" + filename + "'... ");
if (retryAttempts < this.fileDownloadRetryAttempts) {
LOG.info("Retry attempt " + (retryAttempts) + " for '" + filename + "'");
}
}
LOG.info("Problem downloading '" + filename + "'... ");
if (retryAttempts < this.fileDownloadRetryAttempts) {
LOG.info("Retry attempt " + (retryAttempts) + " for '" + filename + "'");
}
}

throw new MojoExecutionException("Unable to successfully download '" + filename + "'!");
}

public DriverMap ensureStandaloneExecutableFilesExist() throws MojoFailureException, MojoExecutionException, IOException, URISyntaxException {
public synchronized DriverMap ensureStandaloneExecutableFilesExist() throws MojoFailureException, MojoExecutionException, IOException, URISyntaxException {
LOG.info("Archives will be downloaded to '" + this.downloadedZipFileDirectory.getAbsolutePath() + "'");
LOG.info("Standalone executable files will be extracted to '" + this.rootStandaloneServerDirectory + "'");
LOG.info(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public FileExtractor(boolean overwriteFilesThatExist) {
* @throws IllegalArgumentException Unsupported archive
* @throws MojoFailureException Error running plugin
*/
public String extractFileFromArchive(File downloadedCompressedFile, String extractedToFilePath, BinaryType possibleFilenames) throws IOException, IllegalArgumentException, MojoFailureException {
public synchronized String extractFileFromArchive(File downloadedCompressedFile, String extractedToFilePath, BinaryType possibleFilenames) throws IOException, IllegalArgumentException, MojoFailureException {
DownloadableFileType fileType = DownloadableFileType.valueOf(FilenameUtils.getExtension(downloadedCompressedFile.getName()).toUpperCase());
LOG.debug("Determined archive type: " + fileType);
LOG.debug("Overwrite files that exist: " + overwriteFilesThatExist);
Expand Down Expand Up @@ -80,8 +80,7 @@ public String extractFileFromArchive(File downloadedCompressedFile, String extra
* @return boolean
* @throws IOException IOException
*/

String unzipFile(File downloadedCompressedFile, String extractedToFilePath, BinaryType possibleFilenames) throws IOException, ExpectedFileNotFoundException {
synchronized String unzipFile(File downloadedCompressedFile, String extractedToFilePath, BinaryType possibleFilenames) throws IOException, ExpectedFileNotFoundException {
LOG.debug("Attempting to extract binary from .zip file...");
ArrayList<String> filenamesWeAreSearchingFor = new ArrayList<String>(possibleFilenames.getBinaryFilenames());
ZipFile zip = new ZipFile(downloadedCompressedFile);
Expand Down Expand Up @@ -118,7 +117,6 @@ String unzipFile(File downloadedCompressedFile, String extractedToFilePath, Bina
* @return boolean
* @throws IOException MojoFailureException
*/

private String untarFile(InputStream compressedFileInputStream, String extractedToFilePath, BinaryType possibleFilenames) throws IOException, ExpectedFileNotFoundException {
LOG.debug("Attempting to extract binary from a .tar file...");
ArchiveEntry currentFile;
Expand Down

0 comments on commit 833c0ee

Please sign in to comment.