development configuration overriding env
This commit is contained in:
parent
69434775ca
commit
b852d1dc6b
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
/target/
|
/target/
|
||||||
|
/src/main/resources/development.properties
|
||||||
|
14
README.md
14
README.md
@ -1,3 +1,15 @@
|
|||||||
# mavor
|
# mavor
|
||||||
|
|
||||||
download a maven artifact and all its dependencies as zip
|
download a maven artifact and all its dependencies as zip
|
||||||
|
|
||||||
|
## Environment Variables
|
||||||
|
all environemnt variables are required
|
||||||
|
* `MAVOR_MAVEN_EXECUTABLE`: path to the maven executable, e.g. `/usr/bin/mvn`
|
||||||
|
* `MAVOR_TEMP_DIR`: path to a readable and writeable directory to temporarily store files, e.g. `/home/damage/Temp`
|
||||||
|
|
||||||
|
## Development
|
||||||
|
To avoid setting environment variables during devleopment, create `src/main/resources/development.properties` with content like:
|
||||||
|
```
|
||||||
|
MAVOR_MAVEN_EXECUTABLE=/usr/bin/mvn
|
||||||
|
MAVOR_TEMP_DIR=/home/damage/Temp
|
||||||
|
```
|
@ -1,14 +1,36 @@
|
|||||||
package de.devloop.mavor;
|
package de.devloop.mavor;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
public class Configuration {
|
public class Configuration {
|
||||||
|
|
||||||
|
private static final String DEVELOPMENT_PROPERTIES = "development.properties";
|
||||||
|
|
||||||
private static final String ENV_MAVEN_EXECUTABLE = "MAVOR_MAVEN_EXECUTABLE";
|
private static final String ENV_MAVEN_EXECUTABLE = "MAVOR_MAVEN_EXECUTABLE";
|
||||||
private static final String ENV_TEMP_DIR = "MAVOR_TEMP_DIR";
|
private static final String ENV_TEMP_DIR = "MAVOR_TEMP_DIR";
|
||||||
|
|
||||||
private final String mavenExecutable = Objects.requireNonNull(System.getProperty(ENV_MAVEN_EXECUTABLE));
|
private String mavenExecutable;
|
||||||
private final String tempDir = Objects.requireNonNull(System.getProperty(ENV_TEMP_DIR));
|
private String tempDir;
|
||||||
|
|
||||||
|
public Configuration() throws IOException {
|
||||||
|
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||||
|
InputStream developmentPropertiesStream = classLoader.getResourceAsStream(DEVELOPMENT_PROPERTIES);
|
||||||
|
if (Objects.nonNull(developmentPropertiesStream)) {
|
||||||
|
Properties developmentProperties = new Properties();
|
||||||
|
developmentProperties.load(developmentPropertiesStream);
|
||||||
|
initByProperties(developmentProperties);
|
||||||
|
} else {
|
||||||
|
initByProperties(System.getProperties());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initByProperties(Properties properties) {
|
||||||
|
mavenExecutable = properties.getProperty(ENV_MAVEN_EXECUTABLE);
|
||||||
|
tempDir = properties.getProperty(ENV_TEMP_DIR);
|
||||||
|
}
|
||||||
|
|
||||||
public String getMavenExecutable() {
|
public String getMavenExecutable() {
|
||||||
return mavenExecutable;
|
return mavenExecutable;
|
||||||
@ -17,4 +39,4 @@ public class Configuration {
|
|||||||
public String getTempDir() {
|
public String getTempDir() {
|
||||||
return tempDir;
|
return tempDir;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -35,7 +35,16 @@ public class DownloadJars extends AuthenticatedServlet {
|
|||||||
private static final String PARAMETER_POM = "pom";
|
private static final String PARAMETER_POM = "pom";
|
||||||
private static final String PARAMETER_TYPE = "type";
|
private static final String PARAMETER_TYPE = "type";
|
||||||
|
|
||||||
private final Configuration configuration = new Configuration();
|
private Configuration configuration;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() throws ServletException {
|
||||||
|
try {
|
||||||
|
configuration = new Configuration();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ServletException("Configuration Error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doAuthenticatedPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doAuthenticatedPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
@ -93,7 +102,7 @@ public class DownloadJars extends AuthenticatedServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ExecutionResult executeMaven(File tempDirJars) throws IOException, InterruptedException {
|
private ExecutionResult executeMaven(File tempDirJars) throws IOException, InterruptedException {
|
||||||
String mavenCmd = String.format("%s dependency:copy-dependencies -DoutputDirectory=\"%s\"", configuration.getMavenExecutable(), tempDirJars.getCanonicalPath());
|
String mavenCmd = String.format("%s dependency:copy-dependencies -DoutputDirectory=%s", configuration.getMavenExecutable(), tempDirJars.getCanonicalPath());
|
||||||
Process mvnProcess = Runtime.getRuntime().exec(mavenCmd, null, tempDirJars.getCanonicalFile());
|
Process mvnProcess = Runtime.getRuntime().exec(mavenCmd, null, tempDirJars.getCanonicalFile());
|
||||||
String stdout = new String(mvnProcess.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
String stdout = new String(mvnProcess.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||||
String stderr = new String(mvnProcess.getErrorStream().readAllBytes(), StandardCharsets.UTF_8);
|
String stderr = new String(mvnProcess.getErrorStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||||
|
@ -16,7 +16,16 @@ public class DownloadZip extends AuthenticatedServlet {
|
|||||||
|
|
||||||
private static final String PARAMETER_FILENAME = "file";
|
private static final String PARAMETER_FILENAME = "file";
|
||||||
|
|
||||||
private final Configuration configuration = new Configuration();
|
private Configuration configuration;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() throws ServletException {
|
||||||
|
try {
|
||||||
|
configuration = new Configuration();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ServletException("Configuration Error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user