Mercurial > hg > tc-symbol-server
changeset 34:b983676b66f9
formed source server url based on parameters
author | Evgeniy.Koshkin |
---|---|
date | Tue, 13 Aug 2013 15:53:37 +0400 |
parents | 76233e3aceb7 |
children | 2d2f54daf202 1586b9eb682e |
files | agent/src/jetbrains/buildServer/symbols/FileUrlProvider.java agent/src/jetbrains/buildServer/symbols/FileUrlProviderFactory.java agent/src/jetbrains/buildServer/symbols/SymbolsIndexer.java common/src/jetbrains/buildServer/symbols/SymbolsConstants.java server/resources/editSymbolsBuildFeatureParams.jsp server/src/META-INF/build-server-plugin-symbol-server.xml server/src/jetbrains/buildServer/symbols/DownloadSourcesController.java server/src/jetbrains/buildServer/symbols/IndexSymbolsBuildFeature.java server/src/jetbrains/buildServer/symbols/SymbolsIndexerParametersPreprocessor.java |
diffstat | 9 files changed, 115 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/agent/src/jetbrains/buildServer/symbols/FileUrlProvider.java Mon Aug 12 20:57:13 2013 +0400 +++ b/agent/src/jetbrains/buildServer/symbols/FileUrlProvider.java Tue Aug 13 15:53:37 2013 +0400 @@ -7,20 +7,18 @@ * @author Evgeniy.Koshkin */ public class FileUrlProvider { - private static final String GUEST_AUTH_APP_SOURCES = "guestAuth/app/sources"; - - private final String myServerUrl; + private final String myUrlPrefix; private final long myBuildId; private final File mySourcesRootDirectory; public FileUrlProvider(String serverUrl, long buildId, File sourcesRootDirectory) { - myServerUrl = serverUrl; + myUrlPrefix = serverUrl; myBuildId = buildId; mySourcesRootDirectory = sourcesRootDirectory; } public String getHttpAlias() { - return String.format("%s/%s/builds/id-%d/sources/files", myServerUrl, GUEST_AUTH_APP_SOURCES, myBuildId); + return String.format("%s/builds/id-%d/sources/files", myUrlPrefix, myBuildId); } public String getFileUrl(String path) throws IOException {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/agent/src/jetbrains/buildServer/symbols/FileUrlProviderFactory.java Tue Aug 13 15:53:37 2013 +0400 @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package jetbrains.buildServer.symbols; + +import com.intellij.openapi.diagnostic.Logger; +import jetbrains.buildServer.agent.AgentRunningBuild; +import jetbrains.buildServer.agent.BuildProgressLogger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Evgeniy.Koshkin + */ +public class FileUrlProviderFactory { + private static final Logger LOG = Logger.getInstance(FileUrlProviderFactory.class.getCanonicalName()); + + @Nullable + public static FileUrlProvider getProvider(@NotNull AgentRunningBuild build, @NotNull BuildProgressLogger buildLogger){ + String sourceServerUrlPrefix = build.getSharedConfigParameters().get(SymbolsConstants.SOURCES_SERVER_URL_PARAM_NAME); + if(sourceServerUrlPrefix == null){ + final String message = String.format("Configuration parameter %s was not set. ", SymbolsConstants.SOURCES_SERVER_URL_PARAM_NAME); + LOG.warn(message); + buildLogger.warning(message); + return null; + } + final String message = String.format("Using Sources Server URL %s", sourceServerUrlPrefix); + buildLogger.message(message); + LOG.debug(message); + sourceServerUrlPrefix = sourceServerUrlPrefix.substring(0, sourceServerUrlPrefix.length() - 1); //cut last '/' + return new FileUrlProvider(sourceServerUrlPrefix, build.getBuildId(), build.getCheckoutDirectory()); + } +}
--- a/agent/src/jetbrains/buildServer/symbols/SymbolsIndexer.java Mon Aug 12 20:57:13 2013 +0400 +++ b/agent/src/jetbrains/buildServer/symbols/SymbolsIndexer.java Tue Aug 13 15:53:37 2013 +0400 @@ -85,7 +85,7 @@ final Collection<File> pdbFiles = getArtifactPathsByFileExtension(artifacts, PDB_FILE_EXTENSION); if(pdbFiles.isEmpty()) return; - final FileUrlProvider urlProvider = getUrlProviderForBuild(myBuild, buildLogger); + final FileUrlProvider urlProvider = FileUrlProviderFactory.getProvider(myBuild, buildLogger); if(urlProvider == null) return; final PdbFilePatcher pdbFilePatcher = new PdbFilePatcher(myBuild.getBuildTempDirectory(), new SrcSrvStreamBuilder(urlProvider)); @@ -106,18 +106,6 @@ } } - @Nullable - private FileUrlProvider getUrlProviderForBuild(@NotNull AgentRunningBuild build, BuildProgressLogger buildLogger) { - String serverUrl = build.getSharedConfigParameters().get(SymbolsConstants.SERVER_URL_PARAMETER_NAME); - if(serverUrl == null){ - final String message = String.format("Configuration parameter %s was not set. ", SymbolsConstants.SERVER_URL_PARAMETER_NAME); - LOG.warn(message); - buildLogger.warning(message); - return null; - } - return new FileUrlProvider(serverUrl, build.getBuildId(), build.getCheckoutDirectory()); - } - private Collection<File> getArtifactPathsByFileExtension(List<ArtifactsCollection> artifactsCollections, String fileExtension){ final Collection<File> result = new HashSet<File>(); for(ArtifactsCollection artifactsCollection : artifactsCollections){
--- a/common/src/jetbrains/buildServer/symbols/SymbolsConstants.java Mon Aug 12 20:57:13 2013 +0400 +++ b/common/src/jetbrains/buildServer/symbols/SymbolsConstants.java Tue Aug 13 15:53:37 2013 +0400 @@ -5,6 +5,11 @@ */ public class SymbolsConstants { public static final String BUILD_FEATURE_TYPE = "symbol-indexer"; - public static final String SERVER_URL_PARAMETER_NAME = "symbols.server-url"; + + public static final String SOURCES_AUTH_REQUIRED_PARAM_NAME = "symbols.sources-auth-required"; + public static final String SOURCES_SERVER_URL_PARAM_NAME = "symbols.sources-server-url"; + public static final String SERVER_OWN_URL_PARAM_NAME = "symbols.server-own-url"; + public static final String APP_SYMBOLS = "app/symbols/"; + public static final String APP_SOURCES = "app/sources/"; }
--- a/server/resources/editSymbolsBuildFeatureParams.jsp Mon Aug 12 20:57:13 2013 +0400 +++ b/server/resources/editSymbolsBuildFeatureParams.jsp Tue Aug 13 15:53:37 2013 +0400 @@ -11,8 +11,8 @@ <tr> <th>Sources Access:</th> <td> - <props:checkboxProperty name="symbols.sources-authrequired"/> - <label for="symbols.sources-authrequired">Grand access to the sources to authenticated users only.</label> + <props:checkboxProperty name="symbols.sources-auth-required"/> + <label for="symbols.sources-auth-required">Grand access to the sources to authenticated users only.</label> </td> </tr> </table> \ No newline at end of file
--- a/server/src/META-INF/build-server-plugin-symbol-server.xml Mon Aug 12 20:57:13 2013 +0400 +++ b/server/src/META-INF/build-server-plugin-symbol-server.xml Tue Aug 13 15:53:37 2013 +0400 @@ -8,6 +8,7 @@ <bean class="jetbrains.buildServer.symbols.SymbolServerSettingsTab"/> <bean class="jetbrains.buildServer.symbols.IndexSymbolsBuildFeature"/> + <bean class="jetbrains.buildServer.symbols.SymbolsIndexerParametersPreprocessor"/> <bean class="jetbrains.buildServer.symbols.BuildSymbolsIndexProvider"/> <bean class="jetbrains.buildServer.symbols.DownloadSymbolsController"/>
--- a/server/src/jetbrains/buildServer/symbols/DownloadSourcesController.java Mon Aug 12 20:57:13 2013 +0400 +++ b/server/src/jetbrains/buildServer/symbols/DownloadSourcesController.java Tue Aug 13 15:53:37 2013 +0400 @@ -33,14 +33,14 @@ * @author Evgeniy.Koshkin */ public class DownloadSourcesController extends BaseController { - private static final String APP_SOURCES = "/app/sources/"; + private static final String VALID_URL_PATTERN = ".*/builds/id-\\d*/sources/.*"; private static final Logger LOG = Logger.getLogger(DownloadSourcesController.class); public DownloadSourcesController(@NotNull SBuildServer server, @NotNull WebControllerManager controllerManager) { super(server); - controllerManager.registerController(APP_SOURCES + "**", this); + controllerManager.registerController(SymbolsConstants.APP_SOURCES + "**", this); } @Nullable
--- a/server/src/jetbrains/buildServer/symbols/IndexSymbolsBuildFeature.java Mon Aug 12 20:57:13 2013 +0400 +++ b/server/src/jetbrains/buildServer/symbols/IndexSymbolsBuildFeature.java Tue Aug 13 15:53:37 2013 +0400 @@ -19,8 +19,6 @@ */ public class IndexSymbolsBuildFeature extends BuildFeature { - private static final String SOURCES_AUTH_REQUIRED_PARAM_NAME = "symbols.sources-authrequired"; - private String myEditParametersUrl; public IndexSymbolsBuildFeature(final PluginDescriptor pluginDescriptor, final WebControllerManager web, final ServerSettings serverSettings) { @@ -67,7 +65,7 @@ @NotNull @Override public String describeParameters(@NotNull Map<String, String> params) { - return Boolean.parseBoolean(params.get(SOURCES_AUTH_REQUIRED_PARAM_NAME)) + return Boolean.parseBoolean(params.get(SymbolsConstants.SOURCES_AUTH_REQUIRED_PARAM_NAME)) ? "Access to the indexed sources requires HTTP authentication." : "No authentication is required to retrieve indexed sources"; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/jetbrains/buildServer/symbols/SymbolsIndexerParametersPreprocessor.java Tue Aug 13 15:53:37 2013 +0400 @@ -0,0 +1,53 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package jetbrains.buildServer.symbols; + +import jetbrains.buildServer.RootUrlHolder; +import jetbrains.buildServer.serverSide.*; +import jetbrains.buildServer.web.util.WebUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; + +/** + * @author Evgeniy.Koshkin + */ +public class SymbolsIndexerParametersPreprocessor implements BuildStartContextProcessor { + + private final RootUrlHolder myRootUrlHolder; + + public SymbolsIndexerParametersPreprocessor(RootUrlHolder rootUrlHolder) { + myRootUrlHolder = rootUrlHolder; + } + + public void updateParameters(@NotNull BuildStartContext context) { + final SBuildType buildType = context.getBuild().getBuildType(); + if(buildType == null) return; + final Collection<SBuildFeatureDescriptor> buildFeatures = buildType.getResolvedSettings().getBuildFeatures(); + for(SBuildFeatureDescriptor buildFeature : buildFeatures){ + if(!buildFeature.getId().equals(SymbolsConstants.BUILD_FEATURE_TYPE)) continue; + boolean isAuthRequiredToGetSources = buildFeature.getParameters().containsKey(SymbolsConstants.SOURCES_AUTH_REQUIRED_PARAM_NAME); + String serverOwnUrl = context.getSharedParameters().get(SymbolsConstants.SERVER_OWN_URL_PARAM_NAME); + if(serverOwnUrl == null){ + serverOwnUrl = myRootUrlHolder.getRootUrl(); + } + final String authPrefix = isAuthRequiredToGetSources ? WebUtil.HTTP_AUTH_PREFIX : WebUtil.GUEST_AUTH_PREFIX; + final String sourceServerUrl = String.format("%s%s%s", serverOwnUrl, authPrefix, SymbolsConstants.APP_SOURCES); + context.addSharedParameter(SymbolsConstants.SOURCES_SERVER_URL_PARAM_NAME, sourceServerUrl); + } + } +}