-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #689 from naver/feature/support-gradle-groovy
Support Gradle groovy script Reviewed by : geunwoo
- Loading branch information
Showing
24 changed files
with
656 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,37 @@ | ||
FROM jeanblanchard/java:serverjre-8 | ||
MAINTAINER JunHo Yoon "[email protected]" | ||
|
||
RUN apk update; apk add curl bash | ||
RUN apk update; apk add curl bash tar | ||
|
||
ARG MAVEN_VERSION=3.6.3 | ||
ARG MAVEN_DOWNLOAD_BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries | ||
|
||
ARG GRADLE_VERSION=6.7.1 | ||
ARG GRADLE_DOWNLOAD_BASE_URL=https://services.gradle.org/distributions | ||
|
||
# Install maven | ||
RUN mkdir -p /usr/share/maven \ | ||
&& echo "Downloading maven" \ | ||
&& curl -fsSL -o /tmp/apache-maven.tar.gz ${MAVEN_DOWNLOAD_BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \ | ||
&& echo "Unziping maven" \ | ||
&& tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \ | ||
&& rm -f /tmp/apache-maven.tar.gz | ||
|
||
# Install gradle | ||
RUN mkdir -p /usr/share/gradle \ | ||
&& echo "Downloading gradle" \ | ||
&& curl -fsSL -o /tmp/gradle.zip ${GRADLE_DOWNLOAD_BASE_URL}/gradle-${GRADLE_VERSION}-bin.zip \ | ||
&& echo "Unziping gradle" \ | ||
&& unzip -d /usr/share/gradle /tmp/gradle.zip \ | ||
&& rm -f /tmp/gradle.zip | ||
|
||
# Set up environment variables | ||
ENV BASE_DIR=/opt \ | ||
NGRINDER_HOME=/opt/ngrinder-controller | ||
NGRINDER_HOME=/opt/ngrinder-controller \ | ||
MAVEN_HOME=/usr/share/maven \ | ||
GRADLE_HOME=/usr/share/gradle/gradle-${GRADLE_VERSION} | ||
|
||
ENV PATH=$PATH:$GRADLE_HOME/bin:$MAVEN_HOME/bin | ||
|
||
# Expose ports | ||
EXPOSE 80 16001 12000-12009 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
#!/usr/bin/env bash | ||
echo "wait a while extracting war files... It takes time for the first run." | ||
echo "Installed build tools." | ||
mvn -version | ||
gradle -version | ||
|
||
echo "Wait a while extracting war files... It takes time for the first run." | ||
java -jar ${BASE_DIR}/ngrinder-*.war --port 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
...ontroller/src/main/java/org/ngrinder/script/handler/GroovyGradleProjectScriptHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
* Copyright (c) 2012-present NAVER Corp. | ||
* | ||
* This file is part of The nGrinder software distribution. Refer to | ||
* the file LICENSE which is part of The nGrinder distribution for | ||
* licensing details. The nGrinder distribution is available on the | ||
* Internet at https://naver.github.io/ngrinder | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.ngrinder.script.handler; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.ngrinder.common.util.PathUtils; | ||
import org.ngrinder.infra.config.Config; | ||
import org.ngrinder.model.User; | ||
import org.ngrinder.script.model.FileEntry; | ||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.List; | ||
|
||
import static java.lang.System.getenv; | ||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static java.nio.file.Paths.get; | ||
import static org.apache.commons.io.FileUtils.deleteQuietly; | ||
import static org.apache.commons.io.FilenameUtils.normalize; | ||
import static org.apache.commons.lang.StringUtils.EMPTY; | ||
import static org.apache.commons.lang.StringUtils.isNotEmpty; | ||
import static org.ngrinder.common.util.AccessUtils.getSafe; | ||
import static org.ngrinder.common.util.CollectionUtils.buildMap; | ||
import static org.ngrinder.common.util.ExceptionUtils.processException; | ||
import static org.ngrinder.common.util.UrlUtils.getHost; | ||
import static org.ngrinder.script.model.FileCategory.SCRIPT; | ||
import static org.ngrinder.script.model.FileType.DIR; | ||
|
||
/** | ||
* Groovy gradle project {@link ScriptHandler}. | ||
* | ||
* @since 3.5.3 | ||
*/ | ||
@Component | ||
public class GroovyGradleProjectScriptHandler extends GroovyProjectScriptHandler { | ||
|
||
public static final String GRADLE_HOME_ENV_NAME = "GRADLE_HOME"; | ||
|
||
private final String ngrinderHomePath; | ||
private String gradlePath; | ||
|
||
public GroovyGradleProjectScriptHandler(Config config) { | ||
super("groovy_gradle", "", "Groovy Gradle Project", "groovy", "build.gradle", true); | ||
|
||
gradlePath = getSafe(getenv(GRADLE_HOME_ENV_NAME), ""); | ||
if (isNotEmpty(gradlePath)) { | ||
gradlePath += "/bin/"; | ||
} | ||
|
||
ngrinderHomePath = config.getHome().getDirectory().getAbsolutePath(); | ||
} | ||
|
||
@Override | ||
protected String getCopyDependenciesCommand(File distDir) { | ||
String distDirPath = distDir.getAbsolutePath(); | ||
return gradlePath + "gradle -I " + ngrinderHomePath + "/init.gradle -p" + distDirPath + | ||
" __copyDependencies -PoutputDirectory=" + distDirPath + "/lib"; | ||
} | ||
|
||
@Override | ||
protected boolean isSuccess(List<String> results) { | ||
if (results.isEmpty()) { | ||
return false; | ||
} | ||
return results.stream().noneMatch(str -> str.contains("FAILED")); | ||
} | ||
|
||
@Override | ||
public boolean prepareScriptEnv(User user, String path, String fileName, String name, // LF | ||
String url, boolean createLib, String scriptContent) { | ||
path = PathUtils.join(path, fileName); | ||
// Create Dir entry | ||
createBaseDirectory(user, path); | ||
// Create each template entries | ||
createFileEntries(user, path, name, url, scriptContent); | ||
if (createLib) { | ||
createLibraryDirectory(user, path); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
protected void deleteUnnecessaryFilesFromDist(File distDir) { | ||
super.deleteUnnecessaryFilesFromDist(distDir); | ||
deleteQuietly(new File(distDir, ".gradle")); | ||
} | ||
|
||
private void createFileEntries(User user, String path, String name, String url, String scriptContent) { | ||
String[] scriptTemplatePaths = { getBuildScriptName(), "src/main/resources/resource1.txt", "src/main/java/TestRunner.groovy" }; | ||
for (String scriptTemplatePath : scriptTemplatePaths) { | ||
try (InputStream inputStream = new ClassPathResource("/script_template/groovy_gradle/" + scriptTemplatePath).getInputStream()) { | ||
String fileContent = IOUtils.toString(inputStream, UTF_8.name()); | ||
if (scriptTemplatePath.endsWith("TestRunner.groovy")) { | ||
fileContent = scriptContent; | ||
} else { | ||
fileContent = fileContent.replace("${userName}", user.getUserName()); | ||
fileContent = fileContent.replace("${name}", name); | ||
fileContent = fileContent.replace("${url}", url); | ||
} | ||
FileEntry fileEntry = new FileEntry(); | ||
fileEntry.setContent(fileContent); | ||
fileEntry.setPath(normalize(PathUtils.join(path, scriptTemplatePath), true)); | ||
fileEntry.setDescription("create groovy gradle project"); | ||
String hostName = getHost(url); | ||
if (isNotEmpty(hostName) | ||
&& fileEntry.getFileType().getFileCategory() == SCRIPT) { | ||
fileEntry.getProperties().put("targetHosts", getHost(url)); | ||
} else { | ||
fileEntry.getProperties().put("targetHosts", EMPTY); | ||
} | ||
getFileEntryRepository().save(user, fileEntry, UTF_8.name()); | ||
} catch (IOException e) { | ||
throw processException("Error while saving " + get(scriptTemplatePath).getFileName(), e); | ||
} | ||
} | ||
} | ||
|
||
private void createBaseDirectory(User user, String path) { | ||
FileEntry dirEntry = new FileEntry(); | ||
dirEntry.setPath(path); | ||
// Make it eclipse default folder ignored. | ||
dirEntry.setProperties(buildMap("svn:ignore", ".project\n.classpath\n.settings\ntarget")); | ||
dirEntry.setFileType(DIR); | ||
dirEntry.setDescription("create groovy gradle project"); | ||
getFileEntryRepository().save(user, dirEntry, null); | ||
} | ||
} |
Oops, something went wrong.