blob: f8360f9c55c8be714b81af6bf0237b2f58995207 [file] [log] [blame]
/*
* 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 com.intellij.framework.library.impl;
import com.intellij.facet.frameworks.beans.Artifact;
import com.intellij.facet.frameworks.beans.ArtifactItem;
import com.intellij.framework.library.DownloadableLibraryDescription;
import com.intellij.framework.library.DownloadableLibraryFileDescription;
import com.intellij.framework.FrameworkAvailabilityCondition;
import com.intellij.framework.library.FrameworkLibraryVersion;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.util.download.impl.FileSetVersionsFetcherBase;
import org.jetbrains.annotations.NotNull;
import java.net.URL;
import java.util.List;
/**
* @author nik
*/
public class LibraryVersionsFetcher extends FileSetVersionsFetcherBase<FrameworkLibraryVersion, DownloadableLibraryFileDescription> implements DownloadableLibraryDescription {
public LibraryVersionsFetcher(@NotNull String groupId, @NotNull URL[] localUrls) {
super(groupId, localUrls);
}
@Override
protected FrameworkLibraryVersion createVersion(Artifact version, List<DownloadableLibraryFileDescription> files) {
return new FrameworkLibraryVersionImpl(version.getName(), version.getVersion(), createAvailabilityCondition(version), files, myGroupId);
}
@NotNull
protected FrameworkAvailabilityCondition createAvailabilityCondition(Artifact version) {
return FrameworkAvailabilityCondition.ALWAYS_TRUE;
}
@Override
protected DownloadableLibraryFileDescription createFileDescription(ArtifactItem item, String url, String prefix) {
String sourceUrl = item.getSourceUrl();
if (sourceUrl != null) {
sourceUrl = prependPrefix(sourceUrl, prefix);
}
String docUrl = item.getDocUrl();
if (docUrl != null) {
docUrl = prependPrefix(docUrl, prefix);
}
final String name = item.getName();
return new DownloadableLibraryFileDescriptionImpl(url, FileUtil.getNameWithoutExtension(name), FileUtilRt.getExtension(name), sourceUrl, docUrl, item.isOptional());
}
}