| /********************************************************************* |
| * Copyright (c) 2009, 2012 SpringSource, a division of VMware, Inc. |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| **********************************************************************/ |
| |
| package org.eclipse.virgo.ide.runtime.core.provisioning; |
| |
| import java.io.File; |
| import java.io.IOException; |
| import java.util.HashMap; |
| import java.util.Map; |
| import java.util.Set; |
| |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.core.runtime.jobs.Job; |
| import org.eclipse.virgo.ide.runtime.core.artefacts.Artefact; |
| import org.eclipse.virgo.ide.runtime.core.artefacts.LocalBundleArtefact; |
| import org.eclipse.virgo.ide.runtime.internal.core.utils.WebDownloadUtils; |
| import org.eclipse.virgo.util.io.FileCopyUtils; |
| import org.eclipse.wst.server.core.IRuntime; |
| |
| /** |
| * {@link Job} that provisions the missing source jars of the installed bundles in the dm Server's repository. |
| * |
| * @author Christian Dupuis |
| * @since 1.0.0 |
| */ |
| public class RepositorySourceProvisiongJob extends RepositoryProvisioningJob { |
| |
| private final Map<Artefact, File> outputFileMapping = new HashMap<Artefact, File>(); |
| |
| public RepositorySourceProvisiongJob(Set<IRuntime> runtimes, Set<Artefact> artifactsToDownload) { |
| super(runtimes, artifactsToDownload, false, true); |
| } |
| |
| @Override |
| protected void downloadSource(IProgressMonitor monitor, File bundlesFile, Artefact artifact) { |
| if (artifact instanceof LocalBundleArtefact) { |
| LocalBundleArtefact bundle = (LocalBundleArtefact) artifact; |
| String url = new StringBuilder().append("http://www.springsource.com/repository/app/bundle/version/download?name=").append( |
| bundle.getSymbolicName()).append("&version=").append(bundle.getVersion()).append("&type=source").toString(); |
| File outputFile = WebDownloadUtils.downloadFile(url, bundlesFile, monitor); |
| if (outputFile != null) { |
| this.outputFileMapping.put(artifact, outputFile); |
| } |
| } |
| } |
| |
| @Override |
| protected void copyDownloadedArtifactsIntoServer(File bundlesFile, File libraryFile) { |
| for (Map.Entry<Artefact, File> entry : this.outputFileMapping.entrySet()) { |
| if (entry.getKey() instanceof LocalBundleArtefact) { |
| File folder = ((LocalBundleArtefact) entry.getKey()).getFile().getParentFile(); |
| File outputFile = new File(folder, entry.getValue().getName()); |
| try { |
| outputFile.createNewFile(); |
| FileCopyUtils.copy(entry.getValue(), outputFile); |
| } catch (IOException e) { |
| } |
| } |
| } |
| } |
| } |