Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use latest opencsv version and replace with builder #62

Merged
merged 2 commits into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>4.6</version>
<version>5.7.1</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand All @@ -39,6 +41,9 @@

import javax.servlet.ServletException;

import com.opencsv.CSVParser;
import com.opencsv.CSVParserBuilder;
import com.opencsv.CSVReaderBuilder;
import org.acegisecurity.Authentication;
import org.acegisecurity.context.SecurityContextHolder;
import org.apache.commons.codec.digest.DigestUtils;
Expand Down Expand Up @@ -137,10 +142,7 @@ public FormValidation doCheckPropertyFile(@QueryParameter final String propertyF
}
property.execute();
}
catch(MalformedURLException e) {
return FormValidation.warning(Messages.ExtendedChoiceParameterDefinition_PropertyFileDoesntExist(), propertyFile);
}
catch(BuildException e) {
catch(MalformedURLException | BuildException e) {
return FormValidation.warning(Messages.ExtendedChoiceParameterDefinition_PropertyFileDoesntExist(), propertyFile);
}

Expand Down Expand Up @@ -762,22 +764,20 @@ private Binding getGroovyBinding() {

private synchronized GroovyShell getGroovyShell(String groovyClasspath) {
if(groovyShell == null) {
Jenkins jenkins = Jenkins.getInstance();
if(jenkins != null) {
ClassLoader cl = jenkins.getPluginManager().uberClassLoader;
Jenkins jenkins = Jenkins.get();
ClassLoader cl = jenkins.getPluginManager().uberClassLoader;

if(cl == null) {
cl = Thread.currentThread().getContextClassLoader();
}

CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
if(!StringUtils.isBlank(groovyClasspath)) {
compilerConfiguration.setClasspath(groovyClasspath);
}
if(cl == null) {
cl = Thread.currentThread().getContextClassLoader();
}

Binding groovyBinding = getGroovyBinding();
groovyShell = new GroovyShell(cl, groovyBinding, compilerConfiguration);
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
if(!StringUtils.isBlank(groovyClasspath)) {
compilerConfiguration.setClasspath(groovyClasspath);
}

Binding groovyBinding = getGroovyBinding();
groovyShell = new GroovyShell(cl, groovyBinding, compilerConfiguration);
}
else {
if(!StringUtils.isBlank(groovyClasspath)) {
Expand Down Expand Up @@ -837,10 +837,10 @@ private void setBindings(GroovyShell shell, String bindings) throws IOException
}
}

Jenkins instance = Jenkins.getInstance();
Jenkins instance = Jenkins.get();
shell.setProperty("jenkins", instance);

if(projectName != null && instance != null) {
if(projectName != null) {
AbstractProject<?, ?> project = (AbstractProject<?, ?>)instance.getItem(projectName);
shell.setProperty("currentProject", project);
}
Expand Down Expand Up @@ -939,10 +939,11 @@ Map<String, Set<String>> calculateChoicesByDropdownId() throws Exception {
String resolvedPropertyFile = expandVariables(propertyFile);
File file = new File(resolvedPropertyFile);
List<String[]> fileLines = Collections.emptyList();
CSVParser csvParser = new CSVParserBuilder().withSeparator('\t').build();
if(file.isFile()) {
CSVReader csvReader = null;
try {
csvReader = new CSVReader(new InputStreamReader(new FileInputStream(file), "UTF-8"), '\t');
csvReader = new CSVReaderBuilder(new InputStreamReader(Files.newInputStream(file.toPath()), StandardCharsets.UTF_8)).withCSVParser(csvParser).build();
fileLines = csvReader.readAll();
}
finally {
Expand All @@ -953,7 +954,7 @@ Map<String, Set<String>> calculateChoicesByDropdownId() throws Exception {
URL propertyFileUrl = new URL(resolvedPropertyFile);
CSVReader csvReader = null;
try {
csvReader = new CSVReader(new InputStreamReader(propertyFileUrl.openStream(), "UTF-8"), '\t');
csvReader = new CSVReaderBuilder(new InputStreamReader(propertyFileUrl.openStream(), StandardCharsets.UTF_8)).withCSVParser(csvParser).build();
fileLines = csvReader.readAll();
}
finally {
Expand Down