diff --git a/.travis/settings.xml b/.travis/settings.xml index 905ce6b..1167e94 100644 --- a/.travis/settings.xml +++ b/.travis/settings.xml @@ -1,66 +1,22 @@ - - - - - - - - - ossrh - ${env.SONATYPE_USERNAME} - ${env.SONATYPE_PASSWORD} - - - - - - - repo-list - - - am - Apache Maven2 Central Repository - https://repo.maven.apache.org/maven2 - default - - false - - - never - - - - ossrh - OSS Sonatype Repository - - true - - - never - - https://oss.sonatype.org/content/repositories/releases/ - - - jenkins - Jenkins Repository - - true - - - never - - http://repo.jenkins-ci.org/releases/ - - - - ${env.GPG_EXECUTABLE} - ${env.GPG_PASSPHRASE} - - - - - repo-list - - + + + + ossrh + ${env.SONATYPE_USERNAME} + ${env.SONATYPE_PASSWORD} + + + + + ossrh + + true + + + ${env.GPG_EXECUTABLE} + ${env.GPG_PASSPHRASE} + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index f29be4b..d85c62d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,142 +1,141 @@ - - 4.0.0 - - ru.sbtqa.tag - video-recorder - 1.0.2-SNAPSHOT - jar - - video-recorder - video-recorder description - http://github.com/sbtqa/video-recorder - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - - - - - Viktor Sidochenko - viktor.sidochenko@gmail.com - sbtqa - http://github.com/sbtqa - - - - scm:git:git://github.com/sbtqa/video-recorder - scm:git:ssh://github.com:sbtqa/video-recorder.git - https://github.com/sbtqa/video-recorder/tree/master - - - - UTF-8 - 1.7 - 1.7 - - - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - - - - org.monte - screen-recorder - 0.7.7 - - - org.slf4j - slf4j-api - 1.7.12 - - - junit - junit - 4.9 - test - - - org.mockito - mockito-core - 1.9.5 - test - - - ru.sbtqa - monte-media - 1.0.0 - jar - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.3 - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.3 - true - - ossrh - https://oss.sonatype.org/ - true - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - - sign-artifacts - verify - - sign - - - - - - - - + + 4.0.0 + ru.sbtqa.tag + video-recorder + 1.0.2-SNAPSHOT + jar + video-recorder + video-recorder description + http://github.com/sbtqa/video-recorder + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + + Viktor Sidochenko + viktor.sidochenko@gmail.com + sbtqa + http://github.com/sbtqa + + + + scm:git:git://github.com/sbtqa/video-recorder + scm:git:ssh://github.com:sbtqa/video-recorder.git + https://github.com/sbtqa/video-recorder/tree/master + + + UTF-8 + 1.7 + 1.7 + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + jenkins + Jenkins Repository (releases) + http://repo.jenkins-ci.org/releases/ + + + + + org.monte + screen-recorder + 0.7.7 + + + org.slf4j + slf4j-api + 1.7.12 + + + junit + junit + 4.9 + test + + + org.mockito + mockito-core + 1.9.5 + test + + + ru.sbtqa + monte-media + 1.0.0 + jar + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.3 + true + + ossrh + https://oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + + + + \ No newline at end of file diff --git a/src/main/java/ru/sbtqa/tag/videorecorder/VideoRecorderImpl.java b/src/main/java/ru/sbtqa/tag/videorecorder/VideoRecorderImpl.java index 7e6f25f..b7e9fd2 100644 --- a/src/main/java/ru/sbtqa/tag/videorecorder/VideoRecorderImpl.java +++ b/src/main/java/ru/sbtqa/tag/videorecorder/VideoRecorderImpl.java @@ -5,60 +5,65 @@ import java.awt.Rectangle; import java.io.File; import java.io.IOException; - +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import ru.sbtqa.monte.media.Format; import ru.sbtqa.monte.media.Registry; public class VideoRecorderImpl extends ru.sbtqa.monte.screenrecorder.ScreenRecorder implements VideoRecorder { - - private final String TEMP_FILENAME_WITHOUT_EXTENSION = "currentRecording_" + System.currentTimeMillis(); - private final File TEMP_MOVIE_FOLDER; - + + private static final Logger LOG = LoggerFactory.getLogger(VideoRecorderImpl.class); + + private final String tempFilenameWithoutExtension = "currentRecording_" + System.currentTimeMillis(); + private final File tempMovieFolder; + private String currentTempExtension; - + public VideoRecorderImpl(GraphicsConfiguration cfg, Rectangle captureArea, Format fileFormat, - Format screenFormat, Format mouseFormat, Format audioFormat, File movieFolder) - throws IOException, AWTException { + Format screenFormat, Format mouseFormat, Format audioFormat, File movieFolder) + throws IOException, AWTException { super(cfg, captureArea, fileFormat, screenFormat, mouseFormat, audioFormat, movieFolder); - TEMP_MOVIE_FOLDER = movieFolder; + tempMovieFolder = movieFolder; } - + @Override protected File createMovieFile(Format fileFormat) throws IOException { this.currentTempExtension = Registry.getInstance().getExtension(fileFormat); String tempFile = getTempFileName(); - + File fileToWriteMovie = new File(tempFile); if (fileToWriteMovie.exists()) { - fileToWriteMovie.delete(); + if (!fileToWriteMovie.delete()) { + LOG.error("Failed to remove temporary file {}", fileToWriteMovie.getAbsolutePath()); + } } - + return fileToWriteMovie; } - + private String getTempFileName() { - return TEMP_MOVIE_FOLDER.getPath() + File.separator - + TEMP_FILENAME_WITHOUT_EXTENSION + "." + this.currentTempExtension; + return tempMovieFolder.getPath() + File.separator + + tempFilenameWithoutExtension + "." + this.currentTempExtension; } - + @Override public String saveAs(String path, String filename) throws IOException { this.stop(); - + File tempFile = this.getCreatedMovieFiles().get(0); - + File destFile = getDestinationFile(path, filename); - tempFile.renameTo(destFile); + if (!tempFile.renameTo(destFile)) { + LOG.error("Failed to rename file {}", path + filename); + } return destFile.getAbsolutePath(); } - + private File getDestinationFile(String path, String filename) { String destFolderSuffix = ""; - - File file = new File(path + destFolderSuffix + File.separator - + filename + "." + this.currentTempExtension); - - return file; + + return new File(path + destFolderSuffix + File.separator + + filename + "." + this.currentTempExtension); } - -} \ No newline at end of file + +} diff --git a/src/main/java/ru/sbtqa/tag/videorecorder/VideoRecorderModule.java b/src/main/java/ru/sbtqa/tag/videorecorder/VideoRecorderModule.java index c7f07f0..e66ee85 100644 --- a/src/main/java/ru/sbtqa/tag/videorecorder/VideoRecorderModule.java +++ b/src/main/java/ru/sbtqa/tag/videorecorder/VideoRecorderModule.java @@ -1,36 +1,34 @@ package ru.sbtqa.tag.videorecorder; +import java.awt.AWTException; +import java.awt.Dimension; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsEnvironment; import java.io.File; import java.io.IOException; - import ru.sbtqa.monte.media.Format; import ru.sbtqa.monte.media.FormatKeys; -import ru.sbtqa.monte.media.VideoFormatKeys; -import ru.sbtqa.monte.media.math.Rational; - import static ru.sbtqa.monte.media.FormatKeys.EncodingKey; import static ru.sbtqa.monte.media.FormatKeys.FrameRateKey; import static ru.sbtqa.monte.media.FormatKeys.KeyFrameIntervalKey; +import ru.sbtqa.monte.media.FormatKeys.MediaType; import static ru.sbtqa.monte.media.FormatKeys.MediaTypeKey; import static ru.sbtqa.monte.media.FormatKeys.MimeTypeKey; - -import java.awt.AWTException; -import java.awt.Dimension; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsEnvironment; -import ru.sbtqa.monte.media.FormatKeys.MediaType; +import ru.sbtqa.monte.media.VideoFormatKeys; import static ru.sbtqa.monte.media.VideoFormatKeys.CompressorNameKey; import static ru.sbtqa.monte.media.VideoFormatKeys.DepthKey; import static ru.sbtqa.monte.media.VideoFormatKeys.HeightKey; import static ru.sbtqa.monte.media.VideoFormatKeys.QualityKey; import static ru.sbtqa.monte.media.VideoFormatKeys.WidthKey; +import ru.sbtqa.monte.media.math.Rational; +import ru.sbtqa.tag.videorecorder.exceptions.VideoRecorderRuntimeException; public class VideoRecorderModule { private static final int MAX_RECORDING_TIME_SECS = Integer.MAX_VALUE; - private static int FRAME_RATE_PER_SEC = 2; - private static int BIT_DEPTH = 16; - private static float QUALITY_RATIO = 0.7f; + private static int frameRatePerSec = 2; + private static int bitDepth = 16; + private static float qualityRatio = 0.7f; private final String videoFolderPath; public VideoRecorderModule(String videoFolderPath) { @@ -38,15 +36,15 @@ public VideoRecorderModule(String videoFolderPath) { } public static void setFrameRatePerSec(int rate) { - FRAME_RATE_PER_SEC = rate; + frameRatePerSec = rate; } - public static void setBitDepth(int bitDepth) { - BIT_DEPTH = bitDepth; + public static void setBitDepth(int depth) { + bitDepth = depth; } - public static void setQualityRatio(float qualityRatio) { - QUALITY_RATIO = qualityRatio; + public static void setQualityRatio(float ratio) { + qualityRatio = ratio; } public VideoRecorder provideScreenRecorder() { @@ -60,9 +58,9 @@ public VideoRecorder provideScreenRecorder() { String videoFormatName = VideoFormatKeys.ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE; String compressorName = VideoFormatKeys.COMPRESSOR_NAME_AVI_TECHSMITH_SCREEN_CAPTURE; Dimension outputDimension = gc.getBounds().getSize(); - int bitDepth = BIT_DEPTH; - float quality = QUALITY_RATIO; - int screenRate = FRAME_RATE_PER_SEC; + int depth = bitDepth; + float quality = qualityRatio; + int screenRate = frameRatePerSec; long maxRecordingTime = MAX_RECORDING_TIME_SECS; VideoRecorderImpl sr; @@ -70,15 +68,13 @@ public VideoRecorder provideScreenRecorder() { sr = new VideoRecorderImpl(gc, gc.getBounds(), getFileFormat(mimeType), getOutputFormatForScreenCapture(videoFormatName, compressorName, outputDimension, - bitDepth, quality, screenRate), + depth, quality, screenRate), getMouseFormat(), getAudioFormat(), movieFolder); sr.setMaxRecordingTime(maxRecordingTime); - } catch (IOException e) { - throw new RuntimeException(e); - } catch (AWTException e) { - throw new RuntimeException(e); + } catch (IOException | AWTException e) { + throw new VideoRecorderRuntimeException("Failed to create video recorder object", e); } return sr; diff --git a/src/main/java/ru/sbtqa/tag/videorecorder/exceptions/VideoRecorderRuntimeException.java b/src/main/java/ru/sbtqa/tag/videorecorder/exceptions/VideoRecorderRuntimeException.java new file mode 100644 index 0000000..13ce91e --- /dev/null +++ b/src/main/java/ru/sbtqa/tag/videorecorder/exceptions/VideoRecorderRuntimeException.java @@ -0,0 +1,30 @@ +package ru.sbtqa.tag.videorecorder.exceptions; + +public class VideoRecorderRuntimeException extends RuntimeException { + + /** + * + * @param e TODO + */ + public VideoRecorderRuntimeException(Throwable e) { + super(e); + } + + /** + * + * @param message a {@link java.lang.String} object. + * @param e a {@link java.lang.Throwable} object. + */ + public VideoRecorderRuntimeException(String message, Throwable e) { + super(message, e); + } + + /** + * + * @param message a {@link java.lang.String} object. + */ + public VideoRecorderRuntimeException(String message) { + super(message); + } + +}