From 4cf1bb73b788fcedc9cd96b349d7095571399b69 Mon Sep 17 00:00:00 2001 From: earthling Date: Thu, 6 Oct 2016 10:52:26 -0700 Subject: [PATCH 1/3] Add an option to prevent the p4java client from writing to the .p4tickets file. --- .../scm/perforce/PerforceConfiguration.java | 15 +++++++++++++++ .../plugins/scm/perforce/PerforceExecutor.java | 4 +++- .../plugins/scm/perforce/PerforcePluginTest.java | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sonar/plugins/scm/perforce/PerforceConfiguration.java b/src/main/java/org/sonar/plugins/scm/perforce/PerforceConfiguration.java index 2939165..a58a0d7 100644 --- a/src/main/java/org/sonar/plugins/scm/perforce/PerforceConfiguration.java +++ b/src/main/java/org/sonar/plugins/scm/perforce/PerforceConfiguration.java @@ -37,6 +37,7 @@ public class PerforceConfiguration implements BatchComponent { private static final String FALSE = "false"; + private static final String TRUE = "true"; private static final String CATEGORY_PERFORCE = "Perforce"; static final String PORT_PROP_KEY = "sonar.perforce.port"; private static final String USESSL_PROP_KEY = "sonar.perforce.useSsl"; @@ -46,6 +47,7 @@ public class PerforceConfiguration implements BatchComponent { private static final String CLIENT_IMPERSONATED_HOST_PROP_KEY = "sonar.perforce.clientImpersonatedHostname"; private static final String CHARSET_PROP_KEY = "sonar.perforce.charset"; private static final String SOCKSOTIMEOUT_PROP_KEY = "sonar.perforce.sockSoTimeout"; + private static final String WRITE_TICKETS = "sonar.perforce.writeTickets"; private final Settings settings; @@ -128,6 +130,16 @@ public static List getProperties() { .category(CoreProperties.CATEGORY_SCM) .subCategory(CATEGORY_PERFORCE) .index(7) + .build(), + PropertyDefinition.builder(WRITE_TICKETS) + .name("Do not write to tickets file when authenticating") + .description("Perforce client locks the ticket file during writes, this can cause concurrent analyses to fail. Set this to false to disable this behavior.") + .type(PropertyType.BOOLEAN) + .defaultValue(TRUE) + .onQualifiers(Qualifiers.PROJECT) + .category(CoreProperties.CATEGORY_SCM) + .subCategory(CATEGORY_PERFORCE) + .index(8) .build()); } @@ -169,4 +181,7 @@ public int sockSoTimeout() { return settings.getInt(SOCKSOTIMEOUT_PROP_KEY); } + public boolean writeTickets() { + return settings.getBoolean(WRITE_TICKETS); + } } diff --git a/src/main/java/org/sonar/plugins/scm/perforce/PerforceExecutor.java b/src/main/java/org/sonar/plugins/scm/perforce/PerforceExecutor.java index 0030223..68895e5 100644 --- a/src/main/java/org/sonar/plugins/scm/perforce/PerforceExecutor.java +++ b/src/main/java/org/sonar/plugins/scm/perforce/PerforceExecutor.java @@ -30,6 +30,7 @@ import com.perforce.p4java.impl.mapbased.rpc.RpcPropertyDefs; import com.perforce.p4java.impl.mapbased.rpc.sys.helper.RpcSystemFileCommandsHelper; import com.perforce.p4java.option.UsageOptions; +import com.perforce.p4java.option.server.LoginOptions; import com.perforce.p4java.option.server.TrustOptions; import com.perforce.p4java.server.IOptionsServer; import com.perforce.p4java.server.ServerFactory; @@ -126,7 +127,8 @@ private void initServer() { if (!isLogin(server)) { // Login to the server with a password. // Password can be null if it is not needed (i.e. SSO logins). - server.login(config.password(), null); + LoginOptions options = new LoginOptions(false, config.writeTickets()); + server.login(config.password(), options); } } } catch (URISyntaxException e) { diff --git a/src/test/java/org/sonar/plugins/scm/perforce/PerforcePluginTest.java b/src/test/java/org/sonar/plugins/scm/perforce/PerforcePluginTest.java index 96a5492..29984d7 100644 --- a/src/test/java/org/sonar/plugins/scm/perforce/PerforcePluginTest.java +++ b/src/test/java/org/sonar/plugins/scm/perforce/PerforcePluginTest.java @@ -27,6 +27,6 @@ public class PerforcePluginTest { @Test public void getExtensions() { - assertThat(new PerforcePlugin().getExtensions()).hasSize(11); + assertThat(new PerforcePlugin().getExtensions()).hasSize(12); } } From 45c1dc6a99ba2775318381ff1d5afe0d474cd98a Mon Sep 17 00:00:00 2001 From: earthling Date: Thu, 6 Oct 2016 13:12:07 -0700 Subject: [PATCH 2/3] Document parameter to skip writing tickets (and fix gramar). --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4200cbd..584ec7d 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,11 @@ sonar.perforce.useSsl | Use SSL protocol (p4javassl://) to connect to server | f sonar.perforce.charset | Character set used for translation of unicode files (P4CHARSET) sonar.perforce.sockSoTimeout | Perforce socket read timeout for communicating with the Perforce service (milliseconds) | 30000 (30s) sonar.perforce.clientImpersonatedHostname | Name of the host computer to impersonate (P4HOST) | +sonar.perforce.writeTickets | Do not write p4 tickets file when authenticating | false ## Known Limitations * No auto-detection since nothing in workspace seems to show this is under Perforce control management (like .git folder for Git workspace). * Blame is not executed in parallel since we are not confident in the thread safety of p4java library. -## Developper informations -The plugin use the p4java pure Java implementation of Perforce client: http://www.perforce.com/perforce/doc.current/manuals/p4java/01_p4java.html +## Developer information +The plugin uses the p4java pure Java implementation of Perforce client: http://www.perforce.com/perforce/doc.current/manuals/p4java/01_p4java.html From 5402f1ed895644062d4d7341f59371ae3ced275d Mon Sep 17 00:00:00 2001 From: earthling Date: Fri, 7 Oct 2016 13:10:32 -0700 Subject: [PATCH 3/3] remove option to control writing to .p4tickets - just don't write to .p4tickets --- README.md | 1 - .../scm/perforce/PerforceConfiguration.java | 16 ---------------- .../plugins/scm/perforce/PerforceExecutor.java | 2 +- .../plugins/scm/perforce/PerforcePluginTest.java | 2 +- 4 files changed, 2 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 584ec7d..56c9527 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,6 @@ sonar.perforce.useSsl | Use SSL protocol (p4javassl://) to connect to server | f sonar.perforce.charset | Character set used for translation of unicode files (P4CHARSET) sonar.perforce.sockSoTimeout | Perforce socket read timeout for communicating with the Perforce service (milliseconds) | 30000 (30s) sonar.perforce.clientImpersonatedHostname | Name of the host computer to impersonate (P4HOST) | -sonar.perforce.writeTickets | Do not write p4 tickets file when authenticating | false ## Known Limitations * No auto-detection since nothing in workspace seems to show this is under Perforce control management (like .git folder for Git workspace). diff --git a/src/main/java/org/sonar/plugins/scm/perforce/PerforceConfiguration.java b/src/main/java/org/sonar/plugins/scm/perforce/PerforceConfiguration.java index a58a0d7..dc0061c 100644 --- a/src/main/java/org/sonar/plugins/scm/perforce/PerforceConfiguration.java +++ b/src/main/java/org/sonar/plugins/scm/perforce/PerforceConfiguration.java @@ -37,7 +37,6 @@ public class PerforceConfiguration implements BatchComponent { private static final String FALSE = "false"; - private static final String TRUE = "true"; private static final String CATEGORY_PERFORCE = "Perforce"; static final String PORT_PROP_KEY = "sonar.perforce.port"; private static final String USESSL_PROP_KEY = "sonar.perforce.useSsl"; @@ -47,7 +46,6 @@ public class PerforceConfiguration implements BatchComponent { private static final String CLIENT_IMPERSONATED_HOST_PROP_KEY = "sonar.perforce.clientImpersonatedHostname"; private static final String CHARSET_PROP_KEY = "sonar.perforce.charset"; private static final String SOCKSOTIMEOUT_PROP_KEY = "sonar.perforce.sockSoTimeout"; - private static final String WRITE_TICKETS = "sonar.perforce.writeTickets"; private final Settings settings; @@ -130,16 +128,6 @@ public static List getProperties() { .category(CoreProperties.CATEGORY_SCM) .subCategory(CATEGORY_PERFORCE) .index(7) - .build(), - PropertyDefinition.builder(WRITE_TICKETS) - .name("Do not write to tickets file when authenticating") - .description("Perforce client locks the ticket file during writes, this can cause concurrent analyses to fail. Set this to false to disable this behavior.") - .type(PropertyType.BOOLEAN) - .defaultValue(TRUE) - .onQualifiers(Qualifiers.PROJECT) - .category(CoreProperties.CATEGORY_SCM) - .subCategory(CATEGORY_PERFORCE) - .index(8) .build()); } @@ -180,8 +168,4 @@ public String clientImpersonatedHostname() { public int sockSoTimeout() { return settings.getInt(SOCKSOTIMEOUT_PROP_KEY); } - - public boolean writeTickets() { - return settings.getBoolean(WRITE_TICKETS); - } } diff --git a/src/main/java/org/sonar/plugins/scm/perforce/PerforceExecutor.java b/src/main/java/org/sonar/plugins/scm/perforce/PerforceExecutor.java index 68895e5..4ad8607 100644 --- a/src/main/java/org/sonar/plugins/scm/perforce/PerforceExecutor.java +++ b/src/main/java/org/sonar/plugins/scm/perforce/PerforceExecutor.java @@ -127,7 +127,7 @@ private void initServer() { if (!isLogin(server)) { // Login to the server with a password. // Password can be null if it is not needed (i.e. SSO logins). - LoginOptions options = new LoginOptions(false, config.writeTickets()); + LoginOptions options = new LoginOptions(false, true); server.login(config.password(), options); } } diff --git a/src/test/java/org/sonar/plugins/scm/perforce/PerforcePluginTest.java b/src/test/java/org/sonar/plugins/scm/perforce/PerforcePluginTest.java index 29984d7..96a5492 100644 --- a/src/test/java/org/sonar/plugins/scm/perforce/PerforcePluginTest.java +++ b/src/test/java/org/sonar/plugins/scm/perforce/PerforcePluginTest.java @@ -27,6 +27,6 @@ public class PerforcePluginTest { @Test public void getExtensions() { - assertThat(new PerforcePlugin().getExtensions()).hasSize(12); + assertThat(new PerforcePlugin().getExtensions()).hasSize(11); } }