view agent/src/jetbrains/buildServer/symbols/SrcSrvStreamBuilder.java @ 26:87b24e4efcc3

fixed multiple indexing of the same pdb file
author Evgeniy.Koshkin
date Wed, 07 Aug 2013 17:29:18 +0400
parents f4e0050e2a2f
children 6ac3c2491e1a
line wrap: on
line source

/*
 * 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 java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collection;

/**
 * @author Evgeniy.Koshkin
 */
public class SrcSrvStreamBuilder {

  private final FileUrlProvider myUrlProvider;

  public SrcSrvStreamBuilder(final FileUrlProvider urlProvider) {
    myUrlProvider = urlProvider;
  }

  public void dumpStreamToFile(File targetFile, Collection<File> sourceFiles) throws IOException {
    final FileWriter fileWriter = new FileWriter(targetFile.getPath(), true);

    try {
      fileWriter.write("SRCSRV: ini ------------------------------------------------\r\n");
      fileWriter.write("VERSION=3\r\n");
      fileWriter.write("INDEXVERSION=2\r\n");
      fileWriter.write("VERCTRL=http\r\n");
      fileWriter.write("SRCSRV: variables ------------------------------------------\r\n");
      fileWriter.write("SRCSRVVERCTRL=http\r\n");
      fileWriter.write(String.format("HTTP_ALIAS=%s\r\n", myUrlProvider.getHttpAlias()));
      fileWriter.write("HTTP_EXTRACT_TARGET=%HTTP_ALIAS%/%var2%\r\n");
      fileWriter.write("SRCSRVTRG=%HTTP_EXTRACT_TARGET%\r\n");
      fileWriter.write("SRCSRVCMD=\r\n");
      fileWriter.write("SRCSRV: source files ------------------------------------------\r\n");
      for(File sourceFile : sourceFiles){
        final String sourceFileCanonical = sourceFile.getCanonicalPath();
        fileWriter.write(String.format("%s*%s\r\n", sourceFileCanonical, myUrlProvider.getFileUrl(sourceFileCanonical)));
      }
      fileWriter.write("SRCSRV: end ------------------------------------------------");
    }
    finally {
      fileWriter.close();
    }
  }
}