jetbrains.buildServer.serverSide.SProject Java Examples

The following examples show how to use jetbrains.buildServer.serverSide.SProject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MigratingSQSManager.java    From TeamCity.SonarQubePlugin with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public SQSActionResult removeServer(@NotNull SProject project, @NotNull String serverId) {
    SQSActionResult oldSqsInfo = null;
    for (SQSManager sqsManager: mySQSManagers) {
        if (sqsManager != myEditManager) {
            final SQSActionResult sqsActionResult = sqsManager.removeServer(project, serverId);
            if (oldSqsInfo == null || !oldSqsInfo.isError()) {
                oldSqsInfo = sqsActionResult;
            }
        }
    }

    final SQSActionResult sqsInfo = myEditManager.removeServer(project, serverId);
    return oldSqsInfo == null || !oldSqsInfo.isError() ? sqsInfo : oldSqsInfo;
}
 
Example #2
Source File: MigratingSQSManager.java    From TeamCity.SonarQubePlugin with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public SQSActionResult editServer(@NotNull SProject project, @NotNull SQSInfo sqsInfo) {
    if (myEditManager.getServer(project, sqsInfo.getId()) == null) {
        for (SQSManager sqsManager: mySQSManagers) {
            if (sqsManager == myEditManager) continue;

            SQSInfo init = sqsManager.getServer(project, sqsInfo.getId());
            if (init != null) {
                migrate(sqsManager, project, sqsInfo);
                return new SQSActionResult(init, sqsInfo, "SonarQube Server '" + sqsInfo.getName() + "' updated and moved to project features");
            } else {
                return new SQSActionResult(null, null, "Cannot edit: SonarQube Server with id '" + sqsInfo.getId() + "' was not found", true);
            }
        }
    }

    return myEditManager.editServer(project, sqsInfo);
}
 
Example #3
Source File: ProjectSlackNotificationsBean.java    From tcSlackBuildNotifier with MIT License 6 votes vote down vote up
public static ProjectSlackNotificationsBean build(SlackNotificationProjectSettings projSettings, SBuildType sBuildType, SProject project, SlackNotificationMainSettings mainSettings){
	ProjectSlackNotificationsBean bean = new ProjectSlackNotificationsBean();
	List<SBuildType> projectBuildTypes = TeamCityIdResolver.getOwnBuildTypes(project);
	Set<String> enabledBuildTypes = new HashSet<String>();
	enabledBuildTypes.add(sBuildType.getBuildTypeId());
	
	bean.projectId = TeamCityIdResolver.getInternalProjectId(project);
	bean.slackNotificationList = new LinkedHashMap<String, SlacknotificationConfigAndBuildTypeListHolder>();
	
	/* Create a "new" config with blank stuff so that clicking the "new" button has a bunch of defaults to load in */
	SlackNotificationConfig newBlankConfig = new SlackNotificationConfig("", "", "", "", true, new BuildState().setAllEnabled(), false, false, enabledBuildTypes, true, true, true, true);
	newBlankConfig.setUniqueKey("new");
	/* And add it to the list */
	addSlackNotificationConfigHolder(bean, projectBuildTypes, newBlankConfig, mainSettings);
	
	/* Iterate over the rest of the slacknotifications in this project and add them to the json config */
	for (SlackNotificationConfig config : projSettings.getBuildSlackNotificationsAsList(sBuildType)){
		addSlackNotificationConfigHolder(bean, projectBuildTypes, config, mainSettings);
	}
	
	return bean;
	
}
 
Example #4
Source File: ProjectSlackNotificationsBean.java    From tcSlackBuildNotifier with MIT License 6 votes vote down vote up
public static ProjectSlackNotificationsBean build(SlackNotificationProjectSettings projSettings, SProject project, SlackNotificationMainSettings mainSettings){
	ProjectSlackNotificationsBean bean = new ProjectSlackNotificationsBean();
	List<SBuildType> projectBuildTypes = TeamCityIdResolver.getOwnBuildTypes(project);
	
	bean.projectId = TeamCityIdResolver.getInternalProjectId(project);
	bean.slackNotificationList = new LinkedHashMap<String, SlacknotificationConfigAndBuildTypeListHolder>();

	/* Create a "new" config with blank stuff so that clicking the "new" button has a bunch of defaults to load in */
	SlackNotificationConfig newBlankConfig = new SlackNotificationConfig("", "", "", "", true, new BuildState().setAllEnabled(), true, true, null, true, true, true, true);
	newBlankConfig.setUniqueKey("new");
	/* And add it to the list */
	addSlackNotificationConfigHolder(bean, projectBuildTypes, newBlankConfig, mainSettings);
	
	/* Iterate over the rest of the slacknotifications in this project and add them to the json config */
	for (SlackNotificationConfig config : projSettings.getSlackNotificationsAsList()){
		addSlackNotificationConfigHolder(bean, projectBuildTypes, config, mainSettings);
	}
	
	return bean;
	
}
 
Example #5
Source File: EditSQRRunType.java    From TeamCity.SonarQubePlugin with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void fillModel(@NotNull final HttpServletRequest request,
                      @NotNull final BuildTypeForm form,
                      @NotNull final Map model) {
    SProject project = form.getProject();
    final List<SQSInfo> availableServers = mySqsManager.getAvailableServers(project);
    model.put("servers", availableServers);
    final String sonarServer = getSonarServer(form);

    if (Util.isEmpty(sonarServer)) {
        model.put("showSelectServer", Boolean.TRUE);
    } else if (mySqsManager.getServer(form.getProject(), sonarServer) == null) {
        model.put("showUnknownServer", Boolean.TRUE);
    }

    model.put("project", form.getProject());
}
 
Example #6
Source File: SQSManagerTest.java    From TeamCity.SonarQubePlugin with Apache License 2.0 6 votes vote down vote up
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception {
    myRoot = mock(SProject.class);
    when(myRoot.getProjectId()).thenReturn(myRootProjectId);
    when(myRoot.getParentProject()).thenReturn(null);

    myProject = mock(SProject.class);
    when(myProject.getProjectId()).thenReturn(myProjectId);
    when(myProject.getParentProject()).thenReturn(myRoot);

    mySettingsManager = mock(ProjectSettingsManager.class);

    myServerInfo = mockSQSInfo(mySettingsManager, myServerId, myProjectId);

    myRootServerInfo = mockSQSInfo(mySettingsManager, myRootServerId, myRootProjectId);
}
 
Example #7
Source File: ManageSQSActionController.java    From TeamCity.SonarQubePlugin with Apache License 2.0 6 votes vote down vote up
private SQSInfo removeServerInfo(@NotNull final HttpServletRequest request,
                              @NotNull final SProject project,
                              @NotNull final Element ajaxResponse) throws IOException {
    final String serverinfoId = getServerInfoId(request);
    if (serverinfoId == null) {
        ajaxResponse.setAttribute("error", "ID is not set");
    } else {
        final SQSManager.SQSActionResult result = mySqsManager.removeServer(project, serverinfoId);
        if (!result.isError()) {
            ajaxResponse.setAttribute("status", result.getReason());
            return result.getBeforeAction();
        } else {
            ajaxResponse.setAttribute("error", result.getReason());
        }
}
    return null;
}
 
Example #8
Source File: SlackProjectTab.java    From TCSlackNotifierPlugin with MIT License 5 votes vote down vote up
@Override
protected void fillModel(Map<String, Object> model, HttpServletRequest httpServletRequest, SProject sProject, SUser sUser) {

    SlackProjectSettings slackProjectSettings = (SlackProjectSettings) projectSettingsManager.getSettings(sProject.getProjectId(), SlackProjectSettingsFactory.SETTINGS_KEY);

    String channel = slackConfigProcessor.getDefaultChannel() ;
    boolean enabled = true ;
    String logoUrl = "" ;

    if( slackProjectSettings != null && slackProjectSettings.getChannel() != null && slackProjectSettings.getChannel().length() > 0 )
    {
        channel = slackProjectSettings.getChannel() ;
    }
    if( slackProjectSettings != null && slackProjectSettings.getLogoUrl() != null && slackProjectSettings.getLogoUrl().length() > 0 )
    {
        logoUrl = slackProjectSettings.getLogoUrl();
    }
    if( slackProjectSettings != null )
    {
        enabled = slackProjectSettings.isEnabled();
    }

    model.put("configDir" , sProject.getConfigDirectory().toString());
    model.put("channel" , channel );
    model.put("enabled" , enabled );
    model.put("logoUrl" , logoUrl );

}
 
Example #9
Source File: TeamCityIdResolver.java    From tcSlackBuildNotifier with MIT License 5 votes vote down vote up
/**
 * Finds a TeamCity project in the ProjectManager by ProjectId.
 * Uses findProjectByExternalId() if available, otherwise uses findProjectById()
 * @param TeamCity projectManager instance
 * @param projectId string
 * @return TeamCity Project Config object
 */
public static SProject findProjectById(ProjectManager projectManager, String projectId) {
	try {
		return projectManager.findProjectByExternalId(projectId);
	} catch (NoSuchMethodError ex){
		LOGGER.log(Level.INFO,ex.getMessage(),ex);
		return projectManager.findProjectById(projectId);
	}
}
 
Example #10
Source File: TeamCityIdResolver.java    From tcSlackBuildNotifier with MIT License 5 votes vote down vote up
public static String getProjectId(SProject project){
	try {
		return project.getExternalId();
	} catch (NoSuchMethodError ex) {
		LOGGER.log(Level.INFO,ex.getMessage(),ex);
		return project.getProjectId();
	}
}
 
Example #11
Source File: ServerManagementProjectTab.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
private Map<SProject, List<SQSInfo>> getServersMap(@NotNull final SProject currentProject) {
    SProject project = currentProject;
    Map<SProject, List<SQSInfo>> infoMap = new HashMap<SProject, List<SQSInfo>>();
    while (project != null) {
        if (infoMap.containsKey(project)) {
            break;
        }
        final List<SQSInfo> availableServers = mySqsManager.getOwnAvailableServers(project);
        if (!availableServers.isEmpty()) {
            infoMap.put(project, availableServers);
        }
        project = project.getParentProject();
    }
    return infoMap;
}
 
Example #12
Source File: ServerManagementProjectTab.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void fillModel(@NotNull final Map<String, Object> model, @NotNull final HttpServletRequest request) {
    final SProject currentProject = getProject(request);
    if (currentProject == null) {
        return;
    }
    Map<SProject, List<SQSInfo>> infoMap = getServersMap(currentProject);
    model.put("availableServersMap", infoMap);
    model.put("projectId", currentProject.getExternalId());
    model.put("userHasPermissionManagement", AuthUtil.hasPermissionToManageProject(securityContext.getAuthorityHolder(), currentProject.getProjectId()));
}
 
Example #13
Source File: ServerManagementProjectTab.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public String getTabTitle(@NotNull final HttpServletRequest request) {
    final SProject currentProject = getProject(request);
    if (currentProject == null) {
        return TAB_TITLE;
    }
    final List<SQSInfo> availableServers = mySqsManager.getOwnAvailableServers(currentProject);
    if (availableServers.isEmpty()) {
        return TAB_TITLE;
    }
    return TAB_TITLE + " (" + availableServers.size() + ")";
}
 
Example #14
Source File: TeamCityIdResolver.java    From tcSlackBuildNotifier with MIT License 5 votes vote down vote up
/**
 * Finds builds that belong the referenced project. Uses new method getOwnBuildTypes() if available.
 * Does not find builds in sub-projects.
 * @param project
 * @return List of BuildTypes corresponding to what is configured in the project.
 */
public static List<SBuildType> getOwnBuildTypes(SProject project) {
	try {
		return project.getOwnBuildTypes();
	} catch (NoSuchMethodError ex){
		LOGGER.log(Level.INFO,ex.getMessage(),ex);
		return project.getBuildTypes();
	}
}
 
Example #15
Source File: ProjectAndBuildSlacknotificationsBean.java    From tcSlackBuildNotifier with MIT License 5 votes vote down vote up
public static ProjectAndBuildSlacknotificationsBean newInstance (SProject project, SlackNotificationProjectSettings settings, SBuildType sBuild) {
	ProjectAndBuildSlacknotificationsBean bean = new ProjectAndBuildSlacknotificationsBean();
	bean.project = project;
	bean.slackNotificationProjectSettings = settings;
	
	bean.projectSlacknotifications = settings.getProjectSlackNotificationsAsList();
	bean.buildSlacknotifications = new ArrayList<BuildSlacknotificationsBean>();
	
	if (sBuild != null && sBuild.getProjectId().equals(project.getProjectId())){
		bean.buildSlacknotifications.add(new BuildSlacknotificationsBean(sBuild, settings.getBuildSlackNotificationsAsList(sBuild)));
	}
	return bean;
}
 
Example #16
Source File: ManageSQSActionController.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
private SQSInfo editServerInfo(@NotNull final HttpServletRequest request,
                            @NotNull final SProject project,
                            @NotNull final Element ajaxResponse) {
    if (!validate(request, ajaxResponse)) {
        return null;
    }

    final String serverInfoId = getServerInfoId(request);
    if (serverInfoId == null) {
        ajaxResponse.setAttribute("error", "ID is not set");
        return null;
    }

    final SQSInfo old = mySqsManager.getServer(project, serverInfoId);
    if (old == null) {
        return null;
    }

    final String pass = getPassword(request, old);
    final String jdbcPass = getJDBCPassword(request, old);
    final SQSInfo info = createServerInfo(request, serverInfoId, pass, jdbcPass);
    final SQSManager.SQSActionResult result = mySqsManager.editServer(project, info);
    if (!result.isError()) {
        ajaxResponse.setAttribute("status", "OK");
    } else {
        ajaxResponse.setAttribute("error", result.getReason());
    }
    return result.getAfterAction();
}
 
Example #17
Source File: SQSManagerEmptyTypeProjectFeatures.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public synchronized SQSActionResult removeServer(@NotNull SProject project, @NotNull String serverId) {
    final Optional<SProjectFeatureDescriptor> found = findByServerId(project, serverId);
    if (found.isPresent() && project.removeFeature(found.get().getId()) != null) {
        final SQSInfoImpl old = new SQSInfoImpl(found.get());
        return new SQSActionResult(old, null, "SonarQube Server '" + old.getName() + "' removed");
    }
    return new SQSActionResult(null, null, "Cannot remove: SonarQube Server with id '" + serverId + "' doesn't exist");
}
 
Example #18
Source File: SQSManagerImpl.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
static ProjectAccessor recurse(@NotNull final SProject project) {
    return new ProjectAccessor(project) {
        public SProject next() {
            if (myProject == null) {
                return null;
            }
            SProject t = myProject;
            myProject = myProject.getParentProject();
            return t;
        }
    };
}
 
Example #19
Source File: ManageSQSActionController.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
private SQSInfo addServerInfo(@NotNull final HttpServletRequest request,
                              @NotNull final SProject project,
                              @NotNull final Element ajaxResponse) throws IOException {
    if (validate(request, ajaxResponse)) {
        final SQSInfo serverInfo = createServerInfo(request, null, decryptIfNeeded(request.getParameter(SONAR_PASSWORD)), decryptIfNeeded(request.getParameter(SONAR_JDBC_PASSWORD)));
        final SQSManager.SQSActionResult result = mySqsManager.addServer(project, serverInfo);
        if (!result.isError()) {
            ajaxResponse.setAttribute("status", "OK");
        } else {
            ajaxResponse.setAttribute("error", result.getReason());
        }
        return serverInfo;
    }
    return null;
}
 
Example #20
Source File: SQSManagerProjectFeatures.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public synchronized SQSInfo getServer(@NotNull SProject project, @NotNull String serverId) {
    final Optional<SProjectFeatureDescriptor> optional = project.getAvailableFeaturesOfType(PROJECT_FEATURE_TYPE).stream().filter(f -> {
        final String id = f.getParameters().get(BaseSQSInfo.ID);
        return id != null && serverId.equals(id);
    }).findFirst();
    if (optional.isPresent()) {
        return new SQSInfoImpl(optional.get());
    }
    return null;
}
 
Example #21
Source File: SQSManagerProjectFeatures.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public synchronized SQSInfo getOwnServer(@NotNull SProject project, @NotNull String serverId) {
    final Optional<SProjectFeatureDescriptor> optional = findByServerId(project, serverId);
    if (optional.isPresent()) {
        return new SQSInfoImpl(optional.get());
    }
    return null;
}
 
Example #22
Source File: SQSManagerProjectFeatures.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public synchronized SQSActionResult editServer(@NotNull SProject project, @NotNull SQSInfo modifiedServer) {
    final Optional<SProjectFeatureDescriptor> found = findByServerId(project, modifiedServer.getId());
    if (found.isPresent()) {
        final SProjectFeatureDescriptor featureDescriptor = found.get();
        project.updateFeature(featureDescriptor.getId(), PROJECT_FEATURE_TYPE, toMap(modifiedServer));
        return new SQSActionResult(new SQSInfoImpl(found.get()), modifiedServer, "SonarQube Server '" + modifiedServer.getName() + "' updated");
    } else {
        return addServer(project, modifiedServer);
    }
}
 
Example #23
Source File: SQSManagerProjectFeatures.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public synchronized SQSActionResult addServer(@NotNull SProject toProject, @NotNull SQSInfo newServer) {
    if (getServer(toProject, newServer.getId()) != null) return new SQSActionResult(null, null, "Cannot add: SonarQube Server with id '" + newServer.getId() + "' already exists", true);
    doAddServer(toProject, newServer);
    return new SQSActionResult(null, newServer, "SonarQube Server '" + newServer.getName() + " added");
}
 
Example #24
Source File: SQSManagerProjectFeatures.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public synchronized SQSActionResult removeServer(@NotNull SProject project, @NotNull String serverId) {
    final Optional<SProjectFeatureDescriptor> found = findByServerId(project, serverId);
    if (found.isPresent() && project.removeFeature(found.get().getId()) != null) {
        final SQSInfoImpl old = new SQSInfoImpl(found.get());
        return new SQSActionResult(old, null, "SonarQube Server '" + old.getName() + "' removed");
    }
    return new SQSActionResult(null, null, "Cannot remove: SonarQube Server with id '" + serverId + "' doesn't exist");
}
 
Example #25
Source File: TestUtil.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
public static Projects createProjects(@NotNull final String rootId, @NotNull final String projectId) {
    final SProject root = mock(SProject.class);
    when(root.getProjectId()).thenReturn(rootId);
    when(root.getParentProject()).thenReturn(null);

    final SProject project = mock(SProject.class);
    when(project.getProjectId()).thenReturn(projectId);
    when(project.getParentProject()).thenReturn(root);

    when(root.getProjects()).thenReturn(Collections.singletonList(project));
    when(root.getOwnProjects()).thenReturn(Collections.singletonList(project));

    return new Projects(root, project);
}
 
Example #26
Source File: MigratingSQSManager.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public List<SQSInfo> getAvailableServers(@NotNull SProject project) {
    final Set<SQSInfo> res = new HashSet<>();
    for (SQSManager sqsManager: mySQSManagers) {
        res.addAll(sqsManager.getAvailableServers(project));
    }
    return new ArrayList<>(res);
}
 
Example #27
Source File: MigratingSQSManager.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public List<SQSInfo> getOwnAvailableServers(@NotNull SProject project) {
    final Set<SQSInfo> res = new HashSet<>();
    for (SQSManager sqsManager: mySQSManagers) {
        res.addAll(sqsManager.getOwnAvailableServers(project));
    }
    return new ArrayList<>(res);
}
 
Example #28
Source File: MigratingSQSManager.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public SQSInfo getServer(@NotNull SProject project, @NotNull String serverId) {
    for (SQSManager sqsManager: mySQSManagers) {
        SQSInfo server = sqsManager.getServer(project, serverId);
        if (server != null) return server;
    }
    return null;
}
 
Example #29
Source File: MigratingSQSManager.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public SQSInfo getOwnServer(@NotNull SProject project, @NotNull String serverId) {
    for (SQSManager sqsManager: mySQSManagers) {
        SQSInfo server = sqsManager.getOwnServer(project, serverId);
        if (server != null) return server;
    }
    return null;
}
 
Example #30
Source File: MigratingSQSManager.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
private void migrate(final SQSManager sqsManager, @NotNull final SProject project, @NotNull final SQSInfo... sqsInfos) {
    for (SQSInfo sqsInfo : sqsInfos) {
        myEditManager.addServer(project, sqsInfo);
        sqsManager.removeServer(project, sqsInfo.getId());
    }
    if (sqsInfos.length > 0) {
        if (sqsInfos.length > 1) {
            project.persist(myConfigActionFactory.createAction(project, sqsInfos.length + " SonarQube Servers moved from " + sqsManager.getDescription() + " to " + myEditManager.getDescription()));
        } else {
            project.persist(myConfigActionFactory.createAction(project, "SonarQube Server '" + sqsInfos[0].getName() + "' moved from " + sqsManager.getDescription() + " to " + myEditManager.getDescription()));
        }
    }
}