private String getPluginId() { return pluginConfiguration.getId(); }
public static PluginConfiguration fromJSON(JsonReader jsonReader) { PluginConfiguration pluginConfiguration = new PluginConfiguration(); jsonReader.readStringIfPresent("id", pluginConfiguration::setId); jsonReader.readStringIfPresent("version", pluginConfiguration::setVersion); return pluginConfiguration; } }
public static void toJSON(OutputWriter jsonWriter, PluginConfiguration pluginConfiguration) { jsonWriter.add("id", pluginConfiguration.getId()); jsonWriter.add("version", pluginConfiguration.getVersion()); }
public boolean validatePluginId(PackageRepository packageRepository) { String pluginId = packageRepository.getPluginConfiguration().getId(); if (isEmpty(pluginId)) { packageRepository.getPluginConfiguration().errors().add(PluginConfiguration.ID, "Please select package repository plugin"); return false; } for (String currentPluginId : repositoryMetadataStore.getPlugins()) { if (currentPluginId.equals(pluginId)) { GoPluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptorFor(pluginId); packageRepository.getPluginConfiguration().setVersion(pluginDescriptor.version()); return true; } } packageRepository.getPluginConfiguration().errors().add(PluginConfiguration.ID, "Invalid plugin id"); return false; }
@Test public void shouldReturnPluginIdAsDisplayValue() throws Exception { PluginConfiguration pluginConfiguration = new PluginConfiguration("test-plugin-1", "1.0"); PluggableTask pluggableTask = new PluggableTask(pluginConfiguration, new Configuration()); MissingPluggableTaskViewModel viewModel = new MissingPluggableTaskViewModel(pluggableTask, null); assertThat(viewModel.getParameters().get("template"), is(String.format("Associated plugin '%s' not found. Please contact the Go admin to install the plugin.", pluginConfiguration.getId()))); assertThat(viewModel.getTypeForDisplay(), is(pluginConfiguration.getId())); } }
@Override public boolean hasSameTypeAs(Task task) { if (!getClass().equals(task.getClass())) { return false; } return this.pluginConfiguration.equals(((PluggableTask) task).pluginConfiguration); }
@Test public void isValidShouldVerifyForValidConfigurationProperties() { PluginConfiguration pluginConfiguration = new PluginConfiguration("github.pr", "1.1"); Configuration configuration = mock(Configuration.class); PluggableTaskConfigStore.store().setPreferenceFor(pluginConfiguration.getId(), mock(TaskPreference.class)); when(configuration.hasErrors()).thenReturn(true); PluggableTask pluggableTask = new PluggableTask(pluginConfiguration, configuration); assertFalse(pluggableTask.isValid()); verify(configuration).validateTree(); verify(configuration).hasErrors(); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } SCM that = (SCM) o; if (id != null ? !id.equals(that.id) : that.id != null) { return false; } if (name != null ? !name.equals(that.name) : that.name != null) { return false; } if (pluginConfiguration != null ? !pluginConfiguration.equals(that.pluginConfiguration) : that.pluginConfiguration != null) { return false; } if (configuration != null ? !configuration.equals(that.configuration) : that.configuration != null) { return false; } return true; }
@Override public String getTypeForDisplay() { return pluggableTask.getPluginConfiguration().getId(); } }
public PluginConfiguration toPluginConfiguration(CRPluginConfiguration pluginConfiguration) { return new PluginConfiguration(pluginConfiguration.getId(), pluginConfiguration.getVersion()); }
@Test public void shouldAddConfigurationProperties() { List<ConfigurationProperty> configurationProperties = Arrays.asList(ConfigurationPropertyMother.create("key", "value", "encValue"), new ConfigurationProperty()); PluginConfiguration pluginConfiguration = new PluginConfiguration("github.pr", "1.1"); TaskPreference taskPreference = mock(TaskPreference.class); TaskConfig taskConfig = new TaskConfig(); Configuration configuration = new Configuration(); Property property = new Property("key"); property.with(Property.SECURE, false); PluggableTaskConfigStore.store().setPreferenceFor(pluginConfiguration.getId(), taskPreference); TaskConfigProperty taskConfigProperty = taskConfig.addProperty("key"); when(taskPreference.getConfig()).thenReturn(taskConfig); PluggableTask pluggableTask = new PluggableTask(pluginConfiguration, configuration); pluggableTask.addConfigurations(configurationProperties); assertThat(configuration.size(), is(2)); }
private CRPluggableTask pluggableTaskToCRPluggableTask(PluggableTask pluggableTask) { CRPluginConfiguration pluginConfiguration = new CRPluginConfiguration(pluggableTask.getPluginConfiguration().getId(), pluggableTask.getPluginConfiguration().getVersion()); List<CRConfigurationProperty> configuration = configurationToCRConfiguration(pluggableTask.getConfiguration()); CRPluggableTask task = new CRPluggableTask(pluginConfiguration, configuration); commonCRTaskMembers(task, pluggableTask); return task; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } PluggableTask that = (PluggableTask) o; if (configuration != null ? !configuration.equals(that.configuration) : that.configuration != null) { return false; } if (!pluginConfiguration.equals(that.pluginConfiguration)) { return false; } return true; }
@Override public String getTaskType() { return PLUGGABLE_TASK_PREFIX + "_" + getPluginConfiguration().getId().replaceAll("[^a-zA-Z0-9_]", "_"); }
private List<PluggableTask> allPluginTasks() { final ArrayList<PluggableTask> tasks = new ArrayList<>(); for (final String pluginId : PluggableTaskConfigStore.store().pluginIds()) { GoPluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptorFor(pluginId); TaskPreference taskPreference = PluggableTaskConfigStore.store().preferenceFor(pluginId); if (pluginDescriptor != null && taskPreference != null) { tasks.add(new PluggableTask(new PluginConfiguration(pluginId, pluginDescriptor.version()), getConfiguration(taskPreference.getConfig()))); } } return tasks; }
@Test public void shouldSetConfigAttributesAsAvailable() throws Exception { SCMConfigurations scmConfigurations = new SCMConfigurations(); scmConfigurations.add(new SCMConfiguration("url")); scmConfigurations.add(new SCMConfiguration("username")); scmConfigurations.add(new SCMConfiguration("password").with(SECURE, true)); SCMMetadataStore.getInstance().addMetadataFor("plugin-id", scmConfigurations, null); Map<String, String> attributeMap = DataStructureUtils.m(SCM.SCM_ID, "scm-id", SCM.NAME, "scm-name", SCM.AUTO_UPDATE, "false", "url", "http://localhost", "username", "user", "password", "pass"); SCM scm = new SCM(null, new PluginConfiguration("plugin-id", "1"), new Configuration()); scm.setConfigAttributes(attributeMap); assertThat(scm.getId(), is("scm-id")); assertThat(scm.getName(), is("scm-name")); assertThat(scm.isAutoUpdate(), is(false)); assertThat(scm.getPluginConfiguration().getId(), is("plugin-id")); assertThat(scm.getConfigAsMap().get("url").get(SCM.VALUE_KEY), is("http://localhost")); assertThat(scm.getConfigAsMap().get("username").get(SCM.VALUE_KEY), is("user")); assertThat(scm.getConfigAsMap().get("password").get(SCM.VALUE_KEY), is("pass")); assertThat(scm.getConfiguration().getProperty("password").getConfigurationValue(), is(nullValue())); assertThat(scm.getConfiguration().getProperty("password").getEncryptedConfigurationValue(), is(not(nullValue()))); }
@Test public void shouldCheckForFieldAssignments() { Configuration configuration = new Configuration(); SCM scm = SCMMother.create("id", "name", "plugin-id", "version", configuration); assertThat(scm.getId(), is("id")); assertThat(scm.getName(), is("name")); assertThat(scm.getPluginConfiguration().getId(), is("plugin-id")); assertThat(scm.getPluginConfiguration().getVersion(), is("version")); assertThat(scm.getConfiguration().listOfConfigKeys().isEmpty(), is(true)); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } PackageRepository that = (PackageRepository) o; if (configuration != null ? !configuration.equals(that.configuration) : that.configuration != null) { return false; } if (id != null ? !id.equals(that.id) : that.id != null) { return false; } if (name != null ? !name.equals(that.name) : that.name != null) { return false; } if (packages != null ? !packages.equals(that.packages) : that.packages != null) { return false; } if (pluginConfiguration != null ? !pluginConfiguration.equals(that.pluginConfiguration) : that.pluginConfiguration != null) { return false; } return true; }
public String getSCMType() { return "pluggable_material_" + getPluginConfiguration().getId().replaceAll("[^a-zA-Z0-9_]", "_"); } }
@Test public void validateTreeShouldVerifyIfConfigurationHasErrors() { Configuration configuration = mock(Configuration.class); PluggableTask pluggableTask = new PluggableTask(new PluginConfiguration(), configuration); when(configuration.hasErrors()).thenReturn(true); assertFalse(pluggableTask.validateTree(null)); }