/src/main/java/com/atlassian/bamboo/plugin/dotnet/visualstudio/RunnerExtractor.java
Java | 95 lines | 67 code | 13 blank | 15 comment | 2 complexity | 3f20c925b5ad34cb9b14a9e9d96422ab MD5 | raw file
Possible License(s): BSD-3-Clause
- package com.atlassian.bamboo.plugin.dotnet.visualstudio;
-
- import com.atlassian.bamboo.build.fileserver.BuildDirectoryManager;
- import com.atlassian.spring.container.LazyComponentReference;
- import com.atlassian.util.concurrent.LazyReference;
- import net.jcip.annotations.ThreadSafe;
- import org.apache.commons.io.IOUtils;
- import org.apache.log4j.Logger;
- import org.jetbrains.annotations.NotNull;
-
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
-
- /**
- * Extracts various wrapper scripts from the plugin classpath in a thread safe way
- */
- @ThreadSafe
- public class RunnerExtractor
- {
- @SuppressWarnings("unused")
- private static final Logger log = Logger.getLogger(RunnerExtractor.class);
- // ------------------------------------------------------------------------------------------------------- Constants
-
- private static final LazyComponentReference<BuildDirectoryManager> BUILD_DIRECTORY_MANAGER_REFERENCE = new LazyComponentReference<BuildDirectoryManager>("buildDirectoryManager");
-
- private static final LazyReference<String> DOTNET_RUNNERS_HOME = new LazyReference<String>()
- {
- @Override
- protected String create() throws Exception
- {
- File file = new File(BUILD_DIRECTORY_MANAGER_REFERENCE.get().getApplicationHome(), "DotNetSupport");
- file.mkdirs();
- return file.getAbsolutePath();
- }
- };
-
- private static final LazyReference<String> DEVENV_RUNNER_REFERENCE = new LazyReference<String>()
- {
- @Override
- protected String create() throws Exception
- {
- return extract("/com/atlassian/bamboo/plugin/dotnet/visualstudio/devenvrunner.bat", "devenvrunner.bat");
- }
- };
-
- // ------------------------------------------------------------------------------------------------- Type Properties
- // ---------------------------------------------------------------------------------------------------- Dependencies
- // ---------------------------------------------------------------------------------------------------- Constructors
-
- private RunnerExtractor()
- {
- }
-
- // ----------------------------------------------------------------------------------------------- Interface Methods
- // -------------------------------------------------------------------------------------------------- Action Methods
- // -------------------------------------------------------------------------------------------------- Public Methods
-
- /**
- * Get the path to Bamboo's external devenv wrapper batch file
- * @return path
- */
- public static String getDevenvRunnerPath()
- {
- return DEVENV_RUNNER_REFERENCE.get();
- }
-
- // -------------------------------------------------------------------------------------- Basic Accessors / Mutators
-
- private static String extract(@NotNull String resourceName, String filename) throws IOException
- {
- InputStream inputStream = null;
- OutputStream outputStream = null;
- try
- {
- inputStream = RunnerExtractor.class.getResourceAsStream(resourceName);
- if (inputStream == null)
- {
- throw new IllegalStateException("Could not find '" + resourceName + "' on classpath");
- }
-
- File file = new File(DOTNET_RUNNERS_HOME.get(), filename);
- outputStream = new FileOutputStream(file);
- IOUtils.copy(inputStream, outputStream);
- return file.getAbsolutePath();
- }
- finally
- {
- IOUtils.closeQuietly(inputStream);
- IOUtils.closeQuietly(outputStream);
- }
- }
- }