/* * Copyright 2000-2011 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.nuget.server.toolRegistry.impl; import jetbrains.buildServer.util.ArchiveUtil; import jetbrains.buildServer.util.FileUtil; import org.jetbrains.annotations.NotNull; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Collection; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; /** * Created by Eugene Petrenko (eugene.petrenko@gmail.com) * Date: 15.08.11 20:51 */ public class ToolPacker { public File packTool(@NotNull final String toolId, @NotNull final File rootDir) throws IOException { final File tool = new File(FileUtil.getTempDirectory(), toolId + ".zip"); final ZipOutputStream fos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(tool))); try { fos.putNextEntry(new ZipEntry("teamcity-plugin.xml")); fos.write(TOOL_DESCRIPTOR.getBytes("utf-8")); fos.closeEntry(); if (!ArchiveUtil.packZip(rootDir, fos)) { throw new IOException("Failed to create agent tool plugin"); } } finally { FileUtil.close(fos); } return tool; } private static final String TOOL_DESCRIPTOR = "" + "\n" + "\n" + " \n" + ""; }