Skip to content

Commit

Permalink
Merge pull request #34 from worktile/develop
Browse files Browse the repository at this point in the history
1.1.3
  • Loading branch information
cheerfyt authored May 27, 2020
2 parents f6e44c3 + 0b4ce9d commit 2e128f0
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 181 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>io.jenkins.plugins</groupId>
<artifactId>worktile</artifactId>
<version>1.1.2-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT</version>
<packaging>hpi</packaging>
<name>Worktile Plugin</name>
<description>
Expand Down
32 changes: 17 additions & 15 deletions src/main/java/io/jenkins/plugins/worktile/MemoryTokenStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@

public class MemoryTokenStore {

public static final Map<String, WTTokenEntity> store = new HashMap<>();
protected static final Map<String, WTTokenEntity> store = new HashMap<>();

public static boolean put(String clientId, String clientSecret, WTTokenEntity entity) {
try {
String key = WTHelper.md5(clientId + clientSecret);
return store.put(key, entity) != null;
} catch (Exception e) {
return false;
public static boolean put(String clientId, String clientSecret, WTTokenEntity entity) {
try {
String key = WTHelper.md5(clientId + clientSecret);
return store.put(key, entity) != null;
}
catch(Exception e) {
return false;
}
}
}

public static WTTokenEntity get(String clientId, String clientSecret) {
try {
String key = WTHelper.md5(clientId + clientSecret);
return store.get(key);
} catch (Exception exception) {
return null;
public static WTTokenEntity get(String clientId, String clientSecret) {
try {
String key = WTHelper.md5(clientId + clientSecret);
return store.get(key);
}
catch(Exception exception) {
return null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.plaincredentials.StringCredentials;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.interceptor.RequirePOST;
import org.kohsuke.stapler.verb.POST;

import javax.annotation.Nonnull;
import java.io.IOException;
Expand Down Expand Up @@ -93,28 +97,37 @@ public boolean configure(StaplerRequest req, JSONObject formatData) throws FormE
return true;
}

@SuppressWarnings("unused")
public FormValidation doCheckEndpoint(@QueryParameter(value = "endpoint", fixEmpty = true) String endpoint) {
if (WTHelper.isNotBlank(endpoint) && !WTHelper.isURL(endpoint)) {
return FormValidation.error(Messages.WTGlobalConfig_OpenApiEndpointError());
}
return FormValidation.ok();
}

@SuppressWarnings("unused")
public FormValidation doCheckClientId(@QueryParameter(value = "clientId", fixEmpty = true) String clientId) {
return WTHelper.isNotBlank(clientId) ? FormValidation.ok()
: FormValidation.error(Messages.WTGlobalConfig_ClientIdError());
}

@SuppressWarnings("unused")
public FormValidation doCheckCredentialsId(
@QueryParameter(value = "credentialsId", fixEmpty = true) String credentialsId) {
return WTHelper.isNotBlank(credentialsId) ? FormValidation.ok()
: FormValidation.error(Messages.WTGlobalConfig_CredentialsIdEmpty());
}

@POST
@Restricted(DoNotUse.class)
@SuppressWarnings("unused")
public FormValidation doTestConnection(@QueryParameter(value = "endpoint", fixEmpty = true) String endpoint,
@QueryParameter(value = "clientId", fixEmpty = true) String clientId,
@QueryParameter(value = "credentialsId", fixEmpty = true) String credentialsId) throws IOException {

// Check permission, only ADMINISTER
Jenkins.get().hasPermission(Jenkins.ADMINISTER);

if (StringUtils.isEmpty(credentialsId) || StringUtils.isEmpty(endpoint) || StringUtils.isEmpty(clientId)) {
return FormValidation.error(Messages.WTGlobalConfig_AnyOfIdError());
}
Expand All @@ -132,10 +145,11 @@ public FormValidation doTestConnection(@QueryParameter(value = "endpoint", fixEm
return FormValidation.error(Messages.WTGlobalConfig_DoTestConnectionFailure() + ": "
+ Messages.WTGlobalConfig_ClientIdOrClientSecretError());
} catch (Exception e) {
return FormValidation.error(Messages.WTGlobalConfig_DoTestConnectionFailure() + e.getMessage());
return FormValidation.error(Messages.WTGlobalConfig_DoTestConnectionFailure() + ": " + e.getMessage());
}
}

@SuppressWarnings("unused")
public ListBoxModel doFillCredentialsIdItems(@QueryParameter final String endpoint,
@QueryParameter final String clientId, @QueryParameter final String credentialsId) {

Expand Down
39 changes: 14 additions & 25 deletions src/main/java/io/jenkins/plugins/worktile/WTHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public static boolean isURL(String url) {
try {
new URL(url).toURI();
return true;
}
catch(Exception e) {
} catch (Exception e) {
return false;
}
}
Expand Down Expand Up @@ -64,8 +63,7 @@ public static String statusOfRun(final Run<?, ?> run) {
public static EnvVars safeEnvVars(Run<?, ?> run) {
try {
return run.getEnvironment(TaskListener.NULL);
}
catch(Exception e) {
} catch (Exception e) {
return new EnvVars();
}
}
Expand All @@ -75,36 +73,27 @@ public static long toSafeTs(long time) {
}

public static String resolveOverview(Run<?, ?> run, String overviewPattern) {
if(overviewPattern == null) {
if (overviewPattern == null || overviewPattern.equals("")) {
return null;
}
Pattern pattern = Pattern.compile(overviewPattern);
try {
Pattern pattern = Pattern.compile(overviewPattern);
List<String> matched = WTHelper.matches(pattern, run.getLog(999), true, true);
return matched.size() > 0 ? matched.get(0) : null;
}
catch(Exception exception) {
return null;
}
}

public static List<String> matches(
Pattern pattern, List<String> contexts, boolean breakOnMatch, boolean origin
) {
HashSet<String> set = new HashSet<>();
for(String context : contexts) {
Matcher matcher = pattern.matcher(context);
while(matcher.find()) {
set.add(origin ? context : matcher.group().toUpperCase());
List<String> logs = run.getLog(999);
for (String log : logs) {
Matcher matcher = pattern.matcher(log);
if (matcher.find()) {
return log;
}
}
if(breakOnMatch) { break; }
return null;
} catch (Exception exception) {
return null;
}
return new ArrayList<>(set);
}

public static List<String> formatWorkItems(List<String> workItems) {
HashSet<String> set = new HashSet<>();
for(String item : workItems) {
for (String item : workItems) {
set.add(item.substring(1));
}
return new ArrayList<>(set);
Expand Down
Loading

0 comments on commit 2e128f0

Please sign in to comment.